2020-07-28


After last week’s failure in sound this week(end) was a total win over sound 💪

I knew the game played better with some audible feedback and I also knew that the only way I could pull it off in NextBASIC was to use the interrupt handler at the machine code level. I’d previously tried and failed with im 2 but this time I looked at the native DRIVER support that NextOS offers a hook in to the im 1 interrupt.

The short version is, once I groked the border example I managed to port the AYFX player from Shiru to a driver.

The bulk of my code involved handling the driver calls and make sure to swap in the user bank during the routines and swap back to the original bank into the slot I was using.

I made some silly mistakes in the code, but managed to debug successfully using Cspect, things like ld a, (addr) must be read (and thought of) as “load a with addr” (and not “load a into addr”!).

My bank swapping code looks like this:

MMU6_C000_NR_56		equ $56

; ************************************************
; backup_bank
; Take the current bank in MMU 6 and store the value
; in (active_bank) for later restore.
; ************************************************
backup_bank:
  push      af        ; make a backup of A
  ld        bc, $243b ; select NEXT register
  in        a,(c)     ; save register state
  ld        (saved_reg), a
  ld        a, MMU6_C000_NR_56
  out       (c),a
  inc       b             ; $253b to access (read or write) value
  in        a,(c)
  ld        (active_bank),a
  dec       b         ; $243B
  ld        a,2
saved_reg equ $-1     ; this points saved_reg to the `2` above
  out       (c),a     ; just in case IRQ was in between registry work
  pop       af
  ret

; ************************************************
; activate_user_bank
; Switches in a user defined bank into MMU6
; ************************************************
activate_user_bank:
  call      backup_bank
  ld        a, (ayfx_bank)
  nextreg   MMU6_C000_NR_56, a
  ret

; ************************************************
; restore_bank
; Returns the bank slot to it's original setting
; ************************************************
restore_bank:
  ld        a, (active_bank)
  nextreg   MMU6_C000_NR_56, a
  ret

The result: uninterrupted game play with sound effects 🎉

Now the bug list is looking pretty small, the priority is a graphics glitch on level 4 (which can also be seen at the end of the game over on the letter “E”), then the scoring system (with high scores) and then… and then we’re there.

Get Go Mummy! (ZX Spectrum Next)

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.