diff --git a/.gitignore b/.gitignore index a7e8e21..d5127c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +nbproject/private build dist \ No newline at end of file diff --git a/SerialClass.cpp b/SerialClass.cpp index 018808c..f80519c 100644 --- a/SerialClass.cpp +++ b/SerialClass.cpp @@ -46,7 +46,7 @@ SerialClass::~SerialClass() { } -SerialClass::ErrorType SerialClass::OpenPort(const char* name) { +SerialClass::ErrorType SerialClass::OpenPort(const char* name, int rate) { #ifdef __WIN32__ if ( hComm != INVALID_HANDLE_VALUE ) { @@ -71,7 +71,7 @@ SerialClass::ErrorType SerialClass::OpenPort(const char* name) { return ERROR_CONFIG; } - dcbSerialParams.BaudRate = CBR_9600; // Setting BaudRate = 9600 + dcbSerialParams.BaudRate = rate; // Setting BaudRate = 9600 dcbSerialParams.ByteSize = 8; // Setting ByteSize = 8 dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1 dcbSerialParams.Parity = NOPARITY; // Setting Parity = None diff --git a/SerialClass.h b/SerialClass.h index b615280..571b40a 100644 --- a/SerialClass.h +++ b/SerialClass.h @@ -32,7 +32,7 @@ class SerialClass { ERROR_WRITE_FAIL, }; - ErrorType OpenPort(const char* name); + ErrorType OpenPort(const char* name, int rate); ErrorType SetRate(int rate); void ClosePort(); diff --git a/SiofsClass.cpp b/SiofsClass.cpp index 9f0d759..205a60a 100644 --- a/SiofsClass.cpp +++ b/SiofsClass.cpp @@ -648,6 +648,8 @@ void SiofsClass::FsWrite() { } + std::cout << "FS: Wrote " << info.length << " bytes." << std::endl; + ret = fwrite(buffer, 1, info.length, handles[info.fd]); free(buffer); diff --git a/main.cpp b/main.cpp index 8f4320d..7f8aceb 100644 --- a/main.cpp +++ b/main.cpp @@ -21,7 +21,7 @@ #include "SerialClass.h" #include "SiofsClass.h" -#define VERSION "0.80" +#define VERSION "0.82" #ifdef __WIN32__ #define SERIAL_DEFAULT "COM1" @@ -34,9 +34,12 @@ int serial_baud = 115200; std::string psexe_file; std::string bin_file; +std::string pat_file; unsigned int bin_addr; +int old_protocol = false; int terminal_mode = false; +int no_console = false; int hex_mode = false; extern int fs_messages; @@ -116,6 +119,7 @@ typedef struct { typedef struct { EXEC params; unsigned int crc32; + unsigned int flags; } EXEPARAM; typedef struct { @@ -314,8 +318,8 @@ int uploadEXE(const char* exefile, SerialClass* serial) { fclose(fp); param.crc32 = crc32(buffer, param.params.t_size, CRC32_REMAINDER); + param.flags = 0; - serial->SetRate(115200); serial->SendBytes((void*)"MEXE", 4); char reply[4]; @@ -336,7 +340,11 @@ int uploadEXE(const char* exefile, SerialClass* serial) { return -1; } - serial->SendBytes(¶m, sizeof(EXEPARAM)); + if( !old_protocol ) { + serial->SendBytes(¶m, sizeof(EXEPARAM)); + } else { + serial->SendBytes(¶m, sizeof(EXEPARAM)-4); + } Sleep(20); serial->SendBytes(buffer, param.params.t_size); @@ -346,7 +354,7 @@ int uploadEXE(const char* exefile, SerialClass* serial) { } -int uploadBIN(const char* file, unsigned int addr, SerialClass* serial) { +int uploadBIN(const char* file, unsigned int addr, SerialClass* serial, int patch) { BINPARAM param; char* buffer; @@ -373,8 +381,11 @@ int uploadBIN(const char* file, unsigned int addr, SerialClass* serial) { fclose(fp); - serial->SetRate(115200); - serial->SendBytes((void*)"MBIN", 4); + if( patch ) { + serial->SendBytes((void*)"MPAT", 4); + } else { + serial->SendBytes((void*)"MBIN", 4); + } char reply[4]; int timeout = true; @@ -418,7 +429,7 @@ int main(int argc, char** argv) { if ( argc >= 2 ) { - if ( strcmp( "-h", argv[1] ) == 0 ) { + if( ( strcmp( "-h", argv[1] ) == 0 ) || ( strcmp( "-?", argv[1] ) == 0 ) ) { std::cout << "Usage:" << std::endl; std::cout << " mcomms [-dev ] [-baud ] [-dir ] [-term] [-fsmsg]" << @@ -432,10 +443,13 @@ int main(int argc, char** argv) { std::cout << " -term - Enable terminal mode (forward keystrokes to serial)." << std::endl; std::cout << " -hex - Output received data in hex." << std::endl; #endif - std::cout << " -fsmsg - Enable SIOFS messages." << std::endl << std::endl; + std::cout << " -fsmsg - Enable SIOFS messages." << std::endl; + std::cout << " -nocons - Quit immediately, no console mode." << std::endl; + std::cout << " -old - Use old LITELOAD 1.0 protocol." << std::endl << std::endl; std::cout << " LITELOAD Parameters (catflap inspired):" << std::endl; std::cout << " up - Upload a file to specified address." << std::endl; + std::cout << " patch - Upload a patch binary." << std::endl; std::cout << " run - Upload a PS-EXE file (CPE format is supported)." << std::endl << std::endl; std::cout << " Specified memory address must be in hex." << std::endl << std::endl; @@ -499,6 +513,14 @@ int main(int argc, char** argv) { hex_mode = true; #endif + } else if ( strcmp("-nocons", argv[i]) == 0 ) { + + no_console = true; + + } else if ( strcmp("-old", argv[i]) == 0 ) { + + old_protocol = true; + } else if ( strcmp("-fsmsg", argv[i]) == 0 ) { fs_messages = true; @@ -513,6 +535,16 @@ int main(int argc, char** argv) { psexe_file = argv[i]; break; + } else if ( strcmp("patch", argv[i]) == 0 ) { + + i++; + if ( i >= argc ) { + std::cout << "Missing filename parameter." << std::endl; + return EXIT_FAILURE; + } + pat_file = argv[i]; + break; + } else if ( strcmp("up", argv[i]) == 0 ) { i++; @@ -538,7 +570,7 @@ int main(int argc, char** argv) { } - switch( serial.OpenPort(serial_device.c_str()) ) { + switch( serial.OpenPort(serial_device.c_str(), serial_baud) ) { case SerialClass::ERROR_OPENING: std::cout << "ERROR: Unable to open " << serial_device << "." << std::endl; return EXIT_FAILURE; @@ -547,35 +579,51 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + // Upload patch data + if( !pat_file.empty() ) { + + std::cout << "Uploading patch file..." << std::endl; + + if( uploadBIN(pat_file.c_str(), 0, &serial, 1) < 0 ) { + serial.ClosePort(); + return EXIT_FAILURE; + } + + serial.ClosePort(); + return EXIT_SUCCESS; + + } + // Upload binary file if specified - if ( !bin_file.empty() ) { + if( !bin_file.empty() ) { std::cout << "Uploading binary file..." << std::endl; - if ( uploadBIN(bin_file.c_str(), bin_addr, &serial) < 0 ) { + if( uploadBIN(bin_file.c_str(), bin_addr, &serial, 0) < 0 ) { + serial.ClosePort(); return EXIT_FAILURE; } + serial.ClosePort(); return EXIT_SUCCESS; } // Upload executable if specified - if ( !psexe_file.empty() ) { + if( !psexe_file.empty() ) { std::cout << "Uploading executable..." << std::endl; if ( uploadEXE(psexe_file.c_str(), &serial) < 0 ) { + serial.ClosePort(); return EXIT_FAILURE; } } - - // Set serial speed - if ( serial.SetRate(serial_baud) != SerialClass::OK ) { - std::cout << "ERROR: Unsupported baud rate specified for " << serial_device << "." << std::endl; - return EXIT_FAILURE; + if( no_console ) { + serial.ClosePort(); + return EXIT_SUCCESS; } std::cout << "Listening " << serial_device << " at " << serial_baud << " baud." << std::endl; diff --git a/nbproject/private/Makefile-variables.mk b/nbproject/private/Makefile-variables.mk deleted file mode 100644 index 020a7f9..0000000 --- a/nbproject/private/Makefile-variables.mk +++ /dev/null @@ -1,8 +0,0 @@ -# -# Generated - do not edit! -# -# NOCDDL -# -# Debug configuration -# Release configuration -# Debug-linux configuration diff --git a/nbproject/private/configurations.xml b/nbproject/private/configurations.xml deleted file mode 100644 index e5a86da..0000000 --- a/nbproject/private/configurations.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - Makefile - - - - localhost - 3 - - - - - - - - - - - - - - - gdb - - - - "${OUTPUT_PATH}" run "D:\Old PC Files\root\psyq\projects\mdemo\main.cpe - "${OUTPUT_PATH}" run "D:\Old PC Files\root\psyq\projects\mdemo\main.cpe" - "${OUTPUT_PATH}" - "${OUTPUT_PATH}" -term - - "${OUTPUT_PATH}" -term - - true - 1 - 0 - 0 - - - - - - - localhost - 3 - - - - - - - - - - - - - - - gdb - - - - "${OUTPUT_PATH}" - "${OUTPUT_PATH}" -fsmsg - "${OUTPUT_PATH}" -term -hex - - "${OUTPUT_PATH}" -term -hex - - true - 1 - 0 - 0 - - - - - - - localhost - 2 - - - - - - - - - - - - - - - gdb - - - - "${OUTPUT_PATH}" run "D:\Old PC Files\root\psyq\projects\mdemo\main.cpe - "${OUTPUT_PATH}" run "D:\Old PC Files\root\psyq\projects\mdemo\main.cpe" - "${OUTPUT_PATH}" -term - "${OUTPUT_PATH}" - - "${OUTPUT_PATH}" - - true - 0 - 0 - - - - - - diff --git a/nbproject/private/launcher.properties b/nbproject/private/launcher.properties deleted file mode 100644 index 6cc2127..0000000 --- a/nbproject/private/launcher.properties +++ /dev/null @@ -1,40 +0,0 @@ -# Launchers File syntax: -# -# [Must-have property line] -# launcher1.runCommand= -# [Optional extra properties] -# launcher1.displayName= -# launcher1.buildCommand= -# launcher1.runDir= -# launcher1.symbolFiles= -# launcher1.env.= -# (If this value is quoted with ` it is handled as a native command which execution result will become the value) -# [Common launcher properties] -# common.runDir= -# (This value is overwritten by a launcher specific runDir value if the latter exists) -# common.env.= -# (Environment variables from common launcher are merged with launcher specific variables) -# common.symbolFiles= -# (This value is overwritten by a launcher specific symbolFiles value if the latter exists) -# -# In runDir, symbolFiles and env fields you can use these macroses: -# ${PROJECT_DIR} - project directory absolute path -# ${OUTPUT_PATH} - linker output path (relative to project directory path) -# ${OUTPUT_BASENAME}- linker output filename -# ${TESTDIR} - test files directory (relative to project directory path) -# ${OBJECTDIR} - object files directory (relative to project directory path) -# ${CND_DISTDIR} - distribution directory (relative to project directory path) -# ${CND_BUILDDIR} - build directory (relative to project directory path) -# ${CND_PLATFORM} - platform name -# ${CND_CONF} - configuration name -# ${CND_DLIB_EXT} - dynamic library extension -# -# All the project launchers must be listed in the file! -# -# launcher1.runCommand=... -# launcher2.runCommand=... -# ... -# common.runDir=... -# common.env.KEY=VALUE - -# launcher1.runCommand= \ No newline at end of file diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml deleted file mode 100644 index 310b5bd..0000000 --- a/nbproject/private/private.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - 1 - 1 - - - - - file:/C:/Users/Lameguy64/Desktop/Projects/mcomms/SiofsClass.cpp - file:/C:/Users/Lameguy64/Desktop/Projects/mcomms/SiofsClass.h - file:/C:/Users/Lameguy64/Desktop/Projects/mcomms/SerialClass.cpp - file:/C:/Users/Lameguy64/Desktop/Projects/mcomms/main.cpp - - -