Permalink
Browse files

Cheating with the driver status to match programmer expectations (eve…

…n if this is pretty much futurism)
  • Loading branch information...
sik
sik committed Jul 25, 2017
1 parent 12d03b4 commit 7d516cc248777ae239c5a4e50fa325365ddd7d53
Showing with 59 additions and 23 deletions.
  1. +6 −6 README
  2. +19 −0 c/echo.c
  3. +34 −17 src-68k/echo.68k
View
12 README
@@ -7,12 +7,12 @@
| | |_ |_ ___ | | | | | | | |
| |_______ |_ |___| _| | | | | |_ |_____| _|
|___________| |________| |___| |___| |_________|
___ ___ _ _ ___ __ ___ ___ ___ _ ___ ___ _ ___
| _| | | | | \ | _| | _| | | _| | | | _|
| |_| | | | | | | | | | |_| | | |_| | | | |_ _ _ ___ ___ | | | |_
|_ | | | | | | | | | | _| | | | | | | | _| | | | __| _ \ | | |_ |
_| | | | | | | | | | | |_| | | | | | | | |_ | | | __| /_ | |_ _| |
|___|___|___|_|_|__/ |___|_|_|___|_|_|_|___| \_/|___|_|_\_| |_|_|___|
___ ___ _ _ ___ __ ___ ___ ___ _ ___ ___ _ ___ _
| _| | | | | \ | _| | _| | | _| | | | _| |
| |_| | | | | | | | | | |_| | | |_| | | | |_ _ _ ___ ___ | | | |_| |
|_ | | | | | | | | | | _| | | | | | | | _| | | | __| _ \ | | |_ | |
_| | | | | | | | | | | |_| | | | | | | | |_ | | | __| /_ | |_ _| | |
|___|___|___|_|_|__/ |___|_|_|___|_|_|_|___| \_/|___|_|_\_| |_|_|___|_|
=============================================================================
View
@@ -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();
View
@@ -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.

0 comments on commit 7d516cc

Please sign in to comment.