From 7d885a9ce8669541578a7d28e0d8e87817a54715 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 21 Sep 2024 13:38:28 +0100 Subject: [PATCH] 4.7.2 fix apple2 device id detection bug, fix apple2gs clock implementation --- Changelog.md | 9 +++++ apple2/apple2-6502/bus/sp_find_device.s | 44 ++++++++++++++--------- apple2/apple2gs/fn_clock/clock_get_time.c | 6 ++-- apple2/apple2gs/fn_clock/clock_get_tz.c | 4 +-- version.txt | 2 +- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6434301..3edee0e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,15 @@ ## [Unreleased] +## [4.7.2] - 2024-09-22 + +- [apple2] fix finding device bug that was breaking network id and not setting correct device id +- [clock apple2gs] fix clock implementation + +I moved the apple2gs C code into the apple2 path, and tested apps against it. +Adds 160 bytes to the application vs ASM version, but does produce runnable applications. +This should now work with apple2gs. + ## [4.7.1] - 2024-09-21 - [clock] add apple2gs clock implementation (untested) diff --git a/apple2/apple2-6502/bus/sp_find_device.s b/apple2/apple2-6502/bus/sp_find_device.s index afc0374..c4c0bc7 100644 --- a/apple2/apple2-6502/bus/sp_find_device.s +++ b/apple2/apple2-6502/bus/sp_find_device.s @@ -3,7 +3,6 @@ .export device_type_id .export device_count .export _device_id_idx - .export tmp_orig_type .import _sp_cmdlist .import _sp_init @@ -35,20 +34,33 @@ sp_find_device: lda _sp_is_init bne have_init - ; 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 + ; no, so do it now, we first have to save some data about what we're currently searching for, as it gets overwritten searching for network device lda device_type_id - sta tmp_orig_type + pha + lda id_loc1 + pha + lda id_loc1 + 1 + pha jsr _sp_init - bne restore_type + sta tmp1 ; save the result + + ; restore the data we stashed + pla + sta id_loc1 + 1 + sta id_loc2 + 1 + pla + sta id_loc1 + sta id_loc2 + pla + sta device_type_id + + lda tmp1 ; restore the result + bne have_init return_error: ; not found, so return 0 as the network device, and is an error jmp return0 -restore_type: - lda tmp_orig_type - sta device_type_id - have_init: lda #$00 jsr pusha ; doesn't change A, so can be used to double up as both params @@ -102,6 +114,8 @@ 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 + stx id_loc2 + sty id_loc2 + 1 lda $ffff ; don't use 0000, compiler thinks you want ZP! id_loc1 = *-2 @@ -114,12 +128,8 @@ id_loc1 = *-2 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 - + ; no ID set, so fetch it +: jsr sp_find_device beq not_found ; found it from searching, so return the id after setting it @@ -138,7 +148,9 @@ id_loc2 = *-2 rts .bss +; the type of the device we are looking for device_type_id: .res 1 + +; temp variables device_count: .res 1 -_device_id_idx: .res 1 -tmp_orig_type: .res 1 \ No newline at end of file +_device_id_idx: .res 1 diff --git a/apple2/apple2gs/fn_clock/clock_get_time.c b/apple2/apple2gs/fn_clock/clock_get_time.c index 4151f7f..1def70d 100644 --- a/apple2/apple2gs/fn_clock/clock_get_time.c +++ b/apple2/apple2gs/fn_clock/clock_get_time.c @@ -11,10 +11,12 @@ uint8_t clock_get_time(uint8_t* tz, TimeFormat format) { uint8_t result; sp_get_clock_id(); + if (sp_clock_id == 0) return FN_ERR_IO_ERROR; + if (format >= 6) return FN_ERR_BAD_CMD; - result = sp_status(sp_clock_id, 'G'); - if (result == 0) return FN_ERR_IO_ERROR; + result = sp_status(sp_clock_id, format_cmds[format]); + if (result != 0) return FN_ERR_IO_ERROR; memcpy(tz, sp_payload, sp_count); return FN_ERR_OK; diff --git a/apple2/apple2gs/fn_clock/clock_get_tz.c b/apple2/apple2gs/fn_clock/clock_get_tz.c index 1dc9ef1..77f3229 100644 --- a/apple2/apple2gs/fn_clock/clock_get_tz.c +++ b/apple2/apple2gs/fn_clock/clock_get_tz.c @@ -4,14 +4,14 @@ #include "fujinet-clock.h" #include "fujinet-bus-apple2.h" -uint8_t clock_get_tz(uint8_t *tz) { +uint8_t clock_get_tz(char *tz) { uint8_t result; sp_get_clock_id(); if (sp_clock_id == 0) return FN_ERR_IO_ERROR; result = sp_status(sp_clock_id, 'G'); - if (result == 0) return FN_ERR_IO_ERROR; + if (result != 0) return FN_ERR_IO_ERROR; memcpy(tz, sp_payload, sp_count); return FN_ERR_OK; diff --git a/version.txt b/version.txt index cfacfe4..0b87099 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -4.7.1 \ No newline at end of file +4.7.2 \ No newline at end of file