11
2- ; First, let's include libraries
2+ ; First, let's include libraries.
33
44INCLUDE "hardware.inc/hardware.inc"
55 rev_Check_hardware_inc 4 . 0
@@ -10,14 +10,12 @@ INCLUDE "debugfile.inc/debugfile.inc"
1010INCLUDE "rgbds-structs/structs.inc"
1111
1212
13- ; A couple more hardware defines
14-
15- def NB_SPRITES equ 40
13+ INCLUDE "sgb.inc"
1614
1715
1816; `ld b, X` followed by `ld c, Y` is wasteful (same with other reg pairs).
19- ; This writes to both halves of the pair at once, without sacrificing readability
20- ; Example usage: `lb bc, X, Y `
17+ ; This writes to both halves of the pair at once, without sacrificing readability.
18+ ; Example usage: `lb bc, 42, 69 `
2119MACRO lb
2220 assert - 128 <= (\ 2 ) && (\ 2 ) <= 255 , "Second argument to `lb` must be 8-bit!"
2321 assert - 128 <= (\ 3 ) && (\ 3 ) <= 255 , "Third argument to `lb` must be 8-bit!"
3129def RomBank equ $ 7fff
3230
3331
34- ; SGB packet types
35- RSRESET
36- def PAL01 rb 1
37- def PAL23 rb 1
38- def PAL12 rb 1
39- def PAL03 rb 1
40- def ATTR_BLK rb 1
41- def ATTR_LIN rb 1
42- def ATTR_DIV rb 1
43- def ATTR_CHR rb 1
44- def SOUND rb 1 ; $08
45- def SOU_TRN rb 1
46- def PAL_SET rb 1
47- def PAL_TRN rb 1
48- def ATRC_EN rb 1
49- def TEST_EN rb 1
50- def ICON_EN rb 1
51- def DATA_SND rb 1
52- def DATA_TRN rb 1 ; $10
53- def MLT_REQ rb 1
54- def JUMP rb 1
55- def CHR_TRN rb 1
56- def PCT_TRN rb 1
57- def ATTR_TRN rb 1
58- def ATTR_SET rb 1
59- def MASK_EN rb 1
60- def OBJ_TRN rb 1 ; $18
61- def PAL_PRI rb 1
62-
63- def SGB_PACKET_SIZE equ 16
64-
65- ; sgb_packet packet_type, nb_packets, data...
66- MACRO sgb_packet
67- def PACKET_SIZE equ _NARG - 1 ; Size of what's below
68- db (\ 1 << 3 ) | (\ 2 )
69- REPT _NARG - 2
70- SHIFT
71- db \ 2
72- ENDR
73-
74- ds SGB_PACKET_SIZE - PACKET_SIZE , 0
75- ENDM
76-
77-
78- ; 64 bytes, should be sufficient for most purposes. If you're really starved on
79- ; check your stack usage and consider setting this to 32 instead. 16 is probably not enough.
80- def STACK_SIZE equ $ 40
32+ ; 64 bytes, should be sufficient for most purposes; preferably, keep this even, but not necessarily a power of 2.
33+ ; If you're really starved on memory, check your stack usage and consider setting this to 32 instead.
34+ ; 16 is unlikely to be enough.
35+ def STACK_SIZE equ 64
8136
8237
8338; Use this to cause a crash.
84- ; I don't recommend using this unless you want a condition:
85- ; `call cc, Crash` is 3 bytes (`cc` being a condition); `error cc` is only 2 bytes
86- ; This should help minimize the impact of error checking
39+ ; Note that `runtime_assert` may be more ergonomic on emulators, and is less intrusive.
40+ ;
41+ ; `call cc, Crash` is 3 bytes (`cc` being a condition); `error cc` is only 2 bytes!
42+ ; This should help minimize the impact of error checking.
8743MACRO error
88- IF _NARG == 0
89- rst Crash
90- ELSE
91- assert Crash == $ 0038
92- ; This assembles to XX FF (with XX being the `jr` instruction)
93- ; If the condition is fulfilled, this jumps to the operand: $FF
94- ; $FF encodes the instruction `rst $38`!
95- jr \ 1 , @ + 1
96- ENDC
44+ assert Crash == $ 0038
45+ ; This assembles to XX FF (with XX being the `jr` instruction).
46+ ; If the condition is fulfilled, this jumps to the operand, which is $FF.
47+ ; And $FF encodes the instruction `rst $38`!
48+ jr \ 1 , @ + 1
9749ENDM
0 commit comments