Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions lib/bus/iwm/iwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down
29 changes: 20 additions & 9 deletions lib/bus/iwm/iwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lib/bus/iwm/iwm_ll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
20 changes: 8 additions & 12 deletions lib/bus/mac/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down