Make the SED1376 save its own state, ADS7846 is next

This commit is contained in:
meepingsnesroms
2018-08-14 01:25:22 -07:00
parent 2e9578656f
commit b536d4be5c
4 changed files with 97 additions and 77 deletions

View File

@@ -142,15 +142,12 @@ uint64_t emulatorGetStateSize(){
size += sizeof(uint32_t);//save state version
size += sizeof(uint32_t);//palmSpecialFeatures
size += m68328StateSize();//the current CPU state
size += sizeof(uint8_t);//lowPowerStopActive
if(palmSpecialFeatures & FEATURE_RAM_HUGE)
size += SUPERMASSIVE_RAM_SIZE;//system RAM buffer
else
size += RAM_SIZE;//system RAM buffer
size += REG_SIZE;//hardware registers
size += SED1376_FB_SIZE;//SED1376
size += SED1376_LUT_SIZE * 3;//SED1376 r, g and b luts
size += SED1376_REG_SIZE;//SED1376
size += sed1376StateSize();
size += TOTAL_MEMORY_BANKS;//bank handlers
size += sizeof(uint32_t) * 4 * CHIP_END;//chip select states
size += sizeof(uint8_t) * 5 * CHIP_END;//chip select states
@@ -225,16 +222,8 @@ bool emulatorSaveState(buffer_t buffer){
}
//SED1376
memcpy(buffer.data + offset, sed1376Registers, SED1376_REG_SIZE);
offset += SED1376_REG_SIZE;
memcpy(buffer.data + offset, sed1376RLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(buffer.data + offset, sed1376GLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(buffer.data + offset, sed1376BLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(buffer.data + offset, sed1376Framebuffer, SED1376_FB_SIZE);
offset += SED1376_FB_SIZE;
sed1376SaveState(buffer.data + offset);
offset += sed1376StateSize();
//timing
writeStateValueDouble(buffer.data + offset, palmCrystalCycles);
@@ -357,17 +346,8 @@ bool emulatorLoadState(buffer_t buffer){
}
//SED1376
memcpy(sed1376Registers, buffer.data + offset, SED1376_REG_SIZE);
offset += SED1376_REG_SIZE;
memcpy(sed1376RLut, buffer.data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376GLut, buffer.data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376BLut, buffer.data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376Framebuffer, buffer.data + offset, SED1376_FB_SIZE);
offset += SED1376_FB_SIZE;
sed1376RefreshLut();
sed1376LoadState(buffer.data + offset);
offset += sed1376StateSize();
//timing
palmCrystalCycles = readStateValueDouble(buffer.data + offset);

View File

@@ -101,23 +101,26 @@ void m68k_op_cpu32_dispatch(void){
void m68328Init(){
m68k_init();
m68k_set_cpu_type(M68K_CPU_TYPE_68000);
static bool inited = false;
CPU_ADDRESS_MASK = 0xFFFFFFFF;
if(!inited){
m68k_init();
m68k_set_cpu_type(M68K_CPU_TYPE_68000);
patchOpcode(OPCODE_BGND, m68k_op_bgnd, 16/*dont know how many cycles, average opcode*/);
CPU_ADDRESS_MASK = 0xFFFFFFFF;
for(uint16_t currentOpcode = OPCODE_CPU32_START; currentOpcode <= OPCODE_CPU32_END; currentOpcode++)
patchOpcode(currentOpcode, m68k_op_cpu32_dispatch, 91/*dont know how many cycles, most expensive opcode*/);
patchOpcode(OPCODE_BGND, m68k_op_bgnd, 16/*dont know how many cycles, average opcode*/);
//68328 may actually use some 68020 opcodes, those will be patched in if and when Palm OS attempts to call one
for(uint16_t currentOpcode = OPCODE_CPU32_START; currentOpcode <= OPCODE_CPU32_END; currentOpcode++)
patchOpcode(currentOpcode, m68k_op_cpu32_dispatch, 91/*dont know how many cycles, most expensive opcode*/);
m68k_set_reset_instr_callback(emulatorReset);
m68k_set_int_ack_callback(interruptAcknowledge);
//resetHwRegisters();
//resetAddressSpace();//address space must be reset after hardware registers because it is dependent on them
//lowPowerStopActive = false;
//68328 may actually use some 68020 opcodes, those will be patched in if and when Palm OS attempts to call one
m68k_set_reset_instr_callback(emulatorReset);
m68k_set_int_ack_callback(interruptAcknowledge);
inited = true;
}
}
void m68328Reset(){

View File

@@ -24,17 +24,17 @@
//The LCD power-off sequence is activated by programming the Power Save Mode Enable bit (REG[A0h] bit 0) to 1.
uint8_t sed1376Registers[SED1376_REG_SIZE];
uint8_t sed1376RLut[SED1376_LUT_SIZE];
uint8_t sed1376GLut[SED1376_LUT_SIZE];
uint8_t sed1376BLut[SED1376_LUT_SIZE];
uint8_t sed1376Framebuffer[SED1376_FB_SIZE];
static uint8_t sed1376Registers[SED1376_REG_SIZE];
static uint8_t sed1376RLut[SED1376_LUT_SIZE];
static uint8_t sed1376GLut[SED1376_LUT_SIZE];
static uint8_t sed1376BLut[SED1376_LUT_SIZE];
static uint16_t sed1376OutputLut[SED1376_LUT_SIZE];//used to speed up pixel conversion
static uint32_t screenStartAddress;
static uint16_t lineSize;
static uint16_t (*renderPixel)(uint16_t x, uint16_t y);
uint8_t sed1376Framebuffer[SED1376_FB_SIZE];
#include "sed1376Accessors.c.h"
@@ -102,6 +102,70 @@ static inline uint32_t getPipStartAddress(){
return pipStartAddress;
}
void sed1376Reset(){
memset(sed1376Registers, 0x00, SED1376_REG_SIZE);
memset(sed1376OutputLut, 0x00, SED1376_LUT_SIZE * sizeof(uint16_t));
memset(sed1376RLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376GLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376BLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376Framebuffer, 0x00, SED1376_FB_SIZE);
palmMisc.backlightLevel = 0;
palmMisc.lcdOn = false;
renderPixel = NULL;
sed1376Registers[REV_CODE] = 0x28;
sed1376Registers[DISP_BUFF_SIZE] = 0x14;
//timing hack
sed1376Registers[PWR_SAVE_CFG] = 0x80;
}
uint64_t sed1376StateSize(){
uint64_t size = 0;
size += SED1376_REG_SIZE;
size += SED1376_LUT_SIZE * 3;
size += SED1376_FB_SIZE;
return size;
}
void sed1376SaveState(uint8_t* data){
uint64_t offset = 0;
memcpy(data + offset, sed1376Registers, SED1376_REG_SIZE);
offset += SED1376_REG_SIZE;
memcpy(data + offset, sed1376RLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(data + offset, sed1376GLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(data + offset, sed1376BLut, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(data + offset, sed1376Framebuffer, SED1376_FB_SIZE);
offset += SED1376_FB_SIZE;
}
void sed1376LoadState(uint8_t* data){
uint64_t offset = 0;
memcpy(sed1376Registers, data + offset, SED1376_REG_SIZE);
offset += SED1376_REG_SIZE;
memcpy(sed1376RLut, data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376GLut, data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376BLut, data + offset, SED1376_LUT_SIZE);
offset += SED1376_LUT_SIZE;
memcpy(sed1376Framebuffer, data + offset, SED1376_FB_SIZE);
offset += SED1376_FB_SIZE;
//refresh LUT
MULTITHREAD_LOOP for(uint16_t count = 0; count < SED1376_LUT_SIZE; count++)
sed1376OutputLut[count] = makeRgb16FromSed666(sed1376RLut[count], sed1376GLut[count], sed1376BLut[count]);
}
bool sed1376PowerSaveEnabled(){
return sed1376Registers[PWR_SAVE_CFG] & 0x01;
}
@@ -250,31 +314,6 @@ void sed1376SetRegister(uint8_t address, uint8_t value){
}
}
void sed1376Reset(){
memset(sed1376Registers, 0x00, SED1376_REG_SIZE);
memset(sed1376OutputLut, 0x00, SED1376_LUT_SIZE * sizeof(uint16_t));
memset(sed1376RLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376GLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376BLut, 0x00, SED1376_LUT_SIZE);
memset(sed1376Framebuffer, 0x00, SED1376_FB_SIZE);
palmMisc.backlightLevel = 0;
palmMisc.lcdOn = false;
renderPixel = NULL;
sed1376Registers[REV_CODE] = 0x28;
sed1376Registers[DISP_BUFF_SIZE] = 0x14;
//timing hack
sed1376Registers[PWR_SAVE_CFG] = 0x80;
}
void sed1376RefreshLut(){
MULTITHREAD_LOOP for(uint16_t count = 0; count < SED1376_LUT_SIZE; count++)
sed1376OutputLut[count] = makeRgb16FromSed666(sed1376RLut[count], sed1376GLut[count], sed1376BLut[count]);
}
void sed1376Render(){
if(palmMisc.lcdOn && pllIsOn() && !sed1376PowerSaveEnabled() && !(sed1376Registers[DISP_MODE] & 0x80)){
//only render if LCD on, PLL on, power save off, and force blank off, SED1376 clock is provided by the CPU, if its off so is the SED

View File

@@ -1,19 +1,17 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
extern uint8_t sed1376Registers[];
extern uint8_t sed1376RLut[];
extern uint8_t sed1376GLut[];
extern uint8_t sed1376BLut[];
extern uint8_t sed1376Framebuffer[];
extern uint8_t sed1376Framebuffer[];
void sed1376Reset();
uint64_t sed1376StateSize();
void sed1376SaveState();
void sed1376LoadState();
bool sed1376PowerSaveEnabled();
uint8_t sed1376GetRegister(uint8_t address);
void sed1376SetRegister(uint8_t address, uint8_t value);
void sed1376Reset();
void sed1376RefreshLut();
void sed1376Render();