Skip to content

Commit

Permalink
(2.1.4) Fix network_json_query on a2 to remove cr/lf/9b as last char
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
markjfisher committed Jan 6, 2024
1 parent 3a38805 commit e294d91
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 89 deletions.
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apple2/src/fn_fuji/inc/sp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions apple2/src/fn_fuji/inc/sp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion apple2/src/fn_fuji/sp_clr_payload.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions apple2/src/fn_fuji/sp_data.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion apple2/src/fn_fuji/sp_find_device.s
Original file line number Diff line number Diff line change
Expand Up @@ -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 :+
Expand Down
10 changes: 6 additions & 4 deletions apple2/src/fn_fuji/sp_init.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apple2/src/fn_io/fn_io_base64_encode_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
47 changes: 42 additions & 5 deletions apple2/src/fn_network/network_json_query.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
71 changes: 0 additions & 71 deletions atari/src/fn_network/network_read_asm.s

This file was deleted.

35 changes: 35 additions & 0 deletions common/src/hex_dump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

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");
}
}
}
8 changes: 7 additions & 1 deletion fujinet-network-apple2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@
// 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;

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4

0 comments on commit e294d91

Please sign in to comment.