diff options
author | Won Star | 2006-01-06 12:48:48 +0000 |
---|---|---|
committer | Won Star | 2006-01-06 12:48:48 +0000 |
commit | 8b4627d2470e97a272adfcaec31fd0ea1156aa24 (patch) | |
tree | 125a4475b4202067e208a48398f20f341d1e00c7 /backends | |
parent | 948cb0d0f77170fdbc1b80b07feea7b9794751bc (diff) | |
download | scummvm-rg350-8b4627d2470e97a272adfcaec31fd0ea1156aa24.tar.gz scummvm-rg350-8b4627d2470e97a272adfcaec31fd0ea1156aa24.tar.bz2 scummvm-rg350-8b4627d2470e97a272adfcaec31fd0ea1156aa24.zip |
* Accurate / fast gamma correction using LUT
* Enable changing FM quality and sample rate
* Saves launcher setting to SMC
* Etc.
svn-id: r19929
Diffstat (limited to 'backends')
-rw-r--r-- | backends/gp32/Makefile | 2 | ||||
-rw-r--r-- | backends/gp32/globals.h | 41 | ||||
-rw-r--r-- | backends/gp32/gp32_launcher.cpp | 68 | ||||
-rw-r--r-- | backends/gp32/gp32_launcher.h | 5 | ||||
-rw-r--r-- | backends/gp32/gp32_main.cpp | 127 | ||||
-rw-r--r-- | backends/gp32/gp32_osys.cpp | 6 | ||||
-rw-r--r-- | backends/gp32/gp32std.cpp | 103 | ||||
-rw-r--r-- | backends/gp32/gp32std.h | 3 | ||||
-rw-r--r-- | backends/gp32/gp32std_grap.cpp | 37 | ||||
-rw-r--r-- | backends/gp32/gp32std_grap.h | 1 |
10 files changed, 239 insertions, 154 deletions
diff --git a/backends/gp32/Makefile b/backends/gp32/Makefile index 6420c7b714..44836306dd 100644 --- a/backends/gp32/Makefile +++ b/backends/gp32/Makefile @@ -68,7 +68,7 @@ CFLAGS = -marm -march=armv4t -mtune=arm920 -mapcs \ -mno-thumb-interwork \ -I$(GPSDK)/include \ -g \ - -O3 \ + -O2 \ -fomit-frame-pointer CPPFLAGS = $(CFLAGS) diff --git a/backends/gp32/globals.h b/backends/gp32/globals.h new file mode 100644 index 0000000000..4f4b21ee1f --- /dev/null +++ b/backends/gp32/globals.h @@ -0,0 +1,41 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001-2006 The ScummVM project + * Copyright (C) 2006 Won Star - GP32 Backend + * + * This program 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 2 + * of the License, or (at your option) any later version. + + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $Header$ + * + */ + +#ifndef __GLOBALS_H +#define __GLOBALS_H + +enum { + FM_QUALITY_LOW = 0, + FM_QUALITY_MED, + FM_QUALITY_HI +}; + +struct GlobalVars { + uint16 cpuSpeed; + uint16 gammaRamp; + uint8 fmQuality; + uint32 sampleRate; +}; + +extern GlobalVars g_vars; + +#endif diff --git a/backends/gp32/gp32_launcher.cpp b/backends/gp32/gp32_launcher.cpp index 5eaa1158a7..43753e2f70 100644 --- a/backends/gp32/gp32_launcher.cpp +++ b/backends/gp32/gp32_launcher.cpp @@ -23,9 +23,7 @@ #include "stdafx.h" #include "common/scummsys.h" -#include "common/scaler.h" -#include "common/system.h" -#include "backends/intern.h" +#include "common/file.h" #include "base/engine.h" @@ -35,17 +33,57 @@ #include "backends/gp32/gfx_splash.h" #include "backends/gp32/gp32_launcher.h" +#include "backends/gp32/globals.h" uint16 cpuSpeedTable[15] = {40, 66, 100, 120, 133, 144, 156, 160, 166, 172, 176, 180, 188, 192, 200}; -uint16 gammaTable[16] = {50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200}; +uint16 gammaTable[16] = {5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000}; char *oplTable[3] = {"LOW", "MEDIUM", "HIGH"}; uint16 sampleTable[3] = {11025, 22050, 44100}; uint8 maxTable[5] = {15, 16, 3, 3, 2}; -uint8 currentSetting[5] = {3, 5, 1, 0, 0}; +uint8 currentSetting[5] = {2, 5, 1, 0, 0}; -int g_cpuSpeed = 120; -int g_gammaRamp = 100; +void writeConfigVars() { + Common::File file; + + g_vars.cpuSpeed = cpuSpeedTable[currentSetting[0]]; + g_vars.gammaRamp = gammaTable[currentSetting[1]]; + g_vars.fmQuality = currentSetting[2]; + g_vars.sampleRate = sampleTable[currentSetting[3]]; + + if (!file.open("scummvm.cfg", Common::File::kFileWriteMode, "gp:\\gpetc\\")) { + return; + } + file.writeByte(currentSetting[0]); + file.writeByte(currentSetting[1]); + file.writeByte(currentSetting[2]); + file.writeByte(currentSetting[3]); + file.close(); +} + +void readConfigVars() { + Common::File file; + if (!file.exists("scummvm.cfg", "gp:\\gpetc\\")) { + currentSetting[0] = 2; + currentSetting[1] = 5; + currentSetting[2] = 1; + currentSetting[3] = 0; + writeConfigVars(); + } else { + if (!file.open("scummvm.cfg", Common::File::kFileReadMode, "gp:\\gpetc\\")) { + return; + } + currentSetting[0] = file.readByte(); + currentSetting[1] = file.readByte(); + currentSetting[2] = file.readByte(); + currentSetting[3] = file.readByte(); + g_vars.cpuSpeed = cpuSpeedTable[currentSetting[0]]; + g_vars.gammaRamp = gammaTable[currentSetting[1]]; + g_vars.fmQuality = currentSetting[2]; + g_vars.sampleRate = sampleTable[currentSetting[3]]; + file.close(); + } +} void configMenu() { uint32 nKeyUD; @@ -54,14 +92,17 @@ void configMenu() { int currentSelect = 0; char text[32]; + // OK / CANCEL + currentSetting[4] = 0; + while (1) { gp_fillRect(frameBuffer2, 0, 0, 320, 240, 0xffff); gp_textOut(frameBuffer2, 90, 10, "Configuration Menu", 0); gp_textOut(frameBuffer2, 30, 40, "CPU clock speed", 0); gp_textOut(frameBuffer2, 30, 80, "Gamma ramp", 0); - gp_textOut(frameBuffer2, 30, 120, "FMOPL (AdLib) quality", gp_RGBTo16(128, 128, 128)); - gp_textOut(frameBuffer2, 30, 160, "Sampling rate", gp_RGBTo16(128, 128, 128)); + gp_textOut(frameBuffer2, 30, 120, "FMOPL (AdLib) quality", 0); + gp_textOut(frameBuffer2, 30, 160, "Sampling rate", 0); gp_textOut(frameBuffer2, 100, 210, "OK CANCEL", 0); @@ -72,7 +113,7 @@ void configMenu() { sprintf(text, "%d MHz", cpuSpeedTable[currentSetting[0]]); gp_textOut(frameBuffer2, 220, 40, text, 0); - sprintf(text, "%d %%", gammaTable[currentSetting[1]]); + sprintf(text, "%.2f", (float)gammaTable[currentSetting[1]] / 10000); gp_textOut(frameBuffer2, 220, 80, text, 0); gp_textOut(frameBuffer2, 220, 120, oplTable[currentSetting[2]], gp_RGBTo16(128, 128, 128)); sprintf(text, "%d Hz", sampleTable[currentSetting[3]]); @@ -91,12 +132,12 @@ void configMenu() { currentSelect++; } if (gpd_getButtonDown(nKeyUD, GPC_VK_LEFT)) { - if (currentSelect <= 1) + if (currentSelect <= 3) if (currentSetting[currentSelect] > 0) currentSetting[currentSelect]--; } if (gpd_getButtonDown(nKeyUD, GPC_VK_RIGHT)) { - if (currentSelect <= 1) + if (currentSelect <= 3) if (currentSetting[currentSelect] < maxTable[currentSelect] - 1) currentSetting[currentSelect]++; } @@ -105,8 +146,7 @@ void configMenu() { gpd_getButtonUp(nKeyUD, GPC_VK_FA)) { if (currentSelect == 4) { if (currentSetting[currentSelect] == 0) { // OK - g_cpuSpeed = cpuSpeedTable[currentSetting[0]]; - g_gammaRamp = gammaTable[currentSetting[1]]; + writeConfigVars(); return; } else { // CANCEL return; diff --git a/backends/gp32/gp32_launcher.h b/backends/gp32/gp32_launcher.h index 6acc74f715..d1ca9e0cc1 100644 --- a/backends/gp32/gp32_launcher.h +++ b/backends/gp32/gp32_launcher.h @@ -26,9 +26,8 @@ #include "stdafx.h" #include "common/scummsys.h" -extern void splashScreen(); +extern void readConfigVars(); -extern int g_cpuSpeed; -extern int g_gammaRamp; +extern void splashScreen(); #endif diff --git a/backends/gp32/gp32_main.cpp b/backends/gp32/gp32_main.cpp index 65ab1ba223..1c1186e39a 100644 --- a/backends/gp32/gp32_main.cpp +++ b/backends/gp32/gp32_main.cpp @@ -22,125 +22,21 @@ #include "stdafx.h" #include "common/scummsys.h" -#include "common/scaler.h" -#include "common/system.h" -#include "backends/intern.h" -#include "base/engine.h" +#include "common/config-manager.h" #include "backends/gp32/gp32std.h" #include "backends/gp32/gp32std_grap.h" #include "backends/gp32/gp32_launcher.h" +#include "backends/gp32/globals.h" -#include "backends/gp32/gp32_osys.h" +GlobalVars g_vars; extern "C" int scummvm_main(int argc, char *argv[]); -extern void gp_delay(uint32 msecs); - -extern "C" void cpu_speed(int MCLK, int CLKDIV, int CLKMODE); // CPU Speed control (3 int's, clock, bus, dividor) - -// Where's better position? -static int CLKDIV = 0x48013; -static int MCLK = 40000000; -static int CLKMODE = 0; -static int HCLK = 40000000; -static int PCLK = 40000000; -/* -int gp_getPCLK() { - return PCLK; -} - -int gp_getHCLK() { - return HCLK; -} -*/ -void gp_clockSpeedChange(int freq, int magic, int div) { - #define rTCFG0 (*(volatile unsigned *)0x15100000) - #define rTCFG1 (*(volatile unsigned *)0x15100004) - #define rTCNTB4 (*(volatile unsigned *)0x1510003c) - unsigned int pclk; - unsigned int prescaler0; - - /* Change CPU Speed */ - GpClockSpeedChange(freq, magic, div); - pclk = GpPClkGet(); - - /* Repair SDK timer - it forgets to set prescaler */ - prescaler0 = (pclk / (8000 * 40)) - 1; - rTCFG0 = (rTCFG0 & 0xFFFFFF00) | prescaler0; - rTCFG1 = 0x30033; - - /* Repair GpTickCountGet */ - rTCNTB4 = pclk / 1600; -} - -void gp_setCpuSpeed(int freq) { - switch (freq) { - // overclocked - case 168: { CLKDIV = 0x14000; MCLK = 168000000; CLKMODE = 3; break; } - case 172: { CLKDIV = 0x23010; MCLK = 172000000; CLKMODE = 3; break; } - case 176: { CLKDIV = 0x24010; MCLK = 176000000; CLKMODE = 3; break; } - case 180: { CLKDIV = 0x16000; MCLK = 180000000; CLKMODE = 3; break; } - case 184: { CLKDIV = 0x26010; MCLK = 184000000; CLKMODE = 3; break; } - case 188: { CLKDIV = 0x27010; MCLK = 188000000; CLKMODE = 3; break; } - case 192: { CLKDIV = 0x18000; MCLK = 192000000; CLKMODE = 3; break; } - case 196: { CLKDIV = 0x29010; MCLK = 196000000; CLKMODE = 3; break; } - case 200: { CLKDIV = 0x2A010; MCLK = 200000000; CLKMODE = 3; break; } - case 204: { CLKDIV = 0x2b010; MCLK = 204000000; CLKMODE = 3; break; } - case 208: { CLKDIV = 0x2c010; MCLK = 208000000; CLKMODE = 3; break; } - case 212: { CLKDIV = 0x2d010; MCLK = 212000000; CLKMODE = 3; break; } - case 216: { CLKDIV = 0x2e010; MCLK = 216000000; CLKMODE = 3; break; } - case 220: { CLKDIV = 0x2f010; MCLK = 220000000; CLKMODE = 3; break; } - case 224: { CLKDIV = 0x30010; MCLK = 224000000; CLKMODE = 3; break; } - case 228: { CLKDIV = 0x1e000; MCLK = 228000000; CLKMODE = 3; break; } - case 232: { CLKDIV = 0x32010; MCLK = 232000000; CLKMODE = 3; break; } - case 236: { CLKDIV = 0x33010; MCLK = 236000000; CLKMODE = 3; break; } - case 240: { CLKDIV = 0x20000; MCLK = 240000000; CLKMODE = 3; break; } - case 244: { CLKDIV = 0x35010; MCLK = 244000000; CLKMODE = 3; break; } - case 248: { CLKDIV = 0x36010; MCLK = 248000000; CLKMODE = 3; break; } - case 252: { CLKDIV = 0x22000; MCLK = 252000000; CLKMODE = 3; break; } - case 256: { CLKDIV = 0x38010; MCLK = 256000000; CLKMODE = 3; break; } - - // normal -// case 166: { CLKDIV = 0x4B011; MCLK = 166000000; CLKMODE = 3; break; } - case 166: { CLKDIV = 0x2f001; MCLK = 165000000; CLKMODE = 3; break; } - case 164: { CLKDIV = 0x4a011; MCLK = 164000000; CLKMODE = 3; break; } - case 160: { CLKDIV = 0x48011; MCLK = 160000000; CLKMODE = 3; break; } -// case 156: { CLKDIV = 0x2c001; MCLK = 156000000; CLKMODE = 3; break; } - case 156: { CLKDIV = 0x2c001; MCLK = 156000000; CLKMODE = 3; break; } - case 144: { CLKDIV = 0x28001; MCLK = 144000000; CLKMODE = 3; break; } -// case 133: { CLKDIV = 0x3a011; MCLK = 132000000; CLKMODE = 3; break; } - case 133: { CLKDIV = (81 << 12) | (2 << 4) | 1; MCLK = 133500000; CLKMODE = 2; break; } - case 132: { CLKDIV = 0x3a011; MCLK = 132000000; CLKMODE = 3; break; } - case 120: { CLKDIV = 0x24001; MCLK = 120000000; CLKMODE = 2; break; } -// case 100: { CLKDIV = 0x2b011; MCLK = 102000000; CLKMODE=2; break; } - case 100: { CLKDIV =( 43 << 12) | (1 << 4) | 1; MCLK = 102000000; CLKMODE = 2; break; } -// case 66: { CLKDIV = 0x25002; MCLK= 67500000; CLKMODE=2; break; } - case 66: { CLKDIV = (37 << 12) | (0 << 4) | 2; MCLK= 67500000; CLKMODE = 2; break; } - case 50: { CLKDIV = 0x2a012; MCLK= 50000000; CLKMODE = 0; break; } -// case 40: { CLKDIV = 0x48013; MCLK= 40000000; CLKMODE = 0; break; } - case 40: { CLKDIV = 0x48013; MCLK= 40000000; CLKMODE = 1; break; } -// case 33: { CLKDIV = 0x25003; MCLK= 33750000; CLKMODE = 0; break; } - case 33: { CLKDIV = (37 << 12) | (0 << 4) | 3; MCLK = 33750000; CLKMODE = 2; break; } - case 22: { CLKDIV = 0x33023; MCLK = 22125000; CLKMODE = 0; break; } - } - if (CLKMODE==0) { HCLK = MCLK; PCLK = MCLK; } - if (CLKMODE==1) { HCLK = MCLK; PCLK = MCLK / 2; } - if (CLKMODE==2) { HCLK = MCLK / 2; PCLK = MCLK / 2; } - if (CLKMODE==3) { HCLK = MCLK / 2; PCLK = MCLK / 4; } - //cpu_speed(MCLK, CLKDIV, CLKMODE); - gp_clockSpeedChange(MCLK, CLKDIV, CLKMODE); -} - -void gp_Reset() { - gp_setCpuSpeed(66); - asm volatile("swi #4\n"); -} - void init() { - gp_setCpuSpeed(66); // Default CPU Speed + gp_setCpuSpeed(40); // Default CPU Speed GpGraphicModeSet(16, NULL); @@ -152,28 +48,23 @@ void init() { // error("Invalid Console"); gp_initFrameBuffer(); - GpFatInit(); GpRelativePathSet("gp:\\gpmm"); - //ERR_CODE err_code; - //err_code = GpDirCreate("temp", 0); - // if (err_code != SM_OK) return; - g_cpuSpeed = 120; } void GpMain(void *arg) { init(); + readConfigVars(); + splashScreen(); - + //doConfig - gp_setCpuSpeed(g_cpuSpeed); - GPDEBUG("Set CPU Speed: %d", g_cpuSpeed); + gp_initGammaTable((float)g_vars.gammaRamp / 10000); + gp_setCpuSpeed(g_vars.cpuSpeed); // FOR DEBUG PURPOSE! int argc = 2; - //char *argv[] = { "scummvm", "playfate" }; - //char *argv[] = { "scummvm", "-enull", "-pgp:\\game\\loomcd\\", "loomcd" }; //char *argv[] = { "scummvm", "-enull", "-pgp:\\game\\dott\\", "tentacle" }; char *argv[] = { "scummvm", "-enull", "-d3" }; diff --git a/backends/gp32/gp32_osys.cpp b/backends/gp32/gp32_osys.cpp index bb4933c2c4..97f24f3978 100644 --- a/backends/gp32/gp32_osys.cpp +++ b/backends/gp32/gp32_osys.cpp @@ -28,6 +28,8 @@ #include "common/scummsys.h" #include "common/system.h" +#include "backends/gp32/globals.h" + #include "common/rect.h" #include "common/savefile.h" #include "common/config-manager.h" @@ -647,6 +649,10 @@ bool OSystem_GP32::setSoundCallback(SoundProc proc, void *param) { GPSOUNDBUF gpSoundBuf; + ConfMan.set("FM_medium_quality", (g_vars.fmQuality == FM_QUALITY_MED)); + ConfMan.set("FM_high_quality", (g_vars.fmQuality == FM_QUALITY_HI)); + //ConfMan.set("sample_rate", (int)g_vars.sampleRate); + if (ConfMan.hasKey("output_rate")) _samplesPerSec = ConfMan.getInt("output_rate"); diff --git a/backends/gp32/gp32std.cpp b/backends/gp32/gp32std.cpp index 1a62cb13dc..bacf232310 100644 --- a/backends/gp32/gp32std.cpp +++ b/backends/gp32/gp32std.cpp @@ -158,6 +158,10 @@ GPFILE *gp_fopen(const char *fileName, const char *openMode) { file->cachePos = 0; mode = OPEN_W; err = GpFileCreate(fileName, ALWAYS_CREATE, &file->handle); + } else if(tolower(openMode[0]) == 'a') { + warning("We do not support 'a' file open mode."); + free(file); + return NULL; } else { error("wrong file mode"); } @@ -183,7 +187,7 @@ int gp_fclose(GPFILE *stream) { /* if (*(uint32 *)((char *)stream - sizeof(uint32)) == 0x4321) { debug(0, "Double closing", __FUNCTION__); return 1; - } // return 1 ?? + } */ if (stream->cachePos) { @@ -214,6 +218,7 @@ int gp_fseek(GPFILE *stream, long offset, int whence) { return GpFileSeek(stream->handle, whence, offset, (long *)&dummy); } +//TODO: read cache size_t gp_fread(void *ptr, size_t size, size_t n, GPFILE *stream) { ulong readcount = 0; ERR_CODE err = GpFileRead(stream->handle, ptr, size * n, &readcount); //fixme? size*n @@ -483,6 +488,94 @@ void gp_delay(uint32 msecs) { while (GpTickCountGet() < startTime + msecs); } +void gp_clockSpeedChange(int freq, int magic, int div) { + #define rTCFG0 (*(volatile unsigned *)0x15100000) + #define rTCFG1 (*(volatile unsigned *)0x15100004) + #define rTCNTB4 (*(volatile unsigned *)0x1510003c) + unsigned int pclk; + unsigned int prescaler0; + + // Change CPU Speed + GpClockSpeedChange(freq, magic, div); + pclk = GpPClkGet(); + + // Repair SDK timer - it forgets to set prescaler + prescaler0 = (pclk / (8000 * 40)) - 1; + rTCFG0 = (rTCFG0 & 0xFFFFFF00) | prescaler0; + rTCFG1 = 0x30033; + + // Repair GpTickCountGet + rTCNTB4 = pclk / 1600; +} + +void gp_setCpuSpeed(int freq) { + // Default value for 40 mhz + static int CLKDIV = 0x48013; + static int MCLK = 40000000; + static int CLKMODE = 0; + static int HCLK = 40000000; + static int PCLK = 40000000; + + switch (freq) { + // overclocked + case 168: { CLKDIV = 0x14000; MCLK = 168000000; CLKMODE = 3; break; } + case 172: { CLKDIV = 0x23010; MCLK = 172000000; CLKMODE = 3; break; } + case 176: { CLKDIV = 0x24010; MCLK = 176000000; CLKMODE = 3; break; } + case 180: { CLKDIV = 0x16000; MCLK = 180000000; CLKMODE = 3; break; } + case 184: { CLKDIV = 0x26010; MCLK = 184000000; CLKMODE = 3; break; } + case 188: { CLKDIV = 0x27010; MCLK = 188000000; CLKMODE = 3; break; } + case 192: { CLKDIV = 0x18000; MCLK = 192000000; CLKMODE = 3; break; } + case 196: { CLKDIV = 0x29010; MCLK = 196000000; CLKMODE = 3; break; } + case 200: { CLKDIV = 0x2A010; MCLK = 200000000; CLKMODE = 3; break; } + case 204: { CLKDIV = 0x2b010; MCLK = 204000000; CLKMODE = 3; break; } + case 208: { CLKDIV = 0x2c010; MCLK = 208000000; CLKMODE = 3; break; } + case 212: { CLKDIV = 0x2d010; MCLK = 212000000; CLKMODE = 3; break; } + case 216: { CLKDIV = 0x2e010; MCLK = 216000000; CLKMODE = 3; break; } + case 220: { CLKDIV = 0x2f010; MCLK = 220000000; CLKMODE = 3; break; } + case 224: { CLKDIV = 0x30010; MCLK = 224000000; CLKMODE = 3; break; } + case 228: { CLKDIV = 0x1e000; MCLK = 228000000; CLKMODE = 3; break; } + case 232: { CLKDIV = 0x32010; MCLK = 232000000; CLKMODE = 3; break; } + case 236: { CLKDIV = 0x33010; MCLK = 236000000; CLKMODE = 3; break; } + case 240: { CLKDIV = 0x20000; MCLK = 240000000; CLKMODE = 3; break; } + case 244: { CLKDIV = 0x35010; MCLK = 244000000; CLKMODE = 3; break; } + case 248: { CLKDIV = 0x36010; MCLK = 248000000; CLKMODE = 3; break; } + case 252: { CLKDIV = 0x22000; MCLK = 252000000; CLKMODE = 3; break; } + case 256: { CLKDIV = 0x38010; MCLK = 256000000; CLKMODE = 3; break; } + + // normal +// case 166: { CLKDIV = 0x4B011; MCLK = 166000000; CLKMODE = 3; break; } + case 166: { CLKDIV = 0x2f001; MCLK = 165000000; CLKMODE = 3; break; } + case 164: { CLKDIV = 0x4a011; MCLK = 164000000; CLKMODE = 3; break; } + case 160: { CLKDIV = 0x48011; MCLK = 160000000; CLKMODE = 3; break; } + case 156: { CLKDIV = 0x2c001; MCLK = 156000000; CLKMODE = 3; break; } + case 144: { CLKDIV = 0x28001; MCLK = 144000000; CLKMODE = 3; break; } + case 133: { CLKDIV = 0x51021; MCLK = 133500000; CLKMODE = 2; break; } + case 132: { CLKDIV = 0x3a011; MCLK = 132000000; CLKMODE = 3; break; } + case 120: { CLKDIV = 0x24001; MCLK = 120000000; CLKMODE = 2; break; } + case 100: { CLKDIV = 0x2b011; MCLK = 102000000; CLKMODE = 2; break; } + case 66: { CLKDIV = 0x25002; MCLK = 67500000; CLKMODE = 2; break; } + case 50: { CLKDIV = 0x2a012; MCLK = 50000000; CLKMODE = 0; break; } +// case 40: { CLKDIV = 0x48013; MCLK = 40000000; CLKMODE = 0; break; } + case 40: { CLKDIV = 0x48013; MCLK = 40000000; CLKMODE = 1; break; } +// case 33: { CLKDIV = 0x25003; MCLK = 33750000; CLKMODE = 0; break; } + case 33: { CLKDIV = 0x25003; MCLK = 33750000; CLKMODE = 2; break; } + case 22: { CLKDIV = 0x33023; MCLK = 22125000; CLKMODE = 0; break; } + default: + error("Invalid CPU frequency!"); + } + if (CLKMODE == 0) { HCLK = MCLK; PCLK = MCLK; } + if (CLKMODE == 1) { HCLK = MCLK; PCLK = MCLK / 2; } + if (CLKMODE == 2) { HCLK = MCLK / 2; PCLK = MCLK / 2; } + if (CLKMODE == 3) { HCLK = MCLK / 2; PCLK = MCLK / 4; } + + gp_clockSpeedChange(MCLK, CLKDIV, CLKMODE); +} + +void gp_Reset() { + gp_setCpuSpeed(66); + asm volatile("swi #4\n"); +} + void gp_exit(int code) { if (!code) { printf(" ----------------------------------------"); @@ -521,7 +614,7 @@ void NP(const char *fmt, ...) { va_end(marker); _dprintf("NP:%s", s); - //gp_delay(50); + gp_delay(50); } void LP(const char *fmt, ...) { @@ -534,7 +627,7 @@ void LP(const char *fmt, ...) { va_end(marker); _dprintf("LP:%s", s); - //gp_delay(300); + gp_delay(300); } void SP(const char *fmt, ...) { @@ -547,7 +640,7 @@ void SP(const char *fmt, ...) { va_end(marker); _dprintf("SP:%s", s); - //gp_delay(50); + gp_delay(50); } void BP(const char *fmt, ...) { @@ -560,5 +653,5 @@ void BP(const char *fmt, ...) { va_end(marker); _dprintf("BP:%s", s); - //gp_delay(2000); + gp_delay(2000); } diff --git a/backends/gp32/gp32std.h b/backends/gp32/gp32std.h index 8be7abf1bb..b3c51ec37d 100644 --- a/backends/gp32/gp32std.h +++ b/backends/gp32/gp32std.h @@ -38,7 +38,7 @@ #define LCD_WIDTH 320 #define LCD_HEIGHT 240 -#define FCACHE_SIZE 8 * 1024 // speed up writes +#define FCACHE_SIZE 8 * 1024 typedef struct { F_HANDLE handle; @@ -79,6 +79,7 @@ extern void * gp_malloc(size_t size); extern void * gp_calloc(size_t nitems, size_t size); extern void gp_free(void *block); +extern void gp_setCpuSpeed(int freq); extern int gp_printf(const char *fmt, ...); extern void gp_delay(unsigned long msecs); extern void gp_exit(int code); diff --git a/backends/gp32/gp32std_grap.cpp b/backends/gp32/gp32std_grap.cpp index 5ccd9b47a6..ded5b34107 100644 --- a/backends/gp32/gp32std_grap.cpp +++ b/backends/gp32/gp32std_grap.cpp @@ -28,7 +28,7 @@ #include "backends/gp32/gp32std.h" #include "backends/gp32/gp32std_grap.h" -#include "backends/gp32/gp32_launcher.h" +#include "backends/gp32/globals.h" GPDRAWSURFACE lcdSurface[2]; @@ -37,6 +37,9 @@ uint8 flipIndex = 1; uint16 *frameBuffer1; uint16 *frameBuffer2; +uint8 gammaLUT[256]; +uint8 gammaLUTInv[256]; + extern const unsigned char fontresEng1[]; extern const unsigned char fontresKor1[]; @@ -87,15 +90,25 @@ void gp_fillRect(uint16 *frameBuffer, int16 x, int16 y, int16 w, int16 h, uint16 } } +void gp_initGammaTable(float value) +{ + for(int i = 0; i < 256; i++) { + if(value == 1.0f) { + gammaLUT[i] = i; + gammaLUTInv[i] = i; + } else { + gammaLUT[i] = (uint8)(pow((double)i / 256, 1 / (double)value) * 256); + gammaLUTInv[i] = (uint8)(pow((double)i / 256, (double)value) * 256); + } + } +} + uint16 gp_RGBTo16(uint16 r, uint16 g, uint16 b) { // GP32 16bit color 5551 - if(g_gammaRamp != 100) { - r *= ((float)g_gammaRamp / 100); - g *= ((float)g_gammaRamp / 100); - b *= ((float)g_gammaRamp / 100); - r = r >= 255 ? 255 : r; - g = g >= 255 ? 255 : g; - b = b >= 255 ? 255 : b; + if(g_vars.gammaRamp != 10000) { + r = gammaLUT[r]; + g = gammaLUT[g]; + b = gammaLUT[b]; } return (((r >> 3) & 0x1F) << 11) | (((g >> 3) & 0x1F) << 6) | ((b >> 3) & 0x1F) << 1; } @@ -105,10 +118,10 @@ void gp_16ToRGB(uint16 color, uint8 *r, uint8 *g, uint8 *b) { *g = ((((color) >> 6) & 0x1F) << 3); //(((color>>5)&0x3F) << 2); *b = ((((color) >> 1) & 0x1F) << 3); //((color&0x1F) << 3); - if(g_gammaRamp != 100) { - *r /= ((float)g_gammaRamp / 100); - *g /= ((float)g_gammaRamp / 100); - *b /= ((float)g_gammaRamp / 100); + if(g_vars.gammaRamp != 10000) { + *r = gammaLUTInv[*r]; + *g = gammaLUTInv[*g]; + *b = gammaLUTInv[*b]; } } diff --git a/backends/gp32/gp32std_grap.h b/backends/gp32/gp32std_grap.h index cf42cebcf3..6f57f70621 100644 --- a/backends/gp32/gp32std_grap.h +++ b/backends/gp32/gp32std_grap.h @@ -37,6 +37,7 @@ extern void gp_16ToRGB(uint16 color, uint8 *r, uint8 *g, uint8 *b); extern void gp_textOut(uint16 *frameBuffer, int x, int y, char* lpszText, uint16 wColor); +extern void gp_initGammaTable(float value); extern void gp_initFrameBuffer(); extern void gp_flipScreen(); |