From dc3170db98d9e44a88c66f0fb758f92e3a9aeb34 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Fri, 5 Nov 2021 22:48:04 +0000 Subject: [PATCH] Implement File/append flag. --- projects/examples/blank.tal | 2 +- projects/examples/demos/asma-piano.tal | 2 +- projects/examples/demos/drum-rack.tal | 2 +- projects/examples/demos/font.tal | 2 +- projects/examples/demos/piano.tal | 2 +- projects/examples/devices/file.load.tal | 2 +- projects/examples/devices/file.save.tal | 2 +- projects/examples/devices/file.tal | 2 +- projects/examples/gui/picture.tal | 2 +- projects/library/asma.tal | 3 +++ projects/software/asma.tal | 2 +- projects/software/calc.tal | 2 +- projects/software/launcher.tal | 2 +- src/devices/file.c | 4 ++-- src/devices/file.h | 2 +- src/uxncli.c | 2 +- src/uxnemu.c | 2 +- 17 files changed, 20 insertions(+), 17 deletions(-) diff --git a/projects/examples/blank.tal b/projects/examples/blank.tal index 24d1808..82f35a6 100644 --- a/projects/examples/blank.tal +++ b/projects/examples/blank.tal @@ -21,7 +21,7 @@ |60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] |b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] ( variables ) diff --git a/projects/examples/demos/asma-piano.tal b/projects/examples/demos/asma-piano.tal index a6ae192..d239a3f 100644 --- a/projects/examples/demos/asma-piano.tal +++ b/projects/examples/demos/asma-piano.tal @@ -2,7 +2,7 @@ |00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( vectors ) diff --git a/projects/examples/demos/drum-rack.tal b/projects/examples/demos/drum-rack.tal index 8c7c2d0..b371f8b 100644 --- a/projects/examples/demos/drum-rack.tal +++ b/projects/examples/demos/drum-rack.tal @@ -30,7 +30,7 @@ |70 @Midi [ &vector $2 &channel $1 ¬e $1 &velocity $1 ] |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/examples/demos/font.tal b/projects/examples/demos/font.tal index cfb1cf2..ec3579b 100644 --- a/projects/examples/demos/font.tal +++ b/projects/examples/demos/font.tal @@ -12,7 +12,7 @@ |00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 |20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 -|a0 @File &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 +|a0 @File &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ( variables ) diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal index 2baac75..2948b9e 100644 --- a/projects/examples/demos/piano.tal +++ b/projects/examples/demos/piano.tal @@ -27,7 +27,7 @@ |70 @Midi [ &vector $2 &channel $1 ¬e $1 &velocity $1 ] |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/examples/devices/file.load.tal b/projects/examples/devices/file.load.tal index 97372e5..429d16f 100644 --- a/projects/examples/devices/file.load.tal +++ b/projects/examples/devices/file.load.tal @@ -4,7 +4,7 @@ |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/examples/devices/file.save.tal b/projects/examples/devices/file.save.tal index 0d24c50..f3ff575 100644 --- a/projects/examples/devices/file.save.tal +++ b/projects/examples/devices/file.save.tal @@ -3,7 +3,7 @@ ( devices ) |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/examples/devices/file.tal b/projects/examples/devices/file.tal index 8f32eba..083de14 100644 --- a/projects/examples/devices/file.tal +++ b/projects/examples/devices/file.tal @@ -8,7 +8,7 @@ |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |10 @Console [ &pad $8 &write $1 ] |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/examples/gui/picture.tal b/projects/examples/gui/picture.tal index c7ea9c1..c50f072 100644 --- a/projects/examples/gui/picture.tal +++ b/projects/examples/gui/picture.tal @@ -7,7 +7,7 @@ |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/library/asma.tal b/projects/library/asma.tal index b41b0c6..50aed77 100644 --- a/projects/library/asma.tal +++ b/projects/library/asma.tal @@ -24,6 +24,9 @@ ) @asma-assemble-file ( src-filename* dest-filename* -- ) + #01 .File/append DEO + DUP2 .File/name DEO2 + #01 .File/delete DEO ;asma/dest-filename STA2 ;asma/src-filename STA2 ;asma-init-first-pass JSR2 diff --git a/projects/software/asma.tal b/projects/software/asma.tal index d6b2805..0fcaaeb 100644 --- a/projects/software/asma.tal +++ b/projects/software/asma.tal @@ -2,7 +2,7 @@ |00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( vectors ) diff --git a/projects/software/calc.tal b/projects/software/calc.tal index d080849..ee40950 100644 --- a/projects/software/calc.tal +++ b/projects/software/calc.tal @@ -35,7 +35,7 @@ |30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 ] +|a0 @File [ &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 ] ( variables ) diff --git a/projects/software/launcher.tal b/projects/software/launcher.tal index b374d76..150a632 100644 --- a/projects/software/launcher.tal +++ b/projects/software/launcher.tal @@ -22,7 +22,7 @@ |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |80 @Controller [ &vector $2 &button $1 &key $1 ] |90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] -|a0 @File &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 +|a0 @File &vector $2 &name $2 &length $2 &success $2 &load $2 &save $2 &stat $2 &delete $1 &append $1 |b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] ( variables ) diff --git a/src/devices/file.c b/src/devices/file.c index 1409cbc..1f8a4d4 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -107,11 +107,11 @@ file_read(void *dest, Uint16 len) } Uint16 -file_write(void *src, Uint16 len) +file_write(void *src, Uint16 len, Uint8 flags) { if(state != FILE_WRITE) { reset(); - if((f = fopen(current_filename, "ab")) != NULL) + if((f = fopen(current_filename, (flags & 0x01) ? "ab" : "wb")) != NULL) state = FILE_WRITE; } if(state == FILE_WRITE) diff --git a/src/devices/file.h b/src/devices/file.h index 7fd3dfa..ce45c1c 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -12,6 +12,6 @@ WITH REGARD TO THIS SOFTWARE. void file_prepare(void *filename); Uint16 file_read(void *dest, Uint16 len); -Uint16 file_write(void *src, Uint16 len); +Uint16 file_write(void *src, Uint16 len, Uint8 flags); Uint16 file_stat(void *dest, Uint16 len); Uint16 file_delete(); diff --git a/src/uxncli.c b/src/uxncli.c index 5407e85..48f45bd 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -87,7 +87,7 @@ file_deo(Device *d, Uint8 port) poke16(d->dat, 0x6, file_read(&d->mem[peek16(d->dat, 0x8)], peek16(d->dat, 0x4))); break; case 0xb: - poke16(d->dat, 0x6, file_write(&d->mem[peek16(d->dat, 0xa)], peek16(d->dat, 0x4))); + poke16(d->dat, 0x6, file_write(&d->mem[peek16(d->dat, 0xa)], peek16(d->dat, 0x4), d->dat[0xf])); break; case 0xd: poke16(d->dat, 0x6, file_stat(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0x4))); diff --git a/src/uxnemu.c b/src/uxnemu.c index 28e2fff..498a497 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -379,7 +379,7 @@ file_deo(Device *d, Uint8 port) poke16(d->dat, 0x6, file_read(&d->mem[peek16(d->dat, 0x8)], peek16(d->dat, 0x4))); break; case 0xb: - poke16(d->dat, 0x6, file_write(&d->mem[peek16(d->dat, 0xa)], peek16(d->dat, 0x4))); + poke16(d->dat, 0x6, file_write(&d->mem[peek16(d->dat, 0xa)], peek16(d->dat, 0x4), d->dat[0xf])); break; case 0xd: poke16(d->dat, 0x6, file_stat(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0x4)));