Make day 1 work

This commit is contained in:
Sijmen 2020-12-09 02:08:57 +01:00
parent b613ab8965
commit 7f72298c99
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
4 changed files with 115 additions and 34 deletions

View File

@ -1,16 +1,12 @@
// vim: filetype=kickass // vim: filetype=kickass
*=* "Day 01"
day01: day01:
move_16_imm($03, $04, str_input) move_16_imm($03, $04, str_title)
jsr write_string
move_16_imm($03, $04, day01_input)
jsr write_string
move_16_imm($03, $04, str_converted)
jsr write_string jsr write_string
move_16_imm($03, $04, day01_input) move_16_imm($03, $04, day01_input)
move_16_imm($25, $26, buffer)
ldy #0 ldy #0
!line: !line:
@ -26,45 +22,132 @@ day01:
i16_mul10($22, $23) i16_mul10($22, $23)
lda ($03), y lda ($03), y
sec sec
sbc #'0' sbc #'0'
i16_i8_add_a($22, $23) i16_i8_add_a($22, $23)
iny iny
bne !digit-
inc $04
jmp !digit- jmp !digit-
!break: !break:
sty $24 sty $24
lda $23 ldy #0
jsr print_hex_0x
lda $22 lda $22
jsr print_hex sta ($25), y
iny
lda $23
sta ($25), y
jsr print_newline lda #2
jsr print_carriage_return i16_i8_add_a($25, $26)
ldy $24 ldy $24
iny iny
bne !+
inc $04
!:
lda ($03), y lda ($03), y
bne !line- bne !line-
move_16_imm($25, $26, buffer)
move_16_imm($03, $04, str_parse_done)
jsr write_string
// Add every number to every other number
!outer:
move_16_imm($27, $28, buffer)
// $03..$04 = buffer[i]
ldy #0
lda ($25), y
sta $03
iny
lda ($25), y
sta $04
dey
lda ($25), y
bne !not_zero+
iny
lda ($25), y
bne !not_zero+
.break
jmp !error+
!not_zero:
// Subtract from 2020 to see what number we need
i16_imm_i16_sub($fb, $fc, 2020, $03, $04)
!inner:
// $fd..$fe = buffer[j]
ldy #0
lda ($27), y
sta $fd
iny
lda ($27), y
sta $fe
dey
lda ($27), y
bne !not_zero+
iny
lda ($27), y
bne !not_zero+
i16_inc($25, $26)
jmp !outer-
!not_zero:
// j++
lda #2
i16_i8_add_a($27, $28)
i16_i16_cmp_bne($fb, $fc, $fd, $fe, !inner-)
!done: !done:
// Multiply the results together
sec
jsr multiply_16bit_unsigned
move_16_imm($03, $04, str_calc_done)
jsr write_string
lda $25
sta udivmod32_dividend + 3
lda $24
sta udivmod32_dividend + 2
lda $23
sta udivmod32_dividend + 1
lda $22
sta udivmod32_dividend + 0
jsr print_decimal_u32
rts
!error:
move_16_imm($03, $04, str_no_result)
jsr write_string
rts rts
day01_input: str_title:
.import text "../rust/inputs/day01_example" .text "# Day 01, part 1:"
.byte 0
str_input:
.text "# Input"
.byte '\n', 0 .byte '\n', 0
str_converted: str_parse_done:
.text "* Finished parsing"
.byte '\n', 0
str_calc_done:
.text "* Finished calculating"
.byte '\n', 0
str_no_result:
.byte '\n' .byte '\n'
.text "# Converted" .text "! Could not find a result"
.byte '\n', 0 .byte '\n', 0

View File

@ -4,6 +4,7 @@
BasicUpstart2(main) BasicUpstart2(main)
* = $8000
.align $100 .align $100
* = * "Square table" * = * "Square table"
square1_lo: square1_lo:
@ -15,16 +16,17 @@ square2_lo:
square2_hi: square2_hi:
.fill 512, 0 .fill 512, 0
* = * "Day 1 input" * = * "Day 01 Input"
day01_input: day01_input:
.import text "../rust/inputs/day01" .import text "../rust/inputs/day01"
.byte 0 .byte 0
* = * "Day 01 Input End"
//* = $8000 "Cartridge ROM" //* = $8000 "Cartridge ROM"
//* = $a000 "Basic ROM" //* = $a000 "Basic ROM"
* = $c000 * = $c000 "Main program"
.const SCREEN_RAM = $0400 .const SCREEN_RAM = $0400
.const COLOR_RAM = $d800 .const COLOR_RAM = $d800
@ -56,17 +58,8 @@ main:
jsr generate_multiplication_tables jsr generate_multiplication_tables
// Test division by 10 jsr day01
lda #$cc
sta udivmod32_dividend + 0
lda #$28
sta udivmod32_dividend + 1
lda #$f9
sta udivmod32_dividend + 2
lda #$07
sta udivmod32_dividend + 3
jsr print_decimal_u32
!loop: !loop:
jmp !loop- jmp !loop-

View File

@ -1,5 +1,7 @@
// vim: filetype=kickass // vim: filetype=kickass
*=* "Math Routines"
.const T1=$03 .const T1=$03
.const T2=$fd .const T2=$fd
.const PRODUCT=$22 .const PRODUCT=$22

View File

@ -1,5 +1,7 @@
// vim: filetype=kickass // vim: filetype=kickass
*=* "Screen Routines"
// //
// clear_screen // clear_screen
// //
@ -141,6 +143,7 @@ write_string:
jsr print_hex jsr print_hex
} }
// Destroys: a, x, y, $03
print_hex_0x: print_hex_0x:
sta zp_temp sta zp_temp