Skip to content

Commit 681d915

Browse files
committed
[apple2] refactor find functions, add fallback to find fuji device for backwards compat for firmware
1 parent d694846 commit 681d915

File tree

9 files changed

+138
-58
lines changed

9 files changed

+138
-58
lines changed

apple2/src/bus/cc65/sp_find_clock.s

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.export _sp_find_clock
21
.export _sp_get_clock_id
32
.export _sp_clock_id
43

@@ -9,8 +8,7 @@
98

109
.macpack cpu
1110

12-
; bool sp_find_clock()
13-
_sp_find_clock:
11+
sp_find_clock:
1412
lda #$13
1513
jsr _sp_find_device
1614

@@ -21,7 +19,6 @@ _sp_find_clock:
2119
jmp return1
2220

2321
not_found:
24-
2522
.if (.cpu .bitand ::CPU_ISET_65SC02)
2623
stz _sp_clock_id
2724
.else
@@ -35,10 +32,15 @@ not_found:
3532
_sp_get_clock_id:
3633
ldx #$00 ; prep the return hi byte for C callers
3734
lda _sp_clock_id
38-
beq _sp_find_clock
35+
bne :+ ; if it's already set, just exit
36+
37+
; otherwise we need to try and find it from SP
38+
jsr sp_find_clock
3939

40-
; A contains the ID > 0, X is 0, so just return
41-
rts
40+
; return whatever was set in sp_clock
41+
ldx #$00
42+
lda _sp_clock_id
43+
: rts
4244

4345
.data
4446
_sp_clock_id: .byte $00

apple2/src/bus/cc65/sp_find_cpm.s

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.export _sp_find_cpm
21
.export _sp_get_cpm_id
32
.export _sp_cpm_id
43

@@ -9,8 +8,7 @@
98

109
.macpack cpu
1110

12-
; bool sp_find_cpm()
13-
_sp_find_cpm:
11+
sp_find_cpm:
1412
lda #$12
1513
jsr _sp_find_device
1614

@@ -21,7 +19,6 @@ _sp_find_cpm:
2119
jmp return1
2220

2321
not_found:
24-
2522
.if (.cpu .bitand ::CPU_ISET_65SC02)
2623
stz _sp_cpm_id
2724
.else
@@ -35,10 +32,15 @@ not_found:
3532
_sp_get_cpm_id:
3633
ldx #$00 ; prep the return hi byte for C callers
3734
lda _sp_cpm_id
38-
beq _sp_find_cpm
35+
bne :+ ; if it's already set, just exit
36+
37+
; otherwise we need to try and find it from SP
38+
jsr sp_find_cpm
3939

40-
; A contains the ID > 0, X is 0, so just return
41-
rts
40+
; return whatever was set in sp_cpm
41+
ldx #$00
42+
lda _sp_cpm_id
43+
: rts
4244

4345
.data
4446
_sp_cpm_id: .byte $00

apple2/src/bus/cc65/sp_find_device.s

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
.export _sp_find_device
22

3+
.export device_type_id
4+
.export device_count
5+
.export device_id_idx
6+
.export tmp_orig_type
7+
38
.import _sp_cmdlist
49
.import _sp_init
510
.import _sp_is_init
@@ -29,13 +34,19 @@ _sp_find_device:
2934
lda _sp_is_init
3035
bne have_init
3136

32-
; no, so do it now
37+
; 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
38+
lda device_type_id
39+
sta tmp_orig_type
3340
jsr _sp_init
34-
bne have_init
41+
bne restore_type
3542

36-
; return 0 as the network device, and is an error
43+
; not found, so return 0 as the network device, and is an error
3744
jmp return0
3845

46+
restore_type:
47+
lda tmp_orig_type
48+
sta device_type_id
49+
3950
have_init:
4051
lda #$00
4152
jsr pusha ; doesn't change A, so can be used to double up as both params
@@ -95,4 +106,5 @@ not_found_yet:
95106
.bss
96107
device_type_id: .res 1
97108
device_count: .res 1
98-
device_id_idx: .res 1
109+
device_id_idx: .res 1
110+
tmp_orig_type: .res 1

