Persistence of Layer2 after reset

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

User avatar
Uto
Posts: 83
Joined: Tue May 30, 2017 9:33 am

Persistence of Layer2 after reset

Postby Uto » Thu Feb 13, 2020 9:42 am

Hi!

I have realized that after a reset (well ,actually a jumpo to address 0), the layer2 content persists. I understand layer 2 works separatedly, but I would have expected it to be cleared.

The problem is my DAAD addon is able to display pictures in layer2 mode, but the control of adventure replay is all under the original DAAD interpreter, that is: when you die/quit and you are asked whether to play again or not, the interpreter reacts to YES by restarting the game, what eventually will brings control back to my addon, and I can hide/replace the picture, but when the player says NO, the interpreter just runs a RST 0, not passing through my addon, so I cannot delete the picture or just hide the layer 2, and what I get is the Sinclair copyright screen with my picture on top.

Is there a way to ask Next to reset its registers when RST 0 is performed. Is there any other way?

Note: I know I may patch the interpreter, I can even do it in RAM, so I don't need to patch the interpreter file, but I'm trying to find a non intrusive method first, if any.

Thanks in advance.

Edit: I have tought I can replace the END condact in DAAD code (same as END condact in PAW or Quill) with some additional login in my addon, which would allow me to disable layer 2 before reseting. I keep the question here though, just in case before I go that way, some of you tell me there is way to do it easier than that. Fingers crossed :-)

User avatar
varmfskii
Posts: 287
Joined: Fri Jun 23, 2017 1:13 pm
Location: Stone Mountain, GA USA

Re: Persistence of Layer2 after reset

Postby varmfskii » Thu Feb 13, 2020 5:24 pm

You can generate a soft reset by writing a $01 to nextreg 2 or a hard reset by writing a $02 to nextreg 2.
Backer #2741 - TS2068, Byte, ZX Evolution

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Persistence of Layer2 after reset

Postby SevenFFF » Thu Feb 13, 2020 5:42 pm

Yes, RST 0 is not really a machine reset at all, just a BASIC reinitialise. The soft and hard resets varmfskii mentions actually drive the /RESET pin on the Z80 and selected internal hardware, whereas RST 0 just jumps to address zero. Next CP/M actually does a programmatic soft-reset to exit back to NextZXOS for similar reasons, so you can take that as good practice. Note that internal/external hardware is not reset by doing either a soft or hard reset - there are separate nextreg mechanisms for resetting the bus and internal/external hardware without resetting the machine itself.

It's really best to initialise ALL the Next registers and ports you will be using to known values in your startup code, because people can launch programs, exit them, and launch your program, and you can't rely on other people's programs to do cleanup when they exit.

As an example, consider a program that reprogrammed one of the palettes in its startup code, but didn't display any graphics using that palette until a game start option was chosen from the menu. If a user exited to BASIC from the start menu, then the palettes would stay reprogrammed but with no visual indication. Now if you start your program and assume the palette contains default colour values, the user will get an unexpected result when you start displaying graphics using that palette.

Another example is the boot testcard. This actually relies on certain machine state persisting across soft resets, because a reset is the only way to change video mode once it is locked.

NextBASIC does set some defaults when it starts, but only those defaults it is going to use itself as part of the editor and normal BASIC operation.

Also, consider that your program could be launched from esxDOS in one of the other machine personalities. All the Next features are still available, and your program will work fine when packaged in a file format that can be loaded by esxDOS. But there is no ROM there to do an extended Next reset. They are all standard Sinclair ROMs. So the individual programs must be responsible for their own initialisation.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
varmfskii
Posts: 287
Joined: Fri Jun 23, 2017 1:13 pm
Location: Stone Mountain, GA USA

Re: Persistence of Layer2 after reset

Postby varmfskii » Thu Feb 13, 2020 10:28 pm

