Author |
Message |
- Joined: 11 Dec 2019
- Posts: 30
- Location: Finland
|
Real SC3000, BASIC-cartridge and interrupts
Posted: Sat Feb 15, 2020 11:30 am
|
I now have a working tape-version (.WAV) of the assembly game which I ported from MSX to Sega. Game loads nicely into my real Sega SC-3000 from my laptop.
I use PSGlib for sounds which needs a steady interrupt. This was easy to do with the ROM-version of the game. But with tape-version which is executed from BASIC with a CALL, I cannot figure out how to trap (hook) an interrupt for PSGlib for the sounds to work.
I searched through the reserved RAM-area ($8000-$97ff) for a possible address where one could place the interrupt hook but couldn't find one. How should the hooking be done?
Thanks in advance
/helmha
|
|
|
- Site Admin
- Joined: 19 Oct 1999
- Posts: 14744
- Location: London
|
Posted: Sat Feb 15, 2020 12:19 pm
|
It depends how (or if) Basic allows you to hook it. Which version are you targeting?
|
|
|
- Joined: 11 Dec 2019
- Posts: 30
- Location: Finland
|
Posted: Sat Feb 15, 2020 1:51 pm
|
Maxim wrote It depends how (or if) Basic allows you to hook it. Which version are you targeting?
I have the BASIC LEVEL III B-cartridge.
|
|
|
- Joined: 03 Oct 2011
- Posts: 188
- Location: New Zealand
|
Posted: Sun Feb 16, 2020 11:53 pm Last edited by honestbob on Mon Feb 17, 2020 9:27 pm; edited 2 times in total
|
I looked pretty hard into the Basic IIIB source a few years back. From memory there is no way to hook the VDP interrupt.
So instead you have to write a polling loop that keeps polling the VDP status register until you see that bit 7 is set (which happens just before the interrupt). You then execute your screen / keyboard / sound handling, and go back into the polling loop.
I think you want something very similar to this:
di ; prevent the Basic IIIB interrupt handler from running
...
; VDP polling loop
VDPPollingLoop:
ld c, $BF ; vdp status register is $BF
in a, (c) ; read vdp status register
and $80 ; check if the interrupt has triggered - ie. bit 7 is set
jr z, VDPPollingLoop ; if not triggered, do polling loop again
ret
...
DoSomething:
; do whatever VRAM updates and keyboard / joystick scans you need or PSGlib handling
...
call VDPPollingLoop ; now call the polling loop and wait until next interrupt is ready
jp DoSomething ; and go do your interrupt handling again
My apologies if that isn't quite right. It should be pretty close though :)
Some more info from Sega Computer Magazine August 1988
"Bit 7 is set at the end of each raster scan pending an interrupt. It must be read every interrupt in order to clear the interrupt and receive the new interrupt for the next frame. This is why we must disable interrupts before writing or reading to VRAM. At the end of every interrupt the status register is read and the address register is cleared, resulting in some strange effects if not disabled."
|
|
|
- Site Admin
- Joined: 19 Oct 1999
- Posts: 14744
- Location: London
|
Posted: Mon Feb 17, 2020 12:46 am
|
If you enable interrupts then that may cause more trouble. You don’t really want to run the built in interrupt handler, and it may well cause the polling loop to miss frames.
|
|
|
- Joined: 03 Oct 2011
- Posts: 188
- Location: New Zealand
|
Posted: Mon Feb 17, 2020 1:07 am
|
Maxim wrote If you enable interrupts then that may cause more trouble. You don’t really want to run the built in interrupt handler, and it may well cause the polling loop to miss frames.
Yes, agreed. All the 100% machine code tape games I have seen on the SC-3000 do di right at the start and never enable them again - so you only use the polling loop and the Basic IIIB VDP handler doesn't trigger again.
Will edit the above example to put di at the start
|
|
|
- Joined: 11 Dec 2019
- Posts: 30
- Location: Finland
|
Posted: Tue Feb 18, 2020 1:17 pm
|
Thank you very much! It seems to work alright :)
|
|
|
- Joined: 03 Oct 2011
- Posts: 188
- Location: New Zealand
|
Posted: Tue Feb 18, 2020 11:41 pm
|
No worries. Looking forward to seeing the ported game :)
Cheers
|
|
|