diff --git a/src/dbvz.c b/src/dbvz.c index 86de58c..a80828e 100644 --- a/src/dbvz.c +++ b/src/dbvz.c @@ -35,22 +35,6 @@ static uint8_t spi1RxWritePosition; static bool spi1RxOverflowed; static uint8_t spi1TxReadPosition; static uint8_t spi1TxWritePosition; -static uint16_t uart1RxFifo[13]; -static uint16_t uart1TxFifo[9]; -static uint8_t uart1RxReadPosition; -static uint8_t uart1RxWritePosition; -static bool uart1RxOverflowed;//this var may not be needed -static uint8_t uart1TxReadPosition; -static uint8_t uart1TxWritePosition; -/* -static uint16_t uart2RxFifo[65]; -static uint16_t uart2TxFifo[65]; -static uint8_t uart2RxReadPosition; -static uint8_t uart2RxWritePosition; -static bool uart2RxOverflowed;//this var may not be needed -static uint8_t uart2TxReadPosition; -static uint8_t uart2TxWritePosition; -*/ static int32_t pwm1ClocksToNextSample; static uint8_t pwm1Fifo[6]; static uint8_t pwm1ReadPosition; @@ -569,7 +553,7 @@ void dbvzSetRegister8(uint32_t address, uint8_t value){ //this is a 16 bit register but Palm OS writes to the 8 bit FIFO section alone //send byte and update interrupts if enabled if((registerArrayRead16(USTCNT1) & 0xA000) == 0xA000){ - uart1RxFifoWrite(value); + uart1TxFifoWrite(value); updateUart1Interrupt(); } return; @@ -989,7 +973,7 @@ void dbvzSetRegister16(uint32_t address, uint16_t value){ //send byte and update interrupts if enabled if((registerArrayRead16(USTCNT1) & 0xA000) == 0xA000){ - uart1RxFifoWrite(value & 0x1000 ? value & 0xFF : EMU_SERIAL_BREAK); + uart1TxFifoWrite(value & 0x1000 ? value & 0xFF : EMU_SERIAL_BREAK); updateUart1Interrupt(); } return; @@ -1104,13 +1088,6 @@ void dbvzReset(void){ spi1RxOverflowed = false; spi1TxReadPosition = 0; spi1TxWritePosition = 0; - memset(uart1RxFifo, 0x00, sizeof(uart1RxFifo)); - memset(uart1TxFifo, 0x00, sizeof(uart1TxFifo)); - uart1RxReadPosition = 0; - uart1RxWritePosition = 0; - uart1RxOverflowed = false; - uart1TxReadPosition = 0; - uart1TxWritePosition = 0; pwm1ClocksToNextSample = 0; memset(pwm1Fifo, 0x00, sizeof(pwm1Fifo)); pwm1ReadPosition = 0; @@ -1377,26 +1354,6 @@ void dbvzSaveState(uint8_t* data){ writeStateValue8(data + offset, spi1TxWritePosition); offset += sizeof(uint8_t); - //UART1 - for(index = 0; index < 13; index++){ - writeStateValue16(data + offset, uart1RxFifo[index]); - offset += sizeof(uint16_t); - } - for(index = 0; index < 9; index++){ - writeStateValue16(data + offset, uart1TxFifo[index]); - offset += sizeof(uint16_t); - } - writeStateValue8(data + offset, uart1RxReadPosition); - offset += sizeof(uint8_t); - writeStateValue8(data + offset, uart1RxWritePosition); - offset += sizeof(uint8_t); - writeStateValue8(data + offset, uart1RxOverflowed); - offset += sizeof(uint8_t); - writeStateValue8(data + offset, uart1TxReadPosition); - offset += sizeof(uint8_t); - writeStateValue8(data + offset, uart1TxWritePosition); - offset += sizeof(uint8_t); - //PWM1, audio writeStateValue32(data + offset, pwm1ClocksToNextSample); offset += sizeof(int32_t); @@ -1493,26 +1450,6 @@ void dbvzLoadState(uint8_t* data){ spi1TxWritePosition = readStateValue8(data + offset); offset += sizeof(uint8_t); - //UART1 - for(index = 0; index < 13; index++){ - uart1RxFifo[index] = readStateValue16(data + offset); - offset += sizeof(uint16_t); - } - for(index = 0; index < 9; index++){ - uart1TxFifo[index] = readStateValue16(data + offset); - offset += sizeof(uint16_t); - } - uart1RxReadPosition = readStateValue8(data + offset); - offset += sizeof(uint8_t); - uart1RxWritePosition = readStateValue8(data + offset); - offset += sizeof(uint8_t); - uart1RxOverflowed = readStateValue8(data + offset); - offset += sizeof(uint8_t); - uart1TxReadPosition = readStateValue8(data + offset); - offset += sizeof(uint8_t); - uart1TxWritePosition = readStateValue8(data + offset); - offset += sizeof(uint8_t); - //PWM1, audio pwm1ClocksToNextSample = readStateValue32(data + offset); offset += sizeof(int32_t); diff --git a/src/dbvzRegisterAccessors.c.h b/src/dbvzRegisterAccessors.c.h index 96eaa59..0cf42db 100644 --- a/src/dbvzRegisterAccessors.c.h +++ b/src/dbvzRegisterAccessors.c.h @@ -91,59 +91,71 @@ static void spi1TxFifoFlush(void){ //UART1 FIFO accessors static uint8_t uart1RxFifoEntrys(void){ - //check for wraparound - if(uart1RxWritePosition < uart1RxReadPosition) - return uart1RxWritePosition + 13 - uart1RxReadPosition; - return uart1RxWritePosition - uart1RxReadPosition; + if(palmIrDataSize){ + uint32_t fifoEntrys = palmIrDataSize(); + + return FAST_MIN(fifoEntrys, 12); + } + return 0x00; } static uint16_t uart1RxFifoRead(void){ - if(uart1RxFifoEntrys() > 0) - uart1RxReadPosition = (uart1RxReadPosition + 1) % 13; - uart1RxOverflowed = false; - return uart1RxFifo[uart1RxReadPosition]; -} - -static void uart1RxFifoWrite(uint16_t value){ - if(uart1RxFifoEntrys() < 12){ - uart1RxWritePosition = (uart1RxWritePosition + 1) % 13; - } - else{ - uart1RxOverflowed = true; - debugLog("UART1 RX FIFO overflowed\n"); - } - uart1RxFifo[uart1RxWritePosition] = value; + if(palmIrDataReceive) + return palmIrDataReceive(); + return 0x0000; } static void uart1RxFifoFlush(void){ - uart1RxReadPosition = uart1RxWritePosition; + if(palmIrDataFlush) + palmIrDataFlush(); } static uint8_t uart1TxFifoEntrys(void){ - //check for wraparound - if(uart1TxWritePosition < uart1TxReadPosition) - return uart1TxWritePosition + 9 - uart1TxReadPosition; - return uart1TxWritePosition - uart1TxReadPosition; -} - -static uint16_t uart1TxFifoRead(void){ - //dont need a safety check here, the emulator will always check that data is present before trying to access it - uart1TxReadPosition = (uart1TxReadPosition + 1) % 9; - return uart1TxFifo[uart1TxReadPosition]; + return 0;//all entrys are transmitted instantly so none are left inside the CPU } static void uart1TxFifoWrite(uint16_t value){ - if(uart1TxFifoEntrys() < 8){ - uart1TxWritePosition = (uart1TxWritePosition + 1) % 9; - uart1TxFifo[uart1TxWritePosition] = value; - } + if(palmIrDataSend) + palmIrDataSend(value); } static void uart1TxFifoFlush(void){ - uart1TxReadPosition = uart1TxWritePosition; + //do nothing, its always empty } -//TODO, UART2 FIFO accessors +//UART2 FIFO accessors +static uint8_t uart2RxFifoEntrys(void){ + if(palmSerialDataSize){ + uint32_t fifoEntrys = palmSerialDataSize(); + + return FAST_MIN(fifoEntrys, 64); + } + return 0x00; +} + +static uint16_t uart2RxFifoRead(void){ + if(palmSerialDataReceive) + return palmSerialDataReceive(); + return 0x0000; +} + +static void uart2RxFifoFlush(void){ + if(palmSerialDataFlush) + palmSerialDataFlush(); +} + +static uint8_t uart2TxFifoEntrys(void){ + return 0;//all entrys are transmitted instantly so none are left inside the CPU +} + +static void uart2TxFifoWrite(uint16_t value){ + if(palmSerialDataSend) + palmSerialDataSend(value); +} + +static void uart2TxFifoFlush(void){ + //do nothing, its always empty +} //PWM1 FIFO accessors static uint8_t pwm1FifoEntrys(void){ diff --git a/src/dbvzTiming.c.h b/src/dbvzTiming.c.h index 6c9e096..f9682d9 100644 --- a/src/dbvzTiming.c.h +++ b/src/dbvzTiming.c.h @@ -300,7 +300,6 @@ static void rtcAddSecondClk32(void){ } } } - } else{ //standard frame based time increment diff --git a/src/emulator.c b/src/emulator.c index 50d7fcf..ca8be5e 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -60,6 +60,14 @@ int16_t* palmAudio; blip_t* palmAudioResampler; double palmCycleCounter;//can be greater then 0 if too many cycles where run double palmClockMultiplier;//used by the emulator to overclock the emulated Palm +uint32_t (*palmIrDataSize)(void);//returns the current number of bytes in the hosts IR receive FIFO +uint16_t (*palmIrDataReceive)(void);//called by the emulator to read the hosts IR receive FIFO +void (*palmIrDataSend)(uint16_t data);//called by the emulator to send IR data +void (*palmIrDataFlush)(void);//called by the emulator to delete all data in the hosts IR receive FIFO +uint32_t (*palmSerialDataSize)(void);//returns the current number of bytes in the hosts serial receive FIFO +uint16_t (*palmSerialDataReceive)(void);//called by the emulator to read the hosts serial receive FIFO +void (*palmSerialDataSend)(uint16_t data);//called by the emulator to send serial data +void (*palmSerialDataFlush)(void);//called by the emulator to delete all data in the hosts serial receive FIFO void (*palmGetRtcFromHost)(uint8_t* writeBack);//[0] = hours, [1] = minutes, [2] = seconds @@ -78,6 +86,14 @@ uint32_t emulatorInit(uint8_t* palmRomData, uint32_t palmRomSize, uint8_t* palmB if(!palmRomData || palmRomSize < 0x8) return EMU_ERROR_INVALID_PARAMETER; + palmIrDataSize = NULL; + palmIrDataReceive = NULL; + palmIrDataSend = NULL; + palmIrDataFlush = NULL; + palmSerialDataSize = NULL; + palmSerialDataReceive = NULL; + palmSerialDataSend = NULL; + palmSerialDataFlush = NULL; palmGetRtcFromHost = NULL; #if defined(EMU_SUPPORT_PALM_OS5) diff --git a/src/emulator.h b/src/emulator.h index a6e89fd..d9a9e21 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -182,6 +182,14 @@ extern int16_t* palmAudio;//read allowed, 2 channel signed 16 bit audio extern blip_t* palmAudioResampler;//dont touch extern double palmCycleCounter;//dont touch extern double palmClockMultiplier;//read/write allowed, setting by multiplication and cacheing the result is the best way +extern uint32_t (*palmIrDataSize)(void);//returns the current number of bytes in the hosts IR receive FIFO +extern uint16_t (*palmIrDataReceive)(void);//called by the emulator to read the hosts IR receive FIFO +extern void (*palmIrDataSend)(uint16_t data);//called by the emulator to send IR data +extern void (*palmIrDataFlush)(void);//called by the emulator to delete all data in the hosts IR receive FIFO +extern uint32_t (*palmSerialDataSize)(void);//returns the current number of bytes in the hosts serial receive FIFO +extern uint16_t (*palmSerialDataReceive)(void);//called by the emulator to read the hosts serial receive FIFO +extern void (*palmSerialDataSend)(uint16_t data);//called by the emulator to send serial data +extern void (*palmSerialDataFlush)(void);//called by the emulator to delete all data in the hosts serial receive FIFO extern void (*palmGetRtcFromHost)(uint8_t* writeBack);//[0] = hours, [1] = minutes, [2] = seconds //functions