I had a design which was going to incorporate a
FastIO port, specifically the 4-bit option (Thanks Garth & Jeff) which I wrote some macros for the WDC assembler to support it. I have now decided to scrap it from my design, but I wanted to record the macros somewhere for posterity as they might be useful to others. You could quite easily adapt these macros to work with the 8-bit version, too.
Code:
; @region FastIoMacros
; Macros for manipulating the FastIO port
;
; EXAMPLE - How to use RFIO and V2F
; RFIO 2 ; Read bit 2 from FIO into V
; V2C ; Copy V flag to C flag
; ROR A ; Shift C into the MSb of A
; or
; ROL A ; Shift C into the LSb of A
;
; EXAMPLE - How to use WFIO
; ROR A ; Shift the LSb out of A into C
; WFIO 1 ; Write C to bit 1 of the FIO
; or
; WFIO 2, TRUE ; Write a '1' to bit 2 of the FIO
; Read FastIO
; Read the given mBit from the FastIO port into the V flag.
RFIO MACRO mBit
IF mBit>3 ; Check that mBit is valid
EXIT RFIO first parameter invalid
ENDIF
CLV ; V has to be cleared as the ~SO pin can only set V.
; Special opcode decoded by external hardware. Causes the FIO to use ~SO pin
; to set the V flag if the relevant FIO input bit is high.
db $03|(mBit<<5)
ENDM
; Copy the V flag into the C flag
V2C MACRO
BVS ?vset# ; Jump if V=1
CLC ; V=0 therefore set C=0
BRA ?vend# ; Jump to end of macro
?vset#
SEC ; V=1 therefore set C=1
?vend#
ENDM
; Write FastIO
; If mValue is provided, writes the literal value to mBit in the FastIO port.
; if mValue is not provided, the current value of the C flag is used instead.
WFIO MACRO mBit, mValue
IF mBit>3 ; Check that mBit is valid
EXIT WFIO first parameter invalid
ENDIF
IFMA 2 ; If mValue is present, use that
IF mValue>1 ; Check that mValue is valid (0 or 1)
EXIT WFIO second parameter invalid
ENDIF
; Special opcode decoded by external hardware.
; Writes bit 4 of the opcode to the relevant FIO output port
db $0B|(mBit<<5)|(mValue<<4)
ELSE ; mValue is not present, so use C instead
BCS ?cset# ; Jump if C=1
; Special opcode decoded by external hardware.
; Writes a zero to the relevant FIO output port
db $0B|(mBit<<5)
BRA ?cend#
?cset#
; Special opcode decoded by external hardware.
; Writes a one to the relevant FIO output port
db $1B|(mBit<<5)
?cend#
ENDIF
ENDM
; @end
_________________
Want to design a PCB for your project? I strongly recommend
KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of
Retro Computing and
Arduino components you might find useful.