First steps towards making config window/settings stick.

This commit is contained in:
Shamus Hammons 2020-09-08 17:01:44 -05:00
parent 6508be6bbd
commit f8d9fa1865
8 changed files with 150 additions and 16 deletions

View File

@ -118,7 +118,15 @@ static const char slotNum[7][(5 * 5) + 1] =
};
//static uint8_t card1[(96 * 11) + 1] = { 0 };
/*
0123456789ABCDEF
----------------
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ
m zorched to D ($6D -> $44) [0110 1101 -> 0100 0100]
*/
void Config::Init(SDL_Renderer * renderer)
{
@ -158,7 +166,7 @@ void Config::Init(SDL_Renderer * renderer)
SDL_SetRenderTarget(renderer, cardTex[2]);
GUI::DrawString(renderer, 6, 0, "SCSI");
cardBay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 123, 99);
cardBay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 123, 99);
SDL_SetTextureBlendMode(cardBay, SDL_BLENDMODE_BLEND);
SDL_SetRenderTarget(renderer, cardBay);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
@ -183,11 +191,11 @@ void Config::Init(SDL_Renderer * renderer)
objList.push_back(new CheckBox(1, 27, &cbnChecked, cbnText));
objList.push_back(new LineEdit(1, 6, le1, 48, le1Text));
objList.push_back(new Draggable(1 * FONT_WIDTH, 8 * FONT_HEIGHT, 96, 11, cardTex[0]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 9 * FONT_HEIGHT, 96, 11, cardTex[0]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 10 * FONT_HEIGHT, 96, 11, cardTex[1]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 11 * FONT_HEIGHT, 96, 11, cardTex[1]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 12 * FONT_HEIGHT, 96, 11, cardTex[2]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 8 * FONT_HEIGHT, 96, 11, &settings.cardSlot[0], cardTex[0]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 9 * FONT_HEIGHT, 96, 11, &settings.cardSlot[1], cardTex[0]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 10 * FONT_HEIGHT, 96, 11, &settings.cardSlot[2], cardTex[1]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 11 * FONT_HEIGHT, 96, 11, &settings.cardSlot[3], cardTex[1]));
objList.push_back(new Draggable(1 * FONT_WIDTH, 12 * FONT_HEIGHT, 96, 11, &settings.cardSlot[4], cardTex[2]));
}
@ -275,17 +283,19 @@ void Config::MouseUp(int32_t x, int32_t y, uint32_t buttons)
{
d->dragging = false;
if ((d->r.x > 120) && (d->r.x < 220) && (d->r.y > (8 * FONT_HEIGHT)) && (d->r.y < (15 * FONT_HEIGHT)))
if ((d->r.x > 120) && (d->r.x < 220)
&& (d->r.y > (8 * FONT_HEIGHT))
&& (d->r.y < (15 * FONT_HEIGHT)))
{
d->spot = ((d->r.y - (8 * FONT_HEIGHT)) / FONT_HEIGHT) + 1;
*(d->spot) = ((d->r.y - (8 * FONT_HEIGHT)) / FONT_HEIGHT) + 1;
d->r.x = 120;
d->r.y = (7 + d->spot) * FONT_HEIGHT;
d->r.y = (7 + *(d->spot)) * FONT_HEIGHT;
}
else
{
d->r.x = d->homex;
d->r.y = d->homey;
d->spot = 0;
*(d->spot) = 0;
}
refresh = true;

View File

@ -115,6 +115,7 @@ SDL_Texture * scrollLeftIcon = NULL;
SDL_Texture * scrollRightIcon = NULL;
bool DiskSelector::showWindow = false;
std::vector<FileStruct> fsList;
std::vector<FileStruct> hdList;
void DiskSelector::Init(SDL_Renderer * renderer)
@ -139,6 +140,7 @@ void DiskSelector::Init(SDL_Renderer * renderer)
SDL_UpdateTexture(window, NULL, windowPixels, DS_WIDTH * sizeof(Uint32));
FindDisks();
FindHardDisks();
DrawFilenames(renderer);
}
@ -156,8 +158,12 @@ void DiskSelector::FindDisks(void)
WriteLog("GUI (DiskSelector)::FindDisks(): # of columns is %i (%i files)\n", numColumns, fsList.size());
}
/*
OK, so the way that you can determine if a file is a directory in a cross-platform way is to do an opendir() call on a discovered filename. If it returns NULL, then it's a regular file and not a directory. Though I think the Linux method is more elegant. :-P
OK, so the way that you can determine if a file is a directory in a cross-
platform way is to do an opendir() call on a discovered filename. If it
returns NULL, then it's a regular file and not a directory. Though I think the
Linux method is more elegant. :-P
*/
//
// Find all disks images within path (recursive call does depth first search)
@ -356,6 +362,71 @@ bool DiskSelector::HasLegalExtension(const char * name)
}
//
// Find all disks images top level call
//
void DiskSelector::FindHardDisks(void)
{
hdList.clear();
FindHardDisks(settings.disksPath);
std::sort(hdList.begin(), hdList.end(), FileStruct());
WriteLog("GUI (DiskSelector)::FindHardDisks(): # of HDs is %i\n", hdList.size());
}
//
// Find all hard disk images within path (recursive call does depth first search)
//
void DiskSelector::FindHardDisks(const char * path)
{
DIR * dir = opendir(path);
if (!dir)
{
WriteLog("GUI (DiskSelector)::FindHardDisks: Could not open directory \"%s\%!\n", path);
return;
}
dirent * ent;
while ((ent = readdir(dir)) != NULL)
{
char buf[0x10000];
sprintf(buf, "%s/%s", path, ent->d_name);
// Cross-platform way to test if it's a directory (test = NULL -> file)
DIR * test = opendir(buf);
if (test == NULL)
{
const char * ext = strrchr(ent->d_name, '.');
if ((ext != NULL) && (strcasecmp(ext, ".2mg") == 0))
{
FileStruct fs;
fs.image = ent->d_name;
fs.fullPath = buf;
hdList.push_back(fs);
}
}
else
{
// Make sure we close the thing, since it's a bona-fide dir!
closedir(test);
// Only recurse if the directory is not one of the special ones...
if ((strcmp(ent->d_name, "..") != 0)
&& (strcmp(ent->d_name, ".") != 0))
{
FindHardDisks(buf);
}
}
}
closedir(dir);
}
void DiskSelector::DrawFilenames(SDL_Renderer * renderer)
{
if (SDL_SetRenderTarget(renderer, window) < 0)

View File

@ -20,6 +20,8 @@ class DiskSelector
static void ReadManifest(FILE *, DiskSet *);
static bool CheckManifest(const char *, DiskSet *);
static bool HasLegalExtension(const char *);
static void FindHardDisks();
static void FindHardDisks(const char *);
static void DrawFilenames(SDL_Renderer *);
static void ShowWindow(int);
static void HideWindow(void);

View File

@ -3,6 +3,7 @@
#include <SDL2/SDL.h>
#include <stdint.h>
#include "font10pt.h"
enum ObjectType { OTNone = 0, OTCheckBox, OTLineEdit, OTDraggable, OTCount };
@ -36,14 +37,26 @@ struct LineEdit {
struct Draggable {
OBJECT_COMMON;
uint8_t * spot;
int32_t homex, homey;
bool dragging;
SDL_Texture * img;
SDL_Rect dest;
uint8_t spot;
Draggable(): type(OTDraggable), hovered(false), homex(0), homey(0), dragging(false), img(0), spot(0) { r.x = r.y = r.w = r.h = 0; }
Draggable(int32_t xx, int32_t yy, int32_t w, int32_t h, SDL_Texture * i = 0): type(OTDraggable), hovered(false), homex(xx), homey(yy), dragging(false), img(i), spot(0) { r.x = xx; r.y = yy; r.w = w; r.h = h; }
Draggable(): type(OTDraggable), hovered(false), spot(0), homex(0), homey(0), dragging(false), img(0) { r.x = r.y = r.w = r.h = 0; }
Draggable(int32_t xx, int32_t yy, int32_t w, int32_t h, uint8_t * s = 0, SDL_Texture * i = 0): type(OTDraggable), hovered(false), spot(s), homex(xx), homey(yy), dragging(false), img(i)
{
r.x = xx;
r.y = yy;
r.w = w;
r.h = h;
if ((s) && (*s != 0))
{
r.x = 120;
r.y = (7 + *(spot)) * FONT_HEIGHT;
}
}
};
#endif // __ELEMENTS_H__

View File

@ -626,7 +626,7 @@ void InstallHardDrive(uint8_t slot)
hdData = ReadFile(fnBuf, &size);
if (hdData)
WriteLog("HD: Read Hard Drive image file, %u bytes ($%X)\n", size - 0x40, size - 0x40);
WriteLog("HD: Read Hard Drive image file '%s', %u bytes ($%X)\n", settings.hd[0], size - 0x40, size - 0x40);
else
WriteLog("HD: Could not read Hard Drive image file!\n");
}

View File

@ -68,7 +68,7 @@ void LoadSettings(void)
// strcpy(settings.BIOSPath, sdlemu_getval_string("BIOSROM", "./ROMs/apple2e-enhanced.rom"));
strcpy(settings.disksPath, GetValue("disks", "./disks/"));
strcpy(settings.hd[0], GetValue("harddrive1", "./disks/Pitch-Dark-20180731.2mg"));
strcpy(settings.hd[0], GetValue("harddrive1", ""));
strcpy(settings.hd[1], GetValue("harddrive2", ""));
strcpy(settings.hd[2], GetValue("harddrive3", ""));
strcpy(settings.hd[3], GetValue("harddrive4", ""));
@ -77,6 +77,12 @@ void LoadSettings(void)
strcpy(settings.hd[6], GetValue("harddrive7", ""));
strcpy(settings.autoStatePath, GetValue("autoStateFilename", "./apple2auto.state"));
settings.cardSlot[0] = GetValue("card1", 6); // Disk ][
settings.cardSlot[1] = GetValue("card2", 0); // Disk ][
settings.cardSlot[2] = GetValue("card3", 4); // Mockingboard
settings.cardSlot[3] = GetValue("card4", 0); // Mockingboard
settings.cardSlot[4] = GetValue("card5", 0); // AHSSCSI
CheckForTrailingSlash(settings.disksPath);
}
@ -107,6 +113,11 @@ void SaveSettings(void)
SetValue("harddrive5", settings.hd[4]);
SetValue("harddrive6", settings.hd[5]);
SetValue("harddrive7", settings.hd[6]);
SetValue("card1", settings.cardSlot[0]);
SetValue("card2", settings.cardSlot[1]);
SetValue("card3", settings.cardSlot[2]);
SetValue("card4", settings.cardSlot[3]);
SetValue("card5", settings.cardSlot[4]);
UpdateConfigFile();
}

