OSDN Git Service

bug bug bug...
[fast-forth/master.git] / MSP430_COND / CATCHALL.f
1 \ -*- coding: utf-8 -*-
2 \ http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
3
4 \ Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 \ Copyright (C) <2015>  <J.M. THOORENS>
6 \
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.
11 \
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.
16 \
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/>.
19
20
21
22 \ https://forth-standard.org/standard/core/HOLDS
23 \ Adds the string represented by addr u to the pictured numeric output string
24 \ compilation use: <# S" string" HOLDS #>
25 \ free HOLDS chars space in the 32+2 bytes HOLD area = {24,21,0} chars with a 32 bits sized {hexa,decimal,binary} number.
26 \ perfect to display all a line on LCD 2x20 chars...
27 \ C HOLDS    addr u --
28 CODE HOLDS
29         MOV @PSP+,X     \ 2
30         ADD TOS,X       \ 1 src
31         MOV &HP,Y       \ 3 dst
32 BEGIN   SUB #1,Y        \ 1 dst-1
33         SUB #1,X        \ 1 src-1
34         SUB #1,TOS      \ 1 cnt-1
35 U>= WHILE               \ 2
36         MOV.B @X,0(Y)   \ 4
37 REPEAT                  \ 2
38         MOV Y,&HP       \ 3
39         MOV @PSP+,TOS   \ 2
40         NEXT            \ 4  15 words
41 ENDCODE
42
43
44 \ https://forth-standard.org/standard/core/StoD
45 \ Convert the number n to the double-cell number d with the same numerical value.
46 CODE S>D        \ n -- d
47 SUB #2,PSP
48 MOV TOS,0(PSP)
49 BIT #$8000,TOS
50 MOV #0,TOS
51 0<> IF
52     SUB #1,TOS
53 THEN
54 NEXT
55 ENDCODE
56     \
57
58 \ https://forth-standard.org/standard/core/VALUE
59
60 \ Skip leading space delimiters. Parse name delimited by a space. 
61 \ Create a definition for name with the execution semantics defined below,
62 \ with an initial value equal to x.
63
64 \ Place x on the stack. The value of x is that given when name was created, 
65 \ until the phrase x TO name is executed, causing a new value of x to be assigned to name.
66
67 CODE VALUE
68     MOV #CONSTANT,PC
69 ENDCODE
70
71 CODE TO
72     MOV #IS,PC
73 ENDCODE IMMEDIATE
74
75
76
77
78 \ input: file size double word  Sector_per_cluster {1,2,4,8,16,32,64}
79 \ output cluster double word and cluster offset
80 CODE SD_DIV     \ SIZ_LO SIZ_HI SECPERCLU -- CLU_LO CLU_HI OFFSET
81 MOV.B 3(PSP),Y  \ Y = 0:CurSizeLOHi
82 MOV.B @PSP,X    \ X = 0:CurSizeHILo 
83 SWPB X          \ X = CurSizeHIlo:0
84 ADD Y,X         \ X = CurSizeHIlo:CurSizeLOhi
85 MOV.B 1(PSP),Y  \ Y:X = CurSize / 256
86 \ RRA Y           \ Y = Sectors number_High
87 \ RRC X           \ X = Sectors number_Low
88
89 MOV.B TOS,T     \ T = divisor = SECPERCLU
90
91 MOV #0,W        \ 1 W = 0:REMlo = 0
92 MOV #8,S        \ 1 CNT
93 \ RRA T           \ 1 0>0:SPClo>C   preshift one right DIVISOR
94 BEGIN
95     RRA Y       \ 1 0>SEC_HI>C
96     RRC X       \ 1 C>SEC_LO>C
97     RRC.B W     \ 1 C>REMlo>C
98     SUB #1,S    \ CNT-1
99     RRA T       \ 1 0>SPChi:SPClo>C
100 U>= UNTIL
101 BEGIN
102     RRA W       \ 1 0>0:REMlo>C
103     SUB #1,S    \ 1 CNT-1
104 \ 0= UNTIL        \ Y = OFFSET, S = CLU_LO, W = CLU_HI
105 S< UNTIL        \ Y = OFFSET, S = CLU_LO, W = CLU_HI
106 MOV.B W,TOS     \ -- xx xx REMlo
107 MOV X,2(PSP)    \ -- CLU_LO xx OFFSET
108 MOV Y,0(PSP)    \ -- CLU_LO CLU_HI OFFSET
109 MOV @IP+,PC
110 ENDCODE
111
112
113 \ tests tools
114 \ -----------
115     \
116
117 VARIABLE >PAD       \ declaration to do in start of source file
118 PAD IS >PAD         \ init >PAD, idem
119     \
120
121 \ sample anything during an interrupt for example
122 \ usage in ASSEMBLER WORD :   ... LO2HI SAMPLE HI2LO ...     if IP is already saved
123 \ usage in ASSEMBLER WORD :   ... PUSH IP LO2HI SAMPLE HI2LO MOV @RSP+,IP ...     if IP is not already saved
124 \ usage in FORTH WORD :    ... SAMPLE ...
125
126 CODE SAMPLE2PAD
127 CMP #TIB,&>PAD      \ 4 do nothing if [>PAD] = TIB 
128 0<> IF              \ 2 
129     MOV &>PAD,R6    \ 3 R6 = rDOVAR
130     MOV &TB0R,0(R6) \ 5 we want sample TB0R
131     MOV W,2(R6)
132     ADD #4,&>PAD    \ 3
133     MOV #R>,R6      \ 2 RFROM ==> rDOVAR
134 THEN                \
135 MOV @IP+,PC         \ 4
136 ENDCODE             \ add LO2HI = 10 + 23 = 33 cycles ==>  4us @ 8MHz
137     \
138
139 \ display samples, up to 42 samples
140 CODE DISPLAY_S      \ --
141 CMP #PAD,&>PAD
142 0= IF
143     NEXT
144 THEN
145 COLON
146 CR
147 >PAD @ PAD DO   \ limit first --
148     I  @ U.
149 2 +LOOP
150 PAD IS >PAD     \ reset >PAD
151 ;
152     \
153
154
155
156
157 DEFER TEST
158     \
159 CODE NOOP      \ compile MOV #NEXT,PC
160 NEXT
161 ENDCODE
162     \
163
164 CODE SAMPLE.    \ display what you want ( much slower than SAMPLE2PAD )
165     SUB #4,PSP
166     MOV TOS,2(PSP)
167     MOV &BASE,0(PSP)
168     MOV &GPFLAGS,TOS \ we want sample GPFLAGS
169     MOV #$10,&BASE
170     PUSHM S,Y
171     COLON
172     ." $" U.
173     BASE !
174     HI2LO
175     MOV @RSP+,IP
176     POPM Y,S
177     NEXT
178 ENDCODE
179     \
180
181 \ ' SAMPLE. IS TEST \ to start test
182 \ ' NOOP IS TEST    \ to stop test
183
184