From aba437e5a2783421a6c25e17e426fc59afb8909c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 14 Oct 2020 22:33:49 +0200 Subject: [PATCH] diskio load and save use kernel routines for load and save, and don't bother with SEQ files --- compiler/res/prog8lib/diskio.p8 | 91 ++++++++++++++++----------------- examples/test.p8 | 13 ++++- examples/textelite.p8 | 2 +- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/compiler/res/prog8lib/diskio.p8 b/compiler/res/prog8lib/diskio.p8 index 5a11904eb..67f133728 100644 --- a/compiler/res/prog8lib/diskio.p8 +++ b/compiler/res/prog8lib/diskio.p8 @@ -77,63 +77,60 @@ io_error: } - str filename = "0:??????????????????????????????????????" - sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> byte { - ubyte flen = strlen(filenameptr) - filename[0] = '0' - filename[1] = ':' - memcopy(filenameptr, &filename+2, flen) - memcopy(",s,w", &filename+2+flen, 5) - c64.SETNAM(flen+6, filename) - c64.SETLFS(1, drivenumber, 1) - void c64.OPEN() - if_cs - goto io_error + c64.SETNAM(strlen(filenameptr), filenameptr) + c64.SETLFS(1, drivenumber, 0) + uword end_address = address + size - c64.CHKOUT(1) - if_cs - goto io_error + %asm {{ + lda address + sta P8ZP_SCRATCH_W1 + lda address+1 + sta P8ZP_SCRATCH_W1+1 + stx P8ZP_SCRATCH_REG + lda # byte { - ubyte flen = strlen(filenameptr) - filename[0] = '0' - filename[1] = ':' - memcopy(filenameptr, &filename+2, flen) - memcopy(",s,r", &filename+2+flen, 5) - c64.SETNAM(flen+6, filename) - c64.SETLFS(1, drivenumber, 2) - void c64.OPEN() - if_cs - goto io_error - void c64.CHKIN(1) - if_cs - goto io_error + sub load(ubyte drivenumber, uword filenameptr, uword address_override) -> uword { + c64.SETNAM(strlen(filenameptr), filenameptr) + ubyte secondary = 1 + uword end_of_load = 0 + if address_override + secondary = 0 + c64.SETLFS(1, drivenumber, secondary) + %asm {{ + stx P8ZP_SCRATCH_REG + lda #0 + ldx address_override + ldy address_override+1 + jsr c64.LOAD + bcs + + stx end_of_load + sty end_of_load+1 ++ ldx P8ZP_SCRATCH_REG + }} - do { - @(address) = c64.CHRIN() - address++ - } until c64.READST() + if end_of_load + return end_of_load - address_override -io_error: - c64.CLRCHN() - c64.CLOSE(1) - - ubyte status = c64.READST() - return status==0 or status==64 + return 0 } + + str filename = "0:??????????????????????????????????????" + sub delete(ubyte drivenumber, uword filenameptr) { ; -- delete a file on the drive ubyte flen = strlen(filenameptr) diff --git a/examples/test.p8 b/examples/test.p8 index 9888beeac..f7f4ac090 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,12 +1,23 @@ %import textio %import diskio %zeropage basicsafe - +%option no_sysinit main { sub start() { + txt.print("saving...") + diskio.delete(8, "data.bin") + if diskio.save(8, "data.bin", $0400, 40*25) { + txt.clear_screenchars('*') + txt.print("loading...") + uword size = diskio.load(8, "data.bin", $0400) + txt.print_uwhex(size, true) + txt.chrout('\n') + } else txt.print("io error\n") + + testX() } diff --git a/examples/textelite.p8 b/examples/textelite.p8 index 6564ad9b9..4f9fe43a4 100644 --- a/examples/textelite.p8 +++ b/examples/textelite.p8 @@ -65,7 +65,7 @@ main { } trader { - str Savegame = "txtel.savegame" + str Savegame = "↑commander.save" str input = "??????????" ubyte num_chars