diff --git a/apple2/src/bus/cc65/sp_find_clock.s b/apple2/src/bus/cc65/sp_find_clock.s index 313ba8e..f8dc73d 100644 --- a/apple2/src/bus/cc65/sp_find_clock.s +++ b/apple2/src/bus/cc65/sp_find_clock.s @@ -1,46 +1,14 @@ .export _sp_get_clock_id .export _sp_clock_id - .import _sp_find_device - - .import return0 - .import return1 - - .macpack cpu - -sp_find_clock: - lda #$13 - jsr _sp_find_device - - bmi not_found - beq not_found - - sta _sp_clock_id - jmp return1 - -not_found: -.if (.cpu .bitand ::CPU_ISET_65SC02) - stz _sp_clock_id -.else - lda #$00 - sta _sp_clock_id -.endif - jmp return0 - + .import sp_find_device_type ; uint8_t sp_get_clock_id() _sp_get_clock_id: - ldx #$00 ; prep the return hi byte for C callers - lda _sp_clock_id - bne :+ ; if it's already set, just exit - - ; otherwise we need to try and find it from SP - jsr sp_find_clock - - ; return whatever was set in sp_clock - ldx #$00 - lda _sp_clock_id -: rts + lda #$13 + ldx #<_sp_clock_id + ldy #>_sp_clock_id + jmp sp_find_device_type .data -_sp_clock_id: .byte $00 +_sp_clock_id: .byte $00 diff --git a/apple2/src/bus/cc65/sp_find_cpm.s b/apple2/src/bus/cc65/sp_find_cpm.s index a1bef82..e57ef61 100644 --- a/apple2/src/bus/cc65/sp_find_cpm.s +++ b/apple2/src/bus/cc65/sp_find_cpm.s @@ -1,46 +1,14 @@ .export _sp_get_cpm_id .export _sp_cpm_id - .import _sp_find_device - - .import return0 - .import return1 - - .macpack cpu - -sp_find_cpm: - lda #$12 - jsr _sp_find_device - - bmi not_found - beq not_found - - sta _sp_cpm_id - jmp return1 - -not_found: -.if (.cpu .bitand ::CPU_ISET_65SC02) - stz _sp_cpm_id -.else - lda #$00 - sta _sp_cpm_id -.endif - jmp return0 - + .import sp_find_device_type ; uint8_t sp_get_cpm_id() _sp_get_cpm_id: - ldx #$00 ; prep the return hi byte for C callers - lda _sp_cpm_id - bne :+ ; if it's already set, just exit - - ; otherwise we need to try and find it from SP - jsr sp_find_cpm - - ; return whatever was set in sp_cpm - ldx #$00 - lda _sp_cpm_id -: rts + lda #$12 + ldx #<_sp_cpm_id + ldy #>_sp_cpm_id + jmp sp_find_device_type .data -_sp_cpm_id: .byte $00 +_sp_cpm_id: .byte $00 diff --git a/apple2/src/bus/cc65/sp_find_device.s b/apple2/src/bus/cc65/sp_find_device.s index 028bd5b..6511e88 100644 --- a/apple2/src/bus/cc65/sp_find_device.s +++ b/apple2/src/bus/cc65/sp_find_device.s @@ -1,4 +1,4 @@ - .export _sp_find_device + .export sp_find_device_type .export device_type_id .export device_count @@ -15,10 +15,13 @@ .import pusha .import negax .import return0 + .import return1 .include "sp.inc" + .include "zp.inc" -; int sp_find_device(uint8_t type_id); +; bool sp_find_device(); +; device_type_id contains the type id to search for ; where type_id is the internal fujinet device type_id: ; $10 = fujinet ; $11 = network @@ -28,8 +31,7 @@ ; $15 = modem ; $01 = floppy disk ; $02 = hard disk -_sp_find_device: - sta device_type_id ; save the type_id +sp_find_device: ; check if we've already run sp_init lda _sp_is_init bne have_init @@ -40,6 +42,7 @@ _sp_find_device: jsr _sp_init bne restore_type +return_error: ; not found, so return 0 as the network device, and is an error jmp return0 @@ -53,20 +56,12 @@ have_init: jsr _sp_status ; sp_status(0,0) fetches the device count beq status_ok_1 - - ; there was an error, negate A/X and return it - jmp negax - ; implicit RTS + bne return_error status_ok_1: - ldx #$00 ; prep the return value if it's going to be 0 lda _sp_payload ; device count in sp_payload[0] - beq :+ ; if the count is zero, just return 0, don't touch X as it's already 0 - bpl have_count - - ; byte extend the negative value into X, as A is already negative - dex -: rts + beq return_error ; if the count is <= 0, just return 0 + bmi return_error have_count: ; now repeatedly call sp_status(i, 3) to get the DIB status for the device, which contains name and its device type @@ -100,7 +95,46 @@ not_found_yet: beq device_loop ; we have checked all devices, non had the type we were looking for - jmp return0 + bcs return_error + +; A = device type (e.g. $11 = network) +; X/Y = location to save the id +sp_find_device_type: + sta device_type_id ; the type to search for + stx id_loc1 ; the low location of the address to save the id at + sty id_loc1 + 1 ; the high location of the address to save the id at + + lda $ffff ; don't use 0000, compiler thinks you want ZP! +id_loc1 = *-2 + + ; is it already set? + beq :+ + + ; the id was set in the indicated location, and is now in A, so return it, setting X to 0 for high byte for C callers + ldx #$00 + cmp #$00 ; force status bits for the return + rts + + ; no ID set, so fetch it, write x/y to the location the id needs to be saved to +: stx id_loc2 + sty id_loc2 + 1 + + jsr sp_find_device + + beq not_found + + ; found it from searching, so return success after setting the id + jsr set_id + jmp return1 + +not_found: + tax ; set x to 0 + +set_id: + sta $ffff +id_loc2 = *-2 + + rts .bss diff --git a/apple2/src/bus/cc65/sp_find_fuji.s b/apple2/src/bus/cc65/sp_find_fuji.s index 5523b3c..2f0baa8 100644 --- a/apple2/src/bus/cc65/sp_find_fuji.s +++ b/apple2/src/bus/cc65/sp_find_fuji.s @@ -1,7 +1,7 @@ .export _sp_get_fuji_id .export _sp_fuji_id - .import _sp_find_device + .import sp_find_device_type .import _sp_is_init .import _sp_payload .import _sp_status @@ -15,49 +15,28 @@ .macpack cpu -sp_find_fuji: +; uint8_t sp_get_fuji_id() +_sp_get_fuji_id: lda #$10 - jsr _sp_find_device + ldx #<_sp_fuji_id + ldy #>_sp_fuji_id + jsr sp_find_device_type - bmi not_found_by_id beq not_found_by_id - - sta _sp_fuji_id - jmp return1 + rts not_found_by_id: + tax ; set X to 0 ; if _sp_is_init is still 0, we didn't find the fujinet at all, so exit out lda _sp_is_init beq :+ - ; 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 - 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: - lda #$01 sta device_id_idx + device_loop: jsr pusha ; the current Device ID lda #$03 @@ -65,7 +44,6 @@ device_loop: 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 @@ -86,7 +64,7 @@ device_loop: ; found it, so return the current index ldx #$00 lda device_id_idx - rts + bne :+ not_found_yet: inc device_id_idx @@ -96,8 +74,11 @@ not_found_yet: beq device_loop ; we have checked all devices, non had the type we were looking for - jmp return0 + lda #$00 + tax +: sta _sp_fuji_id + rts .data _sp_fuji_id: .byte $00 diff --git a/apple2/src/bus/cc65/sp_find_modem.s b/apple2/src/bus/cc65/sp_find_modem.s index ebeeddb..c76e957 100644 --- a/apple2/src/bus/cc65/sp_find_modem.s +++ b/apple2/src/bus/cc65/sp_find_modem.s @@ -1,46 +1,14 @@ .export _sp_get_modem_id .export _sp_modem_id - .import _sp_find_device - - .import return0 - .import return1 - - .macpack cpu - -sp_find_modem: - lda #$15 - jsr _sp_find_device - - bmi not_found - beq not_found - - sta _sp_modem_id - jmp return1 - -not_found: -.if (.cpu .bitand ::CPU_ISET_65SC02) - stz _sp_modem_id -.else - lda #$00 - sta _sp_modem_id -.endif - jmp return0 - + .import sp_find_device_type ; uint8_t sp_get_modem_id() _sp_get_modem_id: - ldx #$00 ; prep the return hi byte for C callers - lda _sp_modem_id - bne :+ ; if it's already set, just exit - - ; otherwise we need to try and find it from SP - jsr sp_find_modem - - ; return whatever was set in sp_modem - ldx #$00 - lda _sp_modem_id -: rts + lda #$15 + ldx #<_sp_modem_id + ldy #>_sp_modem_id + jmp sp_find_device_type .data -_sp_modem_id: .byte $00 +_sp_modem_id: .byte $00 diff --git a/apple2/src/bus/cc65/sp_find_network.s b/apple2/src/bus/cc65/sp_find_network.s index 0134343..3ebd3fb 100644 --- a/apple2/src/bus/cc65/sp_find_network.s +++ b/apple2/src/bus/cc65/sp_find_network.s @@ -1,46 +1,14 @@ .export _sp_get_network_id .export _sp_network - .import _sp_find_device - - .import return0 - .import return1 - - .macpack cpu - -sp_find_network: - lda #$11 - jsr _sp_find_device - - bmi not_found - beq not_found - - sta _sp_network - jmp return1 - -not_found: -.if (.cpu .bitand ::CPU_ISET_65SC02) - stz _sp_network -.else - lda #$00 - sta _sp_network -.endif - jmp return0 - + .import sp_find_device_type ; uint8_t sp_get_network_id() _sp_get_network_id: - ldx #$00 ; prep the return hi byte for C callers - lda _sp_network - bne :+ ; if it's already set, just exit - - ; otherwise we need to try and find it from SP - jsr sp_find_network - - ; return whatever was set in sp_network - ldx #$00 - lda _sp_network -: rts + lda #$11 + ldx #<_sp_network + ldy #>_sp_network + jmp sp_find_device_type .data _sp_network: .byte $00 diff --git a/apple2/src/bus/cc65/sp_find_printer.s b/apple2/src/bus/cc65/sp_find_printer.s index 7d46318..93461e8 100644 --- a/apple2/src/bus/cc65/sp_find_printer.s +++ b/apple2/src/bus/cc65/sp_find_printer.s @@ -1,46 +1,14 @@ .export _sp_get_printer_id .export _sp_printer_id - .import _sp_find_device - - .import return0 - .import return1 - - .macpack cpu - -sp_find_printer: - lda #$14 - jsr _sp_find_device - - bmi not_found - beq not_found - - sta _sp_printer_id - jmp return1 - -not_found: -.if (.cpu .bitand ::CPU_ISET_65SC02) - stz _sp_printer_id -.else - lda #$00 - sta _sp_printer_id -.endif - jmp return0 - + .import sp_find_device_type ; uint8_t sp_get_printer_id() _sp_get_printer_id: - ldx #$00 ; prep the return hi byte for C callers - lda _sp_printer_id - bne :+ ; if it's already set, just exit - - ; otherwise we need to try and find it from SP - jsr sp_find_printer - - ; return whatever was set in sp_printer - ldx #$00 - lda _sp_printer_id -: rts + lda #$14 + ldx #<_sp_printer_id + ldy #>_sp_printer_id + jmp sp_find_device_type .data -_sp_printer_id: .byte $00 +_sp_printer_id: .byte $00 diff --git a/apple2/src/bus/cc65/sp_status_control_dispatch.s b/apple2/src/bus/cc65/sp_status_control_dispatch.s index 1824d9c..d7b92bb 100644 --- a/apple2/src/bus/cc65/sp_status_control_dispatch.s +++ b/apple2/src/bus/cc65/sp_status_control_dispatch.s @@ -72,7 +72,7 @@ sp_dispatch: ; the SP dispatch alters the return address by 3 bytes to skip the data below. ; it returs with any error codes. ; The dispatch address is altered in sp_init - jsr $0000 + jsr $ffff _sp_dispatch_address = *-2 dispatch_data: diff --git a/testing/bdd-testing/features/apple2/fn_network/invokers/test_sp_find_unmatched.s b/testing/bdd-testing/features/apple2/fn_network/invokers/test_sp_find_unmatched.s index 21a1d5f..27e2030 100644 --- a/testing/bdd-testing/features/apple2/fn_network/invokers/test_sp_find_unmatched.s +++ b/testing/bdd-testing/features/apple2/fn_network/invokers/test_sp_find_unmatched.s @@ -1,6 +1,6 @@ .export _main - .import _sp_find_device + .import sp_find_device .import _sp_init .import spe_should_fail_device_lookup @@ -9,7 +9,7 @@ .proc _main jsr _sp_init setax #unmatched_name - jmp _sp_find_device + jmp sp_find_device .endproc .data diff --git a/testing/bdd-testing/features/apple2/fn_network/sp_find_device_unmatched.feature b/testing/bdd-testing/features/apple2/fn_network/sp_find_device_unmatched.feature index 5be35ac..942ee43 100644 --- a/testing/bdd-testing/features/apple2/fn_network/sp_find_device_unmatched.feature +++ b/testing/bdd-testing/features/apple2/fn_network/sp_find_device_unmatched.feature @@ -13,6 +13,6 @@ Feature: library test - apple2 sp_find_device # number of devices in slot 1 is 6 from emulator And I expect to see _sp_payload equal 6 - # return from _sp_find_device is 0 when device does not match + # return from sp_find_device is 0 when device does not match And I expect register A equal 0 And I expect register X equal 0 diff --git a/version.txt b/version.txt index f4fa8fc..3208b09 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -4.6.1 \ No newline at end of file +4.6.2 \ No newline at end of file