vic20: added cart support, fixed bugs

This commit is contained in:
Steven Hugg 2022-09-06 13:53:45 -05:00
parent 30342d2618
commit 3853f9a86a
6 changed files with 62 additions and 31 deletions

View File

@ -0,0 +1,16 @@
processor 6502
org $a000-2 ; so we can write the ...
.word $a000 ; cartridge 2-byte header
.word Start ; start vector
.word Start ; RESTORE vector
.byte $41, $30, $c3, $c2, $cd ; "A0CBM"
Start:
lda $9004
WaitLine;
cmp $9004
beq WaitLine
sta $900f
jmp Start

View File

@ -205,6 +205,7 @@ void declare_winner(byte winner) {
void play_round() { void play_round() {
reset_players(); reset_players();
clrscr(); clrscr();
bgcolor(COLOR_BLUE);
textcolor(COLOR_WHITE); textcolor(COLOR_WHITE);
draw_playfield(); draw_playfield();
while (1) { while (1) {

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,10 @@
//// WASM Machine //// WASM Machine
// http://www.zimmers.net/anonftp/pub/cbm/documents/chipdata/VIC-I.txt
// http://www.zimmers.net/anonftp/pub/cbm/maps/Vic20.MemoryMap.txt
// http://sleepingelephant.com/denial/wiki/index.php/Autostart
import { Machine } from "../common/baseplatform"; import { Machine } from "../common/baseplatform";
import { Probeable, TrapCondition } from "../common/devices"; import { Probeable, TrapCondition } from "../common/devices";
import { KeyFlags } from "../common/emu"; import { KeyFlags } from "../common/emu";
@ -10,7 +14,7 @@ import { BaseWASMMachine } from "../common/wasmplatform";
export class VIC20_WASMMachine extends BaseWASMMachine implements Machine, Probeable { export class VIC20_WASMMachine extends BaseWASMMachine implements Machine, Probeable {
numTotalScanlines = 312; numTotalScanlines = 312;
cpuCyclesPerLine = 63; cpuCyclesPerLine = 71;
videoOffsetBytes = -24 * 4; videoOffsetBytes = -24 * 4;
prgstart : number; prgstart : number;
@ -30,42 +34,47 @@ export class VIC20_WASMMachine extends BaseWASMMachine implements Machine, Probe
} }
// load rom // load rom
if (this.romptr && this.romlen) { if (this.romptr && this.romlen) {
let rom = this.romarr;
this.exports.machine_load_rom(this.sys, this.romptr, this.romlen); this.exports.machine_load_rom(this.sys, this.romptr, this.romlen);
this.prgstart = this.romarr[0] + (this.romarr[1]<<8); // get load address let iscart = rom[4+2]==0x41 && rom[5+2]==0x30 && rom[6+2]==0xC3 && rom[7+2]==0xC2 && rom[8+2]==0xCD;
// look for BASIC program start if (!iscart) {
if (this.prgstart == 0x1001) { this.prgstart = rom[0] + (rom[1]<<8); // get load address
this.prgstart = this.romarr[2] + (this.romarr[3]<<8) + 2; // point to after BASIC program // look for BASIC program start
console.log("prgstart", hex(this.prgstart)); if (this.prgstart == 0x1001) {
} this.prgstart = rom[2] + (rom[3]<<8) + 2; // point to after BASIC program
// is program loaded into RAM? console.log("prgstart", hex(this.prgstart));
if (this.prgstart < 0x8000) {
// advance BIOS a few frames
this.exports.machine_exec(this.sys, 400000);
// type in command (SYS 2061)
var cmd = "SYS "+this.prgstart+"\r";
console.log(cmd);
for (var i=0; i<cmd.length; i++) {
var key = cmd.charCodeAt(i);
this.exports.machine_exec(this.sys, 20000);
this.exports.machine_exec(this.sys, 20000);
this.exports.machine_key_down(this.sys, key);
this.exports.machine_exec(this.sys, 20000);
this.exports.machine_exec(this.sys, 20000);
this.exports.machine_key_up(this.sys, key);
} }
// advance clock until program starts // is program loaded into RAM?
for (var i=0; i<10000 && this.getPC() != this.prgstart; i++) { if (this.prgstart < 0x8000) {
//this.exports.machine_tick(this.sys); // advance BIOS a few frames
this.exports.machine_exec(this.sys, 500000);
// type in command (SYS 2061)
var cmd = "SYS "+this.prgstart+"\r";
console.log(cmd);
for (var i=0; i<cmd.length; i++) {
var key = cmd.charCodeAt(i);
this.exports.machine_exec(this.sys, 10000);
this.exports.machine_exec(this.sys, 10000);
this.exports.machine_key_down(this.sys, key);
this.exports.machine_exec(this.sys, 10000);
this.exports.machine_exec(this.sys, 10000);
this.exports.machine_key_up(this.sys, key);
}
// advance clock until program starts
for (var i=0; i<10000 && this.getPC() != this.prgstart; i++) {
this.exports.machine_tick(this.sys);
}
} }
} else { } else {
// get out of reset // get out of reset
this.exports.machine_exec(this.sys, 100); //this.exports.machine_exec(this.sys, 100);
// wait until cartridge start // wait until cartridge start
// TODO: detect ROM cartridge // TODO: detect ROM cartridge
var warmstart = this.romarr[0x4] + this.romarr[0x5]*256; var warmstart = this.romarr[0x2+2] + this.romarr[0x3+2]*256;
for (var i=0; i<150000 && this.getPC() != warmstart; i++) { for (var i=0; i<10000 && this.getPC() != warmstart; i++) {
this.exports.machine_tick(this.sys); this.exports.machine_tick(this.sys);
} }
console.log('cart', i, hex(warmstart));
} }
// TODO: shouldn't we return here @ start of frame? // TODO: shouldn't we return here @ start of frame?
// and stop probing // and stop probing
@ -74,7 +83,7 @@ export class VIC20_WASMMachine extends BaseWASMMachine implements Machine, Probe
advanceFrame(trap: TrapCondition) : number { advanceFrame(trap: TrapCondition) : number {
// TODO: does this sync with VSYNC? // TODO: does this sync with VSYNC?
var scanline = this.getRasterY(); var scanline = this.getRasterY();
var clocks = Math.floor((this.numTotalScanlines - scanline) * 19656 / this.numTotalScanlines); var clocks = Math.floor((this.numTotalScanlines - scanline) * 22152 / this.numTotalScanlines);
var probing = this.probe != null; var probing = this.probe != null;
if (probing) this.exports.machine_reset_probe_buffer(); if (probing) this.exports.machine_reset_probe_buffer();
clocks = super.advanceFrameClock(trap, clocks); clocks = super.advanceFrameClock(trap, clocks);

View File

@ -6,18 +6,23 @@ import { BaseMAME6502Platform } from "../common/mameplatform";
const VIC20_PRESETS = [ const VIC20_PRESETS = [
{id:'hello.dasm', name:'Hello World (ASM)'}, {id:'hello.dasm', name:'Hello World (ASM)'},
{id:'hellocart.dasm', name:'Hello Cartridge (ASM)'},
{id:'siegegame.c', name:'Siege Game (C)'}, {id:'siegegame.c', name:'Siege Game (C)'},
]; ];
const VIC20_MEMORY_MAP = { main:[ const VIC20_MEMORY_MAP = { main:[
{name:'RAM', start:0x0000,size:0x0400,type:'ram'}, {name:'RAM', start:0x0000,size:0x0400,type:'ram'},
{name:'RAM', start:0x1000,size:0x1000,type:'ram'}, {name:'RAM', start:0x1000,size:0x1000,type:'ram'},
{name:'Cartridge ROM',start:0x8000,size:0x2000,type:'rom'}, {name:'BLK1 Cart ROM',start:0x2000,size:0x2000,type:'rom'},
{name:'BASIC ROM', start:0xc000,size:0x2000,type:'rom'}, {name:'BLK2 Cart ROM',start:0x4000,size:0x2000,type:'rom'},
{name:'BLK3 Cart ROM',start:0x6000,size:0x2000,type:'rom'},
{name:'Character ROM',start:0x8000,size:0x1000,type:'rom'},
{name:'I/O 1', start:0x9000,size:0x0400,type:'io'}, {name:'I/O 1', start:0x9000,size:0x0400,type:'io'},
{name:'Color RAM', start:0x9400,size:0x0400,type:'io'}, {name:'Color RAM', start:0x9400,size:0x0400,type:'io'},
{name:'I/O 2', start:0x9800,size:0x0400,type:'io'}, {name:'I/O 2', start:0x9800,size:0x0400,type:'io'},
{name:'I/O 3', start:0x9c00,size:0x0400,type:'io'}, {name:'I/O 3', start:0x9c00,size:0x0400,type:'io'},
{name:'BLK5 Autostart',start:0xa000,size:0x2000,type:'rom'},
{name:'BASIC ROM', start:0xc000,size:0x2000,type:'rom'},
{name:'KERNAL ROM', start:0xe000,size:0x2000,type:'rom'}, {name:'KERNAL ROM', start:0xe000,size:0x2000,type:'rom'},
] } ] }