From 0131ed15f35320efc2d27e594e439b4361f4aec0 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 5 Jul 2020 12:36:41 -0500 Subject: [PATCH] apple2: can read from boot prom --- doc/notes.txt | 48 +++++++++++++++++++++++++++++++++++++++++++ scripts/dist.sh | 11 ++++++++++ scripts/sync-dev.sh | 4 ++-- src/machine/apple2.ts | 47 +++++++++++++++++++++++++----------------- 4 files changed, 89 insertions(+), 21 deletions(-) create mode 100755 scripts/dist.sh diff --git a/doc/notes.txt b/doc/notes.txt index 5bc55501..a5bde2a5 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -436,3 +436,51 @@ https://bellard.org/tcc/ https://wiki.osdev.org/Smaller_C https://yasm.tortall.net/ https://wiki.osdev.org/Tool_Comparison + + +COMPONENT EMULATION + +Emulate discrete chips +- verilog +- js +- wasm? (overhead?) +Block diagram level +Buses +Insn/cycle timing +Pos/neg clock edge +Timers +Polling vs. callbacks (https://github.com/floooh/chips) +- callbacks might only affect devices internally, until next cycle +CRT simulator +Move leaf nodes to workers (sound chips) +CPU opcode-step switch: https://floooh.github.io/2019/12/13/cycle-stepped-6502.html +- macros are cool! +Inspect bus edges and internal state + +type Bits = number; +interface Clocked { } +interface BusListener { + recv(value : Bits) : void; +} +class Bus { + listeners : BusListener; + send(value : Bits) : void { + } +} +function bus(bits : number) { + return function( + target: any, + propertyKey: string, + descriptor: PropertyDescriptor + ) { + //descriptor.configurable = value; + }; +} +class M6502_T { + IR : Bits<16>; /* internal instruction register */ + addr : Bus<16>; + data : Bus<8>; + + @bus(16) address : Bus<16>; +} + diff --git a/scripts/dist.sh b/scripts/dist.sh new file mode 100755 index 00000000..1a22e133 --- /dev/null +++ b/scripts/dist.sh @@ -0,0 +1,11 @@ +# https://github.com/Kentzo/git-archive-all +# build archives +export VERSION=`git tag | tail -1` +export OUTDIR=dist +echo Creating $OUTDIR +git-archive-all --prefix . release/$OUTDIR.zip +zip -9r release/$OUTDIR.zip gen +mkdir $OUTDIR +cd $OUTDIR +unzip ../release/$OUTDIR.zip + diff --git a/scripts/sync-dev.sh b/scripts/sync-dev.sh index e98aa600..9f8f6d43 100755 --- a/scripts/sync-dev.sh +++ b/scripts/sync-dev.sh @@ -2,5 +2,5 @@ . ./scripts/env.sh DESTPATH=$RSYNC_PATH/dev/ -git ls-files -z | rsync --stats --exclude '.*' --exclude 'scripts/*' --exclude=node_modules -ril --chmod=a+rx -e "ssh" --files-from - -0 . $DESTPATH -rsync --stats -rpilvz --chmod=a+rx -e "ssh" ./gen config.js $DESTPATH/ +git ls-files -z | rsync --stats -riltz --exclude '.*' --exclude 'scripts/*' --exclude=node_modules --chmod=a+rx -e "ssh" --files-from - -0 . $DESTPATH +rsync --stats -riltz --chmod=a+rx -e "ssh" ./gen config.js $DESTPATH/ diff --git a/src/machine/apple2.ts b/src/machine/apple2.ts index 2d363695..d10a2848 100644 --- a/src/machine/apple2.ts +++ b/src/machine/apple2.ts @@ -28,7 +28,7 @@ interface AppleIIControlsState { interface AppleIIState extends AppleIIStateBase, AppleIIControlsState { c : MOS6502State; grswitch : number; - slots: any[]; + slots: SlotDevice[]; } interface SlotDevice extends Bus { @@ -147,30 +147,40 @@ export class AppleII extends BasicScanlineMachine { this.auxRAMselected = false; this.auxRAMbank = 1; this.writeinhibit = true; + this.skipboot(); + } + skipboot() { // execute until $c600 boot for (var i=0; i<2000000; i++) { this.cpu.advanceClock(); - if (this.cpu.getPC() == 0xc602) { - break; - } + if ((this.cpu.getPC()>>8) == 0xc6) break; + } + // get out of $c600 boot + for (var i=0; i<2000000; i++) { + this.cpu.advanceClock(); + if ((this.cpu.getPC()>>8) < 0xc6) break; } } noise() : number { return (this.rnd = xorshift32(this.rnd)) & 0xff; } - readConst(address:number) : number { - if (address < 0xc000) { - return this.ram[address]; - } else if (address >= 0xd000) { - if (!this.auxRAMselected) - return this.bios[address - 0xd000]; - else if (address >= 0xe000) - return this.ram[address]; - else - return this.ram[address + this.bank2rdoffset]; - } else - return 0; - } + readConst(address: number): number { + if (address < 0xc000) { + return this.ram[address]; + } else if (address >= 0xd000) { + if (!this.auxRAMselected) + return this.bios[address - 0xd000]; + else if (address >= 0xe000) + return this.ram[address]; + else + return this.ram[address + this.bank2rdoffset]; + } else if (address >= 0xc100 && address < 0xc800) { + var slot = (address >> 8) & 7; + return (this.slots[slot] && this.slots[slot].readROM(address & 0xff)) | 0; + } else { + return 0; + } + } read(address:number) : number { address &= 0xffff; if (address < 0xc000 || address >= 0xd000) { @@ -221,8 +231,7 @@ export class AppleII extends BasicScanlineMachine { return (this.slots[slot-8] && this.slots[slot-8].read(address & 0xf)) | 0; } } else if (address >= 0xc100 && address < 0xc800) { - var slot = (address >> 8) & 7; - return (this.slots[slot] && this.slots[slot].readROM(address & 0xff)) | 0; + return this.readConst(address); } return this.noise(); }