From e05379a6626e6d14f1145d2b3ab5bc55064e2d8d Mon Sep 17 00:00:00 2001 From: Chris Osborn Date: Thu, 22 Aug 2024 10:40:53 -0700 Subject: [PATCH] Define more SmartPort command constants. --- lib/bus/iwm/iwm.cpp | 38 +++++++++++++++----------------------- lib/bus/iwm/iwm.h | 29 ++++++++++++++++++++--------- lib/bus/iwm/iwm_ll.cpp | 10 ++++------ lib/bus/mac/mac.cpp | 20 ++++++++------------ 4 files changed, 47 insertions(+), 50 deletions(-) diff --git a/lib/bus/iwm/iwm.cpp b/lib/bus/iwm/iwm.cpp index ae580ecbc..f23681307 100644 --- a/lib/bus/iwm/iwm.cpp +++ b/lib/bus/iwm/iwm.cpp @@ -257,16 +257,12 @@ void iwmDevice::iwm_return_badcmd(iwm_decoded_cmd_t cmd) //Handle possible data packet to avoid crash extended and non-extended switch(cmd.command) { - case 0x42: - case 0x44: - case 0x49: - case 0x4a: - case 0x4b: - case 0x02: - case 0x04: - case 0x09: - case 0x0a: - case 0x0b: + case SP_ECMD_WRITEBLOCK: + case SP_ECMD_CONTROL: + case SP_ECMD_WRITE: + case SP_CMD_WRITEBLOCK: + case SP_CMD_CONTROL: + case SP_CMD_WRITE: data_len = 512; IWM.iwm_decode_data_packet((uint8_t *)data_buffer, data_len); Debug_printf("\r\nUnit %02x Bad Command with data packet %02x\r\n", id(), cmd.command); @@ -278,7 +274,7 @@ void iwmDevice::iwm_return_badcmd(iwm_decoded_cmd_t cmd) return; } - if(cmd.command == 0x04) //Decode command control code + if(cmd.command == SP_CMD_CONTROL) //Decode command control code { send_reply_packet(SP_ERR_BADCTL); //we may be required to accept some control commands // but for now just report bad control if it's a control @@ -297,16 +293,12 @@ void iwmDevice::iwm_return_device_offline(iwm_decoded_cmd_t cmd) //Handle possible data packet to avoid crash extended and non-extended switch(cmd.command) { - case 0x42: - case 0x44: - case 0x49: - case 0x4a: - case 0x4b: - case 0x02: - case 0x04: - case 0x09: - case 0x0a: - case 0x0b: + case SP_ECMD_WRITEBLOCK: + case SP_ECMD_CONTROL: + case SP_ECMD_WRITE: + case SP_CMD_WRITEBLOCK: + case SP_CMD_CONTROL: + case SP_CMD_WRITE: data_len = 512; IWM.iwm_decode_data_packet((uint8_t *)data_buffer, data_len); Debug_printf("\r\nUnit %02x Offline, Command with data packet %02x\r\n", id(), cmd.command); @@ -318,7 +310,7 @@ void iwmDevice::iwm_return_device_offline(iwm_decoded_cmd_t cmd) return; } - if(cmd.command == 0x04) //Decode command control code + if(cmd.command == SP_CMD_CONTROL) //Decode command control code { send_reply_packet(SP_ERR_OFFLINE); uint8_t control_code = get_status_code(cmd); @@ -345,7 +337,7 @@ void iwmDevice::iwm_status(iwm_decoded_cmd_t cmd) // override; { uint8_t status_code = cmd.params[2]; - if (status_code == 0x03) + if (status_code == SP_CMD_FORMAT) { Debug_printf("\r\nSending DIB Status for device 0x%02x", id()); send_status_dib_reply_packet(); diff --git a/lib/bus/iwm/iwm.h b/lib/bus/iwm/iwm.h index 97ff9771f..328631500 100644 --- a/lib/bus/iwm/iwm.h +++ b/lib/bus/iwm/iwm.h @@ -22,15 +22,26 @@ #include "fnFS.h" enum { - SP_CMD_STATUS = 0x00, - SP_CMD_READBLOCK = 0x01, - SP_CMD_WRITEBLOCK = 0x02, - SP_CMD_FORMAT = 0x03, - SP_CMD_CONTROL = 0x04, - SP_CMD_OPEN = 0x06, - SP_CMD_CLOSE = 0x07, - SP_CMD_READ = 0x08, - SP_CMD_WRITE = 0x09, + SP_CMD_STATUS = 0x00, + SP_CMD_READBLOCK = 0x01, + SP_CMD_WRITEBLOCK = 0x02, + SP_CMD_FORMAT = 0x03, + SP_CMD_CONTROL = 0x04, + SP_CMD_INIT = 0x05, + SP_CMD_OPEN = 0x06, + SP_CMD_CLOSE = 0x07, + SP_CMD_READ = 0x08, + SP_CMD_WRITE = 0x09, + SP_ECMD_STATUS = 0x40, + SP_ECMD_READBLOCK = 0x41, + SP_ECMD_WRITEBLOCK = 0x42, + SP_ECMD_FORMAT = 0x43, + SP_ECMD_CONTROL = 0x44, + SP_ECMD_INIT = 0x45, + SP_ECMD_OPEN = 0x46, + SP_ECMD_CLOSE = 0x47, + SP_ECMD_READ = 0x48, + SP_ECMD_WRITE = 0x49, }; // see page 81-82 in Apple IIc ROM reference and Table 7-5 in IIgs firmware ref diff --git a/lib/bus/iwm/iwm_ll.cpp b/lib/bus/iwm/iwm_ll.cpp index baf7d6d27..ff21b95cd 100644 --- a/lib/bus/iwm/iwm_ll.cpp +++ b/lib/bus/iwm/iwm_ll.cpp @@ -58,7 +58,7 @@ void IRAM_ATTR phi_isr_handler(void *arg) c = IWM.command_packet.command & 0x0f; if (!error) // packet received ok and checksum good { - if (c == 0x05) + if (c == SP_CMD_INIT) { smartport.iwm_ack_clr(); sp_command_mode = sp_cmd_state_t::command; @@ -73,11 +73,9 @@ void IRAM_ATTR phi_isr_handler(void *arg) // look for CTRL command // Debug_printf("\nhello from ISR - looking for control command!"); - if ((c == 0x02) || - (c == 0x04) || - (c == 0x09) || - (c == 0x0a) || - (c == 0x0b)) + if ((c == SP_CMD_WRITEBLOCK) || + (c == SP_CMD_CONTROL) || + (c == SP_CMD_WRITE)) { // Debug_printf("\nhello from ISR - control command!"); if (smartport.req_wait_for_falling_timeout(5500)) diff --git a/lib/bus/mac/mac.cpp b/lib/bus/mac/mac.cpp index 87232a4b8..9a6e324a8 100644 --- a/lib/bus/mac/mac.cpp +++ b/lib/bus/mac/mac.cpp @@ -528,16 +528,12 @@ void iwmDevice::iwm_return_badcmd(iwm_decoded_cmd_t cmd) // Handle possible data packet to avoid crash extended and non-extended switch (cmd.command) { - case 0x42: - case 0x44: - case 0x49: - case 0x4a: - case 0x4b: - case 0x02: - case 0x04: - case 0x09: - case 0x0a: - case 0x0b: + case SP_ECMD_WRITEBLOCK: + case SP_ECMD_CONTROL: + case SP_ECMD_WRITE: + case SP_CMD_WRITEBLOCK: + case SP_CMD_CONTROL: + case SP_CMD_WRITE: data_len = 512; IWM.iwm_decode_data_packet((uint8_t *)data_buffer, data_len); Debug_printf("\r\nUnit %02x Bad Command with data packet %02x\r\n", id(), cmd.command); @@ -548,7 +544,7 @@ void iwmDevice::iwm_return_badcmd(iwm_decoded_cmd_t cmd) Debug_printf("\r\nUnit %02x Bad Command %02x", id(), cmd.command); return; } - if (cmd.command == 0x04) // Decode command control code + if (cmd.command == SP_CMD_CONTROL) // Decode command control code { send_reply_packet(SP_ERR_BADCTL); // we may be required to accept some control commands // but for now just report bad control if it's a control @@ -578,7 +574,7 @@ void iwmDevice::iwm_status(iwm_decoded_cmd_t cmd) // override; uint8_t status_code = cmd.params[2]; // cmd.g7byte3 & 0x7f; // (packet_buffer[19] & 0x7f); // | (((unsigned short)packet_buffer[16] << 3) & 0x80); Debug_printf("\r\nTarget Device: %02x", id()); // add a switch case statement for ALL THE STATUSESESESESS - if (status_code == 0x03) + if (status_code == SP_CMD_FORMAT) { // if statcode=3, then status with device info block Debug_printf("\r\n******** Sending DIB! ********"); send_status_dib_reply_packet();