Skip to content

Commit

Permalink
- Bugfixes and new concept to build SMC.BIN header.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlightControl-User committed Oct 8, 2023
1 parent 223a8a3 commit bca8cbb
Show file tree
Hide file tree
Showing 13 changed files with 6,265 additions and 6,117 deletions.
Binary file modified python/SMC-HEADER.BIN
Binary file not shown.
Binary file removed python/SMC-R45.BIN
Binary file not shown.
Binary file modified python/SMC.BIN
Binary file not shown.
12 changes: 7 additions & 5 deletions python/smc_convert.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from intelhex import IntelHex

version = "R45.1.0"

src1 = IntelHex()

src1.fromfile("C:/Users/svenv/OneDrive/Documents/GitHub/x16-flash/python/x16-smc-header.hex", format="hex")
src1.fromfile("python/x16-smc-header.hex", format="hex")
src1.tofile("python/SMC-HEADER.BIN", format="bin")

src2 = IntelHex()

src2.fromfile("C:/Users/svenv/OneDrive/Documents/GitHub/x16-flash/python/x16-smc-r45.1.0.hex", format="hex")
src2.tofile("python/SMC-R45.1.0.BIN", format="bin")
src2.tofile("python/SMC-"+version+".BIN", format="bin")

# Try reading the file in binary mode and writing it back in binary
# mode. By default it reads files in text mode
input1 = open('python/SMC-HEADER.BIN', 'rb').read()
input2 = open('python/SMC-R45.1.0.bin', 'rb').read()
input1 = open("python/SMC-HEADER.BIN", "rb").read()
input2 = open("python/SMC-"+version+".BIN", "rb").read()

input1 += input2

with open('python/SMC.BIN', 'wb') as fp:
with open("python/SMC.BIN", "wb") as fp:
fp.write(input1)
4 changes: 2 additions & 2 deletions python/x16-smc-header.hex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:100000002B2C000000000000000000000000000099
:1000100000000000000000000000000000000000E0
:100000002D010000000000000000000000000000C2
:1000100000000000000000000000000000002C2B89
:00000001FF
2 changes: 1 addition & 1 deletion src/cx16-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void display_info_smc(unsigned char info_status, unsigned char* info_text) {
status_smc = info_status;
display_smc_led(status_color[info_status]);
gotoxy(INFO_X, INFO_Y);
printf("SMC %-9s ATTiny %-9s BL:%u ", status_text[info_status], smc_version_text, smc_bootloader);
printf("SMC %-9s ATTiny %-8s BL:%u ", status_text[info_status], smc_version_text, smc_bootloader);
if(info_text) {
printf("%-25s", info_text);
}
Expand Down
15 changes: 11 additions & 4 deletions src/cx16-smc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__mem unsigned int smc_bootloader = 0;
__mem unsigned int smc_file_size = 0;

__mem unsigned char smc_rom_releases[32];
__mem unsigned char smc_file_header[32];

__mem unsigned char smc_release;
__mem unsigned char smc_major;
Expand Down Expand Up @@ -78,9 +78,16 @@ unsigned long smc_get_version_text(unsigned char* version_string, unsigned char
return MAKELONG(MAKEWORD(minor, major), MAKEWORD(0, release));
}

/**
* @brief Search in the smc file header for supported ROM.BIN releases.
* The first 3 bytes of the smc file header contain the SMC.BIN version, major and minor numbers.
*
* @param rom_release The ROM release to search for.
* @return unsigned char true if found.
*/
unsigned char smc_supported_rom(unsigned char rom_release) {
for(unsigned char i=0; i<32; i++) {
if(smc_rom_releases[i] == rom_release)
for(unsigned char i=31; i>3; i--) {
if(smc_file_header[i] == rom_release)
return 1;
}
return 0;
Expand Down Expand Up @@ -156,7 +163,7 @@ unsigned int smc_read(unsigned char display_progress) {
if (fp) {

// Read the ROM releases in the SMC.BIN header first.
smc_file_read = fgets(smc_rom_releases, 32, fp);
smc_file_read = fgets(smc_file_header, 32, fp);

// Has the header been read, all ok, otherwise the file size is wrong!
if(smc_file_read) {
Expand Down
2 changes: 1 addition & 1 deletion src/cx16-smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern unsigned int smc_bootloader;
extern unsigned char smc_version_text[16];
extern unsigned int smc_file_size;

extern unsigned char smc_rom_releases[32];
extern unsigned char smc_file_header[32];

extern unsigned char smc_release;
extern unsigned char smc_major;
Expand Down
8 changes: 4 additions & 4 deletions src/cx16-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ void main() {
display_info_smc(STATUS_ISSUE, "SMC.BIN too large!"); // Stop with SMC issue, and reset the CX16.
} else {
// SF-4 | SMC.BIN and all ok | Display the SMC.BIN file version and set SMC to Flash. | Flash
// Fill the version data ...
smc_file_release = rom_get_release(*((char*)RAM_BASE+0x30));
smc_file_major = rom_get_prefix(*((char*)RAM_BASE+0x31));
smc_file_minor = rom_get_prefix(*((char*)RAM_BASE+0x32));
// The first 3 bytes of the smc file header is the version of the SMC file.
smc_file_release = smc_file_header[0];
smc_file_major = smc_file_header[1];
smc_file_minor = smc_file_header[2];

char smc_file_version_text[13];
smc_get_version_text(smc_file_version_text, smc_file_release, smc_file_major, smc_file_minor);
Expand Down
Binary file modified target/src/SMC.BIN
Binary file not shown.
Loading

0 comments on commit bca8cbb

Please sign in to comment.