Skip to content
This repository was archived by the owner on Dec 21, 2025. It is now read-only.

Commit 4b2be45

Browse files
committed
Move SGB defines to a separate file
1 parent 1205799 commit 4b2be45

File tree

3 files changed

+62
-68
lines changed

3 files changed

+62
-68
lines changed

include/defines.inc

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
; First, let's include libraries
2+
; First, let's include libraries.
33

44
INCLUDE "hardware.inc/hardware.inc"
55
rev_Check_hardware_inc 4.0
@@ -10,14 +10,12 @@ INCLUDE "debugfile.inc/debugfile.inc"
1010
INCLUDE "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`
2119
MACRO 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!"
@@ -31,67 +29,21 @@ ENDM
3129
def 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.
8743
MACRO 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
9749
ENDM

include/sgb.inc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; SGB packet types
2+
rsreset
3+
def PAL01 rb 1
4+
def PAL23 rb 1
5+
def PAL12 rb 1
6+
def PAL03 rb 1
7+
def ATTR_BLK rb 1
8+
def ATTR_LIN rb 1
9+
def ATTR_DIV rb 1
10+
def ATTR_CHR rb 1
11+
def SOUND rb 1 ; $08
12+
def SOU_TRN rb 1
13+
def PAL_SET rb 1
14+
def PAL_TRN rb 1
15+
def ATRC_EN rb 1
16+
def TEST_EN rb 1
17+
def ICON_EN rb 1
18+
def DATA_SND rb 1
19+
def DATA_TRN rb 1 ; $10
20+
def MLT_REQ rb 1
21+
def JUMP rb 1
22+
def CHR_TRN rb 1
23+
def PCT_TRN rb 1
24+
def ATTR_TRN rb 1
25+
def ATTR_SET rb 1
26+
def MASK_EN rb 1
27+
def OBJ_TRN rb 1 ; $18
28+
def PAL_PRI rb 1
29+
30+
def SGB_PACKET_SIZE equ 16
31+
32+
; sgb_packet packet_type, nb_packets, data...
33+
MACRO sgb_packet
34+
def PACKET_SIZE equ _NARG - 1 ; Size of what's below
35+
db (\1 << 3) | (\2)
36+
REPT _NARG - 2
37+
SHIFT
38+
db \2
39+
ENDR
40+
41+
ds SGB_PACKET_SIZE - PACKET_SIZE, 0
42+
ENDM

src/lib/header.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ hConsoleType:: db
99
SECTION UNION "Shadow OAM", WRAM0,ALIGN[8]
1010

1111
wShadowOAM::
12-
ds NB_SPRITES * 4
12+
ds OAM_COUNT * 4
1313

1414

1515
SECTION "Header", ROM0[$100]
@@ -97,7 +97,7 @@ Reset:: ; This is where the VBlank handler jumps to if Start+Select+B+A are all
9797
; This will get committed to hardware OAM after the end of the first
9898
; frame, but the hardware doesn't display it, so that's fine.
9999
ld hl, wShadowOAM
100-
ld c, NB_SPRITES * 4
100+
ld c, OAM_COUNT * 4
101101
xor a
102102
rst MemsetSmall
103103
ld a, h ; ld a, HIGH(wShadowOAM)
@@ -113,7 +113,7 @@ SECTION "OAM DMA routine", ROMX
113113
; It gets copied to HRAM and is called there from the VBlank handler.
114114
OAMDMA:
115115
ldh [rDMA], a
116-
ld a, NB_SPRITES
116+
ld a, OAM_COUNT
117117
.wait
118118
dec a
119119
jr nz, .wait

0 commit comments

Comments
 (0)