//
-// Thunder: A Rolling Thunder Emulator w/6809 debugger v0.40
-// (Last build: 3/6/2004)
+// Thunder: A Rolling Thunder Emulator
//
-// by James L. Hammons
+// by James Hammons
+// (C) 2004, 2014 Underground Software
//
-// (c) 2004 Underground Software
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO WHEN WHAT
+// --- ---------- -----------------------------------------------------------
+// JLH 07/23/2009 Added changelog ;-)
+// JLH 08/12/2009 Stabilized emulation so that it works
+// JLH 04/04/2014 Converted to SDL 2
+// JLH 04/17/2014 Removed a metric fuck-tonne of cruft, added YM2151 & MCU
//
-#define THUNDER_VERSION "0.4.0"
-#define THUNDER_BETA_VERSION "6"
+#define THUNDER_VERSION "1.1.0"
+#include <SDL2/SDL.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <new>
#include <stdio.h>
#include <stdlib.h>
-#include <conio.h> // For getch()
+#include <stdint.h>
#include <time.h>
-#include "SDL.h" // Get yer SDL out...!
-#include "types.h"
-#include "v6809.h"
-#include "screen.h"
#include "gui.h"
#include "log.h"
+#include "psg.h"
+#include "screen.h"
+#include "sound.h"
+#include "v63701.h"
+#include "v6809.h"
+#include "video.h"
+#include "ym2151.h"
+
+
+using namespace std;
+
-using namespace std; // Yes!
-
-/*
-#define ROM1 "RT3-1B.ROM"
-#define ROM2 "RT3-2B.ROM"
-#define ROM3 "RT3-3.ROM"
-#define ROM4 "RT3-4.ROM"
-#define ROM5 "RT1-5.ROM"
-#define ROM6 "RT1-6.ROM"
-#define ROM7 "RT1-7.ROM"
-#define ROM8 "RT1-8.ROM"
-#define ROM9 "RT1-9.ROM"
-#define ROM10 "RT1-10.ROM"
-#define ROM11 "RT1-11.ROM"
-#define ROM12 "RT1-12.ROM"
-#define ROM13 "RT1-13.ROM"
-#define ROM14 "RT1-14.ROM"
-#define ROM15 "RT1-15.ROM"
-#define ROM16 "RT1-16.ROM"
-#define ROM17 "RT1-17.ROM"
-#define ROM18 "RT1-18.ROM"
-#define ROM19 "RT3-19.ROM"
-#define ROM20 "RT3-20.ROM"
-#define ROM21 "RT1-21.ROM"
-#define ROM22 "RT2-22.ROM"
-#define PROM1 "RT1-1.BIN"
-#define PROM2 "RT1-2.BIN"
-#define PROM3 "RT1-3.BIN"
-#define PROM4 "RT1-4.BIN"
-#define PROM5 "RT1-5.BIN"
-*/
#define ROM1 "rt3-1b.9c"
#define ROM2 "rt3-2b.12c"
#define ROM3 "rt3-3.12d"
#define PROM5 "mb7112e.6u"
#define MCUROM "rt1-mcu.bin"
+
// Global defines
SDL_Surface * screen;
-BYTE * gram, * grom; // Allocate RAM & ROM pointers
-BYTE * gram1, * gram2, * grom1, * grom2; // Actual memory
-BYTE * grom3, * grom4, * data_rom, * spr_rom, * voice_rom;
-BYTE * chr_rom; // Character ROM pointer
-
-V6809REGS cpu1, cpu2;
-
-bool trace = false; // ditto...
-bool looking_at_rom = true; // true = R1, false = R2
-DWORD banksw1, banksw2; // Bank switch addresses
-WORD game_over_switch; // Game over delay
-WORD dpc; // Debug pc reg...
-bool show_scr = true; // Whether or not to show background
-bool enable_cpu = true; // Whether or not to enable CPUs
-bool irqGoA = true; // IRQ switch for CPU #1
-bool irqGoB = true; // IRQ switch for CPU #2
-
-WORD refresh = 0; // Crappy global screen stuff...
+uint8_t * gram, * grom; // Allocate RAM & ROM pointers
+// Actual memory
+uint8_t gram1[0x10000], gram2[0x10000], grom1[0x10000], grom2[0x10000];
+uint8_t grom3[0x8000], data_rom[0x40000], spr_rom[0x80000], voice_rom[0x20000];
+uint8_t chr_rom[0x60000]; // Character ROM pointer
+uint8_t mcuMem[0x10000]; // 64K for MCU
+
+V6809REGS cpu1, cpu2; // CPU execution contexts
+V63701REGS mcu;
+
+bool trace1 = false; // ditto...
+bool looking_at_rom = true; // true = R1, false = R2
+uint32_t banksw1, banksw2; // Bank switch addresses
+uint16_t game_over_switch; // Game over delay
+uint16_t dpc; // Debug pc reg...
+bool show_scr = true; // Whether or not to show background
+bool enable_cpu = true; // Whether or not to enable CPUs
+bool irqGoA = true; // IRQ switch for CPU #1
+bool irqGoB = true; // IRQ switch for CPU #2
+
+uint16_t refresh_ = 0; // Crappy global screen stuff...
bool refresh2 = true;
-DWORD psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-BYTE * psg_adrs[16];
-DWORD voc_lens[32] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-BYTE * voc_adrs[32];
-DWORD fm_lens[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-BYTE * fm_adrs[14];
-
-fstream tr; // Tracelog hook
-WORD pcx; // Where we at?
-
-static char op_mat1[256] = {
- 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
- 0, 0, 5, 5, 0, 0, 4, 4, 0, 5, 8, 0, 8, 5, 6, 6,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 7, 7, 7, 7, 6, 6, 6, 6, 0, 5, 5, 5, 8, 5, 5, 5,
- 5, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 0, 5, 5, 0, 5,
- 5, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 0, 5, 5, 0, 5,
- 7, 0, 0, 7, 7, 0, 7, 7, 7, 7, 7, 0, 7, 7, 7, 7,
- 2, 0, 0, 2, 2, 0, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2,
- 8, 8, 8, 9, 8, 8, 8, 0, 8, 8, 8, 8, 9, 3, 9, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 8, 8, 8, 9, 8, 8, 8, 0, 8, 8, 8, 8, 9, 0, 9, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
-op_mat2[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 0,
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 7, 7,
- 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 2,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2 },
-op_mat3[256] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0,
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
- 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
- 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-static char mnemonics[256][6] = {
- "NEG ","??? ","??? ","COM ","LSR ","??? ","ROR ","ASR ",
- "LSL ","ROL ","DEC ","??? ","INC ","TST ","JMP ","CLR ",
- "PAGE1","PAGE2","NOP ","SYNC ","??? ","??? ","LBRA ","LBSR ",
- "??? ","DAA ","ORCC ","??? ","ANDCC","SEX ","EXG ","TFR ",
- "BRA ","BRN ","BHI ","BLS ","BHS ","BLO ","BNE ","BEQ ",
- "BVC ","BVS ","BPL ","BMI ","BGE ","BLT ","BGT ","BLE ",
- "LEAX ","LEAY ","LEAS ","LEAU ","PSHS ","PULS ","PSHU ","PULU ",
- "??? ","RTS ","ABX ","RTI ","CWAI ","MUL ","RESET","SWI ",
- "NEGA ","??? ","??? ","COMA ","LSRA ","??? ","RORA ","ASRA ",
- "LSLA ","ROLA ","DECA ","??? ","INCA ","TSTA ","??? ","CLRA ",
- "NEGB ","??? ","??? ","COMB ","LSRB ","??? ","RORB ","ASRB ",
- "LSLB ","ROLB ","DECB ","??? ","INCB ","TSTB ","??? ","CLRB ",
- "NEG ","??? ","??? ","COM ","LSR ","??? ","ROR ","ASR ",
- "LSL ","ROL ","DEC ","??? ","INC ","TST ","JMP ","CLR ",
- "NEG ","??? ","??? ","COM ","LSR ","??? ","ROR ","ASR ",
- "LSL ","ROL ","DEC ","??? ","INC ","TST ","JMP ","CLR ",
- "SUBA ","CMPA ","SCBA ","SUBD ","ANDA ","BITA ","LDA ","??? ",
- "EORA ","ADCA ","ORA ","ADDA ","CMPX ","BSR ","LDX ","??? ",
- "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA ","STA ",
- "EORA ","ADCA ","ORA ","ADDA ","CMPX ","JSR ","LDX ","STX ",
- "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA ","STA ",
- "EORA ","ADCA ","ORA ","ADDA ","CMPX ","JSR ","LDX ","STX ",
- "SUBA ","CMPA ","SBCA ","SUBD ","ANDA ","BITA ","LDA ","STA ",
- "EORA ","ADCA ","ORA ","ADDA ","CMPX ","JSR ","LDX ","STX ",
- "SUBB ","CMPB ","SCBB ","ADDD ","ANDB ","BITB ","LDB ","??? ",
- "EORB ","ADCB ","ORB ","ADDB ","LDD ","??? ","LDU ","??? ",
- "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB ","STB ",
- "EORB ","ADCB ","ORB ","ADDB ","LDD ","STD ","LDU ","STU ",
- "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB ","STB ",
- "EORB ","ADCB ","ORB ","ADDB ","LDD ","STD ","LDU ","STU ",
- "SUBB ","CMPB ","SBCB ","ADDD ","ANDB ","BITB ","LDB ","STB ",
- "EORB ","ADCB ","ORB ","ADDB ","LDD ","STD ","LDU ","STU " },
-mnemonics2[256][6] = {
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","LBRN ","LBHI ","LBLS ","LBHS ","LBLO ","LBNE ","LBEQ ",
- "LBVC ","LBVS ","LBPL ","LBMI ","LBGE ","LBLT ","LBGT ","LBLE ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","SWI2 ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","CMPD ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPY ","??? ","LDY ","??? ",
- "??? ","??? ","??? ","CMPD ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPY ","??? ","LDY ","STY ",
- "??? ","??? ","??? ","CMPD ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPY ","??? ","LDY ","STY ",
- "??? ","??? ","??? ","CMPD ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPY ","??? ","LDY ","STY ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","LDS ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","LDS ","STS ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","LDS ","STS ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","LDS ","STS " },
-mnemonics3[256][6] = {
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","SWI3 ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","CMPU ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPS ","??? ","??? ","??? ",
- "??? ","??? ","??? ","CMPU ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPS ","??? ","??? ","??? ",
- "??? ","??? ","??? ","CMPU ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPS ","??? ","??? ","??? ",
- "??? ","??? ","??? ","CMPU ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","CMPS ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? ",
- "??? ","??? ","??? ","??? ","??? ","??? ","??? ","??? " },
-tregs[16][3] = {
- "D", "X", "Y", "U", "S", "PC", "??", "??",
- "A", "B", "CC", "DP", "??", "??", "??", "??" },
-iregs[4][2] = {"X", "Y", "U", "S" };
+uint32_t psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+uint8_t * psg_adrs[16];
-//
-// Fetch a byte out of memory
-//
-/*BYTE Fetch()
-{
-// extern WORD sr, ur, xr, yr; // Needed for tracelog
- extern WORD pcr;
- BYTE b;
+Byte input1, input2, input3, input4, input5;
- b = (pcr < 0x8000 ? gram1[pcr] : grom1[pcr]);
- pcr++;
+fstream tr; // Tracelog hook
+uint16_t pcx; // Where we at?
- return b;
-}*/
+// Function prototypes
+uint8_t MCUReadMemory(uint16_t address);
+void MCUWriteMemory(uint16_t address, uint8_t data);
-//
-// Fetch a word out of memory (little endian format)
-//
-/*WORD FetchW()
-{
- WORD w = Fetch() << 8; w |= Fetch();
- return w;
-}*/
//
-// Read a byte from memory (without touching PC. Not a Fetch!)
+// Read a byte from memory
//
-BYTE RdMem(WORD addr)
+uint8_t RdMem(uint16_t addr)
{
- BYTE b;
+ uint8_t b;
if (addr < 0x8000)
{
- if (addr > 0x5FFF)
- b = data_rom[banksw1 + (addr - 0x6000)]; // Get char data
+ // Memory shared with MCU (CPU #1 only! CPU #2 does not)
+ if ((addr >= 0x4000) && (addr <= 0x43FF))
+ return mcuMem[addr - 0x3000];
+// if ((addr >= 0x4000) && (addr <= 0x41FF))
+// return MCUReadMemory(addr - 0x3000);
+// if ((addr >= 0x4200) && (addr <= 0x43FF))
+// return mcuMem[addr - 0x3000];
+
+ if (addr >= 0x6000)
+ return data_rom[banksw1 + (addr - 0x6000)]; // Get char data
else
- b = gram1[addr];
+ return gram1[addr];
}
- else
- b = grom1[addr];
- return b;
+ return grom1[addr];
}
+
//
// Write a byte to memory
//
-void WrMem(WORD addr, BYTE b)
+void WrMem(uint16_t address, uint8_t data)
{
- extern bool charbase; // Needed for screen. Extern it in it??
- //extern WORD sr, ur, xr, yr; // Needed for tracelog
- //extern WORD pcr;
-/* if ((addr>0x40FF) && (addr<0x4390))
- {
- tr << hex << addr << ":" << (int)b;
- //for(int i=0; i<32; i++)
- //{
- // if (gram1[0x4400+i]<0x10) tr << "0";
- // tr << hex << (WORD)gram1[0x4400+i] << " ";
- //}
- tr << endl;
- }//*/
-
- if (addr == 0x6000)
- SpawnSound(GAMESOUND, gram1[0x6200], 0); // Do voice chan 1
- if (addr == 0x6400)
- SpawnSound(GAMESOUND, gram1[0x6600], 1); // Do voice chan 2
- if (addr == 0x6800)
- banksw1 = (DWORD)b << 13; // Set char data bankswitch base address
- if (addr > 0x4284 && addr < 0x42A5 && b)
- SpawnSound(PSGSOUND, addr - 0x4285); // Do PSG sound on chans 2, 3
- if (addr == 0x4380)
+ extern bool disasm;
+ extern bool charbase; // Needed for screen. Extern it in it??
+#if 0
+ if (address == 0x4182)
{
- SpawnSound(FMSOUND, b); // Do FM sound on channel 4
- if (b == 12)
- game_over_switch = 240; // Set game over delay...
+ WriteLog("\nWriteMem: CPU #1 writing $%02X to $4182!\n\n", b);
}
- if (addr < 0x423D || addr > 0x425C) // Protect writes to DSWs
- gram1[addr] = b;
- if (addr == 0x8800)
- charbase = false; // Char banksw1
- if (addr == 0x8C00)
- charbase = true; // Char banksw2
- if (addr == 0x8400) // Frame go strobe? VBlank acknowledge?
+#endif
+#if 0
+if (((address >= 0x4180) && (address <= 0x4191)) || (address == 0x4380))
+ printf("WriteMem: CPU #1 writing $%02X to $%04X...\n", b, address);
+#endif
+
+ if (address == 0x6000)
+{
+//printf("Spawning VOICE channel #1: $6000=$%02X, $6200=$%02X\n", b, gram1[0x6200]);
+ SpawnSound(GAMESOUND, gram1[0x6200], 0); // Do voice chan 1
+}
+ if (address == 0x6400)
+{
+//printf("Spawning VOICE channel #2: $6400=$%02X, $6600=$%02X\n", b, gram1[0x6600]);
+ SpawnSound(GAMESOUND, gram1[0x6600], 1); // Do voice chan 2
+}
+ if (address == 0x6800)
+ banksw1 = (uint32_t)data << 13; // Set char data bankswitch base address
+ if (address > 0x4284 && address < 0x42A5 && data)
+ SpawnSound(PSGSOUND, address - 0x4285); // Do PSG sound on chans 2, 3
+
+//if ((address >= 0x4284) && (address < 0x42A5))
+//{
+// printf("WrMem: Wrote $%02X to PSG address $%04X...\n", data, address);
+//}
+ // Memory shared with MCU (CPU #1 only! CPU #2 does not)
+ if ((address >= 0x4000) && (address <= 0x43FF))
+ mcuMem[address - 0x3000] = data;
+// if ((address >= 0x4000) && (address <= 0x41FF))
+// MCUWriteMemory(address - 0x3000, data);
+// if ((address >= 0x4200) && (address <= 0x43FF))
+// mcuMem[address - 0x3000] = data;
+ else
+ gram1[address] = data;
+
+ if (address == 0x8800)
+ charbase = false; // Char banksw1
+ if (address == 0x8C00)
+ charbase = true; // Char banksw2
+ if (address == 0x8400) // Frame go strobe? VBlank acknowledge?
{
- if (refresh++ == 1) // 30 Hz...
- {
- BlitChar(screen, chr_rom, gram1);
- refresh = (refresh2 ? 1 : 0); // 60/30 Hz...
- }
-// irqGoA = true; // Will this work??? no...
- cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
+ BlitChar(screen, chr_rom, gram1);
+
+ // IRQ Ack (may also be frame go...
+ ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
+#if 1
+ if (disasm)
+ WriteLog("WriteMem: CPU #1 Acknowledging IRQ...\n", data);
+#endif
}
}
+
//
-// Fetch a byte out of memory (2nd processor)
+// Read a byte from memory (2nd processor)
//
-/*BYTE FetchB()
+uint8_t RdMemB(uint16_t address)
{
-// extern WORD sr, ur, xr, yr; // Needed for tracelog
- extern WORD pcrB;
- BYTE b;
-
- if (pcrB<0x8000)
- {
- if (pcrB<0x2000)
- b = gram1[pcrB+0x4000];
- if ((pcrB>0x1FFF) && (pcrB<0x6000))
- b = gram1[pcrB-0x2000];
- if (pcrB>0x5FFF)
- b = gram1[pcrB];
- }
- else
- b = grom2[pcrB];
- pcrB++;
-
- return b;
+ if (address < 0x8000)
+ {
+ if (address < 0x2000)
+ return gram1[address + 0x4000];
+ else if ((address >= 0x2000) && (address < 0x6000))
+ return gram1[address - 0x2000];
+ else if (address >= 0x6000)
+ return grom3[banksw2 + (address - 0x6000)];
+ }
+
+ return grom2[address];
}
-//
-// Fetch a word out of memory (little endian format) (2nd processor)
-//
-WORD FetchWB()
-{
- WORD w = FetchB() << 8; w |= FetchB();
- return w;
-}*/
//
-// Read a byte from memory (without touching PC. Not a Fetch!) (2nd processor)
+// Write a byte to memory (2nd processor)
//
-BYTE RdMemB(WORD addr)
+void WrMemB(uint16_t address, uint8_t data)
{
-// extern WORD cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Needed for tracelog
- BYTE b;
+ extern bool disasm;
+ extern bool charbase;
- if (addr < 0x8000)
+ // Set sprite data bank switch
+ if (address == 0xD803)
+ banksw2 = (uint32_t)(data & 0x03) << 13;
+
+ if (address < 0x2000)
+ gram1[address + 0x4000] = data;
+
+ if ((address >= 0x2000) && (address < 0x6000))
+ gram1[address - 0x2000] = data;
+
+ if (address == 0x8800)
{
- if (addr < 0x2000)
- b = gram1[addr + 0x4000];
- if (addr > 0x1FFF && addr < 0x6000)
- b = gram1[addr - 0x2000];
- if (addr > 0x5FFF)
- b = grom3[banksw2 + (addr - 0x6000)]; // Correct?
+ // IRQ Ack (may also be frame go...)
+ ClearLineOfCurrentV6809(V6809_ASSERT_LINE_IRQ);
+#if 1
+ if (disasm)
+ WriteLog("WriteMem: CPU #2 Acknowledging IRQ...\n", data);
+#endif
}
- else
- b = grom2[addr];
-
-/* if ((addr>0x3FFF) && (addr<0x4400)) tr << "R-" << hex << pcx << ": "
- << addr << "-"
- << (int)looking_at_rom
- << " [" << (int)b
- << "] XR:" << xr << " YR:" << yr
- << " SR:" << sr << " UR:" << ur
- << endl; //*/
- return b;
}
-//
-// Write a byte to memory (2nd processor)
-//
-void WrMemB(WORD addr, BYTE b)
+
+uint8_t MCUReadMemory(uint16_t address)
{
- extern bool charbase;
- //extern WORD sr, ur, xr, yr; // Needed for tracelog
- //extern WORD pcr;
-/* if ((addr>0x00FF) && (addr<0x0390))
- {
- tr << hex << addr << ":" << (int)b;
- //for(int i=0; i<32; i++)
- //{
- // if (gram1[0x4400+i]<0x10) tr << "0";
- // tr << hex << (WORD)gram1[0x4400+i] << " ";
- //}
- tr << endl;
- }//*/
-
- if (addr == 0x8800)
-// irqGoB = true; // Will it work??? no...
- cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
- if (addr == 0x6000)
- SpawnSound(GAMESOUND, gram1[0x6200], 0); // Do voice chan 1
- if (addr == 0x6400)
- SpawnSound(GAMESOUND, gram1[0x6600], 1); // Do voice chan 2
- if (addr > 0x0284 && addr < 0x02A5 && b)
- SpawnSound(PSGSOUND, addr - 0x0285); // Do PSG sound on chans 2, 3
- if (addr == 0xD803)
- banksw2 = (DWORD)(b & 0x03) << 13; // Set sprite data bank switch
- if (addr == 0x0380)
+ if (address < 0x20)
+ return InternalRegisterRead(address);
+ else if ((address >= 0x1000) && (address <= 0x113F))
+// else if ((address >= 0x1000) && (address <= 0x11FF))
+ return ReadPSG(address - 0x1000);
+ else if ((address >= 0x2000) && (address <= 0x2001))
+ return YMReadReg(0);
+ // Various joystick + buttons; all are active low.
+ else if (address == 0x2020)
+ return input1.byte;
+ else if (address == 0x2021)
+ return input2.byte;
+ // This is DSW1 & 2. All switch settings are active low.
+ else if (address == 0x2030)
+ return input4.byte;
+ else if (address == 0x2031)
+ return input5.byte;
+
+ return mcuMem[address];
+}
+
+
+void MCUWriteMemory(uint16_t address, uint8_t data)
+{
+ static uint8_t ymRegister;
+
+ if (address < 0x20)
+ {
+ InternalRegisterWrite(address, data);
+ return;
+ }
+ else if (((address >= 0x4000) && (address <= 0xBFFF))
+ || (address >= 0xF000))
+ return;
+ else if ((address >= 0x1000) && (address <= 0x113F))
+// else if ((address >= 0x1000) && (address <= 0x11FF))
+ {
+ WritePSG(address - 0x1000, data);
+ return;
+ }
+ else if (address == 0x2000)
{
- SpawnSound(FMSOUND, b); // Do FM sound on chan 4
- if (b == 12)
- game_over_switch = 240; // Set game over delay...
+ ymRegister = data;
+ return;
}
- if (addr < 0x023D || addr > 0x025C) // Protect writes against DSWs
+ else if (address == 0x2001)
{
- if (addr < 0x2000)
- gram1[addr + 0x4000] = b;
- if (addr > 0x1FFF && addr < 0x6000)
- gram1[addr - 0x2000] = b;
- if (addr > 0x5FFF)
- gram1[addr] = b;
+ YMWriteReg(0, ymRegister, data);
+ return;
}
+
+ // RAM is from $0 - $3FFF, $C000 - $EFFF
+ mcuMem[address] = data;
}
-//
-// Display bytes in mem in hex
-//
-void DisplayBytes(WORD src, unsigned long dst)
+
+uint8_t V63701ReadPort1(void)
{
- BYTE cnt;
- unsigned long i;
-
- printf("%04X: ", src);
- cnt = 0; // Init counter...
- if (src > dst) dst += 0x10000; // That should fix the FFFF bug...
- for(i=src; i<dst; i++)
- {
- printf("%02X ", (BYTE)(looking_at_rom ? RdMem(i) : RdMemB(i)));
- cnt++; // Bump counter...
- }
- for(i=cnt; i<5; i++) // Pad the leftover spaces...
- {
- cout << " ";
- }
+// printf("V63701ReadPort1: Read $%02X...\n", input3.byte);
+ return input3.byte;
}
-// temp crap...
-BYTE Fetch(void) { return 0; }
-WORD FetchW(void) { return 0; }
-BYTE FetchB(void) { return 0; }
-WORD FetchWB(void) { return 0; }
-//
-// Decode a 6809 instruction at 'addr'
-//
-void Decode_6809()
+uint8_t V63701ReadPort2(void)
{
- BYTE (* DFetch)(); // Decode Fetch() pointer...
- WORD (* DFetchW)(); // Decode FetchW() pointer...
- DFetch = (looking_at_rom ? Fetch : FetchB);
- DFetchW = (looking_at_rom ? FetchW : FetchWB);
-
-/* extern*/ WORD pcr, pcrB; // Pull in 'pcr' from '6809.cpp'
- WORD pc_save = pcr, pcB_save = pcrB;
- pcr = dpc; pcrB = dpc;
- BYTE opcode = DFetch(); // Get the opcode ('fetch' cycle)
- BYTE opcode2, operand;
- WORD loperand;
- BYTE admode = op_mat1[opcode]; // addressing mode
- char outbuf[80], mnem[6], tmp[30];
-
- strcpy(mnem, mnemonics[opcode]); // Copy page 1 opcode
- if (opcode == 0x10) // Extended opcode?
- {
- opcode2 = DFetch(); // Then get next byte
- admode = op_mat2[opcode2]; // And use it as index into 'op_mat2'
- strcpy(mnem, mnemonics2[opcode2]); // Overwrite mnemonic
- }
- if (opcode == 0x11) // Same as above...
- {
- opcode2 = DFetch();
- admode = op_mat3[opcode2];
- strcpy(mnem, mnemonics3[opcode2]); // Overwrite mnemonic
- }
- switch(admode) // Decode it...
- {
- case 0: // Illegal
- { sprintf(outbuf, "???"); break; }
- case 1: // Zero page
- { operand = DFetch(); // Get ZP address
- sprintf(outbuf, "%s $%02X", mnem, operand);
- break; }
- case 2: // Absolute
- { loperand = DFetchW(); // Get ABS address
- sprintf(outbuf, "%s $%04X", mnem, loperand);
- break; }
- case 3: // Relative
- { operand = DFetch(); // Get offset
- WORD tmpc = (looking_at_rom ? pcr : pcrB);
- sprintf(outbuf, "%s $%04X", mnem, tmpc+(SWORD)(SBYTE)operand);
- break; }
- case 4: // Long Relative
- { loperand = DFetchW(); // Get long offset
- WORD tmpc = (looking_at_rom ? pcr : pcrB);
- sprintf(outbuf, "%s $%04X", mnem, tmpc+(SWORD)loperand);
- break; }
- case 5: // Inherent
- { sprintf(outbuf, "%s ", mnem);
- break; }
- case 6: // Txfr/exchg/push/pull
- { operand = DFetch(); // Get txfr/exg/push/pull byte
- if ((opcode == 0x1E) || (opcode == 0x1F)) // Is it TXF/EXG?
- {
- sprintf(tmp, "%s,%s", tregs[operand>>4], tregs[operand&0x0F]);
- }
- else
- {
- tmp[0] = 0;
- if (operand&0x01) strcat(tmp, "CC ");
- if (operand&0x02) strcat(tmp, "A ");
- if (operand&0x04) strcat(tmp, "B ");
- if (operand&0x08) strcat(tmp, "DP ");
- if (operand&0x10) strcat(tmp, "X ");
- if (operand&0x20) strcat(tmp, "Y ");
- if (operand&0x40) (((opcode==0x34)||(opcode==0x35))
- ? strcat(tmp, "U ") : strcat(tmp, "S "));
- if (operand&0x80) strcat(tmp, "PC");
- }
- sprintf(outbuf, "%s %s", mnem, tmp);
- break; }
- case 7: // Indexed (the tough one!)
- { operand = DFetch(); // Get IDX byte
- BYTE reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
- lo_nyb = (operand & 0x0F), boff;
- WORD woff;
-
- strcpy(tmp, "??");
- if (!(operand & 0x80)) // Hi bit set? Then decode 4 bit offset
- {
- sprintf(tmp, "(%d),%s", (idxind ? -(16-lo_nyb) : lo_nyb),
- iregs[reg]);
- }
- else // Add the ($nnnn,R) code dude...
- {
- if (idxind)
- {
- switch(lo_nyb)
- {
- case 1: sprintf(tmp, "(,%s++)", iregs[reg]); break;
- case 3: sprintf(tmp, "(,--%s)", iregs[reg]); break;
- case 4: sprintf(tmp, "(,%s)", iregs[reg]); break;
- case 5: sprintf(tmp, "(B,%s)", iregs[reg]); break;
- case 6: sprintf(tmp, "(A,%s)", iregs[reg]); break;
- case 8:
- { boff = DFetch(); sprintf(tmp, "($%02X,%s)", boff,
- iregs[reg]); break; }
- case 9:
- { woff = DFetchW(); sprintf(tmp, "($%04X,%s)", woff,
- iregs[reg]); break; }
- case 11: sprintf(tmp, "(D,%s)", iregs[reg]); break;
- case 12:
- { boff = DFetch(); sprintf(tmp, "($%02X,PC)", boff); break; }
- case 13:
- { woff = DFetchW(); sprintf(tmp, "($%04X,PC)", woff); break; }
- case 15:
- { woff = DFetchW(); sprintf(tmp, "[$%04X]", woff); break; }
- default: strcpy(tmp, "??");
- }
- }
- else
- {
- switch(lo_nyb)
- {
- case 0: sprintf(tmp, ",%s+", iregs[reg]); break;
- case 1: sprintf(tmp, ",%s++", iregs[reg]); break;
- case 2: sprintf(tmp, ",-%s", iregs[reg]); break;
- case 3: sprintf(tmp, ",--%s", iregs[reg]); break;
- case 4: sprintf(tmp, ",%s", iregs[reg]); break;
- case 5: sprintf(tmp, "(B),%s", iregs[reg]); break;
- case 6: sprintf(tmp, "(A),%s", iregs[reg]); break;
- case 8:
- { boff = DFetch(); sprintf(tmp, "($%02X),%s", boff,
- iregs[reg]); break; }
- case 9:
- { woff = DFetchW(); sprintf(tmp, "($%04X),%s", woff,
- iregs[reg]); break; }
- case 11: sprintf(tmp, "(D),%s", iregs[reg]); break;
- case 12:
- { boff = DFetch(); sprintf(tmp, "($%02X),PC", boff); break; }
- case 13:
- { woff = DFetchW(); sprintf(tmp, "($%04X),PC", woff); break; }
- default: strcpy(tmp, "??");
- }
- }
- }
- sprintf(outbuf, "%s %s", mnem, tmp);
- break; }
- case 8: // Immediate
- { operand = DFetch(); // Get IMM byte
- sprintf(outbuf, "%s #$%02X", mnem, operand);
- break; }
- case 9: // Long Immediate
- { loperand = DFetchW(); // Get IMM word
- sprintf(outbuf, "%s #$%04X", mnem, loperand);
- break; }
- }
- DisplayBytes(dpc, (looking_at_rom ? pcr : pcrB)); // Show bytes
- cout << outbuf << endl; // display opcode & addressing, etc
- dpc = (looking_at_rom ? pcr : pcrB); // Advance debug PC
- pcr = pc_save; pcrB = pcB_save; // Restore PCs
+ return 0xFF;
}
-//
-// Convert hex to dec
-//
-WORD htod(char *str)
+
+void V63701WritePort1(uint8_t data)
{
- WORD value = 0;
- int len = strlen(str);
-
- for(int i=0; i<len; i++)
- {
- if (str[i]>='0' && str[i]<='9')
- {
- value = (value<<4) | (unsigned)(str[i]-'0');
- }
- if (str[i]>='a' && str[i]<='f')
- {
- value = (value<<4) | (unsigned)(str[i]-'a')+10;
- }
- if (str[i]>='A' && str[i]<='F')
- {
- value = (value<<4) | (unsigned)(str[i]-'A')+10;
- }
- }
- return(value);
+// printf("V63701WritePort1: Wrote $%02X...\n", data);
}
-//
-// Load 32K file into ROM image space
-//
-bool Load32KImg(char * filename, WORD address)
+
+void V63701WritePort2(uint8_t data)
{
- ifstream ff;
- char ch;
-
- ff.open(filename, ios::binary | ios::in); // Open 'da file...
- if (ff)
- {
- for(long i=0; i<32768; i++) // Read it in...
- {
- ff.get(ch);
- grom[address+i] = ch;
- }
- ff.close(); // Close 'da file...
- }
- return(ff);
+// printf("V63701WritePort2: Wrote $%02X...\n", data);
}
+
//
// Generic Load file into image space
// (No error checking performed! Responsibility of caller!)
//
-bool LoadImg(char * filename, BYTE * mem, DWORD address, DWORD length)
+bool LoadImg(const char * filename, uint8_t * mem, uint32_t address, uint32_t length)
{
- ifstream ff;
- char path[80];
- char ch;
-
- strcpy(path, "./ROMs/");
- strcat(path, filename);
-// ff.open(filename, ios::binary | ios::in); // Open 'da file...
- ff.open(path, ios::binary | ios::in); // Open 'da file...
- if (ff)
- {
- for(DWORD i=0; i<length; i++) // Read it in...
- {
- ff.get(ch);
- mem[address+i] = ch;
- }
- ff.close(); // Close 'da file...
- }
- return(ff);
+ char path[128];
+
+ strcpy(path, "./ROMs/");
+ strcat(path, filename);
+ FILE * file = fopen(path, "rb");
+
+ if (!file)
+ return false;
+
+ fread(&mem[address], 1, length, file);
+ fclose(file);
+
+ return true;
}
+
//
// Read color PROMs
//
bool ReadColorPROMs(void)
{
- fstream ff1, ff2;
-// BYTE ch;
- char ch;
- extern BYTE palette[768]; // Screen physical palette
- extern BYTE ccolor[256][8]; // Character color PROM values
- extern BYTE scolor[128][16]; // Sprite color PROM values
-
- ff1.open("./ROMs/"PROM3, ios::binary|ios::in);
- if (ff1)
- {
- for(int i=0; i<256; i++) // Load char pallete with PROM values
- {
- for(int j=0; j<8; j++)
- {
- ff1.get(ch);
- ccolor[i][j] = (BYTE)ch;
- }
- }
- ff1.close();
- }
- ff1.open("./ROMs/"PROM4, ios::binary|ios::in);
- if (ff1)
- {
- for(int i=0; i<128; i++) // Load sprite pallete with PROM values
- {
- for(int j=0; j<16; j++)
- {
- ff1.get(ch);
- scolor[i][j] = (BYTE)ch;
- }
- }
- ff1.close();
- }
-
- ff1.open("./ROMs/"PROM1, ios::binary|ios::in);
- ff2.open("./ROMs/"PROM2, ios::binary|ios::in);
- if (ff1) // If open was successful...
- {
- for(int i=0; i<768; i+=3)
- {
- ff1.get(ch);
- palette[i] = (BYTE)(ch&0x0F);
- palette[i+1] = (BYTE)(ch>>4);
- ff2.get(ch);
- palette[i+2] = (BYTE)ch;
- }
-
- // Do palette stretching here... I.e. add 0 to hinyb 0, 1 to hinyb 1, etc.
-
- for(int i=0; i<768; i++)
- palette[i] = ((palette[i]<<4)&0xF0) | (palette[i]&0x0F);
-
- ff1.close();
- ff2.close();
- }
- return ff1;
+ fstream ff1, ff2;
+ // uint8_t ch;
+ char ch;
+ extern uint32_t palette[256]; // Screen physical palette
+ extern uint8_t ccolor[256][8]; // Character color PROM values
+ extern uint8_t scolor[128][16]; // Sprite color PROM values
+
+ ff1.open("./ROMs/"PROM3, ios::binary | ios::in);
+
+ if (ff1)
+ {
+ for(int i=0; i<256; i++) // Load char pallete with PROM values
+ {
+ for(int j=0; j<8; j++)
+ {
+ ff1.get(ch);
+ ccolor[i][j] = (uint8_t)ch;
+ }
+ }
+
+ ff1.close();
+ }
+
+ ff1.open("./ROMs/"PROM4, ios::binary | ios::in);
+
+ if (ff1)
+ {
+ for(int i=0; i<128; i++) // Load sprite pallete with PROM values
+ {
+ for(int j=0; j<16; j++)
+ {
+ ff1.get(ch);
+ scolor[i][j] = (uint8_t)ch;
+ }
+ }
+
+ ff1.close();
+ }
+
+ ff1.open("./ROMs/"PROM1, ios::binary | ios::in);
+ ff2.open("./ROMs/"PROM2, ios::binary | ios::in);
+
+ // If open was successful...
+ if (ff1 && ff2)
+ {
+ // Palette is 12-bit RGB, we stretch it to 24-bit
+ for(int i=0; i<256; i++)
+ {
+ char c1, c2;
+ ff1.get(c1);
+ ff2.get(c2);
+ uint8_t r = (uint8_t)c1 & 0x0F;
+ uint8_t g = (uint8_t)c1 >> 4;
+ uint8_t b = (uint8_t)c2;
+ palette[i] = 0xFF000000 | (b << 20) | (b << 16) | (g << 12) | (g << 8) | (r << 4) | r;
+ }
+
+ ff1.close();
+ ff2.close();
+ }
+
+ // PROM5 has the following in it (tile address decoder):
+ // 00: 00 20 40 60 02 22 42 62 04 24 44 64 06 26 46 66
+ // 10: 88 A8 C8 E8 8A AA CA EA 8C AC CC EC 8E AE CE EE
+
+ return ff1;
}
+
//
// Unpack font data
//
bool UnpackFonts(void)
{
-// BYTE b1, b2, b3;
- char b1, b2, b3;
- fstream f1, f2;
- //0x4000 $800 chars
- f1.open("./ROMs/"ROM7, ios::binary | ios::in);
- f2.open("./ROMs/"ROM8, ios::binary | ios::in);
- if ((!f1) || (!f2)) return false; // Return if not found...
- for(long i=0; i<0x40000; i+=64)
- {
- for(int j=0; j<64; j+=8)
- {
- f1.get(b1); f1.get(b2); f2.get(b3);
- b3 ^= 0xFF; // Invert top data...
- chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
- chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
- chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
- chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
- chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
- chr_rom[i+j+5] = (b3 & 0x04) | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
- chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
- chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
- }
- }
- f1.close();
- f2.close();
-
- f1.open("./ROMs/"ROM5, ios::binary | ios::in);
- f2.open("./ROMs/"ROM6, ios::binary | ios::in);
- for(long i=0x40000; i<0x60000; i+=64)
- {
- for(int j=0; j<64; j+=8)
- {
- f1.get(b1); f1.get(b2); f2.get(b3);
- b3 ^= 0xFF; // Invert top data
- chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
- chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
- chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
- chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
- chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
- chr_rom[i+j+5] = (b3 & 0x04) | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
- chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
- chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
- }
- }
- f1.close();
- f2.close();
- return true; // Made it!
+// uint8_t b1, b2, b3;
+ char b1, b2, b3;
+ fstream f1, f2;
+ //0x4000 $800 chars
+ f1.open("./ROMs/"ROM7, ios::binary | ios::in);
+ f2.open("./ROMs/"ROM8, ios::binary | ios::in);
+
+ if ((!f1) || (!f2))
+ return false; // Return if not found...
+
+ for(long i=0; i<0x40000; i+=64)
+ {
+ for(int j=0; j<64; j+=8)
+ {
+ f1.get(b1); f1.get(b2); f2.get(b3);
+ b3 ^= 0xFF; // Invert top data...
+ chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
+ chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
+ chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
+ chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
+ chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
+ chr_rom[i+j+5] = (b3 & 0x04) | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
+ chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
+ chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
+ }
+ }
+
+ f1.close();
+ f2.close();
+
+ f1.open("./ROMs/"ROM5, ios::binary | ios::in);
+ f2.open("./ROMs/"ROM6, ios::binary | ios::in);
+
+ for(long i=0x40000; i<0x60000; i+=64)
+ {
+ for(int j=0; j<64; j+=8)
+ {
+ f1.get(b1); f1.get(b2); f2.get(b3);
+ b3 ^= 0xFF; // Invert top data
+ chr_rom[i+j] = ((b3 & 0x80) >> 5) | ((b1 & 0x80) >> 6) | ((b1 & 0x08) >> 3);
+ chr_rom[i+j+1] = ((b3 & 0x40) >> 4) | ((b1 & 0x40) >> 5) | ((b1 & 0x04) >> 2);
+ chr_rom[i+j+2] = ((b3 & 0x20) >> 3) | ((b1 & 0x20) >> 4) | ((b1 & 0x02) >> 1);
+ chr_rom[i+j+3] = ((b3 & 0x10) >> 2) | ((b1 & 0x10) >> 3) | (b1 & 0x01);
+ chr_rom[i+j+4] = ((b3 & 0x08) >> 1) | ((b2 & 0x80) >> 6) | ((b2 & 0x08) >> 3);
+ chr_rom[i+j+5] = (b3 & 0x04) | ((b2 & 0x40) >> 5) | ((b2 & 0x04) >> 2);
+ chr_rom[i+j+6] = ((b3 & 0x02) << 1) | ((b2 & 0x20) >> 4) | ((b2 & 0x02) >> 1);
+ chr_rom[i+j+7] = ((b3 & 0x01) << 2) | ((b2 & 0x10) >> 3) | (b2 & 0x01);
+ }
+ }
+
+ f1.close();
+ f2.close();
+
+ return true; // Made it!
}
+
//
// Get length of sample from WAV format
//
-DWORD GetWAVLength(fstream &file)
+uint32_t GetWAVLength(fstream & file)
{
char ch;
- DWORD len;
+ uint32_t len;
file.ignore(16); // Skip header BS
for(int i=0; i<2; i++)
{
- file.get(ch); len = (int)(BYTE)ch;
- file.get(ch); len |= (int)(BYTE)ch << 8;
- file.get(ch); len |= (int)(BYTE)ch << 16;
- file.get(ch); len |= (int)(BYTE)ch << 24;
+ file.get(ch); len = (int)(uint8_t)ch;
+ file.get(ch); len |= (int)(uint8_t)ch << 8;
+ file.get(ch); len |= (int)(uint8_t)ch << 16;
+ file.get(ch); len |= (int)(uint8_t)ch << 24;
- file.ignore(len + 4); // Skip intermediate data
+ // Skip intermediate data
+ file.ignore(len + 4);
}
- file.get(ch); len = (int)(BYTE)ch; // & finally get length of data
- file.get(ch); len |= (int)(BYTE)ch << 8;
- file.get(ch); len |= (int)(BYTE)ch << 16;
- file.get(ch); len |= (int)(BYTE)ch << 24;
+ // & finally get length of data
+ file.get(ch); len = (int)(uint8_t)ch;
+ file.get(ch); len |= (int)(uint8_t)ch << 8;
+ file.get(ch); len |= (int)(uint8_t)ch << 16;
+ file.get(ch); len |= (int)(uint8_t)ch << 24;
return len;
}
+
+#if 0
//
// Load PSG samples from disk
//
{
char file[40];
char ch;
- DWORD len;
+ uint32_t len;
for(int i=0; i<16; i++)
{
if (fp)
{
len = GetWAVLength(fp); // Get WAV data length...
-
- psg_adrs[i] = new BYTE[len]; // Attempt to allocate space...
+ psg_adrs[i] = new uint8_t[len]; // Attempt to allocate space...
if (psg_adrs[i] != NULL)
{
}
psg_lens[i] = len;
- cout << "Found sample file: " << file << " [Length: " << dec << len << "]" << endl;
+ printf("Found sample file: %s\t[Length: %u]\n", file, len);
}
fp.close();
}
}
}
+#endif
+FILE * psg1, * psg2;
+
//
-// Load FM samples from disk
+// Main loop
//
-void LoadFMs(void)
+int main(int argc, char * argv[])
{
- char file[200];
- char ch;
- DWORD len;
+ InitLog("thunder.log");
- for(int i=0; i<14; i++)
- {
- fstream fp;
+extern bool disasm; // From 'V6809.CPP'
+ extern bool charbase; // From 'SCREEN.CPP'
+ charbase = false;
- fm_adrs[i] = NULL; // Zero out pointer
- sprintf(file, "./sounds/fm%i.wav", i); // Create filename
+ char lbuff[80];
+ fstream ff; // Declare fstream without file hooks...
+ bool brk = false, brk2 = false; // Breakpoint set flag
+ uint16_t brkpnt, brkpnt2; // Where the breakpoint is...
+ bool running; // CPU running state flag...
+ bool self_test = false; // Self-test switch
+ bool scr_type = false; // false=chars, true=pixels
+ uint16_t debounce = 0; // Key de-bounce counter
+ uint16_t fire_debounce = 0; // Fire button debounce counter
+ uint8_t x; // General placeholder...
+// bool active = true; // Program running flag
- fp.open(file, ios::binary | ios::in); // Attempt to open it...
+ SDL_Event event; // SDL "event"
+ extern uint8_t palette[768]; // Screen physical palette
+ uint32_t ticks, oldTicks;
- if (fp)
- {
- len = GetWAVLength(fp); // Get WAV length...
+ cout << endl << "THUNDER v"THUNDER_VERSION" ";
+ cout << "by James Hammons" << endl;
+ cout << "Serial #20149417 / Prerelease" << endl;
+ cout << "© 2003, 2014 Underground Software" << endl << endl;
- fm_adrs[i] = new BYTE[len]; // Attempt to allocate space...
+ cout << "This emulator is free software. If you paid for it you were RIPPED OFF"
+ << endl << endl;
- if (fm_adrs[i] != NULL)
- {
- for(int j=0; j<(signed)len; j++)
- {
- fp.get(ch);
- fm_adrs[i][j] = ch; // & load it in...
- }
+// SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder");
- fm_lens[i] = len;
- cout << "Found sample file: " << file << " [Length: " << dec << len
- << "]" << endl;
- }
+ gram = gram1; grom = grom1; // Needed only for debugger
- fp.close();
- }
+ memset(gram, 0, 0x10000);
+ memset(grom, 0, 0x10000);
+ memset(gram2, 0, 0x10000);
+ memset(grom2, 0, 0x10000);
+
+ game_over_switch = 0; // Init game over delay
+
+ cout << "Loading ROMs..." << endl;
+ if (!ReadColorPROMs()) // Load virtual PROMs
+ { cout << "Could not open PROM files!" << endl; return -1; }
+
+ if (!LoadImg(ROM1, grom1, 0x8000, 0x8000)) // Load $8000-$FFFF 1st ROM
+ { cout << "Could not open file '" << ROM1 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM2, grom2, 0x8000, 0x8000)) // Load $8000-$FFFF 2nd ROM
+ { cout << "Could not open file '" << ROM2 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM3, grom3, 0, 0x8000)) // Load 3rd ROM into its own space
+ { cout << "Could not open file '" << ROM3 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM17, data_rom, 0, 0x10000)) // Load 17th ROM
+ { cout << "Could not open file '" << ROM17 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM18, data_rom, 0x10000, 0x10000)) // Load 18th ROM
+ { cout << "Could not open file '" << ROM18 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM19, data_rom, 0x20000, 0x10000)) // Load 19th ROM
+ { cout << "Could not open file '" << ROM19 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM20, data_rom, 0x30000, 0x10000)) // Load 20th ROM
+ { cout << "Could not open file '" << ROM20 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM9, spr_rom, 0, 0x10000)) // Load 9th ROM
+ { cout << "Could not open file '" << ROM9 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM10, spr_rom, 0x10000, 0x10000)) // Load 10th ROM
+ { cout << "Could not open file '" << ROM10 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM11, spr_rom, 0x20000, 0x10000)) // Load 11th ROM
+ { cout << "Could not open file '" << ROM11 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM12, spr_rom, 0x30000, 0x10000)) // Load 12th ROM
+ { cout << "Could not open file '" << ROM12 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM13, spr_rom, 0x40000, 0x10000)) // Load 13th ROM
+ { cout << "Could not open file '" << ROM13 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM14, spr_rom, 0x50000, 0x10000)) // Load 14th ROM
+ { cout << "Could not open file '" << ROM14 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM15, spr_rom, 0x60000, 0x10000)) // Load 15th ROM
+ { cout << "Could not open file '" << ROM15 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM16, spr_rom, 0x70000, 0x10000)) // Load 16th ROM
+ { cout << "Could not open file '" << ROM16 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM21, voice_rom, 0, 0x10000)) // Load 21st ROM
+ { cout << "Could not open file '" << ROM21 << "'!" << endl; return -1; }
+
+ if (!LoadImg(ROM22, voice_rom, 0x10000, 0x10000)) // Load 22nd ROM
+ { cout << "Could not open file '" << ROM22 << "'!" << endl; return -1; }
+
+ if (!UnpackFonts()) // Load 5, 6, 7, 8th ROMs
+ {
+ cout << "Could not open font files!" << endl;
+ return -1;
}
-}
-//
-// Main loop
-//
-int main(int argc, char * argv[])
-{
- InitLog("thunder.log");
+ // Load MCU program + data
+ if (!LoadImg(MCUROM, mcuMem, 0xF000, 0x1000)) // Load MCU ROM
+ { cout << "Could not open file '" << MCUROM << "'!" << endl; return -1; }
-/* extern WORD cpu1.pc, cpu1.s, cpu1.u, cpu1.x, cpu1.y; // Pull in vars from '6809.cpp'
- extern BYTE cpu1.a, cpu1.b, cpu1.cc, cpu1.dp;
- extern long iclock;
- extern bool illegal;
- extern WORD cpu2.pc, cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Pull in vars from '6809B.cpp'
- extern BYTE cpu2.a, cpu2.b, cpu2.cc, cpu2.dp;
- extern long iclockB;
- extern bool illegalB;
- extern void (* exec_op0[256])(); // Array of page zero opcode functions...
- extern void (* exec_op1[256])(); // Array of page one opcode functions...
- extern void (* exec_op2[256])(); // Array of page two opcode functions...
- extern void (* exec_op0B[256])(); // Array of page zero opcode functions...
- extern void (* exec_op1B[256])(); // Array of page one opcode functions...
- extern void (* exec_op2B[256])(); // Array of page two opcode functions...*/
- extern bool charbase; // From 'SCREEN.CPP'
-// extern unsigned int vesa_memptr;
- charbase = false;
-
- char lbuff[80];
- fstream ff; // Declare fstream without file hooks...
- bool brk = false, brk2 = false; // Breakpoint set flag
- WORD brkpnt, brkpnt2; // Where the breakpoint is...
- bool running; // CPU running state flag...
- bool self_test = false; // Self-test switch
- bool scr_type = false; // false=chars, true=pixels
- WORD debounce = 0; // Key de-bounce counter
- WORD fire_debounce = 0; // Fire button debounce counter
-// bool refresh2 = true; // Default to 60 Hz...
- BYTE x; // General placeholder...
- bool active = true; // Program running flag
-
-// SDL_Surface * screen = NULL; // SDL screen pointer
- SDL_Event event; // SDL "event"
-// int keyPressed; // SDL key pressed...
- BYTE keys[256]; // Keyboard "switch-like" buffer
- extern BYTE palette[768]; // Screen physical palette
- DWORD ticks, oldTicks;
-
-// tr.open("exe.log", ios::binary | ios::out); // Tracelog
-
- cout << endl << "THUNDER beta "THUNDER_BETA_VERSION" ";
- cout << "by Jimmy Hamm <jlhamm@acm.org>" << endl;
- cout << "Serial #20030313 / Prerelease" << endl;
- cout << "(C) 2003 Underground Software" << endl << endl;
-
- cout << "This emulator is freeware. If you paid for it you were RIPPED OFF"
- << endl << endl;
-
- cout << "Initializing SDL..." << endl;
-
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
- {
- cout << "Couldn't initialize SDL: " << SDL_GetError() << endl;
- return -1;
- }
-
- SDL_WM_SetCaption("Thunder Beta 6", "Thunder");
-
- cout << "Allocating memory..." << endl;
-//Does this anyway... set_new_handler(0); // Make 'new' return NULL on failure...
- gram1 = new BYTE[0x10000];
- if (gram1 == NULL) { cout << "Could not allocate RAM space #1!" << endl
- << "Aborting!" << endl; return -1; }
- grom1 = new BYTE[0x10000];
- if (grom1 == NULL) { cout << "Could not allocate ROM space #1!" << endl
- << "Aborting!" << endl; return -1; }
- gram2 = new BYTE[0x10000];
- if (gram2 == NULL) { cout << "Could not allocate RAM space #2!" << endl
- << "Aborting!" << endl; return -1; }
- grom2 = new BYTE[0x10000];
- if (grom2 == NULL) { cout << "Could not allocate ROM space #2!" << endl
- << "Aborting!" << endl; return -1; }
- chr_rom = new BYTE[0x60000];
- if (chr_rom == NULL) { cout << "Could not allocate character RAM!" << endl
- << "Aborting!" << endl; return -1; }
- grom3 = new BYTE[0x8000];
- if (grom3 == NULL) { cout << "Could not allocate ROM space #4!" << endl
- << "Aborting!" << endl; return -1; }
- grom4 = new BYTE[0x8000];
- if (grom4 == NULL) { cout << "Could not allocate ROM space #5!" << endl
- << "Aborting!" << endl; return -1; }
- data_rom = new BYTE[0x40000];
- if (data_rom == NULL) { cout << "Could not allocate ROM level data!" << endl
- << "Aborting!" << endl; return -1; }
- spr_rom = new BYTE[0x80000];
- if (spr_rom == NULL) { cout << "Could not allocate ROM sprite data!" << endl
- << "Aborting!" << endl; return -1; }
- voice_rom = new BYTE[0x20000];
- if (voice_rom == NULL) { cout << "Could not allocate ROM voice data!" << endl
- << "Aborting!" << endl; return -1; }
-
- gram = gram1; grom = grom1; // Needed only for debugger
-
- for(long i=0; i<0x10000; i++)
- {
- gram[i] = 0; grom[i] = 0; // Zero out memory
- gram2[i] = 0; grom2[i] = 0;
- }
- game_over_switch = 0; // Init game over delay
-// cpu1.a = 0; cpu1.b = 0; cpu1.cc = 0; cpu1.dp = 0; cpu1.x = 0; cpu1.y = 0; cpu1.s = 0; ur = 0; cpu1.pc = 0;
-
- cout << "Loading ROMs..." << endl;
-// LoadCMOS(); // Load CMOS at $CC00-$CFFF
- if (!ReadColorPROMs()) // Load virtual PROMs
- { cout << "Could not open PROM files!" << endl; return -1; }
-
- if (!LoadImg(ROM1, grom1, 0x8000, 0x8000)) // Load $8000-$FFFF 1st ROM
- { cout << "Could not open file '" << ROM1 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM2, grom2, 0x8000, 0x8000)) // Load $8000-$FFFF 2nd ROM
- { cout << "Could not open file '" << ROM2 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM3, grom3, 0, 0x8000)) // Load 3rd ROM into its own space
- { cout << "Could not open file '" << ROM3 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM4, grom4, 0, 0x8000)) // Load 4rd ROM into its own space
- { cout << "Could not open file '" << ROM4 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM17, data_rom, 0, 0x10000)) // Load 17th ROM
- { cout << "Could not open file '" << ROM17 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM18, data_rom, 0x10000, 0x10000)) // Load 18th ROM
- { cout << "Could not open file '" << ROM18 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM19, data_rom, 0x20000, 0x10000)) // Load 19th ROM
- { cout << "Could not open file '" << ROM19 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM20, data_rom, 0x30000, 0x10000)) // Load 20th ROM
- { cout << "Could not open file '" << ROM20 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM9, spr_rom, 0, 0x10000)) // Load 9th ROM
- { cout << "Could not open file '" << ROM9 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM10, spr_rom, 0x10000, 0x10000)) // Load 10th ROM
- { cout << "Could not open file '" << ROM10 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM11, spr_rom, 0x20000, 0x10000)) // Load 11th ROM
- { cout << "Could not open file '" << ROM11 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM12, spr_rom, 0x30000, 0x10000)) // Load 12th ROM
- { cout << "Could not open file '" << ROM12 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM13, spr_rom, 0x40000, 0x10000)) // Load 13th ROM
- { cout << "Could not open file '" << ROM13 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM14, spr_rom, 0x50000, 0x10000)) // Load 14th ROM
- { cout << "Could not open file '" << ROM14 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM15, spr_rom, 0x60000, 0x10000)) // Load 15th ROM
- { cout << "Could not open file '" << ROM15 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM16, spr_rom, 0x70000, 0x10000)) // Load 16th ROM
- { cout << "Could not open file '" << ROM16 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM21, voice_rom, 0, 0x10000)) // Load 21st ROM
- { cout << "Could not open file '" << ROM21 << "'!" << endl; return -1; }
-
- if (!LoadImg(ROM22, voice_rom, 0x10000, 0x10000)) // Load 22nd ROM
- { cout << "Could not open file '" << ROM22 << "'!" << endl; return -1; }
-
- if (!UnpackFonts()) // Load 5, 6, 7, 8th ROMs
- {
- cout << "Could not open font files!" << endl;
- return -1;
- }
-
- LoadPSGs(); // Load samples if they're there...
- LoadFMs();
-
- // Quick 'n' Dirty voice dump (sound 0x0E)
-/* DWORD adc = (voice_rom[26]<<8) | voice_rom[27];
- bool doneWitIt = false;
- int crh = 0;
- while (!doneWitIt)
- {
- if (voice_rom[adc] < 0x10) tr << "0";
- tr << hex << (int)voice_rom[adc] << " ";
- if (crh++ > 24) { crh = 0; tr << endl; }
- if ((voice_rom[adc] == 0xFF) && (voice_rom[adc-1] != 0x00))
- doneWitIt = true;
- adc++;
- }//*/
+ if (!LoadImg(ROM4, mcuMem, 0x4000, 0x8000)) // Load 4th ROM
+ { cout << "Could not open file '" << ROM4 << "'!" << endl; return -1; }
+
+// Now emulated! :-D
+ // Load PSG samples if they're there...
+// LoadPSGs();
// Set up V6809 execution contexts
- memset(&cpu1, sizeof(V6809REGS), 0);
+ memset(&cpu1, 0, sizeof(V6809REGS));
cpu1.RdMem = RdMem;
cpu1.WrMem = WrMem;
cpu1.cpuFlags |= V6809_ASSERT_LINE_RESET;
- memset(&cpu2, sizeof(V6809REGS), 0);
+ memset(&cpu2, 0, sizeof(V6809REGS));
cpu2.RdMem = RdMemB;
cpu2.WrMem = WrMemB;
cpu2.cpuFlags |= V6809_ASSERT_LINE_RESET;
- bool firstTime = true; // kludge...
+ memset(&mcu, 0, sizeof(V63701REGS));
+ mcu.RdMem = MCUReadMemory;
+ mcu.WrMem = MCUWriteMemory;
+ mcu.cpuFlags |= V63701_ASSERT_LINE_RESET;
+
+// uint32_t my_clock = 0;
+ running = true; // Set running status...
+// trace1 = false;
+// SetRefreshRate(refresh2); // Tell GUI our refresh rate
+
+ // Set all inputs to inactive...
+ input1.byte = input2.byte = input3.byte = input4.byte = input5.byte = 0xFF;
+// mcu.port1 = 0xFF;
+// mcu.port2 = 0xFF;
+#if 0
+ // This is data that is supposed to come from the MCU... So that's why it hangs
+ gram1[0x4182] = 0xA6; // Temp kludge
+ gram1[0x4184] = 0xA6;
+ gram1[0x4183] = 0x00; // More of the same
+ gram1[0x4185] = 0x00;
+#endif
+ banksw1 = 0; // Will this work?
+ banksw2 = 0;
+ InitGUI(); // Reset # of coins
+
+WriteLog("About to set up screen...\n");
+ InitVideo();
+
+ oldTicks = SDL_GetTicks();
-WriteLog("About to go to the main loop...\n");
- while (active)
+WriteLog("About to set up audio...\n");
+ InitSound();
+
+memset(scrBuffer, 0xFF, VIRTUAL_SCREEN_WIDTH*VIRTUAL_SCREEN_HEIGHT*sizeof(uint32_t));
+RenderScreenBuffer();
+
+#if 1
+psg1 = fopen("psgchan1.raw", "wb");
+psg2 = fopen("psgchan3.raw", "wb");
+#endif
+
+WriteLog("About to enter main loop...\n");
+ while (running)
{
- cout << ">";
- if (firstTime)
- {
- firstTime = false; // crappy kludge...
- lbuff[0] = 'r';
- lbuff[1] = 0;
- }
- else
- cin >> lbuff;
+ HandleGUIDebounce(); // Debounce GUI keys
- if (lbuff[0] == 'd')
- {
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- dpc = htod(lbuff);
- }
- printf("%04X: ", dpc);
- WORD pc_save = cpu1.pc, pcB_save = cpu2.pc;
- cpu1.pc = dpc; cpu2.pc = dpc;
- for(int i=0; i<16; i++)
- printf("%02X ", (looking_at_rom ? Fetch() : FetchB()));
- cout << " ";
- cpu1.pc = dpc; cpu2.pc = dpc;
- for(int i=0; i<16; i++)
- {
- BYTE a = (looking_at_rom ? Fetch() : FetchB());
- if (a<10) cout << (char)(a+48);
- if ((a>9) && (a<37)) cout << (char)(a+55);
- if (a>36) cout << ".";
- }
- cout << endl;
- dpc = (looking_at_rom ? cpu1.pc : cpu2.pc);
- cpu1.pc = pc_save; cpu2.pc = pcB_save;
- }
- else if (lbuff[0] == 'e')
- {
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- dpc = htod(lbuff);
- }
- printf("%04X: ", dpc);
- for(int i=0; i<16; i++) printf("%02X ", (BYTE)gram[dpc++]);
- cout << endl;
- }
- else if (lbuff[0] == 'l')
- {
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- dpc = htod(lbuff);
- }
- for(int i=0; i<23; i++)
- Decode_6809();
- }
- else if (lbuff[0] == 't')
+#if 0
+ if (game_over_switch)
{
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- dpc = htod(lbuff);
- }
- if (looking_at_rom)
- {
- cpu1.pc = dpc;
- Decode_6809();
- Execute6809(&cpu1, 1);
- dpc = cpu1.pc;
- printf("A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
- cpu1.a, cpu1.b, cpu1.cc, cpu1.dp, cpu1.x, cpu1.y, cpu1.s, cpu1.u, cpu1.pc);
- cout << " iclock=" << cpu1.clock << endl;
- }
- else
- {
- cpu2.pc = dpc;
- Decode_6809();
- Execute6809(&cpu2, 1);
- dpc = cpu2.pc;
- printf("A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
- cpu2.a, cpu2.b, cpu2.cc, cpu2.dp, cpu2.x, cpu2.y, cpu2.s, cpu2.u, cpu2.pc);
- cout << " iclock=" << cpu2.clock << endl;
- }
+ game_over_switch--; // Countdown...
+
+ if (game_over_switch == 0)
+ gram1[0x4380] = 0; // Kill music!
}
- else if ((lbuff[0] == 'r') || (lbuff[0] == 'c')) // Run/continue...
- {
-WriteLog("Executing 'run' command...\n");
- DWORD my_clock = 0;
- running = true; // Set running status...
- trace = false;
- SetRefreshRate(refresh2); // Tell GUI our refresh rate
- //for(WORD i=0; i<0x8000; i++) gram2[i] = grom3[i]; //Temp
-
- if (lbuff[0] == 'r') // If run, then reset CPUs
- {
-WriteLog("Executing secondary 'run' command...\n");
- gram1[0x4182] = 0xA6; // Temp kludge
- gram1[0x4184] = 0xA6;
- gram1[0x4183] = 0x00; // More of the same
- gram1[0x4185] = 0x00;
- banksw1 = 0; // Will this work?
- banksw2 = 0;
-// iclock = 0; // Reset instr clock #1...
- InitGUI(); // Reset # of coins
-
-/* cpu1.pc = ((grom1[0xFFFE]<<8) | grom1[0xFFFF]); // Reset 6809 #1
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32; cpu1.pc = htod(lbuff);
- }
- else cpu1.cc = 0xFF; // Set CC register
-
- cpu2.pc = ((grom2[0xFFFE]<<8) | grom2[0xFFFF]); // Reset 6809 #2
- cpu2.cc = 0xFF; // Set CC register
- while(iclock < 8000) // was 17000, 20000, 5000
- {
- Execute6809(&cpu1, 1); Execute6809(&cpu2, 1);
- }*/
-WriteLog("--> CPU clock #1: %u\n", cpu1.clock);
- // Will *this* help video sync?
- while (cpu1.clock < 8000) // was 17000, 20000, 5000
- {
- Execute6809(&cpu1, 1);
- Execute6809(&cpu2, 1);
- }
- }
+#endif
-WriteLog("About to set up screen...\n");
-// if (!SetVESA2()) running = false; // Set up screen
- // Set up screen (windowed)
- screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); //video_bpp, videoflags);
- if (screen == NULL)
- {
- cout << "Failed to initialize screen!" << endl;
- running = false;
- }
+// Dipswitches are presented to the main CPUs as 0 or 1 at locations
+// $423D - $425B by the MCU
- SDL_Color colors[256];
- for(int i=0; i<256; i++)
- {
- colors[i].r = palette[i*3+0];
- colors[i].g = palette[i*3+1];
- colors[i].b = palette[i*3+2];
- }
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
-
- for(int i=0; i<256; i++)
- keys[i] = 0; // Clear keyboard buffer...
-
- oldTicks = SDL_GetTicks();
-
- // This crap SHOULD be in sound.cpp (not yet created)...
- SDL_AudioSpec desired, obtained;
- desired.freq = 22050;
- desired.format = AUDIO_U8;
- desired.channels = 1;
- desired.samples = 600;
- desired.callback = SoundFunc;
- desired.userdata = NULL;
- // Also, should check to see if it got the hardware it needed, correct sample size, etc.
- if (SDL_OpenAudio(&desired, &obtained) < 0)
- {
- cout << "Couldn't open audio: " << SDL_GetError() << endl;
- return -1;
- }
- SDL_PauseAudio(0); // Get that audio going!
+//testing... (works)
+//gram1[0x423D] = 1;
+ //gram1[0x423D] = self_test; // Reset DSW1-1
+// gram1[0x4268] = 0; // Reset Video test
- while (running)
+ // SDL key handling...
+
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
{
- HandleGUIDebounce(); // Debounce GUI keys
- if (game_over_switch)
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ running = false;
+ // Do PCX snapshot (F4)
+ else if (event.key.keysym.sym == SDLK_F4)
{
- game_over_switch--; // Countdown...
- if (game_over_switch == 0)
- gram1[0x4380] = 0; // Kill music!
- }
- //gram1[0x423D] = self_test; // Reset DSW1-1
- gram1[0x4268] = 0; // Reset Video test
- gram1[0x427A] = 0; gram1[0x427C] = 0;
- gram1[0x427B] = 0; gram1[0x427D] = 0;
- gram1[0x427E] = 0; gram1[0x427F] = 0;
- gram1[0x4280] = 0; gram1[0x4281] = 0;
- gram1[0x4276] = 0; gram1[0x426A] = 0;
- gram1[0x4278] = 0; gram1[0x426C] = 0;
- gram1[0x4262] = 0; gram1[0x4260] = 0;
- //gram1[0x4247] = 0;
-
- // SDL key handling...
-
-// keyPressed = 0; // Reset keypress
- while (SDL_PollEvent(&event) != 0) // Bleed out all pending key events...
- {
- if (event.type == SDL_KEYDOWN)
- keys[event.key.keysym.scancode] = 1;
- if (event.type == SDL_KEYUP)
- keys[event.key.keysym.scancode] = 0;
+// SpawnSound(USERSOUND, SCAMERA);
+ SavePCXSnapshot();
+// debounce = 10;
}
+#if 1
+ else if (event.key.keysym.sym == SDLK_5)
+ input1.bit.b5 = 0;
+ else if (event.key.keysym.sym == SDLK_1)
+ input1.bit.b6 = 0;
+ else if (event.key.keysym.sym == SDLK_RIGHT)
+ input3.bit.b5 = 0;
+ else if (event.key.keysym.sym == SDLK_LEFT)
+ input3.bit.b4 = 0;
+ else if (event.key.keysym.sym == SDLK_UP)
+ input2.bit.b2 = 0;
+ else if (event.key.keysym.sym == SDLK_DOWN)
+ input1.bit.b2 = 0;
+ else if (event.key.keysym.sym == SDLK_q) // (Q) Jump
+ input1.bit.b1 = 0;
+ else if (event.key.keysym.sym == SDLK_e) // (E) Fire
+ input3.bit.b3 = 0;
+#else
+ else if (event.key.keysym.sym == SDLK_1)
+ input1.bit.b0 = 0;
+ else if (event.key.keysym.sym == SDLK_2)
+ input1.bit.b1 = 0;
+ else if (event.key.keysym.sym == SDLK_3)
+ input1.bit.b2 = 0;
+ else if (event.key.keysym.sym == SDLK_4)
+ input1.bit.b3 = 0;
+ else if (event.key.keysym.sym == SDLK_5)
+ input1.bit.b4 = 0;
+ else if (event.key.keysym.sym == SDLK_6)
+ input1.bit.b5 = 0;
+ else if (event.key.keysym.sym == SDLK_7)
+ input1.bit.b6 = 0;
+ else if (event.key.keysym.sym == SDLK_8)
+ input1.bit.b7 = 0;
+
+ else if (event.key.keysym.sym == SDLK_q)
+ input2.bit.b0 = 0;
+ else if (event.key.keysym.sym == SDLK_w)
+ input2.bit.b1 = 0;
+ else if (event.key.keysym.sym == SDLK_e)
+ input2.bit.b2 = 0;
+ else if (event.key.keysym.sym == SDLK_r)
+ input2.bit.b3 = 0;
+ else if (event.key.keysym.sym == SDLK_t)
+ input2.bit.b4 = 0;
+ else if (event.key.keysym.sym == SDLK_y)
+ input2.bit.b5 = 0;
+ else if (event.key.keysym.sym == SDLK_u)
+ input2.bit.b6 = 0;
+ else if (event.key.keysym.sym == SDLK_i)
+ input2.bit.b7 = 0;
+
+ else if (event.key.keysym.sym == SDLK_a)
+ input3.bit.b0 = 0;
+ else if (event.key.keysym.sym == SDLK_s)
+ input3.bit.b1 = 0;
+ else if (event.key.keysym.sym == SDLK_d)
+ input3.bit.b2 = 0;
+ else if (event.key.keysym.sym == SDLK_f)
+ input3.bit.b3 = 0;
+ else if (event.key.keysym.sym == SDLK_g)
+ input3.bit.b4 = 0;
+#endif
+
+ break;
+ case SDL_KEYUP:
+#if 1
+ if (event.key.keysym.sym == SDLK_5)
+ input1.bit.b5 = 1;
+ else if (event.key.keysym.sym == SDLK_1)
+ input1.bit.b6 = 1;
+ else if (event.key.keysym.sym == SDLK_RIGHT)
+ input3.bit.b5 = 1;
+ else if (event.key.keysym.sym == SDLK_LEFT)
+ input3.bit.b4 = 1;
+ else if (event.key.keysym.sym == SDLK_UP)
+ input2.bit.b2 = 1;
+ else if (event.key.keysym.sym == SDLK_DOWN)
+ input1.bit.b2 = 1;
+ else if (event.key.keysym.sym == SDLK_q) // (Q) Jump
+ input1.bit.b1 = 1;
+ else if (event.key.keysym.sym == SDLK_e) // (E) Fire
+ input3.bit.b3 = 1;
+#else
+ if (event.key.keysym.sym == SDLK_1)
+ input1.bit.b0 = 1;
+ else if (event.key.keysym.sym == SDLK_2)
+ input1.bit.b1 = 1;
+ else if (event.key.keysym.sym == SDLK_3)
+ input1.bit.b2 = 1;
+ else if (event.key.keysym.sym == SDLK_4)
+ input1.bit.b3 = 1;
+ else if (event.key.keysym.sym == SDLK_5)
+ input1.bit.b4 = 1;
+ else if (event.key.keysym.sym == SDLK_6)
+ input1.bit.b5 = 1;
+ else if (event.key.keysym.sym == SDLK_7)
+ input1.bit.b6 = 1;
+ else if (event.key.keysym.sym == SDLK_8)
+ input1.bit.b7 = 1;
+
+ else if (event.key.keysym.sym == SDLK_q)
+ input2.bit.b0 = 1;
+ else if (event.key.keysym.sym == SDLK_w)
+ input2.bit.b1 = 1;
+ else if (event.key.keysym.sym == SDLK_e)
+ input2.bit.b2 = 1;
+ else if (event.key.keysym.sym == SDLK_r)
+ input2.bit.b3 = 1;
+ else if (event.key.keysym.sym == SDLK_t)
+ input2.bit.b4 = 1;
+ else if (event.key.keysym.sym == SDLK_y)
+ input2.bit.b5 = 1;
+ else if (event.key.keysym.sym == SDLK_u)
+ input2.bit.b6 = 1;
+ else if (event.key.keysym.sym == SDLK_i)
+ input2.bit.b7 = 1;
+
+ else if (event.key.keysym.sym == SDLK_a)
+ input3.bit.b0 = 1;
+ else if (event.key.keysym.sym == SDLK_s)
+ input3.bit.b1 = 1;
+ else if (event.key.keysym.sym == SDLK_d)
+ input3.bit.b2 = 1;
+ else if (event.key.keysym.sym == SDLK_f)
+ input3.bit.b3 = 1;
+ else if (event.key.keysym.sym == SDLK_g)
+ input3.bit.b4 = 1;
+#endif
+
+ break;
+ }
+ }
-// {
- if (keys[0x01])
+#if 0
+ if (keys[SDLK_ESCAPE])
running = false; // ESC to exit...
if (debounce)
debounce--; // Debounce toggle keys...
else
{
- if (keys[0x3B])
+ if (keys[SDLK_F1])
{
self_test = !self_test; // Self-test (F1-toggle)
debounce = 10; // Key debounce value...
}
- if (keys[0x3C])
+ if (keys[SDLK_F2])
{
gram1[0x4268] = 1; // Video test (F2)
debounce = 10; // Key debounce value...
}
- if (keys[0x58])
+ if (keys[SDLK_F12])
{
scr_type = !scr_type; // Toggle screen (F12)
debounce = 10; // Key debounce value...
}
- if (keys[0x3D])
+ if (keys[SDLK_F3])
{
show_scr = !show_scr; // Toggle bkgrnd (F3)
debounce = 10;
}
- if (keys[0x40])
+ if (keys[SDLK_F6])
{
enable_cpu = !enable_cpu; // Toggle CPUs (F6)
debounce = 10;
}
- if (keys[0x3F])
+ if (keys[SDLK_F5])
{
refresh2 = !refresh2; // Toggle 30/60Hz (F5)
SetRefreshRate(refresh2); // Inform GUI of refresh
SpawnMsg(M30FPS);
debounce = 10; // Key debounce value...
}
- if (keys[0x3E]) // Do PCX snapshot (F4)
+ if (keys[SDLK_F4]) // Do PCX snapshot (F4)
{
- SpawnSound(USERSOUND, SCAMERA);
+ SpawnSound(USERSOUND, SCAMERA);
SnapPCX(screen);
debounce = 10;
}
- if (keys[0x0F]) // Tab active/deactivate GUI
+ if (keys[SDLK_TAB]) // Tab active/deactivate GUI
{
if (ShowGUI())
DeactivateGUI();
else
ActivateGUI();
+
debounce = 10;
}
}
//if (keys[0x3E]) gram1[0x4247] = 1; // Screen hold DS (F4)
- if (keys[77+128]) // Right arrow
+ if (keys[SDLK_RIGHT]) // Right arrow
{
if (ShowGUI())
SelectRight(); // If GUI active...
else
{
- if (!keys[75+128]) // Disallow opposite directions @ same time
+ if (!keys[SDLK_LEFT]) // Disallow opposite directions @ same time
gram1[0x427F] = 1; // Stick right
}
}
- if (keys[75+128])
+ if (keys[SDLK_LEFT])
{
if (ShowGUI())
SelectLeft(); // If GUI active...
else
{
- if (!keys[77+128]) // Disallow opposite directions@same time
+ if (!keys[SDLK_RIGHT]) // Disallow opposite directions@same time
gram1[0x4281] = 1; // Left arrow
}
}
- if (keys[72+128])
+ if (keys[SDLK_UP])
{
if (ShowGUI())
SelectUp(); // If GUI active...
else
{
- if (!keys[80+128]) // Disallow opposite directions@same time
+ if (!keys[SDLK_DOWN]) // Disallow opposite directions@same time
gram1[0x427B] = 1; // Up arrow
}
}
- if (keys[80+128])
+ if (keys[SDLK_DOWN])
{
if (ShowGUI())
SelectDown(); // If GUI active...
else
{
- if (!keys[72+128]) // Disallow opposite directions@same time
+ if (!keys[SDLK_UP]) // Disallow opposite directions@same time
gram1[0x427D] = 1; // Down arrow
}
}
- if (keys[28]) // Return
+ if (keys[SDLK_RETURN]) // Return
{
- BYTE retval = UserSelectedSomething();
+ uint8_t retval = UserSelectedSomething();
+
if (retval == EXIT)
running = false;
+
if (retval == REFRESH)
{
refresh2 = !refresh2;
SetRefreshRate(refresh2);
}
}
- if (keys[0x02])
- gram1[0x427A] = 1; // (1)
- if (keys[0x03])
- gram1[0x427C] = 1; // (2)
- if (keys[0x04])
- gram1[0x427E] = 1; // (3)
- if (keys[0x06])
- gram1[0x4280] = 1; // (5)
- if (keys[0x10]|keys[29])
- gram1[0x4276] = 1; // (Q) Jump
- if (keys[0x11])
- gram1[0x426A] = 1; // (W)
+
+ if (keys[SDLK_1])
+ gram1[0x427A] = 1; // (1)
+
+ if (keys[SDLK_2])
+ gram1[0x427C] = 1; // (2)
+
+ if (keys[SDLK_3])
+ gram1[0x427E] = 1; // (3)
+
+ if (keys[SDLK_5])
+ gram1[0x4280] = 1; // (5)
+
+ if (keys[SDLK_q] | keys[29])
+ gram1[0x4276] = 1; // (Q) Jump
+
+ if (keys[SDLK_w])
+ gram1[0x426A] = 1; // (W)
+
if (fire_debounce)
fire_debounce--;
- if (keys[0x12]|keys[56]) // (E) Fire
+
+ if (keys[SDLK_e] | keys[56]) // (E) Fire
{
if (!fire_debounce)
{
gram1[0x4278] = 1;
+
if (gram1[0x3F08] == 0xFF) // Ugly kludge for debouncing gun
- {
fire_debounce = 8;
- }
else
- {
fire_debounce = 2;
- }
}
}
- if (keys[0x13])
- gram1[0x426C] = 1; // (R)
- if (keys[0x14])
- gram1[0x4262] = 1; // (T)
- if (keys[0x15])
- gram1[0x4260] = 1; // (Y)
- if (keys[0x44])
- gram1[0x41A5]++; // Coin? (F10)
- if (keys[0x2C])
- gram1[0x4189]++; // ? (Z) credits l dig
- if (keys[0x2D])
- gram1[0x418A]++; // ? (X) credits r dig
- if (keys[0x2E])
- gram1[0x418C]++; // ? (C) Start
- if (keys[0x2F])
- gram1[0x418D]++; // ? (V)
- if (keys[0x41])
- SpawnSound(USERSOUND, 0); // Do user sound (F7)
-// if (keys[0x42])
+
+ if (keys[SDLK_r])
+ gram1[0x426C] = 1; // (R)
+
+ if (keys[SDLK_t])
+ gram1[0x4262] = 1; // (T)
+
+ if (keys[SDLK_y])
+ gram1[0x4260] = 1; // (Y)
+
+ if (keys[SDLK_F10])
+ gram1[0x41A5]++; // Coin? (F10)
+
+ if (keys[SDLK_z])
+ gram1[0x4189]++; // ? (Z) credits l dig
+
+ if (keys[SDLK_x])
+ gram1[0x418A]++; // ? (X) credits r dig
+
+ if (keys[SDLK_c])
+ gram1[0x418C]++; // ? (C) Start
+
+ if (keys[SDLK_v])
+ gram1[0x418D]++; // ? (V)
+
+ if (keys[SDLK_F7])
+ SpawnSound(USERSOUND, 0); // Do user sound (F7)
+
+// if (keys[SDLK_F8])
// {
-// gram1[0x4380] = 0; // (F8) kill music (this worx)
-// charbase = false; // Switch chars out...
+// gram1[0x4380] = 0; // (F8) kill music (this worx)
+// charbase = false; // Switch chars out...
// }
-// if (keys[0x43]) gram1[0x4285] = 1; // (F9) strobe unknown loc
- if (keys[0x45]) // (F11)
+// if (keys[SDLK_F9]) gram1[0x4285] = 1; // (F9) strobe unknown loc
+
+ if (keys[SDLK_F11]) // (F11)
{
Execute6809(&cpu1, 10);
Execute6809(&cpu2, 10);
}
// }
- if (enable_cpu)
+//F12 is used above, but the values are ignored. So we'll do it here too.
+ if (keys[SDLK_F12])
{
-/*// if (irqGoA)
- cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;
-
- Execute6809(&cpu1, 25000);
- cpu1.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)
-
-// if (irqGoB)
- cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;
-
- Execute6809(&cpu2, 25000);
- cpu2.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)//*/
-
- cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;
- cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;
- while (cpu1.clock < 25000)
- {
- // Gay, but what are ya gonna do?
- Execute6809(&cpu1, 5);
- Execute6809(&cpu2, 5);
- }
- cpu1.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)
- cpu2.clock -= 25000; // Remove 25K ticks from clock (in case it overflowed)//*/
-
-/* while (my_clock < 25000) // Cycles in 60th of a sec at 1.5 Mhz
- {
- // pcx = cpu1.pc; // Tracelog stuff
- if (brk && (cpu1.pc == brkpnt))
- {
- running = false;
- break;
- }
- if (brk2 && (cpu2.pc == brkpnt2))
- {
- running = false;
- break;
- }
- DWORD prev = iclock;
-
- BYTE opcode = Fetch(); // Get the opcode
- if (opcode == 0x10)
- {
- exec_op1[Fetch()]();
- goto TEXE_NEXT;
- }
- if (opcode == 0x11)
- {
- exec_op2[Fetch()]();
- goto TEXE_NEXT;
- }
- exec_op0[opcode]();
-TEXE_NEXT:
-
- if (iclock > 25000)
- {
- iclock = 0;
-// if (irqGoA)
-// {
- if ((!(cpu1.cc&0x10)) && irqGoA)
- {
- irqGoA = false;
-// if (!(cpu1.cc&0x10)) // Process an interrupt?
-// {
- cpu1.cc |= 0x80; // Set E
- WrMem(--cpu1.s, cpu1.pc&0xFF); WrMem(--cpu1.s, cpu1.pc>>8); // Save all regs...
- WrMem(--cpu1.s, cpu1.u&0xFF); WrMem(--cpu1.s, cpu1.u>>8);
- WrMem(--cpu1.s, cpu1.y&0xFF); WrMem(--cpu1.s, cpu1.y>>8);
- WrMem(--cpu1.s, cpu1.x&0xFF); WrMem(--cpu1.s, cpu1.x>>8);
- WrMem(--cpu1.s, cpu1.dp); WrMem(--cpu1.s, cpu1.b);
- WrMem(--cpu1.s, cpu1.a); WrMem(--cpu1.s, cpu1.cc);
- cpu1.cc |= 0x50; // Set F,I
- cpu1.pc = (grom1[0xFFF8]<<8) | grom1[0xFFF9]; // And do it!
- // Need to find out why RdMem is returning wrong values here...
- }
- }
-// }//irgGoA
- if (iclock > prev)
- my_clock += (iclock - prev); // Increment my_clock
-
- // pcx = cpu2.pc; // Tracelog stuff
- opcode = FetchB(); // Get the opcode
- if (opcode == 0x10)
- {
- exec_op1B[FetchB()]();
- goto TEXE_NEXT2;
- }
- if (opcode == 0x11)
- {
- exec_op2B[FetchB()]();
- goto TEXE_NEXT2;
- }
- exec_op0B[opcode]();
-TEXE_NEXT2:
-
- if (iclockB > 25000)//24550) // Slightly faster IRQs for SUB processor
- {
- iclockB = 0;
-// if (irqGoB)
-// {
- if ((!(cpu2.cc&0x10)) && irqGoB)
- {
- irqGoB = false;
-// if (!(cpu2.cc&0x10)) // Process an interrupt?
-// {
- cpu2.cc |= 0x80; // Set E
- WrMemB(--cpu2.s, cpu2.pc&0xFF); WrMemB(--cpu2.s, cpu2.pc>>8); // Save all regs...
- WrMemB(--cpu2.s, cpu2.u&0xFF); WrMemB(--cpu2.s, cpu2.u>>8);
- WrMemB(--cpu2.s, cpu2.y&0xFF); WrMemB(--cpu2.s, cpu2.y>>8);
- WrMemB(--cpu2.s, cpu2.x&0xFF); WrMemB(--cpu2.s, cpu2.x>>8);
- WrMemB(--cpu2.s, cpu2.dp); WrMemB(--cpu2.s, cpu2.b);
- WrMemB(--cpu2.s, cpu2.a); WrMemB(--cpu2.s, cpu2.cc);
- cpu2.cc |= 0x50; // Set F,I
- cpu2.pc = (grom2[0xFFF8]<<8) | grom2[0xFFF9]; // And do it!
- }
- }
-// } // irqGoB
- // if (brk && (cpu1.pc == brkpnt)) running = false; // Stop running!
- }
- my_clock -= 25000; // Remove frame count from iclock*/
- } // END: enable_cpu
-// if (refresh++ == 1) // 30 Hz...
-// {
-// if (scr_type)
-// BlitWilliamsScreen(gram1); // Display the screen...
-// else
-// BlitChar(screen, chr_rom, gram1);
-// refresh = (refresh2 ? 1 : 0); // 60/30 Hz...
-// }
-
- // Speed throttling happens here...
- while (SDL_GetTicks() - oldTicks < 16); // Actually, it's 16.66... Need to account for that somehow
- oldTicks = SDL_GetTicks();
- }
+ cpu1.cpuFlags |= V6809_ASSERT_LINE_RESET;
+ cpu2.cpuFlags |= V6809_ASSERT_LINE_RESET;
+ }
-// Stop_audio_output();
-// ReleaseTimer();
-// ReleaseKeyboard(); // Release the interrupt...
-// RestoreOldMode(); // Restore screen
- if (brk && (cpu1.pc == brkpnt))
- cout << "CPU 1: Break at " << hex << cpu1.pc << endl;
- if (brk2 && (cpu2.pc == brkpnt2))
- cout << "CPU 2: Break at " << hex << cpu2.pc << endl;
+ if (keys[SDLK_d]) // (D) start disassembly
+ disasm = true;
+#if 0
+ if (keys[SDLK_k])
+ gram1[0x5606] = 0x00;
+ if (keys[SDLK_l])
+ {
+ gram1[0x5607] = 0x01; // Hangs here... (CPU #1 waiting...)
+ WriteLog("\nMAIN: Stuffed $01 in $5607!!!\n\n");
+ }
+ if (keys[SDLK_o])
+ {
+ gram1[0x5FF3] = 0x02;
+ WriteLog("\nMAIN: Stuffed $02 in $5FF3!!!\n\n");
+ }
+#endif
+#endif
- lbuff[0] = 'q'; // Temp kludge...
- }
- else if (lbuff[0] == 'b') // Set/clear breakpoint
+ if (enable_cpu)
+// if (true)
{
- if (lbuff[1] != 0)
+ // We can do this here because we're not executing the cores yet.
+ cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;
+ cpu2.cpuFlags |= V6809_ASSERT_LINE_IRQ;
+ mcu.cpuFlags |= V63701_ASSERT_LINE_IRQ;
+// while (cpu1.clock < 25000)
+// 1.538 MHz = 25633.333... cycles per frame (1/60 s)
+// 25600 cycles/frame
+// Setting interleave to 25 and below causes the V6809 core to hang...
+// 32 gets to the title screen before hanging...
+// 40 works, until it doesn't... :-P
+// 640 * 40
+// 800 * 32
+// Interesting, putting IRQs at 30 Hz makes it run at the correct speed. Still hangs in the demo, though.
+ for(uint32_t i=0; i<640; i++)
+// for(uint32_t i=0; i<1280; i++)
{
- lbuff[0] = 32;
- brkpnt = htod(lbuff);
- brk = true;
- cout << "Breakpoint #1 set at " << hex << brkpnt << dec << endl;
+ // Gay, but what are ya gonna do?
+ // There's better ways, such as keeping track of when slave writes to master, etc...
+ Execute6809(&cpu1, 40);
+ Execute6809(&cpu2, 40);
+
+ // MCU runs at 1,536,000 Hz
+ // 1536000 / 60 / 640 == 40
+ Execute63701(&mcu, 40);
}
- else
- {
- brk = false;
- cout << "Breakpoint cleared" << endl;
- }
- }
- else if (lbuff[0] == 'a') // Set/clear breakpoint #2
- {
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- brkpnt2 = htod(lbuff);
- brk2 = true;
- cout << "Breakpoint #2 set at " << hex << brkpnt2 << dec << endl;
- }
- else
- {
- brk2 = false;
- cout << "Breakpoint cleared" << endl;
- }
- }
- else if (lbuff[0] == 'i') // Inspect registers
- {
- printf("CPU1: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
- cpu1.a, cpu1.b, cpu1.cc, cpu1.dp, cpu1.x, cpu1.y, cpu1.s, cpu1.u, cpu1.pc);
- cout << " iclk=" << dec << cpu1.clock << endl;
- printf("CPU2: A=%02X B=%02X CC=%02X DP=%02X X=%04X Y=%04X S=%04X U=%04X PC=%04X",
- cpu2.a, cpu2.b, cpu2.cc, cpu2.dp, cpu2.x, cpu2.y, cpu2.s, cpu2.u, cpu2.pc);
- cout << " iclk=" << dec << cpu2.clock << endl;
- if (brk)
- cout << "Breakpoint #1 set at " << hex << brkpnt << dec << endl;
- if (brk2)
- cout << "Breakpoint #2 set at " << hex << brkpnt2 << dec << endl;
- }
- else if (strncmp(lbuff, "swap", 4) == 0) // Swap ROMs
- {
- looking_at_rom = !looking_at_rom;
- cout << "Swapped: Looking at ";
- (looking_at_rom ? cout << "ROM #1" : cout << "ROM #2");
- cout << endl;
- }
- else if (strncmp(lbuff, "seek", 4) == 0) // Seek non-zero bytes in RAM
- {
- if (lbuff[4] != 0)
- {
- for(int i=0; i<4; i++)
- lbuff[i] = 32;
- dpc = htod(lbuff);
- }
- do
- {
- x = gram1[dpc++];
- }
- while ((x == 0) && (dpc != 0xFFFF)); // Keep going until something found
- dpc--;
-
- printf("%04X: ", dpc); // Show data found...
- for(int i=0; i<16; i++)
- printf("%02X ", gram1[(WORD)(dpc+i)]);
- cout << " ";
- for(int i=0; i<16; i++)
- {
- BYTE a = gram1[dpc++];
- if (a<10)
- cout << (char)(a+48);
- if ((a>9) && (a<37))
- cout << (char)(a+55);
- if (a>36)
- cout << ".";
- }
- cout << endl;
- }
- else if (lbuff[0] == 'v') // View screen
- {
-// SetVESA2(); // Set up screen
- BlitChar(screen, chr_rom, gram1);
- getch();
-// RestoreOldMode();
- }
+ } // END: enable_cpu
- if (lbuff[0] == 'q')
- active = false; //break; // Quit
- }
+ // Speed throttling happens here...
+ while (SDL_GetTicks() - oldTicks < 16) // Actually, it's 16.66... Need to account for that somehow
+// while (SDL_GetTicks() - oldTicks < 32) // Actually, it's 16.66... Need to account for that somehow
+ SDL_Delay(1); // Release our timeslice...
- SDL_Quit(); // Shut down SDL
+ oldTicks = SDL_GetTicks();
+//cout << "Finished frame..." << endl;
+ }
- delete[] gram1; // Deallocate RAM & ROM spaces
- delete[] grom1;
- delete[] gram2;
- delete[] grom2;
- delete[] chr_rom;
- delete[] grom3;
- delete[] grom4;
- delete[] data_rom;
- delete[] spr_rom;
- delete[] voice_rom;
+ SDL_Quit();
+#if 1
+fclose(psg1);
+fclose(psg2);
+#endif
+#if 0
+ // Deallocate sounds if they were loaded
for(int i=0; i<16; i++)
- if (psg_adrs[i] != NULL)
- delete[] psg_adrs[i]; // Deallocate if loaded
-
+ if (psg_adrs[i])
+ delete[] psg_adrs[i];
+#endif
+#if 0
for(int i=0; i<14; i++)
- if (fm_adrs[i] != NULL)
- delete[] fm_adrs[i]; // Deallocate if loaded
+ if (fm_adrs[i])
+ delete[] fm_adrs[i];
+#endif
-// tr.close(); // Close tracelog
LogDone();
return 1;
}
+
+#if 0
+Hitachi uC runs at 6.144 MHz
+YM2151 runs at 3.579580 MHz
+
+
+Rolling Thunder Memory map
+--------------------------
+Most of the decoding is done by custom chips (CUS47 and CUS41), so the memory
+map is inferred by program behaviour. The customs also handle internally irq
+and watchdog.
+
+The main CPU memory map is the same in all games because CUS47 is used by all
+games. The sub CPU and sound CPU, on the other hand, change because CUS41 is
+replaced by other chips.
+
+All RAM is shared between main and sub CPU, except for sound RAM which is
+shared between main and sound CPU; the portion of object RAM that is overlapped
+by sound RAM is used exclusively by the sub CPU.
+
+MAIN CPU:
+
+Address Dir Data Name Description
+------------------- --- -------- --------- -----------------------
+000x xxxx xxxx xxxx R/W xxxxxxxx SCROLL0 tilemap 0/1 RAM (shared with sub CPU)
+001x xxxx xxxx xxxx R/W xxxxxxxx SCROLL1 tilemap 2/3 RAM (shared with sub CPU)
+0100 00xx xxxx xxxx R/W xxxxxxxx SOUND sound RAM (through CUS30, shared with MCU)
+0100 0000 xxxx xxxx R/W xxxxxxxx portion holding the sound wave data
+0100 0001 00xx xxxx R/W xxxxxxxx portion holding the sound registers
+010x xxxx xxxx xxxx R/W xxxxxxxx OBJECT work RAM (shared with sub CPU) [1]
+0101 1xxx xxxx xxxx R/W xxxxxxxx portion holding sprite registers
+011x xxxx xxxx xxxx R xxxxxxxx ROM 9D program ROM (banked) [2]
+1xxx xxxx xxxx xxxx R xxxxxxxx ROM 9C program ROM
+1000 00-- ---- ---- W -------- watchdog reset (RES generated by CUS47)
+1000 01-- ---- ---- W -------- main CPU irq acknowledge (IRQ generated by CUS47)
+1000 1x-- ---- ---- W -------- BANK tile gfx bank select (data is in A10) (latch in CUS47)
+1001 00-- ---- -x0x W xxxxxxxx LATCH0 tilemap 0/1 X scroll + priority
+1001 00-- ---- -x10 W xxxxxxxx LATCH0 tilemap 0/1 Y scroll
+1001 00-- ---- --11 W ------xx BAMNKM ROM 9D bank select
+1001 01-- ---- -x0x W xxxxxxxx LATCH1 tilemap 2/3 X scroll + priority
+1001 01-- ---- -x10 W xxxxxxxx LATCH1 tilemap 2/3 Y scroll
+1001 01-- ---- --11 W ------xx BAMNKS ROM 12D bank select
+1100 00-- ---- ---- W xxxxxxxx BACKCOLOR background color
+
+[1] Note that this is partially overlapped by sound RAM
+[2] In Rolling Thunder and others, replaced by the ROM/voice expansion board
+
+
+SUB CPU:
+
+Address Dir Data Name Description
+------------------- --- -------- --------- -----------------------
+000x xxxx xxxx xxxx R/W xxxxxxxx SUBOBJ work RAM (shared with main CPU)
+0001 1xxx xxxx xxxx R/W xxxxxxxx portion holding sprite registers
+001x xxxx xxxx xxxx R/W xxxxxxxx SUBSCR0 tilemap 0/1 RAM (shared with main CPU)
+010x xxxx xxxx xxxx R/W xxxxxxxx SUBSCR1 tilemap 2/3 RAM (shared with main CPU)
+011x xxxx xxxx xxxx R xxxxxxxx ROM 12D program ROM (banked) [1]
+1xxx xxxx xxxx xxxx R xxxxxxxx ROM 12C program ROM
+1000 0--- ---- ---- W -------- watchdog reset (MRESET generated by CUS41)
+1000 1--- ---- ---- W -------- main CPU irq acknowledge (generated by CUS41)
+1101 0--- ---- -x0x W xxxxxxxx LATCH0 tilemap 0/1 X scroll + priority
+1101 0--- ---- -x10 W xxxxxxxx LATCH0 tilemap 0/1 Y scroll
+1101 0--- ---- --11 W ------xx BAMNKM ROM 9D bank select
+1101 1--- ---- -x0x W xxxxxxxx LATCH1 tilemap 2/3 X scroll + priority
+1101 1--- ---- -x10 W xxxxxxxx LATCH1 tilemap 2/3 Y scroll
+1101 1--- ---- --11 W ------xx BAMNKS ROM 12D bank select
+
+[1] Only used by Rolling Thunder
+
+
+MCU:
+
+Address Dir Data Name Description
+------------------- --- -------- --------- -----------------------
+0000 0000 xxxx xxxx MCU internal registers, timers, ports and RAM
+0001 xxxx xxxx xxxx R/W xxxxxxxx RAM 3F sound RAM (through CUS30, partially shared with main CPU)
+0001 0000 xxxx xxxx R/W xxxxxxxx portion holding the sound wave data
+0001 0001 00xx xxxx R/W xxxxxxxx portion holding the sound registers
+0010 0--- --00 ---x R/W xxxxxxxx YMCS YM2151
+0010 0--- --01 ---- n.c.
+0010 0--- --10 ---- R xxxxxxxx PORTA switch inputs
+0010 0--- --11 ---- R xxxxxxxx PORTB dip switches
+01xx xxxx xxxx xxxx R xxxxxxxx ROM 6B program ROM (lower half)
+10xx xxxx xxxx xxxx R xxxxxxxx ROM 6B program ROM (upper half)
+1011 0--- ---- ---- W unknown (CUS41)
+1011 1--- ---- ---- W unknown (CUS41)
+1111 xxxx xxxx xxxx R xxxxxxxx MCU internal ROM
+
+
+Notes:
+-----
+- we are using an unusually high CPU interleave factor (800) to avoid hangs
+ in rthunder. The two 6809 in this game synchronize using a semaphore at
+ 5606/5607 (CPU1) 1606/1607 (CPU2). CPU1 clears 5606, does some quick things,
+ and then increments 5606. While it does its quick things (which require
+ about 40 clock cycles) it expects CPU2 to clear 5607.
+ Raising the interleave factor to 1000 makes wndrmomo crash during attract
+ mode. I haven't investigated on the cause.
+
+- There are two watchdogs, one per CPU (or maybe three). Handling them
+ separately is necessary to allow entering service mode without manually
+ resetting in rthunder and genpeitd: only one of the CPUs stops writing to
+ the watchdog.
+
+- The sprite hardware buffers spriteram: the program writes the sprite list to
+ offsets 4-9 of every 16-byte block, then at the end writes to offset 0x1ff2 of
+ sprite RAM to signal the chip that the list is complete. The chip will copy
+ the list from 4-9 to 10-15 and use it from there. This has not been verified
+ on the real hardware, but it is the most logical way of doing it.
+ Emulating this behaviour and not using an external buffer is important in
+ rthunder: when you insert a coin, the whole sprite RAM is cleared, but 0x1ff2
+ is not written to. If we buffered spriteram to an external buffer, this would
+ cause dangling sprites because the buffer would not be updated.
+
+- spriteram buffering fixes sprite lag, but causes a glitch in rthunder when
+ entering a door. The *closed* door is made of tiles, but the *moving* door is
+ made of sprites. Since sprites are delayed by 1 frame, when you enter a door
+ there is one frame where neither the tile-based closed door nor the
+ sprite-based moving door is shown, so it flickers. This behavior has been
+ confirmed on a real PCB.
+
+TODO:
+----
+- The two unknown writes for the MCU are probably watchdog reset and irq acknowledge,
+ but they don't seem to work as expected. During the first few frames they are
+ written out of order and hooking them up in the usual way causes the MCU to
+ stop receiving interrupts.
+
+#endif
+