Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Real SC3000, BASIC-cartridge and interrupts

Reply to topic
Author Message
  • Joined: 11 Dec 2019
  • Posts: 30
  • Location: Finland
Reply with quote
Real SC3000, BASIC-cartridge and interrupts
Post 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
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post Posted: Sat Feb 15, 2020 12:19 pm
It depends how (or if) Basic allows you to hook it. Which version are you targeting?
  View user's profile Send private message Visit poster's website
  • Joined: 11 Dec 2019
  • Posts: 30
  • Location: Finland
Reply with quote
Post 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.
  View user's profile Send private message
  • Joined: 03 Oct 2011
  • Posts: 188
  • Location: New Zealand
Reply with quote
Post 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."
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14744
  • Location: London
Reply with quote
Post 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.
  View user's profile Send private message Visit poster's website
  • Joined: 03 Oct 2011
  • Posts: 188
  • Location: New Zealand
Reply with quote
Post 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
  View user's profile Send private message Visit poster's website
  • Joined: 11 Dec 2019
  • Posts: 30
  • Location: Finland
Reply with quote
Post Posted: Tue Feb 18, 2020 1:17 pm
Thank you very much! It seems to work alright :)
  View user's profile Send private message
  • Joined: 03 Oct 2011
  • Posts: 188
  • Location: New Zealand
Reply with quote
Post Posted: Tue Feb 18, 2020 11:41 pm
No worries. Looking forward to seeing the ported game :)

Cheers
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!