From e294d910d8cb4eaefc40b871df3b819b00ca4a53 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 4 Jan 2024 19:32:46 +0000 Subject: [PATCH] (2.1.4) Fix network_json_query on a2 to remove cr/lf/9b as last char Also reduce sp_payload to 512 from 1024, I don't think anything uses more than that, might bite me on the arse, so see you in the future! --- Changelog.md | 10 +++ apple2/src/fn_fuji/inc/sp.h | 2 + apple2/src/fn_fuji/inc/sp.inc | 2 + apple2/src/fn_fuji/sp_clr_payload.s | 3 +- apple2/src/fn_fuji/sp_data.s | 6 +- apple2/src/fn_fuji/sp_find_device.s | 2 +- apple2/src/fn_fuji/sp_init.s | 10 +-- apple2/src/fn_io/fn_io_base64_encode_input.c | 2 +- apple2/src/fn_network/network_json_query.s | 47 ++++++++++-- atari/src/fn_network/network_read_asm.s | 71 ------------------- common/src/hex_dump.c | 35 +++++++++ fujinet-network-apple2.h | 8 ++- .../apple2/fn_network/smartport/sp_emulator.s | 2 +- version.txt | 2 +- 14 files changed, 113 insertions(+), 89 deletions(-) delete mode 100644 atari/src/fn_network/network_read_asm.s create mode 100644 common/src/hex_dump.c diff --git a/Changelog.md b/Changelog.md index 4ffcc3f..8bdbcbd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,16 @@ ## [Unreleased] +## [2.1.4] - 2024-01-06 + +### Fixed + +- [apple2] network_json_query removes any trailing CR/LF/0x9b in results as last character + +### Changed + +- [apple2] reduced payload memory from 1024 to 512. + ## [2.1.3] - 2024-01-03 ### Changed diff --git a/apple2/src/fn_fuji/inc/sp.h b/apple2/src/fn_fuji/inc/sp.h index 8762b4e..3ecd812 100644 --- a/apple2/src/fn_fuji/inc/sp.h +++ b/apple2/src/fn_fuji/inc/sp.h @@ -20,4 +20,6 @@ #define SP_ERR_NON_FATAL50 (0x50) // ; DEVICE SPECIFIC WARNING #define SP_ERR_NON_FATAL7F (0x7F) // ; DEVICE SPECIFIC WARNING +#define SP_PAYLOAD_SIZE (512) + #endif /* SP_H */ \ No newline at end of file diff --git a/apple2/src/fn_fuji/inc/sp.inc b/apple2/src/fn_fuji/inc/sp.inc index 0430ec3..c5851fa 100644 --- a/apple2/src/fn_fuji/inc/sp.inc +++ b/apple2/src/fn_fuji/inc/sp.inc @@ -31,3 +31,5 @@ SP_ERR_DEV_SPECF := $3F ; SP_ERR_RESERVED $40-$4F SP_ERR_NON_FATAL50 := $50 SP_ERR_NON_FATAL7F := $7F + +SP_PAYLOAD_SIZE := 512 \ No newline at end of file diff --git a/apple2/src/fn_fuji/sp_clr_payload.s b/apple2/src/fn_fuji/sp_clr_payload.s index 246adfb..081a418 100644 --- a/apple2/src/fn_fuji/sp_clr_payload.s +++ b/apple2/src/fn_fuji/sp_clr_payload.s @@ -5,11 +5,12 @@ .import pushax .include "macros.inc" + .include "sp.inc" ; void sp_clr_payload(); .proc _sp_clr_payload pushax #_sp_payload - setax #$400 + setax #SP_PAYLOAD_SIZE jmp _bzero .endproc \ No newline at end of file diff --git a/apple2/src/fn_fuji/sp_data.s b/apple2/src/fn_fuji/sp_data.s index 3151519..ff8100b 100644 --- a/apple2/src/fn_fuji/sp_data.s +++ b/apple2/src/fn_fuji/sp_data.s @@ -6,11 +6,12 @@ .export _sp_is_init .export _sp_payload + .include "sp.inc" + .data ; has the init routine been run? _sp_is_init: .byte 0 - .bss _sp_dest: .res 1 @@ -19,5 +20,4 @@ _sp_count: .res 2 _sp_dispatch_fn: .res 2 _sp_cmdlist: .res 10 -; can this be reduced in size? not sure much more than 512 is used in library -_sp_payload: .res 1024 +_sp_payload: .res SP_PAYLOAD_SIZE diff --git a/apple2/src/fn_fuji/sp_find_device.s b/apple2/src/fn_fuji/sp_find_device.s index 898ffbe..bd57af1 100644 --- a/apple2/src/fn_fuji/sp_find_device.s +++ b/apple2/src/fn_fuji/sp_find_device.s @@ -20,7 +20,7 @@ .proc _sp_find_device axinto ptr1 ; the device name we're looking for - ; find the device count - do we need to keep doing this? + ; find the device count by sending 0/0 status request pusha #$00 ; doubles up as both parameters jsr _sp_status beq :+ diff --git a/apple2/src/fn_fuji/sp_init.s b/apple2/src/fn_fuji/sp_init.s index ce39f77..0b8d2a4 100644 --- a/apple2/src/fn_fuji/sp_init.s +++ b/apple2/src/fn_fuji/sp_init.s @@ -63,15 +63,17 @@ @found_sp: ; set _sp_dispatch_fn address while we have the correct slot in ptr1 + ; first copy it into ptr2, as we need to keep the original ptr1 for next loop if this card fails. + mwa ptr1, ptr2 ldy #$ff - lda (ptr1), y ; _sp_dispatch vector is this value +3 + lda (ptr2), y ; _sp_dispatch vector is this value +3 clc adc #$03 - adw1 ptr1, a ; move ptr1 to _sp_dispatch address, and store it - mwa ptr1, _sp_dispatch_fn + adw1 ptr2, a ; move ptr1 to _sp_dispatch address, and store it + mwa ptr2, _sp_dispatch_fn ; does this device have a NETWORK adapter? - ; first save X which is the slot ID + ; first save X which is our counter for number of devices tested so far txa pha diff --git a/apple2/src/fn_io/fn_io_base64_encode_input.c b/apple2/src/fn_io/fn_io_base64_encode_input.c index 6330e0d..0087b87 100644 --- a/apple2/src/fn_io/fn_io_base64_encode_input.c +++ b/apple2/src/fn_io/fn_io_base64_encode_input.c @@ -11,7 +11,7 @@ uint8_t fn_io_base64_encode_input(char *s, uint16_t len) // 0,1 : length // 2+ : string - if (len > MAX_SP_PAYLOAD) return 1; + if (len > MAX_DATA_LEN) return 1; strncpy(sp_payload, s, len); return sp_control(0, 0xD0); diff --git a/apple2/src/fn_network/network_json_query.s b/apple2/src/fn_network/network_json_query.s index b1386ff..d48d7b1 100644 --- a/apple2/src/fn_network/network_json_query.s +++ b/apple2/src/fn_network/network_json_query.s @@ -4,7 +4,6 @@ .import _fn_device_error .import _fn_error .import _memcpy - .import _sp_clr_payload .import _sp_control .import _sp_network .import _sp_payload @@ -14,12 +13,14 @@ .import _strncpy .import incsp2 .import incsp4 - .import popa .import popax .import pusha .import pushax .import return0 + ; .import _sp_clr_payload + ; .import _hd + .include "sp.inc" .include "macros.inc" .include "zp.inc" @@ -29,7 +30,7 @@ .proc _network_json_query axinto tmp5 ; save string output location - jsr _sp_clr_payload ; calls bzero, so trashes p1/2/3 + ; jsr _sp_clr_payload ; calls bzero, so trashes p1/2/3 ldy #$00 sty _fn_device_error @@ -64,7 +65,7 @@ setax _sp_payload ; length from payload[0..1] jsr _strncpy ; trashes ptr1-2, but we don't need ptr1 anymore, returns dest - ;; NOT REQUIRED - we have zero'd whole of sp_payload previous to the strncpy + ;; NOT REQUIRED ; ; add a 0 to end of query string ; axinto ptr1 ; move sp_payload+2 location into ptr1 ; adw ptr1, _sp_payload ; increment ptr1 by length of query string @@ -124,10 +125,46 @@ not_empty: setax ptr4 ; len jsr _memcpy ; doesn't touch ptr4. + ; ---------------------------------------------- + ; DEBUG hex dump the retruned string. + ; pushax tmp5 + ; pushax ptr4 + + ; pushax tmp5 + ; setax ptr4 ; length + ; jsr _hd + + ; popax ptr4 + ; popax tmp5 + ; ---------------------------------------------- + ; nul terminate the string adw tmp5, ptr4 ; set tmp5 to end of string - sbw1 tmp5, #$01 ; remove 1 for the 0x9b char at the end of the result + sbw1 tmp5, #$01 + + ; ---------------------------------------------- + ; pushax tmp5 + + ; pushax tmp5 + ; setax #$08 + ; jsr _hd + + ; popax tmp5 + ; ---------------------------------------------- + + ; check if last char is 9b/0d/0a, if it is not, move on 1 char before nul terminating ldy #$00 + lda (tmp5), y + cmp #$9b + beq @skip_add + cmp #$0d + beq @skip_add + cmp #$0a + beq @skip_add + + adw1 tmp5, #$01 + +@skip_add: tya sta (tmp5), y diff --git a/atari/src/fn_network/network_read_asm.s b/atari/src/fn_network/network_read_asm.s deleted file mode 100644 index a33da62..0000000 --- a/atari/src/fn_network/network_read_asm.s +++ /dev/null @@ -1,71 +0,0 @@ - .export _network_readX - - .import _fn_device_error - .import _fn_network_bw - .import _fn_network_conn - .import _fn_network_error - .import _network_status_unit - .import _network_unit - .import _sio_read - .import popax - .import pusha - .import pushax - - .include "fujinet-network.inc" - .include "device.inc" - .include "zp.inc" - .include "macros.inc" - -; uint8_t network_read(char* devicespec, uint8_t *buf, uint16_t len) - -; TODO: Work out LARGE transfers, like apple2 does in 512 byte chunks. Or does SIO allow single large chunks? - -_network_readX: - axinto tmp2 ; len, tmp2/3 - - ldy #$00 - sty _fn_device_error - - popax ptr4 ; buf - jsr popax ; device spec, only need unit from it - jsr _network_unit ; unit - sta tmp1 - - ; is the length 0? - lda tmp2 - ora tmp3 - bne :+ - - ; 0 bytes specified, return an error - ldx #$00 - lda #FN_ERR_BAD_CMD - rts - - ; ------------------------------------------------------------------------------------------------------------- - ; DECIDE ACTUAL COUNT, GET BYTES AVAILABLE - ; ------------------------------------------------------------------------------------------------------------- - -: pusha tmp1 ; unit - pushax #_fn_network_bw ; bytes waiting location - pushax #_fn_network_conn ; connection status - setax #_fn_network_error ; network error - jsr _network_status_unit - - lda tmp3 ; hi byte of length asked for - cmp _fn_network_bw+1 ; compare with the hi byte of bytes available - bne :+ ; we don't need to compare anything else if they are different - lda tmp2 ; lo byte of length asked for - cmp _fn_network_bw ; lo byte of bytes available -: bcc lower ; len < bytes waiting, so can use it for read count - - mwa _fn_network_bw, tmp2 ; only use BW count, as it's lower than len - bcs :+ - -lower: - ; ------------------------------------------------------------------------------------------------------------- - ; PERFORM READ - ; ------------------------------------------------------------------------------------------------------------- -: pusha tmp1 ; unit - pushax ptr4 ; buffer - setax tmp2 ; length - jmp _sio_read diff --git a/common/src/hex_dump.c b/common/src/hex_dump.c new file mode 100644 index 0000000..70d0ce8 --- /dev/null +++ b/common/src/hex_dump.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +void hd(char* data, int size) { + int i = 0; + int j = 0; + int p = 0; + int start = 0; + int padding = 0; + char c; + + for (i = 0; i < size; i++) { + printf("%02x ", (unsigned char)data[i]); + + if ((i + 1) % 8 == 0 || i == size - 1) { + padding = ((i + 1) % 8) ? (8 - (i + 1) % 8) : 0; + for (p = 0; p < padding; p++) { + printf(" "); // for alignment + } + printf(" | "); + start = i - (i % 8); + for (j = start; j <= i; j++) { + c = data[j]; + if (isprint((unsigned char)c)) { + printf("%c", c); + } else { + printf("."); + } + } + printf("\n"); + } + } +} \ No newline at end of file diff --git a/fujinet-network-apple2.h b/fujinet-network-apple2.h index 3789668..eddb952 100644 --- a/fujinet-network-apple2.h +++ b/fujinet-network-apple2.h @@ -12,7 +12,7 @@ // These are for C files to be able to access ASM functions, and values // that are internal and not exposed in the normal fujinet-network.h header -#define MAX_SP_PAYLOAD (1024) +#define MAX_DATA_LEN (767) // The id of the network device extern uint8_t sp_network; @@ -20,6 +20,12 @@ extern uint8_t sp_network; // the general payload buffer extern uint8_t sp_payload[]; +// the dispatch function used for doing SP calls for a particular card +extern uint8_t sp_dispatch_fn[2]; + +// count of bytes the status request returned +extern uint16_t sp_count; + void sp_clr_payload(); int8_t sp_status(uint8_t dest, uint8_t statcode); int8_t sp_control(uint8_t dest, uint8_t ctrlcode); diff --git a/testing/bdd-testing/features/apple2/fn_network/smartport/sp_emulator.s b/testing/bdd-testing/features/apple2/fn_network/smartport/sp_emulator.s index 96d4db2..c86966d 100644 --- a/testing/bdd-testing/features/apple2/fn_network/smartport/sp_emulator.s +++ b/testing/bdd-testing/features/apple2/fn_network/smartport/sp_emulator.s @@ -79,7 +79,7 @@ sp_emulator: ; where sp_cmdList holds: ; db command_count - number of bytes in the cmdList that are relevant ; db dest - see table below for dest/unit values. 1 == fujinet, etc. - ; dw sp_payload - always address of payload array (1024) + ; dw sp_payload - always address of payload array (767) ; ... various additional bytes depending on the command ; ; commands: diff --git a/version.txt b/version.txt index abae0d9..c346e7a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.1.3 \ No newline at end of file +2.1.4 \ No newline at end of file