uxn

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

commit fc4e2e2876672a750a03552c44e89099321d6a54
parent ac9f94dd6daf63337fe05a22ad4388ab8208e3ca
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Wed, 14 Apr 2021 20:38:32 +0100

Dropped File.vector, add File.result short

Diffstat:
Mprojects/examples/gui.picture.usm | 4+++-
Msrc/emulator.c | 16+++++++++-------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/projects/examples/gui.picture.usm b/projects/examples/gui.picture.usm @@ -8,8 +8,9 @@ ;size { width 2 height 2 } |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 string 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } -|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 } +|0170 ;File { vector 2 result 2 offset 2 pad 2 name 2 length 2 load 2 save 2 } ( program ) @@ -27,6 +28,7 @@ #0010 #0010 #0020 #0010 #25 ,dvd_icn ,draw-icn JSR2 ( load ) ,filepath =File.name #4000 =File.length ,img =File.load + ~File.result =Console.short BRK diff --git a/src/emulator.c b/src/emulator.c @@ -219,23 +219,25 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) Uint8 *m = u->ram.dat; char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]]; Uint16 length = mempeek16(u, ptr + 8 + 2); - Uint16 offset = mempeek16(u, ptr + 2); + Uint16 offset = mempeek16(u, ptr + 4); if(b0 == 0x0d) { Uint16 addr = (m[ptr + 8 + 4] << 8) + b1; FILE *f = fopen(name, "r"); - if(f && fseek(f, offset, SEEK_SET) != -1 && fread(&m[addr], length, 1, f)) { + if(f && fseek(f, offset, SEEK_SET) != -1 && (length = fread(&m[addr], 1, length, f))) { fclose(f); printf("Loaded %d bytes, at %04x from %s\n", length, addr, name); - evaluxn(u, mempeek16(u, devfile->addr)); - } + } else + length = 0; + mempoke16(u, ptr + 2, length); } else if(b0 == 0x0f) { Uint16 addr = (m[ptr + 8 + 6] << 8) + b1; FILE *f = fopen(name, (m[ptr + 2] & 0x1) ? "a" : "w"); - if(f && fseek(f, offset, SEEK_SET) != -1 && fwrite(&m[addr], length, 1, f)) { + if(f && fseek(f, offset, SEEK_SET) != -1 && (length = fwrite(&m[addr], 1, length, f))) { fclose(f); printf("Saved %d bytes, at %04x from %s\n", length, addr, name); - evaluxn(u, mempeek16(u, devfile->addr)); - } + } else + length = 0; + mempoke16(u, ptr + 2, length); } return b1; }