From af3dcaf5fb68f3a7bbcbaa24c59d7ed52aca61da Mon Sep 17 00:00:00 2001 From: Joppe Blondel Date: Fri, 9 Oct 2026 17:07:17 +0200 Subject: [PATCH] csave-cload roundtrip irl works --- apps/basic/basic.asm | 47 +++++++++++++++++++++++++++++++++++++++++--- memory.mk | 4 ++-- tape.asm | 10 ++++++---- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/apps/basic/basic.asm b/apps/basic/basic.asm index bbaf2e3..0cc7d6f 100644 --- a/apps/basic/basic.asm +++ b/apps/basic/basic.asm @@ -4815,10 +4815,10 @@ CSAVEB: inc hl ; skip # inc hl call BYTESTOBLOCKS push bc - ld a,b ; nr of blocks low byte + ld a,c ; nr of blocks low byte ld (hl),a inc hl - ld a,c ; nr of blocks high byte + ld a,b ; nr of blocks high byte ld (hl),a inc hl push hl @@ -4834,6 +4834,7 @@ CSAVEB: inc hl ; skip # inc hl push hl dec e ; count down str len + ld a,e cp 0 jr nz,1$ ; repeat for the whole string exx @@ -4843,9 +4844,49 @@ CSAVEB: inc hl ; skip # inc hl ; Header block complete (rest of block is accepted garbage) call BIOS_CAS_WRITE_BLOCK - + ld a,'.' + call OUTC + call BIOS_CAS_WRITE_BLOCK + ld a,'.' + call OUTC + ld a,250 + call BIOS_DELAY_MS + ld a,250 + call BIOS_DELAY_MS + ld a,250 + call BIOS_DELAY_MS ; add a 750ms delay pop bc ; get back block count pop de ; get back start address + ld a,b + or c + jr z,3$ ; no data blocks for a zero length +2$: + ; load data into buffer + push bc + call BIOS_CAS_GET_BUFFER + ld bc,128 ; block size + ld a,0 ; raw type + ld (hl),a + inc hl + ex de,hl ; hl=src,de=dest + ldir ; copy the bytes + ex de,hl ; de back to being the src addr + call BIOS_CAS_WRITE_BLOCK + ld a,'.' + call OUTC + call BIOS_CAS_WRITE_BLOCK + ld a,'.' + call OUTC + pop bc + dec bc + ld a,b + or c + jr nz,2$ ; repeat if not done +3$: + ; All blocks are written + + ld hl,CLCLRF + call PRS pop hl pop de diff --git a/memory.mk b/memory.mk index 85502b0..9a4dadd 100644 --- a/memory.mk +++ b/memory.mk @@ -14,8 +14,8 @@ BIOS_ROM_START := 0x0080 BIOS_ROM_SIZE := 0x0780 BASIC_ROM_START := 0x0800 -BASIC_ROM_SIZE := 0x2000 +BASIC_ROM_SIZE := 0x2200 BIOS_RAM_START := 0xc000 BIOS_WP_RAM_START := 0xc800 -BASIC_RAM_START := 0xcc00 +BASIC_RAM_START := 0xce00 diff --git a/tape.asm b/tape.asm index 3e12d5a..486c304 100644 --- a/tape.asm +++ b/tape.asm @@ -636,7 +636,7 @@ gen_byte: ; ------------------------------------------------------- gen_leader: ; short leader - ld b,50 ; generate 50 short pulses + ld b,100 ; generate 100 short pulses 1$: call gen_short dec b @@ -644,7 +644,7 @@ gen_leader: cp 0 jr nz,1$ ; repeat if not done ; long leader - ld b,50 ; generate 50 long pulses + ld b,100 ; generate 100 long pulses 2$: call gen_long dec b @@ -669,8 +669,9 @@ gen_leader: ; Writes the block stored in the block buffer ; ------------------------------------------------------- write_block: - push de push bc + push de + push hl ; calculate the crc16 over the block ld hl, BLOCK_BUFFER ld a, BLOCK_SIZE-2 ; dont use crc value in block @@ -706,8 +707,9 @@ write_block: ld a,200 call delay_ms - pop bc + pop hl pop de + pop bc ret ; ------------------------------------------------------- ; Strings