-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.i
110 lines (94 loc) · 1.89 KB
/
macros.i
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
#ifndef MACROS_I
#define MACROS_I
; == ASM STACK INTERACTION ==
; Must use the register number (e.g. 24 instead of r24)
.macro PUSHRSP reg
push \reg
push \reg + 1
.endm
.macro POPRSP reg
pop \reg + 1
pop \reg
.endm
.macro PUSHDSP reg
st -Y, \reg
st -Y, \reg + 1
.endm
.macro POPDSP reg
ld \reg + 1, Y+
ld \reg, Y+
.endm
; == WORD DEFINITIONS ==
.macro defword name, flags=0, label
.text
.balign 2
.global name_\label
name_\label :
.word link ; link to the previously defined word
.set link,name_\label
.byte \flags|(nameend_\label - . - 1) ; flags + length of the name
.ascii "\name" ; the name
nameend_\label :
.balign 2
.global \label
\label :
.word pm(DOCOL) ; Codeword
; list of word tokens follow
.endm
.macro defcode name, flags=0, label
.text
.balign 2
.global name_\label
name_\label :
.word link ; link to the previously defined word
.set link,name_\label
.byte \flags|(nameend_\label - . - 1) ; flags + length of the name
.ascii "\name" ; the name
nameend_\label :
.balign 2
.global \label
\label :
.word pm(code_\label) ; Codeword
.balign 2
.global code_\label
code_\label :
; list of word tokens follow
.endm
.macro defvar name, flags=0, label, initial=0
defcode \name,\flags,\label
ldi r16, lo8(var_\label)
ldi r17, hi8(var_\label)
PUSHDSP 16
rjmp NEXT
.data
var_\label:
.word \initial
.text
.endm
.macro defconst name, flags=0, label, value
.set value_\name,\value
defcode \name,\flags,\label
ldi r16, lo8(\value)
ldi r17, hi8(\value)
PUSHDSP 16
rjmp NEXT
.endm
; TODO: Make this push the length on as well.
.macro defstring name, flags=0, label, value
defconst "\name",\flags,\label,string_\label
string_\label :
.string "\value"
.endm
; == WORD TOKENS ==
.macro fw name
.byte T_\name
.endm
.macro lit word
fw LIT
.word \word
.endm
.macro zbranch rel
fw ZBRANCH
.word \rel - . - 2
.endm
#endif