now using pseudo-PCload()
This commit is contained in:
parent
daed020c59
commit
da195bbba5
1
Makefile
1
Makefile
|
@ -2,6 +2,7 @@ TARGET = ovl-upload
|
||||||
TYPE = ps-exe
|
TYPE = ps-exe
|
||||||
|
|
||||||
SRCS = ovl-upload.c \
|
SRCS = ovl-upload.c \
|
||||||
|
pcdrv.c \
|
||||||
TIM/cubetex.tim \
|
TIM/cubetex.tim \
|
||||||
../common/crt0/crt0.s \
|
../common/crt0/crt0.s \
|
||||||
tritex.c \
|
tritex.c \
|
||||||
|
|
BIN
Overlay.ovl0
BIN
Overlay.ovl0
Binary file not shown.
BIN
Overlay.ovl1
BIN
Overlay.ovl1
Binary file not shown.
33
ovl-upload.c
33
ovl-upload.c
|
@ -31,6 +31,8 @@
|
||||||
#include <libetc.h>
|
#include <libetc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "pcdrv.h"
|
||||||
|
|
||||||
// If USECD is defined, files will be loaded from the CD. Use this method for testing in an emulator.
|
// If USECD is defined, files will be loaded from the CD. Use this method for testing in an emulator.
|
||||||
// Additionaly, generate the bin/cue with mkpsxiso.
|
// Additionaly, generate the bin/cue with mkpsxiso.
|
||||||
|
|
||||||
|
@ -102,14 +104,26 @@ extern u_long __lvl1_end;
|
||||||
|
|
||||||
//~ u_long overlaySize = 0;
|
//~ u_long overlaySize = 0;
|
||||||
|
|
||||||
static char* overlayFile; // Will hold the name of the file to load.
|
char * overlayFile; // Will hold the name of the file to load.
|
||||||
|
|
||||||
u_char overlayFileID, loadFileIDwas, loadFileID = 0; // Will hold an ID that's unique for each file.
|
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, loadFileIDwas;
|
||||||
|
|
||||||
// Timer for the pad
|
// Timer for the pad
|
||||||
|
|
||||||
u_short timer = 0;
|
u_short timer = 0;
|
||||||
|
|
||||||
|
// pcdrv protocol
|
||||||
|
|
||||||
|
u_char escape = 0; // Hypothetical Escape char for unirom
|
||||||
|
|
||||||
|
u_char protocol = 1; // Hypothetical ID number for the pcdrv protocol in unirom
|
||||||
|
|
||||||
|
u_char command = LOAD; // We're loading the data here
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
|
|
||||||
void init(void);
|
void init(void);
|
||||||
|
@ -318,8 +332,10 @@ int main() {
|
||||||
if (PadStatus & PADselect && !timer) {
|
if (PadStatus & PADselect && !timer) {
|
||||||
|
|
||||||
// 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)
|
||||||
|
// 14 bytes
|
||||||
|
|
||||||
printf("load:%p:%08x:%d", &load_all_overlays_here, &loadFileID, overlayFileID);
|
PCload( &load_all_overlays_here, &loadFileID, overlayFileID );
|
||||||
|
|
||||||
#ifdef USECD
|
#ifdef USECD
|
||||||
|
|
||||||
|
@ -359,6 +375,7 @@ int main() {
|
||||||
|
|
||||||
|
|
||||||
// Render the sample vector model
|
// Render the sample vector model
|
||||||
|
|
||||||
t=0;
|
t=0;
|
||||||
|
|
||||||
// modelCube is a TMESH, len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
|
// modelCube is a TMESH, len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
|
||||||
|
@ -415,10 +432,14 @@ int main() {
|
||||||
FntPrint("Hello overlay!\n");
|
FntPrint("Hello overlay!\n");
|
||||||
|
|
||||||
#ifndef USECD
|
#ifndef USECD
|
||||||
|
|
||||||
|
//~ u_int cmdChecksum = 8 + ptrChecksum(&load_all_overlays_here) +
|
||||||
|
//~ 8 + ptrChecksum((u_long *)&loadFileID) +
|
||||||
|
//~ overlayFileID;
|
||||||
|
|
||||||
|
FntPrint("Overlay with id %d loaded at 0x%08x", overlayFileID, &load_all_overlays_here );
|
||||||
|
|
||||||
FntPrint("Overlay with id %d loaded at 0x%08x", overlayFileID, &load_all_overlays_here);
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USECD
|
#ifdef USECD
|
||||||
|
|
||||||
|
|
Binary file not shown.
210
ovl-upload.py
210
ovl-upload.py
|
@ -27,12 +27,20 @@ import calendar
|
||||||
import math
|
import math
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
DEBUG = 0
|
DEBUG = 1
|
||||||
|
|
||||||
SERIAL_DEVICE = '/dev/ttyUSB0'
|
SERIAL_DEVICE = '/dev/ttyUSB0'
|
||||||
|
|
||||||
SERIAL_SPEED = 115200
|
SERIAL_SPEED = 115200
|
||||||
|
|
||||||
|
# pcdrv
|
||||||
|
|
||||||
|
pcdrvEscape = '00'
|
||||||
|
|
||||||
|
pcdrvProtocol = '01'
|
||||||
|
|
||||||
|
pcdrvCommand = '06'
|
||||||
|
|
||||||
# Names of the overlay files to load.
|
# Names of the overlay files to load.
|
||||||
# See l.550
|
# See l.550
|
||||||
|
|
||||||
|
@ -70,7 +78,7 @@ memAddr = ""
|
||||||
|
|
||||||
flagAddr = ""
|
flagAddr = ""
|
||||||
|
|
||||||
loadFile = ""
|
loadFile = -1
|
||||||
|
|
||||||
levelId = ""
|
levelId = ""
|
||||||
|
|
||||||
|
@ -488,47 +496,169 @@ def main(args):
|
||||||
inputBuffer += ser.read().decode('ascii')
|
inputBuffer += ser.read().decode('ascii')
|
||||||
|
|
||||||
if inputBuffer:
|
if inputBuffer:
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
|
|
||||||
print( "Incoming data : " + inputBuffer )
|
|
||||||
|
|
||||||
# parse command CMD:ARG1:ARG2(:ARGn)
|
|
||||||
|
|
||||||
argList = []
|
|
||||||
|
|
||||||
argList = inputBuffer.split(':')
|
|
||||||
|
|
||||||
# Send command
|
# We're expecting the command with format : 00 01 06 08 xx xx xx xx 08 xx xx xx xx 01 xx xx (16 bytes)
|
||||||
|
|
||||||
if argList[0] == "load" and len(argList) == 4:
|
# Rolling buffer
|
||||||
|
|
||||||
|
# ~ byte = ser.read(1)
|
||||||
|
|
||||||
|
# Make sure byte value is < 128 so that it can be decoded to ascii
|
||||||
|
|
||||||
|
# ~ if byte[0] < 128:
|
||||||
|
|
||||||
|
# ~ inputBuffer += byte.decode('ascii')
|
||||||
|
|
||||||
|
# ~ else:
|
||||||
|
|
||||||
if len(argList[1]) < 8 or len(argList[2]) < 8:
|
# ~ inputBuffer += '.'
|
||||||
|
|
||||||
|
if len(inputBuffer) >= 32:
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
|
||||||
|
print( "Incoming data : " + inputBuffer )
|
||||||
|
|
||||||
|
# If inputBuffer is > 32, remove first char
|
||||||
|
|
||||||
|
# ~ if len(inputBuffer) > 32:
|
||||||
|
|
||||||
|
# ~ inputBuffer = inputBuffer[1:]
|
||||||
|
|
||||||
|
# Parse command
|
||||||
|
|
||||||
|
if inputBuffer[:2] == pcdrvEscape:
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
||||||
|
print( "Received Escape : " + inputBuffer[:2] )
|
||||||
|
|
||||||
|
# Escape byte received, remove it from buffer and continue
|
||||||
|
|
||||||
|
inputBuffer = inputBuffer[2:]
|
||||||
|
|
||||||
|
if inputBuffer[:2] == pcdrvProtocol:
|
||||||
|
|
||||||
print("Wrong data format, aborting...")
|
if DEBUG:
|
||||||
|
|
||||||
break
|
print( "Received Proto: " + inputBuffer[:2] )
|
||||||
|
|
||||||
|
# Protocol byte is pcdrv (01), remove it from buffer and continue
|
||||||
|
|
||||||
|
inputBuffer = inputBuffer[2:]
|
||||||
|
|
||||||
|
if inputBuffer[:2] == pcdrvCommand:
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
|
||||||
|
print( "Received Cmd: " + inputBuffer[:2] )
|
||||||
|
|
||||||
|
# Command byte is valid (06), remove it from buffer and continue
|
||||||
|
|
||||||
|
inputBuffer = inputBuffer[2:]
|
||||||
|
|
||||||
|
# Get 2 checksum bytes in buffer
|
||||||
|
|
||||||
|
CmdCheckSum = inputBuffer[-4:]
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
|
||||||
|
print( "Received ChkSm: " + CmdCheckSum )
|
||||||
|
|
||||||
|
# Calculate checksum on the data - 2 checksum bytes
|
||||||
|
|
||||||
|
dataInBuffer = inputBuffer[:-4]
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
|
||||||
|
print( "Data in buffer: " + dataInBuffer )
|
||||||
|
|
||||||
|
# TODO find a way to calc command checksum in ovl-upload.c ( see l.440 )
|
||||||
|
|
||||||
|
# ~ work = dataInBuffer
|
||||||
|
|
||||||
|
# ~ for c in dataInBuffer:
|
||||||
|
|
||||||
|
# ~ dataCheckSum += int(c, 16)
|
||||||
|
|
||||||
|
# ~ if DEBUG:
|
||||||
|
|
||||||
|
# ~ print( "Generated ChkSm: " + str(dataCheckSum) )
|
||||||
|
|
||||||
|
# Not using the checksum for now
|
||||||
|
|
||||||
|
dataCheckSum = 0
|
||||||
|
|
||||||
|
CmdCheckSum = 0
|
||||||
|
|
||||||
|
# Check
|
||||||
|
|
||||||
|
if int(dataCheckSum) == int(CmdCheckSum):
|
||||||
|
|
||||||
|
dataLen = 0
|
||||||
|
|
||||||
|
# Get data length byte
|
||||||
|
|
||||||
|
dataLen = dataInBuffer[:2]
|
||||||
|
|
||||||
|
dataInBuffer = dataInBuffer[2:]
|
||||||
|
|
||||||
|
# Get actual data
|
||||||
|
|
||||||
|
for b in dataInBuffer :
|
||||||
|
|
||||||
|
if len(memAddr) < int(dataLen) :
|
||||||
|
|
||||||
|
memAddr += b
|
||||||
|
|
||||||
|
# Remove data from buffer
|
||||||
|
|
||||||
|
dataInBuffer = dataInBuffer[int(dataLen):]
|
||||||
|
|
||||||
|
if DEBUG > 1:
|
||||||
|
|
||||||
|
print( "Data in buffer 1: " + dataInBuffer )
|
||||||
|
|
||||||
|
dataLen = 0
|
||||||
|
|
||||||
|
dataLen = dataInBuffer[:2]
|
||||||
|
|
||||||
|
dataInBuffer = dataInBuffer[2:]
|
||||||
|
|
||||||
|
# Get actual data
|
||||||
|
|
||||||
|
for b in dataInBuffer :
|
||||||
|
|
||||||
|
if len(flagAddr) < int(dataLen) :
|
||||||
|
|
||||||
|
flagAddr += b
|
||||||
|
|
||||||
|
# Remove data from buffer
|
||||||
|
|
||||||
|
dataInBuffer = dataInBuffer[int(dataLen):]
|
||||||
|
|
||||||
|
if DEBUG > 1:
|
||||||
|
|
||||||
|
print( "Data in buffer 2: " + dataInBuffer )
|
||||||
|
|
||||||
|
# We should only have two bytes remaining
|
||||||
|
|
||||||
|
if len(dataInBuffer) == 2:
|
||||||
|
|
||||||
|
loadFile = int(dataInBuffer)
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
|
||||||
|
print( memAddr + " - " + flagAddr + " - " + str(loadFile) )
|
||||||
|
|
||||||
|
ser.reset_input_buffer()
|
||||||
|
|
||||||
memAddr = argList[1]
|
inputBuffer = ""
|
||||||
|
|
||||||
flagAddr = argList[2]
|
Listen = 0
|
||||||
|
|
||||||
loadFile = argList[3]
|
break
|
||||||
|
|
||||||
ser.reset_input_buffer()
|
|
||||||
|
|
||||||
inputBuffer = ""
|
|
||||||
|
|
||||||
if DEBUG > 1:
|
|
||||||
|
|
||||||
print( memAddr + " - " + flagAddr + " - " + loadFile )
|
|
||||||
|
|
||||||
Listen = 0
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
ser.reset_input_buffer()
|
ser.reset_input_buffer()
|
||||||
|
@ -537,14 +667,14 @@ def main(args):
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if memAddr and loadFile:
|
if memAddr and flagAddr:
|
||||||
|
|
||||||
# Remove separator and ';1' at end of the string
|
# Remove separator and ';1' at end of the string
|
||||||
|
|
||||||
# ~ fileClean = loadFile.split(';')[0][1:]
|
# ~ fileClean = loadFile.split(';')[0][1:]
|
||||||
fileID = loadFile
|
fileID = loadFile
|
||||||
|
|
||||||
print("Received addresses and file ID : " + memAddr + " - " + flagAddr + " - " + fileID)
|
print("Received addresses and file ID : " + memAddr + " - " + flagAddr + " - " + str(fileID))
|
||||||
|
|
||||||
# TODO : replace with a proper level naming scheme
|
# TODO : replace with a proper level naming scheme
|
||||||
# right now, we're receiving currently loaded file
|
# right now, we're receiving currently loaded file
|
||||||
|
@ -552,13 +682,13 @@ def main(args):
|
||||||
|
|
||||||
binFileName = ""
|
binFileName = ""
|
||||||
|
|
||||||
if fileID == "0":
|
if fileID == 0:
|
||||||
|
|
||||||
binFileName = overlayFile1
|
binFileName = overlayFile1
|
||||||
|
|
||||||
levelId = 1
|
levelId = 1
|
||||||
|
|
||||||
if fileID == "1":
|
if fileID == 1:
|
||||||
|
|
||||||
binFileName = overlayFile0
|
binFileName = overlayFile0
|
||||||
|
|
||||||
|
@ -572,7 +702,7 @@ def main(args):
|
||||||
|
|
||||||
"Reset flag at: " + flagAddr + "\n" +
|
"Reset flag at: " + flagAddr + "\n" +
|
||||||
|
|
||||||
"File : " + loadFile + "\n" +
|
"FileID : " + str(loadFile) + "\n" +
|
||||||
|
|
||||||
"Bin : " + binFileName + " - ID : " + str(levelId)
|
"Bin : " + binFileName + " - ID : " + str(levelId)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "pcdrv.h"
|
||||||
|
|
||||||
|
int ptrChecksum( u_long * pointer ){
|
||||||
|
|
||||||
|
u_int checksum = 0;
|
||||||
|
|
||||||
|
u_long work;
|
||||||
|
|
||||||
|
work = ( u_long ) pointer - 0x80000000 ;
|
||||||
|
|
||||||
|
while( work != 0 ){
|
||||||
|
|
||||||
|
checksum += work % 10;
|
||||||
|
|
||||||
|
work /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return checksum;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int waitForSIODone( int * flag ){
|
||||||
|
|
||||||
|
// This should wait for a signal from the SIO to tell when it's done
|
||||||
|
// Returns val < 0 if wrong
|
||||||
|
|
||||||
|
uint timeOut = 1000;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
printf("%02u%02u%02u08%08x08%08x%02u%04u", escape, protocol, LOAD, loadAddress, flagAddress, overlayFileID, cmdChecksum);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,41 @@
|
||||||
|
// https://discord.com/channels/642647820683444236/646765703143227394/837416216640618558
|
||||||
|
|
||||||
|
// So like we'd have, say,
|
||||||
|
|
||||||
|
// 00 01 00 03 58 58 58 01 xx for pcdrv' file open to open the file name "XXX" and attribute 1
|
||||||
|
|
||||||
|
// (escape) (pcdrv command) (pcdrv open) (filename with length as prefix) (attributes) (checksum)
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
//pcdrv commands
|
||||||
|
|
||||||
|
#define OPEN 0
|
||||||
|
#define CLOSE 1
|
||||||
|
#define SEEK 2
|
||||||
|
#define READ 3
|
||||||
|
#define WRITE 4
|
||||||
|
#define CREATE 5
|
||||||
|
#define LOAD 6
|
||||||
|
|
||||||
|
int ptrChecksum( u_long * pointer );
|
||||||
|
|
||||||
|
int waitForSIODone( int * flag );
|
||||||
|
|
||||||
|
void PCload( u_long * loadAddress, volatile u_char * flagAddress, u_char overlayFileID );
|
||||||
|
|
||||||
|
int PCopen(const char * filename, int attributes );
|
||||||
|
|
||||||
|
int PCcreate(const char * filename, int attributes );
|
||||||
|
|
||||||
|
int PCclose( int fd );
|
||||||
|
|
||||||
|
int PCseek( int fd, int offset, int accessMode );
|
||||||
|
|
||||||
|
int PCread( int fd, int len, char * buffer );
|
||||||
|
|
Loading…
Reference in New Issue