OSDN Git Service

modified word # ; refreshed source folders
[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 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 ; ----------------------------------; up to TIB_LEN = 80 chars
37     PUSH    IP                      ;
38     MOV     #SDA_YEMIT_RET,IP       ; set YEMIT return
39 ; ----------------------------------;
40 StartNewLine                        ;
41 ; ----------------------------------;
42     MOV &CurrentHdl,T               ; prepare a link for the next LOADed 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_ORG,W              ;               W=dst
47     .ELSEIF                         ; use SDIB as SD Input Buffer
48     MOV     #SDIB,W                 ;               W=dst
49     .ENDIF
50     MOV     W,2(PSP)                ; -- StringOrg' TIB TIB_LEN
51     MOV     TOS,0(PSP)              ; -- StringOrg' TIB_LEN TIB_LEN
52     MOV     #0,TOS                  ; -- StringOrg' TIB_LEN Count
53 ; ----------------------------------;
54 SDA_InitSrcAddr                     ; <== SDA_GetFileNextSector
55 ; ----------------------------------;
56     CMP     #0,&BufferLen           ; test if input buffer is empty (EOF)
57     JZ      SDA_GoToInterpret       ; yes, to interpret an empty line (to do nothing)
58     MOV     &BufferPtr,X            ;               X=src
59     JMP     SDA_ComputeChar         ;
60 ; ----------------------------------;
61 SDA_YEMIT_RET                       ;
62 ; ----------------------------------;
63     FORTHtoASM                      ;
64     SUB     #2,IP                   ; 1 restore YEMIT return
65 ; ----------------------------------;
66 SDA_ComputeChar                     ;
67 ; ----------------------------------;
68     CMP     &BufferLen,X            ; 3 BufferPtr >= BufferLen ?
69     JHS     SDA_GetFileNextSector   ; 2 yes
70     MOV.B   BUFFER(X),Y             ; 3 Y = char
71     ADD     #1,X                    ; 1 increment input BufferPtr
72     CMP.B   #32,Y                   ; 2 ascii printable char ?
73     JHS     SDA_MoveChar            ; 2 yes
74     CMP.B   #10,Y                   ; 2 control char = 'LF' ?
75     JNZ     SDA_ComputeChar         ; 2 no
76 ; ----------------------------------;
77 SDA_EndOfLine                       ;
78 ; ----------------------------------;
79     MOV     X,&BufferPtr            ; yes  save BufferPtr for next line
80 ; ----------------------------------;
81 SDA_GoToInterpret                   ; -- StringOrg' TIB_LEN len'
82 ; ----------------------------------;
83     ADD     #2,PSP                  ; -- StringOrg' len'
84     MOV     @RSP+,IP                ;
85     MOV     @IP+,PC                 ; ===> unique output
86 ; ----------------------------------;
87 SDA_MoveChar                        ;
88 ; ----------------------------------;
89     CMP     @PSP,TOS                ; 2 count = TIB_LEN ?
90     JZ      YEMIT                   ; 2 yes, don't move char to dst
91     MOV.B   Y,0(W)                  ; 3 move char to dst
92     ADD     #1,W                    ; 1 increment dst addr
93     ADD     #1,TOS                  ; 1 increment count of moved chars
94     JMP     YEMIT                   ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
95 ; ----------------------------------; 32/29~ char loop, add 14~ for readsectorW ==> 46/43~ ==> 174/186 kbytes/s @ 8MHz
96 SDA_GetFileNextSector               ; StringOrg' TIB_LEN Count --
97 ; ----------------------------------;
98     PUSH    W                       ; save dst
99     CALL    #Read_File              ; that resets BufferPtr
100     MOV     @RSP+,W                 ; restore dst
101     JMP     SDA_InitSrcAddr         ; loopback to end the line
102 ; ----------------------------------;
103
104