From d4ea7fcec521fa4c22c6f1b9e2ceddb23d37651c Mon Sep 17 00:00:00 2001 From: Eric Hood Date: Sun, 21 Feb 2021 20:33:18 -0600 Subject: [PATCH] Moved QuickLoad to library --- EmuLoop.c | 2 +- LoadConfig.c | 1 - LoadIniFile.c | 1 - ReadIniFile.c | 118 -------------------------------------- ReadIniFile.h | 5 -- Vcc.vcxproj | 4 -- library/Config.c | 122 ++++++++++++++++++++++++++++++++++++++-- library/Config.h | 1 + library/QuickLoad.c | 101 +++++++++++++++++++++++++++++++++ library/QuickLoad.h | 5 ++ library/library.vcxproj | 2 + quickload.c | 118 -------------------------------------- quickload.h | 21 ------- 13 files changed, 228 insertions(+), 273 deletions(-) delete mode 100644 ReadIniFile.c delete mode 100644 ReadIniFile.h create mode 100644 library/QuickLoad.c create mode 100644 library/QuickLoad.h delete mode 100644 quickload.c delete mode 100644 quickload.h diff --git a/EmuLoop.c b/EmuLoop.c index 9d333b97..aaac31b9 100644 --- a/EmuLoop.c +++ b/EmuLoop.c @@ -6,8 +6,8 @@ #include "library/Throttle.h" #include "library/DirectDraw.h" #include "library/PAKInterface.h" +#include "library/QuickLoad.h" -#include "quickload.h" #include "HardReset.h" #include "SoftReset.h" #include "UpdateConfig.h" diff --git a/LoadConfig.c b/LoadConfig.c index f8c327d5..5aac4e5c 100644 --- a/LoadConfig.c +++ b/LoadConfig.c @@ -9,7 +9,6 @@ #include "library/fileoperations.h" #include "library/Audio.h" -#include "ReadIniFile.h" #include "UpdateConfig.h" #include "GetSoundCardList.h" #include "SoundInit.h" diff --git a/LoadIniFile.c b/LoadIniFile.c index 77e4d5fe..02109666 100644 --- a/LoadIniFile.c +++ b/LoadIniFile.c @@ -1,7 +1,6 @@ #include "library/VCC.h" #include "library/Config.h" -#include "ReadIniFile.h" #include "UpdateConfig.h" // LoadIniFile allows user to browse for an ini file and reloads the config from it. diff --git a/ReadIniFile.c b/ReadIniFile.c deleted file mode 100644 index f0182a66..00000000 --- a/ReadIniFile.c +++ /dev/null @@ -1,118 +0,0 @@ -#include - -#include "library/Config.h" -#include "library/Joystick.h" -#include "library/Keyboard.h" -#include "library/PAKInterface.h" -#include "library/systemstate.h" -#include "library/fileoperations.h" - -void SetWindowSize(POINT p) { - int width = p.x + 16; - int height = p.y + 81; - - HWND handle = GetActiveWindow(); - - SetWindowPos(handle, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); -} - -unsigned char ReadIniFile(SystemState* systemState) -{ - HANDLE hr = NULL; - POINT p = POINT(); - unsigned char index = 0; - - ConfigState* configState = GetConfigState(); - - //Loads the config structure from the hard disk - configState->CurrentConfig.CPUMultiplyer = GetProfileByte("CPU", "DoubleSpeedClock", 2); - configState->CurrentConfig.FrameSkip = GetProfileByte("CPU", "FrameSkip", 1); - configState->CurrentConfig.SpeedThrottle = GetProfileByte("CPU", "Throttle", 1); - configState->CurrentConfig.CpuType = GetProfileByte("CPU", "CpuType", 0); - configState->CurrentConfig.MaxOverclock = GetProfileShort("CPU", "MaxOverClock", 227); - - configState->CurrentConfig.AudioRate = GetProfileShort("Audio", "Rate", 3); - - GetPrivateProfileString("Audio", "SndCard", "", configState->CurrentConfig.SoundCardName, 63, configState->IniFilePath); - - configState->CurrentConfig.MonitorType = GetProfileByte("Video", "MonitorType", 1); - configState->CurrentConfig.PaletteType = GetProfileByte("Video", "PaletteType", 1); - configState->CurrentConfig.ScanLines = GetProfileByte("Video", "ScanLines", 0); - - configState->CurrentConfig.Resize = GetProfileByte("Video", "AllowResize", 0); - configState->CurrentConfig.Aspect = GetProfileByte("Video", "ForceAspect", 0); - configState->CurrentConfig.RememberSize = GetProfileShort("Video", "RememberSize", 0); - configState->CurrentConfig.WindowSizeX = GetProfileShort("Video", "WindowSizeX", 640); - configState->CurrentConfig.WindowSizeY = GetProfileShort("Video", "WindowSizeY", 480); - configState->CurrentConfig.AutoStart = GetProfileByte("Misc", "AutoStart", 1); - configState->CurrentConfig.CartAutoStart = GetProfileByte("Misc", "CartAutoStart", 1); - - configState->CurrentConfig.RamSize = GetProfileByte("Memory", "RamSize", 1); - - GetProfileText("Memory", "ExternalBasicImage", "", configState->CurrentConfig.ExternalBasicImage); - - GetProfileText("Module", "OnBoot", "", configState->CurrentConfig.ModulePath); - - configState->CurrentConfig.KeyMap = GetProfileByte("Misc", "KeyMapIndex", 0); - - if (configState->CurrentConfig.KeyMap > 3) { - configState->CurrentConfig.KeyMap = 0; //Default to DECB Mapping - } - - vccKeyboardBuildRuntimeTable((keyboardlayout_e)(configState->CurrentConfig.KeyMap)); - - FileCheckPath(configState->CurrentConfig.ModulePath); - FileCheckPath(configState->CurrentConfig.ExternalBasicImage); - - JoystickState* joystickState = GetJoystickState(); - - joystickState->Left.UseMouse = GetProfileByte("LeftJoyStick", "UseMouse", 1); - joystickState->Left.Left = GetProfileByte("LeftJoyStick", "Left", 75); - joystickState->Left.Right = GetProfileByte("LeftJoyStick", "Right", 77); - joystickState->Left.Up = GetProfileByte("LeftJoyStick", "Up", 72); - joystickState->Left.Down = GetProfileByte("LeftJoyStick", "Down", 80); - joystickState->Left.Fire1 = GetProfileByte("LeftJoyStick", "Fire1", 59); - joystickState->Left.Fire2 = GetProfileByte("LeftJoyStick", "Fire2", 60); - joystickState->Left.DiDevice = GetProfileByte("LeftJoyStick", "DiDevice", 0); - joystickState->Left.HiRes = GetProfileByte("LeftJoyStick", "HiResDevice", 0); - joystickState->Right.UseMouse = GetProfileByte("RightJoyStick", "UseMouse", 1); - joystickState->Right.Left = GetProfileByte("RightJoyStick", "Left", 75); - joystickState->Right.Right = GetProfileByte("RightJoyStick", "Right", 77); - joystickState->Right.Up = GetProfileByte("RightJoyStick", "Up", 72); - joystickState->Right.Down = GetProfileByte("RightJoyStick", "Down", 80); - joystickState->Right.Fire1 = GetProfileByte("RightJoyStick", "Fire1", 59); - joystickState->Right.Fire2 = GetProfileByte("RightJoyStick", "Fire2", 60); - joystickState->Right.DiDevice = GetProfileByte("RightJoyStick", "DiDevice", 0); - joystickState->Right.HiRes = GetProfileByte("RightJoyStick", "HiResDevice", 0); - - GetProfileText("DefaultPaths", "CassPath", "", configState->CurrentConfig.CassPath); - GetProfileText("DefaultPaths", "FloppyPath", "", configState->CurrentConfig.FloppyPath); - GetProfileText("DefaultPaths", "COCO3ROMPath", "", configState->CurrentConfig.COCO3ROMPath); - - for (index = 0; index < configState->NumberOfSoundCards; index++) { - if (!strcmp(configState->SoundCards[index].CardName, configState->CurrentConfig.SoundCardName)) { - configState->CurrentConfig.SndOutDev = index; - } - } - - configState->TempConfig = configState->CurrentConfig; - - InsertModule(systemState, configState->CurrentConfig.ModulePath); // Should this be here? - - configState->CurrentConfig.Resize = 1; //Checkbox removed. Remove this from the ini? - - if (configState->CurrentConfig.RememberSize) { - p.x = configState->CurrentConfig.WindowSizeX; - p.y = configState->CurrentConfig.WindowSizeY; - - SetWindowSize(p); - } - else { - p.x = 640; - p.y = 480; - - SetWindowSize(p); - } - - return(0); -} diff --git a/ReadIniFile.h b/ReadIniFile.h deleted file mode 100644 index cd3851a1..00000000 --- a/ReadIniFile.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "library/systemstate.h" - -unsigned char ReadIniFile(SystemState* systemState); diff --git a/Vcc.vcxproj b/Vcc.vcxproj index f4f1afa0..40b1603d 100644 --- a/Vcc.vcxproj +++ b/Vcc.vcxproj @@ -211,8 +211,6 @@ - - @@ -268,8 +266,6 @@ - - diff --git a/library/Config.c b/library/Config.c index 1401ed86..9dd4c241 100644 --- a/library/Config.c +++ b/library/Config.c @@ -5,16 +5,18 @@ #include #include "../resources/resource.h" -#include "systemstate.h" -#include "fileoperations.h" -#include "DirectDraw.h" -#include "PAKInterface.h" #include "Config.h" +#include "DirectDraw.h" +#include "PAKInterface.h" +#include "Keyboard.h" #include "Cassette.h" #include "Joystick.h" #include "MC6821.h" +#include "systemstate.h" +#include "fileoperations.h" + #include "macros.h" using namespace std; @@ -482,4 +484,116 @@ extern "C" { return(1); } +} + +void SetWindowSize(POINT p) { + int width = p.x + 16; + int height = p.y + 81; + + HWND handle = GetActiveWindow(); + + SetWindowPos(handle, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); +} + +extern "C" { + __declspec(dllexport) unsigned char __cdecl ReadIniFile(SystemState* systemState) + { + HANDLE hr = NULL; + POINT p = POINT(); + unsigned char index = 0; + + ConfigState* configState = GetConfigState(); + + //Loads the config structure from the hard disk + configState->CurrentConfig.CPUMultiplyer = GetProfileByte("CPU", "DoubleSpeedClock", 2); + configState->CurrentConfig.FrameSkip = GetProfileByte("CPU", "FrameSkip", 1); + configState->CurrentConfig.SpeedThrottle = GetProfileByte("CPU", "Throttle", 1); + configState->CurrentConfig.CpuType = GetProfileByte("CPU", "CpuType", 0); + configState->CurrentConfig.MaxOverclock = GetProfileShort("CPU", "MaxOverClock", 227); + + configState->CurrentConfig.AudioRate = GetProfileShort("Audio", "Rate", 3); + + GetPrivateProfileString("Audio", "SndCard", "", configState->CurrentConfig.SoundCardName, 63, configState->IniFilePath); + + configState->CurrentConfig.MonitorType = GetProfileByte("Video", "MonitorType", 1); + configState->CurrentConfig.PaletteType = GetProfileByte("Video", "PaletteType", 1); + configState->CurrentConfig.ScanLines = GetProfileByte("Video", "ScanLines", 0); + + configState->CurrentConfig.Resize = GetProfileByte("Video", "AllowResize", 0); + configState->CurrentConfig.Aspect = GetProfileByte("Video", "ForceAspect", 0); + configState->CurrentConfig.RememberSize = GetProfileShort("Video", "RememberSize", 0); + configState->CurrentConfig.WindowSizeX = GetProfileShort("Video", "WindowSizeX", 640); + configState->CurrentConfig.WindowSizeY = GetProfileShort("Video", "WindowSizeY", 480); + configState->CurrentConfig.AutoStart = GetProfileByte("Misc", "AutoStart", 1); + configState->CurrentConfig.CartAutoStart = GetProfileByte("Misc", "CartAutoStart", 1); + + configState->CurrentConfig.RamSize = GetProfileByte("Memory", "RamSize", 1); + + GetProfileText("Memory", "ExternalBasicImage", "", configState->CurrentConfig.ExternalBasicImage); + + GetProfileText("Module", "OnBoot", "", configState->CurrentConfig.ModulePath); + + configState->CurrentConfig.KeyMap = GetProfileByte("Misc", "KeyMapIndex", 0); + + if (configState->CurrentConfig.KeyMap > 3) { + configState->CurrentConfig.KeyMap = 0; //Default to DECB Mapping + } + + vccKeyboardBuildRuntimeTable((keyboardlayout_e)(configState->CurrentConfig.KeyMap)); + + FileCheckPath(configState->CurrentConfig.ModulePath); + FileCheckPath(configState->CurrentConfig.ExternalBasicImage); + + JoystickState* joystickState = GetJoystickState(); + + joystickState->Left.UseMouse = GetProfileByte("LeftJoyStick", "UseMouse", 1); + joystickState->Left.Left = GetProfileByte("LeftJoyStick", "Left", 75); + joystickState->Left.Right = GetProfileByte("LeftJoyStick", "Right", 77); + joystickState->Left.Up = GetProfileByte("LeftJoyStick", "Up", 72); + joystickState->Left.Down = GetProfileByte("LeftJoyStick", "Down", 80); + joystickState->Left.Fire1 = GetProfileByte("LeftJoyStick", "Fire1", 59); + joystickState->Left.Fire2 = GetProfileByte("LeftJoyStick", "Fire2", 60); + joystickState->Left.DiDevice = GetProfileByte("LeftJoyStick", "DiDevice", 0); + joystickState->Left.HiRes = GetProfileByte("LeftJoyStick", "HiResDevice", 0); + joystickState->Right.UseMouse = GetProfileByte("RightJoyStick", "UseMouse", 1); + joystickState->Right.Left = GetProfileByte("RightJoyStick", "Left", 75); + joystickState->Right.Right = GetProfileByte("RightJoyStick", "Right", 77); + joystickState->Right.Up = GetProfileByte("RightJoyStick", "Up", 72); + joystickState->Right.Down = GetProfileByte("RightJoyStick", "Down", 80); + joystickState->Right.Fire1 = GetProfileByte("RightJoyStick", "Fire1", 59); + joystickState->Right.Fire2 = GetProfileByte("RightJoyStick", "Fire2", 60); + joystickState->Right.DiDevice = GetProfileByte("RightJoyStick", "DiDevice", 0); + joystickState->Right.HiRes = GetProfileByte("RightJoyStick", "HiResDevice", 0); + + GetProfileText("DefaultPaths", "CassPath", "", configState->CurrentConfig.CassPath); + GetProfileText("DefaultPaths", "FloppyPath", "", configState->CurrentConfig.FloppyPath); + GetProfileText("DefaultPaths", "COCO3ROMPath", "", configState->CurrentConfig.COCO3ROMPath); + + for (index = 0; index < configState->NumberOfSoundCards; index++) { + if (!strcmp(configState->SoundCards[index].CardName, configState->CurrentConfig.SoundCardName)) { + configState->CurrentConfig.SndOutDev = index; + } + } + + configState->TempConfig = configState->CurrentConfig; + + InsertModule(systemState, configState->CurrentConfig.ModulePath); // Should this be here? + + configState->CurrentConfig.Resize = 1; //Checkbox removed. Remove this from the ini? + + if (configState->CurrentConfig.RememberSize) { + p.x = configState->CurrentConfig.WindowSizeX; + p.y = configState->CurrentConfig.WindowSizeY; + + SetWindowSize(p); + } + else { + p.x = 640; + p.y = 480; + + SetWindowSize(p); + } + + return(0); + } } \ No newline at end of file diff --git a/library/Config.h b/library/Config.h index 5da6ae3d..a0abc5bc 100644 --- a/library/Config.h +++ b/library/Config.h @@ -94,3 +94,4 @@ extern "C" __declspec(dllexport) unsigned char __cdecl TranslateScan2Display(int extern "C" __declspec(dllexport) void __cdecl RefreshJoystickStatus(void); extern "C" __declspec(dllexport) int __cdecl SelectFile(SystemState* systemState, char* filename); +extern "C" __declspec(dllexport) unsigned char __cdecl ReadIniFile(SystemState* systemState); diff --git a/library/QuickLoad.c b/library/QuickLoad.c new file mode 100644 index 00000000..e9b3e8ad --- /dev/null +++ b/library/QuickLoad.c @@ -0,0 +1,101 @@ +#include + +#include "QuickLoad.h" +#include "PAKInterface.h" +#include "MMU.h" + +#include "fileoperations.h" +#include "cpudef.h" + +extern "C" { + __declspec(dllexport) unsigned char __cdecl QuickLoad(SystemState* systemState, char* binFileName) + { + FILE* binImage = NULL; + unsigned int memIndex = 0; + unsigned char fileType = 0; + unsigned short fileLength = 0; + short startAddress = 0; + char extension[MAX_PATH] = ""; + unsigned char* memImage = NULL; + unsigned short xferAddress = 0; + + HANDLE hr = CreateFile(binFileName, NULL, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hr == INVALID_HANDLE_VALUE) { + return(1); //File Not Found + } + + CloseHandle(hr); + binImage = fopen(binFileName, "rb"); + + if (binImage == NULL) { + return(2); //Can't Open File + } + + memImage = (unsigned char*)malloc(65535); + + if (memImage == NULL) + { + MessageBox(NULL, "Can't alocate ram", "Error", 0); + return(3); //Not enough memory + } + + strcpy(extension, FilePathFindExtension(binFileName)); + _strlwr(extension); + + if ((strcmp(extension, ".rom") == 0) || (strcmp(extension, ".ccc") == 0) || (strcmp(extension, "*.pak") == 0)) + { + InsertModule(systemState, binFileName); + + return(0); + } + + if (strcmp(extension, ".bin") == 0) + { + while (true) + { + fread(memImage, sizeof(char), 5, binImage); + fileType = memImage[0]; + fileLength = (memImage[1] << 8) + memImage[2]; + startAddress = (memImage[3] << 8) + memImage[4]; + + switch (fileType) + { + case 0: + fread(&memImage[0], sizeof(char), fileLength, binImage); + + for (memIndex = 0; memIndex < fileLength; memIndex++) { //Kluge!!! + MemWrite8(memImage[memIndex], startAddress++); + } + + break; + + case 255: + xferAddress = startAddress; + + if ((xferAddress == 0) || (xferAddress > 32767) || (fileLength != 0)) + { + MessageBox(NULL, ".Bin file is corrupt or invalid Transfer Address", "Error", 0); + + return(3); + } + + fclose(binImage); + free(memImage); + GetCPU()->CPUForcePC(xferAddress); + + return(0); + + default: + MessageBox(NULL, ".Bin file is corrupt or invalid", "Error", 0); + fclose(binImage); + free(memImage); + + return(3); + } + } + } + + return(255); //Invalid File type + } +} \ No newline at end of file diff --git a/library/QuickLoad.h b/library/QuickLoad.h new file mode 100644 index 00000000..b14fbb6f --- /dev/null +++ b/library/QuickLoad.h @@ -0,0 +1,5 @@ +#pragma once + +#include "SystemState.h" + +extern "C" __declspec(dllexport) unsigned char __cdecl QuickLoad(SystemState* systemState, char* binFileName); diff --git a/library/library.vcxproj b/library/library.vcxproj index c65e74ba..07f7d7c2 100644 --- a/library/library.vcxproj +++ b/library/library.vcxproj @@ -198,6 +198,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/quickload.c b/quickload.c deleted file mode 100644 index d612927d..00000000 --- a/quickload.c +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright 2015 by Joseph Forgione -This file is part of VCC (Virtual Color Computer). - - VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - VCC (Virtual Color Computer) is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VCC (Virtual Color Computer). If not, see . -*/ - -#include -#include - -#include "library/cpudef.h" -#include "library/fileoperations.h" -#include "library/systemstate.h" -#include "library/MMU.h" -#include "library/PAKInterface.h" - -unsigned char QuickLoad(SystemState* systemState, char* binFileName) -{ - FILE* binImage = NULL; - unsigned int memIndex = 0; - unsigned char fileType = 0; - unsigned short fileLength = 0; - short startAddress = 0; - char extension[MAX_PATH] = ""; - unsigned char* memImage = NULL; - unsigned short xferAddress = 0; - - HANDLE hr = CreateFile(binFileName, NULL, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if (hr == INVALID_HANDLE_VALUE) { - return(1); //File Not Found - } - - CloseHandle(hr); - binImage = fopen(binFileName, "rb"); - - if (binImage == NULL) { - return(2); //Can't Open File - } - - memImage = (unsigned char*)malloc(65535); - - if (memImage == NULL) - { - MessageBox(NULL, "Can't alocate ram", "Error", 0); - return(3); //Not enough memory - } - - strcpy(extension, FilePathFindExtension(binFileName)); - _strlwr(extension); - - if ((strcmp(extension, ".rom") == 0) || (strcmp(extension, ".ccc") == 0) || (strcmp(extension, "*.pak") == 0)) - { - InsertModule(systemState, binFileName); - - return(0); - } - - if (strcmp(extension, ".bin") == 0) - { - while (true) - { - fread(memImage, sizeof(char), 5, binImage); - fileType = memImage[0]; - fileLength = (memImage[1] << 8) + memImage[2]; - startAddress = (memImage[3] << 8) + memImage[4]; - - switch (fileType) - { - case 0: - fread(&memImage[0], sizeof(char), fileLength, binImage); - - for (memIndex = 0; memIndex < fileLength; memIndex++) { //Kluge!!! - MemWrite8(memImage[memIndex], startAddress++); - } - - break; - - case 255: - xferAddress = startAddress; - - if ((xferAddress == 0) || (xferAddress > 32767) || (fileLength != 0)) - { - MessageBox(NULL, ".Bin file is corrupt or invalid Transfer Address", "Error", 0); - - return(3); - } - - fclose(binImage); - free(memImage); - GetCPU()->CPUForcePC(xferAddress); - - return(0); - - default: - MessageBox(NULL, ".Bin file is corrupt or invalid", "Error", 0); - fclose(binImage); - free(memImage); - - return(3); - } - } - } - - return(255); //Invalid File type -} - diff --git a/quickload.h b/quickload.h deleted file mode 100644 index 573e260a..00000000 --- a/quickload.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -/* -Copyright 2015 by Joseph Forgione -This file is part of VCC (Virtual Color Computer). - - VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - VCC (Virtual Color Computer) is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VCC (Virtual Color Computer). If not, see . -*/ - -unsigned char QuickLoad(SystemState* systemState, char* binFileName);