100% with SevenFFF there. It is always best to keep track of the state that you change that other follow on software may assume is a certain way, and clean up after yourself.
Backer #2741 - TS2068, Byte, ZX Evolution

Alcoholics Anonymous
Posts: 781
Joined: Mon May 29, 2017 7:00 pm

Re: Persistence of Layer2 after reset

Postby Alcoholics Anonymous » Fri Feb 14, 2020 7:53 am

All of the above is true. The combination of soft reset via nextreg 2 and the nextzxos initialize that follows will restore the machine to a normal state. Not everything is initialized (eg, sprite patterns) but it will only be those things that programs have to initialize themselves when they run.

Avoid a hard reset though -- that starts the machine from scratch almost as if after a power on.

User avatar
Uto
Posts: 83
Joined: Tue May 30, 2017 9:33 am

Re: Persistence of Layer2 after reset

Postby Uto » Fri Feb 14, 2020 9:26 am

Thank you all. I see there are some interesting things to think about here :-)

I'll see what I can do, specially considering I'm not making the interpreter, but just an addon, but well, I can make some function in the addon that can be called from DAAD code for initialization. Whether that code is called by DAAD authors, it's up to them, but I see your point and I'll try to get it ready for others to use, and use it in our in progress game :-)

Same goes for clean up...

Camel
Posts: 37
Joined: Thu Feb 27, 2020 8:59 pm

Re: Persistence of Layer2 after reset

Postby Camel » Thu Apr 16, 2020 12:08 pm

Is there a good example of ensuring everything is initialised at the start of a BASIC program somewhere that people starting out could learn from? Thanks.

Ped7g
Posts: 256
Joined: Mon Jul 16, 2018 7:11 pm

Re: Persistence of Layer2 after reset

Postby Ped7g » Thu Apr 16, 2020 2:00 pm

@Camel: with core 3.1.4 the soft reset will also reset Layer 2 port 0x123B with value 0 and 16, i.e. switch layer2 visibility off, switch off any mapping, and set bank offsets to zero (all of these details are hidden from you in NextBASIC, but let's say simply the Soft reset (the short one) will deal with it in the next version of core (once it will be published at the latestdistro url, or you can already try the gitlab files for a sneak peek).

edit: after entering this, I realized it was maybe cleared in older cores already, just made it to the ports.txt docs with 3.1.4.

Anyway, "good example of ensuring everything is initialised at the start of a BASIC program" - this is what one is trying to do in the machine code, but with the changes to the core in newer versions, at some point your code will be obsolete and not set up EVERYTHING. So I guess if you run into particular problem of "short reset button + load your BAS" ending in wrong initial state, you should rather report it as possible bug here. (and yes, the "ensuring" part is the reset button on ZX, that's considered legit way to get machine into known initial state), so the NextBASIC reset can be improved.
(similarly the NEXLOAD/NEXLOAD2 incorporates "reset machine to default state" functionality, which gets extended with accordance to core changes over time, so even legacy NEX file created when some features didn't exist should be started in reasonable default state)

Camel
Posts: 37
Joined: Thu Feb 27, 2020 8:59 pm

Re: Persistence of Layer2 after reset

Postby Camel » Thu Apr 16, 2020 6:44 pm

Thanks. How would someone do that programmatically in BASIC? e.g., I want to make sure when someone else runs my BASIC program that e.g., nothing set in a layer or anywhere else is going to cause problems.

User avatar
varmfskii
Posts: 287
Joined: Fri Jun 23, 2017 1:13 pm
Location: Stone Mountain, GA USA

Re: Persistence of Layer2 after reset

Postby varmfskii » Thu Apr 16, 2020 8:01 pm

Two possibilities. 1) assume people cleaned up after themselves (it will normally be in starting config). 2) assume that everything that matters is going to be set wrong and act accordingly. (2 is safer, but more work, of course).
Backer #2741 - TS2068, Byte, ZX Evolution


Who is online

Users browsing this forum: No registered users and 2 guests