Merge branch 'master' into c64book

This commit is contained in:
Steven Hugg 2022-08-28 23:11:17 -05:00
commit 8ff713a910
12 changed files with 578 additions and 56 deletions

View File

@ -154,6 +154,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<li><a class="dropdown-item" href="?platform=coleco">ColecoVision</a></li>
<li><a class="dropdown-item" href="?platform=sms-sg1000-libcv">Sega SG-1000</a></li>
<li><a class="dropdown-item" href="?platform=sms-sms-libcv">Sega Master System</a></li>
<li><a class="dropdown-item" href="?platform=sms-gg-libcv">Sega Game Gear</a></li>
<li><a class="dropdown-item" href="?platform=atari7800">Atari 7800</a></li>
<!--
<li><a class="dropdown-item" href="?platform=vectrex">Vectrex</a></li>
@ -323,11 +324,17 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<span class="control-def"><span class="control-key small">\</span> Select</span>
<span class="control-def"><span class="control-key small">Enter</span> Start</span>
</div>
<div class="emucontrols-msx emucontrols-coleco emucontrols-sms text-center small control-insns" style="display:none">
<div class="emucontrols-msx emucontrols-coleco text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&#x2191;&#x2193;&#x2192;</span> Joypad</span>
<span class="control-def"><span class="control-key small">Space</span> Button A</span>
<span class="control-def"><span class="control-key small">Shift</span> Button B</span>
</div>
<div class="emucontrols-sms text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&#x2191;&#x2193;&#x2192;</span> Joypad</span>
<span class="control-def"><span class="control-key small">Space</span> Button A</span>
<span class="control-def"><span class="control-key small">Shift</span> Button B</span>
<span class="control-def"><span class="control-key small">Enter</span> Start</span>
</div>
<div class="emucontrols-vicdual emucontrols-galaxian emucontrols-vector text-center small control-insns" style="display:none">
<span class="control-def"><span class="control-key">&#x2190;&#x2191;&#x2193;&#x2192;</span> Joystick</span>
<span class="control-def"><span class="control-key small">Space</span> Button 1</span>

1
presets/sms-gg-libcv Symbolic link
View File

@ -0,0 +1 @@
sms-sms-libcv

View File

