From 3aacf3d2cedfdeca49ceb57533389870bfc688a9 Mon Sep 17 00:00:00 2001 From: sik Date: Sun, 23 Jul 2017 03:20:35 -0300 Subject: Now with pausing and other niceties --- src-68k/echo.68k | 165 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 137 insertions(+), 28 deletions(-) (limited to 'src-68k') diff --git a/src-68k/echo.68k b/src-68k/echo.68k index f10695a..e6682bd 100644 --- a/src-68k/echo.68k +++ b/src-68k/echo.68k @@ -40,12 +40,16 @@ Echo_Z80Reset macro ;**************************************************************************** Echo_SendCommand: - move.w d1, -(sp) ; Save register - + movem.l d1/a1, -(sp) ; Save registers Echo_Z80Request ; We need the Z80 bus + lea ($A01FFF), a1 ; First try the 1st slot + tst.b (a1) ; Is 1st slot available? + beq.s @Ready ; If so, move on + subq.l #4, a1 ; Try 2nd slot otherwise + @Try: - tst.b ($A01FFF) ; Check if Echo is ready + tst.b (a1) ; Check if 2nd slot is ready beq.s @Ready ; Too busy? Echo_Z80Release ; Let Echo continue move.w #$FF, d1 ; Give it some time @@ -54,10 +58,10 @@ Echo_SendCommand: bra.s @Try ; Try again @Ready: - move.b d0, ($A01FFF) ; Write command ID + move.b d0, (a1) ; Write command ID Echo_Z80Release ; We're done with the Z80 bus - move.w (sp)+, d1 ; Restore register + movem.l (sp)+, d1/a1 ; Restore registers rts ; End of subroutine ;**************************************************************************** @@ -70,12 +74,16 @@ Echo_SendCommand: Echo_SendCommandAddr: Echo_SendCommandEx: - movem.l d0-d1, -(sp) ; Save register - + movem.l d0-d1/a1, -(sp) ; Save registers Echo_Z80Request ; We need the Z80 bus + lea ($A01FFF), a1 ; First try the 1st slot + tst.b (a1) ; Is 1st slot available? + beq.s @Ready ; If so, move on + subq.l #4, a1 ; Try 2nd slot otherwise + @Try: - tst.b ($A01FFF) ; Check if Echo is ready + tst.b (a1) ; Check if 2nd slot is ready beq.s @Ready ; Too busy? Echo_Z80Release ; Let Echo continue move.w #$FF, d1 ; Give it some time @@ -84,14 +92,14 @@ Echo_SendCommandEx: bra.s @Try ; Try again @Ready: - move.b d0, ($A01FFF) ; Write command ID + move.b d0, (a1) ; Write command ID move.l a0, d0 ; Easier to manipulate here - move.b d0, ($A01FFD) ; Store low address byte + move.b d0, -2(a1) ; Store low address byte lsr.l #7, d0 ; Get high address byte lsr.b #1, d0 ; We skip one bit bset.l #7, d0 ; Point into bank window - move.b d0, ($A01FFE) ; Store high address byte + move.b d0, -1(a1) ; Store high address byte lsr.w #8, d0 ; Get bank byte move.w d0, d1 ; Parse 32X bit separately @@ -99,11 +107,11 @@ Echo_SendCommandEx: and.b #$7F, d0 ; Filter out unused bit from addresses and.b #$80, d1 ; Filter out all but 32X bit or.b d1, d0 ; Put everything together - move.b d0, ($A01FFC) ; Store bank byte + move.b d0, -3(a1) ; Store bank byte Echo_Z80Release ; We're done with the Z80 bus - movem.l (sp)+, d0-d1 ; Restore register + movem.l (sp)+, d0-d1/a1 ; Restore registers rts ; End of subroutine ;**************************************************************************** @@ -115,11 +123,16 @@ Echo_SendCommandEx: ;**************************************************************************** Echo_SendCommandByte: + movem.l d1/a1, -(sp) ; Save registers Echo_Z80Request ; We need the Z80 bus - move.w d1, -(sp) ; Save register + lea ($A01FFF), a1 ; First try the 1st slot + tst.b (a1) ; Is 1st slot available? + beq.s @Ready ; If so, move on + subq.l #4, a1 ; Try 2nd slot otherwise + @Try: - tst.b ($A01FFF) ; Check if Echo is ready + tst.b (a1) ; Check if 2nd slot is ready beq.s @Ready ; Too busy? Echo_Z80Release ; Let Echo continue move.w #$FF, d1 ; Give it some time @@ -128,11 +141,11 @@ Echo_SendCommandByte: bra.s @Try ; Try again @Ready: - move.w (sp)+, d1 ; Restore register - move.b d0, ($A01FFF) ; Write command ID - move.b d1, ($A01FFC) ; Write parameter + move.b d0, (a1) ; Write command ID + move.b d1, -3(a1) ; Write parameter Echo_Z80Release ; We're done with the Z80 bus + movem.l (sp)+, d1/a1 ; Restore registers rts ; End of subroutine ;**************************************************************************** @@ -147,6 +160,11 @@ Echo_PlaySFX: move.b #$02, d0 ; Command $02 = play SFX bsr Echo_SendCommandAddr ; Send command to Echo move.w (sp)+, d0 ; Restore register + + Echo_Z80Request ; We need Z80 RAM access... + ori.b #$01, ($A01FF0) ; Force SFX flag to be on + Echo_Z80Release ; OK done with it for real + rts ; End of subroutine ;**************************************************************************** @@ -159,6 +177,11 @@ Echo_StopSFX: move.b #$03, d0 ; Command $03 = stop SFX bsr Echo_SendCommand ; Send command to Echo move.w (sp)+, d0 ; Restore register + + Echo_Z80Request ; We need Z80 RAM access... + andi.b #$FE, ($A01FF0) ; Force SFX flag to be off + Echo_Z80Release ; OK done with it for real + rts ; End of subroutine ;**************************************************************************** @@ -173,6 +196,11 @@ Echo_PlayBGM: move.b #$04, d0 ; Command $04 = play BGM bsr Echo_SendCommandAddr ; Send command to Echo move.w (sp)+, d0 ; Restore register + + Echo_Z80Request ; We need Z80 RAM access... + ori.b #$02, ($A01FF0) ; Force BGM flag to be on + Echo_Z80Release ; OK done with it for real + rts ; End of subroutine ;**************************************************************************** @@ -185,6 +213,23 @@ Echo_StopBGM: move.b #$05, d0 ; Command $05 = stop BGM bsr Echo_SendCommand ; Send command to Echo move.w (sp)+, d0 ; Restore register + + Echo_Z80Request ; We need Z80 RAM access... + andi.b #$FD, ($A01FF0) ; Force BGM flag to be off + Echo_Z80Release ; OK done with it for real + + rts ; End of subroutine + +;**************************************************************************** +; Echo_PauseBGM +; Pauses BGM playback +;**************************************************************************** + +Echo_PauseBGM: + move.w d0, -(sp) ; Save register + move.b #$08, d0 ; Command $08 = pause BGM + bsr Echo_SendCommand ; Send command to Echo + move.w (sp)+, d0 ; Restore register rts ; End of subroutine ;**************************************************************************** @@ -192,12 +237,12 @@ Echo_StopBGM: ; Resumes BGM playback ;**************************************************************************** -;Echo_ResumeBGM: -; move.w d0, -(sp) ; Save register -; move.b #$06, d0 ; Command $06 = resume BGM -; bsr Echo_SendCommand ; Send command to Echo -; move.w (sp)+, d0 ; Restore register -; rts ; End of subroutine +Echo_ResumeBGM: + move.w d0, -(sp) ; Save register + move.b #$06, d0 ; Command $06 = resume BGM + bsr Echo_SendCommand ; Send command to Echo + move.w (sp)+, d0 ; Restore register + rts ; End of subroutine ;**************************************************************************** ; Echo_PlayDirect @@ -311,10 +356,11 @@ Echo_SetVolume: ; Echo_SetVolumeEx ; Changes the global volume for each individual channel. ; -; input a0.l ... Pointer to 13 bytes +; input a0.l ... Pointer to 16 bytes ; 8 bytes with FM volumes (0..127) ; 4 bytes with PSG volumes (0..15) ; 1 byte with PCM toggle (0/1) +; 3 reserved (unused for now) ;**************************************************************************** Echo_SetVolumeEx: @@ -335,6 +381,9 @@ Echo_SetVolumeEx: move.b (a0)+, (a1)+ ; PSG channel 2 move.b (a0)+, (a1)+ ; PSG channel 3 move.b (a0)+, (a1)+ ; PCM channel toggle + move.b (a0)+, (a1)+ ; (reserved) + move.b (a0)+, (a1)+ ; (reserved) + move.b (a0)+, (a1)+ ; (reserved) move.b #1, ($A01FF1) ; Tell Echo to update the volume levels @@ -358,9 +407,9 @@ Echo_GetStatus: Echo_Z80Request ; We need the Z80 bus move.b ($A01FF0), d0 ; Get the status flags - tst.b ($A01FFF) ; Check if command still has to be parsed - beq.s @NotBusy ; Any commands left to be parsed? - bset.l #15, d0 ; If so, set the relevant flag + tst.b ($A01FFB) ; Check if any commands can be sent + beq.s @NotBusy ; Any room left for new commands? + bset.l #15, d0 ; If not, set the relevant flag @NotBusy: cmpi.b #$FF, ($A01F00) ; Check if the direct buffer is empty @@ -371,6 +420,63 @@ Echo_GetStatus: Echo_Z80Release ; Let the Z80 go! rts ; End of subroutine +;**************************************************************************** +; Echo_GetFlags +; Gets the current values of the flags. +; +; output d0.b ... Bitmask with flags +;**************************************************************************** + +Echo_GetFlags: + Echo_Z80Request ; Request Z80 bus + move.b ($A01FF2), d0 ; Get the flags + Echo_Z80Release ; Done with Z80 RAM + rts ; End of subroutine + +;**************************************************************************** +; Echo_SetFlags +; Sets flags from the 68000. +; +; input d0.b ... Bitmask of flags to be set (1 = set, 0 = intact) +;**************************************************************************** + +Echo_SetFlags: + subq.w #4, sp ; Buffer for the events + move.b #$FA, (sp) ; Set flags + move.b d0, 1(sp) ; + move.b #$FF, 2(sp) ; End of stream + + move.l a0, -(sp) ; Issue the events + lea 4(sp), a0 + bsr Echo_PlayDirect + move.l (sp)+, a0 + + addq.w #4, sp ; Done with the buffer + rts ; End of subroutine + +;**************************************************************************** +; Echo_ClearFlags +; Clear flags from the 68000. +; +; input d0.b ... Bitmask of flags to be cleared (1 = clear, 0 = intact) +;**************************************************************************** + +Echo_ClearFlags: + not.b d0 ; Bitmask is inverted + subq.w #4, sp ; Buffer for the events + move.b #$FB, (sp) ; Set flags + move.b d0, 1(sp) ; + move.b #$FF, 2(sp) ; End of stream + not.b d0 ; Restore register + + move.l a0, -(sp) ; Issue the events + lea 4(sp), a0 + bsr Echo_PlayDirect + move.l (sp)+, a0 + + addq.w #4, sp ; Done with the buffer + rts ; End of subroutine + ;**************************************************************************** ; Echo_ListEntry ; Defines an entry in a pointer list @@ -443,6 +549,9 @@ Echo_Init: move.b d0, (a0)+ move.b d0, (a0)+ move.b #1, (a0)+ + move.b d0, (a0)+ + move.b d0, (a0)+ + move.b d0, (a0)+ move.b d0, ($A01FF1) move.b #$FF, ($A01F00) ; No direct events to execute -- cgit v1.2.3