added Lua variable capture for mame
This commit is contained in:
parent
85bf12a970
commit
15e6efd01d
|
@ -0,0 +1,45 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvu.h"
|
||||
|
||||
#define DEFINE_BIOS_FN(name,address) \
|
||||
int name() { __asm call address __endasm; }
|
||||
|
||||
DEFINE_BIOS_FN(cvbios_skill_screen, 0x1f7c)
|
||||
//DEFINE_BIOS_FN(cvbios_read_ctl, 0x1f79)
|
||||
|
||||
int cvbios_read_left_joystick() {
|
||||
__asm
|
||||
ld hl,#0x0000
|
||||
jp 0x1f79
|
||||
__endasm;
|
||||
}
|
||||
|
||||
int cvbios_read_right_joystick() {
|
||||
__asm
|
||||
ld hl,#0x0100
|
||||
jp 0x1f79
|
||||
__endasm;
|
||||
}
|
||||
|
||||
const char* const HEX = "0123456789ABCDEF";
|
||||
|
||||
void main() {
|
||||
// load BIOS-friendly stack address
|
||||
__asm
|
||||
ld sp,#0x73b9
|
||||
__endasm;
|
||||
// call BIOS
|
||||
cvbios_skill_screen();
|
||||
// loop and read joystick
|
||||
do {
|
||||
int ctl = cvbios_read_left_joystick();
|
||||
cvu_voutb(HEX[(ctl>>0)&0xf], 0x1800 + 3);
|
||||
cvu_voutb(HEX[(ctl>>4)&0xf], 0x1800 + 2);
|
||||
cvu_voutb(HEX[(ctl>>8)&0xf], 0x1800 + 1);
|
||||
cvu_voutb(HEX[(ctl>>12)&0xf], 0x1800 + 0);
|
||||
} while(1) ;
|
||||
}
|
52
src/emu.js
52
src/emu.js
|
@ -874,9 +874,16 @@ var BaseMAMEPlatform = function() {
|
|||
var video;
|
||||
var preload_files;
|
||||
var running = false;
|
||||
var console_vars = {};
|
||||
var console_varname;
|
||||
|
||||
this.luareset = function() {
|
||||
console_vars = {};
|
||||
}
|
||||
|
||||
// http://docs.mamedev.org/techspecs/luaengine.html
|
||||
this.luacall = function(s) {
|
||||
//console.log(s);
|
||||
console_varname = null;
|
||||
Module.ccall('_Z13js_lua_stringPKc', 'void', ['string'], [s+""]);
|
||||
}
|
||||
|
||||
|
@ -906,6 +913,18 @@ var BaseMAMEPlatform = function() {
|
|||
return running;
|
||||
}
|
||||
|
||||
function bufferConsoleOutput(s) {
|
||||
if (!s) return;
|
||||
if (s.startsWith(">>>")) {
|
||||
console_varname = s.length > 3 ? s.slice(3) : null;
|
||||
if (console_varname) console_vars[console_varname] = [];
|
||||
} else if (console_varname) {
|
||||
console_vars[console_varname].push(s);
|
||||
} else {
|
||||
console.log(s);
|
||||
}
|
||||
}
|
||||
|
||||
this.startModule = function(mainElement, opts) {
|
||||
romfn = opts.romfn;
|
||||
if (!romdata) romdata = new RAM(opts.romsize).mem;
|
||||
|
@ -920,7 +939,7 @@ var BaseMAMEPlatform = function() {
|
|||
window.Module = {
|
||||
arguments: [opts.driver, '-verbose', '-window', '-nokeepaspect', '-resolution', canvas.width+'x'+canvas.height, '-cart', romfn],
|
||||
screenIsReadOnly: true,
|
||||
print: function (text) { console.log(text); },
|
||||
print: bufferConsoleOutput,
|
||||
canvas:video.canvas,
|
||||
doNotCaptureKeyboard:true,
|
||||
keyboardListeningElement:video.canvas,
|
||||
|
@ -985,4 +1004,33 @@ var BaseMAMEPlatform = function() {
|
|||
}
|
||||
}
|
||||
|
||||
this.saveState = function() {
|
||||
this.luareset();
|
||||
this.luacall('cpu = manager:machine().devices[":maincpu"]\nfor k,v in pairs(cpu.state) do print(">>>cpu_"..k); print(v.value) end');
|
||||
var state = {c:{}};
|
||||
for (var k in console_vars) {
|
||||
if (k.startsWith("cpu_")) {
|
||||
var v = parseInt(console_vars[k][0]);
|
||||
state.c[k.slice(4)] = v;
|
||||
}
|
||||
}
|
||||
// TODO
|
||||
return state;
|
||||
}
|
||||
|
||||
var initluavars=false;
|
||||
|
||||
this.readAddress = function(a) {
|
||||
if (!initluavars) {
|
||||
self.luacall('cpu = manager:machine().devices[":maincpu"]\nmem = cpu.spaces["program"]\n')
|
||||
initluavars = true;
|
||||
}
|
||||
self.luacall('print(">>>v"); print(mem:read_u8(' + a + '))');
|
||||
return parseInt(console_vars.v[0]);
|
||||
}
|
||||
|
||||
this.getDebugCallback = function() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// http://www.theadamresource.com/manuals/technical/Jeffcoleco.html
|
||||
// http://bifi.msxnet.org/msxnet//tech/tms9918a.txt
|
||||
// http://www.colecovision.dk/tools.htm?refreshed
|
||||
// http://www.theadamresource.com/manuals/technical/ColecoVision%20Coding%20Guide.pdf
|
||||
|
||||
var ColecoVision_PRESETS = [
|
||||
{id:'text.c', name:'Text Mode'},
|
||||
|
@ -201,13 +202,6 @@ var ColecoVisionMAMEPlatform = function(mainElement) {
|
|||
romfn:'/emulator/cart.rom',
|
||||
romsize:0x8000,
|
||||
preInit:function(_self) {
|
||||
/*
|
||||
console.log("Writing BIOS");
|
||||
var dir = '/roms/coleco';
|
||||
FS.mkdir('/roms');
|
||||
FS.mkdir(dir);
|
||||
FS.writeFile(dir + "/313 10031-4005 73108a.u2", COLECO_BIOS, {encoding:'binary'});
|
||||
*/
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue