uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 142d046b9bf9e933cabd0e7eaa0c8bc23a5be6da
parent 9851e7f6218f2b1e5b60fce83482e7f97a02a062
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sun,  7 Nov 2021 14:31:37 -0500

Merge branch 'main' of git.sr.ht:~rabbits/uxn

Diffstat:
Mprojects/examples/blank.tal | 2+-
Mprojects/examples/demos/asma-piano.tal | 8++++----
Mprojects/examples/demos/drum-rack.tal | 4++--
Mprojects/examples/demos/font.tal | 8++++----
Mprojects/examples/demos/piano.tal | 2+-
Mprojects/examples/devices/file.load.tal | 4++--
Mprojects/examples/devices/file.save.tal | 4++--
Mprojects/examples/devices/file.tal | 6+++---
Mprojects/examples/gui/picture.tal | 4++--
Mprojects/library/asma.tal | 2+-
Mprojects/library/file-read-chunks.tal | 8++++----
Mprojects/library/load-rom.tal | 4++--
Mprojects/software/asma.tal | 2+-
Mprojects/software/calc.tal | 4++--
Mprojects/software/launcher.tal | 4++--
Msrc/devices/file.c | 20+++++++++-----------
16 files changed, 42 insertions(+), 44 deletions(-)

diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |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 @@ -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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( vectors ) @@ -37,12 +37,12 @@ Load the output ROM over the currently running program, almost as if we loaded the ROM with uxnemu directly! - It's not a totally pristine environment, as File/load doesn't zero out + It's not a totally pristine environment, as File/read doesn't zero out memory beyond the end of the file. So if the assembled program assumes that all memory above it is zero, it may misbehave. Asma itself doesn't use the zero page, but this example code writes a - DEO2 instruction to 0x00ff. In order to execute File/load and have the + DEO2 instruction to 0x00ff. In order to execute File/read and have the CPU continue at memory location 0x0100, we write the final DEO2 instruction there and jump there as our final act. @@ -52,7 +52,7 @@ ) ;&dest-file .File/name DEO2 #ff00 .File/length DEO2 - #0100 .File/load + #0100 .File/read LIT DEO2 #00ff STA LIT BRK #0100 STA #00ff JMP2 diff --git a/projects/examples/demos/drum-rack.tal b/projects/examples/demos/drum-rack.tal @@ -30,7 +30,7 @@ |70 @Midi [ &vector $2 &channel $1 &note $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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) @@ -137,7 +137,7 @@ ( load sample ) OVR TOS #0019 ** ;pad-path ++ .File/name DEO2 OVR #04 / #40 SFT .Audio0/length + DEI2 .File/length DEO2 - OVR TOS 2** ;pad-addr ++ LDA2 .File/load DEO2 + OVR TOS 2** ;pad-addr ++ LDA2 .File/read DEO2 ( draw pad ) OVR #01 ;draw-pad JSR2 ( draw mixer ) diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 +|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ( variables ) @@ -30,21 +30,21 @@ ( load font ) #4900 .File/length DEO2 ;font-path-large .File/name DEO2 - ;font-data .File/load DEO2 + ;font-data .File/read DEO2 ( draw label ) #0020 #0020 ;title #01 ;draw-uf3 JSR2 ( load font ) #2100 .File/length DEO2 ;font-path-medium .File/name DEO2 - ;font-data .File/load DEO2 + ;font-data .File/read DEO2 ( draw label ) #0020 #0048 ;body #02 ;draw-uf2 JSR2 ( load font ) #0900 .File/length DEO2 ;font-path-small .File/name DEO2 - ;font-data .File/load DEO2 + ;font-data .File/read DEO2 ( draw label ) #0030 #00b8 ;footer #03 ;draw-uf1 JSR2 diff --git a/projects/examples/demos/piano.tal b/projects/examples/demos/piano.tal @@ -27,7 +27,7 @@ |70 @Midi [ &vector $2 &channel $1 &note $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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) @@ -20,7 +20,7 @@ ( load contents from file ) #1000 .File/length DEO2 ;filename .File/name DEO2 - ;contents .File/load DEO2 + ;contents .File/read DEO2 .File/success DEI2 ORA ,&success JCN ( failed to read: bright yellow background ) diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) @@ -19,7 +19,7 @@ ( save contents to file ) ;contents/end ;contents SUB2 .File/length DEO2 ;filename .File/name DEO2 - ;contents .File/save DEO2 + ;contents .File/write DEO2 .File/success DEI2 ORA ,&success JCN ( failed to write: bright yellow background ) diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) @@ -26,7 +26,7 @@ ( load file ) #1000 .File/length DEO2 ;srcpath .File/name DEO2 - MEMORY .File/load DEO2 + MEMORY .File/read DEO2 .File/success DEI2 ORA ;on-success JCN2 @@ -58,7 +58,7 @@ BRK ( save file ) #1000 .File/length DEO2 ;dstpath .File/name DEO2 - MEMORY .File/save DEO2 + MEMORY .File/write DEO2 BRK diff --git a/projects/examples/gui/picture.tal b/projects/examples/gui/picture.tal @@ -1,13 +1,13 @@ ( GUI Picture ) %RTN { JMP2r } -%LOAD-IMAGE { .File/length DEO2 .File/name DEO2 ;image .File/load DEO2 } +%LOAD-IMAGE { .File/length DEO2 .File/name DEO2 ;image .File/read DEO2 } ( devices ) |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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) diff --git a/projects/library/asma.tal b/projects/library/asma.tal @@ -509,7 +509,7 @@ include projects/library/binary-tree.tal @asma-flush-to-file ( len* -- ) .File/length DEO2 ;asma/dest-filename LDA2 .File/name DEO2 - ;asma-write-buffer .File/save DEO2 + ;asma-write-buffer .File/write DEO2 JMP2r @asma-flush-to-console ( len* -- ) diff --git a/projects/library/file-read-chunks.tal b/projects/library/file-read-chunks.tal @@ -5,7 +5,7 @@ *** CAUTION: this library is deprecated! *** Chunked file reads are now possible in the File device directly: just use -File/load or File/save multiple times. This library exists for compatibility to +File/read or File/write multiple times. This library exists for compatibility to keep asma going until it gets a more substantial rewrite. *** @@ -32,7 +32,7 @@ don't know the file size. Copes with files up to 4,294,967,295 bytes long. ,ffwd JSR SWP2 ( F* B* U* / FN* SZ* OH* OL* ) ROT2k NIP2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) - OVR2 .File/load DEO2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) + OVR2 .File/read DEO2 ( F* B* U* B* F* / FN* SZ* OH* OL* ) .File/success DEI2 SWP2 ( F* B* U* B* length* F* / FN* SZ* OH* OL* ) JSR2 ( F* B* U'* done-up-to* / FN* SZ* OH* OL* ) ROT2 SWP2 ( F* U'* B* done-up-to* / FN* SZ* OH* OL* ) @@ -57,13 +57,13 @@ don't know the file size. Copes with files up to 4,294,967,295 bytes long. &coarse ( length* offset* ) GTH2k ,&fine JCN OVR2 .File/length DEO2 - ,&addr LDR2 .File/load DEO2 + ,&addr LDR2 .File/read DEO2 OVR2 SUB2 ,&coarse JMP &fine ( length* offset* ) .File/length DEO2 ( length* ) - ,&addr LDR2 .File/load DEO2 + ,&addr LDR2 .File/read DEO2 .File/length DEO2 ( ) JMP2r diff --git a/projects/library/load-rom.tal b/projects/library/load-rom.tal @@ -14,7 +14,7 @@ ( return if file can't be found, or zero length ) #0001 .File/length DEO2 - ;&tmp .File/load DEO2 + ;&tmp .File/read DEO2 .File/success DEI2 ORA JMP JMP2r ( clear wst ) @@ -81,7 +81,7 @@ OVR2 #f401 ( arguments for STZ2 at fd, plus an extra 01 ) STHkr ( first argument for ADD2 ) .File/success ( argument for DEI2 ) - #0100 .File/load ( arguments for DEO2 ) + #0100 .File/read ( arguments for DEO2 ) #ff00 .File/length DEO2 #00f0 JMP2 diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( vectors ) diff --git 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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 ] +|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] ( variables ) @@ -581,7 +581,7 @@ RTN ;theme-txt .File/name DEO2 #0006 .File/length DEO2 - #fffa .File/load DEO2 + #fffa .File/read DEO2 .File/success DEI2 #0006 !! ,&ignore JCN #fffa LDA2 .System/r DEO2 diff --git a/projects/software/launcher.tal b/projects/software/launcher.tal @@ -28,7 +28,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 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &load $2 &save $2 +|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |b0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] ( variables ) @@ -238,7 +238,7 @@ RTN ;theme-txt .File/name DEO2 #0006 .File/length DEO2 - #fffa .File/load DEO2 + #fffa .File/read DEO2 .File/success DEI2 #0006 !! ,&ignore JCN #fffa LDA2 .System/r DEO2 diff --git a/src/devices/file.c b/src/devices/file.c @@ -63,31 +63,29 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f } static Uint16 -file_read_dir(void *dest, Uint16 len) +file_read_dir(char *dest, Uint16 len) { - static char pathname[PATH_MAX]; + static char pathname[4096]; char *p = dest; if(de == NULL) de = readdir(d); for(; de != NULL; de = readdir(d)) { Uint16 n; if(de->d_name[0] == '.' && de->d_name[1] == '\0') continue; - strncpy(pathname, current_filename, sizeof(pathname) - 1); - strncat(pathname, "/", sizeof(pathname) - 1); - strncat(pathname, de->d_name, sizeof(pathname) - 1); + snprintf(pathname, sizeof(pathname), "%s/%s", current_filename, de->d_name); n = get_entry(p, len, pathname, de->d_name, 1); if(!n) break; p += n; len -= n; } - return p - (char *)dest; + return p - dest; } Uint16 file_init(void *filename) { reset(); - current_filename = (char *)filename; + current_filename = filename; return 0; } @@ -111,17 +109,17 @@ file_read(void *dest, Uint16 len) Uint16 file_write(void *src, Uint16 len, Uint8 flags) { + Uint16 ret = 0; if(state != FILE_WRITE) { reset(); if((f = fopen(current_filename, (flags & 0x01) ? "ab" : "wb")) != NULL) state = FILE_WRITE; } if(state == FILE_WRITE) { - Uint16 ret = fwrite(src, 1, len, f); - fflush(f); - return ret; + if((ret = fwrite(src, 1, len, f)) > 0 && fflush(f) != 0) + ret = 0; } - return 0; + return ret; } Uint16