apple2/src/bus/cc65/sp_find_fuji.s

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,103 @@
1-
.export _sp_find_fuji
21
.export _sp_get_fuji_id
32
.export _sp_fuji_id
43

54
.import _sp_find_device
5+
.import _sp_is_init
6+
.import _sp_payload
7+
.import _sp_status
68

9+
.import device_id_idx
10+
.import device_count
11+
12+
.import pusha
713
.import return0
814
.import return1
915

1016
.macpack cpu
1117

12-
; bool sp_find_fuji()
13-
_sp_find_fuji:
18+
sp_find_fuji:
1419
lda #$10
1520
jsr _sp_find_device
1621

17-
bmi not_found
18-
beq not_found
22+
bmi not_found_by_id
23+
beq not_found_by_id
1924

2025
sta _sp_fuji_id
2126
jmp return1
2227

23-
not_found:
28+
not_found_by_id:
29+
; if _sp_is_init is still 0, we didn't find the fujinet at all, so exit out
30+
lda _sp_is_init
31+
beq :+
2432

25-
.if (.cpu .bitand ::CPU_ISET_65SC02)
26-
stz _sp_fuji_id
27-
.else
28-
lda #$00
29-
sta _sp_fuji_id
30-
.endif
31-
jmp return0
33+
; we need to loop through all the devices again for JEFF'S HACK
34+
jsr try_fallback
3235

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

3440
; uint8_t sp_get_fuji_id()
3541
_sp_get_fuji_id:
3642
ldx #$00 ; prep the return hi byte for C callers
3743
lda _sp_fuji_id
38-
beq _sp_find_fuji
44+
bne :+ ; if it's already set, just exit
45+
46+
; otherwise we need to try and find it from SP
47+
jsr sp_find_fuji
48+
49+
; return whatever was set in sp_fuji
50+
ldx #$00
51+
lda _sp_fuji_id
52+
: rts
53+
54+
55+
; similar to sp_find_device, but for hack check
56+
; assumes device_count is set from previous search by ID
57+
try_fallback:
3958

40-
; A contains the ID > 0, X is 0, so just return
59+
lda #$01
60+
sta device_id_idx
61+
device_loop:
62+
jsr pusha ; the current Device ID
63+
lda #$03
64+
jsr _sp_status ; sp_status(id,3) DIB request
65+
66+
bne not_found_yet ; there wasn't a valid DIB for this device index
67+
68+
69+
; FALLBACK CHECK FOR DISK_0
70+
; try old style, where it's the first disk that supports the status/control for fuji device - PIEPMEIER!
71+
; the sp_payload contains following for disk_0 after a DIB status
72+
; sp_payload[18] = $30 = '0' ascii as in "DISK_0"
73+
; sp_payload[21] = $01 = floppy type
74+
; sp_payload[22] = $40 = subtype
75+
76+
lda _sp_payload+18
77+
cmp #$30
78+
bne not_found_yet
79+
lda _sp_payload+21
80+
cmp #$01
81+
bne not_found_yet
82+
lda _sp_payload+22
83+
cmp #$40
84+
bne not_found_yet
85+
86+
; found it, so return the current index
87+
ldx #$00
88+
lda device_id_idx
4189
rts
4290

91+
not_found_yet:
92+
inc device_id_idx
93+
lda device_id_idx
94+
cmp device_count
95+
bcc device_loop
96+
beq device_loop
97+
98+
; we have checked all devices, non had the type we were looking for
99+
jmp return0
100+
101+
43102
.data
44103
_sp_fuji_id: .byte $00

apple2/src/bus/cc65/sp_find_modem.s

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.export _sp_find_modem
21
.export _sp_get_modem_id
32
.export _sp_modem_id
43

