Skip to content

Commit

Permalink
-edge case handling on serial
Browse files Browse the repository at this point in the history
-cs2 docu
  • Loading branch information
wodowiesel committed Jun 29, 2024
1 parent da4480b commit ced7093
Show file tree
Hide file tree
Showing 8 changed files with 1,279 additions and 1,270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ void loop() {

gameTitle[16] = '\0';


// Read cartridge title and check for non-printable text
for (uint16_t romAddress = 0x0134; romAddress <= 0x143; romAddress++) {
char headerChar = (char) read_byte(romAddress);
if ((headerChar >= 0x30 && headerChar <= 0x57) || // 0-9
(headerChar >= 0x41 && headerChar <= 0x5A) || // A-Z
(headerChar >= 0x61 && headerChar <= 0x7A)) { // a-z
gameTitle[(romAddress - 0x0134)] = headerChar;
Serial.println(headerChar);
//Serial.println(headerChar);
/*
* MULICARD MBCs & EMS etc https://gbdev.gg8.se/wiki/articles/Memory_Bank_Controllers
A header matching any of the following is detected as EMS mapper:
Expand Down Expand Up @@ -202,7 +201,6 @@ void loop() {
if (ramSize > 1) {
ramEndAddress = 0xBFFF; // 8K RAM
}


}

Expand Down
11 changes: 6 additions & 5 deletions code-pc/c/GBCartRead_v1.8_Rev1.3_C_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#else
#include <unistd.h>
#endif
int cport_nr = 3; // /dev/ttyS0 (COM1 on windows)
int bdrate = 57600; // 57600 baud (default)
int cport_nr = 2; // /dev/ttyS0 (COM1 on windows) , i use on com3
int bdrate = 9600; // 57600 baud (default)
int firstStart = 1;
int headercounter = 0;
char gametitle[80];
Expand Down Expand Up @@ -181,7 +181,8 @@ int main() {
}
char* tokstr = strtok ((char *) buffer, "\r\n");
if (tokstr == NULL) {
printf ("tokstr: NULL error, no title found\n");
printf ("tokstr: NULL error, no title found, using default: unknown\n");
tokstr = "unknown";
}
while (tokstr != NULL) {
if (headercounter == 0) {
Expand Down Expand Up @@ -301,7 +302,7 @@ int main() {
}
else if (userInput == '2') {
printf ("\nDumping RAM to %s.sav ... ", gametitle);
strncpy(filename, gametitle, 20);
strncpy(filename, gametitle, 20); //why 20?
strcat(filename, ".sav");
write_to_file(filename, "READRAM\n", 1);
printf ("\nFinished\n");
Expand All @@ -314,7 +315,7 @@ int main() {
char userInputConfirm = read_one_letter();
if (userInputConfirm == 'y') {
printf ("\nWriting to RAM from %s.sav ... ", gametitle);
strncpy(filename, gametitle, 20);
strncpy(filename, gametitle, 30);
strcat(filename, ".sav");
read_from_file(filename, "WRITERAM\n");
printf ("\nFinished\n");
Expand Down
Binary file modified code-pc/c/GBCartRead_v1.8_Rev1.3_C_Interface.exe
Binary file not shown.
21 changes: 11 additions & 10 deletions code-pc/c/GBCartRead_v1.8_Rev1.3_C_Interface.i
Original file line number Diff line number Diff line change
Expand Up @@ -131113,8 +131113,8 @@ int unlinkat (int, const char *, int);


# 19 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
int cport_nr = 3;
int bdrate = 57600;
int cport_nr = 2;
int bdrate = 9600;
int firstStart = 1;
int headercounter = 0;
char gametitle[80];
Expand Down Expand Up @@ -131302,12 +131302,13 @@ int main() {
((void *)0)
# 183 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
) {
printf ("tokstr: NULL error\n");
printf ("tokstr: NULL error, no title found, using default: unknown\n");
tokstr = "unknown";
}
while (tokstr !=
# 186 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
# 187 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
((void *)0)
# 186 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
# 187 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
) {
if (headercounter == 0) {
printf ("\nGame title: %s\n", tokstr);
Expand Down Expand Up @@ -131343,7 +131344,7 @@ int main() {
case 29: printf ("MBC5+RUMBLE+RAM\n"); break;
case 30: printf ("MBC5+RUMBLE+RAM+BATTERY\n"); break;
case 252: printf("Gameboy-Camera\n"); break;
default: printf ("Not found\n");
default: printf ("Not found or unknown\n");
}
}
else if (headercounter == 2) {
Expand Down Expand Up @@ -131411,18 +131412,18 @@ int main() {
printf ("\nselect loop error\n");
}
tokstr = strtok (
# 288 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
# 289 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
((void *)0)
# 288 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
# 289 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
, "\r\n");
printf ("tokstr: %s\n", tokstr);
headercounter++;
}
printf ("\nFlushed\n");
fflush(
# 293 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
# 294 "GBCartRead_v1.8_Rev1.3_C_Interface.c" 3 4
((__getreent())->_stdout)
# 293 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
# 294 "GBCartRead_v1.8_Rev1.3_C_Interface.c"
);
}
else if (userInput == '1') {
Expand Down
Binary file modified code-pc/c/GBCartRead_v1.8_Rev1.3_C_Interface.o
Binary file not shown.
Loading

0 comments on commit ced7093

Please sign in to comment.