aoc_omni/gb/2015/1/not_quite_lisp.asm

174 lines
2.5 KiB
NASM
Raw Permalink Normal View History

2024-12-29 08:29:02 -05:00
INCLUDE "lib/hardware.inc"
INCLUDE "lib/macros.inc"
SECTION "VBlank Interrupt", ROM0[$40]
jp VBlankHandler
SECTION "Header", ROM0[$100]
jp EntryPoint
ds $150 - @, 0 ; Make room for the header
SECTION "Init", ROM0[$150]
EntryPoint:
StartInit
ClearScreen
ClearOAM
LoadTiles
2024-12-29 18:10:38 -05:00
MemClear current_frame, 2
2024-12-29 12:51:16 -05:00
MemClear current_floor, 2
2024-12-29 18:10:38 -05:00
MemClear first_basement_floor, 2
2024-12-29 12:51:16 -05:00
MemClear done_flag, 1
;; Initialize input_index
ld bc, input
ld a, b
ld [input_index], a
ld a, c
ld [input_index + 1], a
2024-12-29 08:29:02 -05:00
FinishInit
ei
2024-12-29 12:51:16 -05:00
CheckInput:
ld a, [input_index]
ld h, a
ld a, [input_index + 1]
ld l, a
ld a, [hl]
cp a, "("
jr z, GoingUp
2024-12-29 18:10:38 -05:00
cp a, ")"
jr z, GoingDown
jr GoingNowhere
2024-12-29 12:51:16 -05:00
GoingUp:
call IncrementCurrentFloor
jr GoingNowhere
GoingDown:
2024-12-29 18:10:38 -05:00
ld a, [current_floor]
ld b, a
ld a, [current_floor + 1]
and a, b
call z, SaveBasementFloor
2024-12-29 12:51:16 -05:00
call DecrementCurrentFloor
GoingNowhere:
IncrementWord input_index
ld de, input_end
ld a, [input_index]
2024-12-29 18:10:38 -05:00
cp a, d
2024-12-29 12:51:16 -05:00
jr nz, CheckInput
ld a, [input_index + 1]
2024-12-29 18:10:38 -05:00
cp a, e
2024-12-29 12:51:16 -05:00
jr nz, CheckInput
ld a, 1
ld [done_flag], a
2024-12-29 18:10:38 -05:00
halt
nop
jr Done
2024-12-29 12:51:16 -05:00
Done:
2024-12-29 08:29:02 -05:00
halt
nop
jr Done
2024-12-29 12:51:16 -05:00
IncrementCurrentFloor:
2024-12-29 18:10:38 -05:00
ld a, [current_floor]
2024-12-29 12:51:16 -05:00
ld b, a
2024-12-29 18:10:38 -05:00
ld a, [current_floor + 1]
2024-12-29 12:51:16 -05:00
ld c, a
inc bc
ld a, b
2024-12-29 18:10:38 -05:00
ld [current_floor], a
2024-12-29 12:51:16 -05:00
ld a, c
2024-12-29 18:10:38 -05:00
ld [current_floor + 1], a
2024-12-29 12:51:16 -05:00
ret
DecrementCurrentFloor:
2024-12-29 18:10:38 -05:00
ld a, [current_floor]
2024-12-29 12:51:16 -05:00
ld b, a
2024-12-29 18:10:38 -05:00
ld a, [current_floor + 1]
2024-12-29 12:51:16 -05:00
ld c, a
dec bc
ld a, b
2024-12-29 18:10:38 -05:00
ld [current_floor], a
2024-12-29 12:51:16 -05:00
ld a, c
2024-12-29 18:10:38 -05:00
ld [current_floor + 1], a
2024-12-29 12:51:16 -05:00
ret
2024-12-29 18:10:38 -05:00
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
2024-12-29 12:51:16 -05:00
ret
2024-12-29 08:29:02 -05:00
VBlankHandler:
2024-12-29 12:51:16 -05:00
push AF
push BC
push DE
push HL
IncrementFrameCount
2024-12-29 18:10:38 -05:00
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
2024-12-29 12:51:16 -05:00
ld a, [done_flag]
cp a, 1
2024-12-29 18:10:38 -05:00
jp nz, NotDone
2024-12-29 12:51:16 -05:00
PrintString done_string, 3, 3
2024-12-29 18:10:38 -05:00
PrintByte current_floor + 1, 8, 1
;; PrintByte first_basement_floor + 1, 8, 2
2024-12-29 12:51:16 -05:00
NotDone:
pop HL
pop DE
pop BC
pop AF
2024-12-29 08:29:02 -05:00
reti
SECTION "High RAM", HRAM
2024-12-29 18:10:38 -05:00
current_floor: DS 2
first_basement_floor: DS 2
done_flag: DS 1
2024-12-29 08:29:02 -05:00
SECTION "Input", ROM0
input:
INCBIN "../data/2015/1/input.txt"
input_end:
2024-12-29 12:51:16 -05:00
done_string:
db "Done", 0
done_string_end:
2024-12-29 08:29:02 -05:00
2024-12-29 18:10:38 -05:00
part_1_string: db "Part 1: "
part_1_string_end:
part_2_string: db "Part 2: "
part_2_string_end:
2024-12-29 08:29:02 -05:00
INCLUDE "lib/tiles.asm"