|
1 | | - .export _sp_find_fuji |
2 | 1 | .export _sp_get_fuji_id |
3 | 2 | .export _sp_fuji_id |
4 | 3 |
|
5 | 4 | .import _sp_find_device |
| 5 | + .import _sp_is_init |
| 6 | + .import _sp_payload |
| 7 | + .import _sp_status |
6 | 8 |
|
| 9 | + .import device_id_idx |
| 10 | + .import device_count |
| 11 | + |
| 12 | + .import pusha |
7 | 13 | .import return0 |
8 | 14 | .import return1 |
9 | 15 |
|
10 | 16 | .macpack cpu |
11 | 17 |
|
12 | | -; bool sp_find_fuji() |
13 | | -_sp_find_fuji: |
| 18 | +sp_find_fuji: |
14 | 19 | lda #$10 |
15 | 20 | jsr _sp_find_device |
16 | 21 |
|
17 | | - bmi not_found |
18 | | - beq not_found |
| 22 | + bmi not_found_by_id |
| 23 | + beq not_found_by_id |
19 | 24 |
|
20 | 25 | sta _sp_fuji_id |
21 | 26 | jmp return1 |
22 | 27 |
|
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 :+ |
24 | 32 |
|
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 |
32 | 35 |
|
| 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 |
33 | 39 |
|
34 | 40 | ; uint8_t sp_get_fuji_id() |
35 | 41 | _sp_get_fuji_id: |
36 | 42 | ldx #$00 ; prep the return hi byte for C callers |
37 | 43 | 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: |
39 | 58 |
|
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 |
41 | 89 | rts |
42 | 90 |
|
| 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 | + |
43 | 102 | .data |
44 | 103 | _sp_fuji_id: .byte $00 |
0 commit comments