From 5c52862a0b5d6fb0a7d7066e034043765c48e349 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 31 Jul 2021 09:52:25 -0500 Subject: [PATCH] mame: made 6502/z80 subclasses --- mame/debugger.lua | 10 ++++ src/common/baseplatform.ts | 105 ++++++++++++++++++++++++++----------- src/platform/apple2.ts | 8 +-- src/platform/atari8.ts | 6 +-- src/platform/c64.ts | 20 ++++--- src/platform/coleco.ts | 4 +- src/platform/nes.ts | 4 +- src/platform/sms.ts | 2 +- src/platform/vcs.ts | 4 +- src/platform/x86.ts | 9 +--- 10 files changed, 113 insertions(+), 59 deletions(-) diff --git a/mame/debugger.lua b/mame/debugger.lua index 8a3e3cf5..009f4655 100644 --- a/mame/debugger.lua +++ b/mame/debugger.lua @@ -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") diff --git a/src/common/baseplatform.ts b/src/common/baseplatform.ts index 1538ed7a..454b1d0b 100644 --- a/src/common/baseplatform.ts +++ b/src/common/baseplatform.ts @@ -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? diff --git a/src/platform/apple2.ts b/src/platform/apple2.ts index 95f8531a..c4faa13a 100644 --- a/src/platform/apple2.ts +++ b/src/platform/apple2.ts @@ -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 implements Plat */ } -//PLATFORMS['apple2.mame'] = Apple2MAMEPlatform; +PLATFORMS['apple2.mame'] = Apple2MAMEPlatform; PLATFORMS['apple2'] = NewApple2Platform; diff --git a/src/platform/atari8.ts b/src/platform/atari8.ts index 1fc5180f..3c1356c6 100644 --- a/src/platform/atari8.ts +++ b/src/platform/atari8.ts @@ -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; diff --git a/src/platform/c64.ts b/src/platform/c64.ts index 3113976e..2a6736de 100644 --- a/src/platform/c64.ts +++ b/src/platform/c64.ts @@ -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 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() { diff --git a/src/platform/coleco.ts b/src/platform/coleco.ts index 617da68b..9ddec8c0 100644 --- a/src/platform/coleco.ts +++ b/src/platform/coleco.ts @@ -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 implemen /// MAME support -class ColecoVisionMAMEPlatform extends BaseMAMEPlatform implements Platform { +class ColecoVisionMAMEPlatform extends BaseMAMEZ80Platform implements Platform { start() { this.startModule(this.mainElement, { diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 360a11a0..7844aea5 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -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() { } diff --git a/src/platform/sms.ts b/src/platform/sms.ts index 1b4459be..5248346c 100644 --- a/src/platform/sms.ts +++ b/src/platform/sms.ts @@ -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 diff --git a/src/platform/vcs.ts b/src/platform/vcs.ts index 89fb4346..583bec19 100644 --- a/src/platform/vcs.ts +++ b/src/platform/vcs.ts @@ -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 ) diff --git a/src/platform/x86.ts b/src/platform/x86.ts index 2fae9a83..713a05fb 100644 --- a/src/platform/x86.ts +++ b/src/platform/x86.ts @@ -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