Quit a program cleanly

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

Por aoineko

Paladin (1002)

imagem de aoineko

03-01-2021, 18:59

Hi all (and happy new year!),
I wonder if there is a "clean" way to exit a program and get back to Basic or DOS.
I'm programing a C game that modifies almost all the VRAM and I couldn't find a simple solution to restore the system before returning to Basic or DOS (for ROM, the system reboot when exiting the program so there is no problem).
I tried some of the Bios routines, but without success.
Do you have any advice about that?
By the way, were the "professional" games allowed a clean return to the OS or did they assumed that the user would reboot the MSX at the end of their session?

Entrar ou registrar-se para comentar

Por Briqunullus

Hero (665)

imagem de Briqunullus

03-01-2021, 19:34

For cartridges it's simple. You'll have to turn off the MSX to physically remove the cartridge. And since we've all gotten used to that, nobody expects a game to have a quit option.

Por thegeps

Paragon (1187)

imagem de thegeps

03-01-2021, 20:04

Have you tried to do a call to 0000h? It should reset the msx, I think...

Por Daemos

Prophet (2061)

imagem de Daemos

03-01-2021, 20:11

Quiting from a cartridge is easy. Simply pass return to the machine. If you return from your init code the machine continues to basic.

    db		"AB"
    dw		init,0,0,0,0,0,0

init:
ret

In msxdos there is a call check at map.grauw.nl for the specifics

something like call $5 but I don't remember the specifics

xor a
call $5

Por mcolom

Champion (316)

imagem de mcolom

03-01-2021, 21:09

In one of my program I'm doing this to exit to DOS with an error message:

ERROR_AND_EXIT:
    in a, (0x2E)
  
    call SLOTS_RRRR
    
    ; Set foreground, background, and border colors
    ld a, 6
    ld (FORCLR), a
    ld a, 4
    ld (BAKCLR), a
    ld (BDRCLR), a
    ld ix, CHGCLR
    call CALL_BIOS_IX
  
    ld ix, INIT32
    call CALL_BIOS_IX ; Text mode

    ld hl, ERROR_MESSAGE
    call PRINT
    call EXIT

Explanation: first I put RAM in all slots (if not, it won't be able to get back to DOS), I get back to text mode with text in red, and I print a message. If I had changed the segments of the RAM mapper, I'd have to put again the values used by DOS before getting back (I'm assuming DOS1 without mapper functions). To call the BIOS to change the colors or put the text mode, I use an inter-slot call. As Daemos said, the info pages of Grauw as excellent.

Por mcolom

Champion (316)

imagem de mcolom

03-01-2021, 21:09

Daemos wrote:
xor a
call $5

Yes, but it's register C, not A.

Por aoineko

Paladin (1002)

imagem de aoineko

03-01-2021, 21:50

thegeps wrote:

Have you tried to do a call to 0000h? It should reset the msx, I think...

For the Binary program (under Basic) I tried to call CHKRAM (0000h), INITXT (006Ch) and/or SETTXT (0078h). But the MSX "seem" to hang if I do so.
I will check the state of the system using an emulator...

Por Daemos

Prophet (2061)

imagem de Daemos

03-01-2021, 21:20

Yes, but it's register C, not A.

correct sorry my bad.

Por DamnedAngel

Champion (266)

imagem de DamnedAngel

03-01-2021, 22:36

This is how I do in my MSX-DOS template (which is derived from Konaminan/Avelino's):

;----------------------------------------------------------
;	Step 4: Program termination.
;	Termination code for DOS 2 was returned on L.         
    ld		c,#0x62		; DOS 2 function for program termination (_TERM)
    ld		b,l
    call	5			; On DOS 2 this terminates; on DOS 1 this returns...
    ld		c,#0x0
    jp		5			;...and then this one terminates
					;(DOS 1 function for program termination).

My templates (BIN, COM and ROM) at https://github.com/DamnedAngel/MSX-Templates-for-VisualStudio have some useful entry/exit configurations, including how to interact with MSX-BASIC. They are made primarily for Visual Studio, but one can use them in whatever IDE he/she prefers.

Por aoineko

Paladin (1002)

imagem de aoineko

03-01-2021, 22:30

Looking at the MSX-DOS code in OpenMSX, I don't understand how call $5 can work; I don't see a jump at this address.

Am I missing something?

By the way, when I return from my program, I'm well under MSX-DOS (I can launch a program for example or call CLS) BUT the rending is incorrect : the Screen mode remains unchanged (my game is in Screen 5).
Event if I reset the Screen mode to 0, the rendering is incorrect.
I suppose in my game I remove some important data from VRAM but I don't know how to restore them.

Por aoineko

Paladin (1002)

imagem de aoineko

03-01-2021, 22:29

Ah, OK! I understood how DOS function calls work (sorry I'm a DOS noob ^^).

However, calling the MSX-DOS function 0h or 62h don't fix my display problem after exiting my program.

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