View File

@ -41,6 +41,9 @@ struct Settings
char disksPath[MAX_PATH + 1];
char autoStatePath[MAX_PATH + 1];
char hd[7][MAX_PATH + 1];
// Card slots
uint8_t cardSlot[5]; // 0-1 = Disk ][, 2-3 = Mockingboard, 4 = AHSSCSI
};
// Render types

View File

@ -2287,6 +2287,7 @@ uint8_t btQueueInst[BACKTRACE_SIZE][4];
//
// Function to execute 65C02 for "cycles" cycles
//
//static bool first = true;
void Execute65C02(V65C02REGS * context, uint32_t cycles)
{
regs = context;
@ -2296,6 +2297,29 @@ void Execute65C02(V65C02REGS * context, uint32_t cycles)
while (regs->clock < endCycles)
{
// Hard disk debugging
#if 0
if (first && (regs->pc == 0x801))
{
regs->WrMem(0x42, 1);
regs->WrMem(0x44, 0);
first = false;
}
else if (regs->pc == 0x869)
{
/* regs->WrMem(0x42, 1);
first = false;//*/
/* static char disbuf[80];
uint16_t pc=0x801;
while (pc < 0xA00)
{
pc += Decode65C02(regs, disbuf, pc);
WriteLog("%s\n", disbuf);
}*/
/* dumpDis = true;
WriteLog("\n>>> $42-7: %02X %02X %02X %02X %02X %02X\n\n", regs->RdMem(0x42), regs->RdMem(0x43), regs->RdMem(0x44), regs->RdMem(0x45), regs->RdMem(0x46), regs->RdMem(0x47));//*/
}
#endif
#if 0
//Epoch
if (regs->pc == 0x0518)