Skip to content

Commit

Permalink
[apple2] refactor find functions, add fallback to find fuji device fo…
Browse files Browse the repository at this point in the history
…r backwards compat for firmware
  • Loading branch information
markjfisher committed Sep 14, 2024
1 parent d694846 commit 681d915
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 58 deletions.
16 changes: 9 additions & 7 deletions apple2/src/bus/cc65/sp_find_clock.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.export _sp_find_clock
.export _sp_get_clock_id
.export _sp_clock_id

Expand All @@ -9,8 +8,7 @@

.macpack cpu

; bool sp_find_clock()
_sp_find_clock:
sp_find_clock:
lda #$13
jsr _sp_find_device

Expand All @@ -21,7 +19,6 @@ _sp_find_clock:
jmp return1

not_found:

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_clock_id
.else
Expand All @@ -35,10 +32,15 @@ not_found:
_sp_get_clock_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_clock_id
beq _sp_find_clock
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_clock

; A contains the ID > 0, X is 0, so just return
rts
; return whatever was set in sp_clock
ldx #$00
lda _sp_clock_id
: rts

.data
_sp_clock_id: .byte $00
16 changes: 9 additions & 7 deletions apple2/src/bus/cc65/sp_find_cpm.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.export _sp_find_cpm
.export _sp_get_cpm_id
.export _sp_cpm_id

Expand All @@ -9,8 +8,7 @@

.macpack cpu

; bool sp_find_cpm()
_sp_find_cpm:
sp_find_cpm:
lda #$12
jsr _sp_find_device

Expand All @@ -21,7 +19,6 @@ _sp_find_cpm:
jmp return1

not_found:

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_cpm_id
.else
Expand All @@ -35,10 +32,15 @@ not_found:
_sp_get_cpm_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_cpm_id
beq _sp_find_cpm
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_cpm

; A contains the ID > 0, X is 0, so just return
rts
; return whatever was set in sp_cpm
ldx #$00
lda _sp_cpm_id
: rts

.data
_sp_cpm_id: .byte $00
20 changes: 16 additions & 4 deletions apple2/src/bus/cc65/sp_find_device.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.export _sp_find_device

.export device_type_id
.export device_count
.export device_id_idx
.export tmp_orig_type

.import _sp_cmdlist
.import _sp_init
.import _sp_is_init
Expand Down Expand Up @@ -29,13 +34,19 @@ _sp_find_device:
lda _sp_is_init
bne have_init

; no, so do it now
; no, so do it now, we first have to save the current type we're searching for, as it gets overwritten searching for network device
lda device_type_id
sta tmp_orig_type
jsr _sp_init
bne have_init
bne restore_type

; return 0 as the network device, and is an error
; not found, so return 0 as the network device, and is an error
jmp return0

restore_type:
lda tmp_orig_type
sta device_type_id

have_init:
lda #$00
jsr pusha ; doesn't change A, so can be used to double up as both params
Expand Down Expand Up @@ -95,4 +106,5 @@ not_found_yet:
.bss
device_type_id: .res 1
device_count: .res 1
device_id_idx: .res 1
device_id_idx: .res 1
tmp_orig_type: .res 1
89 changes: 74 additions & 15 deletions apple2/src/bus/cc65/sp_find_fuji.s
Original file line number Diff line number Diff line change
@@ -1,44 +1,103 @@
.export _sp_find_fuji
.export _sp_get_fuji_id
.export _sp_fuji_id

.import _sp_find_device
.import _sp_is_init
.import _sp_payload
.import _sp_status

.import device_id_idx
.import device_count

.import pusha
.import return0
.import return1

.macpack cpu

; bool sp_find_fuji()
_sp_find_fuji:
sp_find_fuji:
lda #$10
jsr _sp_find_device

bmi not_found
beq not_found
bmi not_found_by_id
beq not_found_by_id

sta _sp_fuji_id
jmp return1

not_found:
not_found_by_id:
; if _sp_is_init is still 0, we didn't find the fujinet at all, so exit out
lda _sp_is_init
beq :+

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_fuji_id
.else
lda #$00
sta _sp_fuji_id
.endif
jmp return0
; we need to loop through all the devices again for JEFF'S HACK
jsr try_fallback

; either ID is in A, or it's 0 for failure, either way, we use that to set fuji id and return
: sta _sp_fuji_id
rts

; uint8_t sp_get_fuji_id()
_sp_get_fuji_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_fuji_id
beq _sp_find_fuji
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_fuji

