Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Oam internal priority test #1

Merged
merged 5 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
RGBASM = rgbasm
RGBLINK = rgblink
RGBFIX = rgbfix

RM_F =
ifeq ($(OS), Windows_NT)
RM_F = Del
else
RM_F = rm -f
endif

ASMFLAGS = -L # L - disable optimiziations
FIXFLAGS = -C -v -m 0 -p 0 # v - equlivant to -f lhg that fixes some header values \
m - cartrigde type, p - pad value \
C - for CGB only
HARDWAREINC_PATH = hardware.inc/
# L - disable optimiziations
ASMFLAGS = -L

SRC_DIR = src
SRC_FILE = $(SRC_DIR)/color_bg_oam_priority.asm
TARGET = bg_oam_priority
# v - equlivant to -f lhg that fixes some header values
# m - cartrigde type, p - pad value
# C - for CGB only
FIXFLAGS = -C -v -m 0 -p 0

$(TARGET).gbc: $(TARGET).o
$(RGBLINK) -o $@ $^
$(RGBFIX) $(FIXFLAGS) $@
define create_target =
rgbasm $(ASMFLAGS) -i $(2) -i hardware.inc/ -o $(1).o $(2)/main.asm
rgblink -o $(1).gbc $(1).o
rgbfix $(FIXFLAGS) $(1).gbc
endef

$(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:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,55 +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:
ld a, [rLCDC]
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)
Expand Down
49 changes: 49 additions & 0 deletions src/common.asm
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,53 @@ 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:
ld a, [rLCDC]
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)
alloncm marked this conversation as resolved.
Show resolved Hide resolved
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
41 changes: 41 additions & 0 deletions src/oam_internal_priority/graphics_data.asm
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions src/oam_internal_priority/main.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
INCLUDE "hardware.inc"

SECTION "graphics_data", ROM0
INCLUDE "graphics_data.asm"

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