1 ; -*- coding: utf-8 -*-
3 ;Z SD_ACCEPT addr addr len -- addr' len' get line to interpret from a SD Card file
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.
14 ; used variables : BufferPtr, BufferLen
15 ; EMIT uses only IP TOS and Y registers
16 ; ==================================;
17 ; FORTHWORD "SD_ACCEPT" ; SDIB_org SDIB_org SDIB_len -- SDIB len 94 bytes
18 ; ==================================;
19 SD_ACCEPT ; sequentially move from SD_BUF to SDIB (PAD if RAM=1k) a line of chars delimited by CRLF
20 ; ----------------------------------; up to CPL = 80 chars
22 MOV #SDA_YEMIT_RET,IP ; set YEMIT return
23 ; ----------------------------------;
24 MOV &CurrentHdl,T ; prepare a link for a next LOADed file, if any...
25 MOV &BufferPtr,HDLW_BUFofst(T) ; ...see usage : GetFreeHandle(CheckCaseOfLoadFileToken)
26 ; ----------------------------------;
28 ; ----------------------------------;
29 MOV @PSP+,W ; -- SDIB_org SDIB_len W=SDIB_ptr
30 MOV TOS,X ; X=SDIB_len
31 MOV #0,TOS ; -- SDIB_org len of moved bytes from SD_buf to SDIB
32 ; ----------------------------------;
33 SDA_InitSrcAddr ; <== SDA_GetFileNextSect
34 ; ----------------------------------;
35 MOV &BufferPtr,S ; S=SD_buf_ptr
36 MOV &BufferLen,T ; T=SD_buf_len
38 ; ----------------------------------;
40 ; ----------------------------------;
42 SUB #2,IP ; 1 restore YEMIT return
43 ; ----------------------------------;
44 SDA_ComputeChar ; -- SDIB_org len
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 #32,Y ; 2 ascii printable char ?
51 JC SDA_MoveChar ; 2 yes
52 CMP.B #10,Y ; 2 control char = 'LF' ?
53 JNZ SDA_ComputeChar ; 2 no, loop back
54 ; ----------------------------------;
55 SDA_EndOfLine ; -- SDIB_org len
56 ; ----------------------------------;
57 MOV S,&BufferPtr ; yes save SD_buf_ptr for next line
60 JMP ACCEPT_EOL ; -- SDIB_org len ==> output
61 ; ----------------------------------;
63 ; ----------------------------------;
64 CMP TOS,X ; 1 len = SDIB_len ?
65 JZ YEMIT ; 2 yes, don't move char to dst
66 MOV.B Y,0(W) ; 3 move char to dst
67 ADD #1,W ; 1 increment SDIB_ptr
68 ADD #1,TOS ; 1 increment len of moved chars
69 JMP YEMIT ; 9/6~ send echo to terminal if ECHO, do nothing if NOECHO
70 ; ----------------------------------; 29/26~ char loop, add 14~ for readsectorW one char ==> 43/40~ ==> 186/200 kbytes/s @ 8MHz
71 SDA_GetFileNextSect ; -- SDIB_org len
72 ; ----------------------------------;
73 PUSHM #2,W ; save SDIB_ptr, SDIB_len
74 CALL #Read_File ; which clears SD_buf_ptr and set SD_buf_len
75 POPM #2,W ; restore SDIB_ptr, SDIB_len
76 JMP SDA_InitSrcAddr ; loopback to end the line
77 ; ----------------------------------;