aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README12
-rw-r--r--c/echo.c19
-rw-r--r--src-68k/echo.68k51
3 files changed, 59 insertions, 23 deletions
diff --git a/README b/README
index 6f036e2..e227d3d 100644
--- a/README
+++ b/README
@@ -7,12 +7,12 @@
| | |_ |_ ___ | | | | | | | |
| |_______ |_ |___| _| | | | | |_ |_____| _|
|___________| |________| |___| |___| |_________|
- ___ ___ _ _ ___ __ ___ ___ ___ _ ___ ___ _ ___
- | _| | | | | \ | _| | _| | | _| | | | _|
- | |_| | | | | | | | | | |_| | | |_| | | | |_ _ _ ___ ___ | | | |_
- |_ | | | | | | | | | | _| | | | | | | | _| | | | __| _ \ | | |_ |
- _| | | | | | | | | | | |_| | | | | | | | |_ | | | __| /_ | |_ _| |
- |___|___|___|_|_|__/ |___|_|_|___|_|_|_|___| \_/|___|_|_\_| |_|_|___|
+ ___ ___ _ _ ___ __ ___ ___ ___ _ ___ ___ _ ___ _
+ | _| | | | | \ | _| | _| | | _| | | | _| |
+ | |_| | | | | | | | | | |_| | | |_| | | | |_ _ _ ___ ___ | | | |_| |
+ |_ | | | | | | | | | | _| | | | | | | | _| | | | __| _ \ | | |_ | |
+ _| | | | | | | | | | | |_| | | | | | | | |_ | | | __| /_ | |_ _| | |
+ |___|___|___|_|_|__/ |___|_|_|___|_|_|_|___| \_/|___|_|_\_| |_|_|___|_|
=============================================================================
diff --git a/c/echo.c b/c/echo.c
index 23bd409..60cd34a 100644
--- a/c/echo.c
+++ b/c/echo.c
@@ -375,6 +375,16 @@ void echo_set_pcm_rate(uint8_t rate) {
//***************************************************************************
uint16_t echo_get_status(void) {
+ // Look-up tables used to work around the fact that playing/stopping
+ // won't set the status immediately (only when Echo processes the command)
+ // and this can catch programmers off guard
+ static const uint8_t and_flags[] = {
+ 0xFF,0xFF, 0xFF,0xFE,0xFF,0xFD, 0xFF,0xFF,0xFF
+ };
+ static const uint8_t or_flags[] = {
+ 0x00,0x00, 0x01,0x00,0x02,0x00, 0x00,0x00,0x00
+ };
+
// We need access to the Z80
Z80_REQUEST();
@@ -386,6 +396,15 @@ uint16_t echo_get_status(void) {
if (z80_ram[0x1F00] != 0xFF)
status |= ECHO_STAT_DIRBUSY;
+ // Look ahead in the queue for any pending commands
+ // Adjust the flags accordingly if needed
+ uint8_t command = z80_ram[0x1FFF];
+ status &= and_flags[command];
+ status |= or_flags[command];
+ command = z80_ram[0x1FFB];
+ status &= and_flags[command];
+ status |= or_flags[command];
+
// Done with the Z80
Z80_RELEASE();
diff --git a/src-68k/echo.68k b/src-68k/echo.68k
index e6682bd..7abdbf8 100644
--- a/src-68k/echo.68k
+++ b/src-68k/echo.68k
@@ -161,10 +161,6 @@ Echo_PlaySFX:
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
;****************************************************************************
@@ -178,10 +174,6 @@ Echo_StopSFX:
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
;****************************************************************************
@@ -197,10 +189,6 @@ Echo_PlayBGM:
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
;****************************************************************************
@@ -214,10 +202,6 @@ Echo_StopBGM:
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
;****************************************************************************
@@ -403,7 +387,9 @@ Echo_SetVolumeEx:
;****************************************************************************
Echo_GetStatus:
- moveq #0, d0
+ movem.l d1/a1, -(sp) ; Save registers
+
+ clr.w d0 ; Set all needed bits to 0
Echo_Z80Request ; We need the Z80 bus
move.b ($A01FF0), d0 ; Get the status flags
@@ -417,9 +403,40 @@ Echo_GetStatus:
bset.l #14, d0 ; If so, set the relevant flag
@DirectEmpty:
+ moveq #0, d1 ; Clear unused bits from index
+ lea @AndTable(pc), a1 ; Get pointer to look-up tables
+
+ move.b ($A01FFF), d1 ; Get next pending command (if any)
+ beq.s @QueueChecked ; No commands left to process?
+ move.b (a1,d1.w), d1 ; Get mask of flags to leave
+ and.b d1, d0 ; Remove flags that should be clear
+ move.b @OrTable-@AndTable(a1,d1.w), d1 ; Get mask of flags to set
+ or.b d1, d0 ; Insert flags that should be set
+
+ move.b ($A01FFB), d1 ; Repeat that with 2nd pending command
+ beq.s @QueueChecked
+ move.b (a1,d1.w), d1
+ and.b d1, d0
+ move.b @OrTable-@AndTable(a1,d1.w), d1
+ or.b d1, d0
+
+@QueueChecked:
Echo_Z80Release ; Let the Z80 go!
+ movem.l (sp)+, d1/a1 ; Restore registers
rts ; End of subroutine
+;----------------------------------------------------------------------------
+; Look-up tables used to readjust the status flags based on pending commands
+; that haven't been processed yet (normally they wouldn't be updated yet, but
+; this can catch programmers off guard so we cheat it).
+;
+; Every byte represents a possible command.
+;----------------------------------------------------------------------------
+
+@AndTable: dc.b $FF,$FF, $FF,$FE,$FF,$FD, $FF,$FF,$FF
+@OrTable: dc.b $00,$00, $01,$00,$02,$00, $00,$00,$00
+ even
+
;****************************************************************************
; Echo_GetFlags
; Gets the current values of the flags.