Skip to content

Commit

Permalink
finishing the hud
Browse files Browse the repository at this point in the history
moving interrupts into hud
  • Loading branch information
LaroldsJubilantJunkyard committed Dec 17, 2023
1 parent d581660 commit 82de7ea
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
; ANCHOR: gameplay-background-initialize
INCLUDE "src/main/includes/hardware.inc"
INCLUDE "src/main/includes/character-mapping.inc"

SECTION "BackgroundVariables", WRAM0

mBackgroundScroll:: dw

SECTION "GameplayBackgroundSection", ROM0


InitializeBackground::

call DrawStarFieldBackground

ld a, 0
ld [mBackgroundScroll+0],a
ld a, 0
ld [mBackgroundScroll+1],a

ret
; ANCHOR_END: gameplay-background-initialize

; ANCHOR: gameplay-background-update-start
; This is called during gameplay state on every frame
UpdateBackground::

; Increase our scaled integer by 5
; Get our true (non-scaled) value, and save it for later usage in bc
ld a , [mBackgroundScroll+0]
add a , 5
ld b,a
ld [mBackgroundScroll+0], a
ld a , [mBackgroundScroll+1]
adc a , 0
ld c,a
ld [mBackgroundScroll+1], a
; ANCHOR_END: gameplay-background-update-start

; ANCHOR: gameplay-background-update-end
; Descale our scaled integer
; shift bits to the right 4 spaces
srl c
rr b
srl c
rr b
srl c
rr b
srl c
rr b

; Use the de-scaled low byte as the backgrounds position
ld a,b
ld [rSCY], a

ret
; ANCHOR: gameplay-background-initialize
INCLUDE "src/main/includes/hardware.inc"
INCLUDE "src/main/includes/character-mapping.inc"

SECTION "BackgroundVariables", WRAM0

mBackgroundScroll:: dw

SECTION "GameplayBackgroundSection", ROM0


InitializeBackground::

call DrawStarFieldBackground

ld a, 0
ld [mBackgroundScroll+0],a
ld a, 0
ld [mBackgroundScroll+1],a

ret
; ANCHOR_END: gameplay-background-initialize

; ANCHOR: gameplay-background-update-start
; This is called during gameplay state on every frame
UpdateBackground::

; Increase our scaled integer by 5
; Get our true (non-scaled) value, and save it for later usage in bc
ld a , [mBackgroundScroll+0]
add a , 5
ld b,a
ld [mBackgroundScroll+0], a
ld a , [mBackgroundScroll+1]
adc a , 0
ld c,a
ld [mBackgroundScroll+1], a
; ANCHOR_END: gameplay-background-update-start

; ANCHOR: gameplay-background-update-end
; Descale our scaled integer
; shift bits to the right 4 spaces
srl c
rr b
srl c
rr b
srl c
rr b
srl c
rr b

; Use the de-scaled low byte as the backgrounds position
ld a,b
ld [rSCY], a

ret
; ANCHOR_END: gameplay-background-update-end
90 changes: 68 additions & 22 deletions galactic-armada/src/main/states/gameplay/hud.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; ANCHOR: hud-start
INCLUDE "src/main/includes/hardware.inc"


SECTION "GameplayHUD", ROM0
; ANCHOR_END: hud-start

; ANCHOR: hud-increase-score
IncreaseScore::
Expand Down Expand Up @@ -42,29 +42,75 @@ IncreaseScore_Next:
jp IncreaseScore_Loop
; ANCHOR_END: hud-increase-score

; ANCHOR: hud-draw-lives
DrawBDigitsHL_OnDE::

; How many digits remain in b
ld a, b
and a
ret z
; ANCHOR: interrupts-start

; Decrease b by one
dec a
ld b,a
SECTION "Interrupts", ROM0

DisableInterrupts::
ld a, 0
ldh [rSTAT], a
di
ret

InitStatInterrupts::

ld a, IEF_STAT
ldh [rIE], a
xor a, a ; This is equivalent to `ld a, 0`!
ldh [rIF], a
ei

; This makes our stat interrupts occur when the current scanline is equal to the rLYC register
ld a, STATF_LYC
ldh [rSTAT], a

; We'll start with the first scanline
; The first stat interrupt will call the next time rLY = 0
ld a, 0
ldh [rLYC], a

ret
; ANCHOR_END: interrupts-start

; ANCHOR: interrupts-section
; Define a new section and hard-code it to be at $0048.
SECTION "Stat Interrupt", ROM0[$0048]
StatInterrupt:

push af

; Check if we are on the first scanline
ldh a, [rLYC]
cp 0
jp z, LYCEqualsZero

LYCEquals8:

; Don't call the next stat interrupt until scanline 8
ld a, 0
ldh [rLYC], a

; Turn the LCD on including sprites. But no window
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ16 | LCDCF_WINOFF | LCDCF_WIN9C00
ldh [rLCDC], a

jp EndStatInterrupts

LYCEqualsZero:

; Don't call the next stat interrupt until scanline 8
ld a, 8
ldh [rLYC], a

; Turn the LCD on including the window. But no sprites
ld a, LCDCF_ON | LCDCF_BGON | LCDCF_OBJOFF | LCDCF_OBJ16| LCDCF_WINON | LCDCF_WIN9C00
ldh [rLCDC], a

ld a, [hl]
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
ld [de], a

; Increase which tile we are drawing to
inc de
EndStatInterrupts:

; Increase the tile we are drawing
inc hl
pop af

jp DrawBDigitsHL_OnDE
; ANCHOR_END: hud-draw-lives
reti;
; ANCHOR_END: interrupts-section
73 changes: 0 additions & 73 deletions galactic-armada/src/main/states/gameplay/interrupts.asm

This file was deleted.

25 changes: 25 additions & 0 deletions galactic-armada/src/main/utils/text-utils.asm
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@ MultilineTypewriteTextInHL_AtDE_NewLine:
; continue until we read those consecutive 255's
jp MultilineTypewriteTextInHL_AtDE_NewLine
; ANCHOR_END: multiline-typewriter-effect

; ANCHOR: draw-b-digits
DrawBDigitsHL_OnDE::

; How many digits remain in b
ld a, b
and a
ret z

; Decrease b by one
dec a
ld b,a

ld a, [hl]
add a, 10 ; our numeric tiles start at tile 10, so add to 10 to each bytes value
ld [de], a

; Increase which tile we are drawing to
inc de

; Increase the tile we are drawing
inc hl

jp DrawBDigitsHL_OnDE
; ANCHOR_END: draw-b-digits
4 changes: 2 additions & 2 deletions src/part3/drawing-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ For drawing numbers, we've created a function called `DrawBDigitsHL_OnDE`. To ca

>**Note:** The numbers in our text font start at tile 10. So, for each number read, we'll add 10 to it.
```rgbasm,linenos,start={{#line_no_of "" ../../galactic-armada/src/main/states/gameplay/hud.asm:hud-draw-lives}}
{{#include ../../galactic-armada/src/main/states/gameplay/hud.asm:hud-draw-lives}}
```rgbasm,linenos,start={{#line_no_of "" ../../galactic-armada/src/main/utils/text-utils.asm:draw-b-digits}}
{{#include ../../galactic-armada/src/main/utils/text-utils.asm::draw-b-digits}}
```

We will later call that function like so:
Expand Down
Loading

0 comments on commit 82de7ea

Please sign in to comment.