1 ; -*- coding: utf-8 -*-
5 ;https://forth-standard.org/standard/core/MAX
6 ;C MAX n1 n2 -- n3 signed maximum
8 MAX: CMP @PSP,TOS ; n2-n1
13 ;https://forth-standard.org/standard/core/MIN
14 ;C MIN n1 n2 -- n3 signed minimum
16 MIN: CMP @PSP,TOS ; n2-n1
24 ;https://forth-standard.org/standard/core/SPACE
25 ;C SPACE -- output a space
32 ;https://forth-standard.org/standard/core/SPACES
33 ;C SPACES n -- output n spaces
43 JNZ SPACE ;25~ ==> 27~ by space ==> 2.963 MBds @ 8 MHz
45 SPACESNEXT2 MOV @PSP+,TOS ; -- drop n
51 ; https://forth-standard.org/standard/core/I
52 ; I -- n R: sys1 sys2 -- sys1 sys2
53 ; get the innermost loop index
55 II SUB #2,PSP ;1 make room in TOS
57 MOV @RSP,TOS ;2 index = loopctr - fudge
63 ;https://forth-standard.org/standard/core/OVER
64 ;C OVER x1 x2 -- x1 x2 x1
66 OVER MOV TOS,-2(PSP) ; 3 -- x1 (x2) x2
67 MOV @PSP,TOS ; 2 -- x1 (x2) x1
68 SUB #2,PSP ; 1 -- x1 x2 x1
73 ; https://forth-standard.org/standard/core/toR
74 ; >R x -- R: -- x push to return stack
82 ;https://forth-standard.org/standard/core/UDotR
83 ;X U.R u n -- display u unsigned in n width
86 .word TOR,LESSNUM,lit,0,NUM,NUMS,NUMGREATER
87 .word RFROM,OVER,MINUS,lit,0,MAX,SPACES,TYPE
92 ;https://forth-standard.org/standard/core/CFetch
93 ;C C@ c-addr -- char fetch char from memory
95 CFETCH MOV.B @TOS,TOS ;2
100 ;https://forth-standard.org/standard/core/Plus
101 ;C + n1/u1 n2/u2 -- n3/u3 add n1+n2
108 ;https://forth-standard.org/standard/tools/DUMP
111 PUSH &BASE ; save current base
112 MOV #10h,&BASE ; HEX base
113 ADD @PSP,TOS ; -- ORG END
115 .word SWAP ; -- END ORG
118 .word II,lit,4,UDOTR,SPACE ; generate address
120 .word II,lit,8,PLUS,II,xdo ; display first 8 bytes
121 DUMP2 .word II,CFETCH,lit,3,UDOTR
122 .word xloop,DUMP2 ; bytes display loop
124 .word II,lit,10h,PLUS,II,lit,8,PLUS,xdo ; display last 8 bytes
125 DUMP3 .word II,CFETCH,lit,3,UDOTR
126 .word xloop,DUMP3 ; bytes display loop
128 .word II,lit,10h,PLUS,II,xdo ; display 16 chars
129 DUMP4 .word II,CFETCH
130 .word lit,7Eh,MIN,FBLANK,MAX,EMIT
131 .word xloop,DUMP4 ; chars display loop
132 .word lit,10h,xploop,DUMP1 ; line loop
133 .word RFROM,lit,BASE,STORE ; restore current base
138 FORTHWORD "{SD_TOOLS}"
141 ; read logical sector and dump it
142 ; ----------------------------------;
143 FORTHWORD "SECTOR." ; sector. -- don't forget to add decimal point to your sector number (if < 65536)
144 ; ----------------------------------;
145 SECTOR MOV TOS,X ; X = SectorH
146 MOV @PSP,W ; W = sectorL
147 CALL #readSectorWX ; W = SectorLO X = SectorHI
151 .word NUMGREATER ; ud -- display the double number
154 .word lit,200h,DUMP ;
156 ; ----------------------------------;
158 ; ----------------------------------;
159 ; read first sector of Cluster and dump it
160 ; ----------------------------------;
161 FORTHWORD "CLUSTR." ; cluster. -- don't forget to add decimal point to your sector number (if < 65536)
162 ; ----------------------------------;
163 CLUSTER BIT.B #CD_SD,&SD_CDIN ; test Card Detect: memory card present ?
165 MOV #COLD,PC ; no: force COLD
166 CD_CLUST_OK MOV.B &SecPerClus,W ; SecPerClus(54321) = multiplicator
167 MOV @PSP,X ; X = ClusterL
169 CLUSTERLOOP ADD X,X ; (RLA) shift one left MULTIPLICANDlo16
170 ADDC TOS,TOS ; (RLC) shift one left MULTIPLICANDhi8
171 CLUSTER1 RRA W ; shift one right multiplicator
172 JNC CLUSTERLOOP ; if not carry
173 ADD &OrgClusters,X ; add OrgClusters = sector of virtual cluster 0 (word size)
175 ADDC #0,TOS ; don't forget carry
176 JMP SECTOR ; jump to a defined word
177 ; ----------------------------------;
179 ; dump FAT1 first sector
180 ; ----------------------------------;
181 FORTHWORD "FAT" ;VWXY Display first FATsector
182 ; ----------------------------------;
185 MOV &OrgFAT1,0(PSP) ;
186 MOV #0,TOS ; FATsectorHI = 0
188 ; ----------------------------------;
191 ; dump current DIR first sector
192 ; ----------------------------------;
194 ; ----------------------------------;
196 MOV TOS,2(PSP) ; save TOS
197 MOV &DIRclusterL,0(PSP) ;
198 MOV &DIRclusterH,TOS ;
201 CMP #1,0(PSP) ; cluster 1 ?
203 MOV &OrgRootDir,0(PSP) ; if yes, special case of FAT16 OrgRootDir
205 ; ----------------------------------;