Skip to content

Finding The SmartPort Dispatcher

Thomas Cherryhomes edited this page Dec 26, 2022 · 6 revisions

Before using the SmartPort, you have to find it. More specifically, you have to find the dispatcher.

Finding the Slot

The first part, finding the slot, is accomplished by scanning the I/O space for each slot ($C000, $C100, ...), for the following four bytes at offsets 1, 3, 5, and 7:

Offset Byte
1 $20
3 $00
5 $03
7 $00

C implementation

/**
 * Check for SmartPort presence
 * @return slot #, or 0xFF if not present.
 */
uint8_t sp_find_slot(void)
{
  uint8_t s=0;

  for (s=7; s-- > 0;)
    {
      uint16_t a = 0xc000 + (s * 0x100);
      if ((PEEK(a+1) == 0x20) &&
          (PEEK(a+3) == 0x00) &&
          (PEEK(a+5) == 0x03) &&
          (PEEK(a+7) == 0x00))
        return s;
    }

  // Did not find.
  return 0;
}

Finding the dispatch address

Once the slot has been found, the dispatcher address can be found by reading offset $FF at the found slot, then taking the value found, adding 3 to it, and adding that to the slot address.

C implementation

/**
 * Return dispatch address for Smartport slot.
 * @param s Slot # (1-7)
 * @return smartport dispatch address
 */
uint16_t sp_dispatch_address(uint8_t slot)
{
  uint16_t a = (slot * 0x100) + 0xC000;
  uint8_t j = PEEK(a+0xFF);

  return a + j + 3;
}

Once this is found, you can start Issuing SmartPort Commands.

Clone this wiki locally