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

View File

@ -13,7 +13,9 @@ fi
set -e 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 rgblink -o $year/$day/main.gb $year/$day/main.o
rgbfix -v -p 0xFF $year/$day/main.gb 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