//
-// Thunder: A Rolling Thunder Emulator w/6809 debugger v0.40
-// (Last build: 3/6/2004)
+// Thunder: A Rolling Thunder Emulator w/6809 debugger
//
// by James L. Hammons
+// (c) 2004, 2009 Underground Software
//
-// (c) 2004 Underground Software
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// WHO WHEN WHAT
+// --- ---------- ------------------------------------------------------------
+// JLH 07/23/2009 Added changelog ;-)
//
-#define THUNDER_VERSION "0.4.0"
-#define THUNDER_BETA_VERSION "6"
+#define THUNDER_VERSION "0.5.0"
#include <iostream>
#include <iomanip>
#include <new>
#include <stdio.h>
#include <stdlib.h>
-#include <conio.h> // For getch()
+//#include <conio.h> // For getch()
+#include <curses.h> // For getch()
#include <time.h>
#include "SDL.h" // Get yer SDL out...!
#include "types.h"
using namespace std; // Yes!
-/*
+#if 0
#define ROM1 "RT3-1B.ROM"
#define ROM2 "RT3-2B.ROM"
#define ROM3 "RT3-3.ROM"
#define PROM3 "RT1-3.BIN"
#define PROM4 "RT1-4.BIN"
#define PROM5 "RT1-5.BIN"
-*/
+#else
#define ROM1 "rt3-1b.9c"
#define ROM2 "rt3-2b.12c"
#define ROM3 "rt3-3.12d"
#define PROM4 "mb7138h.6v"
#define PROM5 "mb7112e.6u"
#define MCUROM "rt1-mcu.bin"
+#endif
// Global defines
V6809REGS cpu1, cpu2;
-bool trace = false; // ditto...
+bool trace1 = false; // ditto...
bool looking_at_rom = true; // true = R1, false = R2
DWORD banksw1, banksw2; // Bank switch addresses
WORD game_over_switch; // Game over delay
bool irqGoA = true; // IRQ switch for CPU #1
bool irqGoB = true; // IRQ switch for CPU #2
-WORD refresh = 0; // Crappy global screen stuff...
+WORD 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 };
"A", "B", "CC", "DP", "??", "??", "??", "??" },
iregs[4][2] = {"X", "Y", "U", "S" };
-//
-// Fetch a byte out of memory
-//
-/*BYTE Fetch()
-{
-// extern WORD sr, ur, xr, yr; // Needed for tracelog
- extern WORD pcr;
- BYTE b;
-
- b = (pcr < 0x8000 ? gram1[pcr] : grom1[pcr]);
- pcr++;
-
- return b;
-}*/
-
-//
-// 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!)
//
charbase = true; // Char banksw2
if (addr == 0x8400) // Frame go strobe? VBlank acknowledge?
{
- if (refresh++ == 1) // 30 Hz...
+ if (refresh_++ == 1) // 30 Hz...
{
BlitChar(screen, chr_rom, gram1);
- refresh = (refresh2 ? 1 : 0); // 60/30 Hz...
+ refresh_ = (refresh2 ? 1 : 0); // 60/30 Hz...
}
// irqGoA = true; // Will this work??? no...
cpu1.cpuFlags |= V6809_ASSERT_LINE_IRQ;//wil wok???
}
}
-//
-// Fetch a byte out of memory (2nd processor)
-//
-/*BYTE FetchB()
-{
-// 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;
-}
-
-//
-// 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)
//
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 "));
+ ? strcat(tmp, "U ") : strcat(tmp, "S "));
if (operand&0x80) strcat(tmp, "PC");
}
sprintf(outbuf, "%s %s", mnem, tmp);
case 8:
{ boff = DFetch(); sprintf(tmp, "($%02X,%s)", boff,
iregs[reg]); break; }
- case 9:
+ 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:
+ case 13:
{ woff = DFetchW(); sprintf(tmp, "($%04X,PC)", woff); break; }
case 15:
{ woff = DFetchW(); sprintf(tmp, "[$%04X]", woff); break; }
- default: strcpy(tmp, "??");
+ default: strcpy(tmp, "??");
}
}
else
case 8:
{ boff = DFetch(); sprintf(tmp, "($%02X),%s", boff,
iregs[reg]); break; }
- case 9:
+ 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:
+ case 13:
{ woff = DFetchW(); sprintf(tmp, "($%04X),PC", woff); break; }
- default: strcpy(tmp, "??");
+ default: strcpy(tmp, "??");
}
}
}
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;
}
}
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);
// 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, BYTE * mem, DWORD address, DWORD length)
{
ifstream ff;
char path[80];
// 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);
// 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 << endl << "THUNDER v"THUNDER_VERSION" ";
+ cout << "by James Hammmmons" << endl;
+ cout << "Serial #20090723 / Prerelease" << endl;
+ cout << "(C) 2003, 2009 Underground Software" << endl << endl;
- cout << "This emulator is freeware. If you paid for it you were RIPPED OFF"
+ cout << "This emulator is free software. If you paid for it you were RIPPED OFF"
<< endl << endl;
cout << "Initializing SDL..." << endl;
return -1;
}
- SDL_WM_SetCaption("Thunder Beta 6", "Thunder");
+ SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder");
cout << "Allocating memory..." << endl;
//Does this anyway... set_new_handler(0); // Make 'new' return NULL on failure...
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...
+ // Load samples if they're there...
+ LoadPSGs();
LoadFMs();
// Quick 'n' Dirty voice dump (sound 0x0E)
// 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;
lbuff[0] = 32;
dpc = htod(lbuff);
}
- printf("%04X: ", dpc);
+ 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++)
WriteLog("Executing 'run' command...\n");
DWORD my_clock = 0;
running = true; // Set running status...
- trace = false;
+ trace1 = false;
SetRefreshRate(refresh2); // Tell GUI our refresh rate
//for(WORD i=0; i<0x8000; i++) gram2[i] = grom3[i]; //Temp
else cpu1.cc = 0xFF; // Set CC register
cpu2.pc = ((grom2[0xFFFE]<<8) | grom2[0xFFFF]); // Reset 6809 #2
- cpu2.cc = 0xFF; // Set CC register
+ cpu2.cc = 0xFF; // Set CC register
while(iclock < 8000) // was 17000, 20000, 5000
{
Execute6809(&cpu1, 1); Execute6809(&cpu2, 1);
colors[i].g = palette[i*3+1];
colors[i].b = palette[i*3+2];
}
- SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256);
+ SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
+
+#if 1
+ // This confirms that we're getting video to the screen...
+ SDL_LockSurface(screen);
+
+ uint8 pixel = 0;
+ uint8 * pixels = (uint8 *)(screen->pixels);
+
+ for(uint32 y=0; y<480; y++)
+ for(uint32 x=0; x<640; x++)
+ pixels[(y * 640) + x] = pixel++;
+
+ SDL_UnlockSurface(screen);
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+#endif
for(int i=0; i<256; i++)
keys[i] = 0; // Clear keyboard buffer...
oldTicks = SDL_GetTicks();
+WriteLog("About to set up audio...\n");
// This crap SHOULD be in sound.cpp (not yet created)...
SDL_AudioSpec desired, obtained;
desired.freq = 22050;
}
SDL_PauseAudio(0); // Get that audio going!
+WriteLog("About to enter main loop...\n");
while (running)
{
HandleGUIDebounce(); // Debounce GUI keys
// SDL key handling...
+#warning "MAKE REPOSITORY FOR THIS THING! !!! FIX !!!"
+#warning "AND USE THE OLD SOURCE FOR THE BASE!!!"
+#warning "KEYS ARE FUCKED UP! !!! FIX !!!"
// keyPressed = 0; // Reset keypress
while (SDL_PollEvent(&event) != 0) // Bleed out all pending key events...
{
}
if (keys[0x3E]) // Do PCX snapshot (F4)
{
- SpawnSound(USERSOUND, SCAMERA);
+ SpawnSound(USERSOUND, SCAMERA);
SnapPCX(screen);
debounce = 10;
}
Execute6809(&cpu2, 10);
}
// }
- if (enable_cpu)
+
+// if (enable_cpu)
+ if (true)
{
/*// if (irqGoA)
cpu1.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;
+// 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 (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...
+// refresh_ = (refresh2 ? 1 : 0); // 60/30 Hz...
// }
+//temp, for testing...
+BlitChar(screen, chr_rom, gram1);
// Speed throttling happens here...
- while (SDL_GetTicks() - oldTicks < 16); // Actually, it's 16.66... Need to account for that somehow
+ while (SDL_GetTicks() - oldTicks < 16) // 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();