OSDN Git Service

fixed ASSEMBLER crash
[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 ; no interrupt allowed
23 ; defered word ACCEPT is redirected here by the word LOAD"
24 ; "defered" word CIB is redirected to SDIB (PAD if RAM<2k) by the word LOAD"
25 ; sequentially move an input line ended by CRLF from SD_BUF to PAD
26 ;   if end of SD_BUF is reached before CRLF, asks Read_HandledFile to refill buffer with next sector
27 ;   then load the end of the line to PAD ptr.
28 ; when all LOAD"ed files are read, redirects defered word ACCEPT to default ACCEPT and restore interpret pointers.
29 ; see CloseHandleT.
30
31 ; used variables : BufferPtr, BufferLen
32
33
34 ; ----------------------------------;
35 ;    FORTHWORD "SD_ACCEPT"          ; CIB CIB CPL -- CIB len
36 ; ----------------------------------;
37 SD_ACCEPT                           ; sequentially move from SD_BUF to SDIB (PAD if RAM=1k) a line of chars delimited by CRLF
38 ; ----------------------------------; up to CPL = 80 chars
39     PUSH    IP                      ;
40     MOV     #SDA_YEMIT_RET,IP       ; set YEMIT return
41 ; ----------------------------------;
42 StartNewLine                        ; -- CIB CIB CPL
43 ; ----------------------------------;
44     MOV &CurrentHdl,T               ; prepare a link for the next LOADed file...
45     MOV &BufferPtr,HDLW_BUFofst(T)  ; ...see usage : GetFreeHandle(CheckCaseOfLoadFileToken)
46 ; ----------------------------------;
47     MOV     @PSP+,W                 ; -- CIB CPL        W=dst_ptr
48     MOV     TOS,X                   ;                   X=dst_len
49     MOV     #0,TOS                  ; -- CIB cnt
50 ; ----------------------------------;
51 SDA_InitSrcAddr                     ; <== SDA_GetFileNextSector
52 ; ----------------------------------;
53     MOV     &BufferPtr,S            ;                   S=src_ptr
54     MOV     &BufferLen,T            ;                   T=src_len
55     JMP     SDA_ComputeChar         ;
56 ; ----------------------------------;
57 SDA_YEMIT_RET                       ;
58 ; ----------------------------------;
59     .word   $+2                     ;
60     SUB     #2,IP                   ; 1                 restore YEMIT return
61 ; ----------------------------------;
62 SDA_ComputeChar                     ; -- CIB cnt
63 ; ----------------------------------;
64     CMP     T,S                     ; 1 src_ptr >= src_len ?
65     JC      SDA_GetFileNextSector   ; 2 yes
66     MOV.B   SD_BUF(S),Y             ; 3 Y = char
67     ADD     #1,S                    ; 1 increment input BufferPtr
68     CMP.B   #32,Y                   ; 2 ascii printable char ?
69     JC      SDA_MoveChar            ; 2 yes
70     CMP.B   #10,Y                   ; 2 control char = 'LF' ?
71     JNZ     SDA_ComputeChar         ; 2 no
72 ; ----------------------------------;
73 SDA_EndOfLine                       ; -- org cnt
74 ; ----------------------------------;
75     MOV     S,&BufferPtr            ; yes  save BufferPtr for next line
76     MOV     @RSP+,IP                ;
77     MOV     @IP+,PC                 ; ===> unique output
78 ; ----------------------------------;
79 SDA_MoveChar                        ;
80 ; ----------------------------------;
81     CMP     X,TOS                   ; 1 cnt = dst_len ?
82     JZ      YEMIT1                  ; 2 yes, don't move char to dst
83     MOV.B   Y,0(W)                  ; 3 move char to dst
84     ADD     #1,W                    ; 1 increment dst addr
85     ADD     #1,TOS                  ; 1 increment count of moved chars
86     JMP     YEMIT1                  ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
87 ; ----------------------------------; 29/26~ char loop, add 14~ for readsectorW ==> 43/40~ ==> 186/200 kbytes/s @ 8MHz
88 SDA_GetFileNextSector               ; CIB cnt --
89 ; ----------------------------------;
90     PUSHM   #2,W                    ; save dst_ptr, dst_len
91     CALL    #Read_File              ; that resets BufferPtr
92     POPM    #2,W                    ; restore dst_ptr, dst_len
93     JMP     SDA_InitSrcAddr         ; loopback to end the line
94 ; ----------------------------------;