]> Shamusworld >> Repos - thunder/commitdiff
Fixed most keys
authorShamus Hammons <jlhamm@acm.org>
Thu, 23 Jul 2009 20:16:08 +0000 (20:16 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 23 Jul 2009 20:16:08 +0000 (20:16 +0000)
src/thunder.cpp

index fde0f3ef48289d66db1b384421d113357cab70ac..ed3f6c239377f124af84d5fd1b21a0e658c88bf6 100755 (executable)
@@ -126,6 +126,8 @@ uint8 * fm_adrs[14];
 fstream tr;    // Tracelog hook
 uint16    pcx;   // Where we at?
 
+static uint8 * keys;                                                   // 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,
@@ -959,14 +961,13 @@ int main(int argc, char * argv[])
 //  SDL_Surface * screen = NULL;      // SDL screen pointer
   SDL_Event event;                  // SDL "event"
 //  int keyPressed;                   // SDL key pressed...
-  uint8 keys[256];                   // Keyboard "switch-like" buffer
   extern uint8 palette[768];         // Screen physical palette
   uint32 ticks, oldTicks;
 
 //  tr.open("exe.log", ios::binary | ios::out); // Tracelog
 
   cout << endl << "THUNDER v"THUNDER_VERSION" ";
-  cout << "by James Hammmmons" << endl;
+  cout << "by James Hammons" << endl;
   cout << "Serial #20090723 / Prerelease" << endl;
   cout << "(C) 2003, 2009 Underground Software" << endl << endl;
 
@@ -983,6 +984,8 @@ int main(int argc, char * argv[])
 
   SDL_WM_SetCaption("Thunder v"THUNDER_VERSION" ", "Thunder");
 
+       keys = SDL_GetKeyState(NULL);                           // Get the SDL keyboard matrix
+
   cout << "Allocating memory..." << endl;
 //Does this anyway...  set_new_handler(0);    // Make 'new' return NULL on failure...
   gram1 = new uint8[0x10000];
@@ -1332,52 +1335,51 @@ WriteLog("About to enter main loop...\n");
 
                                // 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 !!!"
+       SDL_PumpEvents();                                                       // Force key events into the buffer.
 //                             keyPressed = 0;                                                 // Reset keypress
-                               while (SDL_PollEvent(&event) != 0)              // Bleed out all pending key events...
-                               {
-                                       if (event.type == SDL_KEYDOWN)
-                                               keys[event.key.keysym.scancode] = 1;
-                                       if (event.type == SDL_KEYUP)
-                                               keys[event.key.keysym.scancode] = 0;
-                               }
+//                             while (SDL_PollEvent(&event) != 0)              // Bleed out all pending key events...
+//                             {
+//                                     if (event.type == SDL_KEYDOWN)
+//                                             keys[event.key.keysym.scancode] = 1;
+//                                     if (event.type == SDL_KEYUP)
+//                                             keys[event.key.keysym.scancode] = 0;
+//                             }
 
 //        {
-                               if (keys[0x01])
+                               if (keys[SDLK_ESCAPE])
                                        running = false;                     // ESC to exit...
 
                                if (debounce)
                                        debounce--;                          // Debounce toggle keys...
                                else
                                {
-                                       if (keys[0x3B])
+                                       if (keys[SDLK_F1])
                                        {
                                                self_test = !self_test;            // Self-test (F1-toggle)
                                                debounce = 10;                     // Key debounce value...
                                        }
-                                       if (keys[0x3C])
+                                       if (keys[SDLK_F2])
                                        {
                                                gram1[0x4268] = 1;                 // Video test (F2)
                                                debounce = 10;                     // Key debounce value...
                                        }
-                                       if (keys[0x58])
+                                       if (keys[SDLK_F12])
                                        {
                                                scr_type = !scr_type;              // Toggle screen (F12)
                                                debounce = 10;                     // Key debounce value...
                                        }
-                                       if (keys[0x3D])
+                                       if (keys[SDLK_F3])
                                        {
                                                show_scr = !show_scr;              // Toggle bkgrnd (F3)
                                                debounce = 10;
                                        }
-                                       if (keys[0x40])
+                                       if (keys[SDLK_F6])
                                        {
                                                enable_cpu = !enable_cpu;          // Toggle CPUs (F6)
                                                debounce = 10;
                                        }
-                                       if (keys[0x3F])
+                                       if (keys[SDLK_F5])
                                        {
                                                refresh2 = !refresh2;             // Toggle 30/60Hz (F5)
                                                SetRefreshRate(refresh2);         // Inform GUI of refresh
@@ -1387,13 +1389,13 @@ WriteLog("About to enter main loop...\n");
                                                        SpawnMsg(M30FPS);
                                                debounce = 10;                    // Key debounce value...
                                        }
-                                       if (keys[0x3E])                      // Do PCX snapshot (F4)
+                                       if (keys[SDLK_F4])                      // Do PCX snapshot (F4)
                                        {
                                                SpawnSound(USERSOUND, SCAMERA);
                                                SnapPCX(screen);
                                                debounce = 10;
                                        }
-                                       if (keys[0x0F])                      // Tab active/deactivate GUI
+                                       if (keys[SDLK_TAB])                      // Tab active/deactivate GUI
                                        {
                                                if (ShowGUI())
                                                        DeactivateGUI();
@@ -1403,47 +1405,47 @@ WriteLog("About to enter main loop...\n");
                                        }
                                }
                                //if (keys[0x3E])  gram1[0x4247] = 1;  // Screen hold DS (F4)
-                               if (keys[77+128])                                               // Right arrow
+                               if (keys[SDLK_RIGHT])                                           // Right arrow
                                {
                                        if (ShowGUI())
                                                SelectRight();                     // If GUI active...
                                        else
                                        {
-                                               if (!keys[75+128])                     // Disallow opposite directions @ same time
+                                               if (!keys[SDLK_LEFT])                     // Disallow opposite directions @ same time
                                                        gram1[0x427F] = 1;               // Stick right
                                        }
                                }
-                               if (keys[75+128])
+                               if (keys[SDLK_LEFT])
                                {
                                        if (ShowGUI())
                                                SelectLeft();                      // If GUI active...
                                        else
                                        {
-                                               if (!keys[77+128])                     // Disallow opposite directions@same time
+                                               if (!keys[SDLK_RIGHT])                     // Disallow opposite directions@same time
                                                gram1[0x4281] = 1;               // Left arrow
                                        }
                                }
-                               if (keys[72+128])
+                               if (keys[SDLK_UP])
                                {
                                        if (ShowGUI())
                                                SelectUp();                        // If GUI active...
                                        else
                                        {
-                                               if (!keys[80+128])                     // Disallow opposite directions@same time
+                                               if (!keys[SDLK_DOWN])                     // Disallow opposite directions@same time
                                                        gram1[0x427B] = 1;               // Up arrow
                                        }
                                }
-                               if (keys[80+128])
+                               if (keys[SDLK_DOWN])
                                {
                                        if (ShowGUI())
                                                SelectDown();                                   // If GUI active...
                                        else
                                        {
-                                               if (!keys[72+128])                              // Disallow opposite directions@same time
+                                               if (!keys[SDLK_UP])                             // Disallow opposite directions@same time
                                                        gram1[0x427D] = 1;                      // Down arrow
                                        }
                                }
-                               if (keys[28])                                                   // Return
+                               if (keys[SDLK_RETURN])                                                  // Return
                                {
                                        uint8 retval = UserSelectedSomething();
                                        if (retval == EXIT)
@@ -1454,13 +1456,13 @@ WriteLog("About to enter main loop...\n");
                                                SetRefreshRate(refresh2);
                                        }
                                }
