summaryrefslogtreecommitdiff
path: root/include/macros.inc
blob: 2f1d4338eca9224082c2eb402a24b4be6ac2e7b3 (plain)
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
farcall: macro
    push af
    ld a, LOW(\1)
    ld [w_farcall_target + 0], a
    ld a, HIGH(\1)
    ld [w_farcall_target + 1], a
    ld a, BANK(\1)
    ld [w_bank_temp], a
    pop af
    call _farcall
endm

farjp: macro
    push af
    ld a, LOW(\1)
    ld [w_farcall_target + 0], a
    ld a, HIGH(\1)
    ld [w_farcall_target + 1], a
    ld a, BANK(\1)
    ld [w_bank_temp], a
    pop af
    jp _farjp
endm


push_bank_rom: macro
    ld a, [w_bank_rom]
    push af
    ld a, \1
    ld [w_bank_rom], a
    ld [rROMB0], a
endm

pop_bank_rom: macro
    pop af
    ld [w_bank_rom], a
    ld [rROMB0], a
endm


RGB: macro
    rept _NARG / 3
        dw palred (\1) + palgreen (\2) + palblue (\3)
        shift 3
    endr
endm

palred   EQUS "(1 << 0) *"
palgreen EQUS "(1 << 5) *"
palblue  EQUS "(1 << 10) *"

palettes EQUS "* PALETTE_SIZE"
palette  EQUS "+ PALETTE_SIZE *"
color    EQUS "+ PAL_COLOR_SIZE *"

tiles EQUS "* $10"


lb: macro
    ld \1, ((\2) & $ff) << 8 | ((\3) & $ff)
endm

ln: macro
    ld \1, ((\2) & $f) << 4 | ((\3) & $f)
endm

ld16: macro
    ld a, LOW(\2)
    ld [\1 + 0], a
    ld a, HIGH(\2)
    ld [\1 + 1], a
endm


const_def: macro
if _NARG >= 1
const_value = \1
else
const_value = 0
endc
if _NARG >= 2
const_inc = \2
else
const_inc = 1
endc
endm

const: macro
\1 EQU const_value
const_value = const_value + const_inc
endm

shift_const: macro
\1 EQU (1 << const_value)
const_value = const_value + const_inc
endm

const_skip: macro
if _NARG >= 1
const_value = const_value + const_inc * (\1)
else
const_value = const_value + const_inc
endc
endm

const_next: macro
if (const_value > 0 && \1 < const_value) || (const_value < 0 && \1 > const_value)
fail "const_next cannot go backwards from {const_value} to \1"
else
const_value = \1
endc
endm

const_dw: macro
    const \1
    dw \2
endm