Dropped File.vector, add File.result short
This commit is contained in:
parent
ac9f94dd6d
commit
fc4e2e2876
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue