Game loop with RST#38 (game programming tutorial) (Development MSX Fora)MSX Resource Center            
            
English Nederlands Espa�ol Portugu�s Russian         
 Nieuws
   Voorpagina
  Nieuws archief
  Nieuws onderwerpen

 Informatie
   MSX Fora
  Artikelen
  Recensies
  Beursverslagen
  Fotoreportages
  Beurzen en meetings
  Enquêtes
  Links
  Zoek

 Software
   Downloads
  Webshop

 MRC
   Wie we zijn
  Kom bij ons team
  Doneren
  Policies
  Contact met het MRC
  Link naar Ons
  Statistieken

 Zoek
 
  

  

 Login
 

Gebruikersnaam

Wachtwoord




Ben je nog niet lid? Klik hier en word MSX vriend!


 Statistieken
 

Er zijn 54 gasten en 1 MSX vriend online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - Game loop with RST#38 (game programming tutorial)

Schrijver

Game loop with RST#38 (game programming tutorial)

Devcon
msx friend
Berichten: 10
Geplaatst: 12 April 2004, 11:40   
Hi all, i have a few questions for all the MSX gurus here
I think, all Konami games uses the RST#38 for the main game loop. And i wanna learn how to do it exactly.
Any of you know a good tutorial? A game source well documented could be cool too.
There are a lot of tech docs (MSX RedBook, etc) but i'm unable to find a step to step game programming guide for dummies hehe. And reverse enginering for a newbie like me is quite hard.

My idea of the code would be like this:


MyIntHandling: DI
CALL MyVDPEngine
CALL MyPSGEngine
EI
RET


Main: DI
IM 1
LD A,0C3H
LD (0FD9AH),A
LD HL,MyIntHandling
LD (0FD9BH),HL
.
.
.
RET

Another question, why the games do a IM 1 before changing the Interrup Handling? And, i have to PUSH/POP all the registers i use in MyIntHandling?
Well, its all. If any of you know a good web page or tutorial of how this things are implemented in a game, and can help me understand this ill be thankfull a lot.

Sorry my bad spelling, and take care all.

-Devcon-
Sonic_aka_T

msx guru
Berichten: 2269
Geplaatst: 12 April 2004, 13:33   
I don't know much about interrupts, but I do know you do need to push *all* registers unless you're using your own Interupt routines and *NO* BIOS. Since you're using the $FD9A hook it would seem that you are using the BIOS. I don't know if the BIOS itself uses the alternate registers, but I guess it does. Ofcourse the BIOS pushes and pops all the registers before calling $FD9A, so from that point of view you wouldn't need to push registers anymore. But if you were to put RAM at $0000, yes, you would intercept at $0038, push all registers (well, technically just the ones that are used in the main program) and then do your routines.
Sonic_aka_T

msx guru
Berichten: 2269
Geplaatst: 12 April 2004, 13:34   
Well, don't forget to pop the registers before returning
GuyveR800
msx guru
Berichten: 3048
Geplaatst: 12 April 2004, 14:40   
First, use the FD9F (H.TIMI) hook, it's the one called every 50th or 60th second.
The FD9A (H.KEYI) hook is for ALL interrupts (MIDI, moonsound, RS232, etc).
Second, you have to store the previous hook value, call it during your program, and restore it when your program exits.

Then, there is no reason to switch to IM1, as it's the normal Z80 interrupt mode for MSX.

Pushing/popping all registers is not necessary, as the RST38 ISR does that itself. However, you SHOULD PUSH/POP AF to the stack, because the ISR stores the VDP statusflag there.
Also, don't put EI/RET at the end of your interrupt handler, because RST38 will enable them itself, and should remain off during all interrupt handling.

The rest of your code looks fine

It's going to look like this:


MyIntHandling: PUSH AF ; push AF, no need for DI, that's already assumed.
CALL MyVDPEngine
CALL MyPSGEngine
POP AF ; pop AF again, we fall through into the OldInt

OldInt: DB 0,0,0,0,0 ; 5 bytes for the previous hook code

Main: DI
LD HL,0FD9Fh ; save current hook to OldInt
LD DE,OldInt
LD BC,5
LDIR
LD A,0C3H
LD (0FD9FH),A
LD HL,MyIntHandling
LD (0FDA0H),HL
.
. ; don't forget to EI somewhere in this code to enable interrupts again
.
RET

then put this code in your exit-code:

DI
LD HL,OldInt ; restore hook
LD DE,0FD9Fh
LD BC,5
LDIR


Alternatively, in stead of falling through to the OldInt, you can also put CALL OldInt somewhere in MyIntHandling and just return with a RET, if that looks cleaner to you

flyguille
msx master
Berichten: 1223
Geplaatst: 12 April 2004, 15:06   
yeah, konami games use the interrupt for run the animation routine and all other things... at the same speed.... that is very well documented in MNBIOS manual. Also is documented how to acelerate all konami games !!!..
ro
msx guru
Berichten: 2346
Geplaatst: 12 April 2004, 15:33   
When using standard BIOS isr (rst #38) there's no need to save regs (using push and pop) yourself 'coz the ISR does that allready.

#38 first it pushes all regs
call INTs (VBL and LNI)
does keyboard routines
pops all regs
returns

This is why the ISR is kinda slow, it has much overhead.
The DI is indeed assumed when entering ISR
Again, this is when using standard BIOS ISR!!

When using own ISR (set your int routine on #38 in RAM page 0) you should atleast save the regs you're going to use in the int. routine. This way you might end up with FAST ISR routines *by controlling it all by yourself. YOU decide what happens on ISR and in which order (screensplits have high priority for example. Also any other VDP actions have to be done before any music routines 'coz of 'flickering' fx... well, you'll notice)

good luck.
ps. you might wanna check the development forum on the MNbios topics. We've discussed so detail interrupt handling there allready...

GuyveR800
msx guru
Berichten: 3048
Geplaatst: 12 April 2004, 15:48   
Yeah, that was about non-BIOS interrupt handling.. Since this guy is a beginner, he's better off using the BIOS for a while longer.
 
 







(c) 1994 - 2008 Stichting MSX Resource Center. MSX is een trademark van MSX Licensing Corporation.