X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fstargem2.cpp;fp=src%2Fstargem2.cpp;h=db2f65abb7e3061e04f7d6c6277dd0c9a34b2e49;hb=e3ad811139308bfe8a818cf5e42e7553785fea82;hp=107f8dbf241c13caab09edaff25b0b3f29de71e4;hpb=0c6f353827a94eb52c21e677658000f98452b247;p=stargem2 diff --git a/src/stargem2.cpp b/src/stargem2.cpp index 107f8db..db2f65a 100755 --- a/src/stargem2.cpp +++ b/src/stargem2.cpp @@ -10,10 +10,11 @@ // --- ---------- ------------------------------------------------------------ // JLH 06/15/2006 Added changelog ;-) // JLH 06/15/2006 Switched over to timeslice execution code -// JLH 07/15/2009 Solved problem with DEMO mode (IRQ handling) +// JLH 07/15/2009 Solved problem with DEMO mode (IRQ handling) (No, didn't) // -#include "SDL.h" + +#include #include #include #include @@ -21,7 +22,7 @@ #include #include #include -#include "types.h" +#include #include "log.h" #include "v6808.h" #include "v6809.h" @@ -32,6 +33,7 @@ #include "dis6809.h" #include "dis6808.h" + //#define __DEBUG__ //#define LOG_PIA1_IO @@ -52,27 +54,27 @@ using namespace std; // Global variables -uint8 gram[0x10000], grom[0x10000], sram[0x10000], srom[0x10000]; // RAM & ROM spaces +uint8_t gram[0x10000], grom[0x10000], sram[0x10000], srom[0x10000]; // RAM & ROM spaces V6809REGS mainCPU; V6808REGS soundCPU; -uint8 color[16]; -uint32 palette[256]; +uint8_t color[16]; +uint32_t palette[256]; bool paletteDirty = false; // Local variables static bool running = true; // Machine running state flag... -static uint32 startTicks; -static uint8 * keys; // SDL raw keyboard matrix -static uint64 clockFrameStart; // V6809 clock at the start of the frame +static uint32_t startTicks; +static const uint8_t * keys; // SDL raw keyboard matrix +static uint64_t clockFrameStart; // V6809 clock at the start of the frame // Function prototypes -uint8 RdMem6809(uint16 addr); -void WrMem6809(uint16 addr, uint8 b); -uint8 RdMem6808(uint16 addr); -void WrMem6808(uint16 addr, uint8 b); -bool LoadImg(const char * filename, uint8 * ram, int size); +uint8_t RdMem6809(uint16_t addr); +void WrMem6809(uint16_t addr, uint8_t b); +uint8_t RdMem6808(uint16_t addr); +void WrMem6808(uint16_t addr, uint8_t b); +bool LoadImg(const char * filename, uint8_t * ram, int size); void SaveCMOS(void); bool LoadMachineState(void); void SaveMachineState(void); @@ -90,12 +92,12 @@ int main(int /*argc*/, char * /*argv*/[]) { InitLog("stargem2.log"); WriteLog("StarGem2 - A portable Stargate emulator by James L. Hammons\n"); - WriteLog("(C) 2009 Underground Software\n\n"); + WriteLog("(C) 2013 Underground Software\n\n"); LoadSettings(); // Initialize Williams' palette (RGB coded as: 3 bits red, 3 bits green, 2 bits blue) - for(uint32 i=0; i<256; i++) + for(uint32_t i=0; i<256; i++) palette[i] = #if SDL_BYTEORDER == SDL_BIG_ENDIAN (((i & 0x01) * 33 + ((i & 0x02) >> 1) * 71 + ((i & 0x04) >> 2) * 151) << 24) @@ -132,7 +134,7 @@ int main(int /*argc*/, char * /*argv*/[]) for(int i=0; i<12; i++) { - uint32 baseAddress = i * 0x1000; + uint32_t baseAddress = i * 0x1000; if (i > 8) baseAddress += 0x4000; @@ -172,7 +174,7 @@ int main(int /*argc*/, char * /*argv*/[]) WriteLog("About to intialize audio...\n"); SoundInit(); - keys = SDL_GetKeyState(NULL); + keys = SDL_GetKeyboardState(NULL); srom[0xF800] = 0x37; // Fix checksum so ST works... running = true; // Set running status... @@ -197,7 +199,7 @@ 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; +/*uint16_t pc = mainCPU.pc;//0x15BA; for(int i=0; i<200; i++) //while (pc < 0x9000) { @@ -205,7 +207,7 @@ for(int i=0; i<200; i++) WriteLog("\n"); }//*/ -/*uint32 pc = 0; +/*uint32_t pc = 0; while (pc < 0xFFFF) { pc += Decode6809(pc); @@ -225,7 +227,7 @@ while (pc < 0xFFFF) // // Load a file into RAM/ROM image space // -bool LoadImg(const char * filename, uint8 * ram, int size) +bool LoadImg(const char * filename, uint8_t * ram, int size) { FILE * fp = fopen(filename, "rb"); @@ -272,10 +274,10 @@ bool LoadMachineState(void) fclose(fp); // Set up backbuffer... ;-) - for(uint16 i=0x0006; i<0x97F8; i++) // Screen memory + for(uint16_t i=0x0006; i<0x97F8; i++) // Screen memory WrMem6809(i, gram[i]); - for(uint16 i=0xC000; i<=0xC00F; i++) // Palette memory + for(uint16_t i=0xC000; i<=0xC00F; i++) // Palette memory WrMem6809(i, gram[i]); paletteDirty = true; @@ -318,9 +320,9 @@ void SaveMachineState(void) #ifdef LOG_PIA1_IO char piaRegsName[4][10] = { "PORTA", "PACTL", "PORTB", "PBCTL" }; #endif -uint8 RdMem6809(uint16 addr) +uint8_t RdMem6809(uint16_t addr) { - uint8 b; + uint8_t b; if (addr >= 0x9000 && addr <= 0xCFFF) // No ROM between $9000 - $CFFF... b = gram[addr]; @@ -340,11 +342,11 @@ uint8 RdMem6809(uint16 addr) { //Interesting, this code ALSO fucks up the demo... //Except when the correct code is called in the scanline callback function... - uint32 elapsedCycles = (uint32)(GetCurrentV6809Clock() - clockFrameStart); - uint32 scanline = (uint32)((double)elapsedCycles / SCANLINE_DURATION_IN_CYCLES); + uint32_t elapsedCycles = (uint32_t)(GetCurrentV6809Clock() - clockFrameStart); + uint32_t scanline = (uint32_t)((double)elapsedCycles / SCANLINE_DURATION_IN_CYCLES); //Changes here don't seem to do much... -// uint32 scanline = (uint32)(((double)elapsedCycles * M6809_CYCLE_IN_USEC) / 70.0); - b = (uint8)scanline & 0xFC; // Only bits 2-7 are connected... +// uint32_t scanline = (uint32_t)(((double)elapsedCycles * M6809_CYCLE_IN_USEC) / 70.0); + b = (uint8_t)scanline & 0xFC; // Only bits 2-7 are connected... } #endif @@ -365,7 +367,7 @@ uint8 RdMem6809(uint16 addr) } //temp... -/*extern uint16 pcr; +/*extern uint16_t pcr; //if (addr >= 0xC000 && addr <= 0xCBFF) if (addr == 0x9C59) WriteLog("RdMem: Reading address %04X [=%02X, PC=%04X]\n", addr, b, pcr);//*/ @@ -376,7 +378,7 @@ if (addr == 0x9C59) return b; } -void WrMem6809(uint16 addr, uint8 b) +void WrMem6809(uint16_t addr, uint8_t b) { //temp... //extern V6809REGS regs; @@ -392,11 +394,11 @@ void WrMem6809(uint16 addr, uint8 b) if (addr >= 0x0006 && addr < 0x97F7) // 304 pixels 152-128=24-16=8 { // NOTE: Screen was 304 x 256, but we truncate the vertical dimension here... - uint16 sx = (addr >> 7) & 0x01FE, sy = addr & 0x00FF; + uint16_t sx = (addr >> 7) & 0x01FE, sy = addr & 0x00FF; if (sy > 5 && sy < 246) { - uint32 saddr = 8 + sx + ((sy - 6) * 320); // Calc screen address + uint32_t saddr = 8 + sx + ((sy - 6) * 320); // Calc screen address scrBuffer[saddr + 0] = palette[color[b >> 4]]; scrBuffer[saddr + 1] = palette[color[b & 0x0F]]; } @@ -424,12 +426,12 @@ if (addr == 0xC80D) // 6808 memory functions // -uint8 RdMem6808(uint16 addr) +uint8_t RdMem6808(uint16_t addr) { return (addr < 0xF000 ? sram[addr] : srom[addr]); } -void WrMem6808(uint16 addr, uint8 b) +void WrMem6808(uint16_t addr, uint8_t b) { sram[addr] = b; @@ -445,7 +447,7 @@ static void FrameCallback(void) SDL_PumpEvents(); // Force key events into the buffer. gram[0xC804] = gram[0xC806] = gram[0xC80C] = 0; // Reset PIA ports... - if (keys[SDLK_ESCAPE]) + if (keys[SDL_SCANCODE_ESCAPE]) running = false; // ESC to exit... if (keys[settings.keyBindings[S_KEY_FIRE]]) gram[0xC804] |= 0x01; @@ -468,26 +470,26 @@ static void FrameCallback(void) if (keys[settings.keyBindings[S_KEY_CENTER_COIN]]) gram[0xC80C] |= 0x20; if (keys[settings.keyBindings[S_KEY_SLAM_SWITCH]]) gram[0xC80C] |= 0x40; - if (keys[SDLK_F5]) // Sound CPU self-test (F5) + if (keys[SDL_SCANCODE_F5]) // Sound CPU self-test (F5) soundCPU.cpuFlags |= V6808_ASSERT_LINE_NMI; - if (keys[SDLK_F6]) // Reset the 6808 (F6) + if (keys[SDL_SCANCODE_F6]) // Reset the 6808 (F6) soundCPU.cpuFlags |= V6808_ASSERT_LINE_RESET; //Temp, for testing... extern bool disasm; //disasm = true; - if (keys[SDLK_F9]) + if (keys[SDL_SCANCODE_F9]) disasm = true; if (paletteDirty) { - for(uint32 addr=0x0006; addr<0x97F7; addr++) + for(uint32_t addr=0x0006; addr<0x97F7; addr++) { - uint16 sx = (addr >> 7) & 0x01FE, sy = addr & 0x00FF; + uint16_t sx = (addr >> 7) & 0x01FE, sy = addr & 0x00FF; if (sy > 5 && sy < 246) { - uint32 saddr = 8 + sx + ((sy - 6) * 320); // Calc screen address - uint8 sb = gram[addr]; + uint32_t saddr = 8 + sx + ((sy - 6) * 320); // Calc screen address + uint8_t sb = gram[addr]; scrBuffer[saddr + 0] = palette[color[sb >> 4]]; scrBuffer[saddr + 1] = palette[color[sb & 0x0F]]; @@ -497,6 +499,19 @@ extern bool disasm; paletteDirty = false; } + static bool fullscreenDebounce = false; + + if (keys[SDL_SCANCODE_F12]) + { + if (!fullscreenDebounce) + { + ToggleFullScreen(); + fullscreenDebounce = true; + } + } + else + fullscreenDebounce = false; + RenderScreenBuffer(); // 1 frame = 1/60 sec ~ 16667 cycles clockFrameStart = mainCPU.clock;