-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,4 @@ describe('test WASI cc7800', function () { | |
assert.ok(stdout.indexOf('Usage: cc7800') >= 0); | ||
}); | ||
}); | ||
|