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
*=* "Day 01"
day01:
move_16_imm($03, $04, str_input)
jsr write_string
move_16_imm($03, $04, day01_input)
jsr write_string
move_16_imm($03, $04, str_converted)
move_16_imm($03, $04, str_title)
jsr write_string
move_16_imm($03, $04, day01_input)
move_16_imm($25, $26, buffer)
ldy #0
!line:
@ -26,45 +22,132 @@ day01:
i16_mul10($22, $23)
lda ($03), y
sec
sbc #'0'
i16_i8_add_a($22, $23)
iny
bne !digit-
inc $04
jmp !digit-
!break:
sty $24
lda $23
jsr print_hex_0x
ldy #0
lda $22
jsr print_hex
sta ($25), y
iny
lda $23
sta ($25), y
jsr print_newline
jsr print_carriage_return
lda #2
i16_i8_add_a($25, $26)
ldy $24
iny
bne !+
inc $04
!:
lda ($03), y
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:
// 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
day01_input:
.import text "../rust/inputs/day01_example"
.byte 0
str_input:
.text "# Input"
str_title:
.text "# Day 01, part 1:"
.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'
.text "# Converted"
.text "! Could not find a result"
.byte '\n', 0

View file

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

View file

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

View file

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