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/OVER
70 ;C OVER x1 x2 -- x1 x2 x1
72 OVER MOV TOS,-2(PSP) ; 3 -- x1 (x2) x2
73 MOV @PSP,TOS ; 2 -- x1 (x2) x1
74 SUB #2,PSP ; 1 -- x1 x2 x1
79 ;https://forth-standard.org/standard/core/UDotR
80 ;X U.R u n -- display u unsigned in n width
83 .word TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
84 .word RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
89 ;https://forth-standard.org/standard/core/CFetch
90 ;C C@ c-addr -- char fetch char from memory
92 CFETCH MOV.B @TOS,TOS ;2
97 ;https://forth-standard.org/standard/core/Plus
98 ;C + n1/u1 n2/u2 -- n3/u3 add n1+n2
105 ;https://forth-standard.org/standard/tools/DUMP
108 PUSH &BASE ; save current base
109 MOV #10h,&BASE ; HEX base
110 ADD @PSP,TOS ; -- ORG END
112 .word SWAP ; -- END ORG
115 .word II,lit,4,UDOTR,SPACE ; generate address
117 .word II,lit,8,PLUS,II,xdo ; display first 8 bytes
118 DUMP2 .word II,CFETCH,lit,3,UDOTR
119 .word xloop,DUMP2 ; bytes display loop
121 .word II,lit,10h,PLUS,II,lit,8,PLUS,xdo ; display last 8 bytes
122 DUMP3 .word II,CFETCH,lit,3,UDOTR
123 .word xloop,DUMP3 ; bytes display loop
125 .word II,lit,10h,PLUS,II,xdo ; display 16 chars
126 DUMP4 .word II,CFETCH
127 .word lit,7Eh,MIN,FBLANK,MAX,EMIT
128 .word xloop,DUMP4 ; chars display loop
129 .word lit,10h,xploop,DUMP1 ; line loop
130 .word RFROM,lit,BASE,STORE ; restore current base
135 FORTHWORD "{SD_TOOLS}"
138 ; read logical sector and dump it
139 ; ----------------------------------;
140 FORTHWORD "SECTOR" ; sector. -- don't forget to add decimal point to your sector number (if < 65536)
141 ; ----------------------------------;
143 MOV TOS,X ; X = SectorH
144 MOV @PSP,W ; W = sectorL
145 CALL #readSectorWX ; W = SectorLO X = SectorHI
148 .word LESSNUM,NUMS,NUMGREATER ; ud -- display the double number
150 .word lit,SD_BUF,lit,200h,DUMP;
152 ; ----------------------------------;
154 ; ----------------------------------;
155 ; read first sector of Cluster and dump it
156 ; ----------------------------------;
157 FORTHWORD "CLUSTER" ; cluster. -- don't forget to add decimal point to your sector number (if < 65536)
158 ; ----------------------------------;
160 MOV.B &SecPerClus,W ; SecPerClus(54321) = multiplicator
161 MOV @PSP,X ; X = ClusterL
164 ADD X,X ; (RLA) shift one left MULTIPLICANDlo16
165 ADDC TOS,TOS ; (RLC) shift one left MULTIPLICANDhi8
167 RRA W ; shift one right multiplicator
168 JNC CLUSTERLOOP ; if not carry
169 ADD &OrgClusters,X ; add OrgClusters = sector of virtual cluster 0 (word size)
171 ADDC #0,TOS ; don't forget carry
172 JMP SECTOR ; jump to a defined word
173 ; ----------------------------------;
175 ; dump FAT1 first sector
176 ; ----------------------------------;
177 FORTHWORD "FAT" ;VWXY Display first FATsector
178 ; ----------------------------------;
181 MOV &OrgFAT1,0(PSP) ;
182 MOV #0,TOS ; FATsectorHI = 0
184 ; ----------------------------------;
187 ; dump current DIR first sector
188 ; ----------------------------------;
190 ; ----------------------------------;
192 MOV TOS,2(PSP) ; save TOS
193 MOV &DIRclusterL,0(PSP) ;
194 MOV &DIRclusterH,TOS ;
197 CMP #1,0(PSP) ; cluster 1 ?
199 MOV &OrgRootDir,0(PSP) ; if yes, special case of FAT16 OrgRootDir
201 ; ----------------------------------;