#include "dis6809.h"
#include "dis6808.h"
+#define __DEBUG__
+
using namespace std;
-#define ROM1 "01"
-#define ROM2 "02"
-#define ROM3 "03"
-#define ROM4 "04"
-#define ROM5 "05"
-#define ROM6 "06"
-#define ROM7 "07"
-#define ROM8 "08"
-#define ROM9 "09"
-#define ROM10 "10"
-#define ROM11 "11"
-#define ROM12 "12"
-#define SOUNDROM "sg.snd"
+#define SOUNDROM "ROMs/sg.snd"
#define CMOS "cmos.ram"
#define SAVESTATE "sg2.state"
// Global variables
-uint8 * gram, * grom, * sram, * srom; // RAM & ROM pointers
+uint8 gram[0x10000], grom[0x10000], sram[0x10000], srom[0x10000]; // RAM & ROM spaces
V6809REGS mainCPU;
V6808REGS soundCPU;
uint8 color[16];
// Local variables
-//static uint8 lastKeyPressed = 0;
-//static bool keyDown = false;
-
-//static FloppyDrive floppyDrive;
-
-//enum { LC_BANK_1, LC_BANK_2 };
-
-//static uint8 visibleBank = LC_BANK_1;
-//static bool readRAM = false;
-//static bool writeRAM = false;
-
static bool running = true; // Machine running state flag...
static uint32 startTicks;
static uint8 * keys; // SDL raw keyboard matrix
void WrMem6808(uint16 addr, uint8 b)
{
sram[addr] = b;
+
+ // A total guess, but let's try it...
+//It probably depends on how the PIA is configured, so this is most likely wrong.
+// if (addr == 0x0401)
+// soundCPU.cpuFlags &= ~V6808_ASSERT_LINE_IRQ;
}
//
//
bool LoadImg(char * filename, uint8 * ram, int size)
{
- char pathname[4096];
-
- strcpy(pathname, settings.BIOSPath);
- strcat(pathname, filename);
-
- FILE * fp = fopen(pathname, "rb");
+ FILE * fp = fopen(filename, "rb");
if (fp == NULL)
- {
- WriteLog("Could not open file '%s'!\n", pathname);
return false;
- }
fread(ram, 1, size, fp);
fclose(fp);
//
int main(int /*argc*/, char * /*argv*/[])
{
-// bool running; // Machine running state flag...
-
- LoadSettings();
InitLog("stargem2.log");
WriteLog("StarGem2 - A portable Stargate emulator by James L. Hammons\n");
+ LoadSettings();
+
// Initialize Williams' palette (RGB coded as: 3 bits red, 3 bits green, 2 bits blue)
for(uint32 i=0; i<256; i++)
palette[i] =
| ((((i & 0x40) >> 6) * 71 + ((i & 0x80) >> 7) * 151) << 16) | 0xFF000000;
#endif
- gram = new uint8[0x10000];
- grom = new uint8[0x10000];
- sram = new uint8[0x10000];
- srom = new uint8[0x10000];
-
- if (gram == NULL)
- {
- WriteLog("Could not allocate RAM space!\nAborting!\n");
- return -1;
- }
- else if (grom == NULL)
- {
- WriteLog("Could not allocate ROM space!\nAborting!\n");
- return -1;
- }
- else if (sram == NULL)
- {
- WriteLog("Could not allocate sRAM space!\nAborting!\n");
- return -1;
- }
- else if (srom == NULL)
- {
- WriteLog("Could not allocate sROM space!\nAborting!\n");
- return -1;
- }
-
// Zero out memory
for(long i=0; i<0x10000; i++)
gram[i] = grom[i] = sram[i] = srom[i] = 0;
soundCPU.WrMem = WrMem6808;
soundCPU.cpuFlags |= V6808_ASSERT_LINE_RESET;
- if (!LoadImg(CMOS, gram + 0xCC00, 0x400))
- WriteLog("CMOS RAM not found!\n");
+ char ROMs[12][8] = {
+ "ROMs/01", "ROMs/02", "ROMs/03", "ROMs/04", "ROMs/05", "ROMs/06",
+ "ROMs/07", "ROMs/08", "ROMs/09", "ROMs/10", "ROMs/11", "ROMs/12"
+ };
- if (!LoadImg(ROM1, grom + 0x0000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM2, grom + 0x1000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM3, grom + 0x2000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM4, grom + 0x3000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM5, grom + 0x4000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM6, grom + 0x5000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM7, grom + 0x6000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM8, grom + 0x7000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM9, grom + 0x8000, 0x1000))
- return -1;
-
- if (!LoadImg(ROM10, grom + 0xD000, 0x1000))
- return -1;
+ for(int i=0; i<12; i++)
+ {
+ uint32 baseAddress = i * 0x1000;
- if (!LoadImg(ROM11, grom + 0xE000, 0x1000))
- return -1;
+ if (i > 8)
+ baseAddress += 0x4000;
- if (!LoadImg(ROM12, grom + 0xF000, 0x1000))
- return -1;
+#if 0
+WriteLog("Loading ROM image '%s' at $%04X...\n", ROMs[i], baseAddress);
+#endif
+// if (!LoadImg(ROMs[i], grom + (i * 0x1000), 0x1000))
+ if (!LoadImg(ROMs[i], grom + baseAddress, 0x1000))
+ {
+ WriteLog("Could not open file '%s'!\n", ROMs[i]);
+ return -1;
+ }
+ }
if (!LoadImg(SOUNDROM, srom + 0xF800, 0x800))
+ {
+ WriteLog("Could not open file '%s'!\n", SOUNDROM);
return -1;
+ }
WriteLog("Stargate ROM images loaded...\n");
WriteLog("About to initialize video...\n");
}
// Have to do this *after* video init but *before* sound init...!
+ WriteLog("About to load machine state...");
+
if (!LoadMachineState())
WriteLog("Machine state file not found!\n");
+ else
+ WriteLog("done!\n");
+
+ if (!LoadImg(CMOS, gram + 0xCC00, 0x400))
+ WriteLog("CMOS RAM not found!\n");
WriteLog("About to intialize audio...\n");
SoundInit();
HandleNextEvent();
}
+#ifdef __DEBUG__
+WriteLog("\n");
+WriteLog("$C900 = $%02X (0=RAM)\n", gram[0xC900]);
+WriteLog("PC: %04X, X: %04X, Y: %04X, S: %04X, U: %04X, A: %02X, B: %02X, DP: %02X, CC: %02X\n", mainCPU.pc, mainCPU.x, mainCPU.y, mainCPU.s, mainCPU.u, mainCPU.a, mainCPU.b, mainCPU.dp, mainCPU.cc);
+WriteLog("\n");
+
+/*uint16 pc = mainCPU.pc;//0x15BA;
+for(int i=0; i<200; i++)
+//while (pc < 0x9000)
+{
+ pc += Decode6809(pc);
+ WriteLog("\n");
+}//*/
+
+/*uint32 pc = 0;
+while (pc < 0xFFFF)
+{
+ pc += Decode6809(pc);
+ WriteLog("\n");
+}//*/
+#endif
+
#endif
SoundDone();
SaveMachineState();
LogDone();
- delete[] gram; // Deallocate RAM & ROM spaces
- delete[] grom;
- delete[] sram;
- delete[] srom;
-
return 0;
}