159 lines
2.3 KiB
NASM
159 lines
2.3 KiB
NASM
// vim: filetype=kickass
|
|
|
|
#import "math.inc"
|
|
|
|
BasicUpstart2(main)
|
|
|
|
* = $1000 "Main program"
|
|
.const SCREEN_RAM = $0400
|
|
.const COLOR_RAM = $d800
|
|
|
|
.const kernal_scinit = $ff81
|
|
.const kernal_chrout = $ffd2
|
|
.const kernal_write_byte = $e716
|
|
|
|
.const zp_temp = $02
|
|
.const cursor_pointer_lo = $05
|
|
.const cursor_pointer_hi = $06
|
|
|
|
.macro move_16_imm(dst, imm) {
|
|
lda #<imm
|
|
sta dst
|
|
lda #>imm
|
|
sta dst + 1
|
|
}
|
|
|
|
.macro u16_u16_move(dst, src) {
|
|
.for (var i = 0; i < 2; i++) {
|
|
lda src + i
|
|
sta dst + i
|
|
}
|
|
}
|
|
|
|
.macro u32_u32_move(dst, src) {
|
|
.for (var i = 0; i < 4; i++) {
|
|
lda src + i
|
|
sta dst + i
|
|
}
|
|
}
|
|
|
|
.macro u32_u32_move_imm(dst, imm) {
|
|
.for (var i = 0; i < 4; i++) {
|
|
lda #((imm >> (i * 8)) & $ff)
|
|
sta dst + i
|
|
}
|
|
}
|
|
|
|
test_tree:
|
|
move_16_imm($03, !str_test+)
|
|
jsr write_string
|
|
|
|
move_16_imm($03, $10)
|
|
jsr tree_insert
|
|
move_16_imm($03, $08)
|
|
jsr tree_insert
|
|
move_16_imm($03, $04)
|
|
jsr tree_insert
|
|
move_16_imm($03, $12)
|
|
jsr tree_insert
|
|
move_16_imm($03, $1337)
|
|
jsr tree_insert
|
|
|
|
|
|
move_16_imm($03, $08)
|
|
jsr tree_contains
|
|
bne !fail+
|
|
|
|
move_16_imm($03, $13)
|
|
jsr tree_contains
|
|
beq !fail+
|
|
|
|
move_16_imm($03, $12)
|
|
jsr tree_contains
|
|
bne !fail+
|
|
|
|
move_16_imm($03, $1337)
|
|
jsr tree_contains
|
|
bne !fail+
|
|
|
|
move_16_imm($03, $0420)
|
|
jsr tree_contains
|
|
beq !fail+
|
|
|
|
move_16_imm($03, !str_success+)
|
|
jsr write_string
|
|
|
|
rts
|
|
|
|
!fail:
|
|
u16_u16_move($10, $03)
|
|
|
|
move_16_imm($03, !str_fail+)
|
|
jsr write_string
|
|
|
|
lda $11
|
|
jsr print_hex_0x
|
|
lda $10
|
|
jsr print_hex
|
|
jsr print_newline
|
|
|
|
rts
|
|
|
|
!str_test:
|
|
.text "[ ] test-tree"
|
|
.byte '\r', 0
|
|
|
|
!str_fail:
|
|
.text "[!!]"
|
|
.byte '\n'
|
|
.text "Failed: "
|
|
.byte 0
|
|
|
|
!str_success:
|
|
.text "[OK]"
|
|
.byte '\n', 0
|
|
|
|
|
|
//
|
|
// main
|
|
//
|
|
main:
|
|
jsr clear_screen
|
|
|
|
// Swap out BASIC and kernal
|
|
sei
|
|
lda %00110000
|
|
sta $01
|
|
|
|
jsr generate_multiplication_tables
|
|
//jsr test_tree
|
|
|
|
|
|
jsr day01
|
|
|
|
!loop:
|
|
jmp !loop-
|
|
|
|
|
|
#import "day01.asm"
|
|
#import "screen.asm"
|
|
#import "math.asm"
|
|
#import "btree.asm"
|
|
|
|
* = * "Day 01 Input"
|
|
day01_input:
|
|
.import text "../rust/inputs/day01"
|
|
.byte 0
|
|
|
|
.align $100
|
|
* = * "Square table"
|
|
square1_lo:
|
|
.fill 512, 0
|
|
square1_hi:
|
|
.fill 512, 0
|
|
square2_lo:
|
|
.fill 512, 0
|
|
square2_hi:
|
|
.fill 512, 0
|
|
|