; definitions that are used in the rest of the program
; Copyright (C) 2020 nytpu
; SPDX-License-Identifier: GPL-3.0-or-later
; For more license details, see LICENSE or <https://www.gnu.org/licenses/>.
; This file incorporates code from:
; Copyright (C) 2018-2020 Eldred Habert
; See LICENSE_MIT or <https://opensource.org/licenses/MIT>
; include the libraries
; structs is broken on newest rgbds version
; struct definitions
bytes 1, YPos
bytes 1, XPos
bytes 1, YBox
bytes 1, XBox
bytes 1, Attr
bytes 3, Tiles
; a couple more hardware defines
NB_SPRITES equ 40
; I generally discourage the use of pseudo-instructions for a variety of reasons,
; but this one includes a label, and manually giving them different names is tedious.
ldh a, [rSTAT]
jr nz, .waitVRAM\@
; `ld b, X` followed by `ld c, Y` is wasteful (same with other reg pairs).
; This writes to both halves of the pair at once, without sacrificing readability
; Example usage: `lb bc, X, Y`
assert -128 <= (\2) && (\2) <= 255, "Second argument to `lb` must be 8-bit!"
assert -128 <= (\3) && (\3) <= 255, "Third argument to `lb` must be 8-bit!"
ld \1, ((\2) << 8) | (\3)
; 64 bytes, should be sufficient for most purposes. If you're really starved on
; memory check your stack usage and consider setting this to 32 instead.
; 16 is probably not enough.
STACK_SIZE equ $40
; Use this to cause a crash.
; I don't recommend using this unless you want a condition:
; `call cc, Crash` is 3 bytes (`cc` being a condition); `error cc` is only 2 bytes
; This should help minimize the impact of error checking
IF _NARG == 0
assert Crash == $0038
; This assembles to XX FF (with XX being the `jr` instruction)
; If the condition is fulfilled, this jumps to the operand: $FF
; $FF encodes the instruction `rst $38`!
jr \1, @-1