Skip to content

Finding The SmartPort Dispatcher

Norman Davie edited this page Feb 19, 2023 · 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;
}

6502 Assembly Example

;*****************************************************
; SMART PORT DETECT
; Search for the fujinet device
; By Norman Davie
;
; VERSION: 0.01
;

        .ORG $2000

        .include "APPLEEQU.S"

SRC_ADDR		=	$ED
SRC_ADDR_LO	        =	$ED
SRC_ADDR_HI		=	$EE

FIND_SMARTPORT_SLOT:

        LDA     #$C7            ; START AT SLOT 7 ($C700)
        STA     SRC_ADDR_HI
        LDA     #$00
        STA     SRC_ADDR_LO

SCAN:
        LDY #$00
        LDX #$00

        LDA (SRC_ADDR),Y        ; COMPARE TO THE MAGIC NUMBERS
        CMP FIJINET_ID,X
        BNE NEXT_SLOT           ; NOT THE SAME, SO GO TO NEXT SLOT

        INY                     ; PREPARE TO CHECK THE NEXT NUMBER
        INY
        INX                     ; POINTER TO NEXT NUMBER TO CHECK
        CPX #$04                ; HAVE WE COMPARED ALL 4 NUMBERS?
        BEQ FOUND               ; YES, WE'VE FOUND IT

NEXT_SLOT:
        LDX SRC_ADDR_HI         ; MOVE TO THE NEXT LOWER SLOT
        DEX                     ; $C700 -> $C600
        STX SRC_ADDR_HI
        CPX #$C0                ; HAVE WE GONE BELOW SLOT 0?
        BMI NOT_FOUND           ; WE'RE DONE
        BPL SCAN                ; CONTINUE SCANNING
FOUND:
        LDA SRC_ADDR_HI
        RTS                     ; WE FOUND IT! A = SLOT ADDRESS

NOT_FOUND:
        LDA #$FF                ; WE DIDN'T FIND IT
        RTS



FIJINET_ID:     .BYTE $20, $00, $03, $00 

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