OSDN Git Service

747f67097729afe79921c521fb28ba6eec71f423
[fast-forth/master.git] / forthMSP430FR_SD_ACCEPT.asm
1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
3
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2017>  <J.M. THOORENS>
6 ;
7 ; This program is free software: you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
11 ;
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ; GNU General Public License for more details.
16 ;
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 ;Z SD_ACCEPT  addr addr len -- addr' len'  get line to interpret from a SD Card file
22 ; note : addr = TIB, addr' = PAD
23 ; defered word ACCEPT is redirected here by the word LOAD"
24 ; sequentially move an input line ended by CRLF from BUFFER to PAD
25 ;   if end of buffer is reached before CRLF, asks Read_HandledFile to fill buffer with next sector
26 ;   then move the end of the line.
27 ; when all LOAD"ed files are read, redirects defered word ACCEPT to (ACCEPT) and restore interpret pointers.
28 ; see CloseHandleT.
29
30 ; used variables : BufferPtr, BufferLen
31
32 ; ----------------------------------;
33 ;    FORTHWORD "SD_ACCEPT"          ; TIB TIB len -- PAD|SDIB len'
34 ; ----------------------------------;
35 SD_ACCEPT                           ; sequentially move from BUFFER to SDIB (or PAD) a line of chars delimited by CRLF
36 ; ----------------------------------;
37     PUSH    IP                      ;
38     MOV     #SDA_YEMIT_RET,IP       ; set YEMIT return
39 ; ----------------------------------;
40 StartNewLine                        ;
41 ; ----------------------------------;
42     MOV     &CurrentHdl,T           ; prepare link for any next LOAD"ed file...
43     MOV &BufferPtr,HDLW_BUFofst(T)  ; ...see usage : HandleComplements
44 ; ----------------------------------; -- TIB TIB len
45     .IFDEF RAM_1K                   ; use PAD as SD Input Buffer because the lack of RAM
46     MOV     #PAD,W                  ;               W=dst
47     MOV     #PAD_SIZE-4,0(PSP)      ; -- TIB max_count len
48     .ELSEIF                         ; use SDIB as SD Input Buffer
49     MOV     #SDIB,W                 ;               W=dst
50     MOV     #SDIB_SIZE-4,0(PSP)     ; -- TIB max_count len
51     .ENDIF
52     MOV     W,2(PSP)                ; -- StringOrg' max_count len
53     MOV     #0,TOS                  ; -- StringOrg' max_count Count
54 ; ----------------------------------;
55 SDA_InitSrcAddr                     ; <== SDA_GetFileNextSector
56 ; ----------------------------------;
57     CMP     #0,&BufferLen           ; test if input buffer is empty (EOF)
58     JZ      SDA_GoToInterpret       ; yes
59     MOV     &BufferPtr,X            ;               X=src
60     JMP     SDA_ComputeChar         ;
61 ; ----------------------------------;
62 SDA_YEMIT_RET                       ;
63 ; ----------------------------------;
64     FORTHtoASM                      ;
65     SUB     #2,IP                   ; 1 restore YEMIT return
66 ; ----------------------------------;
67 SDA_ComputeChar                     ;
68 ; ----------------------------------;
69     CMP     &BufferLen,X            ; 3 BufferPtr >= BufferLen ?
70     JHS     SDA_GetFileNextSector   ; 2 yes
71     MOV.B   BUFFER(X),Y             ; 3 Y = char
72     ADD     #1,X                    ; 1 increment input BufferPtr
73     CMP.B   #32,Y                   ; 2 ascii printable char ?
74     JHS     SDA_MoveChar            ; 2 yes
75     CMP.B   #10,Y                   ; control char = 'LF' ?
76     JNZ     SDA_ComputeChar         ; no
77 ; ----------------------------------;
78 SDA_EndOfLine                       ;
79 ; ----------------------------------;
80     MOV     X,&BufferPtr            ; yes  save BufferPtr for next line
81 ; ----------------------------------;
82 SDA_GoToInterpret                   ; -- StringOrg' max_count len'
83 ; ----------------------------------;
84     ADD     #2,PSP                  ; -- StringOrg' len'
85     MOV     @RSP+,IP                ;
86     MOV     @IP+,PC                 ; ===> unique output
87 ; ----------------------------------;
88 SDA_MoveChar                        ;
89 ; ----------------------------------;
90     CMP     TOS,0(PSP)              ; 3 count = max_chars_count ?
91     JZ      YEMIT                   ; 2 yes, don't move char to dst
92     MOV.B   Y,0(W)                  ; 3 move char to dst
93     ADD     #1,W                    ; 1 increment dst addr
94     ADD     #1,TOS                  ; 1 increment count of moved chars
95     JMP     YEMIT                   ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
96 ; ----------------------------------; 33/30~ char loop, add 14~ for readsectorW ==> 47/44~ ==> 21/23 kbytes/s / MHz
97 SDA_GetFileNextSector               ;
98 ; ----------------------------------;
99     PUSH    W                       ; save dst
100     CALL    #Read_File              ; that resets BufferPtr
101     MOV     @RSP+,W                 ; restore dst
102     JMP     SDA_InitSrcAddr         ; loopback to end the line
103 ; ----------------------------------;
104
105
106 ;C ACCEPT  addr addr len -- addr' len'  get line at addr to interpret len' chars
107             FORTHWORD "ACCEPT"
108 ACCEPT      MOV     #PARENACCEPT,PC
109
110 ;C (ACCEPT)  addr addr len -- addr len'     get len' (up to len) chars from terminal (TERATERM.EXE) via USBtoUART bridge
111             FORTHWORD "(ACCEPT)"
112 PARENACCEPT
113