-                               if (keys[0x02])
+                               if (keys[SDLK_1])
                                        gram1[0x427A] = 1;                                      // (1)
-                               if (keys[0x03])
+                               if (keys[SDLK_2])
                                        gram1[0x427C] = 1;                                      // (2)
-                               if (keys[0x04])
+                               if (keys[SDLK_3])
                                        gram1[0x427E] = 1;                                      // (3)
-                               if (keys[0x06])
+                               if (keys[SDLK_5])
                                        gram1[0x4280] = 1;                                      // (5)
                                if (keys[0x10]|keys[29])
                                        gram1[0x4276] = 1;                                      // (Q)  Jump
@@ -1489,17 +1491,17 @@ WriteLog("About to enter main loop...\n");
                                        gram1[0x4262] = 1;                                      // (T)
                                if (keys[0x15])
                                        gram1[0x4260] = 1;                                      // (Y)
-                               if (keys[0x44])
+                               if (keys[SDLK_F10])
                                        gram1[0x41A5]++;                                        // Coin? (F10)
-                               if (keys[0x2C])
+                               if (keys[SDLK_z])
                                        gram1[0x4189]++;                                        // ? (Z) credits l dig
-                               if (keys[0x2D])
+                               if (keys[SDLK_x])
                                        gram1[0x418A]++;                                        // ? (X) credits r dig
-                               if (keys[0x2E])
+                               if (keys[SDLK_c])
                                        gram1[0x418C]++;                                        // ? (C) Start
-                               if (keys[0x2F])
+                               if (keys[SDLK_v])
                                        gram1[0x418D]++;                                        // ? (V)
-                               if (keys[0x41])
+                               if (keys[SDLK_F7])
                                        SpawnSound(USERSOUND, 0);                       // Do user sound (F7)
 //                             if (keys[0x42])
 //                             {
@@ -1507,7 +1509,7 @@ WriteLog("About to enter main loop...\n");
 //                                     charbase = false;                                       // Switch chars out...
 //                             }
 //                             if (keys[0x43])  gram1[0x4285] = 1;             // (F9) strobe unknown loc
-                               if (keys[0x45])                                                 // (F11)
+                               if (keys[SDLK_F1])                                                      // (F11)
                                {
                                        Execute6809(&cpu1, 10);
                                        Execute6809(&cpu2, 10);