Skip to content

Commit 98dc86b

Browse files
committed
[apple2] light refactor of smartport code
1 parent 7f40238 commit 98dc86b

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- [network atari] Small tweak to ensure translation byte not lost when performing open, using stack instead of tmp variable which may get corrupt
6+
- [fuji apple2] Use "THE_FUJI" for fujinet device lookup instead of old hack for FUJI_DISK_0 - requires updated firmware
67

78
## [4.6.0] - 2024-09-01
89

apple2/src/bus/cc65/sp_dispatch.s

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ _sp_dispatch:
1717
1818
; the SP dispatch alters the return address by 3 bytes to skip the data below.
1919
; it returs with any error codes.
20-
.byte $20 ; JSR - making this a byte so we can get exact location of address being called
21-
_sp_dispatch_address:
22-
; overwritten in sp_init to correct address
23-
.word $0000
20+
; The dispatch address is altered in sp_init
21+
jsr $0000
22+
_sp_dispatch_address = *-2
2423

2524
dispatch_data:
2625
.byte $00 ; command

apple2/src/bus/cc65/sp_init.s

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
.include "zp.inc"
1313
.macpack cpu
1414

15-
; C version 246 bytes, this is 104 or 110 bytes (65c02 vs 6502) as hand written asm
15+
; Find the SmartPort device that has a FujiNet NETWORK adapter on it.
16+
; Really we should search for the FUJI device on it, but historically that was hacked into the DISK_0 device for reasons I'll never ever understand.
1617

1718
.proc _sp_init
1819

1920
; ptr1 = base (c701, c601, ...)
20-
; ptr2 = sp_detect_table
2121

2222
.if (.cpu .bitand ::CPU_ISET_65SC02)
2323
stz _sp_network
@@ -31,23 +31,16 @@
3131
.endif
3232

3333
; setup ptr1 to point to C700, it will decrease as we search cards
34-
ldy #$00
35-
sty ptr1
36-
lda #$c7
37-
sta ptr1+1
34+
ldx #$c7
35+
stx ptr1+1
3836

3937
; begin the detect loop
4038
main_loop:
41-
lda #<sp_detect_table
42-
sta ptr2
43-
lda #>sp_detect_table
44-
sta ptr2+1
45-
4639
ldy #$01
4740

4841
four_loop:
4942
lda (ptr1), y ; Cn00 + y
50-
cmp (ptr2), y ; table + y, which has extra bytes to align this loop
43+
cmp sp_detect_table, y ; table + y, which has extra bytes to align this loop
5144
bne no_match
5245
iny ; we look at Cn01, Cn03, Cn05, Cn07, so increment Y by 2
5346
iny
@@ -67,11 +60,11 @@ matched_four:
6760
lda (ptr1), y
6861
.endif
6962
; add 3, then store in dispatch address
70-
; clc - we know C is set because the previous cpy sets it in the comparison, so we can just add 2 here instead of 3 and save a byte
63+
; we know C is set because the previous cpy
7164
adc #$02
7265
sta _sp_dispatch_address
73-
lda ptr1+1
74-
sta _sp_dispatch_address+1
66+
; x is still Cn
67+
stx _sp_dispatch_address+1
7568

7669
check_network:
7770
; we set sp_is_init to stop sp_get_network_id from recursing
@@ -103,9 +96,9 @@ check_network:
10396

10497
no_match:
10598
; decrease ptr1+1 high byte of CnXX
106-
dec ptr1+1
107-
lda ptr1+1
108-
cmp #$c0
99+
dex
100+
stx ptr1+1
101+
cpx #$c0
109102
bne main_loop
110103

111104
; failed to find a network device on any card

apple2/src/bus/sp_find_fuji.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
uint8_t sp_fuji_id = 0;
77

88
bool sp_find_fuji() {
9-
// this is a hack in firmware, the fujinet shares the same device as D0. for now...
10-
int r = sp_find_device("FUJINET_DISK_0");
9+
int r = sp_find_device("THE_FUJI");
1110
if (r <= 0) {
12-
sp_fuji_id = 0;
13-
return false;
11+
// backwards compatible hack check
12+
r = sp_find_device("FUJINET_DISK_0");
13+
if (r <= 0) {
14+
sp_fuji_id = 0;
15+
return false;
16+
}
1417
}
1518
sp_fuji_id = (uint8_t) (r & 0xFF);
1619
return true;

0 commit comments

Comments
 (0)