mirror of
https://github.com/libretro/Mu.git
synced 2026-09-23 15:15:43 +00:00
Start adding IR communication functions, may not compile
This commit is contained in:
@@ -10,44 +10,111 @@
|
||||
/*this is mainly because running any sort of test takes 3 minutes to compile it, get it on a memory card, load it then find out it doesnt work*/
|
||||
|
||||
|
||||
static bool irdaRunning;
|
||||
static bool irdaError;
|
||||
static bool irdaOutOfSync;
|
||||
static uint16_t irdaPortId;
|
||||
static uint32_t irdaCommandBufferLength;
|
||||
static irda_command_t irdaCommandIn;
|
||||
static irda_command_t irdaCommandOut;
|
||||
static uint8_t irdaCommandInOffset;
|
||||
static uint8_t irdaCommandInBytes[IRDA_COMMAND_SIZE];
|
||||
static uint8_t irdaCommandOutBytes[IRDA_COMMAND_SIZE];
|
||||
|
||||
|
||||
static void irdaSendCommand(irda_command_t command){
|
||||
|
||||
static void irdaSendCommand(uint64_t command){
|
||||
if(irdaRunning){
|
||||
uint32_t bytes;
|
||||
Err error;
|
||||
|
||||
bytes = SrmSend(irdaPortId, &irdaCommandOut, IRDA_COMMAND_SIZE/*bytes*/, &error);
|
||||
if(error != errNone)
|
||||
irdaError = true;
|
||||
if(bytes != IRDA_COMMAND_SIZE)
|
||||
irdaOutOfSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
static irda_command_t irdaGetCommand(){
|
||||
|
||||
static uint64_t irdaGetCommand(){
|
||||
if(irdaRunning){
|
||||
uint32_t requestBytes;
|
||||
uint32_t bytes;
|
||||
Err error;
|
||||
|
||||
error = SrmReceiveCheck(irdaPortId, &requestBytes);
|
||||
if(error != errNone)
|
||||
irdaError = true;
|
||||
|
||||
requestBytes = min(requestBytes, IRDA_COMMAND_SIZE - irdaCommandInOffset + 1);
|
||||
|
||||
bytes = SrmReceive(irdaPortId, ((uint8_t*)&irdaCommandInBytes)[irdaCommandInOffset], requestBytes, 0, &error);
|
||||
if(error != errNone)
|
||||
irdaError = true;
|
||||
irdaCommandInOffset += bytes;
|
||||
|
||||
if(irdaCommandInOffset >= IRDA_COMMAND_SIZE){
|
||||
irdaCommandInOffset = 0;
|
||||
return IRDA_GET_COMMAND(irdaCommandInBytes);
|
||||
}
|
||||
|
||||
return (uint64_t)IRDA_COMMAND_NONE << 32 | 0x00000000;
|
||||
}
|
||||
}
|
||||
|
||||
static void irdaHandleCommands(){
|
||||
|
||||
if(irdaRunning){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void irdaReset(){
|
||||
irdaCommandBufferLength = 0;
|
||||
irdaCommandIn.command = 0x00000000;
|
||||
irdaCommandIn.data = 0x00000000;
|
||||
irdaCommandOut.command = 0x00000000;
|
||||
irdaCommandOut.data = 0x00000000;
|
||||
static bool irdaStart(){
|
||||
if(!irdaRunning){
|
||||
uint32_t value;
|
||||
Err error;
|
||||
|
||||
error = FtrGet(sysFileCSerialMgr, sysFtrNewSerialPresent, &value);
|
||||
if(error != errNone)
|
||||
return false;
|
||||
|
||||
error = SrmOpen(serPortIrPort, 9600, &irdaPortId);
|
||||
if(error != errNone)
|
||||
return false;
|
||||
|
||||
irdaRunning = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;/*its already running, return success*/
|
||||
}
|
||||
|
||||
static void irdaClose(){
|
||||
if(irdaRunning){
|
||||
SrmSendWait(irdaPortId);
|
||||
SrmClose(irdaPortId);
|
||||
}
|
||||
}
|
||||
|
||||
var irdaCommandLoop(){
|
||||
static Boolean firstRun = true;
|
||||
|
||||
if(firstRun){
|
||||
Boolean success;
|
||||
firstRun = false;
|
||||
debugSafeScreenClear(C_WHITE);
|
||||
StrPrintF(sharedDataBuffer, "IRDA remote control\n mode running...");
|
||||
UG_PutString(0, 0, sharedDataBuffer);
|
||||
irdaReset();
|
||||
success = irdaStart();
|
||||
if(success){
|
||||
debugSafeScreenClear(C_WHITE);
|
||||
StrPrintF(sharedDataBuffer, "IRDA remote control\n mode running...");
|
||||
UG_PutString(0, 0, sharedDataBuffer);
|
||||
}
|
||||
else{
|
||||
debugSafeScreenClear(C_WHITE);
|
||||
StrPrintF(sharedDataBuffer, "IRDA startup failed!");
|
||||
UG_PutString(0, 0, sharedDataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if(getButtonPressed(buttonBack)){
|
||||
firstRun = true;
|
||||
irdaClose();
|
||||
exitSubprogram();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,8 +155,8 @@ void subprogramSetData(var data){
|
||||
}
|
||||
|
||||
static Boolean testerInit(){
|
||||
long osVer;
|
||||
Err error;
|
||||
int32_t osVer;
|
||||
Err error;
|
||||
|
||||
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &osVer);
|
||||
if (osVer < PalmOS35) {
|
||||
@@ -171,7 +171,7 @@ static Boolean testerInit(){
|
||||
}
|
||||
|
||||
offscreenBitmap = BmpCreate(SCREEN_WIDTH, SCREEN_HEIGHT, 1, NULL, &error);
|
||||
if(error){
|
||||
if(error != errNone){
|
||||
FrmCustomAlert(alt_err, "Cant create bitmap", 0, 0);
|
||||
return false;
|
||||
}
|
||||
@@ -209,6 +209,8 @@ static void testerExit(){
|
||||
}
|
||||
|
||||
static void testerFrameLoop(){
|
||||
static uint32_t lastResetTime = 0;
|
||||
|
||||
palmButtons = KeyCurrentState();
|
||||
|
||||
if(!unsafeMode){
|
||||
@@ -225,6 +227,12 @@ static void testerFrameLoop(){
|
||||
while(event.eType != nilEvent);
|
||||
}
|
||||
|
||||
/*disable auto off timer*/
|
||||
if(TimGetSeconds() - lastResetTime > 50){
|
||||
EvtResetAutoOffTimer();
|
||||
lastResetTime = TimGetSeconds();
|
||||
}
|
||||
|
||||
lastSubprogramReturnValue = currentSubprogram();
|
||||
|
||||
WinDrawBitmap(offscreenBitmap, 0, 0);
|
||||
@@ -238,7 +246,7 @@ DWord PilotMain(Word cmd, Ptr cmdBPB, Word launchFlags){
|
||||
initSuccess = testerInit();
|
||||
|
||||
if(!initSuccess){
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
applicationRunning = true;
|
||||
@@ -252,6 +260,7 @@ DWord PilotMain(Word cmd, Ptr cmdBPB, Word launchFlags){
|
||||
else if(cmd == sysAppLaunchCmdSystemReset){
|
||||
/*eventualy boot time tests may go here*/
|
||||
}
|
||||
return(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,10 @@ var makeVar(uint8_t length, uint8_t type, uint64_t value);
|
||||
#define writeArbitraryMemory16(address, value) *((volatile uint16_t*)(address)) = (value)
|
||||
#define writeArbitraryMemory32(address, value) *((volatile uint32_t*)(address)) = (value)
|
||||
|
||||
/*convenience*/
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
/*graphics*/
|
||||
void forceFrameRedraw();
|
||||
|
||||
|
||||
@@ -7,25 +7,25 @@
|
||||
|
||||
|
||||
Err makeFile(uint8_t* data, uint32_t size, char* fileName){
|
||||
FileHand file;
|
||||
Err error;
|
||||
uint32_t count;
|
||||
FileHand file;
|
||||
Err error;
|
||||
uint32_t count;
|
||||
|
||||
file = FileOpen(0 /*cardNo*/, fileName, (uint32_t)'DATA', (uint32_t)'GuiC', fileModeReadWrite, &error);
|
||||
if(file == fileNullHandle || error)
|
||||
if(file == fileNullHandle || error != errNone)
|
||||
return error;
|
||||
|
||||
/*the copy is used to anonymize the data source*/
|
||||
count = size;
|
||||
while(count != 0){
|
||||
uint32_t chunkSize = count > SHARED_DATA_BUFFER_SIZE ? SHARED_DATA_BUFFER_SIZE : count;
|
||||
int32_t bytesWritten;
|
||||
uint32_t chunkSize = min(count, SHARED_DATA_BUFFER_SIZE);
|
||||
int32_t bytesWritten;
|
||||
uint32_t i;
|
||||
for(i = 0; i < chunkSize; i++){
|
||||
sharedDataBuffer[i] = data[i + size - count];
|
||||
}
|
||||
bytesWritten = FileWrite(file, sharedDataBuffer, 1, chunkSize, &error);
|
||||
if(bytesWritten != chunkSize || error){
|
||||
if(bytesWritten != chunkSize || error != errNone){
|
||||
FileClose(file);
|
||||
return error;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ uint16_t ads7846GetValue(uint8_t channel, Boolean referenceMode, Boolean mode8bi
|
||||
}
|
||||
|
||||
var hexRamBrowser(){
|
||||
static Boolean firstRun = true;
|
||||
static Boolean firstRun = true;
|
||||
static uint32_t nibble;
|
||||
static uint32_t pointerValue;
|
||||
|
||||
@@ -191,11 +191,11 @@ var getTrapAddress(){
|
||||
}
|
||||
|
||||
var manualLssa(){
|
||||
static Boolean firstRun = true;
|
||||
static Boolean firstRun = true;
|
||||
static uint32_t nibble;
|
||||
static uint32_t hexValue;
|
||||
static uint32_t originalLssa;
|
||||
static Boolean customEnabled;
|
||||
static Boolean customEnabled;
|
||||
|
||||
if(firstRun){
|
||||
nibble = 0x10000000;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.6.1, 2018-05-13T08:39:40. -->
|
||||
<!-- Written by QtCreator 4.6.1, 2018-05-13T12:06:55. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*commands are 64 bits, 32 command/32 data, the data is usualy a pointer*/
|
||||
/*commands are 64 bit big endian, 32 command/32 data, the data is usualy a pointer*/
|
||||
/*all access require 2 transfers, a request and an acknowledge, each device must take turns sending and receiving*/
|
||||
|
||||
typedef struct{
|
||||
uint32_t command;
|
||||
uint32_t data;
|
||||
}irda_command_t;
|
||||
#define IRDA_COMMAND_SIZE 8
|
||||
|
||||
/*the uint64_t casts are required since int is 16 bit on m68k and bit shifting is always performed at int length unless specified otherwise*/
|
||||
#define IRDA_GET_COMMAND(ptr) ((uint64_t)ptr[0] << 56 | (uint64_t)ptr[1] << 48 | (uint64_t)ptr[2] << 40 | (uint64_t)ptr[3] << 32 | (uint64_t)ptr[4] << 24 | (uint64_t)ptr[5] << 16 | (uint64_t)ptr[6] << 8 | (uint64_t)ptr[7])
|
||||
|
||||
enum{
|
||||
IRDA_COMMAND_NONE = 0,
|
||||
|
||||
Reference in New Issue
Block a user