You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.6 KiB
101 lines
1.6 KiB
SECTION "functions", ROM0[$2000] |
|
|
|
_lcdDisable: MACRO |
|
call waitVBlank |
|
ld hl, $ff40 |
|
ld a, [hl] |
|
res 7, a |
|
ld [hl], a |
|
ENDM |
|
|
|
_lcdEnable: MACRO |
|
ld hl, $ff40 |
|
ld a, [hl] |
|
set 7, a |
|
ld [hl], a |
|
ENDM |
|
|
|
; Clears the Nintendo logo tile data. This is intended to leave the screen open |
|
; for simple (i.e. a bunch of boxes drawn with fillTile) test output. |
|
clearLogo: |
|
push af |
|
push hl |
|
|
|
; disable the LCD |
|
_lcdDisable |
|
|
|
; wipe the logo |
|
ld hl, $81A0 |
|
.loop: |
|
ld a, $0 |
|
ld [hld], a |
|
ld a, h |
|
cp $80 |
|
jr nz, .loop |
|
ld a, l |
|
cp $0f |
|
jr nz, .loop |
|
|
|
; enable the LCD and return |
|
_lcdEnable |
|
|
|
pop af |
|
pop hl |
|
ret |
|
|
|
; Writes a value across 16 bytes, starting at HL. Intended to fill a single tile. |
|
; Parameters: |
|
; B - The value to set the bytes to. |
|
; Modifies: |
|
; HL - End result: HL + 16 |
|
fillTile: |
|
push de |
|
ld d, 16 |
|
call memset |
|
pop de |
|
ret |
|
|
|
; Copies up to 256 bytes of memory to another location. |
|
; Parameter: |
|
; BC - Source location. |
|
; HL - Destination location. |
|
; D - The number of bytes to copy. |
|
; Modifies: |
|
; BC - End result: BC + D |
|
; HL - End result: BC + d |
|
; D - End result: $00 |
|
memcpy: |
|
ld a, [bc] |
|
ld [hli], a |
|
inc bc |
|
dec d |
|
ret z |
|
jr memcpy |
|
|
|
; Fills up to 256 bytes of memory with a set value, starting at HL. |
|
; Parameters: |
|
; B - The value to set the bytes to. |
|
; D - The number of bytes to modify. |
|
; HL - Destination location. |
|
; Modifies: |
|
; D - End result: 0 |
|
; HL - End result: HL + D |
|
memset: |
|
push af |
|
ld a, b |
|
.loop: |
|
ld [hli], a |
|
dec d |
|
jr nz, .loop |
|
pop af |
|
ret |
|
|
|
; Wait for vblank without using interrupts. |
|
waitVBlank: |
|
push af |
|
.loop: |
|
ldh a, [$ff44] |
|
cp $90 |
|
jr nz, .loop |
|
pop af |
|
ret
|
|
|