]> Shamusworld >> Repos - apple2/commitdiff
Beginnings of new GUI
authorShamus Hammons <jlhamm@acm.org>
Fri, 30 Jan 2009 15:17:27 +0000 (15:17 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 30 Jan 2009 15:17:27 +0000 (15:17 +0000)
apple2.cfg
src/apple2.cpp
src/applevideo.cpp
src/gui/element.cpp
src/gui/gui.cpp
src/gui/guimisc.cpp
src/gui/menu.cpp
src/sound.cpp
src/timing.cpp
src/video.cpp
src/video.h

index 096874a50ca7c157cffbc33fcdc5e539342040a2..d2bda19e42b53d2a6cde7091961afe3d6dd4c749 100755 (executable)
@@ -24,9 +24,9 @@ autoSaveState = 1
 #floppyImage1 = ./disks/bt1_boot.dsk
 # Yes
 #floppyImage1 = ./disks/bt2_boot.dsk
-# No (PRODOS 8 V1.4 - UNABLE TO LOAD ATINIT FILE)
+# Yes (but segfaults in the timer routine in the title screen)
 floppyImage1 = ./disks/bt3_boot_fixed.dsk
-#floppyImage1 = ./disks/Bard's Tale III - The Thief of Fate (Boot) (Disk 1 of 4).dsk
+floppyImage2 = ./disks/bt3_character_fixed.dsk
 # Yes
 #floppyImage1 = ./disks/Sabotage.dsk
 # ??? (//c or //e w/128K required)
@@ -39,13 +39,17 @@ floppyImage1 = ./disks/bt3_boot_fixed.dsk
 #floppyImage1 = ./disks/wolfenstein_dos32.nib
 # Yes, keys???
 #floppyImage1 = ./disks/MidnightMagic_etc.dsk
-# ??? (PRODOS 8 V1.4 - UNABLE TO LOAD ATINIT FILE)
+# ??? Loads, then dumps to monitor (This is IIe or IIc only)
 #floppyImage1 = ./disks/battle_chess_1.dsk
 # Yes
 #floppyImage1 = ./disks/MoebiusI-1.dsk
-# Yes, but crashes on the attract mode
+#floppyImage2 = ./disks/MoebiusI-2.dsk
+# Yes, but crashes on the attract mode (does the same in AppleWin)
+# Also, has keyboard troubles... no, write problems
+#floppyImage1 = ./disks/moebiusiia.dsk
 #floppyImage1 = ./disks/MoebiusIIA.dsk
-# Yes
+#floppyImage2 = ./disks/MoebiusIIB.dsk
+# Yes, but segfaults on title screen
 #floppyImage1 = ./disks/wind_walker_1.dsk
 # Yes
 #floppyImage1 = ./disks/dino_eggs.dsk
@@ -58,11 +62,13 @@ floppyImage1 = ./disks/bt3_boot_fixed.dsk
 # Yes, autoloads!
 #floppyImage1 = ./disks/u2prog-patched.dsk
 #floppyImage2 = ./disks/u2player-jlh.dsk
+# Yes
+#floppyImage1 = ./disks/TheHeist.dsk
 
 
 # OpenGL options: 1 - use OpenGL rendering, 0 - use old style rendering
 
-useOpenGL = 1
+useOpenGL = 0
 
 # OpenGL filtering type: 1 - blurry, 0 - sharp
 
index 1021f2096356b9bc2a67f1fe6cd67f81d364c25d..6b24271cc009ef9d84dbaee7f0fa802285a9d777 100755 (executable)
@@ -555,7 +555,8 @@ SETALTCH = $C00F ;use alt char set- norm inverse, LC; no Flash (WR-only)
        {
 //Actually, according to the A2 ref, this should do nothing since a write
 //is immediately preceded by a read leaving it in the same state it was...
-//             keyDown = false;
+//But leaving this out seems to fuck up the key handling of some games...
+               keyDown = false;
        }
        else if (addr == 0xC050)
        {
@@ -787,7 +788,7 @@ int main(int /*argc*/, char * /*argv*/[])
 
 //Load up disk image from config file (for now)...
        floppyDrive.LoadImage(settings.diskImagePath1, 0);
-//     floppyDrive.LoadImage(settings.diskImagePath2, 1);
+       floppyDrive.LoadImage(settings.diskImagePath2, 1);
 //     floppyDrive.LoadImage("./disks/temp.nib", 1);   // Load temp .nib file into second drive...
 
 //Kill the DOS ROM in slot 6 for now...
@@ -848,7 +849,8 @@ memcpy(ram + 0xD000, ram + 0xC000, 0x1000);
        SoundInit();
        SDL_EnableUNICODE(1);                                           // Needed to do key translation shit
 
-       gui = new GUI(surface);                                         // Set up the GUI system object...
+//     gui = new GUI(surface);                                         // Set up the GUI system object...
+       gui = new GUI(mainSurface);                                     // Set up the GUI system object...
        gui->AddMenuTitle("Apple2");
        gui->AddMenuItem("Test!", TestWindow/*, hotkey*/);
        gui->AddMenuItem("");
index 86eeeda3899919cc47c2fb9e947036f340ad1c2b..ba8a2721a24dc21dcad4138bb700da63a1eb3c79 100755 (executable)
@@ -500,13 +500,13 @@ fb fb fb -> 15 [1111] -> 15               WHITE
                        {
                                uint8 scrByte = ram[lineAddrLoRes[y] + (displayPage2 ? 0x0400 : 0x0000) + x];
                                uint32 pixel = palette[scrByte & 0x0F];
-       
+
                                for(int cy=0; cy<4; cy++)
                                        for(int cx=0; cx<14; cx++)
                                                scrBuffer[((x * 14) + cx) + (((y * 8) + cy) * VIRTUAL_SCREEN_WIDTH)] = pixel;
-       
+
                                pixel = palette[scrByte >> 4];
-       
+
                                for(int cy=4; cy<8; cy++)
                                        for(int cx=0; cx<14; cx++)
                                                scrBuffer[(x * 14) + (y * VIRTUAL_SCREEN_WIDTH * 8) + cx + (cy * VIRTUAL_SCREEN_WIDTH)] = pixel;
@@ -633,7 +633,7 @@ fb fb fb -> 15 [1111] -> 15         WHITE
 
 static void RenderHiRes(uint16 toLine/*= 192*/)
 {
-// NOTE: Not endian safe. !!! FIX !!!
+// NOTE: Not endian safe. !!! FIX !!! [DONE]
 #if 0
        uint32 pixelOn = (screenType == ST_WHITE_MONO ? 0xFFFFFFFF : 0xFF61FF61);
 #else
index bbaff3cc757598c1e826b7c1387013b16667a1c0..c9401cf8ecd7c5a24972395426052bb04c626ba1 100755 (executable)
@@ -61,11 +61,16 @@ Element::Element(uint32 x, uint32 y, uint32 w, uint32 h,
        extents.h = h;
        coverList.push_back(extents);
 
+#if 0
        // This *should* allow us to store our colors in an endian safe way... :-/
        uint8 * c = (uint8 *)&fgColor;
        c[0] = fgR, c[1] = fgG, c[2] = fgB, c[3] = fgA;
        c = (uint8 *)&bgColor;
        c[0] = bgR, c[1] = bgG, c[2] = bgB, c[3] = bgA;
+#else
+       fgColor = SDL_MapRGBA(screen->format, fgR, fgG, fgB, fgA);
+       bgColor = SDL_MapRGBA(screen->format, bgR, bgG, bgB, bgA);
+#endif
 }
 
 Element::~Element()
index fb6a00080bd9d19fd45ac53b56a8d4eba95cf6ef..fa652146737a3f0a8ebc3c513c89f772b59ec02c 100755 (executable)
 #include "video.h"
 
 // Debug support
-
 //#define DEBUG_MAIN_LOOP
 
+// New main screen buffering
+// This works, but the colors are rendered incorrectly. Also, it seems that there's
+// fullscreen blitting still going on--dragging the disk is fast at first but then
+// gets painfully slow. Not sure what's going on there.
+#define USE_NEW_MAINBUFFERING
+
 //#ifdef DEBUG_MAIN_LOOP
 #include "log.h"
 //#endif
 
 
-GUI::GUI(SDL_Surface * mainSurface): menuItem(new MenuItems())
+GUI::GUI(SDL_Surface * surface): menuItem(new MenuItems())
 {
-       windowList.push_back(new Menu());
-       Element::SetScreen(mainSurface);
+       Element::SetScreen(surface);
+//     windowList.push_back(new Menu());
+
+// Create drive windows, and config windows here...
+
 }
 
 GUI::~GUI()
@@ -91,12 +99,17 @@ void GUI::Run(void)
        for(i=windowList.begin(); i!=windowList.end(); i++)
                (*i)->Draw();
 
+#ifndef USE_NEW_MAINBUFFERING
        RenderScreenBuffer();
+#else
+       FlipMainScreen();
+#endif
 
        // Main loop
        while (!exitGUI)
        {
-               if (SDL_PollEvent(&event))
+//             if (SDL_PollEvent(&event))
+               if (SDL_WaitEvent(&event))
                {
 #ifdef DEBUG_MAIN_LOOP
 WriteLog("An event was found!");
@@ -153,7 +166,11 @@ WriteLog(" -- SDL_USEREVENT\n");
 
 //Dirty rectangle is also possible...
                                else if (event.user.code == SCREEN_REFRESH_NEEDED)
+#ifndef USE_NEW_MAINBUFFERING
                                        RenderScreenBuffer();
+#else
+                                       FlipMainScreen();
+#endif
                        }
                        else if (event.type == SDL_ACTIVEEVENT)
                        {
@@ -161,7 +178,11 @@ WriteLog(" -- SDL_USEREVENT\n");
                                if (event.active.state == SDL_APPMOUSEFOCUS)
                                        showMouse = (event.active.gain ? true : false);
 
+#ifndef USE_NEW_MAINBUFFERING
                                RenderScreenBuffer();
+#else
+                                       FlipMainScreen();
+#endif
                        }
                        else if (event.type == SDL_KEYDOWN)
                        {
@@ -399,13 +420,21 @@ else
 
                        if (Element::ScreenNeedsRefreshing())
                        {
+#ifndef USE_NEW_MAINBUFFERING
 #ifdef DEBUG_MAIN_LOOP
 WriteLog("Screen refresh called!\n");
 #endif
                                RenderScreenBuffer();
                                Element::ScreenWasRefreshed();
+#else
+                               FlipMainScreen();
+                               Element::ScreenWasRefreshed();
+#endif
                        }
                }
+//hm. Works, but slows things way down.
+//Now we use WaitEvents() instead. Yay!
+//SDL_Delay(10);
        }
 
        SDL_EnableKeyRepeat(0, 0);
index 5c31f51ea064fe5a732789de52da3e818759be9c..6a7af2ea72647bce868a5f5aaa2fa56454eb6403 100755 (executable)
@@ -86,6 +86,12 @@ void DrawStringTrans(SDL_Surface * screen, uint32 x, uint32 y, uint32 color, con
        SDL_Rect rect;
        rect.x = x, rect.y = y;
 
+//bleh
+uint8 r1, g1, b1, a1;
+SDL_GetRGBA(color, screen->format, &r1, &g1, &b1, &a1);
+color = SDL_MapRGBA(chr->format, r1, g1, b1, a1);
+//helb
+
        for(uint32 i=0; i<length; i++)
        {
                uint8 c = string[i];
@@ -135,6 +141,14 @@ void DrawStringOpaque(SDL_Surface * screen, uint32 x, uint32 y, uint32 fg, uint3
        SDL_Rect rect;
        rect.x = x, rect.y = y;
 
+//bleh (we have to map colors from the HW surface to the SW surface)
+uint8 r1, g1, b1, a1;
+SDL_GetRGBA(fg, screen->format, &r1, &g1, &b1, &a1);
+fg = SDL_MapRGBA(chr->format, r1, g1, b1, a1);
+SDL_GetRGBA(bg, screen->format, &r1, &g1, &b1, &a1);
+bg = SDL_MapRGBA(chr->format, r1, g1, b1, a1);
+//helb
+
        for(uint32 i=0; i<length; i++)
        {
                uint8 c = string[i];
index 06d696b3e5862217e1a439b51d90c00a8ac23975..f5c273edc8f7e45b9d8bb253331181e760207479 100755 (executable)
@@ -62,11 +62,17 @@ Menu::Menu(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*= 0*/,
        activatedSave(false), clickedSave(false),
        insideSave(0), insidePopupSave(0), menuChosenSave(-1), menuItemChosenSave(-1)
 {
+#if 0
        // This *should* allow us to store our colors in an endian safe way... :-/
+       // Nope. Only on SW surfaces. With HW, all bets are off. :-(
        uint8 * c = (uint8 *)&fgColorHL;
        c[0] = fgchR, c[1] = fgchG, c[2] = fgchB, c[3] = fgchA;
        c = (uint8 *)&bgColorHL;
        c[0] = bgchR, c[1] = bgchG, c[2] = bgchB, c[3] = bgchA;
+#else
+       fgColorHL = SDL_MapRGBA(screen->format, fgchR, fgchG, fgchB, fgchA);
+       bgColorHL = SDL_MapRGBA(screen->format, bgchR, bgchG, bgchB, bgchA);
+#endif
 }
 
 Menu::~Menu()
index 5e92f48332051853aa767b2fe64bf1daa8f4db7f..b39fb82a992984ea11fdcb8a0b1db3daa16c6207 100755 (executable)
@@ -30,7 +30,7 @@
 #define SAMPLES_PER_FRAME      (SAMPLE_RATE / 60.0)
 #define CYCLES_PER_SAMPLE      (1024000.0 / SAMPLE_RATE)
 #define SOUND_BUFFER_SIZE      (8192)
-#define AMPLITUDE                      (32)                            // -32 - +32 seems to be plenty loud!
+//#define AMPLITUDE                    (16)                            // -32 - +32 seems to be plenty loud!
 
 // Global variables
 
@@ -46,6 +46,9 @@ static uint32 sampleBase;
 static SDL_cond * conditional = NULL;
 static SDL_mutex * mutex = NULL;
 static SDL_mutex * mutex2 = NULL;
+static uint8 ampPtr = 5;
+static uint16 amplitude[17] = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
+       4096, 8192, 16384, 32768 };
 
 // Private function prototypes
 
@@ -56,8 +59,8 @@ static void SDLSoundCallback(void * userdata, Uint8 * buffer, int length);
 //
 void SoundInit(void)
 {
-// To weed out problems for now...
 #if 0
+// To weed out problems for now...
 return;
 #endif
 
@@ -126,7 +129,7 @@ static void SDLSoundCallback(void * userdata, Uint8 * buffer, int length)
                        buffer[i] = soundBuffer[i];
 
                // Fill buffer with last value
-               memset(buffer + soundBufferPos, (uint8)(speakerState ? AMPLITUDE : -AMPLITUDE), length - soundBufferPos);
+               memset(buffer + soundBufferPos, (uint8)(speakerState ? amplitude[ampPtr] : -amplitude[ampPtr]), length - soundBufferPos);
                soundBufferPos = 0;                                             // Reset soundBufferPos to start of buffer...
                sampleBase = 0;                                                 // & sampleBase...
 //Ick. This should never happen!
@@ -215,7 +218,7 @@ WriteLog("--> after spinlock (sampleBase=%u)...\n", sampleBase);
 #endif
        }
 
-       int8 sample = (speakerState ? AMPLITUDE : -AMPLITUDE);
+       int8 sample = (speakerState ? amplitude[ampPtr] : -amplitude[ampPtr]);
 
        while (soundBufferPos < currentPos)
                soundBuffer[soundBufferPos++] = (uint8)sample;
index eafaa21f236edf8342ce4870592086751c9b11f5..e93ee1a7e77565474ef634c7306f083141b1f358 100755 (executable)
@@ -38,6 +38,7 @@ struct Event
     void (* timerCallback)(void);
 };
 
+//let's try +1... nope.
 static Event eventList[EVENT_LIST_SIZE];
 static uint32 nextEvent;
 
@@ -98,6 +99,7 @@ double GetTimeToNextEvent(void)
        // increasing time, we have to search through the list for the lowest one.
 
 //ALSO: There's a bug here--nextEvent is getting a bogus value/getting clobbered...
+//      Seems like it's getting clobbered somewhere other than here...
     double time = 0;
     bool firstTime = true;
 
@@ -125,6 +127,9 @@ double GetTimeToNextEvent(void)
        if (time == 0)
                WriteLog("TIMING: GetTimeToNextEvent() failed to find next event!\n");
 
+       if (nextEvent >= EVENT_LIST_SIZE)
+               WriteLog("TIMING: GetTimeToNextEvent() has bad nextEvent (=%u)!\n", nextEvent);
+
     return time;
 }
 
index 7f6891ebcaaa8fa9bb27788e02d33f2fa2f87a2b..170b2380fd192aba1c18a09ed6526c01c20e61fc 100755 (executable)
@@ -40,7 +40,7 @@
 SDL_Surface * surface, * mainSurface, * someAlphaSurface;
 Uint32 mainSurfaceFlags;
 //uint32 scrBuffer[VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT];
-uint32 * scrBuffer = NULL;
+uint32 * scrBuffer = NULL, * mainScrBuffer = NULL;
 SDL_Joystick * joystick;
 
 //
@@ -160,6 +160,8 @@ WriteLog("\n");//*/
        scrBuffer = (uint32 *)surface->pixels;  // Kludge--And shouldn't have to lock since it's a software surface...
 //needed? Dunno. Mebbe an SDL function instead?
 //     memset(scrBuffer, 0x00, VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint32));
+       // Set up the mainScrBuffer
+       mainScrBuffer = (uint32 *)mainSurface->pixels;  // May need to lock...
 
 #ifdef TEST_ALPHA_BLENDING
 //Here's some code to test alpha blending...
@@ -230,6 +232,20 @@ SDL_BlitSurface(someAlphaSurface, NULL, surface, &dstRect);
     }
 }
 
+// Is this even necessary? (Could call SDL_Flip directly...)
+void FlipMainScreen(void)
+{
+#ifdef TEST_ALPHA_BLENDING
+SDL_Rect dstRect = { 100, 100, 30, 30 };
+SDL_BlitSurface(someAlphaSurface, NULL, mainSurface, &dstRect);
+#endif
+
+       if (settings.useOpenGL)
+               sdlemu_draw_texture(mainSurface, surface, 1/*1=GL_QUADS*/);
+       else
+               SDL_Flip(mainSurface);
+}
+
 /*
 //
 // Resize the main SDL screen & scrBuffer
index 63716d42b74ab8dbffe2d90da1afc46ed2981a37..027ee645ad8af6fbf208ec0ea26b6c3b2dd6b0f5 100755 (executable)
@@ -17,6 +17,7 @@ bool InitVideo(void);
 void VideoDone(void);
 //void RenderBackbuffer(void);
 void RenderScreenBuffer(void);
+void FlipMainScreen(void);
 //void ResizeScreen(uint32 width, uint32 height);
 //uint32 GetSDLScreenPitch(void);
 //void ToggleFullscreen(void);
@@ -25,6 +26,8 @@ void RenderScreenBuffer(void);
 
 //extern uint32 scrBuffer[VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT];
 extern uint32 * scrBuffer;
+extern uint32 * mainScrBuffer;
 extern SDL_Surface * surface;
+extern SDL_Surface * mainSurface;
 
 #endif // __VIDEO_H__