Quit a program cleanly

Página 3/4
1 | 2 | | 4

Por aoineko

Master (165)

Imagen del aoineko

04-01-2021, 23:51

Juste before the return of my main function (yes, I'm programming in C ^^), I call Bios_MainROMCall(R_INITXT);, where R_INITXT is defined as 0x006C.

And here is the function body:

void Bios_MainROMCall(u16 addr) __FASTCALL
{
	addr;
	__asm
//		ld	hl, addr	// FastCall
		push 	hl 
		pop	ix 
		ld	iy, (M_EXPTBL-1)
		call	R_CALSLT
		ei				// because CALSLT do DI
	__endasm;
}

(maybe you will recognize your comment ^^)

After exiting my main function, I should comeback to my ctr0 here:

	call	_main
	; exit program and return value from L register
	ld		c, #0x62
	ld		b, l
	call	5				; Try the DOS-2 termination function (_TERM)
	ld		c, #0x00
	jp		5				; Otherwise, try the DOS-1 termination function (0)

But if I do the inter-slot call to INITXT, I never get back control to my program.
Btw, I don't change the slot of any page in my program.

Por aoineko

Master (165)

Imagen del aoineko

05-01-2021, 00:04

Making interslot call to CHGMOD 5, then to TOTEXT solve the problem!
I don't understand why those interslot calls work under DOS and not INITXT :-/
(while INITXT work well under Basic)

Any way, I have a working solution at least.

Por gdx

Enlighted (4695)

Imagen del gdx

06-01-2021, 03:08

Daemos wrote:

If your set video modes by hand don't forget to write your changes to the VDP mirrors as well.

Yes, to create a program that can be quit you have to update manually the system variables at each VDP access, and not only the variables for the of VDP registers contents but also the variables in relation to what you make the VDP do. So I don't think the trick of switching to SCREEN5 and then in Text mode is sufficient in all cases.

Por aoineko

Master (165)

Imagen del aoineko

06-01-2021, 10:09

Under DOS or Basic, I looked at the VDP register status before and after my program with OpenMSX and everything looks the same if I do a CHGMOD 5 and then a TOTEXT before exiting. However, my program changes almost all registers (mode, table address, v/h-blank interrupt, scroll, etc.) but don't change anything in the Bios work area. I have the impression that the TOTEXT completely resets the environment.
Is there any particular known issue doing that?

Por gdx

Enlighted (4695)

Imagen del gdx

08-01-2021, 01:52

No issue, but what I mean is what you have done may be sufficient for your case but it will not be for all cases because it all depends on what has been changed by the program. Failure to manually update system variables at each VDP access can cause bugs in software that runs after exiting your program.

Por NYYRIKKI

Enlighted (5875)

Imagen del NYYRIKKI

08-01-2021, 02:05

I also kind of wonder what kind of situation gdx is now thinking of... I think it would be quite weird if TOTEXT would skip some part of screen initialization.

Ps. I THINK you can just write 5 to #FCAF instead of using real CHGMOD... Should be quite a bit faster.

Por zeilemaker54

Champion (311)

Imagen del zeilemaker54

08-01-2021, 06:35

gdx wrote:

Failure to manually update system variables at each VDP access can cause bugs in software that runs after exiting your program.

That is why using the BIOS is preferable, I will take care of these things. If you bypass the BIOS, you have to take care yourself.

Por aoineko

Master (165)

Imagen del aoineko

08-01-2021, 10:22

Not touching the working area of the Bios, I really don't see what might not been reset properly after calling TOTEXT. I'm not an MSX specialist so I might be missing something.

NYYRIKKI wrote:

Ps. I THINK you can just write 5 to #FCAF instead of using real CHGMOD... Should be quite a bit faster.

Since it's only to leave my program, I don't necessarily need it to be super fast. That said, if it has exactly the same effect, I might use the fastest method. Thank you.

Por aoineko

Master (165)

Imagen del aoineko

08-01-2021, 18:06

I have an other question regarding quitting a binary program under BASIC.
By resetting the text mode and calling the Basic function 409Bh, I go back to Basic with no worries.
But, if I run my game from a Basic program with a bload"x.bin",r, when exiting the game, if I make a List to see the launch program, I get buggy characters.
I guess I'm overwriting a reserved memory area.
My game doesn't use a lot of memory so I don't think I'm overwriting the memory from below.
However, this may be due to my call stack which is located at HIMEM.
This is not a correct value for a program under Basic ?

EDIT : I already read the "Best way to init sp rom" thread (https://www.msx.org/forum/msx-talk/development/best-way-to-i...) ^^

Por DamnedAngel

Master (232)

Imagen del DamnedAngel

08-01-2021, 19:29

Maybe you are trashing the patterns area of VRAM. Can you post a screenshot? If you screen 0:list the same occurs?

Página 3/4
1 | 2 | | 4