trying some things with sio

This commit is contained in:
ABelliqueux 2021-04-28 20:32:46 +02:00
parent a3bd1fbf59
commit ac99c29e82
5 changed files with 216 additions and 123 deletions

View File

@ -31,7 +31,7 @@ import calendar
import math
import signal
DEBUG = 0
DEBUG = 1
# Working directory
@ -54,6 +54,8 @@ flagAddr = ""
loadFile = ""
levelId = ""
# One byte
uno = int(1).to_bytes(1, byteorder='little', signed=False)
@ -441,13 +443,9 @@ def resetListener():
def main(args):
# ~ signal.signal(signal.SIGINT, sig_interrupt_handler)
# ~ global Run, memAddr
while True:
global checkSum, data, Listen, Transfer, dataSize, memAddr, loadFile, flagAddr
global checkSum, data, Listen, Transfer, dataSize, memAddr, loadFile, flagAddr, levelId
# Flush serial buffers to avoid residual data
@ -461,7 +459,6 @@ def main(args):
if Listen:
print("Listening for incoming data...")
if DEBUG > 1:
@ -482,19 +479,29 @@ def main(args):
print( "Incoming data : " + inputBuffer )
# parse command ADDRESS:FILENAME
# parse command CMD:ARG1:ARG2(:ARGn)
parsedBuffer = inputBuffer.split(':')
argList = []
if inputBuffer.startswith(str(800)):
argList = inputBuffer.split(':')
if len( parsedBuffer ) > 2:
# Send command
memAddr = str(parsedBuffer[0])
if argList[0] == "load" and len(argList) == 4:
flagAddr = str(parsedBuffer[1])
if len(argList[1]) < 8 or len(argList[2]) < 8:
loadFile = str(parsedBuffer[2])
if DEBUG:
print("Wrong data format, aborting...")
break
memAddr = argList[1]
flagAddr = argList[2]
loadFile = argList[3]
ser.reset_input_buffer()
@ -508,6 +515,14 @@ def main(args):
break
else:
ser.reset_input_buffer()
inputBuffer = ""
break
if memAddr and loadFile:
# Remove separator and ';1' at end of the string
@ -526,10 +541,14 @@ def main(args):
binFileName = "Overlay.lvl1"
levelId = 1
if fileClean == "level1.bin":
binFileName = "Overlay.lvl0"
levelId = 0
if DEBUG:
print(
@ -540,7 +559,7 @@ def main(args):
"File : " + loadFile + "\n" +
"Bin : " + binFileName
"Bin : " + binFileName + "ID : " + str(levelId)
)
@ -578,7 +597,7 @@ def main(args):
# Set level changed flag
SendBin( uno , flagAddr)
SendBin( levelId.to_bytes(1, byteorder='little', signed=False) , flagAddr)
# Reset everything

49
main.c
View File

