Serial Port Status Program
Posted: Mon Mar 13, 2023 8:44 pm
To test the USB adapters I have recently made, and verify that the design is correct with respect to the handshaking lines, I wrote this little utility. As the handshaking lines can't be manipulated in OPL, it's written in assembly language. I assembled it with my macro assembler and used the output that embeds it into OPL.
Assembly source code:
The OPL that is generated is here, it is stand-alone:
When run, there's a sign on screen, press any key to get to the status display. You can set the CTS level and see the incoming RTS. DTR isn't displayed as it isn't passed through by the hardware, instead it turns the organiser on when asserted.
To assemble the source you will need the include files which are in the assembler repo, then use this line to assemble the code:
<path to assembler>/psion-org2-assembler/org2asm.tcl -f statser.asm
The OPL output I used was the file with an 'opl_3' extension.
Macro assembler:
https://github.com/blackjetrock/psion-org2-assembler
Just need to test the USB adapters now.
Andrew
Assembly source code:
Code: Select all
.INCLUDE MSWI.INC
.INCLUDE MOSHEAD.INC
.INCLUDE MOSVARS.INC
.INCLUDE COMMS.INC
cts .equ 1
ncts .equ 254
dsr .equ 2
rts .equ 4
;; --------------------------------------------------
;; Sign on
;;
;; --------------------------------------------------
bsr 1$
.ascic "Serial Status"
1$: pulx
ldab 0,x
inx
os dp$prnt
os kb$getk
;; --------------------------------------------------
;; Check for comms link. If present then proceed
;; otherwise just exit
;;
;; --------------------------------------------------
bsr check_present
bcs not_present
bra is_present
check_present:
bsr 1$ ; PC relative
.ascic "XFEOF" ; leading count byte string
1$: pulx ; PC = address of "XFEOF"
;os dv$lkup ; if XFEOF not there, no COMMS LINK
rts ; see tech. ref. manual
;; --------------------------------------------------------------------------------
;;
;; Not present so display a message
;;
not_present:
bsr 1$
.ascic "No Comms Link"
1$: pulx
ldab 0,x
inx
os dp$prnt
os kb$getk
rts
;; --------------------------------------------------------------------------------
;; Comms Link present so sit in loop
;; If X pressed then exit
;; C toggles CTS
;; Status of other lines displayed
is_present:
clrb ; Open for reading and writing
RS rs_open
bcs error ; Deal with error
; Now free to access the port
bra statloop
error:
rts
statloop:
;; Stop kb$test from turning packs off, that would stop us getting
;; access to the port hardware.
ldaa #0
staa kbb_pkof
;; Check the keyboard
os kb$test
cmpb #0
beq nokey
;; Key pressed, but kb$test has put it in the unget buffer
;; where it will get stuck. Use kb$getk to actually get the key
os kb$getk
;; Key pressed, handle it
cmpb #^A'X'
beq doexit
;; CTS control
cmpb #^A'S'
beq cts0
cmpb #^A'T'
beq cts1
nokey:
;; Display status
;; of serial port handshake lines
ldaa #0 ;Cursor to top left
ldab #0
os dp$stat
ldaa #14
os dp$emit
bsr 1$
.ascic "RTS="
1$: pulx
ldab 0,x
inx
os dp$prnt
;; Get RTS state
ldaa POB_PORT2
anda #4
asra
asra
adda #^A'0'
os dp$emit
bsr 2$
.ascic " CTS="
2$: pulx
ldab 0,x
inx
os dp$prnt
;; Get CTS state
ldab #0
bsr ctsvar
adda #^A'0'
os dp$emit
ldaa #^A' '
os dp$emit
ldaa #10
os dp$emit
ldaa #13
os dp$emit
bsr 3$
.ascic "CTS:S,T Exit:X"
3$: pulx
ldab 0,x
inx
os dp$prnt
;; Loop back
bra statloop
;; --------------------------------------------------------------------------------
;;
doexit:
;; Now close the comms link
ldab #0
RS rs_close
;; Allow packs to be turned off again by kb$test
ldaa #255
staa kbb_pkof
rts
;; --------------------------------------------------------------------------------
;; Set CTS to zero
;;
cts0:
aim #ncts, POB_PORT2
ldaa #0
ldab #1
bsr ctsvar
bra nokey
;; Set CTS to 1
cts1:
oim #cts, POB_PORT2
ldaa #1
ldab #1
bsr ctsvar
bra nokey
;; --------------------------------------------------------------------------------
;;
;; We have to use a position independent varaible to hold the
;; CTS state as we cn't read the state of the output
ctsvar:
bsr 4$
.byte 0
4$: pulx
;; Set or read the var?
cmpb #0
beq readvar
;; Write variable
staa 0,x
rts
readvar:
ldaa 0,x
rts
;; --------------------------------------------------------------------------------
Code: Select all
statser:
LOCAL MC$(240)
MC$=CHR$($8d)
MC$=MC$+CHR$($0e)
MC$=MC$+CHR$($0d)
MC$=MC$+CHR$($53)
MC$=MC$+CHR$($65)
MC$=MC$+CHR$($72)
MC$=MC$+CHR$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MC$+CHR$($00)
MC$=MC$+CHR$($25)
MC$=MC$+CHR$($02)
MC$=MC$+CHR$($20)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($39)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($b7)
MC$=MC$+CHR$($20)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($3f)
MC$=MC$+CHR$($4b)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($27)
MC$=MC$+CHR$($0e)
MC$=MC$+CHR$($3f)
MC$=MC$+CHR$($48)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($58)
MC$=MC$+CHR$($27)
MC$=MC$+CHR$($64)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($53)
MC$=MC$+CHR$($27)
MC$=MC$+CHR$($6c)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($54)
MC$=MC$+CHR$($27)
MC$=MC$+CHR$($73)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($c6)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($3f)
MC$=MC$+CHR$($14)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($0e)
MC$=MC$+CHR$($3f)
MC$=MC$+CHR$($10)
MC$=MC$+CHR$($8d)
MC$=MC$+CHR$($05)
MC$=MC$+CHR$($04)
MC$=MC$+CHR$($52)
MC$=MC$+CHR$($54)
MC$=MC$+CHR$($53)
MC$=MC$+CHR$($3d)
MC$=MC$+CHR$($38)
MC$=MC$+CHR$($e6)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($08)
MC$=MC$+CHR$($3f)
MC$=MC$+CHR$($11)
MC$=MC$+CHR$($96)
MC$=MC$+CHR$($03)
MC$=MC$+CHR$($84)
MC$=MC$+CHR$($04)
MC$=MC$+CHR$($47)
MC$=MC$+CHR$($47)
MC$=MC$+CHR$($8b)
MC$=MC$+CHR$($30)
MC$=MC$+CHR$($3f)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+CHR$($bd)
MC$=MC$+CHR$($21)
MC$=MC$+CHR$($74)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($ff)
MC$=MC$+CHR$($b7)
MC$=MC$+CHR$($20)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($39)
MC$=MC$+CHR$($71)
MC$=MC$+CHR$($fe)
MC$=MC$+CHR$($03)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($c6)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($8d)
MC$=MC$+CHR$($0d)
MC$=MC$+CHR$($20)
MC$=MC$+CHR$($8d)
MC$=MC$+CHR$($72)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($03)
MC$=MC$+CHR$($86)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($c6)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($8d)
MC$=MC$+CHR$($02)
MC$=MC$+CHR$($20)
MC$=MC$+CHR$($82)
MC$=MC$+CHR$($8d)
MC$=MC$+CHR$($01)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($38)
MC$=MC$+CHR$($c1)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($27)
MC$=MC$+CHR$($03)
MC$=MC$+CHR$($a7)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($39)
MC$=MC$+CHR$($a6)
MC$=MC$+CHR$($00)
MC$=MC$+CHR$($39)
RETURN USR(ADDR(MC$)+1,0)
To assemble the source you will need the include files which are in the assembler repo, then use this line to assemble the code:
<path to assembler>/psion-org2-assembler/org2asm.tcl -f statser.asm
The OPL output I used was the file with an 'opl_3' extension.
Macro assembler:
https://github.com/blackjetrock/psion-org2-assembler
Just need to test the USB adapters now.
Andrew