1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-03 11:49:20 +00:00

mame: made 6502/z80 subclasses

This commit is contained in:
Steven Hugg 2021-07-31 09:52:25 -05:00
parent 34322dd3d7
commit 5c52862a0b
10 changed files with 113 additions and 59 deletions

View File

@ -71,4 +71,14 @@ function string.tohex(str)
end))
end
function table.tojson(t)
local result = {}
for key, value in pairs(t) do
-- prepare json key-value pairs and save them in separate table
table.insert(result, string.format("\"%s\":\"%s\"", key, value))
end
-- get simple json string
return "{" .. table.concat(result, ",") .. "}"
end
print("parsed Lua debugger script")

View File

@ -664,6 +664,7 @@ export abstract class BaseMAMEPlatform {
started : boolean = false;
romfn : string;
romdata : Uint8Array;
romtype : string = 'cart';
video;
running = false;
initluavars : boolean = false;
@ -727,6 +728,7 @@ export abstract class BaseMAMEPlatform {
this.started = true;
var romfn = this.romfn = this.romfn || opts.romfn;
var romdata = this.romdata = this.romdata || opts.romdata || new RAM(opts.romsize).mem;
var romtype = this.romtype = this.romtype || opts.romtype;
// create canvas
var video = this.video = new RasterVideo(this.mainElement, opts.width, opts.height);
video.create();
@ -739,7 +741,13 @@ export abstract class BaseMAMEPlatform {
'-verbose', '-window', '-nokeepaspect',
'-resolution', video.canvas.width+'x'+video.canvas.height
];
if (romfn) modargs.push('-cart', romfn);
if (romfn) {
modargs.push('-'+romtype, romfn);
}
if (opts.extraargs) {
modargs = modargs.concat(opts.extraargs);
}
console.log(modargs);
window['JSMESS'] = {};
window['Module'] = {
arguments: modargs,
@ -839,7 +847,7 @@ export abstract class BaseMAMEPlatform {
// for debugging via browser console
window['mamelua'] = (s:string) => {
this.initlua();
return this.luacall(s);
return [s, this.luacall(s)];
};
}
@ -885,27 +893,6 @@ export abstract class BaseMAMEPlatform {
return parseInt(this.luacall('return cpu.state.'+reg+'.value'));
}
getPC() : number {
return this.getCPUReg('PC');
}
getSP() : number {
return this.getCPUReg('SP');
}
isStable() { return true; }
getCPUState() {
return {
PC:this.getPC(),
SP:this.getSP(),
A:this.getCPUReg('A'),
X:this.getCPUReg('X'),
Y:this.getCPUReg('Y'),
//flags:this.getCPUReg('CURFLAGS'),
};
}
grabState(expr:string) {
this.initlua();
return {
@ -974,17 +961,75 @@ export abstract class BaseMAMEPlatform {
case 'CPU': return this.cpuStateToLongString(state.c);
}
}
// TODO: other than z80
cpuStateToLongString(c) {
if (c.HL)
return cpuStateToLongString_Z80(c);
else
return cpuStateToLongString_6502(c); // TODO
getDebugTree() {
this.initlua();
var devices = JSON.parse(this.luacall(`return table.tojson(manager:machine().devices)`));
var images = JSON.parse(this.luacall(`return table.tojson(manager:machine().images)`));
var regions = JSON.parse(this.luacall(`return table.tojson(manager:machine():memory().regions)`));
return {
devices: devices,
images: images,
regions: regions,
}
}
abstract cpuStateToLongString(c) : string;
abstract getCPUState() : any;
}
export abstract class BaseMAME6502Platform extends BaseMAMEPlatform {
getPC() : number {
return this.getCPUReg('PC');
}
getSP() : number {
return this.getCPUReg('SP');
}
isStable() { return true; }
getCPUState() {
return {
PC:this.getPC(),
SP:this.getSP(),
A:this.getCPUReg('A'),
X:this.getCPUReg('X'),
Y:this.getCPUReg('Y'),
flags:this.getCPUReg('P'),
};
}
disassemble(pc:number, read:(addr:number)=>number) : DisasmLine {
// TODO: z80
return disassemble6502(pc, read(pc), read(pc+1), read(pc+2));
}
cpuStateToLongString(c) {
return cpuStateToLongString_6502(c);
}
}
export abstract class BaseMAMEZ80Platform extends BaseMAMEPlatform {
getPC() : number {
return this.getCPUReg('PC');
}
getSP() : number {
return this.getCPUReg('SP');
}
isStable() { return true; }
getCPUState() {
return {
PC:this.getPC(),
SP:this.getSP(),
AF:this.getCPUReg('AF'),
BC:this.getCPUReg('BC'),
DE:this.getCPUReg('DE'),
HL:this.getCPUReg('HL'),
IX:this.getCPUReg('IX'),
IY:this.getCPUReg('IY'),
IR:this.getCPUReg('R') + (this.getCPUReg('I') << 8),
};
}
disassemble(pc:number, read:(addr:number)=>number) : DisasmLine {
return disassembleZ80(pc, read(pc), read(pc+1), read(pc+2), read(pc+3));
}
cpuStateToLongString(c) {
return cpuStateToLongString_Z80(c);
}
}
//TODO: how to get stack_end?

View File

@ -1,5 +1,5 @@
import { Platform, BaseMAMEPlatform, getOpcodeMetadata_6502, getToolForFilename_6502 } from "../common/baseplatform";
import { Platform, getOpcodeMetadata_6502, getToolForFilename_6502, BaseMAME6502Platform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
const APPLE2_PRESETS = [
@ -23,11 +23,11 @@ const APPLE2_PRESETS = [
/// MAME support
class Apple2MAMEPlatform extends BaseMAMEPlatform implements Platform {
class Apple2MAMEPlatform extends BaseMAME6502Platform implements Platform {
start () {
this.startModule(this.mainElement, {
jsfile:'mame8bitws.js',
jsfile:'mame8bitpc.js',
biosfile:['apple2e.zip'],
//cfgfile:'nes.cfg',
driver:'apple2e',
@ -97,5 +97,5 @@ class NewApple2Platform extends Base6502MachinePlatform<AppleII> implements Plat
*/
}
//PLATFORMS['apple2.mame'] = Apple2MAMEPlatform;
PLATFORMS['apple2.mame'] = Apple2MAMEPlatform;
PLATFORMS['apple2'] = NewApple2Platform;

View File

@ -1,6 +1,6 @@
"use strict";
import { Platform, BaseMAMEPlatform, getOpcodeMetadata_6502, getToolForFilename_6502, Base6502MachinePlatform } from "../common/baseplatform";
import { Platform, getOpcodeMetadata_6502, getToolForFilename_6502, Base6502MachinePlatform, BaseMAME6502Platform } from "../common/baseplatform";
import { PLATFORMS, Keys, makeKeycodeMap } from "../common/emu";
import { Atari8_WASMMachine } from "../machine/atari8";
@ -46,7 +46,7 @@ function getToolForFilename_Atari8(fn:string) {
/// MAME support
abstract class Atari8MAMEPlatform extends BaseMAMEPlatform {
abstract class Atari8MAMEPlatform extends BaseMAME6502Platform {
getPresets() { return Atari8_PRESETS; }
getToolForFilename = getToolForFilename_Atari8;
getOpcodeMetadata = getOpcodeMetadata_6502;
@ -59,7 +59,7 @@ abstract class Atari8MAMEPlatform extends BaseMAMEPlatform {
}
}
abstract class Atari8WASIMAMEPlatform extends BaseMAMEPlatform {
abstract class Atari8WASIMAMEPlatform extends BaseMAME6502Platform {
getPresets() { return Atari8_PRESETS; }
getToolForFilename = getToolForFilename_Atari8;
getOpcodeMetadata = getOpcodeMetadata_6502;

View File

@ -1,6 +1,6 @@
import { C64_WASMMachine } from "../machine/c64";
import { Platform, Base6502MachinePlatform, getToolForFilename_6502, getOpcodeMetadata_6502, BaseMAMEPlatform } from "../common/baseplatform";
import { Platform, Base6502MachinePlatform, getToolForFilename_6502, getOpcodeMetadata_6502, BaseMAME6502Platform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
const C64_PRESETS = [
@ -59,7 +59,7 @@ class C64WASMPlatform extends Base6502MachinePlatform<C64_WASMMachine> implement
}
// C64 MAME platform
abstract class C64MAMEPlatform extends BaseMAMEPlatform {
abstract class C64MAMEPlatform extends BaseMAME6502Platform {
getPresets() { return C64_PRESETS; }
getToolForFilename = getToolForFilename_6502;
getOpcodeMetadata = getOpcodeMetadata_6502;
@ -67,21 +67,25 @@ abstract class C64MAMEPlatform extends BaseMAMEPlatform {
loadROM(title, data) {
if (!this.started) {
this.startModule(this.mainElement, {
jsfile:'mame8bitws.js',
jsfile:'mame8bitpc.js',
biosfile:'c64.zip',
cfgfile:'c64.cfg',
driver:'c64',
width:336*2,
height:225*2,
romfn:'/emulator/disk.d64',
width:418,
height:235,
romfn:'/emulator/image.crt',
romdata:new Uint8Array(data),
romsize:0x2000,
romsize:0x10000,
extraargs: ['-autoboot_delay','5','-autoboot_command','load "$",8,1\n'],
preInit:function(_self) {
},
});
} else {
this.loadROMFile(data);
this.loadRegion(":cartleft:cart:rom", data);
this.loadRegion(":quickload", data);
var result = this.luacall(`image:load("/emulator/image.prg")`)
console.log('load rom', result);
//this.loadRegion(":exp:standard", data);
}
}
start() {

View File

@ -1,6 +1,6 @@
import { ColecoVision } from "../machine/coleco";
import { Platform, BaseZ80MachinePlatform, BaseMAMEPlatform, getToolForFilename_z80 } from "../common/baseplatform";
import { Platform, BaseZ80MachinePlatform, getToolForFilename_z80, BaseMAMEZ80Platform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
export var ColecoVision_PRESETS = [
@ -39,7 +39,7 @@ class ColecoVisionPlatform extends BaseZ80MachinePlatform<ColecoVision> implemen
/// MAME support
class ColecoVisionMAMEPlatform extends BaseMAMEPlatform implements Platform {
class ColecoVisionMAMEPlatform extends BaseMAMEZ80Platform implements Platform {
start() {
this.startModule(this.mainElement, {

View File

@ -1,5 +1,5 @@
import { Platform, Base6502Platform, BaseMAMEPlatform, getOpcodeMetadata_6502, cpuStateToLongString_6502, getToolForFilename_6502, dumpStackToString } from "../common/baseplatform";
import { Platform, Base6502Platform, getOpcodeMetadata_6502, cpuStateToLongString_6502, getToolForFilename_6502, dumpStackToString, BaseMAME6502Platform } from "../common/baseplatform";
import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, dumpRAM, KeyFlags, EmuHalt, ControllerPoller } from "../common/emu";
import { hex, lpad, lzgmini, byteArrayToString } from "../common/util";
import { CodeAnalyzer_nes } from "../common/analysis";
@ -489,7 +489,7 @@ class JSNESPlatform extends Base6502Platform implements Platform, Probeable {
/// MAME support
class NESMAMEPlatform extends BaseMAMEPlatform implements Platform {
class NESMAMEPlatform extends BaseMAME6502Platform implements Platform {
start() {
}

View File

@ -1,6 +1,6 @@
import { SG1000, SMS } from "../machine/sms";
import { Platform, BaseZ80MachinePlatform, BaseMAMEPlatform, getToolForFilename_z80 } from "../common/baseplatform";
import { Platform, BaseZ80MachinePlatform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
// TODO: merge w/ coleco

View File

@ -1,6 +1,6 @@
"use strict";
import { Platform, BasePlatform, cpuStateToLongString_6502, BaseMAMEPlatform, EmuRecorder, dumpStackToString, DisasmLine, CpuState, DebugCondition } from "../common/baseplatform";
import { Platform, BasePlatform, cpuStateToLongString_6502, EmuRecorder, dumpStackToString, DisasmLine, CpuState, DebugCondition, BaseMAME6502Platform } from "../common/baseplatform";
import { PLATFORMS, RAM, newAddressDecoder, dumpRAM, EmuHalt } from "../common/emu";
import { hex, lpad, tobin, byte2signed } from "../common/util";
import { CodeAnalyzer_vcs } from "../common/analysis";
@ -426,7 +426,7 @@ function nonegstr(n) {
///////////////
class VCSMAMEPlatform extends BaseMAMEPlatform implements Platform {
class VCSMAMEPlatform extends BaseMAME6502Platform implements Platform {
// MCFG_SCREEN_RAW_PARAMS( MASTER_CLOCK_NTSC, 228, 26, 26 + 160 + 16, 262, 24 , 24 + 192 + 31 )

View File

@ -1,11 +1,6 @@
import { Platform, Base6502Platform, BaseMAMEPlatform, getOpcodeMetadata_6502, cpuStateToLongString_6502, getToolForFilename_6502, dumpStackToString, BaseDebugPlatform } from "../common/baseplatform";
import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, dumpRAM, KeyFlags, EmuHalt, ControllerPoller } from "../common/emu";
import { hex, lpad, lzgmini, byteArrayToString } from "../common/util";
import { CodeAnalyzer_nes } from "../common/analysis";
import { SampleAudio } from "../common/audio";
import { ProbeRecorder } from "../common/recorder";
import { NullProbe, Probeable, ProbeAll } from "../common/devices";
import { Platform } from "../common/baseplatform";
import { PLATFORMS, RasterVideo } from "../common/emu";
import { loadScript } from "../ide/ui";
// PC emulator: https://github.com/copy/v86