forked from mist64/msbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.s
78 lines (68 loc) · 1.67 KB
/
macros.s
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
; htasc - set the hi bit on the last byte of a string for termination
; (by Tom Greene)
.macro htasc str
.repeat .strlen(str)-1,I
.byte .strat(str,I)
.endrep
.byte .strat(str,.strlen(str)-1) | $80
.endmacro
; For every token, a byte gets put into segment "DUMMY".
; This way, we count up with every token. The DUMMY segment
; doesn't get linked into the binary.
.macro init_token_tables
.segment "VECTORS"
TOKEN_ADDRESS_TABLE:
.segment "KEYWORDS"
TOKEN_NAME_TABLE:
.segment "DUMMY"
DUMMY_START:
.endmacro
; optionally define token symbol
; count up token number
.macro define_token token
.segment "DUMMY"
.ifnblank token
token := <(*-DUMMY_START)+$80
.endif
.res 1; count up in any case
.endmacro
; lay down a keyword, optionally define a token symbol
.macro keyword key, token
.segment "KEYWORDS"
htasc key
define_token token
.endmacro
; lay down a keyword and an address (RTS style),
; optionally define a token symbol
.macro keyword_rts key, vec, token
.segment "VECTORS"
.word vec-1
keyword key, token
.endmacro
; lay down a keyword and an address,
; optionally define a token symbol
.macro keyword_addr key, vec, token
.segment "VECTORS"
.addr vec
keyword key, token
.endmacro
.macro count_tokens
.segment "DUMMY"
NUM_TOKENS := <(*-DUMMY_START)
.endmacro
.macro init_error_table
.segment "ERROR"
ERROR_MESSAGES:
.endmacro
.macro define_error error, msg
.segment "ERROR"
error := <(*-ERROR_MESSAGES)
htasc msg
.endmacro
;---------------------------------------------
; set the MSB of every byte of a string
.macro asc80 str
.repeat .strlen(str),I
.byte .strat(str,I)+$80
.endrep
.endmacro