1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-02-21 06:29:02 +00:00

updated coleco to BasicZ80Scanline

This commit is contained in:
Steven Hugg 2019-08-04 20:10:14 -04:00
parent 221d16a3c0
commit 725d0c9efa
3 changed files with 161 additions and 188 deletions

View File

@ -52,6 +52,7 @@ const _Apple2Platform = function(mainElement) {
// bank 1 is E000-FFFF, bank 2 is D000-DFFF // bank 1 is E000-FFFF, bank 2 is D000-DFFF
var bank2rdoffset=0, bank2wroffset=0; var bank2rdoffset=0, bank2wroffset=0;
var grparams : AppleGRParams; var grparams : AppleGRParams;
var scanline : number;
class Apple2Platform extends Base6502Platform implements Platform { class Apple2Platform extends Base6502Platform implements Platform {
@ -199,6 +200,7 @@ const _Apple2Platform = function(mainElement) {
var clock = 0; var clock = 0;
var debugCond = this.getDebugCallback(); var debugCond = this.getDebugCallback();
for (var sl=0; sl<262; sl++) { for (var sl=0; sl<262; sl++) {
scanline = sl;
for (var i=0; i<cpuCyclesPerLine; i++) { for (var i=0; i<cpuCyclesPerLine; i++) {
if (debugCond && debugCond()) { if (debugCond && debugCond()) {
debugCond = null; debugCond = null;
@ -217,6 +219,10 @@ const _Apple2Platform = function(mainElement) {
video.updateFrame(); video.updateFrame();
} }
} }
getRasterScanline() : number {
return scanline;
}
loadROM(title, data) { loadROM(title, data) {
pgmbin = data; pgmbin = data;

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
import { Platform, BaseMAMEPlatform, BaseZ80Platform, getToolForFilename_z80 } from "../baseplatform"; import { Platform, BaseMAMEPlatform, BasicZ80ScanlinePlatform, getToolForFilename_z80 } from "../baseplatform";
import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap } from "../emu"; import { PLATFORMS, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap } from "../emu";
import { hex, lzgmini, stringToByteArray } from "../util"; import { hex, lzgmini, stringToByteArray } from "../util";
import { MasterAudio, SN76489_Audio } from "../audio"; import { MasterAudio, SN76489_Audio } from "../audio";
import { TMS9918A } from "../video/tms9918a"; import { TMS9918A } from "../video/tms9918a";
@ -25,202 +25,168 @@ import { TMS9918A } from "../video/tms9918a";
// http://www.harmlesslion.com/cgi-bin/showprog.cgi?ColecoVision // http://www.harmlesslion.com/cgi-bin/showprog.cgi?ColecoVision
export var ColecoVision_PRESETS = [ export var ColecoVision_PRESETS = [
{id:'text.c', name:'Text Mode'}, { id: 'text.c', name: 'Text Mode' },
{id:'hello.c', name:'Scrolling Text'}, { id: 'hello.c', name: 'Scrolling Text' },
{id:'text32.c', name:'32-Column Color Text'}, { id: 'text32.c', name: '32-Column Color Text' },
{id:'stars.c', name:'Scrolling Starfield'}, { id: 'stars.c', name: 'Scrolling Starfield' },
{id:'cursorsmooth.c', name:'Moving Cursor'}, { id: 'cursorsmooth.c', name: 'Moving Cursor' },
{id:'simplemusic.c', name:'Simple Music'}, { id: 'simplemusic.c', name: 'Simple Music' },
{id:'musicplayer.c', name:'Multivoice Music'}, { id: 'musicplayer.c', name: 'Multivoice Music' },
{id:'mode2bitmap.c', name:'Mode 2 Bitmap'}, { id: 'mode2bitmap.c', name: 'Mode 2 Bitmap' },
{id:'mode2compressed.c', name:'Mode 2 Bitmap (LZG)'}, { id: 'mode2compressed.c', name: 'Mode 2 Bitmap (LZG)' },
{id:'lines.c', name:'Mode 2 Lines'}, { id: 'lines.c', name: 'Mode 2 Lines' },
{id:'multicolor.c', name:'Multicolor Mode'}, { id: 'multicolor.c', name: 'Multicolor Mode' },
{id:'siegegame.c', name:'Siege Game'}, { id: 'siegegame.c', name: 'Siege Game' },
{id:'shoot.c', name:'Solarian Game'}, { id: 'shoot.c', name: 'Solarian Game' },
{id:'climber.c', name:'Platform Game'}, { id: 'climber.c', name: 'Platform Game' },
]; ];
var COLECOVISION_KEYCODE_MAP = makeKeycodeMap([ var COLECOVISION_KEYCODE_MAP = makeKeycodeMap([
[Keys.UP, 0, 0x1], [Keys.UP, 0, 0x1],
[Keys.DOWN, 0, 0x4], [Keys.DOWN, 0, 0x4],
[Keys.LEFT, 0, 0x8], [Keys.LEFT, 0, 0x8],
[Keys.RIGHT, 0, 0x2], [Keys.RIGHT, 0, 0x2],
[Keys.A, 0, 0x40], [Keys.A, 0, 0x40],
[Keys.B, 1, 0x40], [Keys.B, 1, 0x40],
[Keys.P2_UP, 2, 0x1], [Keys.P2_UP, 2, 0x1],
[Keys.P2_DOWN, 2, 0x4], [Keys.P2_DOWN, 2, 0x4],
[Keys.P2_LEFT, 2, 0x8], [Keys.P2_LEFT, 2, 0x8],
[Keys.P2_RIGHT, 2, 0x2], [Keys.P2_RIGHT, 2, 0x2],
[Keys.P2_A, 2, 0x40], [Keys.P2_A, 2, 0x40],
[Keys.P2_B, 3, 0x40], [Keys.P2_B, 3, 0x40],
]); ]);
/// standard emulator class ColecoVisionPlatform extends BasicZ80ScanlinePlatform implements Platform {
const _ColecoVisionPlatform = function(mainElement) { cpuFrequency = 3579545; // MHz
canvasWidth = 304;
numTotalScanlines = 262;
numVisibleScanlines = 240;
defaultROMSize = 0x8000;
const cpuFrequency = 3579545; // MHz vdp: TMS9918A;
const canvasWidth = 304; bios: Uint8Array;
const numTotalScanlines = 262; keypadMode: boolean;
const numVisibleScanlines = 240; audio;
const cpuCyclesPerLine = Math.round(cpuFrequency / 60 / numTotalScanlines); psg;
var cpu, ram, membus, iobus, rom, bios; getPresets() { return ColecoVision_PRESETS; }
var video, vdp, timer;
var audio, psg;
var inputs = new Uint8Array(4);
var keypadMode = false;
var poller;
class ColecoVisionPlatform extends BaseZ80Platform implements Platform { getKeyboardMap() { return COLECOVISION_KEYCODE_MAP; }
getPresets() { return ColecoVision_PRESETS; } getVideoOptions() { return { overscan: true }; }
start() { newRAM() {
ram = new RAM(1024); return new Uint8Array(0x400);
bios = new lzgmini().decode(stringToByteArray(atob(COLECO_BIOS_LZG))); }
membus = {
read: newAddressDecoder([ newMembus() {
[0x0000, 0x1fff, 0x1fff, function(a) { return bios ? bios[a] : 0; }], return {
[0x6000, 0x7fff, 0x3ff, function(a) { return ram.mem[a]; }], read: newAddressDecoder([
[0x8000, 0xffff, 0x7fff, function(a) { return rom ? rom[a] : 0; }], [0x0000, 0x1fff, 0x1fff, (a) => { return this.bios ? this.bios[a] : 0; }],
]), [0x6000, 0x7fff, 0x3ff, (a) => { return this.ram[a]; }],
write: newAddressDecoder([ [0x8000, 0xffff, 0x7fff, (a) => { return this.rom ? this.rom[a] : 0; }],
[0x6000, 0x7fff, 0x3ff, function(a,v) { ram.mem[a] = v; }], ]),
]), write: newAddressDecoder([
}; [0x6000, 0x7fff, 0x3ff, (a, v) => { this.ram[a] = v; }],
iobus = { ]),
read: function(addr) { };
addr &= 0xff; }
//console.log('IO read', hex(addr,4));
switch (addr) { newIOBus() {
case 0xfc: return inputs[keypadMode?1:0] ^ 0xff; return {
case 0xff: return inputs[keypadMode?3:2] ^ 0xff; read: (addr:number):number => {
} addr &= 0xff;
if (addr >= 0xa0 && addr <= 0xbf) { //console.log('IO read', hex(addr,4));
if (addr & 1) switch (addr) {
return vdp.readStatus(); case 0xfc: return this.inputs[this.keypadMode ? 1 : 0] ^ 0xff;
else case 0xff: return this.inputs[this.keypadMode ? 3 : 2] ^ 0xff;
return vdp.readData(); }
} if (addr >= 0xa0 && addr <= 0xbf) {
return 0; if (addr & 1)
}, return this.vdp.readStatus();
write: function(addr, val) { else
addr &= 0xff; return this.vdp.readData();
val &= 0xff; }
//console.log('IO write', hex(addr,4), hex(val,2)); return 0;
switch (addr >> 4) { },
case 0x8: case 0x9: keypadMode = true; break; write: (addr:number, val:number) => {
case 0xc: case 0xd: keypadMode = false; break; addr &= 0xff;
case 0xa: case 0xb: val &= 0xff;
if (addr & 1) //console.log('IO write', hex(addr,4), hex(val,2));
return vdp.writeAddress(val); switch (addr >> 4) {
else case 0x8: case 0x9: this.keypadMode = true; break;
return vdp.writeData(val); case 0xc: case 0xd: this.keypadMode = false; break;
case 0xf: psg.setData(val); break; case 0xa: case 0xb:
} if (addr & 1)
} return this.vdp.writeAddress(val);
}; else
cpu = this.newCPU(membus, iobus); return this.vdp.writeData(val);
video = new RasterVideo(mainElement,canvasWidth,numVisibleScanlines,{overscan:true}); case 0xf: this.psg.setData(val); break;
video.create();
audio = new MasterAudio();
psg = new SN76489_Audio(audio);
var cru = {
setVDPInterrupt: (b) => {
if (b) {
cpu.nonMaskableInterrupt();
} else {
// TODO: reset interrupt?
}
} }
};
vdp = new TMS9918A(video.getFrameData(), cru, true); // true = 4 sprites/line
poller = setKeyboardFromMap(video, inputs, COLECOVISION_KEYCODE_MAP);
timer = new AnimationTimer(60, this.nextFrame.bind(this));
}
pollControls() { poller.poll(); }
readAddress(addr) {
return membus.read(addr);
}
advance(novideo : boolean) {
for (var sl=0; sl<numTotalScanlines; sl++) {
this.runCPU(cpu, cpuCyclesPerLine);
vdp.drawScanline(sl);
} }
video.updateFrame(); };
} }
loadROM(title, data) { start() {
rom = padBytes(data, 0x8000); super.start();
this.reset(); this.bios = new lzgmini().decode(stringToByteArray(atob(COLECO_BIOS_LZG)));
} this.audio = new MasterAudio();
this.psg = new SN76489_Audio(this.audio);
loadState(state) { var cru = {
cpu.loadState(state.c); setVDPInterrupt: (b) => {
ram.mem.set(state.b); if (b) {
vdp.restoreState(state.vdp); this.cpu.nonMaskableInterrupt();
keypadMode = state.kpm; } else {
inputs.set(state.in); // TODO: reset interrupt?
} }
saveState() {
return {
c:this.getCPUState(),
b:ram.mem.slice(0),
vdp:vdp.getState(),
kpm:keypadMode,
in:inputs.slice(0),
};
}
loadControlsState(state) {
inputs.set(state.in);
}
saveControlsState() {
return {
in:inputs.slice(0)
};
}
getCPUState() {
return cpu.saveState();
}
isRunning() {
return timer && timer.isRunning();
}
pause() {
timer.stop();
audio.stop();
}
resume() {
timer.start();
audio.start();
}
reset() {
cpu.reset();
cpu.setTstates(0);
vdp.reset();
psg.reset();
}
getDebugCategories() {
return super.getDebugCategories().concat(['VDP']);
}
getDebugInfo(category, state) {
switch (category) {
case 'VDP': return this.vdpStateToLongString(state.vdp);
default: return super.getDebugInfo(category, state);
} }
} };
vdpStateToLongString(ppu) { this.vdp = this.newVDP(this.video.getFrameData(), cru, true); // true = 4 sprites/line
return vdp.getRegsString(); }
newVDP(frameData, cru, flicker) {
return new TMS9918A(frameData, cru, flicker);
}
startScanline(sl: number) {
}
drawScanline(sl: number) {
this.vdp.drawScanline(sl);
}
loadState(state) {
super.loadState(state);
this.vdp.restoreState(state['vdp']);
this.keypadMode = state['kpm'];
}
saveState() {
var state = super.saveState();
state['vdp'] = this.vdp.getState();
state['kpm'] = this.keypadMode;
return state;
}
reset() {
super.reset();
this.vdp.reset();
this.psg.reset();
this.keypadMode = false;
}
getDebugCategories() {
return super.getDebugCategories().concat(['VDP']);
}
getDebugInfo(category, state) {
switch (category) {
case 'VDP': return this.vdpStateToLongString(state.vdp);
default: return super.getDebugInfo(category, state);
} }
} }
return new ColecoVisionPlatform(); vdpStateToLongString(ppu) {
return this.vdp.getRegsString();
}
} }
var COLECO_BIOS_LZG = ` var COLECO_BIOS_LZG = `
@ -266,15 +232,15 @@ class ColecoVisionMAMEPlatform extends BaseMAMEPlatform implements Platform {
start() { start() {
this.startModule(this.mainElement, { this.startModule(this.mainElement, {
jsfile:'mamecoleco.js', jsfile: 'mamecoleco.js',
cfgfile:'coleco.cfg', cfgfile: 'coleco.cfg',
biosfile:'coleco/313 10031-4005 73108a.u2', biosfile: 'coleco/313 10031-4005 73108a.u2',
driver:'coleco', driver: 'coleco',
width:280*2, width: 280 * 2,
height:216*2, height: 216 * 2,
romfn:'/emulator/cart.rom', romfn: '/emulator/cart.rom',
romsize:0x8000, romsize: 0x8000,
preInit:function(_self) { preInit: function(_self) {
}, },
}); });
} }
@ -294,4 +260,4 @@ class ColecoVisionMAMEPlatform extends BaseMAMEPlatform implements Platform {
/// ///
PLATFORMS['coleco.mame'] = ColecoVisionMAMEPlatform; PLATFORMS['coleco.mame'] = ColecoVisionMAMEPlatform;
PLATFORMS['coleco'] = _ColecoVisionPlatform; PLATFORMS['coleco'] = ColecoVisionPlatform;

View File

@ -12,6 +12,7 @@ import { TMS9918A } from "../video/tms9918a";
// https://openmsx.org/manual/setup.html // https://openmsx.org/manual/setup.html
// https://www.msx.org/wiki/Slots // https://www.msx.org/wiki/Slots
// https://www.msx.org/wiki/SDCC // https://www.msx.org/wiki/SDCC
// http://cbios.sourceforge.net/
var MSX_PRESETS = [ var MSX_PRESETS = [
{id:'helloworld.asm', name:'Hello World (ASM)'}, {id:'helloworld.asm', name:'Hello World (ASM)'},