// --- ---------- -----------------------------------------------------------
// JLH 07/23/2009 Added changelog ;-)
// JLH 08/12/2009 Stabilized emulation so that it works
+// JLH 04/04/2014 Converted to SDL 2
//
#define THUNDER_VERSION "1.0.0"
//#include <conio.h> // For getch()
#include <curses.h> // For getch()
#include <time.h>
-#include "SDL.h" // Get yer SDL out...!
+#include <SDL2/SDL.h> // Get yer SDL out...!
#include "v6809.h"
#include "screen.h"
#include "gui.h"
#include "log.h"
+#include "video.h"
-using namespace std; // Yes!
+using namespace std;
#define ROM1 "rt3-1b.9c"
fstream tr; // Tracelog hook
uint16_t pcx; // Where we at?
-static uint8_t * keys; // SDL raw keyboard matrix
+//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,
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;
//
bool Load32KImg(char * filename, uint16_t address)
{
+#if 0
ifstream ff;
char ch;
- ff.open(filename, ios::binary | ios::in); // Open 'da file...
+ ff.open(filename, ios::binary | ios::in);
if (ff)
{
- for(long i=0; i<32768; i++) // Read it in...
+ // Read it in...
+ for(long i=0; i<32768; i++)
{
ff.get(ch);
grom[address+i] = ch;
}
- ff.close(); // Close 'da file...
+ ff.close();
}
return ff;
+#else
+ FILE * file = fopen(filename, "rb");
+
+ if (!file)
+ return false;
+
+ fread(&grom[address], 1, 0x8000, file);
+
+ return true;
+#endif
}
fstream ff1, ff2;
// uint8_t ch;
char ch;
- extern uint8_t palette[768]; // Screen physical palette
+// 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
- ff1.open("./ROMs/"PROM3, ios::binary|ios::in);
+ ff1.open("./ROMs/"PROM3, ios::binary | ios::in);
if (ff1)
{
ff1.close();
}
- ff1.open("./ROMs/"PROM4, ios::binary|ios::in);
+ ff1.open("./ROMs/"PROM4, ios::binary | ios::in);
if (ff1)
{
ff1.close();
}
- ff1.open("./ROMs/"PROM1, ios::binary|ios::in);
- ff2.open("./ROMs/"PROM2, ios::binary|ios::in);
+ ff1.open("./ROMs/"PROM1, ios::binary | ios::in);
+ ff2.open("./ROMs/"PROM2, ios::binary | ios::in);
- if (ff1) // If open was successful...
+ // If open was successful...
+ if (ff1)
{
- for(int i=0; i<768; i+=3)
+ // Palette is 12-bit RGB, we stretch it to 24-bit
+ for(int i=0; i<256; i++)
{
- ff1.get(ch);
- palette[i] = (uint8_t)(ch&0x0F);
- palette[i+1] = (uint8_t)(ch>>4);
- ff2.get(ch);
- palette[i+2] = (uint8_t)ch;
+ char c1, c2;
+ uint8_t r, g, b;
+ ff1.get(c1);
+ ff2.get(c2);
+ r = (uint8_t)c1 & 0x0F;
+ g = (uint8_t)c1 >> 4;
+ b = (uint8_t)c2;
+ palette[i] = 0xFF000000 | (b << 20) | (b << 16) | (g << 12) | (g << 8) | (r << 4) | r;
}
- // 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();
}
+ // 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;
}
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");
+// SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder");
- keys = SDL_GetKeyState(NULL); // Get the SDL keyboard matrix
+// 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;
}
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++)
}
SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256);
-
-#if 0
- // This confirms that we're getting video to the screen...
- SDL_LockSurface(screen);
-
- uint8_t pixel = 0;
- uint8_t * pixels = (uint8_t *)(screen->pixels);
-
- for(uint32_t y=0; y<480; y++)
- for(uint32_t x=0; x<640; x++)
- pixels[(y * 640) + x] = pixel++;
-
- SDL_UnlockSurface(screen);
- SDL_UpdateRect(screen, 0, 0, 0, 0);
#endif
+#if 0
for(int i=0; i<256; i++)
keys[i] = 0; // Clear keyboard buffer...
+#endif
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;
}
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
+
if (game_over_switch)
{
game_over_switch--; // Countdown...
+
if (game_over_switch == 0)
gram1[0x4380] = 0; // Kill music!
}
+
//testing... (works)
//gram1[0x423D] = 1;
//gram1[0x423D] = self_test; // Reset DSW1-1
// SDL key handling...
- SDL_PumpEvents(); // Force key events into the buffer.
+// SDL_PumpEvents(); // Force key events into the buffer.
+ SDL_Event event;
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ running = false;
+ }
+ }
+#if 0
if (keys[SDLK_ESCAPE])
running = false; // ESC to exit...
WriteLog("\nMAIN: Stuffed $02 in $5FF3!!!\n\n");
}
#endif
-
+#endif
if (enable_cpu)
// if (true)