6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Jul 02, 2024 1:20 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: FastIO Macros
PostPosted: Tue Feb 06, 2018 10:08 am 
Offline
User avatar

Joined: Tue Oct 25, 2016 8:56 pm
Posts: 360
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: FastIO Macros
PostPosted: Tue Feb 06, 2018 12:58 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
The V2C macro can be made simpler and faster
Code:
V2C         MACRO
    SEC                     ; Assume V=1 therefore set C=1
    BVS     ?vset#          ; Jump if V=1
    CLC                     ; Otherwise V=0 therefore set C=0
?vend#
  ENDM

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: FastIO Macros
PostPosted: Tue Feb 06, 2018 1:11 pm 
Offline
User avatar

Joined: Tue Oct 25, 2016 8:56 pm
Posts: 360
You're right! Though I think you've got your labels a little mixed up there...

_________________
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: