Move day01 to separate file and create move_16_imm macro

This commit is contained in:
Sijmen 2020-12-06 18:19:02 +01:00
parent 1e67af572d
commit b826af0205
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
2 changed files with 79 additions and 95 deletions

70
c64/day01.asm Normal file
View File

@ -0,0 +1,70 @@
// vim: filetype=kickass
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)
jsr write_string
move_16_imm($03, $04, day01_input)
ldy #0
!line:
lda #0
sta $22
sta $23
!digit:
lda ($03), y
cmp #'\n'
beq !break+
i16_mul10($22, $23)
lda ($03), y
sec
sbc #'0'
i16_i8_add_a($22, $23)
iny
jmp !digit-
!break:
sty $24
lda $23
jsr print_hex_0x
lda $22
jsr print_hex
jsr print_newline
jsr print_carriage_return
ldy $24
iny
lda ($03), y
bne !line-
!done:
rts
day01_input:
.import text "../rust/inputs/day01_example"
.byte 0
str_input:
.text "# Input"
.byte '\n', 0
str_converted:
.byte '\n'
.text "# Converted"
.byte '\n', 0

View File

@ -1,4 +1,5 @@
// vim: filetype=kickass
#import "math.inc"
* = $0801 // BASIC start address (#2049)
@ -18,6 +19,13 @@
.const cursor_pointer_lo = $05
.const cursor_pointer_hi = $06
.macro move_16_imm(dst_lo, dst_hi, src) {
lda #<src
sta dst_lo
lda #>src
sta dst_hi
}
//
// main
//
@ -34,104 +42,10 @@ main:
// inc $d020
jmp !loop-
string:
.text "The quick brown newline jumped over the lazy dog."
.byte '\n'
.byte 0
string_cr:
.text "The quick brown carriage return jumped over the lazy dog."
.byte '\r'
.byte 0
day01:
lda #<str_input
sta $03
lda #>str_input
sta $04
jsr write_string
lda #<day01_input
sta $03
lda #>day01_input
sta $04
jsr write_string
lda #<str_converted
sta $03
lda #>str_converted
sta $04
jsr write_string
lda #<day01_input
sta $03
lda #>day01_input
sta $04
.break
ldy #0
!line:
lda #0
sta $22
sta $23
!digit:
lda ($03), y
cmp #'\n'
beq !break+
i16_mul10($22, $23)
lda ($03), y
sec
sbc #'0'
i16_i8_add_a($22, $23)
iny
jmp !digit-
!break:
sty $24
lda $23
jsr print_hex_0x
lda $22
jsr print_hex
jsr print_newline
jsr print_carriage_return
ldy $24
iny
lda ($03), y
bne !line-
!done:
rts
day01_input:
.import text "../rust/inputs/day01_example"
.byte 0
str_input:
.text "# Input"
.byte '\n', 0
str_converted:
.byte '\n'
.text "# Converted"
.byte '\n', 0
buffer:
.fill $0100, 0
#import "day01.asm"
#import "screen.asm"