diff --git a/c64/day01.asm b/c64/day01.asm new file mode 100644 index 0000000..f9d33be --- /dev/null +++ b/c64/day01.asm @@ -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 diff --git a/c64/main.asm b/c64/main.asm index 0f578b5..ba9a370 100644 --- a/c64/main.asm +++ b/c64/main.asm @@ -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_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 $04 - jsr write_string - - lda #day01_input - sta $04 - jsr write_string - - lda #str_converted - sta $04 - jsr write_string - - - 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"