@ -29,6 +29,7 @@
#include "physics.h"
#include "graphics.h"
#include "space.h"
#include "pcdrv.h"
//~ #define USECD
@ -74,9 +75,13 @@ u_long overlaySize = 0;
#include "levels/level1.h"
uint8_t level = 1;
// Level
uint16_t levelHasChanged = 0;
u_short level = 1;
u_short levelWas = 0;
u_short levelHasChanged = 0;
static char* overlayFile;
@ -198,6 +203,8 @@ LEVEL curLvl = {
&meshPlan
};
LEVEL * loadLvl;
// Pad
void callback();
@ -210,12 +217,15 @@ int main() {
overlaySize = __lvl0_end;
loadLvl = &level0;
} else if ( level == 1) {
overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end;
loadLvl = &level1;
}
// Load overlay
@ -241,6 +251,8 @@ int main() {
}
levelWas = level;
// Overlay
VECTOR sp = {CENTERX,CENTERY,0};
@ -345,7 +357,7 @@ int main() {
while ( VSync(1) ) {
if (levelHasChanged){
if ( levelWas != level ){
switch ( level ){
@ -355,6 +367,8 @@ int main() {
overlaySize = __lvl0_end;
loadLvl = &level0;
break;
case 1:
@ -363,12 +377,16 @@ int main() {
overlaySize = __lvl1_end;
loadLvl = &level1;
break;
default:
overlayFile = "\\level0.bin;1";
loadLvl = &level0;
break;
}
@ -379,15 +397,13 @@ int main() {
#endif
SwitchLevel( overlayFile, &load_all_overlays_here, &curLvl, &level0);
//~ printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile);
levelHasChanged = 0;
SwitchLevel( overlayFile, &load_all_overlays_here, &curLvl, loadLvl);
//~ levelHasChanged = 0;
levelWas = level;
}
FntPrint("Ovl:%s\nLvlch : %x\nLvl: %x %d", overlayFile, levelHasChanged, &levelHasChanged, level );
FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
//~ FntPrint("%x\n", curLvl.actorPtr->tim);
@ -1372,18 +1388,25 @@ void callback() {
if ( PADL & PadSelect && !timer ) {
if (!levelHasChanged){
//~ if (!levelHasChanged){
//~ #ifndef USECD
printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile);
printf("load:%p:%08x:%s", &load_all_overlays_here, &level, overlayFile);
//~ PCload( &load_all_overlays_here, &levelHasChanged, overlayFile );
//~ #endif
#ifdef USECD
level = !level;
levelHasChanged = 1;
}
//~ levelHasChanged = 1;
#endif
//~ }
timer = 30;

1
pad.h
View File

@ -6,7 +6,6 @@ typedef struct
{
int xpos, ypos; // Stored position for sprite(s)
int xpos2, ypos2; // controlled by this controller.
unsigned char status; // These 8 values are obtained
unsigned char type; // directly from the controller
unsigned char button1; // buffer we installed with InitPAD.

111
pcdrv.c
View File

@ -1,80 +1,105 @@
int waitForSIODone( int command ){
#include "pcdrv.h"
// This should wait for a signal from the SIO to send when it's done
// command can be 0 open, 1 close, 2 seek, 3 read, 4 write
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;
#define OPEN 0
#define CLOSE 1
#define SEEK 2
#define READ 3
#define WRITE 4
#define CREATE 5
int result = 0;
int open(const char * filename, int attributes) {
for ( uint t = 0; t < timeOut; t ++){
// Send filename and attributes (ro,wo,rw..)
// expects an int referring to a file descriptor on the PC
if ( * flag == 1 ){
int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
result = * flag;
printf("open:%s:%i:%08x", filename, attributes, &fd);
break;
}
waitForSIODone(0)
}
return fd; // If all is well, returns a positive int . If -1, wrong
return result;
};
int create(const char * filename, int attributes) {
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename ) {
// Send filename and attributes (ro,wo,rw..)
// expects an int referring to a file descriptor on the PC
// Send filename , load address, and flag address
// flag address points to an int16 that when set to 1 enable lvl/pointers/screen refresh
// Returns 1 if all good, 0 else
int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
//~ int flag = 0;
printf("create:%s:%i:%08x", filename, attributes, &fd);
printf("load:%08x:%08x:%s", loadAddress, flagAddress, filename);
waitForSIODone(5); // Should return int fd, -1 else
return fd; // If all is well, returns a positive int . If -1, wrong
//~ return ; // If all is well, returns a positive int . If -1, wrong
};
int close( int fd ) {
//~ int PCopen(const char * filename, int attributes) {
// Send the close command and fd as int
//~ // Send filename and attributes (ro,wo,rw..)
//~ // expects an int referring to a file descriptor on the PC
printf("close:%s:%08x", filename, fd);
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
return waitForSIODone(1); // Should return 1 if ok, 0 if wrong, or -1 if wrong ?
//~ printf("open:%s:%i:%08x", filename, attributes, &fd);
};
//~ waitForSIODone(0);
int seek( int fd, int offset, int accessMode){
//~ return fd; // If all is well, returns a positive int . If -1, wrong
// Move file pointer in fd at offset
// Access mode can be 0 abs, 1 rel to start, 2 rel to end
//~ };
printf("seek:%i:%08x:%i", fd, offset, accessMode);
//~ int PCcreate(const char * filename, int attributes) {
return waitForSIODone(2);
//~ // Send filename and attributes (ro,wo,rw..)
//~ // expects an int referring to a file descriptor on the PC
};
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
int read( int fd, int len, char * buffer ){
//~ printf("create:%s:%i:%08x", filename, attributes, &fd);
// Read len bytes of fd and put them in buff
//~ waitForSIODone(5); // Should return int fd, -1 else
int count = 0;
//~ return fd; // If all is well, returns a positive int . If -1, wrong
printf("read:%i:%08x:%i", fd, len, buffer, count);
//~ };
waitForSIODone(3);
//~ int PCclose( int fd ) {
return count;
//~ // Send the close command and fd as int
};
//~ printf("close:%d", fd);
//~ return waitForSIODone(1); // Should return 1 if ok, 0 if wrong, or -1 if wrong ?
//~ };
//~ int PCseek( int fd, int offset, int accessMode){
//~ // Move file pointer in fd at offset
//~ // Access mode can be 0 abs, 1 rel to start, 2 rel to end
//~ printf("seek:%i:%08x:%i", fd, offset, accessMode);
//~ return waitForSIODone(2);
//~ };
//~ int PCread( int fd, int len, char * buffer ){
//~ // Read len bytes of fd and put them in buff
//~ int count = 0;
//~ printf("read:%i:%08x:%i", fd, len, buffer, count);
//~ waitForSIODone(3);
//~ return count;
//~ };

27
pcdrv.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <sys/types.h>
#include <stdio.h>
#define OPEN 0
#define CLOSE 1
#define SEEK 2
#define READ 3
#define WRITE 4
#define CREATE 5
#define LOAD 6
int waitForSIODone( int * flag );
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename );
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 );