-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbi_macros.inc
228 lines (190 loc) · 5.54 KB
/
tbi_macros.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
;;
; Copyright Jacques Deschênes 2019
; This file is part of STM8_NUCLEO
;
; STM8_NUCLEO is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; STM8_NUCLEO is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with STM8_NUCLEO. If not, see <http://www.gnu.org/licenses/>.
;;
;--------------------------------------
TAB_WIDTH=4 ; default tabulation width
EOF=0xff ; end of file marker
NLEN_MASK=0xf ; mask to extract name len
KW_TYPE_MASK=0xf0 ; mask to extract keyword type
STACK_SIZE=140
STACK_EMPTY=RAM_SIZE-1
INT_SIZE=3 ; int24 size in bytes
CELL_SIZE=INT_SIZE
FRUN=0 ; flags run code in variable flags
FOPT=1 ; run time optimization flag
FTIMER=2 ; timer expiration flag
FSLEEP=3 ; halt resulting from SLEEP
FBREAK=4 ; break point flag
FCOMP=5 ; compiling flags
FLN_REJECTED=6 ; a memory full error occured while in *insert_line*.
FTRACE=7 ; trace flag
LINE_HEADER_SIZE=3 ; line number 2 bytes and line length 1 byte
FIRST_DATA_ITEM=LINE_HEADER_SIZE+1 ; skip over DATA_IDX token.
MAX_LINENO=0x7fff; BASIC maximum line number
RX_QUEUE_SIZE=8
TIM2_CLK_FREQ=62500
TIB_SIZE=80
PAD_SIZE=BLOCK_SIZE
NAME_MAX_LEN=15 ; LABLE,CONST and DIM variables maximum length
REC_XTRA_BYTES=5
REC_LEN_MASK=31
STDOUT=1 ; output to uart
BUFOUT=3 ; buffered output
;--------------------------------------
; constantes related to Arduino
; API mapping
;-------------------------------------
INP=0
OUTP=1
EOF=0xff ; end of file marker
TYPE_MASK=0xf0 ; mask to extract data type, i.e. DIM variable symbol or CONST symbol
TYPE_DVAR=(1<<4); DIM variable type
TYPE_CONST=(2<<4); CONST data
NLEN_MASK=0xf ; mask to extract name len
NONE_IDX = 255 ; not a token
;--------------------------------------
; assembler flags
;-------------------------------------
; MATH_OVF=0 ; if 1 the stop on math overflow
; assume 16 Mhz Fcpu
.macro _usec_dly n
ldw x,#(16*n-2)/4 ; 2 cy
decw x ; 1 cy
nop ; 1 cy
jrne .-2 ; 2 cy
.endm
; load X register with
; entry point of dictionary
; before calling 'search_dict'
.macro _ldx_dict dict_name
ldw x,#dict_name+2
.endm
; reset BASIC pointer
; to beginning of last token
; extracted except if it was end of line
.macro _unget_token
decw y
.endm
; extract 16 bits address from BASIC code
.macro _get_addr
ldw x,y ; 1 cy
ldw x,(x) ; 2 cy
addw y,#2 ; 2 cy
.endm ; 5 cy
; alias for _get_addr
.macro _get_word
_get_addr
clr a
.endm ; 6 cy
; extract character from BASIC code
.macro _get_char
ld a,(y) ; 1 cy
incw y ; 1 cy
.endm ; 2 cy
; extract next token
.macro _next_token
_get_char
.endm ; 2 cy
; extract next command token id
.macro _next_cmd
_get_char ; 2 cy
.endm ; 2 cy
; get code address in x
.macro _code_addr
clrw x ; 1 cy
ld xl,a ; 1 cy
sllw x ; 2 cy
ldw x,(code_addr,x) ; 2 cy
.endm ; 6 cy
; call subroutine from index in a
.macro _call_code
_code_addr ; 6 cy
call (x) ; 4 cy
.endm ; 10 cy
; jump to bytecode routine
; routine must jump back to
; interp_loop
.macro _jp_code
_code_addr
jp (x)
.endm ; 8 cycles
; jump back to interp_loop
.macro _next
jp interp_loop
.endm ; 2 cycles
;---------------------------------
; files.asm macros
;---------------------------------
;----------------------------------
; file system
; file header:
; sign field: 2 bytes .ascii "TB"
; program size: 1 word
; data: n*BLOCK_SIZE
; BLOCK_SIZE is 128 bytes depend
; on MCU block erase size.
;----------------------------------
FILE_SIGN_FIELD = 0 ; signature offset
FILE_SIZE_FIELD = 2 ; size offset
FILE_DATA= 4 ; data offset
FILE_HEADER_SIZE = 4 ; bytes
;---------------------
; MACRO
; check if there is
; an erased program
; at this address
; input:
; X file header address
; output:
; Z 1 erazed
; 0 not erased|not program.
;--------------------
.macro _is_erased
pushw x
ldw x,(x)
cpw x,ERASED
popw x
.endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; MACRO
; check for application signature
; input:
; x file header address
; output:
; Z 1 signature present
; 0 no app signature
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.macro _qsign
pushw x
ldw x,(x)
cpw x,SIGNATURE ; "TB"
popw x
.endm
;------------------------------------
; board user LED control macros
;------------------------------------
.macro _led_on
bset LED_PORT,#LED_BIT
.endm
.macro _led_off
bres LED_PORT,#LED_BIT
.endm
.macro _led_toggle
ld a,LED_PORT
xor a,#LED_BIT
ld LED_PORT,a
.endm