1 ; con speed of TERMINAL link, there are three bottlenecks :
2 ; 1- time to send XOFF/RTS_high on CR (CR+LF=EOL), first emergency.
3 ; 2- the char loop time,
4 ; 3- the time between sending XON/RTS_low and clearing UCRXIFG on first received char,
5 ; everything must be done to reduce these times, taking into account the necessity of switching to SLEEP (LPMx mode).
6 ; --------------------------------------;
7 ; (ACCEPT) part I: prepare TERMINAL_INT ;
8 ; --------------------------------------;
10 .word 1537h ;6 push R7,R6,R5,R4
12 MOV #ENDACCEPT,S ;2 S = ACCEPT XOFF return
13 MOV #AKEYREAD1,T ;2 T = default XON return
14 .word 152Dh ;5 PUSHM IP,S,T, as IP ret, XOFF ret, XON ret
15 MOV TOS,W ;1 -- addr len
16 MOV @PSP,TOS ;2 -- org ptr )
17 ADD TOS,W ;1 -- org ptr W=Bound )
18 MOV #0Dh,T ;2 T = 'CR' to speed up char loop in part II > prepare stack and registers
19 MOV #20h,S ;2 S = 'BL' to speed up char loop in part II ) for TERMINAL_INT use
20 BIT #UCRXIFG,&TERMIFG ;3 RX_Int ?
21 JZ ACCEPTNEXT ;2 no : case of quiet input terminal
22 MOV &TERMRXBUF,Y ;3 yes: clear RX_Int
23 CMP #0Ah,Y ;2 received char = LF ? (end of downloading ?)
24 JNZ RXON ;2 no : RXON return = AKEYREAD1, to process first char of new line.
25 ACCEPTNEXT ADD #2,RSP ;1 yes: remove AKEYREAD1 as XON return,
26 MOV #SLEEP,X ;2 and set XON return = SLEEP
27 .word 153Ch ;6 PUSHM S,T,W,X before SLEEP (and so WAKE on any interrupts)
28 ; --------------------------------------;
30 ; --------------------------------------;
31 .IFDEF TERMINAL3WIRES ;
32 RXON_LOOP BIT #UCTXIFG,&TERMIFG ;3 wait the sending end of XON, useless at high baudrates
34 MOV #17,&TERMTXBUF ;4 move char XON into TX_buf
36 .IFDEF TERMINAL4WIRES ;
37 BIC.B #RTS,&HANDSHAKOUT ;4 set RTS low
39 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
40 ; starts first and 3th stopwatches ;
41 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
42 RET ;4 to SLEEP (End of file download or quiet input) or AKEYREAD1 (get next line of file downloading)
43 ; --------------------------------------;
45 ; --------------------------------------;
47 ; --------------------------------------;
48 .IFDEF TERMINAL3WIRES ;
49 RXOFF_LOOP BIT #UCTXIFG,&TERMIFG ;3 wait the sending end of XOFF, useless at high baudrates
51 MOV #19,&TERMTXBUF ;4 move XOFF char into TX_buf
53 .IFDEF TERMINAL4WIRES ;
54 BIS.B #RTS,&HANDSHAKOUT ;4 set RTS high
57 ; --------------------------------------;
59 ; --------------------------------------;
60 ASMWORD "SLEEP" ; may be redirected
63 ; --------------------------------------;
65 ; --------------------------------------;
68 BIS &LPM_MODE,SR ;3 enter in LPMx sleep mode with GIE=1
69 ; --------------------------------------; default FAST FORTH mode (for its input terminal use) : LPM0.
71 ;###############################################################################################################
72 ;###############################################################################################################
74 ; ### # # ####### ####### ###### ###### # # ###### ####### ##### # # ####### ###### #######
75 ; # ## # # # # # # # # # # # # # # # # # # # #
76 ; # # # # # # # # # # # # # # # # # # # # # #
77 ; # # # # # ##### ###### ###### # # ###### # ##### ####### ##### ###### #####
78 ; # # # # # # # # # # # # # # # # # # # # #
79 ; # # ## # # # # # # # # # # # # # # # # # #
80 ; ### # # # ####### # # # # ##### # # ##### # # ####### # # #######
82 ;###############################################################################################################
83 ;###############################################################################################################
86 ; here, Fast FORTH sleeps, waiting any interrupt.
87 ; IP,S,T,W,X,Y registers (R13 to R8) are free for any interrupt routine...
88 ; ...and so PSP and RSP stacks with their rules of use.
89 ; remember: in any interrupt routine you must include : BIC #0x78,0(RSP) before RETI
90 ; to force return to SLEEP.
91 ; or (bad idea ? previous SR flags are lost) simply : ADD #2 RSP, then RET instead of RETI
94 ; ======================================;
95 JMP SLEEP ;2 here is the return for any interrupts, else TERMINAL_INT :-)
96 ; ======================================;
99 ; **************************************;
100 TERMINAL_INT ; <--- TEMR RX interrupt vector, delayed by the LPMx wake up time
101 ; **************************************; if wake up time increases, max bauds rate decreases...
102 ; (ACCEPT) part II under interrupt ; Org Ptr -- len'
103 ; --------------------------------------;
104 ADD #4,RSP ;1 remove SR and PC from stack, SR flags are lost (unused by FORTH interpreter)
105 .word 172Ah ;5 POPM W=buffer_bound,T=0Dh,S=20h
106 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
107 ; starts the 2th stopwatch ;
108 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
109 AKEYREAD MOV.B &TERMRXBUF,Y ;3 read character into Y, UCRXIFG is cleared
110 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
111 ; stops the 3th stopwatch ; 3th bottleneck result : 17~ + LPMx wake_up time ( + 5~ XON loop if F/Bds<230401 )
112 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
113 AKEYREAD1 ; <--- XON RET address 2 ; first emergency: anticipate XOFF on CR as soon as possible
114 CMP.B T,Y ;1 char = CR ?
115 JZ RXOFF ;2 then RET to ENDACCEPT
116 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;+ 4 to send RXOFF
117 ; stops the first stopwatch ;= first bottleneck (empty line process), best case result: 20~ + LPMx wake_up time..
118 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^; ...or 11~ in case of empty line
119 CMP.B S,Y ;1 printable char ?
120 JHS ASTORETEST ;2 yes
121 CMP.B #8,Y ; char = BS ?
122 JNE WAITaKEY ; case of other control chars
123 ; --------------------------------------;
124 ; start of backspace ; made only by an human
125 ; --------------------------------------;
126 CMP @PSP,TOS ; Ptr = Org ?
127 JZ WAITaKEY ; yes: do nothing else
128 SUB #1,TOS ; no : dec Ptr
130 ; --------------------------------------;
132 ; --------------------------------------;
133 ASTORETEST CMP W,TOS ; 1 Bound is reached ?
134 JZ WAITaKEY ; 2 yes: loopback
135 MOV.B Y,0(TOS) ; 3 no: store char @ Ptr, send echo then loopback
136 ADD #1,TOS ; 1 increment Ptr
137 ; --------------------------------------;
138 WAITaKEY BIT #UCRXIFG,&TERMIFG ; 3 new char in TERMRXBUF ?
141 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
142 ; stops the 2th stopwatch ; best case result: 23~ ==> 434 kBds/MHz
143 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
144 ; --------------------------------------;
145 ENDACCEPT ; <--- XOFF return address
146 ; --------------------------------------;
147 MOV #LPM0+GIE,&LPM_MODE ; reset LPM_MODE to default mode LPM0 for next line of input stream
148 CMP #0,&LINE ; if LINE <> 0...
150 ADD #1,&LINE ; ...increment LINE
151 ACCEPTEND SUB @PSP+,TOS ; Org Ptr -- len'
152 MOV @RSP+,IP ; 2 and continue with INTERPRET with GIE=0.
153 ; So FORTH machine is protected against any interrupt...
155 .word 1734h ;6 pop R4,R5,R6,R7
157 mNEXT ; ...until next falling down to LPMx mode of (ACCEPT) part1,
158 ; **************************************; i.e. when the FORTH interpreter has no more to do.
160 ; ------------------------------------------------------------------------------
161 ; TERMINAL I/O, output part
162 ; ------------------------------------------------------------------------------
165 ;Z (EMIT) c -- output character (byte) to the terminal
166 ; hardware or software control on TX flow seems not necessary with UARTtoUSB bridges because
167 ; they stop TX when their RX buffer is full. So no problem when the terminal input is echoed to output.
169 PARENEMIT MOV TOS,Y ; 1
171 YEMIT1 BIT #UCTXIFG,&TERMIFG ; 3 wait the sending end of previous char, useless at high baudrates
173 .IFDEF TERMINAL5WIRES ;
174 YEMIT2 BIT.B #CTS,&HANDSHAKIN ;
177 YEMIT .word 4882h ; hi7/4~ lo:12/4~ send/send_not echo to terminal
178 .word TERMTXBUF ; 3 MOV Y,&TERMTXBUF