diff --git a/common/functions.inc b/common/functions.inc index 2cccd12..a698ebc 100644 --- a/common/functions.inc +++ b/common/functions.inc @@ -46,6 +46,7 @@ clearLogo: ; Writes a value across 16 bytes, starting at HL. Intended to fill a single tile. ; Parameters: ; B - The value to set the bytes to. +; HL - Destintion location. ; Modifies: ; HL - End result: HL + 16 fillTile: @@ -55,6 +56,60 @@ fillTile: pop de ret +; Fills a 16 byte block with a specific pattern. Intended to fill a single tile +; with a specific grayscale or color shade. +; Parameters: +; B - The pattern to write: +; $00: $00 $00 +; $01: $FF $00 +; $02: $00 $FF +; $03: $FF $FF +; HL - Destintion location. +; Modifies: +; B - Set to $00 or $FF. +; HL - End result: HL + 16 +fillTileEx: + push af + ld a, b + ld b, %11 + and b + jr nz, _check3 + + ; b = $00. Fill with plette entry 0. + ld b, $00 + call fillTile + pop af + ret + +_check3: + cp b + jr nz, _handleAlt + + ; b = $ff. Fill with palette entry 3. + ld b, $ff + call fillTile + pop af + ret + +_handleAlt: + push de + ld b, %01 + ld d, 16 + ld e, $ff + cp b + ld a, 0 + jr nz, _fillLoop + xor e +_fillLoop: + ld [hli], a + xor e + dec d + jr nz, _fillLoop + + pop de + pop af + ret + ; Copies up to 256 bytes of memory to another location. ; Parameter: ; BC - Source location. diff --git a/cpu/miscInstrs.asm b/cpu/miscInstrs.asm index 3257849..f94daeb 100644 --- a/cpu/miscInstrs.asm +++ b/cpu/miscInstrs.asm @@ -6,7 +6,7 @@ include "common/functions.inc" SECTION "home", ROM0 ProgramStart: - call clearLogo + ;call clearLogo _lcdDisable @@ -15,20 +15,19 @@ ProgramStart: ldh [$ff47], a ; TODO: Write actual tests. :) - ld a, $ff - ld hl, $8014 - ld [hl], a - ld hl, $8016 - ld [hl], a - ld hl, $8019 - ld [hl], a - ld hl, $801b - ld [hli], a - ld [hli], a - ld [hli], a - ld [hli], a - ld [hli], a - call memset + ld hl, $8010 + ld b, $00 + call fillTileEx + + ld b, $01 + call fillTileEx + + ld b, $02 + call fillTileEx + + ld b, $03 + call fillTileEx + _lcdEnable .loop: