GB 2015 day 1 part 1

This commit is contained in:
Bill Rossi 2024-12-29 18:10:38 -05:00
parent 4807c82bf9
commit 6db0e0618b
4 changed files with 60 additions and 26 deletions

View File

@ -16,8 +16,9 @@ EntryPoint:
ClearOAM
LoadTiles
MemClear current_frame, 1
MemClear current_frame, 2
MemClear current_floor, 2
MemClear first_basement_floor, 2
MemClear done_flag, 1
;; Initialize input_index
@ -39,67 +40,86 @@ CheckInput:
cp a, "("
jr z, GoingUp
jr GoingDown
cp a, ")"
jr z, GoingDown
jr GoingNowhere
GoingUp:
call IncrementCurrentFloor
jr GoingNowhere
GoingDown:
ld a, [current_floor]
ld b, a
ld a, [current_floor + 1]
and a, b
call z, SaveBasementFloor
call DecrementCurrentFloor
GoingNowhere:
IncrementWord input_index
ld de, input_end
ld a, [input_index]
sub a, d
cp a, d
jr nz, CheckInput
ld a, [input_index + 1]
sub a, e
cp a, e
jr nz, CheckInput
ld a, 1
ld [done_flag], a
Done:
halt
nop
jr Done
Done:
halt
nop
jr Done
IncrementCurrentFloor:
ld hl, current_floor
ld a, [hli]
ld a, [current_floor]
ld b, a
ld a, [hli]
ld a, [current_floor + 1]
ld c, a
inc bc
ld hl, current_floor
ld a, b
ld [hli], a
ld [current_floor], a
ld a, c
ld [hli], a
ld [current_floor + 1], a
ret
DecrementCurrentFloor:
ld hl, current_floor
ld a, [hli]
ld a, [current_floor]
ld b, a
ld a, [hli]
ld a, [current_floor + 1]
ld c, a
dec bc
ld hl, current_floor
ld a, b
ld [hli], a
ld [current_floor], a
ld a, c
ld [hli], a
ld [current_floor + 1], a
ret
SaveBasementFloor:
ld a, [first_basement_floor]
ld b, a
ld a, [first_basement_floor + 1]
or a, b
ret nz
ld a, [input_index]
ld [first_basement_floor], a
ld a, [input_index + 1]
ld [first_basement_floor + 1], a
ret
VBlankHandler:
@ -109,14 +129,19 @@ VBlankHandler:
push HL
IncrementFrameCount
PrintByteHex current_frame, 0, 0
PrintByte current_frame, 0, 1
PrintByteHex current_floor, 0, 2
PrintByteHex current_floor + 1, 2, 2
PrintString part_1_string, 0, 1
PrintString part_2_string, 0, 2
;; PrintByteHex current_frame, 0, 0
;; PrintByte current_frame, 0, 1
;; PrintByteHex current_floor, 0, 2
;; PrintByteHex current_floor + 1, 2, 2
ld a, [done_flag]
cp a, 1
jr z, NotDone
jp nz, NotDone
PrintString done_string, 3, 3
PrintByte current_floor + 1, 8, 1
;; PrintByte first_basement_floor + 1, 8, 2
NotDone:
pop HL
@ -126,8 +151,9 @@ NotDone:
reti
SECTION "High RAM", HRAM
current_floor: DS 2
done_flag: DS 1
current_floor: DS 2
first_basement_floor: DS 2
done_flag: DS 1
SECTION "Input", ROM0
input:
@ -138,4 +164,10 @@ done_string:
db "Done", 0
done_string_end:
part_1_string: db "Part 1: "
part_1_string_end:
part_2_string: db "Part 2: "
part_2_string_end:
INCLUDE "lib/tiles.asm"

View File

@ -13,7 +13,9 @@ fi
set -e
rgbasm -o $year/$day/main.o $source_file -H -Wall
rgbgfx -o lib/text.2bpp lib/text.png
rgbasm -o $year/$day/main.o $source_file -H -Wall -E
rgblink -o $year/$day/main.gb $year/$day/main.o
rgbfix -v -p 0xFF $year/$day/main.gb

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB