@@ -99,10 +99,10 @@ void SmartPortOverSlip::handle_smartport_call()
9999 WORD rts_location = static_cast <WORD>(mem[regs.sp + 1 ]) + static_cast <WORD>(mem[regs.sp + 2 ] << 8 );
100100 const BYTE command = mem[rts_location + 1 ];
101101 const WORD cmd_list_loc = mem[rts_location + 2 ] + (mem[rts_location + 3 ] << 8 );
102- // BYTE paramCount = mem[cmdListLoc]; // parameter count not used
102+ const BYTE param_count = mem[cmd_list_loc];
103103 const BYTE unit_number = mem[cmd_list_loc + 1 ];
104104 const WORD sp_payload_loc = static_cast <WORD>(mem[cmd_list_loc + 2 ]) + static_cast <WORD>(mem[cmd_list_loc + 3 ] << 8 );
105- const WORD params_loc = cmd_list_loc + 4 ;
105+ const WORD params_loc = cmd_list_loc + 2 ; // we are ONLY skipping the count and destination bytes (used to skip the payload bytes, but that's only certain commands)
106106
107107 // LogFileOutput("SmartPortOverSlip processing SP command: 0x%02x, unit: "
108108 // "0x%02x, cmdList: 0x%04x, spPayLoad: 0x%04x, p1: 0x%02x\n",
@@ -119,8 +119,8 @@ void SmartPortOverSlip::handle_smartport_call()
119119 memdirty[dirty_page_end] = 0xFF ;
120120
121121
122- // Deal with unit 0, status 0 call to return device count, doesn't need connection details.
123- if (unit_number == 0 && mem[params_loc] == 0 )
122+ // Deal with status call (command == 0) with params unit == 0, status_code == 0 to return device count, doesn't need connection details.
123+ if (command == 0 && unit_number == 0 && mem[params_loc + 2 ] == 0 )
124124 {
125125 device_count (sp_payload_loc);
126126 return ;
@@ -142,19 +142,22 @@ void SmartPortOverSlip::handle_smartport_call()
142142 switch (command)
143143 {
144144 case CMD_STATUS:
145- status_sp (device_id, connection, sp_payload_loc, mem[ params_loc]);
145+ status_sp (device_id, connection, sp_payload_loc, param_count, params_loc); // we are including the payload params and count part now too
146146 break ;
147147 case CMD_READ_BLOCK:
148- read_block (device_id, connection, sp_payload_loc, params_loc);
148+ // TODO: fix the fact params_loc has changed from +4 to +2
149+ read_block (device_id, connection, sp_payload_loc, params_loc + 2 );
149150 break ;
150151 case CMD_WRITE_BLOCK:
151- write_block (device_id, connection, sp_payload_loc, params_loc);
152+ // TODO: fix the fact params_loc has changed from +4 to +2
153+ write_block (device_id, connection, sp_payload_loc, params_loc + 2 );
152154 break ;
153155 case CMD_FORMAT:
154156 format (device_id, connection);
155157 break ;
156158 case CMD_CONTROL:
157- control (device_id, connection, sp_payload_loc, mem[params_loc]);
159+ // TODO: fix the fact params_loc has changed from +4 to +2
160+ control (device_id, connection, sp_payload_loc, param_count, params_loc);
158161 break ;
159162 case CMD_INIT:
160163 init (device_id, connection);
@@ -166,10 +169,12 @@ void SmartPortOverSlip::handle_smartport_call()
166169 close (device_id, connection);
167170 break ;
168171 case CMD_READ:
169- read (device_id, connection, sp_payload_loc, params_loc);
172+ // TODO: fix the fact params_loc has changed from +4 to +2
173+ read (device_id, connection, sp_payload_loc, params_loc + 2 );
170174 break ;
171175 case CMD_WRITE:
172- write (device_id, connection, sp_payload_loc, params_loc);
176+ // TODO: fix the fact params_loc has changed from +4 to +2
177+ write (device_id, connection, sp_payload_loc, params_loc + 2 );
173178 break ;
174179 case CMD_RESET:
175180 reset (device_id, connection);
@@ -480,9 +485,11 @@ void SmartPortOverSlip::write(const BYTE unit_number, Connection *connection, co
480485 handle_simple_response<WriteResponse>(std::move (response));
481486}
482487
483- void SmartPortOverSlip::status_sp (const BYTE unit_number, Connection *connection, const WORD sp_payload_loc, const BYTE status_code )
488+ void SmartPortOverSlip::status_sp (const BYTE unit_number, Connection *connection, const WORD sp_payload_loc, const BYTE params_count, const WORD params_loc )
484489{
485- auto response = status (unit_number, connection, status_code);
490+ const BYTE status_code = mem[params_loc + 2 ];
491+ const BYTE network_unit = params_count > 3 ? mem[params_loc + 3 ] : 0 ;
492+ auto response = status (unit_number, connection, status_code, network_unit);
486493 handle_response<StatusResponse>(std::move (response), [sp_payload_loc](const StatusResponse *sr) {
487494 const auto response_size = sr->get_data ().size ();
488495 memcpy (mem + sp_payload_loc, sr->get_data ().data (), response_size);
@@ -499,16 +506,16 @@ void SmartPortOverSlip::status_sp(const BYTE unit_number, Connection *connection
499506 });
500507}
501508
502- std::unique_ptr<Response> SmartPortOverSlip::status (const BYTE unit_number, Connection *connection, const BYTE status_code)
509+ std::unique_ptr<Response> SmartPortOverSlip::status (const BYTE unit_number, Connection *connection, const BYTE status_code, const BYTE network_unit )
503510{
504511 // see https://www.1000bit.it/support/manuali/apple/technotes/smpt/tn.smpt.2.html
505- const StatusRequest request (Requestor::next_request_number (), unit_number, status_code);
512+ const StatusRequest request (Requestor::next_request_number (), unit_number, status_code, network_unit );
506513 return Requestor::send_request (request, connection);
507514}
508515
509516std::unique_ptr<StatusResponse> SmartPortOverSlip::status_pd (const BYTE unit_number, Connection *connection, const BYTE status_code)
510517{
511- auto response = status (unit_number, connection, status_code);
518+ auto response = status (unit_number, connection, status_code, 0 );
512519
513520 // Cast the Response to a StatusResponse. We need to release ownership. As ChatGPT explains:
514521 /*
@@ -519,13 +526,15 @@ std::unique_ptr<StatusResponse> SmartPortOverSlip::status_pd(const BYTE unit_num
519526 return std::unique_ptr<StatusResponse>(static_cast <StatusResponse *>(response.release ()));
520527}
521528
522- void SmartPortOverSlip::control (const BYTE unit_number, Connection *connection, const WORD sp_payload_loc, const BYTE control_code )
529+ void SmartPortOverSlip::control (const BYTE unit_number, Connection *connection, const WORD sp_payload_loc, const BYTE params_count, const WORD params_loc )
523530{
531+ const BYTE control_code = mem[params_loc + 2 ]; // skip the payload location bytes
532+ const BYTE network_unit = params_count > 3 ? mem[params_loc + 3 ] : 0 ;
524533 const auto length = mem[sp_payload_loc] + (mem[sp_payload_loc + 1 ] << 8 ) + 2 ;
525534 uint8_t *start_ptr = &mem[sp_payload_loc];
526535 std::vector<uint8_t > payload (start_ptr, start_ptr + length);
527536
528- const ControlRequest request (Requestor::next_request_number (), unit_number, control_code, payload);
537+ const ControlRequest request (Requestor::next_request_number (), unit_number, control_code, network_unit, payload);
529538 auto response = Requestor::send_request (request, connection);
530539 handle_simple_response<ControlResponse>(std::move (response));
531540}
0 commit comments