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 math
import signal import signal
DEBUG = 0 DEBUG = 1
# Working directory # Working directory
@ -54,6 +54,8 @@ flagAddr = ""
loadFile = "" loadFile = ""
levelId = ""
# One byte # One byte
uno = int(1).to_bytes(1, byteorder='little', signed=False) uno = int(1).to_bytes(1, byteorder='little', signed=False)
@ -441,13 +443,9 @@ def resetListener():
def main(args): def main(args):
# ~ signal.signal(signal.SIGINT, sig_interrupt_handler)
# ~ global Run, memAddr
while True: 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 # Flush serial buffers to avoid residual data
@ -461,7 +459,6 @@ def main(args):
if Listen: if Listen:
print("Listening for incoming data...") print("Listening for incoming data...")
if DEBUG > 1: if DEBUG > 1:
@ -482,31 +479,49 @@ def main(args):
print( "Incoming data : " + inputBuffer ) 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
if argList[0] == "load" and len(argList) == 4:
memAddr = str(parsedBuffer[0]) if len(argList[1]) < 8 or len(argList[2]) < 8:
flagAddr = str(parsedBuffer[1])
loadFile = str(parsedBuffer[2])
ser.reset_input_buffer() if DEBUG:
inputBuffer = "" print("Wrong data format, aborting...")
if DEBUG > 1:
print( memAddr + " - " + flagAddr + " - " + loadFile )
Listen = 0
break break
memAddr = argList[1]
flagAddr = argList[2]
loadFile = argList[3]
ser.reset_input_buffer()
inputBuffer = ""
if DEBUG > 1:
print( memAddr + " - " + flagAddr + " - " + loadFile )
Listen = 0
break
else:
ser.reset_input_buffer()
inputBuffer = ""
break
if memAddr and loadFile: if memAddr and loadFile:
@ -526,10 +541,14 @@ def main(args):
binFileName = "Overlay.lvl1" binFileName = "Overlay.lvl1"
levelId = 1
if fileClean == "level1.bin": if fileClean == "level1.bin":
binFileName = "Overlay.lvl0" binFileName = "Overlay.lvl0"
levelId = 0
if DEBUG: if DEBUG:
print( print(
@ -540,7 +559,7 @@ def main(args):
"File : " + loadFile + "\n" + "File : " + loadFile + "\n" +
"Bin : " + binFileName "Bin : " + binFileName + "ID : " + str(levelId)
) )
@ -578,7 +597,7 @@ def main(args):
# Set level changed flag # Set level changed flag
SendBin( uno , flagAddr) SendBin( levelId.to_bytes(1, byteorder='little', signed=False) , flagAddr)
# Reset everything # Reset everything

67
main.c
View File

@ -29,6 +29,7 @@
#include "physics.h" #include "physics.h"
#include "graphics.h" #include "graphics.h"
#include "space.h" #include "space.h"
#include "pcdrv.h"
//~ #define USECD //~ #define USECD
@ -74,9 +75,13 @@ u_long overlaySize = 0;
#include "levels/level1.h" #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; static char* overlayFile;
@ -198,6 +203,8 @@ LEVEL curLvl = {
&meshPlan &meshPlan
}; };
LEVEL * loadLvl;
// Pad // Pad
void callback(); void callback();
@ -210,13 +217,16 @@ int main() {
overlaySize = __lvl0_end; overlaySize = __lvl0_end;
loadLvl = &level0;
} else if ( level == 1) { } else if ( level == 1) {
overlayFile = "\\level1.bin;1"; overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end; overlaySize = __lvl1_end;
} loadLvl = &level1;
}
// Load overlay // Load overlay
@ -240,6 +250,8 @@ int main() {
LvlPtrSet( &curLvl, &level1); LvlPtrSet( &curLvl, &level1);
} }
levelWas = level;
// Overlay // Overlay
@ -344,10 +356,10 @@ int main() {
//~ while (1) { //~ while (1) {
while ( VSync(1) ) { while ( VSync(1) ) {
if (levelHasChanged){ if ( levelWas != level ){
switch (level){ switch ( level ){
case 0: case 0:
@ -355,6 +367,8 @@ int main() {
overlaySize = __lvl0_end; overlaySize = __lvl0_end;
loadLvl = &level0;
break; break;
case 1: case 1:
@ -363,31 +377,33 @@ int main() {
overlaySize = __lvl1_end; overlaySize = __lvl1_end;
loadLvl = &level1;
break; break;
default: default:
overlayFile = "\\level0.bin;1"; overlayFile = "\\level0.bin;1";
loadLvl = &level0;
break; break;
} }
#ifdef USECD #ifdef USECD
LoadLevelCD( overlayFile, &load_all_overlays_here ); LoadLevelCD( overlayFile, &load_all_overlays_here );
#endif #endif
SwitchLevel( overlayFile, &load_all_overlays_here, &curLvl, &level0); SwitchLevel( overlayFile, &load_all_overlays_here, &curLvl, loadLvl);
//~ printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile); //~ levelHasChanged = 0;
levelWas = level;
levelHasChanged = 0;
} }
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); //~ FntPrint("%x\n", curLvl.actorPtr->tim);
@ -1372,18 +1388,25 @@ void callback() {
if ( PADL & PadSelect && !timer ) { if ( PADL & PadSelect && !timer ) {
if (!levelHasChanged){ //~ if (!levelHasChanged){
//~ #ifndef USECD //~ #ifndef USECD
printf("load:%p:%08x:%s", &load_all_overlays_here, &level, overlayFile);
//~ PCload( &load_all_overlays_here, &levelHasChanged, overlayFile );
//~ #endif
#ifdef USECD
printf("%p:%p:%s", &load_all_overlays_here, &levelHasChanged, overlayFile);
//~ #endif
level = !level; level = !level;
levelHasChanged = 1; //~ levelHasChanged = 1;
}
#endif
//~ }
timer = 30; timer = 30;

1
pad.h
View File

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

169
pcdrv.c
View File

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