1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2015> <J.M. THOORENS>
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.
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.
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/>.
23 ;https://forth-standard.org/standard/core/MAX
24 ;C MAX n1 n2 -- n3 signed maximum
26 MAX: CMP @PSP,TOS ; n2-n1
31 ;https://forth-standard.org/standard/core/MIN
32 ;C MIN n1 n2 -- n3 signed minimum
34 MIN: CMP @PSP,TOS ; n2-n1
42 ;https://forth-standard.org/standard/core/SPACE
43 ;C SPACE -- output a space
50 ;https://forth-standard.org/standard/core/SPACES
51 ;C SPACES n -- output n spaces
61 JNZ SPACE ;25~ ==> 27~ by space ==> 2.963 MBds @ 8 MHz
63 SPACESNEXT2 MOV @PSP+,TOS ; -- drop n
69 ; https://forth-standard.org/standard/core/I
70 ; I -- n R: sys1 sys2 -- sys1 sys2
71 ; get the innermost loop index
73 II SUB #2,PSP ;1 make room in TOS
75 MOV @RSP,TOS ;2 index = loopctr - fudge
81 ;https://forth-standard.org/standard/core/OVER
82 ;C OVER x1 x2 -- x1 x2 x1
84 OVER MOV TOS,-2(PSP) ; 3 -- x1 (x2) x2
85 MOV @PSP,TOS ; 2 -- x1 (x2) x1
86 SUB #2,PSP ; 1 -- x1 x2 x1
91 ; https://forth-standard.org/standard/core/toR
92 ; >R x -- R: -- x push to return stack
100 ;https://forth-standard.org/standard/core/UDotR
101 ;X U.R u n -- display u unsigned in n width
104 .word TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
105 .word RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
110 ;https://forth-standard.org/standard/core/CFetch
111 ;C C@ c-addr -- char fetch char from memory
113 CFETCH MOV.B @TOS,TOS ;2
118 ;https://forth-standard.org/standard/core/Plus
119 ;C + n1/u1 n2/u2 -- n3/u3 add n1+n2
126 ;https://forth-standard.org/standard/tools/DUMP
129 PUSH &BASE ; save current base
130 MOV #10h,&BASE ; HEX base
131 ADD @PSP,TOS ; -- ORG END
133 .word SWAP ; -- END ORG
136 .word II,lit,4,UDOTR,SPACE ; generate address
138 .word II,lit,8,PLUS,II,xdo ; display first 8 bytes
139 DUMP2 .word II,CFETCH,lit,3,UDOTR
140 .word xloop,DUMP2 ; bytes display loop
142 .word II,lit,10h,PLUS,II,lit,8,PLUS,xdo ; display last 8 bytes
143 DUMP3 .word II,CFETCH,lit,3,UDOTR
144 .word xloop,DUMP3 ; bytes display loop
146 .word II,lit,10h,PLUS,II,xdo ; display 16 chars
147 DUMP4 .word II,CFETCH
148 .word lit,7Eh,MIN,FBLANK,MAX,EMIT
149 .word xloop,DUMP4 ; chars display loop
150 .word lit,10h,xploop,DUMP1 ; line loop
151 .word RFROM,lit,BASE,STORE ; restore current base
156 FORTHWORD "{SD_TOOLS}"
159 ; read logical sector and dump it
160 ; ----------------------------------;
161 FORTHWORD "SECTOR" ; sector. -- don't forget to add decimal point to your sector number (if < 65536)
162 ; ----------------------------------;
164 MOV TOS,X ; X = SectorH
165 MOV @PSP,W ; W = sectorL
166 CALL #readSectorWX ; W = SectorLO X = SectorHI
169 .word LESSNUM,NUMS,NUMGREATER ; ud -- display the double number
171 .word lit,SD_BUF,lit,200h,DUMP;
173 ; ----------------------------------;
175 ; ----------------------------------;
176 ; read first sector of Cluster and dump it
177 ; ----------------------------------;
178 FORTHWORD "CLUSTER" ; cluster. -- don't forget to add decimal point to your sector number (if < 65536)
179 ; ----------------------------------;
181 MOV.B &SecPerClus,W ; SecPerClus(54321) = multiplicator
182 MOV @PSP,X ; X = ClusterL
185 ADD X,X ; (RLA) shift one left MULTIPLICANDlo16
186 ADDC TOS,TOS ; (RLC) shift one left MULTIPLICANDhi8
188 RRA W ; shift one right multiplicator
189 JNC CLUSTERLOOP ; if not carry
190 ADD &OrgClusters,X ; add OrgClusters = sector of virtual cluster 0 (word size)
192 ADDC #0,TOS ; don't forget carry
193 JMP SECTOR ; jump to a defined word
194 ; ----------------------------------;
196 ; dump FAT1 first sector
197 ; ----------------------------------;
198 FORTHWORD "FAT" ;VWXY Display first FATsector
199 ; ----------------------------------;
202 MOV &OrgFAT1,0(PSP) ;
203 MOV #0,TOS ; FATsectorHI = 0
205 ; ----------------------------------;
208 ; dump current DIR first sector
209 ; ----------------------------------;
211 ; ----------------------------------;
213 MOV TOS,2(PSP) ; save TOS
214 MOV &DIRclusterL,0(PSP) ;
215 MOV &DIRclusterH,TOS ;
218 CMP #1,0(PSP) ; cluster 1 ?
220 MOV &OrgRootDir,0(PSP) ; if yes, special case of FAT16 OrgRootDir
222 ; ----------------------------------;