file.rom test no longer crashes the emulator
This commit is contained in:
+24
-5
@@ -134,8 +134,20 @@ fn filestat_to_addr(fi: u8, state: *uxn) void = {
|
||||
case =>
|
||||
fmt::fatal("Bad String encoding in filename");
|
||||
};
|
||||
const stat = os::fstat(state.files[fi].file: io::file)!;
|
||||
const fsize = stat.sz: u32;
|
||||
const fstat = match(os::fstat(state.files[fi].file: io::file)){
|
||||
case let fstat: fs::filestat =>
|
||||
yield fstat;
|
||||
case let err: fs::error =>
|
||||
yield void;
|
||||
|
||||
};
|
||||
const fsize = match(fstat){
|
||||
case let stat: fs::filestat =>
|
||||
yield stat.sz: u32;
|
||||
case =>
|
||||
yield 0: u32;
|
||||
|
||||
};
|
||||
const modestring = if(fsize <= 0xFFFF){
|
||||
yield fmt::asprintf("{:x.4}",fsize)!;
|
||||
}else {
|
||||
@@ -218,16 +230,23 @@ fn filestat_to_addr(fi: u8, state: *uxn) void = {
|
||||
};
|
||||
return;
|
||||
};
|
||||
|
||||
fn write_file_from_addr(fi: u8,state: *uxn) void = {
|
||||
const length = if(fi == 0) { yield short_from_bytes(state.dev[0xaa],state.dev[0xab]); }
|
||||
else { yield short_from_bytes(state.dev[0xba],state.dev[0xbb]); };
|
||||
const srcaddr = if(fi == 0) { yield short_from_bytes(state.dev[0xae],state.dev[0xaf]); }
|
||||
else { yield short_from_bytes(state.dev[0xbe],state.dev[0xbf]); };
|
||||
const endaddr = srcaddr + length;
|
||||
let endaddr = srcaddr + length;
|
||||
const appendf: bool = if(fi == 0) { yield state.dev[0xa7] != 0; }
|
||||
else { yield state.dev[0xb7] != 0; };
|
||||
fmt::printfln("Writing {} bytes from 0x{:x}", length, srcaddr)!;
|
||||
const bytes: []u8 = state.ram[srcaddr..endaddr];
|
||||
// fmt::printfln("Writing {} bytes from 0x{:x}", length, srcaddr)!;
|
||||
fmt::printfln("Writing {} bytes from 0x{:x} to 0x{:x}", endaddr-srcaddr, srcaddr,endaddr)!;
|
||||
// const bytes: []u8 = state.ram[srcaddr..endaddr];
|
||||
const bytes: []u8 = if(endaddr < srcaddr){
|
||||
yield state.ram[srcaddr..];
|
||||
} else {
|
||||
yield state.ram[srcaddr..endaddr];
|
||||
};
|
||||
let byteswritten: u16 = 0;
|
||||
|
||||
if(!state.files[fi].exists){
|
||||
|
||||
Reference in New Issue
Block a user