Skip to content

Commit d694846

Browse files
committed
[apple2] change sp_find functions to search by type instead of name
1 parent 98dc86b commit d694846

33 files changed

+513
-251
lines changed

apple2/src/bus/cc65/sp_close.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.export _sp_close
22

33
.import _sp_cmdlist
4-
.import _sp_dispatch
4+
.import sp_dispatch
55

66
.include "sp.inc"
77

@@ -15,6 +15,6 @@
1515
sta _sp_cmdlist+1 ; sp_cmdlist[1] = dest;
1616
lda #SP_CLOSE_PARAM_COUNT
1717
sta _sp_cmdlist ; sp_cmdlist[0] = SP_CLOSE_PARAM_COUNT;
18-
lda #SP_CMD_CLOSE
19-
jmp _sp_dispatch ; return sp_dispatch(SP_CMD_CLOSE);
18+
ldx #SP_CMD_CLOSE
19+
jmp sp_dispatch ; return sp_dispatch(SP_CMD_CLOSE);
2020
.endproc

apple2/src/bus/cc65/sp_close_nw.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.export _sp_close_nw
22

33
.import _sp_cmdlist
4-
.import _sp_dispatch
4+
.import sp_dispatch
55
.import _sp_nw_unit
66

77
.include "sp.inc"
@@ -20,6 +20,6 @@
2020
sta _sp_cmdlist ; sp_cmdlist[0] = SP_CLOSE_PARAM_COUNT_NW;
2121
lda _sp_nw_unit
2222
sta _sp_cmdlist+2 ; sp_cmdlist[2] = sp_nw_unit;
23-
lda #SP_CMD_CLOSE
24-
jmp _sp_dispatch ; return sp_dispatch(SP_CMD_CLOSE);
23+
ldx #SP_CMD_CLOSE
24+
jmp sp_dispatch ; return sp_dispatch(SP_CMD_CLOSE);
2525
.endproc

apple2/src/bus/cc65/sp_common.s

Lines changed: 0 additions & 24 deletions
This file was deleted.

apple2/src/bus/cc65/sp_control.s

Lines changed: 0 additions & 35 deletions
This file was deleted.

apple2/src/bus/cc65/sp_control_nw.s

Lines changed: 0 additions & 40 deletions
This file was deleted.

apple2/src/bus/cc65/sp_dispatch.s

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.export _sp_find_clock
2+
.export _sp_get_clock_id
3+
.export _sp_clock_id
4+
5+
.import _sp_find_device
6+
7+
.import return0
8+
.import return1
9+
10+
.macpack cpu
11+
12+
; bool sp_find_clock()
13+
_sp_find_clock:
14+
lda #$13
15+
jsr _sp_find_device
16+
17+
bmi not_found
18+
beq not_found
19+
20+
sta _sp_clock_id
21+
jmp return1
22+
23+
not_found:
24+
25+
.if (.cpu .bitand ::CPU_ISET_65SC02)
26+
stz _sp_clock_id
27+
.else
28+
lda #$00
29+
sta _sp_clock_id
30+
.endif
31+
jmp return0
32+
33+
34+
; uint8_t sp_get_clock_id()
35+
_sp_get_clock_id:
36+
ldx #$00 ; prep the return hi byte for C callers
37+
lda _sp_clock_id
38+
beq _sp_find_clock
39+
40+
; A contains the ID > 0, X is 0, so just return
41+
rts
42+
43+
.data
44+
_sp_clock_id: .byte $00

apple2/src/bus/cc65/sp_find_cpm.s

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.export _sp_find_cpm
2+
.export _sp_get_cpm_id
3+
.export _sp_cpm_id
4+
5+
.import _sp_find_device
6+
7+
.import return0
8+
.import return1
9+
10+
.macpack cpu
11+
12+
; bool sp_find_cpm()
13+
_sp_find_cpm:
14+
lda #$12
15+
jsr _sp_find_device
16+
17+
bmi not_found
18+
beq not_found
19+
20+
sta _sp_cpm_id
21+
jmp return1
22+
23+
not_found:
24+
25+
.if (.cpu .bitand ::CPU_ISET_65SC02)
26+
stz _sp_cpm_id
27+
.else
28+
lda #$00
29+
sta _sp_cpm_id
30+
.endif
31+
jmp return0
32+
33+
34+
; uint8_t sp_get_cpm_id()
35+
_sp_get_cpm_id:
36+
ldx #$00 ; prep the return hi byte for C callers
37+
lda _sp_cpm_id
38+
beq _sp_find_cpm
39+
40+
; A contains the ID > 0, X is 0, so just return
41+
rts
42+
43+
.data
44+
_sp_cpm_id: .byte $00
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.export _sp_find_device
2+
3+
.import _sp_cmdlist
4+
.import _sp_init
5+
.import _sp_is_init
6+
.import _sp_nw_unit
7+
.import _sp_payload
8+
.import _sp_status
9+
10+
.import pusha
11+
.import negax
12+
.import return0
13+
14+
.include "sp.inc"
15+
16+
; int sp_find_device(uint8_t type_id);
17+
; where type_id is the internal fujinet device type_id:
18+
; $10 = fujinet
19+
; $11 = network
20+
; $12 = cpm
21+
; $13 = clock
22+
; $14 = printer
23+
; $15 = modem
24+
; $01 = floppy disk
25+
; $02 = hard disk
26+
_sp_find_device:
27+
sta device_type_id ; save the type_id
28+
; check if we've already run sp_init
29+
lda _sp_is_init
30+
bne have_init
31+
32+
; no, so do it now
33+
jsr _sp_init
34+
bne have_init
35+
36+
; return 0 as the network device, and is an error
37+
jmp return0
38+
39+
have_init:
40+
lda #$00
41+
jsr pusha ; doesn't change A, so can be used to double up as both params
42+
jsr _sp_status ; sp_status(0,0) fetches the device count
43+
44+
beq status_ok_1
45+
46+
; there was an error, negate A/X and return it
47+
jmp negax
48+
; implicit RTS
49+
50+
status_ok_1:
51+
ldx #$00 ; prep the return value if it's going to be 0
52+
lda _sp_payload ; device count in sp_payload[0]
53+
beq :+ ; if the count is zero, just return 0, don't touch X as it's already 0
54+
bpl have_count
55+
56+
; byte extend the negative value into X, as A is already negative
57+
dex
58+
: rts
59+
60+
have_count:
61+
; now repeatedly call sp_status(i, 3) to get the DIB status for the device, which contains name and its device type
62+
; a contains the count of devices, 1 based
63+
sta device_count
64+
65+
lda #$01
66+
sta device_id_idx
67+
device_loop:
68+
jsr pusha ; the current Device ID
69+
lda #$03
70+
jsr _sp_status ; sp_status(id,3) DIB request
71+
72+
bne not_found_yet ; there wasn't a valid DIB for this device index
73+
74+
; compare sp_payload[21] to device_type_id
75+
lda _sp_payload+21
76+
cmp device_type_id
77+
bne not_found_yet
78+
79+
; found it, so return the current index
80+
ldx #$00
81+
lda device_id_idx
82+
rts
83+
84+
not_found_yet:
85+
inc device_id_idx
86+
lda device_id_idx
87+
cmp device_count
88+
bcc device_loop
89+
beq device_loop
90+
91+
; we have checked all devices, non had the type we were looking for
92+
jmp return0
93+
94+
95+
.bss
96+
device_type_id: .res 1
97+
device_count: .res 1
98+
device_id_idx: .res 1

0 commit comments

Comments
 (0)