; return whatever was set in sp_fuji
ldx #$00
lda _sp_fuji_id
: rts


; similar to sp_find_device, but for hack check
; assumes device_count is set from previous search by ID
try_fallback:

; A contains the ID > 0, X is 0, so just return
lda #$01
sta device_id_idx
device_loop:
jsr pusha ; the current Device ID
lda #$03
jsr _sp_status ; sp_status(id,3) DIB request

bne not_found_yet ; there wasn't a valid DIB for this device index


; FALLBACK CHECK FOR DISK_0
; try old style, where it's the first disk that supports the status/control for fuji device - PIEPMEIER!
; the sp_payload contains following for disk_0 after a DIB status
; sp_payload[18] = $30 = '0' ascii as in "DISK_0"
; sp_payload[21] = $01 = floppy type
; sp_payload[22] = $40 = subtype

lda _sp_payload+18
cmp #$30
bne not_found_yet
lda _sp_payload+21
cmp #$01
bne not_found_yet
lda _sp_payload+22
cmp #$40
bne not_found_yet

; found it, so return the current index
ldx #$00
lda device_id_idx
rts

not_found_yet:
inc device_id_idx
lda device_id_idx
cmp device_count
bcc device_loop
beq device_loop

; we have checked all devices, non had the type we were looking for
jmp return0


.data
_sp_fuji_id: .byte $00
16 changes: 9 additions & 7 deletions apple2/src/bus/cc65/sp_find_modem.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.export _sp_find_modem
.export _sp_get_modem_id
.export _sp_modem_id

Expand All @@ -9,8 +8,7 @@

.macpack cpu

; bool sp_find_modem()
_sp_find_modem:
sp_find_modem:
lda #$15
jsr _sp_find_device

Expand All @@ -21,7 +19,6 @@ _sp_find_modem:
jmp return1

not_found:

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_modem_id
.else
Expand All @@ -35,10 +32,15 @@ not_found:
_sp_get_modem_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_modem_id
beq _sp_find_modem
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_modem

; A contains the ID > 0, X is 0, so just return
rts
; return whatever was set in sp_modem
ldx #$00
lda _sp_modem_id
: rts

.data
_sp_modem_id: .byte $00
16 changes: 9 additions & 7 deletions apple2/src/bus/cc65/sp_find_network.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.export _sp_find_network
.export _sp_get_network_id
.export _sp_network

Expand All @@ -9,8 +8,7 @@

.macpack cpu

; bool sp_find_network()
_sp_find_network:
sp_find_network:
lda #$11
jsr _sp_find_device

Expand All @@ -21,7 +19,6 @@ _sp_find_network:
jmp return1

not_found:

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_network
.else
Expand All @@ -35,10 +32,15 @@ not_found:
_sp_get_network_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_network
beq _sp_find_network
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_network

; A contains the ID > 0, X is 0, so just return
rts
; return whatever was set in sp_network
ldx #$00
lda _sp_network
: rts

.data
_sp_network: .byte $00
16 changes: 9 additions & 7 deletions apple2/src/bus/cc65/sp_find_printer.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.export _sp_find_printer
.export _sp_get_printer_id
.export _sp_printer_id

Expand All @@ -9,8 +8,7 @@

.macpack cpu

; bool sp_find_printer()
_sp_find_printer:
sp_find_printer:
lda #$14
jsr _sp_find_device

Expand All @@ -21,7 +19,6 @@ _sp_find_printer:
jmp return1

not_found:

.if (.cpu .bitand ::CPU_ISET_65SC02)
stz _sp_printer_id
.else
Expand All @@ -35,10 +32,15 @@ not_found:
_sp_get_printer_id:
ldx #$00 ; prep the return hi byte for C callers
lda _sp_printer_id
beq _sp_find_printer
bne :+ ; if it's already set, just exit

; otherwise we need to try and find it from SP
jsr sp_find_printer

; A contains the ID > 0, X is 0, so just return
rts
; return whatever was set in sp_printer
ldx #$00
lda _sp_printer_id
: rts

.data
_sp_printer_id: .byte $00
1 change: 1 addition & 0 deletions apple2/src/bus/cc65/sp_init.s
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ found_network:
txa
.endif
ldx #$00
cmp #$00 ; force the flags to reflect A reg
rts
.endproc

Expand Down
Loading

0 comments on commit 681d915

Please sign in to comment.