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 ; ----------------------------------;
9 MOV #ENDACCEPT,S ;2 S = ACCEPT XOFF return
10 MOV #AKEYREAD1,T ;2 T = default XON return
11 PUSHM #3,IP ;5 PUSHM IP,S,T, as IP ret, XOFF ret, XON ret
12 MOV TOS,W ;1 -- addr len
13 MOV @PSP,TOS ;2 -- org ptr )
14 ADD TOS,W ;1 -- org ptr W=Bound )
15 MOV #0Dh,T ;2 T = 'CR' to speed up char loop in part II > prepare stack and registers
16 MOV #20h,S ;2 S = 'BL' to speed up char loop in part II ) for TERMINAL_INT use
17 BIT #UCRXIFG,&TERM_IFG ;3 RX_Int ?
18 JZ ACCEPTNEXT ;2 no : case of quiet input terminal
19 MOV &TERM_RXBUF,Y ;3 yes: clear RX_Int
20 CMP #0Ah,Y ;2 received char = LF ? (end of downloading ?)
21 JNZ RXON ;2 no : RXON return = AKEYREAD1, to process first char of new line.
22 ACCEPTNEXT ADD #2,RSP ;1 yes: remove AKEYREAD1 as XON return,
23 PUSHM #3,S ;6 PUSHM S,T,W before SLEEP (and so WAKE on any interrupts)
25 ; ----------------------------------;
28 ; **********************************;
29 TERMINAL_INT ; <--- TEMR RX interrupt vector, delayed by the LPMx wake up time
30 ; **********************************; if wake up time increases, max bauds rate decreases...
31 ; (ACCEPT) part II under interrupt ; Org Ptr -- len'
32 ; ----------------------------------;
33 POPM #5,S ;8 POPM Y=SR,X=PC,W=buffer_bound, T=0Dh,S=20h
34 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
35 ; starts the 2th stopwatch ;
36 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
37 AKEYREAD MOV.B &TERM_RXBUF,Y ;3 read character into Y, UCRXIFG is cleared
38 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
39 ; stops the 3th stopwatch ; 3th bottleneck result : 17~ + LPMx wake_up time ( + 5~ XON loop if F/Bds<230401 )
40 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
41 AKEYREAD1 ; <--- XON RET address 2 ; first emergency: anticipate XOFF on CR as soon as possible
42 CMP.B T,Y ;1 char = CR ?
43 JZ RXOFF ;2 then RET to ENDACCEPT
44 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;+ 4 to send RXOFF
45 ; stops the first stopwatch ;= first bottleneck (empty line process), best case result: 20~ + LPMx wake_up time..
46 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^; ...or 11~ in case of empty line
47 CMP.B S,Y ;1 printable char ?
49 CMP.B #8,Y ; char = BS ?
50 JNE WAITaKEY ; case of other control chars
51 ; ----------------------------------;
52 ; start of backspace ; made only by an human
53 ; ----------------------------------;
54 CMP @PSP,TOS ; Ptr = Org ?
55 JZ WAITaKEY ; yes: do nothing else
56 SUB #1,TOS ; no : dec Ptr
58 ; ----------------------------------;
60 ; ----------------------------------;
61 ASTORETEST CMP W,TOS ; 1 Bound is reached ?
62 JZ WAITaKEY ; 2 yes: loopback
63 MOV.B Y,0(TOS) ; 3 no: store char @ Ptr, send echo then loopback
64 ADD #1,TOS ; 1 increment Ptr
65 ; ----------------------------------;
66 WAITaKEY BIT #UCRXIFG,&TERM_IFG ; 3 new char in TERMRXBUF ?
69 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv;
70 ; stops the 2th stopwatch ; best case result: 23~ ==> 434 kBds/MHz
71 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^;
72 ; ----------------------------------;
73 ENDACCEPT ; <--- XOFF return address
74 ; ----------------------------------;
75 MOV #LPM0+GIE,&LPM_MODE ; reset LPM_MODE to default mode LPM0 for next line of input stream
76 ; ----------------------------------;
79 MOV #0A500h,&SYSCFG0 ; enable write MAIN + INFO
81 MOV #0A500h,&MPUCTL0 ; clear MPU (Memory Protection Unit) enable bit
84 ; ----------------------------------;
85 CMP #0,&LINE ; if LINE <> 0...
87 ADD #1,&LINE ; ...increment LINE
88 ACCEPTEND SUB @PSP+,TOS ; Org Ptr -- len'
89 MOV @RSP+,IP ; 2 and continue with INTERPRET with GIE=0.
90 ; So FORTH machine is protected against any interrupt...
91 mNEXT ; ...until next falling down to LPMx mode of (ACCEPT) part1,
92 ; **********************************; i.e. when the FORTH interpreter has no more to do.
94 ; ------------------------------------------------------------------------------
95 ; TERMINAL I/O, output part
96 ; ------------------------------------------------------------------------------
99 ;https://forth-standard.org/standard/core/EMIT
100 ;C EMIT c -- output character to the output device ; deferred word
102 EMIT MOV @PC+,PC ;3 15~
103 PFAEMIT .word BODYEMIT ; Parameter Field Address (PFA) of EMIT, with its default value
104 BODYEMIT MOV TOS,Y ; 1
106 YEMIT1 BIT #UCTXIFG,&TERM_IFG ; 3 wait the sending end of previous char, useless at high baudrates
108 .IFDEF TERMINAL5WIRES ;
109 YEMIT2 BIT.B #CTS,&HANDSHAKIN ;
112 YEMIT .word 4882h ; hi7/4~ lo:12/4~ send/send_not echo to terminal
113 .word TERM_TXBUF ; 3 MOV Y,&TERMTXBUF