@@ -9,8 +8,7 @@
98

109
.macpack cpu
1110

12-
; bool sp_find_modem()
13-
_sp_find_modem:
11+
sp_find_modem:
1412
lda #$15
1513
jsr _sp_find_device
1614

@@ -21,7 +19,6 @@ _sp_find_modem:
2119
jmp return1
2220

2321
not_found:
24-
2522
.if (.cpu .bitand ::CPU_ISET_65SC02)
2623
stz _sp_modem_id
2724
.else
@@ -35,10 +32,15 @@ not_found:
3532
_sp_get_modem_id:
3633
ldx #$00 ; prep the return hi byte for C callers
3734
lda _sp_modem_id
38-
beq _sp_find_modem
35+
bne :+ ; if it's already set, just exit
36+
37+
; otherwise we need to try and find it from SP
38+
jsr sp_find_modem
3939

40-
; A contains the ID > 0, X is 0, so just return
41-
rts
40+
; return whatever was set in sp_modem
41+
ldx #$00
42+
lda _sp_modem_id
43+
: rts
4244

4345
.data
4446
_sp_modem_id: .byte $00

apple2/src/bus/cc65/sp_find_network.s

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.export _sp_find_network
21
.export _sp_get_network_id
32
.export _sp_network
43

@@ -9,8 +8,7 @@
98

109
.macpack cpu
1110

12-
; bool sp_find_network()
13-
_sp_find_network:
11+
sp_find_network:
1412
lda #$11
1513
jsr _sp_find_device
1614

@@ -21,7 +19,6 @@ _sp_find_network:
2119
jmp return1
2220

2321
not_found:
24-
2522
.if (.cpu .bitand ::CPU_ISET_65SC02)
2623
stz _sp_network
2724
.else
@@ -35,10 +32,15 @@ not_found:
3532
_sp_get_network_id:
3633
ldx #$00 ; prep the return hi byte for C callers
3734
lda _sp_network
38-
beq _sp_find_network
35+
bne :+ ; if it's already set, just exit
36+
37+
; otherwise we need to try and find it from SP
38+
jsr sp_find_network
3939

40-
; A contains the ID > 0, X is 0, so just return
41-
rts
40+
; return whatever was set in sp_network
41+
ldx #$00
42+
lda _sp_network
43+
: rts
4244

4345
.data
4446
_sp_network: .byte $00

apple2/src/bus/cc65/sp_find_printer.s

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.export _sp_find_printer
21
.export _sp_get_printer_id
32
.export _sp_printer_id
43

@@ -9,8 +8,7 @@
98

109
.macpack cpu
1110

12-
; bool sp_find_printer()
13-
_sp_find_printer:
11+
sp_find_printer:
1412
lda #$14
1513
jsr _sp_find_device
1614

@@ -21,7 +19,6 @@ _sp_find_printer:
2119
jmp return1
2220

2321
not_found:
24-
2522
.if (.cpu .bitand ::CPU_ISET_65SC02)
2623
stz _sp_printer_id
2724
.else
@@ -35,10 +32,15 @@ not_found:
3532
_sp_get_printer_id:
3633
ldx #$00 ; prep the return hi byte for C callers
3734
lda _sp_printer_id
38-
beq _sp_find_printer
35+
bne :+ ; if it's already set, just exit
36+
37+
; otherwise we need to try and find it from SP
38+
jsr sp_find_printer
3939

40-
; A contains the ID > 0, X is 0, so just return
41-
rts
40+
; return whatever was set in sp_printer
41+
ldx #$00
42+
lda _sp_printer_id
43+
: rts
4244

4345
.data
4446
_sp_printer_id: .byte $00

apple2/src/bus/cc65/sp_init.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ found_network:
133133
txa
134134
.endif
135135
ldx #$00
136+
cmp #$00 ; force the flags to reflect A reg
136137
rts
137138
.endproc
138139

0 commit comments

Comments
 (0)