OSDN Git Service

la der de der
[fast-forth/master.git] / forthMSP430FR_SD_ACCEPT.asm
1 ; -*- coding: utf-8 -*-
2 ;
3 ;Z SD_ACCEPT  addr addr len -- addr' len'  get line to interpret from a SD Card file
4 ; no interrupt allowed
5 ; defered word ACCEPT is redirected here by the word LOAD"
6 ; "defered" word CIB is redirected to SDIB (PAD if RAM<2k) by the word LOAD"
7 ; sequentially move an input line ended by CRLF from SD_BUF to PAD
8 ;   if end of SD_BUF is reached before CRLF, asks Read_File to refill buffer with next sector
9 ;   then load the end of the line to SDIB_ptr.
10 ; when the last buffer is loaded, the handle is automaticaly closed
11 ; when all LOAD"ed files are read, redirects defered word ACCEPT to default ACCEPT and restore interpret pointers.
12 ; see CloseHandle.
13
14 ; used variables : BufferPtr, BufferLen
15 ; QYEMIT uses only IP and Y registers
16 ; ==================================;
17 ;    FORTHWORD "SD_ACCEPT"          ; SDIB_org SDIB_org SDIB_len -- SDIB_org len    IP = QUIT4
18 ; ==================================;
19 SD_ACCEPT                           ; sequentially move from SD_BUF to SDIB a line of chars delimited by CRLF
20         PUSH    IP                  ;                           R-- IP
21         MOV     #SDA_YEMIT_RET,IP   ; set QYEMIT return
22 ; ----------------------------------; up to CPL = 80 chars
23         MOV &CurrentHdl,T           ; prepare a link for a next LOADed file, if any...
24         MOV &BufferPtr,HDLW_BUFofst(T)  ; ...see usage : GetFreeHandle(CheckCaseOfLoadFileToken)
25 ; ----------------------------------;
26 ; SDA_InitDstAddr                   ;
27 ; ----------------------------------;
28         ADD     TOS,0(PSP)          ; -- SDIB_org SDIB_end SDIB_len
29         MOV     2(PSP),TOS          ; -- SDIB_org SDIB_end SDIB_ptr
30 ; ==================================;
31 SDA_InitSrcAddr                     ; -- SDIB_org SDIB_end SDIB_ptr     <== Read_File return
32 ; ==================================;
33         MOV     &BufferPtr,S        ;
34         MOV     &BufferLen,T        ;
35         MOV     @PSP,W              ; W = SDIB_end
36         MOV.B   #32,X               ; X = BL
37         JMP     SDA_ComputeCharLoop ;
38 ; ----------------------------------;
39 SDA_YEMIT_RET                       ;
40 ; ----------------------------------;
41         mNEXTADR                    ;
42         SUB     #2,IP               ; 1 restore YEMIT return
43 ; ----------------------------------;
44 SDA_ComputeCharLoop                 ; -- SDIB_org SDIB_end SDIB_ptr
45 ; ----------------------------------;
46         CMP     T,S                 ; 1 SD_buf_ptr >= SD_buf_len ?
47         JC      SDA_GetFileNextSect ; 2 if yes
48         MOV.B   SD_BUF(S),Y         ; 3 Y = char
49         ADD     #1,S                ; 1 increment SD_buf_ptr
50         CMP.B   X,Y                 ; 1 ascii printable char ?
51         JC      SDA_MoveChar        ; 2 yes
52         CMP.B   #10,Y               ; 2 control char = 'LF' ?
53         JNZ     SDA_ComputeCharLoop ; 2 no, loop back
54 ; ----------------------------------;
55 ;SDA_EndOfLine                      ;
56 ; ----------------------------------;
57         MOV S,&BufferPtr            ; save SD_buf_ptr for next line loop
58 ; ==================================;
59 SDA_EndOfFile                       ; -- SDIB_org SDIB_end SDIB_ptr     <== CloseHandle return
60 ; ==================================;
61         MOV     @RSP+,IP            ;                           R--
62         ADD     #2,PSP              ; -- SDIB_ORG SDIB_PTR
63         SUB     @PSP,TOS            ; -- SDIB_ORG LEN
64         MOV.B   X,Y                 ; Y = BL
65         JMP     QYEMIT              ; -- org len                        ==> output of SD_ACCEPT ==> INTERPRET
66 ; ----------------------------------;
67 SDA_MoveChar                        ; -- SDIB_ORG SDIB_END SDIB_PTR
68 ; ----------------------------------;
69         CMP     W,TOS               ; 1 SDIB_ptr = SDIB_end ?
70         JZ      QYEMIT              ; 2 yes, don't move char to dst
71         MOV.B   Y,0(TOS)            ; 3 move char to dst
72         ADD     #1,TOS              ; 1 increment SDIB_ptr
73         JMP     QYEMIT              ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
74 ; ----------------------------------; 27/24~ char loop, add 14~ for readsectorW one char ==> 41/38~ ==> 195/210 kbytes/s @ 8MHz
75 SDA_GetFileNextSect                 ; -- SDIB_org SDIB_end SDIB_ptr
76 ; ----------------------------------;
77         PUSH    #SDA_InitSrcAddr    ; set the default return of Read_File, modified by CloseHandle when the end of file is reached 
78         MOV     #Read_File,PC       ;
79 ; ----------------------------------;