Added rolling buffer, now semi reliable
This commit is contained in:
parent
179a080b3d
commit
1af3a1bf87
148
ovl-upload.c
148
ovl-upload.c
@ -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.
|
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;
|
u_char overlayFileID = 0, loadFileIDwas = 0;
|
||||||
|
|
||||||
// Timer for the pad
|
// Timer for the pad
|
||||||
@ -128,9 +126,11 @@ u_char command = LOAD; // We're loading the data here
|
|||||||
|
|
||||||
uint32_t checkSum = 0;
|
uint32_t checkSum = 0;
|
||||||
|
|
||||||
const char * inBuffer = "";
|
//~ const char OKAY[4] = "OKYA";
|
||||||
|
|
||||||
char byte;
|
volatile u_char inBuffer[4] = " ";
|
||||||
|
|
||||||
|
//~ char byte;
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ void init(){
|
|||||||
|
|
||||||
// Init font system
|
// Init font system
|
||||||
FntLoad(960, 0);
|
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() {
|
int main() {
|
||||||
|
|
||||||
// Update this value to avoid trigger at launch
|
// Update this value to avoid trigger at launch
|
||||||
|
|
||||||
loadFileIDwas = overlayFileID = loadFileID;
|
loadFileIDwas = overlayFileID;
|
||||||
|
|
||||||
if ( loadFileID == 0 ){
|
if ( overlayFileID == 0 ){
|
||||||
|
|
||||||
overlayFile = "\\cube.bin;1";
|
overlayFile = "\\cube.bin;1";
|
||||||
|
|
||||||
} else if ( loadFileID == 1) {
|
} else if ( overlayFileID == 1) {
|
||||||
|
|
||||||
overlayFile = "\\tri.bin;1";
|
overlayFile = "\\tri.bin;1";
|
||||||
|
|
||||||
@ -283,30 +272,38 @@ int main() {
|
|||||||
|
|
||||||
LoadTexture(_binary_TIM_cubetex_tim_start, &tim_cube);
|
LoadTexture(_binary_TIM_cubetex_tim_start, &tim_cube);
|
||||||
|
|
||||||
//~ static u_char SIOinit = 0;
|
|
||||||
|
|
||||||
//~ static u_char SIO = 0;
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (1) {
|
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
|
// Overlay switch
|
||||||
|
|
||||||
if ( loadFileID != loadFileIDwas ){
|
if ( overlayFileID != loadFileIDwas ){
|
||||||
|
|
||||||
// Update previous file value
|
// Update previous file value
|
||||||
|
|
||||||
loadFileIDwas = loadFileID;
|
loadFileIDwas = overlayFileID;
|
||||||
|
|
||||||
// Change file to load
|
// Change file to load
|
||||||
|
|
||||||
switch ( loadFileID ){
|
switch ( overlayFileID ){
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
overlayFile = "\\cube.bin;1";
|
overlayFile = "\\cube.bin;1";
|
||||||
|
|
||||||
overlayFileID = 0;
|
//~ overlayFileID = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -314,7 +311,7 @@ int main() {
|
|||||||
|
|
||||||
overlayFile = "\\tri.bin;1";
|
overlayFile = "\\tri.bin;1";
|
||||||
|
|
||||||
overlayFileID = 1;
|
//~ overlayFileID = 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -322,7 +319,7 @@ int main() {
|
|||||||
|
|
||||||
overlayFile = "\\cube.bin;1";
|
overlayFile = "\\cube.bin;1";
|
||||||
|
|
||||||
overlayFileID = 0;
|
//~ overlayFileID = 0;
|
||||||
|
|
||||||
break;
|
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
|
// Read pad status
|
||||||
|
|
||||||
PadStatus = PadRead(0);
|
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.
|
// 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)
|
// format : 00(:)01(:)06(:)04 xx xx xx xx(:)04 xx xx xx xx(:)01 (separators are not send)
|
||||||
// 14 bytes
|
// 14 bytes
|
||||||
|
#ifndef USECD
|
||||||
|
|
||||||
PCload( &load_all_overlays_here, &loadFileID, overlayFileID );
|
PCload( &load_all_overlays_here, inBuffer, &overlayFileID );
|
||||||
|
|
||||||
//~ SIO = 1;
|
#endif
|
||||||
|
|
||||||
#ifdef USECD
|
#ifdef USECD
|
||||||
|
|
||||||
// We can do that because we only have two files
|
// We can do that because we only have two files
|
||||||
|
|
||||||
loadFileID = !loadFileID;
|
overlayFileID = !overlayFileID;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -538,7 +455,10 @@ int main() {
|
|||||||
|
|
||||||
#ifndef USECD
|
#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
|
#endif
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ def WaitForResponse( expectedAnswer ):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if DEBUG > 1:
|
if DEBUG > 3:
|
||||||
|
|
||||||
print("Waiting for data in serial input buffer.")
|
print("Waiting for data in serial input buffer.")
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ def main(args):
|
|||||||
|
|
||||||
if DEBUG > 1:
|
if DEBUG > 1:
|
||||||
|
|
||||||
print("memAddr : " + str(memAddr) + " - loadFile" + loadFile )
|
print("memAddr : " + str(memAddr) + " - loadFile" + str(loadFile ))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
@ -751,7 +751,11 @@ def main(args):
|
|||||||
|
|
||||||
time.sleep( sleepTime )
|
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
|
# Reset everything
|
||||||
|
|
||||||
|
89
pcdrv.c
89
pcdrv.c
@ -1,11 +1,10 @@
|
|||||||
#include "pcdrv.h"
|
#include "pcdrv.h"
|
||||||
|
|
||||||
|
|
||||||
static char sio_read(){
|
static char sio_read(){
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
c = getchar();
|
c = getchar();
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
};
|
};
|
||||||
@ -85,58 +84,92 @@ 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
|
// This should wait for a signal from the SIO to tell when it's done
|
||||||
// Returns val < 0 if wrong
|
// Returns 1 if ok, 0 else
|
||||||
//~ const char * inBuffer = "";
|
|
||||||
|
|
||||||
//~ uint16_t timeOut = 1000;
|
const char * OKYA = "OKYA";
|
||||||
|
|
||||||
//~ char result = 0;
|
u_char SIOdone = 0;
|
||||||
|
|
||||||
//~ while(1){
|
int i = 0;
|
||||||
|
|
||||||
//~ char byte = getchar();
|
while(1){
|
||||||
|
|
||||||
//~ inBuffer += byte;
|
const u_char * buffer = ( const u_char * )bufferAddress;
|
||||||
|
|
||||||
//~ if(inBuffer == "DONE"){
|
// Rolling buffer
|
||||||
|
|
||||||
//~ FntPrint("inBuffer : %s", inBuffer);
|
if( strlen( buffer ) > 4){
|
||||||
|
|
||||||
//~ break;
|
memmove( ( u_char * ) buffer, buffer + 1, strlen(buffer));
|
||||||
|
|
||||||
//~ }
|
}
|
||||||
|
|
||||||
//~ }
|
// Check inBuffer for answer
|
||||||
|
|
||||||
//~ return 1;
|
if( strcmp(buffer, OKYA) == 0 ){
|
||||||
|
|
||||||
//~ };
|
FntPrint("WORX!\n\n");
|
||||||
|
|
||||||
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID ) {
|
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
|
// Send filename , load address, and flag address
|
||||||
// E.G : 00 01 06 04 8001000 04 80010001 01 + 0000000000 <- cmd checksum
|
// 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);
|
u_int cmdChecksum = djbHash(commandBuffer, 28);
|
||||||
|
|
||||||
printf("%s%10u", commandBuffer, cmdChecksum);
|
printf("%s%10u", commandBuffer, cmdChecksum);
|
||||||
|
|
||||||
//~ waitForSIODone();
|
// Need delay ?
|
||||||
|
|
||||||
|
for(u_int wait = 0; wait < 100; wait++){
|
||||||
|
|
||||||
|
wait = wait;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if( waitForSIODone(bufferAddress) ) {
|
||||||
|
|
||||||
|
*overlayFileID = !*overlayFileID;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int PCopen( const char * filename, int mode ){
|
int PCopen( const char * filename, u_char mode ){
|
||||||
|
|
||||||
// Open filename in mode
|
// Open filename in mode
|
||||||
// Returns file descriptor or -1 if fail
|
// Returns file descriptor or -1 if fail
|
||||||
|
// E.G : 00 01 00 04 48454C4F 00 + 0000000000 <- cmd checksum
|
||||||
|
|
||||||
u_int bufferLen = 10 + strLen( filename );
|
u_int bufferLen = 10 + strLen( filename );
|
||||||
|
|
||||||
@ -178,14 +211,20 @@ void BuildCmd(){
|
|||||||
while( i < sizeof( commandBuffer) - checkSumLen ){
|
while( i < sizeof( commandBuffer) - checkSumLen ){
|
||||||
|
|
||||||
if( i == 0 ){
|
if( i == 0 ){
|
||||||
|
|
||||||
commandBuffer[0] = escape;
|
commandBuffer[0] = escape;
|
||||||
|
|
||||||
commandBuffer[1] = protocol;
|
commandBuffer[1] = protocol;
|
||||||
|
|
||||||
i = 2;
|
i = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i == 2 ){
|
if( i == 2 ){
|
||||||
|
|
||||||
commandBuffer[i] = LOAD;
|
commandBuffer[i] = LOAD;
|
||||||
|
|
||||||
i ++;
|
i ++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commandBuffer[i] = sizeof(&loadAddress);
|
commandBuffer[i] = sizeof(&loadAddress);
|
||||||
|
20
pcdrv.h
20
pcdrv.h
@ -29,12 +29,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <libsio.h>
|
#include <libsio.h>
|
||||||
|
#include <string.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)
|
|
||||||
|
|
||||||
|
|
||||||
#define ESCAPE 00 // Hypothetical Escape char for unirom
|
#define ESCAPE 00 // Hypothetical Escape char for unirom
|
||||||
|
|
||||||
@ -50,8 +45,16 @@
|
|||||||
#define CREATE 05
|
#define CREATE 05
|
||||||
#define LOAD 06
|
#define LOAD 06
|
||||||
|
|
||||||
|
// flags parameters
|
||||||
|
|
||||||
|
#define O_RDONLY 0
|
||||||
|
#define O_WRONLY 1
|
||||||
|
#define O_RDWR 2
|
||||||
|
|
||||||
static char sio_read();
|
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 djbHash( const char* str, unsigned n );
|
||||||
|
|
||||||
static inline uint32_t djbProcess(uint32_t hash, 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);
|
void sendRU32(uint32_t data);
|
||||||
|
|
||||||
int waitForSIODone();
|
u_short PCload( u_long * loadAddress, volatile u_char * bufferAddress, u_char * overlayFileID );
|
||||||
|
|
||||||
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID );
|
|
||||||
|
|
||||||
int PCopen( const char * filename, int mode );
|
int PCopen( const char * filename, int mode );
|
||||||
|
|
||||||
@ -77,4 +78,3 @@ int PCclose( int fd );
|
|||||||
int PCseek( int fd, int offset, int accessMode );
|
int PCseek( int fd, int offset, int accessMode );
|
||||||
|
|
||||||
int PCread( int fd, int len, char * buffer );
|
int PCread( int fd, int len, char * buffer );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user