Skip to content

Commit

Permalink
c64: removed wait_vblank macro
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Dec 1, 2023
1 parent bd63ef1 commit 312cb3d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
2 changes: 0 additions & 2 deletions presets/c64/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ typedef enum { false, true } bool; // boolean
// default screen base address on startup
#define DEFAULT_SCREEN ((void*)0x400)

// wait until next frame, same as waitvsync()
#define wait_vblank waitvsync
// is raster line > 255?
#define RASTER_HIBIT (VIC.ctrl1 & 0x80)

Expand Down
54 changes: 54 additions & 0 deletions src/common/wasi/libretro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { WASIRunner } from "./wasishim";

export class LibRetroRunner extends WASIRunner {
constructor() {
super();
}
getEnv() {
return {
...super.getEnv(),
retro_environment_callback: (cmd: number, data: number) => {
console.log(`retro_environment_callback: ${cmd}, ${data}`);
return 0;
},
retro_video_refresh_callback: (data: number, width: number, height: number, pitch: number) => {
console.log(`retro_video_refresh_callback: ${data}, ${width}, ${height}, ${pitch}`);
},
retro_audio_sample_batch_callback: (data: number, frames: number) => {
console.log(`retro_audio_sample_batch_callback: ${data}, ${frames}`);
},
retro_audio_sample_callback: (left: number, right: number) => {
console.log(`retro_audio_sample_callback: ${left}, ${right}`);
return 0;
},
retro_input_poll_callback: () => {
console.log(`retro_input_poll_callback`);
},
retro_input_state_callback: (port: number, device: number, index: number, id: number) => {
console.log(`retro_input_state_callback: ${port}, ${device}, ${index}, ${id}`);
return 0;
},
}
}
retro_init() {
let errno = this.initialize();
// TODO: if (errno) throw new Error(`retro_init failed: ${errno}`);
this.exports().retro_init_callbacks();
this.exports().retro_init();
this.exports().retro_set_controller_port_device(0,1);
this.exports().retro_set_controller_port_device(1,1);
}
retro_api_version() {
return this.exports().retro_api_version();
}
load_rom(path: string, data: Uint8Array) {
const meta = '';
this.exports().retro_load_rom(path, data, data.length, meta);
}
reset() {
this.exports().retro_reset();
}
advance() {
this.exports().retro_run();
}
}
12 changes: 10 additions & 2 deletions src/common/wasi/wasishim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class WASIMemoryFilesystem implements WASIFilesystem {
}

export class WASIRunner {
#instance; // TODO
#instance : any; // TODO
#memarr8: Uint8Array;
#memarr32: Int32Array;
#args: Uint8Array[] = [];
Expand All @@ -282,6 +282,9 @@ export class WASIRunner {
constructor() {
this.createStdioBrowser();
}
exports() {
return this.#instance.exports;
}
createStdioNode() {
this.stdin = new WASIStreamingFileDescriptor(0, '<stdin>', FDType.CHARACTER_DEVICE, FDRights.FD_READ, process.stdin);
this.stdout = new WASIStreamingFileDescriptor(1, '<stdout>', FDType.CHARACTER_DEVICE, FDRights.FD_WRITE, process.stdout);
Expand Down Expand Up @@ -373,6 +376,10 @@ export class WASIRunner {
}
return this.getErrno();
}
initialize() {
this.#instance.exports._initialize();
return this.getErrno();
}
getImportObject() {
return {
"wasi_snapshot_preview1": this.getWASISnapshotPreview1(),
Expand Down Expand Up @@ -604,11 +611,12 @@ export class WASIRunner {
fd_readdir() { warning("TODO: fd_readdir"); return WASIErrors.NOTSUP; },
path_unlink_file() { warning("TODO: path_unlink_file"); return WASIErrors.NOTSUP; },
clock_time_get() { warning("TODO: clock_time_get"); return WASIErrors.NOTSUP; },
fd_tell() { warning("TODO: fd_tell"); return WASIErrors.NOTSUP; },
}
}
getEnv() {
return {
__syscall_unlinkat() { warning('TODO: unlink'); return 0; },
__syscall_unlinkat() { warning('TODO: unlink'); return WASIErrors.NOTSUP; },
}
}
}
24 changes: 24 additions & 0 deletions src/test/testlibretro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import assert from "assert";
import * as fs from "fs";
import { LibRetroRunner } from "../common/wasi/libretro";

async function loadLibretro() {
const wasmdata = fs.readFileSync(`./wasi/stella2014_libretro_2.wasm`);
let shim = new LibRetroRunner();
await shim.loadAsync(wasmdata);
return shim;
}

/*
describe('test WASI libretro', function () {
it('libretro init', async function () {
let shim = await loadLibretro();
assert.strictEqual(1, shim.retro_api_version());
shim.retro_init();
let romdata = fs.readFileSync(`./test/roms/vcs/brickgame.rom`);
shim.load_rom('brickgame.rom', romdata);
shim.reset();
shim.advance();
});
});
*/
1 change: 1 addition & 0 deletions src/test/testwasishim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ describe('test WASI cc7800', function () {
assert.ok(stdout.indexOf('Usage: cc7800') >= 0);
});
});

0 comments on commit 312cb3d

Please sign in to comment.