Added rolling buffer, now semi reliable

This commit is contained in:
ABelliqueux 2021-05-14 18:13:07 +02:00
parent 179a080b3d
commit 1af3a1bf87
4 changed files with 128 additions and 165 deletions

View File

@ -43,7 +43,7 @@
#ifdef USECD
#include <libcd.h>
#endif
// Sample vector models
@ -110,8 +110,6 @@ char * overlayFile; // Will hold the name of the file to load.
char * ptrToChar[8]; // Will hold the name of the file to load.
volatile u_char loadFileID = 0; // Will hold an ID that's unique for each file.
u_char overlayFileID = 0, loadFileIDwas = 0;
// Timer for the pad
@ -128,9 +126,11 @@ u_char command = LOAD; // We're loading the data here
uint32_t checkSum = 0;
const char * inBuffer = "";
//~ const char OKAY[4] = "OKYA";
volatile u_char inBuffer[4] = " ";
char byte;
//~ char byte;
// Prototypes
@ -176,7 +176,7 @@ void init(){
// Init font system
FntLoad(960, 0);
FntOpen(16, 16, 196, 64, 0, 256);
FntOpen(16, 16, 196, 96, 0, 356);
}
@ -213,28 +213,17 @@ void LoadTexture(u_long * tim, TIM_IMAGE * tparam){ // This part is from Lam
}
//~ static inline uint32_t djbProcess(uint32_t hash, const char str[], unsigned n) {
//~ return n ? djbProcess ( ( ( hash << 5 ) + hash ) ^ str[0], str + 1, n - 1) : hash;
//~ }
//~ static inline uint32_t djbHash( const char* str, unsigned n ){
//~ return djbProcess( 5381, str, n);
//~ }
int main() {
// Update this value to avoid trigger at launch
loadFileIDwas = overlayFileID = loadFileID;
loadFileIDwas = overlayFileID;
if ( loadFileID == 0 ){
if ( overlayFileID == 0 ){
overlayFile = "\\cube.bin;1";
} else if ( loadFileID == 1) {
} else if ( overlayFileID == 1) {
overlayFile = "\\tri.bin;1";
@ -283,30 +272,38 @@ int main() {
LoadTexture(_binary_TIM_cubetex_tim_start, &tim_cube);
//~ static u_char SIOinit = 0;
//~ static u_char SIO = 0;
// Main loop
while (1) {
// Check inBuffer for answer
//~ if( strcmp(inBuffer, OKAY) == 0 ){
//~ loadFileID = !loadFileID;
//~ FntPrint("Change");
//~ for(char c = 0; c < sizeof(inBuffer); c++){ inBuffer[c] = 0; }
//~ }
// Overlay switch
if ( loadFileID != loadFileIDwas ){
if ( overlayFileID != loadFileIDwas ){
// Update previous file value
loadFileIDwas = loadFileID;
loadFileIDwas = overlayFileID;
// Change file to load
switch ( loadFileID ){
switch ( overlayFileID ){
case 0:
overlayFile = "\\cube.bin;1";
overlayFileID = 0;
//~ overlayFileID = 0;
break;
@ -314,7 +311,7 @@ int main() {
overlayFile = "\\tri.bin;1";
overlayFileID = 1;
//~ overlayFileID = 1;
break;
@ -322,7 +319,7 @@ int main() {
overlayFile = "\\cube.bin;1";
overlayFileID = 0;
//~ overlayFileID = 0;
break;
@ -346,87 +343,6 @@ int main() {
}
// SIO FUN : USELESS as it hijacks unirom's SIO implementation... Keeping it for ref
//~ static char * ok = "OKAY";
//~ static char * buffer = " ";
//static u_char clearFlag = 1;
//~ if( SIO ){
//~ // Is SIO is not init, dot it
//~ if( ! SIOinit ){
//~ ResetCallback();
//~ AddSIO(115200);
//~ ResetGraph(0);
//~ SIO_CLEAR;
//~ SIOinit = 1;
//~ }
//if ( clearFlag ){
//SIO_CLEAR;
//clearFlag = 0;
//}
//~ if( strlen(buffer) > 4){
//~ memmove(buffer, buffer + 1, strlen(buffer));
//~ }
//~ // Clears driver status error-related bits
//~ // Check if sio driver is able to write communications data
//~ if( SIO_STATUS & SR_RXRDY ){
//~ // Read byte
//~ char c = SIO_READB;
//~ // Add to buffer
//~ strncat(buffer, &c, 1);
//~ }
//~ // Compare buffer to string
//~ if( strcmp(ok, buffer) == 0) {
//~ loadFileID = !loadFileID;
//~ DelSIO();
//~ SIO = 0;
//~ SIOinit = 0;
//clearFlag = 1;
//~ }
//~ if( buffer ){
//~ FntPrint("%s", buffer);
//~ }
//~ }
// END SIO FUN
// Read pad status
PadStatus = PadRead(0);
@ -438,16 +354,17 @@ int main() {
// We send the memory address where the file should be loaded, the memory address of the loadFileID, so that the screen is updated when it changes, and the file id.
// format : 00(:)01(:)06(:)04 xx xx xx xx(:)04 xx xx xx xx(:)01 (separators are not send)
// 14 bytes
PCload( &load_all_overlays_here, &loadFileID, overlayFileID );
#ifndef USECD
//~ SIO = 1;
PCload( &load_all_overlays_here, inBuffer, &overlayFileID );
#endif
#ifdef USECD
// We can do that because we only have two files
loadFileID = !loadFileID;
overlayFileID = !overlayFileID;
#endif
@ -538,7 +455,10 @@ int main() {
#ifndef USECD
FntPrint("Overlay with id %d loaded at 0x%08x\n%x", overlayFileID, &load_all_overlays_here, &overlayFileID );
FntPrint("Overlay with id %d loaded at 0x%08x\n", overlayFileID, &load_all_overlays_here );
FntPrint("buffer at %08x : %s\n", inBuffer, inBuffer);
#endif

View File

@ -145,7 +145,7 @@ def WaitForResponse( expectedAnswer ):
while True:
if DEBUG > 1:
if DEBUG > 3:
print("Waiting for data in serial input buffer.")
@ -499,7 +499,7 @@ def main(args):
if DEBUG > 1:
print("memAddr : " + str(memAddr) + " - loadFile" + loadFile )
print("memAddr : " + str(memAddr) + " - loadFile" + str(loadFile ))
while True:
@ -751,8 +751,12 @@ def main(args):
time.sleep( sleepTime )
SendBin( levelId.to_bytes(1, byteorder='little', signed=False) , flagAddr)
# ~ SendBin( levelId.to_bytes(1, byteorder='little', signed=False) , flagAddr)
time.sleep( sleepTime )
SendBin( b'OKYA' , flagAddr)
# Reset everything
resetListener()

111
pcdrv.c
View File

@ -1,11 +1,10 @@
#include "pcdrv.h"
static char sio_read(){
char c;
char c;
c = getchar();
c = getchar();
return c;
};
@ -85,59 +84,93 @@ void sendRU32(uint32_t data) {
};
//~ int waitForSIODone(){
u_short waitForSIODone( volatile u_char * bufferAddress){
// This should wait for a signal from the SIO to tell when it's done
// Returns val < 0 if wrong
//~ const char * inBuffer = "";
// Returns 1 if ok, 0 else
//~ uint16_t timeOut = 1000;
const char * OKYA = "OKYA";
//~ char result = 0;
u_char SIOdone = 0;
//~ while(1){
//~ char byte = getchar();
//~ inBuffer += byte;
//~ if(inBuffer == "DONE"){
//~ FntPrint("inBuffer : %s", inBuffer);
//~ break;
//~ }
//~ }
int i = 0;
//~ return 1;
while(1){
const u_char * buffer = ( const u_char * )bufferAddress;
// Rolling buffer
//~ };
if( strlen( buffer ) > 4){
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID ) {
memmove( ( u_char * ) buffer, buffer + 1, strlen(buffer));
}
// Check inBuffer for answer
if( strcmp(buffer, OKYA) == 0 ){
FntPrint("WORX!\n\n");
SIOdone = 1;
break;
}
i++;
// Avoid infinite loop
if ( i > 10000 ){
break;
}
}
return SIOdone;
};
u_short PCload( u_long * loadAddress, volatile u_char * bufferAddress, u_char * overlayFileID ) {
// Send filename , load address, and flag address
// E.G : 00 01 06 04 8001000 04 80010001 01 + 0000000000 <- cmd checksum
char commandBuffer[28];
char commandBuffer[28];
sprintf(commandBuffer, "%02u%02u%02u08%08x08%08x%02u", ESCAPE, PROTOCOL, LOAD, loadAddress, flagAddress, overlayFileID);
sprintf(commandBuffer, "%02u%02u%02u08%08x08%08x%02u", ESCAPE, PROTOCOL, LOAD, loadAddress, bufferAddress, *overlayFileID);
u_int cmdChecksum = djbHash(commandBuffer, 28);
printf("%s%10u", commandBuffer, cmdChecksum);
// Need delay ?
for(u_int wait = 0; wait < 100; wait++){
wait = wait;
}
if( waitForSIODone(bufferAddress) ) {
*overlayFileID = !*overlayFileID;
};
u_int cmdChecksum = djbHash(commandBuffer, 28);
printf("%s%10u", commandBuffer, cmdChecksum);
//~ waitForSIODone();
};
int PCopen( const char * filename, int mode ){
int PCopen( const char * filename, u_char mode ){
// Open filename in mode
// Returns file descriptor or -1 if fail
// E.G : 00 01 00 04 48454C4F 00 + 0000000000 <- cmd checksum
u_int bufferLen = 10 + strLen( filename );
char commandBuffer[ bufferLen ];
@ -178,14 +211,20 @@ void BuildCmd(){
while( i < sizeof( commandBuffer) - checkSumLen ){
if( i == 0 ){
commandBuffer[0] = escape;
commandBuffer[1] = protocol;
i = 2;
}
if( i == 2 ){
commandBuffer[i] = LOAD;
i ++;
}
commandBuffer[i] = sizeof(&loadAddress);

20
pcdrv.h
View File

@ -29,12 +29,7 @@
#include <stdint.h>
#include <stdio.h>
#include <libsio.h>
#define SIO_CLEAR _sio_control(2,1,0)
#define SIO_STATUS _sio_control(0,0,0)
#define SIO_CONTROL _sio_control(0,1,0)
#define SIO_READB _sio_control(0,4,0)
#include <string.h>
#define ESCAPE 00 // Hypothetical Escape char for unirom
@ -50,8 +45,16 @@
#define CREATE 05
#define LOAD 06
// flags parameters
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
static char sio_read();
u_short waitForSIODone( volatile u_char * bufferAddress);
static inline uint32_t djbHash( const char* str, unsigned n );
static inline uint32_t djbProcess(uint32_t hash, const char str[], unsigned n);
@ -64,9 +67,7 @@ void sendU32(uint32_t data);
void sendRU32(uint32_t data);
int waitForSIODone();
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID );
u_short PCload( u_long * loadAddress, volatile u_char * bufferAddress, u_char * overlayFileID );
int PCopen( const char * filename, int mode );
@ -77,4 +78,3 @@ int PCclose( int fd );
int PCseek( int fd, int offset, int accessMode );
int PCread( int fd, int len, char * buffer );