mirror of
https://github.com/libretro/Mu.git
synced 2026-09-22 14:45:57 +00:00
Add backlight for m500, clean up m515 backlight
Also backup gradiant code.
This commit is contained in:
85
src/dbvz.c
85
src/dbvz.c
@@ -9,6 +9,7 @@
|
||||
#include "flx68000.h"
|
||||
#include "ads7846.h"
|
||||
#include "sdCard.h"
|
||||
#include "sed1376.h"
|
||||
#include "audio/blip_buf.h"
|
||||
#include "m68k/m68k.h"
|
||||
|
||||
@@ -57,8 +58,32 @@ static int32_t audioGetFramePercentage(void);
|
||||
#include "dbvzRegisterAccessors.c.h"
|
||||
#include "dbvzTiming.c.h"
|
||||
|
||||
uint16_t rgb16From24(uint8_t r, uint8_t g, uint8_t b){
|
||||
uint16_t color = r >> 3 << 11 & 0xF800;
|
||||
color |= g >> 2 << 5 & 0x07E0;
|
||||
color |= b >> 3 & 0x001F;
|
||||
return color;
|
||||
}
|
||||
|
||||
void rgb24From16(uint16_t color, uint8_t* r, uint8_t* g, uint8_t* b){
|
||||
*r = (color >> 11 & 0x1F) << 3;
|
||||
*g = (color >> 5 & 0x3F) << 2;
|
||||
*b = (color & 0x1F) << 3;
|
||||
}
|
||||
|
||||
uint16_t gradiantPoint(uint16_t start, uint16_t end, uint16_t range, uint16_t positon){
|
||||
uint8_t rgbStart[3];
|
||||
uint8_t rgbEnd[3];
|
||||
float percent = positon / (float)range;
|
||||
|
||||
rgb24From16(start, &rgbStart[0], &rgbStart[1], &rgbStart[2]);
|
||||
rgb24From16(end, &rgbEnd[0], &rgbEnd[1], &rgbEnd[2]);
|
||||
|
||||
return rgb16From24(rgbStart[0] * (1.0 - percent) + rgbEnd[0] * percent, rgbStart[1] * (1.0 - percent) + rgbEnd[1] * percent, rgbStart[2] * (1.0 - percent) + rgbEnd[2] * percent);
|
||||
}
|
||||
|
||||
void dbvzLcdRender(void){
|
||||
static const uint16_t masterColorLut[16] = {0xFFFF, 0xEEEE, 0xDDDD, 0xCCCC, 0xBBBB, 0xAAAA, 0x9999, 0x8888, 0x7777, 0x6666, 0x5555, 0x4444, 0x3333, 0x2222, 0x1111, 0x0000};//TODO: get a real LUT
|
||||
static /*const*/ uint16_t masterColorLut[16] = {0x746D, 0x6C0C, 0x63CB, 0x5B8A, 0x534A, 0x4AE9, 0x42A8, 0x3A67, 0x3A27, 0x31C6, 0x2985, 0x2144, 0x1904, 0x10A3, 0x0862, 0x0000};
|
||||
static const uint8_t bppLut[4] = {1, 2, 4, 0};
|
||||
uint16_t colorLut2Bpp[4];//stores indexes to masterColorLut
|
||||
uint32_t startAddress = registerArrayRead32(LSSA);
|
||||
@@ -71,6 +96,44 @@ void dbvzLcdRender(void){
|
||||
uint16_t y;
|
||||
uint16_t x;
|
||||
|
||||
/*
|
||||
Color out:0x746D(printed 1 times)
|
||||
Color out:0x6C0C(printed 1 times)
|
||||
Color out:0x63CB(printed 1 times)
|
||||
Color out:0x5B8A(printed 1 times)
|
||||
Color out:0x534A(printed 1 times)
|
||||
Color out:0x4AE9(printed 1 times)
|
||||
Color out:0x42A8(printed 1 times)
|
||||
Color out:0x3A67(printed 1 times)
|
||||
Color out:0x3A27(printed 1 times)
|
||||
Color out:0x31C6(printed 1 times)
|
||||
Color out:0x2985(printed 1 times)
|
||||
Color out:0x2144(printed 1 times)
|
||||
Color out:0x1904(printed 1 times)
|
||||
Color out:0x10A3(printed 1 times)
|
||||
Color out:0x0862(printed 1 times)
|
||||
Color out:0x0021(printed 1 times)
|
||||
*/
|
||||
/*
|
||||
//debugLog("Color out:0x%04X\n", gradiantPoint(0x2222, 0xFFFF, 100, 40));
|
||||
//0x2222 <-> 0x0000
|
||||
for(x = 0; x < 16; x++){
|
||||
uint8_t rgb[3];
|
||||
//masterColorLut[x] = gradiantPoint(gradiantPoint(0x2222, 0xFFFF, 100, 30), 0x0000, 15, x);//good!
|
||||
//masterColorLut[x] = gradiantPoint(0x746D, 0x0000, 15, x);
|
||||
rgb24From16(0x746D, &rgb[0], &rgb[1], &rgb[2]);
|
||||
masterColorLut[x] = rgb16From24(rgb[0] - (rgb[0] / 15) * x, rgb[1] - (rgb[1] / 15) * x, rgb[2] - (rgb[2] / 15) * x);
|
||||
debugLog("Color out:0x%04X\n", masterColorLut[x]);
|
||||
}
|
||||
|
||||
for(y = 0; y < 160; y++){
|
||||
for(x = 0; x < 160; x++){
|
||||
dbvzFramebuffer[y * dbvzFramebufferWidth + x] = masterColorLut[y / 10];
|
||||
}
|
||||
}
|
||||
return;
|
||||
//*/
|
||||
|
||||
//dont render if LCD controller is disabled
|
||||
if(!(registerArrayRead8(LCKCON) & 0x80)){
|
||||
memset(dbvzFramebuffer, 0x00, dbvzFramebufferWidth * dbvzFramebufferHeight * sizeof(uint16_t));
|
||||
@@ -135,16 +198,6 @@ void dbvzLcdRender(void){
|
||||
}
|
||||
}
|
||||
|
||||
bool dbvzLcdEnabled(void){
|
||||
//if LSSA is set to something other than the Palm OS constant render from it instead of the SED1376
|
||||
//the enable bit is perpously ignored because it is managed by the OS and apps may not set it
|
||||
//return palmAllowInvalidBehavior && registerArrayRead32(LSSA) != 0xBADC0DE0;
|
||||
//return palmAllowInvalidBehavior && registerArrayRead8(LCKCON) & 0x80;
|
||||
//return false;
|
||||
//return true;
|
||||
return registerArrayRead8(LCKCON) & 0x80;
|
||||
}
|
||||
|
||||
bool dbvzIsPllOn(void){
|
||||
return !(dbvzSysclksPerClk32 < 1.0);
|
||||
}
|
||||
@@ -771,6 +824,8 @@ void dbvzSetRegister8(uint32_t address, uint8_t value){
|
||||
//write without the top 2 bits
|
||||
registerArrayWrite8(address, value & 0x3F);
|
||||
updateAds7846ChipSelectStatus();
|
||||
if(palmEmulatingM500)
|
||||
palmMisc.backlightLevel = !!(getPortGValue() & 0x02) * 100;
|
||||
return;
|
||||
|
||||
case PJSEL:
|
||||
@@ -786,7 +841,8 @@ void dbvzSetRegister8(uint32_t address, uint8_t value){
|
||||
registerArrayWrite8(address, value);
|
||||
checkPortDInterrupts();
|
||||
updateVibratorStatus();
|
||||
updateBacklightAmplifierStatus();
|
||||
if(!palmEmulatingM500)
|
||||
sed1376UpdateLcdStatus();
|
||||
return;
|
||||
|
||||
case PMSEL:
|
||||
@@ -1410,7 +1466,8 @@ void dbvzReset(void){
|
||||
updateVibratorStatus();
|
||||
updateAds7846ChipSelectStatus();
|
||||
updateSdCardChipSelectStatus();
|
||||
updateBacklightAmplifierStatus();
|
||||
if(!palmEmulatingM500)
|
||||
sed1376UpdateLcdStatus();
|
||||
|
||||
dbvzSysclksPerClk32 = sysclksPerClk32();
|
||||
|
||||
@@ -1462,8 +1519,6 @@ uint32_t dbvzStateSize(void){
|
||||
size += sizeof(uint8_t) * 6;//pwm1Fifo[6]
|
||||
size += sizeof(uint8_t) * 2;//pwm1(Read/Write)
|
||||
|
||||
//debugLog("size is:%d\n", size);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ extern uint16_t dbvzFramebufferHeight;
|
||||
|
||||
//CPU
|
||||
void dbvzLcdRender(void);
|
||||
bool dbvzLcdEnabled(void);
|
||||
bool dbvzIsPllOn(void);
|
||||
bool m515BacklightAmplifierState(void);
|
||||
bool dbvzAreRegistersXXFFMapped(void);
|
||||
|
||||
@@ -989,10 +989,6 @@ static void updateSdCardChipSelectStatus(void){
|
||||
sdCardSetChipSelect(!!(getPortJValue() & 0x08));
|
||||
}
|
||||
|
||||
static void updateBacklightAmplifierStatus(void){
|
||||
palmMisc.backlightLevel = (palmMisc.backlightLevel > 0) ? (50 + m515BacklightAmplifierState() * 50) : 0;
|
||||
}
|
||||
|
||||
static void updateTouchState(void){
|
||||
if(!(registerArrayRead8(PFSEL) & registerArrayRead8(PFDIR) & 0x02)){
|
||||
if((ads7846PenIrqEnabled ? !palmInput.touchscreenTouched : true) == !!(registerArrayRead16(ICR) & 0x0080))
|
||||
|
||||
@@ -772,7 +772,11 @@ void emulatorRunFrame(void){
|
||||
if(palmEmulatingM500){
|
||||
dbvzLcdRender();
|
||||
|
||||
//TODO: backlight level
|
||||
if(palmMisc.backlightLevel == 100){
|
||||
MULTITHREAD_LOOP(index) for(index = 0; index < 160 * 160; index++){
|
||||
palmFramebuffer[index] = palmFramebuffer[index] & 0xF81F | palmFramebuffer[index] + 0x02E0 & 0x07E0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
sed1376Render();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "emulator.h"
|
||||
#include "portability.h"
|
||||
#include "dbvz.h"
|
||||
#include "sed1376.h"
|
||||
#include "flx68000.h"//for flx68000GetPc()
|
||||
|
||||
|
||||
@@ -283,7 +284,7 @@ void sed1376SetRegister(uint8_t address, uint8_t value){
|
||||
case GPIO_CONF_0:
|
||||
case GPIO_CONT_0:
|
||||
sed1376Registers[address] = value & 0x7F;
|
||||
updateLcdStatus();
|
||||
sed1376UpdateLcdStatus();
|
||||
return;
|
||||
|
||||
case GPIO_CONF_1:
|
||||
@@ -420,3 +421,8 @@ void sed1376Render(void){
|
||||
debugLog("Cant draw screen, LCD on:%s, PLL on:%s, power save on:%s, forced blank on:%s\n", palmMisc.lcdOn ? "true" : "false", dbvzIsPllOn() ? "true" : "false", sed1376PowerSaveEnabled() ? "true" : "false", !!(sed1376Registers[DISP_MODE] & 0x80) ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
void sed1376UpdateLcdStatus(void){
|
||||
palmMisc.lcdOn = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x20);
|
||||
palmMisc.backlightLevel = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x10) ? (50 + m515BacklightAmplifierState() * 50) : 0;
|
||||
}
|
||||
|
||||
@@ -19,5 +19,6 @@ uint8_t sed1376GetRegister(uint8_t address);
|
||||
void sed1376SetRegister(uint8_t address, uint8_t value);
|
||||
|
||||
void sed1376Render(void);
|
||||
void sed1376UpdateLcdStatus(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -121,9 +121,3 @@ static void selectRenderer(bool color, uint8_t bpp){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updaters
|
||||
static void updateLcdStatus(void){
|
||||
palmMisc.lcdOn = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x20);
|
||||
palmMisc.backlightLevel = !!(sed1376Registers[GPIO_CONT_0] & sed1376Registers[GPIO_CONF_0] & 0x10) ? (50 + m515BacklightAmplifierState() * 50) : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user