diff --git a/Makefile b/Makefile index 94f0a4a..9bedc2b 100644 --- a/Makefile +++ b/Makefile @@ -15,16 +15,15 @@ FIXFLAGS = -C -v -m 0 -p 0 # v - equlivant to -f lhg that fixes some header val C - for CGB only HARDWAREINC_PATH = hardware.inc/ -SRC_DIR = src -SRC_FILE = $(SRC_DIR)/color_bg_oam_priority.asm -TARGET = bg_oam_priority +define create_target = + $(RGBASM) -i $(2) -i $(HARDWAREINC_PATH) -o $(1).o $(2)/main.asm + $(RGBLINK) -o $(1).gbc $(1).o + $(RGBFIX) $(FIXFLAGS) $(1).gbc +endef -$(TARGET).gbc: $(TARGET).o - $(RGBLINK) -o $@ $^ - $(RGBFIX) $(FIXFLAGS) $@ - -$(TARGET).o: $(SRC_FILE) - $(RGBASM) -i $(SRC_DIR) -i $(HARDWAREINC_PATH) -o $@ $^ +all: + $(call create_target,bg_oam_priority,src/color_bg_oam_priority) + $(call create_target,oam_internal_priority,src/oam_internal_priority) .PHONY: clean clean: diff --git a/src/graphics_data.asm b/src/color_bg_oam_priority/graphics_data.asm similarity index 100% rename from src/graphics_data.asm rename to src/color_bg_oam_priority/graphics_data.asm diff --git a/src/color_bg_oam_priority.asm b/src/color_bg_oam_priority/main.asm similarity index 86% rename from src/color_bg_oam_priority.asm rename to src/color_bg_oam_priority/main.asm index 8f45644..2c40bce 100644 --- a/src/color_bg_oam_priority.asm +++ b/src/color_bg_oam_priority/main.asm @@ -3,7 +3,7 @@ INCLUDE "graphics_data.asm" INCLUDE "hardware.inc" SECTION "std", ROM0 -INCLUDE "common.asm" +INCLUDE "../common.asm" SECTION "stat interrupt", ROM0[$48] jp hl @@ -137,54 +137,6 @@ Main:: .loop jp .loop ; wait for interrupts -;---------------------------------------------------- -; Wait for Vblank -; Wait untill the STAT register shows vblank status -;---------------------------------------------------- -WaitVblank: - ld a, [rSTAT] - and a, %11 ; get only the mode flag - cp a, 1 ; check for 1 (the vblank status) - jr nz, WaitVblank - ret - -;---------------------------------------------------- -; Turn off the LCD display -;---------------------------------------------------- -TurnOffLcd: - and a, %10000000 ; get LCDC bit 7 to check if lcd is off - cp a, 0 ; check lcdc for lcd off - ret z ; if lcd already off return and dont wait for vblank (it will never return) - call WaitVblank - ld a, 0 - ld [rLCDC], a - ret - -;---------------------------------------------------- -; Laod a pallete color with a color -; mut d - color index -; const e - oam or bg (0 for oam, 1 for bg) -; const bc - color -;---------------------------------------------------- -LoadPallete: - ld a, d - set 7, a ; in order for the pallete pointer to auto increment - bit 0, e ; check if 0 (oam) or 1 (bg) - jr z, .oam_pallete - .bg_pallete - ld [rBCPS], a - ld a, c - ld [rBCPD], a - ld a, b - ld [rBCPD], a - .oam_pallete - ld [rOCPS], a - ld a, c - ld [rOCPD], a - ld a, b - ld [rOCPD], a - ret - ;---------------------------------------------------- ; All the stat interrupt handlers - one for each ; OAM object (pipeline) diff --git a/src/common.asm b/src/common.asm index aa9dad3..722a0f2 100644 --- a/src/common.asm +++ b/src/common.asm @@ -58,4 +58,52 @@ Mulu8: jr nz, .mulloop .exit pop de + ret + +;---------------------------------------------------- +; Wait for Vblank +; Wait untill the STAT register shows vblank status +;---------------------------------------------------- +WaitVblank: + ld a, [rSTAT] + and a, %11 ; get only the mode flag + cp a, 1 ; check for 1 (the vblank status) + jr nz, WaitVblank + ret + +;---------------------------------------------------- +; Turn off the LCD display +;---------------------------------------------------- +TurnOffLcd: + and a, %10000000 ; get LCDC bit 7 to check if lcd is off + cp a, 0 ; check lcdc for lcd off + ret z ; if lcd already off return and dont wait for vblank (it will never return) + call WaitVblank + ld a, 0 + ld [rLCDC], a + ret + +;---------------------------------------------------- +; Laod a pallete color with a color +; mut d - color index +; const e - oam or bg (0 for oam, 1 for bg) +; const bc - color +;---------------------------------------------------- +LoadPallete: + ld a, d + set 7, a ; in order for the pallete pointer to auto increment + bit 0, e ; check if 0 (oam) or 1 (bg) + jr z, .oam_pallete +.bg_pallete + ld [rBCPS], a + ld a, c + ld [rBCPD], a + ld a, b + ld [rBCPD], a +.oam_pallete + ld [rOCPS], a + ld a, c + ld [rOCPD], a + ld a, b + ld [rOCPD], a ret \ No newline at end of file diff --git a/src/oam_internal_priority/graphics_data.asm b/src/oam_internal_priority/graphics_data.asm new file mode 100644 index 0000000..f889675 --- /dev/null +++ b/src/oam_internal_priority/graphics_data.asm @@ -0,0 +1,41 @@ +; Colors definition +DEF WHITE EQU $FFFF +DEF RED EQU $001F +DEF GREEN EQU $03E0 + +TileData: + ; bg tile + dw `11111111 + dw `11111111 + dw `11111111 + dw `11111111 + dw `11111111 + dw `11111111 + dw `11111111 + dw `11111111 + + ; oam tiles + dw `00000000 + dw `00000010 + dw `00000110 + dw `00001110 + dw `00011110 + dw `00111110 + dw `01111110 + dw `00000000 + + dw `00000000 + dw `00000020 + dw `00000220 + dw `00002220 + dw `00022220 + dw `00222220 + dw `02222220 + dw `00000000 +.end + +OAMData: + ; Y, X, Tile, attr + db 40, 46, 2, 0 + db 40, 40, 1, 0 +.end \ No newline at end of file diff --git a/src/oam_internal_priority/main.asm b/src/oam_internal_priority/main.asm new file mode 100644 index 0000000..f943182 --- /dev/null +++ b/src/oam_internal_priority/main.asm @@ -0,0 +1,66 @@ +SECTION "graphics_data", ROM0 +INCLUDE "graphics_data.asm" +INCLUDE "hardware.inc" + +SECTION "std", ROM0 +INCLUDE "../common.asm" + +SECTION "boot", ROM0[$100] + nop + jp Main + +SECTION "main", ROM0[$150] +Main:: + di ; no need for interrupts for now + ld sp, $0FFFE ; setup the stack + + call TurnOffLcd + + ; Copy tiles to VRAM + ld hl, _VRAM + ld bc, TileData + ld de, TileData.end - TileData + call Memcpy + + ; Set screen 0 to use tile 0 + ld hl, _SCRN0 + ld bc, $400 + ld a, 0 + call Memset + + ; set vram bank to 1 in order to set the BG attributes + ld a, 1 + ld [rVBK], a + + ld hl, _SCRN0 + ld bc, $400 + ld a, 0 ; bg priority off, bg pallete 0 + call Memset ; loading the first screen attributes with 0 + + ; load the oam attributes to the oam ram + ld hl, _OAMRAM + ld bc, OAMData + ld de, OAMData.end - OAMData + call Memcpy + + ; set up palletes + ld d, 2 ; color index + ld e, 1 ; BG + ld bc, WHITE + call LoadPallete ; BG pallete - set color 1 of pallete 0 + + ld d, 2 ; color index + ld e, 0 ; OAM + ld bc, GREEN + call LoadPallete ; OAM pallete - set color 1 of pallete 0 + + ld d, 4 ; color index + ld e, 0 ; OAM + ld bc, RED + call LoadPallete ; OAM pallete - set color 2 of pallete 0 + + ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_OBJON|LCDCF_BGON + ld [rLCDC], a ; turn lcd on, with the correct flags + +.loop + jp .loop ; wait forever \ No newline at end of file