ovl-upload/pcdrv.c

59 lines
1.5 KiB
C
Raw Normal View History

2021-04-30 16:42:24 +02:00
#include "pcdrv.h"
2021-05-01 14:51:25 +02:00
// Hashing algorythm from @nicolasnoble : https://github.com/grumpycoders/pcsx-redux/blob/main/src/mips/common/util/djbhash.h
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);
};
2021-04-30 16:42:24 +02:00
int waitForSIODone( int * flag ){
// This should wait for a signal from the SIO to tell when it's done
// Returns val < 0 if wrong
2021-05-01 14:51:25 +02:00
uint16_t timeOut = 1000;
2021-04-30 16:42:24 +02:00
char result = 0;
for ( uint t = 0; t < timeOut; t ++){
if ( * flag == 1 ){
result = * flag;
break;
}
}
return result;
};
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID ) {
// Send filename , load address, and flag address
u_char escape = 0; // Hypothetical Escape char for unirom
u_char protocol = 1; // Hypothetical protocol indicator for unirom
2021-05-01 14:51:25 +02:00
//~ u_char cmdChecksum = 0; // Not using that yet, ideally, should allow to check that the received command on the pc is the same as the one sent by the psx
char commandBuffer[28];
2021-04-30 16:42:24 +02:00
2021-05-01 14:51:25 +02:00
sprintf(commandBuffer, "%02u%02u%02u08%08x08%08x%02u", escape, protocol, LOAD, loadAddress, flagAddress, overlayFileID);
u_int cmdChecksum = djbHash(commandBuffer, 28);
printf("%s%10u", commandBuffer, cmdChecksum);
2021-04-30 16:42:24 +02:00
};