From 9535b0f878d0875a67f18d685cf37beb6eb25edc Mon Sep 17 00:00:00 2001 From: Matthieu Bucchianeri Date: Sat, 15 Feb 2025 16:44:10 -0800 Subject: [PATCH] Major rework of IO to use MOVSW. --- XTMax/Code/XTMax/XTMax.ino | 67 +++++-- XTMax/Code/XTMax/bootrom.h | 236 +++++++++++------------ XTMax/Drivers/BootROM/bootrom.asm | 219 ++++++++------------- XTMax/Drivers/BootROM/build.cmd | 2 +- XTMax/Drivers/BootROM/checksum.py | 17 -- XTMax/Drivers/BootROM/generate_header.py | 27 +++ 6 files changed, 273 insertions(+), 295 deletions(-) create mode 100644 XTMax/Drivers/BootROM/generate_header.py diff --git a/XTMax/Code/XTMax/XTMax.ino b/XTMax/Code/XTMax/XTMax.ino index b063d62..633e3e3 100644 --- a/XTMax/Code/XTMax/XTMax.ino +++ b/XTMax/Code/XTMax/XTMax.ino @@ -172,7 +172,8 @@ #define EMS_TOTAL_SIZE (16*1024*1024) -#define SD_BASE 0x280 // Must be a multiple of 16. +#define SD_BASE 0x280 // Must be a multiple of 8. +#define SD_FIXED_DISK_ID 0x80 // or 0x81 for 2nd disk. // -------------------------------------------------------------------------------------------------- @@ -197,7 +198,7 @@ uint8_t spi_shift_out =0; uint8_t sd_spi_datain =0; uint32_t sd_spi_cs_n = 0x0; uint32_t sd_spi_dataout =0; -uint8_t sd_scratch_register[5] = {0, 0, 0, 0, 0}; +uint8_t sd_scratch_register[4] = {0, 0, 0, 0}; uint16_t sd_requested_timeout = 0; elapsedMillis sd_timeout; @@ -542,15 +543,15 @@ inline void Mem_Read_Cycle() { GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; } - /* - XTMax_MEM_Response_Array - - Array holds value 0,1,2 - 0 = unitiailzed - add wait states and snoop - 1 = No wait states and no response - 2 = No wait states and yes respond + /* + XTMax_MEM_Response_Array + - Array holds value 0,1,2 + 0 = unitiailzed - add wait states and snoop + 1 = No wait states and no response + 2 = No wait states and yes respond - */ - else if (isa_address<0xA0000) { // "Conventional" RAM + */ + else if (isa_address<0xA0000) { // "Conventional" RAM isa_data_out = Internal_RAM_Read(); GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_LOW + CHRDY_OUT_LOW + trigger_out; @@ -591,6 +592,19 @@ inline void Mem_Read_Cycle() { GPIO8_DR = sd_pin_outputs + MUX_DATA_n_HIGH + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; } + else if (isa_address>=BOOTROM_ADDR+sizeof(BOOTROM) && isa_address=BOOTROM_ADDR+sizeof(BOOTROM) && isa_address= sd_requested_timeout; break; + case SD_BASE+7: isa_data_out = sd_timeout >= sd_requested_timeout; break; default: isa_data_out = 0xff; break; } @@ -739,7 +773,7 @@ inline void IO_Write_Cycle() { } - else if ((isa_address&0x0FF0)==SD_BASE ) { // Location of SD Card registers + else if ((isa_address&0x0FF8)==SD_BASE ) { // Location of SD Card registers GPIO7_DR = GPIO7_DATA_OUT_UNSCRAMBLE + MUX_ADDR_n_HIGH + CHRDY_OUT_LOW + trigger_out; GPIO8_DR = sd_pin_outputs + MUX_DATA_n_LOW + CHRDY_OE_n_HIGH + DATA_OE_n_HIGH; @@ -755,8 +789,7 @@ inline void IO_Write_Cycle() { case SD_BASE+4: sd_scratch_register[1] = data_in; break; case SD_BASE+5: sd_scratch_register[2] = data_in; break; case SD_BASE+6: sd_scratch_register[3] = data_in; break; - case SD_BASE+7: sd_scratch_register[4] = data_in; break; - case SD_BASE+15: sd_timeout = 0; sd_requested_timeout = data_in * 10; break; + case SD_BASE+7: sd_timeout = 0; sd_requested_timeout = data_in * 10; break; } //gpio9_int = GPIO9_DR; diff --git a/XTMax/Code/XTMax/bootrom.h b/XTMax/Code/XTMax/bootrom.h index e42c6e4..9bf2577 100644 --- a/XTMax/Code/XTMax/bootrom.h +++ b/XTMax/Code/XTMax/bootrom.h @@ -1,121 +1,111 @@ -#define BOOTROM_ADDR 0xCE000 +#define BOOTROM_ADDR 0xce000 unsigned char BOOTROM[] = { - 85, 170, 4, 6, 80, 81, 82, 86, 250, 184, 197, 5, 232, 49, 5, 232, - 54, 4, 115, 3, 233, 240, 0, 49, 192, 80, 157, 156, 88, 37, 0, 240, - 61, 0, 240, 117, 26, 176, 255, 177, 33, 210, 232, 117, 18, 251, 190, 0, - 0, 185, 255, 255, 243, 172, 9, 201, 250, 116, 4, 48, 210, 235, 8, 178, - 1, 184, 7, 6, 232, 249, 4, 184, 131, 2, 146, 238, 184, 44, 6, 232, - 238, 4, 49, 192, 142, 192, 38, 161, 78, 0, 186, 132, 2, 239, 232, 253, - 4, 184, 48, 7, 232, 217, 4, 38, 161, 76, 0, 186, 134, 2, 239, 232, - 236, 4, 184, 52, 7, 232, 200, 4, 184, 65, 6, 232, 194, 4, 184, 0, - 206, 38, 163, 78, 0, 232, 214, 4, 184, 48, 7, 232, 178, 4, 184, 14, - 1, 38, 163, 76, 0, 232, 198, 4, 184, 52, 7, 232, 162, 4, 184, 86, - 6, 232, 156, 4, 184, 0, 206, 38, 163, 6, 1, 232, 176, 4, 184, 48, - 7, 232, 140, 4, 184, 226, 1, 38, 163, 4, 1, 232, 160, 4, 184, 52, - 7, 232, 124, 4, 184, 242, 6, 232, 118, 4, 184, 0, 206, 38, 163, 98, - 0, 232, 138, 4, 184, 48, 7, 232, 102, 4, 184, 186, 3, 38, 163, 96, - 0, 232, 122, 4, 184, 52, 7, 232, 86, 4, 184, 186, 6, 232, 80, 4, - 184, 64, 0, 142, 192, 38, 254, 6, 117, 0, 38, 160, 117, 0, 232, 93, - 4, 184, 52, 7, 232, 57, 4, 251, 94, 90, 89, 88, 7, 203, 251, 85, - 86, 128, 250, 128, 116, 57, 137, 197, 137, 214, 156, 14, 184, 48, 1, 80, - 156, 186, 132, 2, 237, 80, 186, 134, 2, 237, 80, 137, 232, 137, 242, 207, - 156, 80, 137, 240, 60, 128, 114, 19, 137, 232, 128, 252, 8, 117, 12, 6, - 184, 64, 0, 142, 192, 38, 138, 22, 117, 0, 7, 88, 157, 235, 58, 128, - 252, 21, 126, 5, 232, 113, 0, 235, 34, 128, 252, 1, 116, 10, 128, 252, - 21, 116, 5, 190, 123, 1, 235, 3, 190, 137, 1, 86, 137, 222, 136, 227, - 48, 255, 208, 227, 135, 222, 46, 255, 164, 156, 1, 140, 197, 190, 64, 0, - 142, 198, 38, 136, 38, 116, 0, 142, 197, 137, 229, 139, 118, 8, 86, 115, - 4, 157, 249, 235, 2, 157, 248, 94, 93, 202, 2, 0, 159, 3, 242, 1, - 6, 2, 157, 2, 96, 3, 200, 1, 200, 1, 200, 1, 123, 3, 159, 3, - 200, 1, 200, 1, 145, 3, 159, 3, 200, 1, 200, 1, 159, 3, 159, 3, - 200, 1, 200, 1, 159, 3, 161, 3, 80, 184, 213, 6, 232, 113, 3, 88, - 80, 136, 224, 48, 228, 232, 134, 3, 184, 52, 7, 232, 98, 3, 88, 233, - 204, 1, 0, 4, 255, 0, 0, 255, 255, 0, 200, 0, 0, 0, 0, 0, - 63, 0, 6, 189, 64, 0, 142, 197, 48, 228, 38, 134, 38, 116, 0, 132, - 228, 116, 1, 249, 7, 195, 132, 192, 117, 3, 233, 161, 1, 80, 48, 228, - 137, 198, 83, 232, 225, 1, 137, 197, 1, 240, 137, 222, 131, 211, 0, 232, - 8, 2, 91, 88, 115, 3, 233, 137, 1, 83, 81, 82, 87, 80, 137, 193, - 48, 237, 137, 223, 186, 130, 2, 176, 0, 238, 81, 137, 232, 137, 243, 177, - 81, 232, 217, 2, 114, 70, 186, 143, 2, 176, 10, 238, 186, 128, 2, 236, - 60, 254, 116, 10, 186, 143, 2, 236, 132, 192, 117, 48, 235, 238, 185, 0, - 1, 82, 186, 131, 2, 236, 90, 132, 192, 252, 116, 4, 243, 109, 235, 4, - 237, 171, 226, 252, 237, 131, 197, 1, 131, 214, 0, 89, 226, 188, 186, 130, - 2, 176, 1, 238, 88, 95, 90, 89, 91, 233, 42, 1, 186, 130, 2, 176, - 1, 238, 89, 88, 40, 200, 95, 90, 89, 91, 233, 13, 1, 132, 192, 117, - 3, 233, 10, 1, 80, 48, 228, 137, 198, 83, 232, 74, 1, 137, 197, 1, - 240, 137, 222, 131, 211, 0, 232, 113, 1, 91, 88, 115, 3, 233, 242, 0, - 30, 83, 81, 82, 87, 80, 137, 193, 48, 237, 137, 223, 140, 192, 142, 216, - 186, 130, 2, 176, 0, 238, 81, 137, 232, 137, 243, 177, 88, 232, 61, 2, - 114, 109, 186, 128, 2, 176, 254, 238, 185, 0, 1, 135, 247, 82, 186, 131, - 2, 236, 90, 132, 192, 252, 116, 4, 243, 111, 235, 4, 173, 239, 226, 252, - 135, 254, 186, 143, 2, 176, 25, 238, 186, 128, 2, 236, 60, 255, 117, 10, - 186, 143, 2, 236, 132, 192, 117, 55, 235, 238, 36, 31, 60, 5, 117, 47, - 186, 143, 2, 176, 25, 238, 186, 128, 2, 236, 132, 192, 117, 10, 186, 143, - 2, 236, 132, 192, 117, 25, 235, 238, 131, 197, 1, 131, 214, 0, 89, 226, - 149, 186, 130, 2, 176, 1, 238, 88, 95, 90, 89, 91, 31, 235, 103, 186, - 130, 2, 176, 1, 238, 89, 88, 40, 200, 95, 90, 89, 91, 31, 235, 74, - 132, 192, 116, 74, 80, 48, 228, 137, 197, 83, 232, 138, 0, 1, 232, 131, - 211, 0, 232, 181, 0, 91, 88, 114, 57, 235, 59, 182, 254, 6, 184, 64, - 0, 142, 192, 38, 138, 22, 117, 0, 7, 181, 254, 177, 255, 49, 192, 248, - 195, 80, 83, 232, 97, 0, 232, 145, 0, 91, 88, 114, 21, 235, 23, 235, - 21, 180, 3, 232, 155, 0, 135, 209, 248, 195, 180, 170, 249, 195, 180, 1, - 249, 195, 180, 4, 249, 195, 48, 228, 248, 195, 49, 192, 142, 216, 142, 192, - 185, 0, 1, 191, 0, 124, 243, 171, 184, 1, 2, 186, 128, 0, 185, 1, - 0, 187, 0, 124, 205, 19, 129, 62, 254, 125, 85, 170, 117, 15, 184, 7, - 7, 232, 92, 1, 49, 192, 142, 192, 234, 0, 124, 0, 0, 184, 33, 7, - 232, 77, 1, 251, 244, 235, 253, 49, 192, 49, 219, 82, 81, 82, 136, 200, - 36, 192, 209, 224, 209, 224, 136, 232, 185, 255, 0, 247, 225, 90, 136, 241, - 48, 237, 1, 200, 177, 63, 247, 225, 89, 81, 48, 237, 128, 225, 63, 73, - 1, 200, 131, 210, 0, 137, 211, 89, 90, 195, 81, 82, 232, 18, 0, 57, - 211, 114, 10, 119, 4, 57, 200, 114, 4, 249, 90, 89, 195, 248, 90, 89, - 195, 186, 250, 0, 185, 63, 197, 195, 80, 30, 83, 81, 82, 86, 184, 0, - 206, 142, 216, 186, 130, 2, 176, 1, 238, 185, 1, 0, 186, 160, 134, 180, - 134, 205, 21, 186, 128, 2, 176, 255, 185, 10, 0, 238, 226, 253, 186, 130, - 2, 176, 0, 238, 187, 10, 0, 190, 5, 5, 185, 1, 0, 180, 1, 232, - 92, 0, 115, 15, 49, 201, 186, 32, 78, 180, 134, 205, 21, 75, 117, 231, - 249, 235, 52, 190, 11, 5, 185, 5, 0, 180, 1, 232, 64, 0, 114, 39, - 186, 143, 2, 176, 250, 238, 190, 17, 5, 185, 1, 0, 180, 1, 232, 45, - 0, 190, 23, 5, 185, 1, 0, 180, 0, 232, 34, 0, 115, 9, 186, 143, - 2, 236, 132, 192, 116, 224, 249, 94, 90, 89, 91, 31, 114, 8, 184, 120, - 6, 232, 108, 0, 88, 195, 184, 155, 6, 232, 100, 0, 88, 195, 186, 128, - 2, 176, 255, 238, 81, 185, 6, 0, 252, 172, 238, 226, 252, 185, 8, 0, - 236, 60, 255, 225, 251, 89, 56, 224, 118, 3, 249, 235, 4, 248, 236, 226, - 253, 176, 255, 238, 195, 64, 0, 0, 0, 0, 149, 72, 0, 0, 1, 170, - 135, 119, 0, 0, 0, 0, 1, 105, 64, 0, 0, 0, 1, 186, 128, 2, - 80, 176, 255, 238, 136, 200, 136, 252, 239, 88, 134, 216, 239, 134, 216, 180, - 1, 239, 185, 8, 0, 236, 60, 255, 225, 251, 132, 192, 116, 1, 249, 195, - 156, 30, 83, 86, 137, 198, 184, 0, 206, 142, 216, 180, 14, 49, 219, 252, - 172, 8, 192, 116, 4, 205, 16, 235, 247, 94, 91, 31, 157, 195, 156, 30, - 83, 81, 82, 86, 137, 194, 184, 0, 206, 142, 216, 49, 219, 252, 137, 214, - 177, 12, 211, 238, 131, 230, 15, 138, 132, 181, 5, 180, 14, 205, 16, 137, - 214, 177, 8, 211, 238, 131, 230, 15, 138, 132, 181, 5, 180, 14, 205, 16, - 137, 214, 177, 4, 211, 238, 131, 230, 15, 138, 132, 181, 5, 180, 14, 205, - 16, 137, 214, 131, 230, 15, 138, 132, 181, 5, 180, 14, 205, 16, 94, 90, - 89, 91, 31, 157, 195, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, - 66, 67, 68, 69, 70, 66, 111, 111, 116, 82, 79, 77, 32, 102, 111, 114, - 32, 88, 84, 77, 97, 120, 32, 118, 49, 46, 48, 13, 10, 67, 111, 112, - 121, 114, 105, 103, 104, 116, 32, 40, 99, 41, 32, 50, 48, 50, 53, 32, - 77, 97, 116, 116, 104, 105, 101, 117, 32, 66, 117, 99, 99, 104, 105, 97, - 110, 101, 114, 105, 13, 10, 0, 67, 80, 85, 32, 115, 117, 112, 112, 111, - 114, 116, 115, 32, 73, 78, 83, 47, 79, 85, 84, 83, 32, 105, 110, 115, - 116, 114, 117, 99, 116, 105, 111, 110, 115, 13, 10, 0, 79, 108, 100, 32, - 73, 78, 84, 49, 51, 104, 32, 86, 101, 99, 116, 111, 114, 32, 61, 32, - 0, 78, 101, 119, 32, 73, 78, 84, 49, 51, 104, 32, 86, 101, 99, 116, - 111, 114, 32, 61, 32, 0, 78, 101, 119, 32, 70, 105, 120, 101, 100, 32, - 68, 105, 115, 107, 32, 80, 97, 114, 97, 109, 101, 116, 101, 114, 32, 84, - 97, 98, 108, 101, 32, 61, 32, 0, 83, 68, 32, 67, 97, 114, 100, 32, - 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 100, 32, 115, 117, 99, 99, - 101, 115, 115, 102, 117, 108, 108, 121, 13, 10, 0, 83, 68, 32, 67, 97, - 114, 100, 32, 102, 97, 105, 108, 101, 100, 32, 116, 111, 32, 105, 110, 105, - 116, 105, 97, 108, 105, 122, 101, 13, 10, 0, 84, 111, 116, 97, 108, 32, - 70, 105, 120, 101, 100, 32, 68, 105, 115, 107, 32, 68, 114, 105, 118, 101, - 115, 32, 61, 32, 0, 85, 110, 115, 117, 112, 112, 111, 114, 116, 101, 100, - 32, 73, 78, 84, 49, 51, 104, 32, 70, 117, 110, 99, 116, 105, 111, 110, - 32, 0, 78, 101, 119, 32, 73, 78, 84, 49, 56, 104, 32, 86, 101, 99, - 116, 111, 114, 32, 61, 32, 0, 66, 111, 111, 116, 105, 110, 103, 32, 102, - 114, 111, 109, 32, 83, 68, 32, 67, 97, 114, 100, 46, 46, 46, 13, 10, - 0, 78, 111, 116, 32, 98, 111, 111, 116, 97, 98, 108, 101, 13, 10, 0, - 58, 0, 32, 0, 13, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 85, 170, 4, 6, 80, 81, 82, 86, 250, 184, 124, 5, 232, 232, 4, 232, + 237, 3, 115, 3, 233, 158, 0, 184, 190, 5, 232, 218, 4, 49, 192, 142, + 192, 38, 161, 78, 0, 186, 131, 2, 239, 232, 233, 4, 184, 151, 6, 232, + 197, 4, 38, 161, 76, 0, 186, 133, 2, 239, 232, 216, 4, 184, 155, 6, + 232, 180, 4, 184, 0, 206, 38, 163, 78, 0, 184, 188, 0, 38, 163, 76, + 0, 184, 27, 6, 232, 160, 4, 186, 130, 2, 236, 48, 228, 80, 232, 180, + 4, 184, 155, 6, 232, 144, 4, 88, 60, 128, 117, 16, 184, 0, 206, 38, + 163, 6, 1, 184, 151, 1, 38, 163, 4, 1, 235, 14, 184, 0, 206, 38, + 163, 26, 1, 184, 151, 1, 38, 163, 24, 1, 184, 0, 206, 38, 163, 98, + 0, 184, 110, 3, 38, 163, 96, 0, 184, 54, 6, 232, 89, 4, 184, 64, + 0, 142, 192, 38, 254, 6, 117, 0, 38, 160, 117, 0, 232, 102, 4, 184, + 155, 6, 232, 66, 4, 251, 94, 90, 89, 88, 7, 203, 251, 85, 86, 80, + 82, 186, 130, 2, 236, 90, 56, 194, 88, 116, 57, 137, 197, 137, 214, 156, + 14, 184, 229, 0, 80, 156, 186, 131, 2, 237, 80, 186, 133, 2, 237, 80, + 137, 232, 137, 242, 207, 156, 80, 137, 240, 60, 128, 114, 19, 137, 232, 128, + 252, 8, 117, 12, 6, 184, 64, 0, 142, 192, 38, 138, 22, 117, 0, 7, + 88, 157, 235, 58, 128, 252, 21, 126, 5, 232, 113, 0, 235, 34, 128, 252, + 1, 116, 10, 128, 252, 21, 116, 5, 190, 48, 1, 235, 3, 190, 62, 1, + 86, 137, 222, 136, 227, 48, 255, 208, 227, 135, 222, 46, 255, 164, 81, 1, + 140, 197, 190, 64, 0, 142, 198, 38, 136, 38, 116, 0, 142, 197, 137, 229, + 139, 118, 8, 86, 115, 4, 157, 249, 235, 2, 157, 248, 94, 93, 202, 2, + 0, 83, 3, 167, 1, 187, 1, 79, 2, 20, 3, 125, 1, 125, 1, 125, + 1, 47, 3, 83, 3, 125, 1, 125, 1, 69, 3, 83, 3, 125, 1, 125, + 1, 83, 3, 83, 3, 125, 1, 125, 1, 83, 3, 85, 3, 80, 184, 81, + 6, 232, 115, 3, 88, 80, 136, 224, 48, 228, 232, 136, 3, 184, 155, 6, + 232, 100, 3, 88, 233, 203, 1, 0, 4, 255, 0, 0, 255, 255, 0, 200, + 0, 0, 0, 0, 0, 63, 0, 6, 189, 64, 0, 142, 197, 48, 228, 38, + 134, 38, 116, 0, 132, 228, 116, 1, 249, 7, 195, 132, 192, 117, 3, 233, + 160, 1, 80, 48, 228, 137, 198, 83, 232, 227, 1, 137, 197, 1, 240, 137, + 222, 131, 211, 0, 232, 10, 2, 91, 88, 115, 3, 233, 136, 1, 30, 83, + 81, 82, 87, 80, 137, 193, 48, 237, 184, 0, 206, 142, 216, 137, 223, 186, + 130, 2, 176, 0, 238, 81, 137, 232, 137, 243, 177, 81, 232, 213, 2, 114, + 60, 186, 135, 2, 176, 10, 238, 186, 128, 2, 236, 60, 254, 116, 10, 186, + 135, 2, 236, 132, 192, 117, 38, 235, 238, 185, 0, 1, 86, 190, 0, 8, + 252, 243, 165, 94, 237, 131, 197, 1, 131, 214, 0, 89, 226, 199, 186, 130, + 2, 176, 1, 238, 88, 95, 90, 89, 91, 31, 233, 45, 1, 186, 130, 2, + 176, 1, 238, 89, 88, 40, 200, 95, 90, 89, 91, 31, 233, 15, 1, 132, + 192, 117, 3, 233, 12, 1, 80, 48, 228, 137, 198, 83, 232, 79, 1, 137, + 197, 1, 240, 137, 222, 131, 211, 0, 232, 118, 1, 91, 88, 115, 3, 233, + 244, 0, 30, 83, 81, 82, 87, 80, 137, 193, 48, 237, 137, 223, 140, 192, + 142, 216, 184, 0, 206, 142, 192, 186, 130, 2, 176, 0, 238, 81, 137, 232, + 137, 243, 177, 88, 232, 61, 2, 114, 102, 186, 128, 2, 176, 254, 238, 185, + 0, 1, 86, 137, 254, 191, 0, 8, 252, 243, 165, 137, 247, 94, 186, 135, + 2, 176, 25, 238, 186, 128, 2, 236, 60, 255, 117, 10, 186, 135, 2, 236, + 132, 192, 117, 59, 235, 238, 36, 31, 60, 5, 117, 51, 186, 135, 2, 176, + 25, 238, 186, 128, 2, 236, 132, 192, 117, 10, 186, 135, 2, 236, 132, 192, + 117, 29, 235, 238, 131, 197, 1, 131, 214, 0, 89, 226, 160, 186, 130, 2, + 176, 1, 238, 140, 216, 142, 192, 88, 95, 90, 89, 91, 31, 235, 107, 186, + 130, 2, 176, 1, 238, 89, 140, 216, 142, 192, 88, 40, 200, 95, 90, 89, + 91, 31, 235, 74, 132, 192, 116, 74, 80, 48, 228, 137, 197, 83, 232, 141, + 0, 1, 232, 131, 211, 0, 232, 184, 0, 91, 88, 114, 57, 235, 59, 182, + 254, 6, 184, 64, 0, 142, 192, 38, 138, 22, 117, 0, 7, 181, 254, 177, + 255, 49, 192, 248, 195, 80, 83, 232, 100, 0, 232, 148, 0, 91, 88, 114, + 21, 235, 23, 235, 21, 180, 3, 232, 158, 0, 135, 209, 248, 195, 180, 170, + 249, 195, 180, 1, 249, 195, 180, 4, 249, 195, 48, 228, 248, 195, 49, 192, + 142, 216, 142, 192, 185, 0, 1, 191, 0, 124, 243, 171, 186, 130, 2, 236, + 136, 194, 184, 1, 2, 185, 1, 0, 187, 0, 124, 205, 19, 129, 62, 254, + 125, 85, 170, 117, 15, 184, 110, 6, 232, 92, 1, 49, 192, 142, 192, 234, + 0, 124, 0, 0, 184, 136, 6, 232, 77, 1, 251, 244, 235, 253, 49, 192, + 49, 219, 82, 81, 82, 136, 200, 36, 192, 209, 224, 209, 224, 136, 232, 185, + 255, 0, 247, 225, 90, 136, 241, 48, 237, 1, 200, 177, 63, 247, 225, 89, + 81, 48, 237, 128, 225, 63, 73, 1, 200, 131, 210, 0, 137, 211, 89, 90, + 195, 81, 82, 232, 18, 0, 57, 211, 114, 10, 119, 4, 57, 200, 114, 4, + 249, 90, 89, 195, 248, 90, 89, 195, 186, 250, 0, 185, 63, 197, 195, 80, + 30, 83, 81, 82, 86, 184, 0, 206, 142, 216, 186, 130, 2, 176, 1, 238, + 185, 1, 0, 186, 160, 134, 180, 134, 205, 21, 186, 128, 2, 176, 255, 185, + 10, 0, 238, 226, 253, 186, 130, 2, 176, 0, 238, 187, 10, 0, 190, 188, + 4, 185, 1, 0, 180, 1, 232, 92, 0, 115, 15, 49, 201, 186, 32, 78, + 180, 134, 205, 21, 75, 117, 231, 249, 235, 52, 190, 194, 4, 185, 5, 0, + 180, 1, 232, 64, 0, 114, 39, 186, 135, 2, 176, 250, 238, 190, 200, 4, + 185, 1, 0, 180, 1, 232, 45, 0, 190, 206, 4, 185, 1, 0, 180, 0, + 232, 34, 0, 115, 9, 186, 135, 2, 236, 132, 192, 116, 224, 249, 94, 90, + 89, 91, 31, 114, 8, 184, 217, 5, 232, 108, 0, 88, 195, 184, 252, 5, + 232, 100, 0, 88, 195, 186, 128, 2, 176, 255, 238, 81, 185, 6, 0, 252, + 172, 238, 226, 252, 185, 8, 0, 236, 60, 255, 225, 251, 89, 56, 224, 118, + 3, 249, 235, 4, 248, 236, 226, 253, 176, 255, 238, 195, 64, 0, 0, 0, + 0, 149, 72, 0, 0, 1, 170, 135, 119, 0, 0, 0, 0, 1, 105, 64, + 0, 0, 0, 1, 186, 128, 2, 80, 176, 255, 238, 136, 200, 136, 252, 239, + 88, 134, 216, 239, 134, 216, 180, 1, 239, 185, 8, 0, 236, 60, 255, 225, + 251, 132, 192, 116, 1, 249, 195, 156, 30, 83, 86, 137, 198, 184, 0, 206, + 142, 216, 180, 14, 49, 219, 252, 172, 8, 192, 116, 4, 205, 16, 235, 247, + 94, 91, 31, 157, 195, 156, 30, 83, 81, 82, 86, 137, 194, 184, 0, 206, + 142, 216, 49, 219, 252, 137, 214, 177, 12, 211, 238, 131, 230, 15, 138, 132, + 108, 5, 180, 14, 205, 16, 137, 214, 177, 8, 211, 238, 131, 230, 15, 138, + 132, 108, 5, 180, 14, 205, 16, 137, 214, 177, 4, 211, 238, 131, 230, 15, + 138, 132, 108, 5, 180, 14, 205, 16, 137, 214, 131, 230, 15, 138, 132, 108, + 5, 180, 14, 205, 16, 94, 90, 89, 91, 31, 157, 195, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 66, 111, 111, 116, + 82, 79, 77, 32, 102, 111, 114, 32, 88, 84, 77, 97, 120, 32, 118, 49, + 46, 48, 13, 10, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 40, 99, + 41, 32, 50, 48, 50, 53, 32, 77, 97, 116, 116, 104, 105, 101, 117, 32, + 66, 117, 99, 99, 104, 105, 97, 110, 101, 114, 105, 13, 10, 0, 79, 108, + 100, 32, 73, 78, 84, 49, 51, 104, 32, 86, 101, 99, 116, 111, 114, 32, + 32, 32, 32, 32, 32, 32, 61, 32, 0, 83, 68, 32, 67, 97, 114, 100, + 32, 105, 110, 105, 116, 105, 97, 108, 105, 122, 101, 100, 32, 115, 117, 99, + 99, 101, 115, 115, 102, 117, 108, 108, 121, 13, 10, 0, 83, 68, 32, 67, + 97, 114, 100, 32, 102, 97, 105, 108, 101, 100, 32, 116, 111, 32, 105, 110, + 105, 116, 105, 97, 108, 105, 122, 101, 13, 10, 0, 70, 105, 120, 101, 100, + 32, 68, 105, 115, 107, 32, 73, 68, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 61, 32, 0, 84, 111, 116, 97, 108, 32, 70, 105, 120, 101, + 100, 32, 68, 105, 115, 107, 32, 68, 114, 105, 118, 101, 115, 32, 61, 32, + 0, 85, 110, 115, 117, 112, 112, 111, 114, 116, 101, 100, 32, 73, 78, 84, + 49, 51, 104, 32, 70, 117, 110, 99, 116, 105, 111, 110, 32, 0, 66, 111, + 111, 116, 105, 110, 103, 32, 102, 114, 111, 109, 32, 83, 68, 32, 67, 97, + 114, 100, 46, 46, 46, 13, 10, 0, 78, 111, 116, 32, 98, 111, 111, 116, + 97, 98, 108, 101, 13, 10, 0, 58, 0, 32, 0, 13, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -127,4 +117,14 @@ unsigned char BOOTROM[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173}; \ No newline at end of file + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35}; \ No newline at end of file diff --git a/XTMax/Drivers/BootROM/bootrom.asm b/XTMax/Drivers/BootROM/bootrom.asm index eadd8e6..86e2de0 100644 --- a/XTMax/Drivers/BootROM/bootrom.asm +++ b/XTMax/Drivers/BootROM/bootrom.asm @@ -16,22 +16,11 @@ cpu 8086 ; ensure we remain compatible with 8086 ; %define XTMAX_IO_BASE (0x280) - -%define FIXED_DISK_0 (0) -%define FIXED_DISK_1 (1) - -; -; Whether we will emulate the 1st or 2nd disk. -; -%define DISK_NUMBER FIXED_DISK_0 - -%if DISK_NUMBER == FIXED_DISK_0 ; ; Whether we are going to rename the BIOS's 1st disk to be the second disk. ; This is useful to allow booting from the second disk. ; ;%define TAKE_OVER_FIXED_DISK_0 -%endif ; ; Whether we will try/force using our own bootstrap code instead of falling back to BASIC. @@ -97,57 +86,6 @@ entry: jc .skip %endif -; -; Detecting 80186-compatible so we can use REP INSW/OUTSW. -; Based on https://cosmodoc.org/topics/processor-detection/ -; -.cpuid: - ; Push a zero value to the stack, then immediately pop that zero - ; value into the FLAGS register. Depending on the CPU, some bits will - ; refuse this change and remain on. - xor ax, ax - push ax - popf - ; Push the current state of FLAGS to the stack, then immediately pop - ; the flag state into AX for further analysis. - pushf - pop ax - ; Consider only flag bits 12..15, and see if they all remained on. - and ax, 0xf000 - cmp ax, 0xf000 - jne .support_string_io ; at least 80286 - ; Perform "FFh >> 33" then check for a zero or nonzero result. - mov al, 0xff - mov cl, 0x21 - shr al, cl - jnz .support_string_io ; at least 80186/80188 - ; Ensure interrupts are enabled, then save SI's value on the stack. - sti - ; Here, ES is pointing to some unspecified place in memory. Below is - ; a busy loop that reads 64 KiB of memory from ES:SI, loading each - ; byte into AL and doing nothing further with it. After each - ; iteration, SI is incremented and CX is decremented. The loop ends - ; when CX reaches zero. Or does it? - mov si, 0 - mov cx, 0xffff - rep lodsb - ; See if the value in CX made it all the way to zero. If it did, the - ; CPU is a V30 or V20. - or cx, cx - cli - jz .support_string_io ; at least V20 -.not_support_string_io: - xor dl, dl - jmp .store_string_io -.support_string_io: - mov dl, 1 - mov ax, string_io_msg - call print_string -.store_string_io: - mov ax, XTMAX_IO_BASE+3 ; scratch register 0 - xchg ax, dx - out dx, al ; save capability - %ifndef AS_COM_PROGRAM ; ; Install our BIOS INT13h hook into the interrupt vector table. @@ -160,31 +98,22 @@ entry: mov es, ax mov ax, es:[0x13*4+2] - mov dx, XTMAX_IO_BASE+4 ; scratch register 1-2 + mov dx, XTMAX_IO_BASE+3 ; scratch register 0-1 out dx, ax ; save segment call print_hex mov ax, colon call print_string mov ax, es:[0x13*4] - mov dx, XTMAX_IO_BASE+6 ; scratch register 3-4 + mov dx, XTMAX_IO_BASE+5 ; scratch register 2-3 out dx, ax ; save offset call print_hex mov ax, newline call print_string - mov ax, new_13h_msg - call print_string - mov ax, ROM_SEGMENT mov es:[0x13*4+2], ax ; store segment - call print_hex - mov ax, colon - call print_string mov ax, int13h_entry mov es:[0x13*4], ax ; store offset - call print_hex - mov ax, newline - call print_string ; ; Move fixed disk 0 to fixed disk 1. @@ -199,19 +128,29 @@ entry: ; For the 2nd disk, it is stored in the interrupt vector table, at vector 46h. ; .install_fixed_disk_parameters_table: - mov ax, new_fdpt_msg + mov ax, disk_id_msg call print_string - - mov ax, ROM_SEGMENT - mov es:[(0x41+DISK_NUMBER*5)*4+2], ax ; store segment - call print_hex - mov ax, colon - call print_string - mov ax, fixed_disk_parameters_table - mov es:[(0x41+DISK_NUMBER*5)*4], ax ; store offset + mov dx, XTMAX_IO_BASE+2 ; fixed disk id + in al, dx + xor ah, ah + push ax call print_hex mov ax, newline call print_string + pop ax + cmp al, 0x80 + jne .second_disk + mov ax, ROM_SEGMENT + mov es:[0x41*4+2], ax ; store segment + mov ax, fixed_disk_parameters_table + mov es:[0x41*4+0], ax ; store offset + jmp .end_fdpt +.second_disk: + mov ax, ROM_SEGMENT + mov es:[0x46*4+2], ax ; store segment + mov ax, fixed_disk_parameters_table + mov es:[0x46*4+0], ax ; store offset +.end_fdpt: %ifdef USE_BOOTSTRAP .update_bda: @@ -219,19 +158,10 @@ entry: ; Install our BIOS INT18h hook into the interrupt vector table. ; .install_18h_vector: - mov ax, new_18h_msg - call print_string - mov ax, ROM_SEGMENT mov es:[0x18*4+2], ax ; store segment - call print_hex - mov ax, colon - call print_string mov ax, int18h_entry mov es:[0x18*4], ax ; store offset - call print_hex - mov ax, newline - call print_string %endif %if !(%isdef(USE_BOOTSTRAP) && %isdef(FORCE_OWN_BOOTSTRAP)) @@ -292,7 +222,13 @@ int13h_entry: %endif push TEMP0 push TEMP1 - cmp dl, 0x80+DISK_NUMBER ; is this our drive? + push ax + push dx + mov dx, XTMAX_IO_BASE+2 ; fixed disk id + in al, dx + pop dx + cmp dl, al ; is this our drive? + pop ax je .check_function ; @@ -317,14 +253,14 @@ int13h_entry: ; Simulate INT 13h with the original vector. ; pushf ; setup for iret below - mov dx, XTMAX_IO_BASE+4 ; scratch register 1-2 + mov dx, XTMAX_IO_BASE+3 ; scratch register 0-1 %ifndef AS_COM_PROGRAM in ax, dx %else mov ax, cs %endif push ax ; setup for iret below - mov dx, XTMAX_IO_BASE+6 ; scratch register 3-4 + mov dx, XTMAX_IO_BASE+5 ; scratch register 2-3 %ifndef AS_COM_PROGRAM in ax, dx %else @@ -546,6 +482,7 @@ func_02_read_sector: jc error_sector_not_found ; TODO: (robustness) check buffer boundaries .setup: + push ds push bx push cx push dx @@ -553,7 +490,11 @@ func_02_read_sector: push ax mov cx, ax ; number of sectors to read xor ch, ch - mov di, bx ; setup use of stosw +%ifndef AS_COM_PROGRAM + mov ax, ROM_SEGMENT + mov ds, ax +%endif + mov di, bx ; setup use of movsw .assert_cs: mov dx, XTMAX_IO_BASE+2 ; chip select port mov al, 0 ; assert chip select @@ -574,7 +515,7 @@ func_02_read_sector: mov ax, wait_msg call print_string %endif - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port mov al, 10 ; 100 ms out dx, al .receive_token: @@ -582,7 +523,7 @@ func_02_read_sector: in al, dx cmp al, 0xfe je .got_token - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port in al, dx test al, al jnz .error @@ -593,22 +534,12 @@ func_02_read_sector: call print_string %endif mov cx, 256 ; block size (in words) - push dx - mov dx, XTMAX_IO_BASE+3 ; scratch register 0 - in al, dx - pop dx - test al, al ; supports insw? + push si + mov si, end_of_rom ; virtual buffer cld - jz .receive_block -.receive_block_fast: -cpu 186 - rep insw -cpu 8086 - jmp .receive_crc .receive_block: - in ax, dx - stosw - loop .receive_block + rep movsw + pop si .receive_crc: in ax, dx ; discard CRC add TEMP_LO, 1 ; next block @@ -626,6 +557,7 @@ cpu 8086 pop dx pop cx pop bx + pop ds jmp succeeded .error: .deassert_cs2: @@ -640,6 +572,7 @@ cpu 8086 pop dx pop cx pop bx + pop ds jmp error_drive_not_ready ; @@ -686,7 +619,11 @@ func_03_write_sector: xor ch, ch mov di, bx ; destination address mov ax, es - mov ds, ax + mov ds, ax ; save es and setup for movsw +%ifndef AS_COM_PROGRAM + mov ax, ROM_SEGMENT + mov es, ax +%endif .assert_cs: mov dx, XTMAX_IO_BASE+2 ; chip select port mov al, 0 ; assert chip select @@ -707,30 +644,19 @@ func_03_write_sector: mov al, 0xfe ; send token out dx, al mov cx, 256 ; block size (in words) - xchg di, si ; save si (aka TEMP1) - push dx - mov dx, XTMAX_IO_BASE+3 ; scratch register 0 - in al, dx - pop dx - test al, al ; supports outsw? + push si ; save si (aka TEMP1) + mov si, di + mov di, end_of_rom ; virtual buffer cld - jz .send_block -.send_block_fast: -cpu 186 - rep outsw -cpu 8086 - jmp .end_send_block .send_block: - lodsw - out dx, ax - loop .send_block -.end_send_block: - xchg si, di ; restore si (aka TEMP1) + rep movsw + mov di, si + pop si ; restore si (aka TEMP1) %ifdef DEBUG_IO mov ax, wait_msg call print_string %endif - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port mov al, 25 ; 250 ms out dx, al .receive_status: @@ -738,7 +664,7 @@ cpu 8086 in al, dx cmp al, 0xff jne .got_status - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port in al, dx test al, al jnz .error @@ -763,7 +689,7 @@ cpu 8086 mov ax, wait_msg call print_string %endif - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port mov al, 25 ; 250 ms out dx, al .receive_finish: @@ -771,7 +697,7 @@ cpu 8086 in al, dx test al, al jnz .got_finish - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port in al, dx test al, al jnz .error @@ -796,6 +722,8 @@ cpu 8086 mov al, 1 ; deassert chip select out dx, al .return1: + mov ax, ds + mov es, ax ; restore es pop ax pop di pop dx @@ -810,6 +738,8 @@ cpu 8086 out dx, al .return2: pop cx ; number of sectors not written successfully + mov ax, ds + mov es, ax ; restore es pop ax sub al, cl ; number of sectors written successfully pop di @@ -971,12 +901,15 @@ int18h_entry: xor ax, ax mov ds, ax mov es, ax -.read_boot_sector: +.clear_memory: mov cx, 256 mov di, 0x7c00 rep stosw +.read_boot_sector: + mov dx, XTMAX_IO_BASE+2 ; fixed disk id + in al, dx + mov dl, al mov ax, 0x201 ; read 1 sector - mov dx, 0x80+DISK_NUMBER mov cx, 1 ; sector 1 mov bx, 0x7c00 int 0x13 @@ -1182,7 +1115,7 @@ init_sd: call send_sd_init_cmd jc .exit .acmd41: - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port mov al, 250 ; 2.5 s out dx, al .retry_acmd41: @@ -1200,7 +1133,7 @@ init_sd: mov ah, 0 ; expect ready state call send_sd_init_cmd jnc .exit - mov dx, XTMAX_IO_BASE+15; timeout port + mov dx, XTMAX_IO_BASE+7 ; timeout port in al, dx test al, al jz .retry_acmd41 @@ -1340,16 +1273,13 @@ debug_handler: welcome_msg db 'BootROM for XTMax v1.0', 0xD, 0xA db 'Copyright (c) 2025 Matthieu Bucchianeri', 0xD, 0xA, 0 -string_io_msg db 'CPU supports INS/OUTS instructions', 0xD, 0xA, 0 -old_13h_msg db 'Old INT13h Vector = ', 0 -new_13h_msg db 'New INT13h Vector = ', 0 -new_fdpt_msg db 'New Fixed Disk Parameter Table = ', 0 +old_13h_msg db 'Old INT13h Vector = ', 0 init_ok_msg db 'SD Card initialized successfully', 0xD, 0xA, 0 init_error_msg db 'SD Card failed to initialize', 0xD, 0xA, 0 +disk_id_msg db 'Fixed Disk ID = ', 0 num_drives_msg db 'Total Fixed Disk Drives = ', 0 unsupported_msg db 'Unsupported INT13h Function ', 0 %ifdef USE_BOOTSTRAP -new_18h_msg db 'New INT18h Vector = ', 0 boot_msg db 'Booting from SD Card...', 0xD, 0xA, 0 no_boot_msg db 'Not bootable', 0xD, 0xA, 0 %endif @@ -1381,3 +1311,8 @@ sd_idle_msg db 'Received idle', 0xD, 0xA, 0 times 2047-($-$$) db 0 db 0 ; will be used to complete the checksum. %endif + +; +; The virtual buffer for I/O follows the ROM immediately. +; +end_of_rom: diff --git a/XTMax/Drivers/BootROM/build.cmd b/XTMax/Drivers/BootROM/build.cmd index f3f4a4e..a4087f1 100644 --- a/XTMax/Drivers/BootROM/build.cmd +++ b/XTMax/Drivers/BootROM/build.cmd @@ -1,2 +1,2 @@ ..\Driver_Build_Tools\NASM\nasm.exe -f bin -o bootrom.com -DAS_COM_PROGRAM .\bootrom.asm -..\Driver_Build_Tools\NASM\nasm.exe -f bin -o bootrom .\bootrom.asm & python checksum.py +..\Driver_Build_Tools\NASM\nasm.exe -f bin -o bootrom .\bootrom.asm & python checksum.py & python generate_header.py diff --git a/XTMax/Drivers/BootROM/checksum.py b/XTMax/Drivers/BootROM/checksum.py index c6e5b13..29c75d7 100644 --- a/XTMax/Drivers/BootROM/checksum.py +++ b/XTMax/Drivers/BootROM/checksum.py @@ -1,23 +1,6 @@ -# https://stackoverflow.com/questions/53808694/how-do-i-format-a-python-list-as-an-initialized-c-array -def to_c_array(values, ctype="float", name="table", formatter=str, colcount=8): - # apply formatting to each element - values = [formatter(v) for v in values] - - # split into rows with up to `colcount` elements per row - rows = [values[i:i+colcount] for i in range(0, len(values), colcount)] - - # separate elements with commas, separate rows with newlines - body = ',\n '.join([', '.join(r) for r in rows]) - - # assemble components into the complete string - return '{} {}[] = {{\n {}}};'.format(ctype, name, body) - with open("bootrom", "rb") as f: b = bytearray(f.read()) # compute the checksum and store a byte to b[-1] = 256 - sum(b[0:-1]) & 0xff with open("bootrom", "wb") as f: f.write(b) -with open("../../Code/XTMax/bootrom.h", "w") as f: - f.write("#define BOOTROM_ADDR 0xCE000\n") - f.write(to_c_array(b, ctype="unsigned char", name="BOOTROM", colcount=16)) diff --git a/XTMax/Drivers/BootROM/generate_header.py b/XTMax/Drivers/BootROM/generate_header.py new file mode 100644 index 0000000..b2ed057 --- /dev/null +++ b/XTMax/Drivers/BootROM/generate_header.py @@ -0,0 +1,27 @@ +segment = None +with open("bootrom.asm", "r") as f: + for line in f: + if line.startswith('%define ROM_SEGMENT'): + segment = int(line[19:].strip('() \n'), 16) + break + +with open("bootrom", "rb") as f: + bitstream = bytearray(f.read()) + +# https://stackoverflow.com/questions/53808694/how-do-i-format-a-python-list-as-an-initialized-c-array +def to_c_array(values, ctype="float", name="table", formatter=str, colcount=8): + # apply formatting to each element + values = [formatter(v) for v in values] + + # split into rows with up to `colcount` elements per row + rows = [values[i:i+colcount] for i in range(0, len(values), colcount)] + + # separate elements with commas, separate rows with newlines + body = ',\n '.join([', '.join(r) for r in rows]) + + # assemble components into the complete string + return '{} {}[] = {{\n {}}};'.format(ctype, name, body) + +with open("../../Code/XTMax/bootrom.h", "w") as f: + f.write("#define BOOTROM_ADDR {}\n".format(hex(segment << 4))) + f.write(to_c_array(bitstream, ctype="unsigned char", name="BOOTROM", colcount=16))