@ -72,21 +72,23 @@ void music_play(byte index) {
void music_stop() {
}
/*{pal:222,n:16}*/
const char PALETTE0[16] = {
0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F,
#ifdef __PLATFORM_SMS_GG_LIBCV__
/*{pal:444,n:32}*/
const short PALETTE[32] = {
0xe00, 0xa60, 0xee3, 0xddd, 0xe00, 0xa60, 0xee3, 0xddd,
0xe00, 0xa60, 0xee3, 0xddd, 0xe00, 0xa60, 0xee3, 0xddd,
0xe00, 0x111, 0xddd, 0x43e, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0xe00, 0xa60, 0xee3, 0xddd, 0xe00, 0xa60, 0xee3, 0xddd,
};
/*{pal:222,n:16}*/
const char PALETTE1[16] = {
0x30, 0x00, 0x3F, 0x03,
0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F,
#else
/*{pal:222,n:32}*/
const char PALETTE[32] = {
0x30, 0x38, 0x3E, 0x3F, 0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F, 0x30, 0x38, 0x3E, 0x3F,
0x30, 0x00, 0x3F, 0x03, 0x30, 0x38, 0x3E, 0x3F,
0x30, 0x38, 0x3E, 0x3F, 0x30, 0x38, 0x3E, 0x3F
};
#endif
/// METASPRITES
@ -750,7 +752,7 @@ void pal_bright(byte level) {
byte or = PALBR_OR[level];
byte and = PALBR_AND[level];
for (i=0; i<16; i++) {
pal[i] = PALETTE0[i] & and | or;
pal[i] = PALETTE[i] & and | or;
}
cvu_memtocmemcpy(0xc000, pal, 16);
}
@ -799,8 +801,7 @@ void play_scene() {
void setup_graphics() {
cvu_memtovmemcpy(PATTERN, CHR_GENERIC, sizeof(CHR_GENERIC));
cvu_memtocmemcpy(0xc000, PALETTE0, 16);
cvu_memtocmemcpy(0xc010, PALETTE1, 16);
cvu_memtocmemcpy(0xc000, PALETTE, sizeof(PALETTE));
flip_sprite_patterns(PATTERN+0x80*32, CHR_GENERIC+0xd0*32, 0x30*32);
cv_set_left_column_blank(true);
}

View File

@ -21,17 +21,23 @@ extern uintptr_t font_bitmap_0[];
#define SPRITE_PATTERNS 0x3800 // 32*32 = 1024 bytes
#define SPRITES 0x3c00 // 4*32 = 128 bytes
/*{pal:222,n:16}*/
const char PALETTE0[16] = {
0x10, 0x03, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F,
0x22, 0x28, 0x2A, 0x2E, 0x30, 0x37, 0x3B, 0x3F,
};
/*{pal:222,n:16}*/
const char PALETTE1[16] = {
#ifdef __PLATFORM_SMS_GG_LIBCV__
/*{pal:444,n:32}*/
const short PALETTE[32] = {
0x2221, 0x4441, 0x6661, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
};
#else
/*{pal:222,n:32}*/
const char PALETTE[32] = {
0x10, 0x03, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F,
0x22, 0x28, 0x2A, 0x2E, 0x30, 0x37, 0x3B, 0x3F,
0x10, 0x03, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F,
0x22, 0x28, 0x2A, 0x2E, 0x30, 0x37, 0x3B, 0x3F,
};
#endif
/*{w:8,h:8,bpp:1,count:2,brev:1,np:4,pofs:1,sl:4}*/
const char PATTERNS[64] = {
@ -79,8 +85,7 @@ void setup_graphics() {
// copy sprites to pattern table VRAM
cvu_memtovmemcpy(PATTERN+32, PATTERNS, sizeof(PATTERNS));
// copy palettes to VRAM
cvu_memtocmemcpy(0xc000, PALETTE0, 16);
cvu_memtocmemcpy(0xc010, PALETTE1, 16);
cvu_memtocmemcpy(0xc000, PALETTE, sizeof(PALETTE));
}
// image table has two bytes per cell (name + attribute)

View File

@ -671,7 +671,7 @@ export abstract class Base6809Platform extends BaseZ80Platform {
//TODO: how to get stack_end?
export function dumpStackToString(platform:Platform, mem:Uint8Array|number[], start:number, end:number, sp:number, jsrop:number) : string {
export function dumpStackToString(platform:Platform, mem:Uint8Array|number[], start:number, end:number, sp:number, jsrop:number, bigendian?:boolean) : string {
var s = "";
var nraw = 0;
//s = dumpRAM(mem.slice(start,start+end+1), start, end-start+1);
@ -684,6 +684,7 @@ export function dumpStackToString(platform:Platform, mem:Uint8Array|number[], st
// see if there's a JSR on the stack here
// TODO: make work with roms and memory maps
var addr = read(sp) + read(sp+1)*256;
if (bigendian) { addr = ((addr & 0xff) << 8) | ((addr & 0xff00) >> 8) }
var jsrofs = jsrop==0x20 ? -2 : -3; // 6502 vs Z80
var opcode = read(addr + jsrofs); // might be out of bounds
if (opcode == jsrop) { // JSR
@ -968,7 +969,6 @@ export abstract class BaseZ80MachinePlatform<T extends Machine> extends BaseMach
var start = sp & 0xff00;
var end = start + 0xff;
if (sp == 0) sp = 0x10000;
console.log(sp,start,end);
return dumpStackToString(<Platform><any>this, [], start, end, sp, 0xcd);
}
default: return isDebuggable(this.machine) && this.machine.getDebugInfo(category, state);
@ -980,6 +980,35 @@ export abstract class BaseZ80MachinePlatform<T extends Machine> extends BaseMach
}
export abstract class Base6809MachinePlatform<T extends Machine> extends BaseMachinePlatform<T> {
getToolForFilename = getToolForFilename_6809;
getDebugCategories() {
if (isDebuggable(this.machine))
return this.machine.getDebugCategories();
else
return ['CPU','Stack'];
}
getDebugInfo(category:string, state:EmuState) : string {
switch (category) {
case 'CPU': return cpuStateToLongString_6809(state.c);
case 'Stack': {
var sp = (state.c.SP-1) & 0xffff;
var start = sp & 0xff00;
var end = start + 0xff;
if (sp == 0) sp = 0x10000;
return dumpStackToString(<Platform><any>this, [], start, end, sp, 0x17, true);
}
default: return super.getDebugInfo(category, state);
}
}
disassemble(pc:number, read:(addr:number)=>number) : DisasmLine {
// TODO: don't create new CPU
return Object.create(CPU6809()).disasm(read(pc), read(pc+1), read(pc+2), read(pc+3), read(pc+4), pc);
}
}
///
class SerialIOVisualizer {

View File

@ -2456,7 +2456,8 @@ return {
}
return f;
},
disasm: disasm
disasm: disasm,
isStable: function() { return true; }
};
};

View File

@ -1013,3 +1013,30 @@ export class SMSVDP extends TMS9918A {
}
};
export class GameGearVDP extends SMSVDP {
cram = new Uint8Array(64); // color RAM
cram_latch = 0;
writeData(value: number) {
if (this.writeToCRAM) {
//console.log(hex(this.addressRegister), hex(value), hex(this.cram_latch));
if (this.addressRegister & 1) { // odd address?
let rgb4 = this.cram_latch + (value << 8);
let rgba = RGBA((rgb4&15)*17, ((rgb4>>4)&15)*17, ((rgb4>>8)&15)*17);
let palindex = this.addressRegister & (this.cram.length-1);
this.cram[palindex-1] = this.cram_latch;
this.cram[palindex] = value;
this.cpalette[palindex >> 1] = rgba;
this.prefetchByte = value;
this.addressRegister &= this.ramMask;
this.redrawRequired = true;
} else {
this.cram_latch = value; // even address
}
this.addressRegister++;
} else {
super.writeData(value);
}
this.latch = false;
}
}

View File

@ -1,11 +1,9 @@
import { Z80, Z80State } from "../common/cpu/ZilogZ80";
import { BasicScanlineMachine } from "../common/devices";
import { BaseZ80VDPBasedMachine } from "./vdp_z80";
import { KeyFlags, newAddressDecoder, padBytes, Keys, makeKeycodeMap, newKeyboardHandler } from "../common/emu";
import { hex, lzgmini, stringToByteArray } from "../common/util";
import { TssChannelAdapter, MasterAudio, SN76489_Audio } from "../common/audio";
import { TMS9918A, SMSVDP } from "../common/video/tms9918a";
import { newAddressDecoder, padBytes, Keys, makeKeycodeMap } from "../common/emu";
import { hex } from "../common/util";
import { MasterAudio, SN76489_Audio } from "../common/audio";
import { SMSVDP, GameGearVDP } from "../common/video/tms9918a";
// http://www.smspower.org/Development/Index
// http://www.smspower.org/uploads/Development/sg1000.txt
@ -28,6 +26,7 @@ var SG1000_KEYCODE_MAP = makeKeycodeMap([
[Keys.P2_A, 1, 0x4],
[Keys.P2_B, 1, 0x8],
[Keys.VK_BACK_SLASH, 1, 0x10], // reset
[Keys.VK_ENTER, 1, 0x80], // start/pause
]);
export class SG1000 extends BaseZ80VDPBasedMachine {
@ -61,33 +60,41 @@ export class SG1000 extends BaseZ80VDPBasedMachine {
setMemoryControl(v:number) { }
setIOPortControl(v:number) { }
readIO(addr:number) {
switch (addr & 0xc1) {
case 0x40: return this.getVCounter();
case 0x41: return this.getHCounter();
case 0x80: return this.vdp.readData();
case 0x81: return this.vdp.readStatus();
case 0xc0: return this.inputs[0] ^ 0xff;
case 0xc1: return this.inputs[1] ^ 0xff;
}
return 0;
}
writeIO(addr:number, val:number) {
switch (addr & 0xc1) {
case 0x00: return this.setMemoryControl(val);
case 0x01: return this.setIOPortControl(val);
case 0x40:
case 0x41: return this.psg.setData(val);
case 0x80: return this.vdp.writeData(val);
case 0x81: return this.vdp.writeAddress(val);
}
}
newIOBus() {
return {
read: (addr:number) => {
addr &= 0xff;
//console.log('IO read', hex(addr,4));
switch (addr & 0xc1) {
case 0x40: return this.getVCounter();
case 0x41: return this.getHCounter();
case 0x80: return this.vdp.readData();
case 0x81: return this.vdp.readStatus();
case 0xc0: return this.inputs[0] ^ 0xff;
case 0xc1: return this.inputs[1] ^ 0xff;
}
return 0;
return this.readIO(addr);
},
write: (addr:number, val:number) => {
addr &= 0xff;
val &= 0xff;
//console.log('IO write', hex(addr,4), hex(val,2));
switch (addr & 0xc1) {
case 0x00: return this.setMemoryControl(val);
case 0x01: return this.setIOPortControl(val);
case 0x40:
case 0x41: return this.psg.setData(val);
case 0x80: return this.vdp.writeData(val);
case 0x81: return this.vdp.writeAddress(val);
}
this.writeIO(addr, val);
}
};
}
@ -223,3 +230,17 @@ export class SMS extends SG1000 {
}
}
// https://segaretro.org/images/1/16/Sega_Game_Gear_Hardware_Reference_Manual.pdf
export class GameGear extends SMS {
newVDP(frameData, cru, flicker) {
return new GameGearVDP(frameData, cru, flicker);
}
readIO(addr:number) {
switch (addr & 0xc1) {
case 0x00: return (~this.inputs[1] & 0x80) | 0x40;
case 0xdc: return this.inputs[0] ^ 0xff;
case 0xdd: return this.inputs[1] ^ 0xff;
}
return super.readIO(addr);
}
}

398
src/machine/williams.ts Normal file
View File

@ -0,0 +1,398 @@
import { hex } from "chroma-js";
import { MasterAudio, WorkerSoundChannel } from "../common/audio";
import { MemoryBus } from "../common/baseplatform";
import { CPU6809 } from "../common/cpu/6809";
import { BasicScanlineMachine } from "../common/devices";
import { Keys, makeKeycodeMap, newAddressDecoder, newKeyboardHandler, padBytes } from "../common/emu";
const INITIAL_WATCHDOG = 8;
const SCREEN_HEIGHT = 304;
export class WilliamsMachine extends BasicScanlineMachine {
xtal = 12000000;
cpuFrequency = this.xtal / 3 / 4;
//cpuCyclesPerLine = 64;
cpuCyclesPerLine = 54; // TODO: becuse we swapped width and height
canvasWidth = 256;
numTotalScanlines = 304;
numVisibleScanlines = 304;
defaultROMSize = 0xc000;
rotate = -90;
sampleRate = 1;
cpu;
membus: MemoryBus;
ram = new Uint8Array(0xc000);
nvram = new Uint8Array(0x400);
rom = new Uint8Array(0xc000);
portsel = 0;
banksel = 0;
watchdog_counter = 0;
watchdog_enabled = false;
pia6821 = new Uint8Array(8);
blitregs = new Uint8Array(8);
worker: Worker;
master;
audioadapter;
palette = new Uint32Array(16);
screenNeedsRefresh = false;
displayPCs;
cpuScale = 1;
waitCycles = 0;
constructor(public isDefender: boolean) {
super();
this.palette.fill(0xff000000);
this.initBus(isDefender);
this.initInputs(isDefender);
this.initAudio();
this.initCPU();
}
initInputs(isDefender: boolean) {
var DEFENDER_KEYCODE_MAP = makeKeycodeMap([
[Keys.A, 4, 0x1],
[Keys.RIGHT, 4, 0x2],
[Keys.B, 4, 0x4],
[Keys.VK_X, 4, 0x8],
[Keys.P2_START, 4, 0x10],
[Keys.START, 4, 0x20],
[Keys.LEFT, 4, 0x40],
[Keys.DOWN, 4, 0x80],
[Keys.UP, 6, 0x1],
[Keys.SELECT, 0, 0x4],
[Keys.VK_7, 0, 0x1],
[Keys.VK_8, 0, 0x2],
[Keys.VK_9, 0, 0x8],
]);
var ROBOTRON_KEYCODE_MAP = makeKeycodeMap([
[Keys.P2_UP, 0, 0x1],
[Keys.P2_DOWN, 0, 0x2],
[Keys.P2_LEFT, 0, 0x4],
[Keys.P2_RIGHT, 0, 0x8],
[Keys.START, 0, 0x10],
[Keys.P2_START, 0, 0x20],
[Keys.UP, 0, 0x40],
[Keys.DOWN, 0, 0x80],
[Keys.LEFT, 2, 0x1],
[Keys.RIGHT, 2, 0x2],
[Keys.VK_7, 4, 0x1],
[Keys.VK_8, 4, 0x2],
[Keys.VK_6, 4, 0x4],
[Keys.VK_9, 4, 0x8],
[Keys.SELECT, 4, 0x10],
]);
var KEYCODE_MAP = isDefender ? DEFENDER_KEYCODE_MAP : ROBOTRON_KEYCODE_MAP;
//this.inputs.set(this.pia6821);
this.handler = newKeyboardHandler(this.pia6821, KEYCODE_MAP);
}
initBus(isDefender: boolean) {
var ioread_defender = newAddressDecoder([
[0x400, 0x5ff, 0x1ff, (a) => { return this.nvram[a]; }],
[0x800, 0x800, 0, (a) => { return this.scanline; }],
[0xc00, 0xc07, 0x7, (a) => { return this.pia6821[a]; }],
[0x0, 0xfff, 0, (a) => { /*console.log('ioread',hex(a));*/ }],
]);
var iowrite_defender = newAddressDecoder([
[0x0, 0xf, 0xf, this.setPalette.bind(this)],
[0x3fc, 0x3ff, 0, (a, v) => { if (v == 0x38) this.watchdog_counter = INITIAL_WATCHDOG; this.watchdog_enabled = true; }],
[0x400, 0x5ff, 0x1ff, (a, v) => { this.nvram[a] = v; }],
[0xc02, 0xc02, 0x1, (a, v) => { if (this.worker) this.worker.postMessage({ command: v & 0x3f }); }],
[0xc00, 0xc07, 0x7, (a, v) => { this.pia6821[a] = v; }],
[0x0, 0xfff, 0, (a, v) => { /* console.log('iowrite', hex(a), hex(v)); */ }],
]);
var memread_defender = newAddressDecoder([
[0x0000, 0xbfff, 0xffff, (a) => { return this.ram[a]; }],
[0xc000, 0xcfff, 0x0fff, (a) => {
switch (this.banksel) {
case 0: return ioread_defender(a);
case 1: return this.rom[a + 0x3000];
case 2: return this.rom[a + 0x4000];
case 3: return this.rom[a + 0x5000];
case 7: return this.rom[a + 0x6000];
default: return 0; // TODO: error light
}
}],
[0xd000, 0xffff, 0xffff, (a) => { return this.rom ? this.rom[a - 0xd000] : 0; }],
]);
var memwrite_defender = newAddressDecoder([
[0x0000, 0x97ff, 0, this.write_display_byte.bind(this)],
[0x9800, 0xbfff, 0, (a, v) => { this.ram[a] = v; }],
[0xc000, 0xcfff, 0x0fff, iowrite_defender.bind(this)],
[0xd000, 0xdfff, 0, (a, v) => { this.banksel = v & 0x7; }],
[0, 0xffff, 0, (a, v) => { /* console.log(hex(a), hex(v)); */ }],
]);
// Robotron, Joust, Bubbles, Stargate
var ioread_robotron = newAddressDecoder([
[0x804, 0x807, 0x3, (a) => { return this.pia6821[a]; }],
[0x80c, 0x80f, 0x3, (a) => { return this.pia6821[a + 4]; }],
[0xb00, 0xbff, 0, (a) => { return this.scanline; }],
[0xc00, 0xfff, 0x3ff, (a) => { return this.nvram[a]; }],
[0x0, 0xfff, 0, (a) => { /* console.log('ioread',hex(a)); */ }],
]);
var iowrite_robotron = newAddressDecoder([
[0x0, 0xf, 0xf, this.setPalette.bind(this)],
[0x80c, 0x80c, 0xf, (a, v) => { if (this.worker) this.worker.postMessage({ command: v }); }],
//[0x804, 0x807, 0x3, function(a,v) { console.log('iowrite',a); }], // TODO: sound
//[0x80c, 0x80f, 0x3, function(a,v) { console.log('iowrite',a+4); }], // TODO: sound
[0x900, 0x9ff, 0, (a, v) => { this.banksel = v & 0x1; }],
[0xa00, 0xa07, 0x7, this.setBlitter.bind(this)],
[0xbff, 0xbff, 0, (a, v) => { if (v == 0x39) { this.watchdog_counter = INITIAL_WATCHDOG; this.watchdog_enabled = true; } }],
[0xc00, 0xfff, 0x3ff, (a, v) => { this.nvram[a] = v; }],
//[0x0, 0xfff, 0, function(a,v) { console.log('iowrite',hex(a),hex(v)); }],
]);
var memread_robotron = newAddressDecoder([
[0x0000, 0x8fff, 0xffff, (a) => { return this.banksel ? this.rom[a] : this.ram[a]; }],
[0x9000, 0xbfff, 0xffff, (a) => { return this.ram[a]; }],
[0xc000, 0xcfff, 0x0fff, ioread_robotron],
[0xd000, 0xffff, 0xffff, (a) => { return this.rom ? this.rom[a - 0x4000] : 0; }],
]);
var memwrite_robotron = newAddressDecoder([
[0x0000, 0x97ff, 0, this.write_display_byte.bind(this)],
[0x9800, 0xbfff, 0, (a, v) => { this.ram[a] = v; }],
[0xc000, 0xcfff, 0x0fff, iowrite_robotron.bind(this)],
//[0x0000, 0xffff, 0, function(a,v) { console.log(hex(a), hex(v)); }],
]);
var memread_williams = isDefender ? memread_defender : memread_robotron;
var memwrite_williams = isDefender ? memwrite_defender : memwrite_robotron;
this.membus = {
read: memread_williams,
write: memwrite_williams,
};
this.membus = this.probeMemoryBus(this.membus);
this.readAddress = this.membus.read;
}
initAudio() {
this.master = new MasterAudio();
this.worker = new Worker("./src/common/audio/z80worker.js");
let workerchannel = new WorkerSoundChannel(this.worker);
this.master.master.addChannel(workerchannel);
}
initCPU() {
this.rom = new Uint8Array(this.defaultROMSize);
this.cpu = this.newCPU(this.membus);
//this.connectCPUMemoryBus(this);
}
newCPU(membus: MemoryBus) {
var cpu = Object.create(CPU6809());
cpu.init(membus.write, membus.read, 0);
return cpu;
}
readAddress;
// d1d6 ldu $11 / beq $d1ed
setPalette(a, v) {
// RRRGGGBB
var color = 0xff000000 | ((v & 7) << 5) | (((v >> 3) & 7) << 13) | (((v >> 6) << 22));
if (color != this.palette[a]) {
this.palette[a] = color;
this.screenNeedsRefresh = true;
}
}
write_display_byte(a: number, v: number) {
this.ram[a] = v;
this.drawDisplayByte(a, v);
if (this.displayPCs) this.displayPCs[a] = this.cpu.getPC(); // save program counter
}
drawDisplayByte(a, v) {
var ofs = ((a & 0xff00) << 1) | ((a & 0xff) ^ 0xff);
this.pixels[ofs] = this.palette[v >> 4];
this.pixels[ofs + 256] = this.palette[v & 0xf];
}
setBlitter(a, v) {
if (a) {
this.blitregs[a] = v;
} else {
var cycles = this.doBlit(v);
this.waitCycles -= cycles * this.cpuScale; // wait CPU cycles
}
}
doBlit(flags) {
//console.log(hex(flags), blitregs);
flags &= 0xff;
var offs = SCREEN_HEIGHT - this.blitregs[7];
var sstart = (this.blitregs[2] << 8) + this.blitregs[3];
var dstart = (this.blitregs[4] << 8) + this.blitregs[5];
var w = this.blitregs[6] ^ 4; // blitter bug fix
var h = this.blitregs[7] ^ 4;
if (w == 0) w++;
if (h == 0) h++;
if (h == 255) h++;
var sxinc = (flags & 0x1) ? 256 : 1;
var syinc = (flags & 0x1) ? 1 : w;
var dxinc = (flags & 0x2) ? 256 : 1;
var dyinc = (flags & 0x2) ? 1 : w;
var pixdata = 0;
for (var y = 0; y < h; y++) {
var source = sstart & 0xffff;
var dest = dstart & 0xffff;
for (var x = 0; x < w; x++) {
var data = this.membus.read(source);
if (flags & 0x20) {
pixdata = (pixdata << 8) | data;
this.blit_pixel(dest, (pixdata >> 4) & 0xff, flags);
} else {
this.blit_pixel(dest, data, flags);
}
source += sxinc;
source &= 0xffff;
dest += dxinc;
dest &= 0xffff;
}
if (flags & 0x2)
dstart = (dstart & 0xff00) | ((dstart + dyinc) & 0xff);
else
dstart += dyinc;
if (flags & 0x1)
sstart = (sstart & 0xff00) | ((sstart + syinc) & 0xff);
else
sstart += syinc;
}
return w * h * (2 + ((flags & 0x4) >> 2)); // # of memory accesses
}
blit_pixel(dstaddr, srcdata, flags) {
var curpix = dstaddr < 0xc000 ? this.ram[dstaddr] : this.membus.read(dstaddr);
var solid = this.blitregs[1];
var keepmask = 0xff; //what part of original dst byte should be kept, based on NO_EVEN and NO_ODD flags
//even pixel (D7-D4)
if ((flags & 0x8) && !(srcdata & 0xf0)) { //FG only and src even pixel=0
if (flags & 0x80) keepmask &= 0x0f; // no even
} else {
if (!(flags & 0x80)) keepmask &= 0x0f; // not no even
}
//odd pixel (D3-D0)
if ((flags & 0x8) && !(srcdata & 0x0f)) { //FG only and src odd pixel=0
if (flags & 0x40) keepmask &= 0xf0; // no odd
} else {
if (!(flags & 0x40)) keepmask &= 0xf0; // not no odd
}
curpix &= keepmask;
if (flags & 0x10) // solid bit
curpix |= (solid & ~keepmask);
else
curpix |= (srcdata & ~keepmask);
if (dstaddr < 0x9800) // can cause recursion otherwise
this.membus.write(dstaddr, curpix);
}
startScanline(): void {
this.audio && this.audioadapter && this.audioadapter.generate(this.audio);
// TODO: line-by-line
if (this.screenNeedsRefresh && this.scanline == 0) {
for (var i = 0; i < 0x9800; i++)
this.drawDisplayByte(i, this.ram[i]);
this.screenNeedsRefresh = false;
}
if (this.scanline == 0 && this.watchdog_enabled && this.watchdog_counter-- <= 0) {
console.log("WATCHDOG FIRED, PC =", this.cpu.getPC().toString(16)); // TODO: alert on video
// TODO: this.breakpointHit(cpu.T());
this.reset();
}
}
drawScanline(): void {
// interrupts happen every 1/4 of the screen
let sl = this.scanline;
if (sl == 0 || sl == 0x3c || sl == 0xbc || sl == 0xfc) {
if (!this.isDefender || this.pia6821[7] == 0x3c) { // TODO?
if (this.cpu.interrupt)
this.cpu.interrupt();
if (this.cpu.requestInterrupt)
this.cpu.requestInterrupt();
}
}
}
read(a: number): number {
return this.membus.read(a);
}
write(a: number, v: number): void {
this.membus.write(a, v);
}
readConst(a: number): number {
if (a >= 0xc000 && a <= 0xcbff) return 0xff;
else return this.membus.read(a); // TODO
}
reset() {
super.reset();
this.watchdog_counter = INITIAL_WATCHDOG;
this.watchdog_enabled = false;
this.banksel = 1;
}
loadSoundROM(data) {
console.log("loading sound ROM " + data.length + " bytes");
var soundrom = padBytes(data, 0x4000);
this.worker.postMessage({ rom: soundrom });
}
loadROM(data) {
if (data.length > 2) {
if (this.isDefender) {
this.loadSoundROM(data.slice(0x6800));
data = this.rom.slice(0, 0x6800);
} else if (data.length > 0xc000) {
this.loadSoundROM(data.slice(0xc000));
data = this.rom.slice(0, 0xc000);
} else if (data.length > 0x9000 && data[0x9000]) {
this.loadSoundROM(data.slice(0x9000));
}
data = padBytes(data, 0xc000);
}
super.loadROM(data);
}
loadState(state) {
this.cpu.loadState(state.c);
this.ram.set(state.ram);
this.nvram.set(state.nvram);
this.pia6821.set(state.inputs);
this.blitregs.set(state.blt);
this.watchdog_counter = state.wdc;
this.banksel = state.bs;
this.portsel = state.ps;
}
saveState() {
return {
c: this.cpu.saveState(),
ram: this.ram.slice(0),
nvram: this.nvram.slice(0),
inputs: this.pia6821.slice(0),
blt: this.blitregs.slice(0),
wdc: this.watchdog_counter,
bs: this.banksel,
ps: this.portsel,
};
}
loadControlsState(state) {
this.pia6821.set(state.inputs);
}
saveControlsState() {
return {
inputs: this.pia6821.slice(0),
};
}
}

View File

@ -1,5 +1,5 @@
import { SG1000, SMS } from "../machine/sms";
import { GameGear, SG1000, SMS } from "../machine/sms";
import { Platform, BaseZ80MachinePlatform } from "../common/baseplatform";
import { PLATFORMS } from "../common/emu";
@ -46,7 +46,17 @@ class SMSPlatform extends BaseZ80MachinePlatform<SMS> implements Platform {
readVRAMAddress(a) { return this.machine.readVRAMAddress(a); }
}
class GameGearPlatform extends BaseZ80MachinePlatform<GameGear> implements Platform {
newMachine() { return new GameGear(); }
getPresets() { return SMS_PRESETS; }
getDefaultExtension() { return ".c"; };
readAddress(a) { return this.machine.read(a); }
readVRAMAddress(a) { return this.machine.readVRAMAddress(a); }
}
///
PLATFORMS['sms-sg1000-libcv'] = SG1000Platform;
PLATFORMS['sms-sms-libcv'] = SMSPlatform;
PLATFORMS['sms-gg-libcv'] = GameGearPlatform;

View File

@ -1,8 +1,11 @@
import { Platform, BaseZ80Platform, Base6809Platform } from "../common/baseplatform";
import { Platform, BaseZ80Platform, Base6809Platform, Base6809MachinePlatform } from "../common/baseplatform";
import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap } from "../common/emu";
import { hex } from "../common/util";
import { MasterAudio, WorkerSoundChannel } from "../common/audio";
import { WilliamsMachine } from "../machine/williams";
// https://www.arcade-museum.com/manuals-videogames/D/Defender.pdf
var WILLIAMS_PRESETS = [
{ id: 'gfxtest.c', name: 'Graphics Test' },
@ -469,7 +472,23 @@ var WilliamsDefenderPlatform = function(mainElement, options) {
] } };
}
PLATFORMS['williams'] = Williams6809Platform;
class NewWilliamsPlatform extends Base6809MachinePlatform<WilliamsMachine> implements Platform {
newMachine() { return new WilliamsMachine(false); }
getPresets() { return WILLIAMS_PRESETS; }
getDefaultExtension() { return ".c"; };
readAddress(a) { return this.machine.readConst(a); }
getMemoryMap() {
return { main:[
{name:'Video RAM',start:0x0000,size:0xc000,type:'ram'},
{name:'I/O Registers',start:0xc000,size:0xc00,type:'io'},
{name:'NVRAM',start:0xcc00,size:0x400,type:'ram'},
{name:'ROM',start:0xd000,size:0x3000,type:'rom'},
] } };
}
PLATFORMS['williams'] = NewWilliamsPlatform;
PLATFORMS['williams.old'] = Williams6809Platform;
PLATFORMS['williams-defender'] = WilliamsDefenderPlatform;
PLATFORMS['williams-z80'] = WilliamsZ80Platform;

View File

@ -388,6 +388,7 @@ var PLATFORM_PARAMS = {
};
PLATFORM_PARAMS['sms-sms-libcv'] = PLATFORM_PARAMS['sms-sg1000-libcv'];
PLATFORM_PARAMS['sms-gg-libcv'] = PLATFORM_PARAMS['sms-sms-libcv'];
var _t1;
export function starttime() { _t1 = new Date(); }
@ -1060,6 +1061,8 @@ export function preprocessMCPP(step:BuildStep, filesys:string) {
if (step.mainfile) {
args.unshift.apply(args, ["-D", "__MAIN__"]);
}
let platform_def = (platform.toUpperCase() as any).replaceAll(/[^a-zA-Z0-9]/g,'_');
args.unshift.apply(args, ["-D", `__PLATFORM_${platform_def}__`]);
if (params.extra_preproc_args) {
args.push.apply(args, params.extra_preproc_args);
}