// 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 "1.0.0"
+#define THUNDER_VERSION "1.1.0"
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
-//#include <conio.h> // For getch()
-#include <curses.h> // For getch()
+//#include <curses.h> // For getch()
#include <time.h>
-#include <SDL2/SDL.h> // Get yer SDL out...!
+#include <SDL2/SDL.h>
#include "v6809.h"
#include "screen.h"
#include "gui.h"
V6809REGS cpu1, cpu2;
-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 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;
uint32_t psg_lens[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
fstream tr; // Tracelog hook
uint16_t pcx; // Where we at?
-//kludge, for now
-//static uint8_t keys[0x1000]; // SDL raw keyboard matrix
-
-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" };
-
//
// Read a byte from memory (without touching PC. Not a Fetch!)
void WrMem(uint16_t addr, uint8_t b)
{
extern bool disasm;
- extern bool charbase; // Needed for screen. Extern it in it??
- //extern uint16_t sr, ur, xr, yr; // Needed for tracelog
- //extern uint16_t 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 << (uint16_t)gram1[0x4400+i] << " ";
- //}
- tr << endl;
- }//*/
+ extern bool charbase; // Needed for screen. Extern it in it??
#if 0
if (addr == 0x4182)
{
WriteLog("\nWriteMem: CPU #1 writing $%02X to $4182!\n\n", b);
}
#endif
-#if 1
+#if 0
if (((addr >= 0x4180) && (addr <= 0x4191)) || (addr == 0x4380))
printf("WriteMem: CPU #1 writing $%02X to $%04X...\n", b, addr);
#endif
//
uint8_t RdMemB(uint16_t addr)
{
-// extern uint16_t cpu2.s, cpu2.u, cpu2.x, cpu2.y; // Needed for tracelog
uint8_t b;
if (addr < 0x8000)
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;
}
{
extern bool disasm;
extern bool charbase;
- //extern uint16_t sr, ur, xr, yr; // Needed for tracelog
- //extern uint16_t 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 << (uint16_t)gram1[0x4400+i] << " ";
- //}
- tr << endl;
- }//*/
+
#if 0
if (addr == 0x0182)
{
WriteLog("\nWriteMem: CPU #2 writing $%02X to $0182 ($4182)!\n\n", b);
}
#endif
-#if 1
+#if 0
if (((addr >= 0x0180) && (addr <= 0x0191)) || (addr == 0x0380))
printf("WriteMem: CPU #2 writing $%02X to $%04X...\n", b, addr);
#endif
}
-//
-// Display bytes in mem in hex
-//
-void DisplayBytes(uint16_t src, unsigned long dst)
-{
- uint8_t cnt = 0;
- WriteLog("%04X: ", src);
-
- if (src > dst)
- dst += 0x10000; // That should fix the FFFF bug...
-
- for(unsigned long i=src; i<dst; i++)
- {
- WriteLog("%02X ", (uint8_t)(looking_at_rom ? RdMem(i) : RdMemB(i)));
- cnt++;
- }
-
- // Pad the leftover spaces...
- for(unsigned long i=cnt; i<5; i++)
- WriteLog(" ");
-}
-
-
-// temp crap...
-uint8_t Fetch(void) { return RdMem(dpc); }
-uint16_t FetchW(void) { return (uint16_t)((RdMem(dpc) << 8) | RdMem(dpc+1)); }
-uint8_t FetchB(void) { return RdMemB(dpc); }
-uint16_t FetchWB(void) { return (uint16_t)((RdMemB(dpc) << 8) | RdMemB(dpc+1)); }
-
-
-//
-// Decode a 6809 instruction at 'addr'
-//
-void Decode_6809()
-{
- uint8_t (* DFetch)(); // Decode Fetch() pointer...
- uint16_t (* DFetchW)(); // Decode FetchW() pointer...
- DFetch = (looking_at_rom ? Fetch : FetchB);
- DFetchW = (looking_at_rom ? FetchW : FetchWB);
-
- /* extern*/ uint16_t pcr, pcrB; // Pull in 'pcr' from '6809.cpp'
- uint16_t pc_save = pcr, pcB_save = pcrB;
- pcr = dpc; pcrB = dpc;
- uint8_t opcode = DFetch(); // Get the opcode ('fetch' cycle)
- uint8_t opcode2, operand;
- uint16_t loperand;
- uint8_t 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
- }
-
- // Decode it...
- switch (admode)
- {
- 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
- uint16_t tmpc = (looking_at_rom ? pcr : pcrB);
- sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16_t)(int8_t)operand);
- break;
- }
- case 4: // Long Relative
- {
- loperand = DFetchW(); // Get long offset
- uint16_t tmpc = (looking_at_rom ? pcr : pcrB);
- sprintf(outbuf, "%s $%04X", mnem, tmpc+(int16_t)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
- uint8_t reg = ((operand & 0x60) >> 5), idxind = ((operand & 0x10) >> 4),
- lo_nyb = (operand & 0x0F), boff;
- uint16_t 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
- WriteLog(outbuf);
- WriteLog("\n"); // display opcode & addressing, etc
- dpc = (looking_at_rom ? pcr : pcrB); // Advance debug PC
- pcr = pc_save;
- pcrB = pcB_save; // Restore PCs
-}
-
-
-//
-// Convert hex to dec
-//
-uint16_t htod(char * str)
-{
- uint16_t 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');
- else if (str[i] >= 'a' && str[i] <= 'f')
- value = (value << 4) | (unsigned)((str[i] - 'a') + 10);
- else if (str[i] >= 'A' && str[i] <= 'F')
- value = (value << 4) | (unsigned)((str[i] - 'A') + 10);
- }
-
- return value;
-}
-
-
-//
-// Load 32K file into ROM image space
-//
-bool Load32KImg(char * filename, uint16_t address)
-{
-#if 0
- ifstream ff;
- char ch;
-
- ff.open(filename, ios::binary | ios::in);
-
- if (ff)
- {
- // Read it in...
- for(long i=0; i<32768; i++)
- {
- ff.get(ch);
- grom[address+i] = ch;
- }
-
- ff.close();
- }
-
- return ff;
-#else
- FILE * file = fopen(filename, "rb");
-
- if (!file)
- return false;
-
- fread(&grom[address], 1, 0x8000, file);
-
- return true;
-#endif
-}
-
-
//
// Generic Load file into image space
// (No error checking performed! Responsibility of caller!)
//
bool LoadImg(const char * filename, uint8_t * mem, uint32_t address, uint32_t length)
{
- ifstream ff;
- char path[80];
- char ch;
+ char path[128];
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...
+ FILE * file = fopen(path, "rb");
- if (ff)
- {
- for(uint32_t i=0; i<length; i++) // Read it in...
- {
- ff.get(ch);
- mem[address+i] = ch;
- }
+ if (!file)
+ return false;
- ff.close(); // Close 'da file...
- }
+ fread(&mem[address], 1, length, file);
+ fclose(file);
- return ff;
+ return true;
}
fstream ff1, ff2;
// uint8_t ch;
char ch;
-// extern uint8_t palette[768]; // Screen physical palette
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
ff2.open("./ROMs/"PROM2, ios::binary | ios::in);
// If open was successful...
- if (ff1)
+ if (ff1 && ff2)
{
// Palette is 12-bit RGB, we stretch it to 24-bit
for(int i=0; i<256; i++)
}
psg_lens[i] = len;
-// cout << "Found sample file: " << file << "\t[Length: " << dec << len << "]" << endl;
printf("Found sample file: %s\t[Length: %u]\n", file, len);
}
{
fstream fp;
- fm_adrs[i] = NULL; // Zero out pointer
- sprintf(file, "./sounds/fm%i.wav", i); // Create filename
+ fm_adrs[i] = NULL; // Zero out pointer
+ sprintf(file, "./sounds/fm%i.wav", i); // Create filename
+ fp.open(file, ios::binary | ios::in); // Attempt to open it...
- fp.open(file, ios::binary | ios::in); // Attempt to open it...
+ if (!fp)
+ continue;
- if (fp)
- {
- len = GetWAVLength(fp); // Get WAV length...
- fm_adrs[i] = new uint8_t[len]; // Attempt to allocate space...
+ len = GetWAVLength(fp); // Get WAV length...
+ fm_adrs[i] = new uint8_t[len]; // Attempt to allocate space...
- if (fm_adrs[i] != NULL)
+ if (fm_adrs[i] != NULL)
+ {
+ for(int j=0; j<(signed)len; j++)
{
- for(int j=0; j<(signed)len; j++)
- {
- fp.get(ch);
- fm_adrs[i][j] = ch; // & load it in...
- }
-
- fm_lens[i] = len;
-// cout << "Found sample file: " << file << " [Length: " << dec << len << "]" << endl;
- printf("Found sample file: %s\t[Length: %u]\n", file, len);
+ fp.get(ch);
+ fm_adrs[i][j] = ch; // & load it in...
}
- fp.close();
+ fm_lens[i] = len;
+ printf("Found sample file: %s\t[Length: %u]\n", file, len);
}
+
+ fp.close();
}
}
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
-// bool refresh2 = true; // Default to 60 Hz...
uint8_t x; // General placeholder...
bool active = true; // Program running flag
cout << endl << "THUNDER v"THUNDER_VERSION" ";
cout << "by James Hammons" << endl;
- cout << "Serial #20149404 / Prerelease" << endl;
+ cout << "Serial #20149417 / Prerelease" << endl;
cout << "© 2003, 2014 Underground Software" << endl << endl;
cout << "This emulator is free software. If you paid for it you were RIPPED OFF"
<< endl << endl;
-#if 0
- 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;
- }
-#endif
-
// SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder");
-// keys = SDL_GetKeyState(NULL); // Get the SDL keyboard matrix
-
gram = gram1; grom = grom1; // Needed only for debugger
-#if 0
- for(long i=0; i<0x10000; i++)
- {
- gram[i] = 0; grom[i] = 0; // Zero out memory
- gram2[i] = 0; grom2[i] = 0;
- }
-#else
memset(gram, 0, 0x10000);
memset(grom, 0, 0x10000);
memset(gram2, 0, 0x10000);
memset(grom2, 0, 0x10000);
-#endif
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; }
LoadPSGs();
LoadFMs();
- // Quick 'n' Dirty voice dump (sound 0x0E)
-/* uint32_t 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++;
- }//*/
-
// Set up V6809 execution contexts
memset(&cpu1, 0, sizeof(V6809REGS));
cpu2.WrMem = WrMemB;
cpu2.cpuFlags |= V6809_ASSERT_LINE_RESET;
- bool firstTime = true; // kludge...
+ uint32_t my_clock = 0;
+ running = true; // Set running status...
+ trace1 = false;
+ SetRefreshRate(refresh2); // Tell GUI our refresh rate
-WriteLog("About to go to the main loop...\n");
- while (active)
- {
- cout << ">";
- if (firstTime)
- {
- firstTime = false; // crappy kludge...
- lbuff[0] = 'r';
- lbuff[1] = 0;
- }
- else
- cin >> lbuff;
-
- if (lbuff[0] == 'd')
- {
- if (lbuff[1] != 0)
- {
- lbuff[0] = 32;
- dpc = htod(lbuff);
- }
- printf("%04X: ", dpc);
- uint16_t 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++)
- {
- uint8_t 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 ", (uint8_t)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 (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;
- }
- }
- else if ((lbuff[0] == 'r') || (lbuff[0] == 'c')) // Run/continue...
- {
-WriteLog("Executing 'run' command...\n");
- uint32_t my_clock = 0;
- running = true; // Set running status...
- trace1 = false;
- SetRefreshRate(refresh2); // Tell GUI our refresh rate
- //for(uint16_t 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");
#if 1
- // 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;
+ // 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;
+ banksw1 = 0; // Will this work?
+ banksw2 = 0;
// iclock = 0; // Reset instr clock #1...
- InitGUI(); // Reset # of coins
-
-#if 0
- 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);
- }
-#endif
-#if 0
-WriteLog("--> CPU clock #1: %u\n", cpu1.clock);
- // Will *this* help video sync? NO
- while (cpu1.clock < 8000) // was 17000, 20000, 5000
- {
- Execute6809(&cpu1, 1);
- Execute6809(&cpu2, 1);
- }
-#endif
- }
+ InitGUI(); // Reset # of coins
WriteLog("About to set up screen...\n");
-#if 0
- screen = SDL_SetVideoMode(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, 8, SDL_SWSURFACE | SDL_DOUBLEBUF);
- if (screen == NULL)
- {
- cout << "Failed to initialize screen!" << endl;
- running = false;
- }
-#else
- InitVideo();
-#endif
-
-#if 0
- 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);
-#endif
-
-#if 0
- for(int i=0; i<256; i++)
- keys[i] = 0; // Clear keyboard buffer...
-#endif
+ InitVideo();
- oldTicks = SDL_GetTicks();
+ oldTicks = SDL_GetTicks();
WriteLog("About to set up audio...\n");
#if 1
- // 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;
- }
+ // 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!
+ SDL_PauseAudio(0); // Get that audio going!
#endif
memset(scrBuffer, 0xFF, VIRTUAL_SCREEN_WIDTH*VIRTUAL_SCREEN_HEIGHT*sizeof(uint32_t));
RenderScreenBuffer();
+
WriteLog("About to enter main loop...\n");
- while (running)
- {
- HandleGUIDebounce(); // Debounce GUI keys
+ while (running)
+ {
+ HandleGUIDebounce(); // Debounce GUI keys
- if (game_over_switch)
- {
- game_over_switch--; // Countdown...
+ if (game_over_switch)
+ {
+ game_over_switch--; // Countdown...
- if (game_over_switch == 0)
- gram1[0x4380] = 0; // Kill music!
- }
+ if (game_over_switch == 0)
+ gram1[0x4380] = 0; // Kill music!
+ }
//testing... (works)
//gram1[0x423D] = 1;
- //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...
-
-// SDL_PumpEvents(); // Force key events into the buffer.
- SDL_Event event;
-
- while (SDL_PollEvent(&event))
+ //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...
+
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ running = false;
+ else if (event.key.keysym.sym == SDLK_F10)
+ gram1[0x41A5]++; // Coin? (F10)
+ else if (event.key.keysym.sym == SDLK_c)
+ gram1[0x418C]++; // ? (C) Start
+ else if (event.key.keysym.sym == SDLK_RIGHT)
{
- switch (event.type)
- {
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- running = false;
- else if (event.key.keysym.sym == SDLK_F10)
- gram1[0x41A5]++; // Coin? (F10)
- else if (event.key.keysym.sym == SDLK_c)
- gram1[0x418C]++; // ? (C) Start
- }
+ // Disallow opposite directions @ same time
+ if (gram1[0x4281] == 0)
+ gram1[0x427F] = 1; // Stick right
}
+ else if (event.key.keysym.sym == SDLK_LEFT)
+ {
+ // Disallow opposite directions@same time
+ if (gram1[0x427F] == 0)
+ gram1[0x4281] = 1; // Stick left
+ }
+ else if (event.key.keysym.sym == SDLK_UP)
+ {
+ // Disallow opposite directions@same time
+ if (gram1[0x427D] == 0)
+ gram1[0x427B] = 1; // Stick up
+ }
+ else if (event.key.keysym.sym == SDLK_DOWN)
+ {
+ // Disallow opposite directions@same time
+ if (gram1[0x427B] == 0)
+ gram1[0x427D] = 1; // Stick down
+ }
+ else if (event.key.keysym.sym == SDLK_q)
+ gram1[0x4276] = 1; // (Q) Jump
+ else if (event.key.keysym.sym == SDLK_e) // (E) Fire
+ gram1[0x4278] = 1;
+
+ break;
+ case SDL_KEYUP:
+ if (event.key.keysym.sym == SDLK_RIGHT)
+ gram1[0x427F] = 0;
+ else if (event.key.keysym.sym == SDLK_LEFT)
+ gram1[0x4281] = 0;
+ else if (event.key.keysym.sym == SDLK_UP)
+ gram1[0x427B] = 0;
+ else if (event.key.keysym.sym == SDLK_DOWN)
+ gram1[0x427D] = 0;
+ else if (event.key.keysym.sym == SDLK_q)
+ gram1[0x4276] = 0; // (Q) Jump
+ else if (event.key.keysym.sym == SDLK_e) // (E) Fire
+ gram1[0x4278] = 0;
+
+ break;
+ }
+ }
#if 0
if (keys[SDLK_ESCAPE])
#endif
#endif
- if (enable_cpu)
+ if (enable_cpu)
// if (true)
- {
- // 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;
+ {
+ // 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;
// while (cpu1.clock < 25000)
// 1.538 MHz = 25633.333... cycles per frame (1/60 s)
// 25600 cycles/frame
// 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<640; i++)
// for(uint32_t i=0; i<1280; i++)
- {
- // 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);
- }
- } // 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...
-// }
-
-#if 0
-//temp, for testing...
-BlitChar(screen, chr_rom, gram1);
-#endif
- // 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...
-
- oldTicks = SDL_GetTicks();
-//cout << "Finished frame..." << endl;
- }
-
-// 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;
-
- lbuff[0] = 'q'; // Temp kludge...
- }
- else if (lbuff[0] == 'b') // Set/clear breakpoint
- {
- if (lbuff[1] != 0)
{
- lbuff[0] = 32;
- brkpnt = htod(lbuff);
- brk = true;
- cout << "Breakpoint #1 set at " << hex << brkpnt << dec << endl;
- }
- 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[(uint16_t)(dpc+i)]);
-
- cout << " ";
-
- for(int i=0; i<16; i++)
- {
- uint8_t a = gram1[dpc++];
-
- if (a<10)
- cout << (char)(a+48);
- if ((a>9) && (a<37))
- cout << (char)(a+55);
- if (a>36)
- cout << ".";
+ // 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);
}
+ } // END: enable_cpu
- cout << endl;
- }
- else if (lbuff[0] == 'v') // View screen
- {
- BlitChar(screen, chr_rom, gram1);
- getch();
- }
+ // 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...
- if (lbuff[0] == 'q')
- active = false; //break; // Quit
+ oldTicks = SDL_GetTicks();
+//cout << "Finished frame..." << endl;
}
- SDL_Quit(); // Shut down SDL
+ SDL_Quit();
+ // Deallocate sounds if they were loaded
for(int i=0; i<16; i++)
if (psg_adrs[i])
- delete[] psg_adrs[i]; // Deallocate if loaded
+ delete[] psg_adrs[i];
for(int i=0; i<14; i++)
if (fm_adrs[i])
- delete[] fm_adrs[i]; // Deallocate if loaded
+ delete[] fm_adrs[i];
LogDone();