OSDN Git Service

V208 update FastForth.pdf
[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 SD_BUF 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"          ; CIB CIB CPL -- CIB len
34 ; ----------------------------------;
35 SD_ACCEPT                           ; sequentially move from SD_BUF to SDIB (PAD if RAM=1k) a line of chars delimited by CRLF
36 ; ----------------------------------; up to CPL = 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 ; ----------------------------------; -- CIB CIB CPL
45     MOV     2(PSP),W                ;               W=dst
46     MOV     TOS,0(PSP)              ; -- CIB CPL CPL
47     MOV     #0,TOS                  ; -- CIB CPL Count
48 ; ----------------------------------;
49 SDA_InitSrcAddr                     ; <== SDA_GetFileNextSector
50 ; ----------------------------------;
51     MOV     &BufferPtr,X            ;               X=src
52     JMP     SDA_ComputeChar         ;
53 ; ----------------------------------;
54 SDA_YEMIT_RET                       ;
55 ; ----------------------------------;
56     FORTHtoASM                      ;
57     SUB     #2,IP                   ; 1 restore YEMIT return
58 ; ----------------------------------;
59 SDA_ComputeChar                     ;
60 ; ----------------------------------;
61     CMP     &BufferLen,X            ; 3 BufferPtr >= BufferLen ?
62     JHS     SDA_GetFileNextSector   ; 2 yes
63     MOV.B   SD_BUF(X),Y             ; 3 Y = char
64     ADD     #1,X                    ; 1 increment input BufferPtr
65     CMP.B   #32,Y                   ; 2 ascii printable char ?
66     JHS     SDA_MoveChar            ; 2 yes
67     CMP.B   #10,Y                   ; 2 control char = 'LF' ?
68     JNZ     SDA_ComputeChar         ; 2 no
69 ; ----------------------------------;
70 SDA_EndOfLine                       ;
71 ; ----------------------------------;
72     MOV     X,&BufferPtr            ; yes  save BufferPtr for next line
73     ADD     #2,PSP                  ; -- CIB len
74     MOV     @RSP+,IP                ;
75     MOV     @IP+,PC                 ; ===> unique output
76 ; ----------------------------------;
77 SDA_MoveChar                        ;
78 ; ----------------------------------;
79     CMP     @PSP,TOS                ; 2 count = CPL ?
80     JZ      YEMIT1                  ; 2 yes, don't move char to dst
81     MOV.B   Y,0(W)                  ; 3 move char to dst
82     ADD     #1,W                    ; 1 increment dst addr
83     ADD     #1,TOS                  ; 1 increment count of moved chars
84     JMP     YEMIT1                  ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
85 ; ----------------------------------; 32/29~ char loop, add 14~ for readsectorW ==> 46/43~ ==> 174/186 kbytes/s @ 8MHz
86 SDA_GetFileNextSector               ; CIB CPL Count --
87 ; ----------------------------------;
88     PUSH    W                       ; save dst
89     CALL    #Read_File              ; that resets BufferPtr
90     MOV     @RSP+,W                 ; restore dst
91     JMP     SDA_InitSrcAddr         ; loopback to end the line
92 ; ----------------------------------;
93
94