Skip to content

Commit

Permalink
First test
Browse files Browse the repository at this point in the history
  • Loading branch information
alloncm committed Feb 5, 2023
1 parent e92bb53 commit a6b4bac
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 58 deletions.
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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,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)
Expand Down
48 changes: 48 additions & 0 deletions src/common.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
66 changes: 66 additions & 0 deletions src/oam_internal_priority/main.asm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a6b4bac

Please sign in to comment.