Add day 5 and fancy menu

This commit is contained in:
Sijmen 2020-12-15 03:26:53 +01:00
parent 6ba6c568df
commit e5e3a10fb5
Signed by: vijfhoek
GPG Key ID: DAF7821E067D9C48
10 changed files with 672 additions and 39 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ c64/*.prg
c64/tests/
inputs/
.vim/

View File

@ -20,6 +20,8 @@
.const inner_value = $fd
day01:
jsr tree_clear
move_16_imm($03, str_title)
jsr write_string

193
c64/day05.asm Normal file
View File

@ -0,0 +1,193 @@
// vim: filetype=kickass
* = * "Day 05"
//
// day05
//
// Destroys: $03..04, $08..09, $0a..0d
//
.const column_min = $0a
.const column_max = $0b
.const row_min = $0c
.const row_max = $0d
.const input_ptr = $08
.const max_value = $0e
.const min_value = $2c
// Conflicts with tree_values_lo and _hi
.const buffer = $c800 // $c800..cfff
day05:
move_16_imm($03, !str_title+)
jsr write_string
lda #0
tay
!loop:
.for (var i = $0000; i < $0800; i += $0100)
sta buffer + i, y
iny
bne !loop-
move_16_imm(input_ptr, day05_input)
move_16_imm(max_value, 0)
move_16_imm(min_value, $ffff)
ldy #0
!init_vars:
lda #128
sta row_max
lda #8
sta column_max
lda #0
sta row_min
sta column_min
!loop:
lda ($08), y
// TODO could be optimized easily
cmp #'F'
bne !else+
// lower half
lda row_min
adc row_max
lsr
sta row_max
jmp !next+
!else:
cmp #'B'
bne !else+
// upper half
lda row_min
adc row_max
lsr
sta row_min
jmp !next+
!else:
cmp #'L'
bne !else+
// lower half column
lda column_min
adc column_max
lsr
sta column_max
jmp !next+
!else:
cmp #'R'
bne !else+
// upper half column
lda column_min
adc column_max
lsr
sta column_min
jmp !next+
!else:
cmp #'\n'
bne !else+
lda #0; sta row_min + 1
// row_min *= 8
lda row_min
asl; rol row_min + 1
asl; rol row_min + 1
asl; rol row_min + 1
// row_min |= column_min
ora column_min
sta row_min
lda row_min + 1
cmp max_value + 1
bcc !not_max+
bne !max+
lda row_min
cmp max_value
bcc !not_max+
!max:
u16_u16_move(max_value, row_min)
!not_max:
lda min_value + 1
cmp row_min + 1
bcc !not_max+
bne !max+
lda min_value
cmp row_min
bcc !not_max+
!max:
u16_u16_move(min_value, row_min)
!not_max:
lda row_min + 1
clc
adc #>buffer
sta row_min + 1
ldx #0
lda #1
sta (row_min, x)
iny
bne !+
//.break
inc $09
!:
jmp !init_vars-
!else:
jmp !done+
!next:
iny
bne !+
//.break
inc $09
!:
jmp !loop-
!done:
u16_u16_move(udivmod32_dividend, max_value)
move_16_imm(udivmod32_dividend + 2, 0)
jsr print_decimal_u32
move_16_imm($03, str_part2)
jsr write_string
lda #>buffer
clc
adc min_value + 1
sta column_min + 1
// Find the first free seat
ldy min_value
!loop:
y_buf_inc(column_min)
lda (column_min), y
bne !loop-
sty udivmod32_dividend
lda column_min + 1
sec
sbc #>buffer
sta udivmod32_dividend + 1
move_16_imm(udivmod32_dividend + 2, 0)
jsr print_decimal_u32
rts
!newline:
rts
!str_title:
.text "# Day 05"
.byte '\n', '\n'
.text "Part 1: "
.byte 0

View File

@ -8,10 +8,6 @@
.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
@ -59,7 +55,6 @@ test_tree:
move_16_imm($03, $1337)
jsr tree_insert
move_16_imm($03, $08)
jsr tree_contains
bne !fail+
@ -118,31 +113,37 @@ test_tree:
// main
//
main:
jsr clear_screen
// Swap out BASIC and kernal
sei
lda %00110000
lda #$35
sta $01
lda #49
sta $07
jsr setup_interrupt
jsr clear_screen
jsr draw_menu
jsr generate_multiplication_tables
jsr tree_clear
//jsr test_tree
jsr day01
!loop:
jmp !loop-
!:
jsr menu_update
jmp !-
#import "day01.asm"
#import "day05.asm"
#import "screen.asm"
#import "math.asm"
#import "btree.asm"
#import "menu.asm"
* = * "Day 01 Input"
* = * "Day 01 Input"
day01_input:
.import text "../rust/inputs/day01"
.byte 0
* = * "Day 05 input"
day05_input:
.import text "../inputs/05"
.byte 0

View File

@ -352,12 +352,12 @@ generate_multiplication_tables:
// TODO could probably be optimized further
//
// Input:
// - udivmod32_dividend: LSB of the dividend.
// - udivmod32_divisor: LSB of the divisor.
// - udivmod32_dividend ($10..$13): LSB of the dividend.
// - udivmod32_divisor ($14..$17): LSB of the divisor.
//
// Output:
// - udivmod32_result: LSB of the division result.
// - udivmod32_remainder: LSB of the modulo result.
// - udivmod32_result ($18..1b): LSB of the division result.
// - udivmod32_remainder ($1c..$1f): LSB of the modulo result.
//
// Destroys: a, $20..$2b
//
@ -515,4 +515,3 @@ udivmod32:
bne !do_start-
rts

View File

@ -3,6 +3,7 @@
.const square1_hi = $c200
.const square2_lo = $c400
.const square2_hi = $c600
.const pearson_table = $c800
.const tree_values_lo = $c900
.const tree_values_hi = $ca00
@ -58,7 +59,7 @@
// Output:
// - $24..$25 - 16-bit unsigned result
//
// Destroys: a, x, $22..$25, $fd, $fe
// Destroys: a, x, $22, $23, $fd, $fe
//
.macro u16_div10() {
lda #$19
@ -70,6 +71,7 @@
jsr multiply_16bit_unsigned
}
// Destroys: zp_temp
.macro i8_mul5_a() {
sta zp_temp
asl
@ -109,6 +111,7 @@
i16_i16_add(dst, $fd)
}
// Destroys: -
.macro u32_mul2(lsb) {
asl lsb + 0
rol lsb + 1
@ -116,6 +119,7 @@
rol lsb + 3
}
// Destroys: a
.macro u32_mul10(lsb) {
u32_mul2(lsb)
@ -134,6 +138,7 @@
i32_i32_add(lsb, $2c)
}
// Destroys: a
.macro i32_i16_add(dst, src) {
clc
lda dst + 0
@ -147,6 +152,7 @@
!:
}
// Destroys: a
.macro i32_i32_add(dst, src) {
clc
lda dst + 0
@ -184,12 +190,29 @@
sta dst + 1
}
// Destroys: a, dst_lo, dst_hi
// Destroys: a
.macro i16_inc(dst) {
lda #1
i16_i8_add_a(dst)
}
.macro y_buf_inc(buffer) {
iny
bne !+
inc buffer + 1
!:
}
// Destroys: a
.macro y_buf_dec(buffer) {
tya
bne !+
dec buffer + 1
!:
dey
}
// Destroys: a
.macro i16_i16_sub_imm(dst_lo, dst_hi, src_lo, src_hi, imm) {
sec
@ -235,3 +258,17 @@
cmp b + 1
bne target
}
.macro pearson_hash(dst, buffer) {
lda #0
sta dst
loop:
lda buffer, y
beq end
eor dst
tax
lda pearson_table, x
sta dst
jmp loop
end:
}

296
c64/menu.asm Normal file
View File

@ -0,0 +1,296 @@
// vim: filetype=kickass
.const PA = $dc00
.const PB = $dc01
.const DDRA = $dc02
.const DDRB = $dc03
* = * "Menu Routines"
//
// draw_menu
//
draw_menu:
lda $d018
and #%11110001
ora #%00000100
sta $d018
ldy #$fa + 1
sty $d020
sty $d021
!:
// TODO Compression for the characters
lda menu_characters + $0000 - 1, y
sta SCREEN_RAM + $0000 - 1, y
lda menu_characters + $00fa - 1, y
sta SCREEN_RAM + $00fa - 1, y
lda menu_characters + $01f4 - 1, y
sta SCREEN_RAM + $01f4 - 1, y
lda menu_characters + $02ee - 1, y
sta SCREEN_RAM + $02ee - 1, y
lda menu_colors + $0000 - 1, y
sta COLOR_RAM + $0000 - 1, y
lsr; lsr; lsr; lsr
sta COLOR_RAM + $00fa - 1, y
lda menu_colors + $00fa - 1, y
sta COLOR_RAM + $01f4 - 1, y
lsr; lsr; lsr; lsr
sta COLOR_RAM + $02ee - 1, y
dey
bne !-
rts
//
// menu_update
//
menu_update:
lda PA
lsr
bcs !not_up+
lda $07
sec
sbc #8
cmp #49
bcc !wait+
sta $07
jmp !wait+
!not_up:
lsr
bcs !not_down+
lda $07
clc
adc #08
cmp #242
bcs !wait+
sta $07
jmp !wait+
!not_down:
lsr
lsr
lsr
bcs !done+
sei
jsr clear_screen
lda $07
lsr; lsr; lsr
sec
sbc #6
asl
tay
// Modify JSR instruction to jump to the right day
lda !days+, y
sta !jump+ + 1
lda !days+ + 1, y
sta !jump+ + 2
!jump:
jsr !done+
!wait:
ldy #80
ldx #0
!:
!:
dex
bne !-
dey
bne !--
!done:
rts
!days:
.word day01 // 1
.word 0 // 2
.word 0 // 3
.word 0 // 4
.word day05 // 5
.word 0 // 6
.word 0 // 7
.word 0 // 8
.word 0
.word 0 // 9
.word 0
.word 0
.word 0 // 15
.word 0
.word 0 // 10
.word 0 // 14
.word 0
.word 0 // 11
.word 0 // 13
.word 0
.word 0 // 12
.word 0
.word 0
.word 0
.word 0
//
// setup_interrupt
//
setup_interrupt:
sei
SetRasterInterrupt(menu_irq)
move_16_imm($fffa, nmi_nop)
lda #$7f
sta $dc0d
sta $dd0d
lda #$01
sta $d019
sta $d01a
lda #$35
sta $01
cli
rts
menu_irq:
pha
txa
pha
tya
pha
StabilizeRaster()
ldy #11
sty $d020
sty $d021
ldy #90
!:
dey
bne !-
ldy #0
sty $d021
sty $d020
SetRasterInterrupt(menu_irq)
asl $d019
pla
tay
pla
tax
pla
rti
nmi_nop:
rti
.macro SetRasterInterrupt(address) {
move_16_imm($fffe, address)
lda $d011
and #$7f
sta $d011
lda $07
sta $d012
}
.macro StabilizeRaster() {
move_16_imm($fffe, stabilized_irq)
inc $d012
asl $d019
tsx
cli
nop
nop
nop
nop
nop
nop
nop
nop
nop
stabilized_irq:
txs
sei
ldx #6
!:
dex
bne !-
bit $00
lda $d012
cmp $d012
beq *+2
}
.align $0100
* = * "Menu Data"
menu_characters:
.byte $20,$20,$20,$20,$6f,$6f,$6f,$52,$52,$52,$46,$46,$46,$46,$42,$46,$46,$46,$46,$52,$52,$52,$6f,$6f,$6f,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$31,$2a,$2a
.byte $45,$45,$77,$77,$20,$2e,$27,$20,$20,$2d,$20,$20,$2d,$20,$20,$4d,$2d,$20,$2e,$27,$27,$68,$20,$68,$20,$77,$77,$45,$45,$44,$43,$40,$46,$52,$6f,$20,$20,$32,$20,$20
.byte $68,$20,$20,$68,$20,$27,$2e,$27,$2e,$20,$2d,$20,$20,$20,$2d,$20,$4d,$20,$2d,$27,$27,$3a,$20,$20,$68,$20,$68,$20,$20,$20,$68,$20,$20,$68,$20,$20,$20,$33,$20,$20
.byte $20,$20,$68,$20,$68,$20,$20,$68,$20,$27,$27,$2e,$2e,$27,$27,$27,$64,$1b,$1d,$2e,$27,$20,$20,$68,$20,$20,$20,$20,$68,$20,$20,$20,$68,$20,$68,$20,$20,$34,$20,$20
.byte $27,$2e,$20,$68,$20,$20,$68,$20,$20,$68,$20,$20,$64,$64,$6f,$4e,$63,$27,$27,$20,$20,$68,$20,$20,$68,$20,$20,$68,$20,$20,$20,$20,$20,$68,$20,$20,$20,$35,$2a,$2a
.byte $27,$20,$20,$2e,$2e,$6f,$6f,$6f,$6f,$6f,$4e,$77,$63,$63,$20,$20,$68,$20,$20,$68,$20,$20,$68,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$36,$20,$20
.byte $68,$20,$3a,$1b,$1d,$27,$2e,$20,$20,$20,$68,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$37,$20,$20
.byte $20,$20,$20,$27,$2e,$4d,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$38,$20,$20
.byte $20,$20,$68,$20,$20,$20,$4d,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$68,$20,$4d,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$39,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$4d,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$2e,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$4d,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$3a,$27,$27,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$4d,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$64,$64,$64,$64,$20,$20,$27,$2e,$20,$2c,$20,$31,$35,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$4d,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$63,$63,$63,$63,$4d,$20,$20,$3a,$20,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$4d,$20,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$2e,$4d,$27,$20,$2c,$20,$20,$31,$30,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$4d,$20,$20,$20,$2e,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$27,$2e,$1b,$1d,$20,$2c,$20,$31,$34,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$4d,$27,$27,$2c,$3a,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$64,$4e,$27,$2e,$2e,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$3a,$1b,$1d,$2e,$2e,$27,$20,$20,$20,$20,$20,$20,$20,$20,$20,$4e,$63,$68,$20,$20,$20,$27,$20,$31,$31,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$27,$27,$4d,$64,$64,$20,$20,$68,$20,$20,$20,$20,$20,$4e,$20,$20,$20,$20,$20,$20,$20,$20,$31,$33,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$63,$63,$4d,$64,$64,$20,$20,$20,$20,$4e,$68,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$63,$63,$4d,$64,$64,$4e,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$31,$32,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$63,$63,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$68,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
.byte $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$2e,$20,$2e,$2e,$20,$20,$20,$2e,$27,$20,$2e,$2e,$20,$20,$20,$20,$20,$20,$20,$20,$20
menu_colors:
.byte $6f, $0e, $6e, $0e, $0e, $0e, $0e, $0e, $0e, $0e, $0e, $6e, $0e, $0e, $02, $0e, $0e, $0e, $0e, $0e // 0;00 - 0;20 | 6;10 - 6;30
.byte $0e, $0e, $0e, $0e, $0e, $00, $00, $f0, $00, $00, $00, $00, $00, $50, $50, $10, $e0, $6f, $07, $07 // 0;20 - 1;00 | 6;30 - 7;10
.byte $0e, $0e, $0e, $0e, $0e, $01, $61, $0e, $0e, $61, $00, $00, $01, $00, $01, $01, $01, $0e, $01, $01 // 1;00 - 1;20 | 7;10 - 7;30
.byte $01, $06, $00, $06, $0e, $0e, $0e, $fe, $0e, $0e, $0e, $0e, $6e, $0e, $0e, $00, $10, $0f, $00, $60 // 1;20 - 2;00 | 7;30 - 8;10
.byte $06, $0e, $0e, $06, $0e, $01, $01, $01, $01, $0e, $01, $00, $00, $00, $01, $0e, $01, $0e, $01, $01 // 2;00 - 2;20 | 8;10 - 8;30
.byte $01, $01, $00, $00, $06, $00, $06, $00, $00, $00, $06, $03, $03, $06, $03, $60, $00, $1f, $00, $00 // 2;20 - 3;00 | 8;30 - 9;10
.byte $0e, $0e, $06, $0e, $06, $0e, $0e, $06, $0e, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01 // 3;00 - 3;20 | 9;10 - 9;30
.byte $01, $00, $00, $06, $00, $00, $00, $f0, $06, $00, $00, $00, $06, $0e, $06, $00, $00, $0f, $10, $00 // 3;20 - 4;00 | 9;30 - 10;10
.byte $65, $05, $00, $06, $0e, $0e, $06, $0e, $0e, $06, $01, $01, $01, $01, $01, $01, $01, $01, $01, $00 // 4;00 - 4;20 | 10;10 - 10;30
.byte $00, $06, $00, $00, $56, $00, $00, $06, $00, $00, $00, $00, $00, $06, $00, $00, $00, $0f, $07, $17 // 4;20 - 5;00 | 10;30 - 11;10
.byte $05, $00, $00, $05, $05, $01, $01, $01, $01, $01, $01, $01, $01, $01, $01, $00, $06, $00, $00, $06 // 5;00 - 5;20 | 11;10 - 11;30
.byte $00, $50, $56, $50, $00, $00, $00, $00, $00, $06, $00, $00, $00, $00, $00, $00, $00, $0f, $00, $60 // 5;20 - 6;00 | 11;30 - 12;10
.byte $16, $00, $05, $01, $01, $05, $05, $05, $00, $00 // 6;00 - 6;10 | 12;10 - 12;20
.byte $00, $00, $00, $00, $00, $01, $f1, $f1, $01, $00, $00, $05, $05, $0e, $05, $00, $0f, $0f, $00, $00 // 12;20 - 13;00 | 18;30 - 19;10
.byte $00, $00, $00, $00, $00, $00, $60, $10, $10, $10, $10, $11, $00, $06, $00, $00, $10, $60, $00, $00 // 13;00 - 13;20 | 19;10 - 19;30
.byte $00, $00, $00, $00, $60, $01, $01, $01, $01, $01, $00, $00, $05, $0e, $0b, $00, $00, $00, $00, $00 // 13;20 - 14;00 | 19;30 - 20;10
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $06, $10, $10, $11, $10, $10, $10, $06, $00, $00, $00 // 14;00 - 14;20 | 20;10 - 20;30
.byte $00, $00, $00, $01, $00, $00, $f0, $f0, $00, $05, $01, $05, $0e, $05, $00, $00, $0f, $0f, $00, $00 // 14;20 - 15;00 | 20;30 - 21;10
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $60, $11, $10, $00, $00, $05, $00, $00 // 15;00 - 15;20 | 21;10 - 21;30
.byte $00, $00, $60, $00, $00, $06, $00, $00, $00, $05, $05, $01, $01, $0e, $05, $00, $0f, $0f, $00, $00 // 15;20 - 16;00 | 21;30 - 22;10
.byte $00, $00, $00, $00, $00, $00, $00, $60, $00, $10, $00, $06, $00, $00, $01, $05, $05, $05, $05, $00 // 16;00 - 16;20 | 22;10 - 22;30
.byte $00, $06, $00, $00, $00, $00, $00, $00, $00, $01, $01, $05, $05, $05, $00, $00, $00, $00, $00, $00 // 16;20 - 17;00 | 22;30 - 23;10
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $10, $10, $10, $00, $05, $01, $01, $05, $05, $05, $00 // 17;00 - 17;20 | 23;10 - 23;30
.byte $00, $00, $00, $00, $00, $00, $00, $00, $01, $01, $06, $00, $00, $00, $05, $00, $0f, $0f, $00, $00 // 17;20 - 18;00 | 23;30 - 24;10
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $50, $e0, $50, $50, $00, $05, $05, $51, $51, $01, $50 // 18;00 - 18;20 | 24;10 - 24;30
.byte $50, $06, $00, $00, $00, $00, $00, $01, $00, $00 // 18;20 - 18;30 | 24;30 - 25;00

1
c64/menu.pe Normal file

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,11 @@
// Destroys: a, y
//
clear_screen:
lda #$06
sta $d021
lda #$0e
sta $d020
ldy #0
!loop:
@ -49,12 +54,13 @@ clear_screen:
//
print_newline:
sec
lda $05
lda cursor_pointer_lo
adc #40
sta cursor_pointer_lo
bcc !done+
inc cursor_pointer_hi
!done:
inc cursor_pointer_hi
!done:
// fallthrough
//
@ -141,7 +147,7 @@ write_string:
jsr print_hex
}
// Destroys: a, x, y, $03
// Destroys: a, x, y, zp_temp ($02)
print_hex_0x:
sta zp_temp
@ -187,6 +193,10 @@ print_hex:
.text "0123456789ABCDEF"
// Input:
// - $03..$04: The number to print
//
// Destroys: a, y, $24..$25
print_decimal_u16:
ldy #6
@ -196,21 +206,12 @@ print_decimal_u16:
!loop:
u16_div10()
lda $24
sta $22
lda $25
sta $23
u16_u16_move($22, $24)
i16_mul10($22)
i16_i16_sub($22, $23, $03, $04, $22, $23)
lda $24
sta $03
lda $25
sta $04
u16_u16_move($03, $24)
lda $22
clc
@ -246,6 +247,9 @@ print_decimal_u16:
//
// Input:
// - udivmod32_dividend - Number to print
//
// Destroys: a, y, $02..$04, $10..$2b
//
print_decimal_u32:
ldy #11
@ -305,3 +309,31 @@ print_decimal_u32:
!buffer:
.fill 12, 0
wait_space_then_reset:
ldx #$ff
stx $dc02
ldy #$00
sty $dc03
!:
lda #$7f
sta $dc00
lda $dc01
and #$10
bne !-
move_16_imm($03, !str_resetting+)
jsr write_string
// Reset
lda #%00110111
sta $01
jmp $fce2
rts
!str_resetting:
.byte '\n'
.text "Resetting..."
.byte 0

70
c64/zp.org Normal file
View File

@ -0,0 +1,70 @@
| Address | i8_div5_a | u16_div10 | i8_mul5_a | i16_mul10 | multiply_8bit_* | multiply_16bit_* | multiply_32bit_* | udivmod32 | print_newline | write_string | print_decimal_u16 | print_decimal_u32 | draw_menu | day05 |
| | | | | | | | | | print_carriage_return | | | | | |
| | | | | | | | | | print_hex_0x | | | | | |
| | | | | | | | | | print_hex | | | | | |
|---------+-----------+-----------+-----------+-----------+-----------------+------------------+------------------+-----------+-----------------------+--------------+-------------------+-------------------+-----------+-----------|
| <r> | | | | | | | | | | | | | | |
| $02 | temporary | | temporary | | | | | | temporary | temporary | temporary | temporary | | |
| $03 | | input | | | | | | | | input | input (destroyed) | temporary | temporary | temporary |
| $04 | | input | | | | | | | | input | input (destroyed) | temporary | temporary | temporary |
| $05 | | | | | | | | | state | state | state | state | state | state |
| $06 | | | | | | | | | state | state | state | state | state | state |
| $07 | | | | | | | | | | | | | state | |
| $08 | | | | | | | | | | | | | | temporary |
| $09 | | | | | | | | | | | | | | temporary |
| $0a | | | | | | | | | | | | | | temporary |
| $0b | | | | | | | | | | | | | | temporary |
| $0c | | | | | | | | | | | | | | temporary |
| $0d | | | | | | | | | | | | | | temporary |
| $0e | | | | | | | | | | | | | | temporary |
| $0f | | | | | | | | | | | | | | |
| $10 | | | | | | | | input | | | | input (destroyed) | | |
| $11 | | | | | | | | input | | | | input (destroyed) | | |
| $12 | | | | | | | | input | | | | input (destroyed) | | |
| $13 | | | | | | | | input | | | | input (destroyed) | | |
| $14 | | | | | | | | input | | | | temporary | | |
| $15 | | | | | | | | input | | | | temporary | | |
| $16 | | | | | | | | input | | | | temporary | | |
| $17 | | | | | | | | input | | | | temporary | | |
| $18 | | | | | | | | output | | | | temporary | | |
| $19 | | | | | | | | output | | | | temporary | | |
| $1a | | | | | | | | output | | | | temporary | | |
| $1b | | | | | | | | output | | | | temporary | | |
| $1c | | | | | | | | output | | | | temporary | | |
| $1d | | | | | | | | output | | | | temporary | | |
| $1e | | | | | | | | output | | | | temporary | | |
| $1f | | | | | | | | output | | | | temporary | | |
| $20 | | | | | | | | temporary | | | | temporary | | |
| $21 | | | | | | | | temporary | | | | temporary | | |
| $22 | | temporary | | | output | output | temporary | temporary | | | temporary | temporary | | |
| $23 | | temporary | | | output | output | temporary | temporary | | | temporary | temporary | | |
| $24 | | output | | | | output | temporary | temporary | | | temporary | temporary | | |
| $25 | | output | | | | output | temporary | temporary | | | temporary | temporary | | |
| $26 | | | | | input | input | temporary | temporary | | | | temporary | | |
| $27 | | | | | | input | temporary | temporary | | | | temporary | | |
| $28 | | | | | | | | temporary | | | | temporary | | |
| $29 | | | | | | | | temporary | | | | temporary | | |
| $2a | | | | | | | | temporary | | | | temporary | | |
| $2b | | | | | | | | temporary | | | | temporary | | |
| $2c | | | | | | | | | | | | | | |
| $2d | | | | | | | | | | | | | | |
| $2e | | | | | | | | | | | | | | |
| $2f | | | | | | | | | | | | | | |
| $30 | | | | | | | input | | | | | | | |
| $31 | | | | | | | input | | | | | | | |
| $32 | | | | | | | input | | | | | | | |
| $33 | | | | | | | input | | | | | | | |
| $34 | | | | | | | input | | | | | | | |
| $35 | | | | | | | input | | | | | | | |
| $36 | | | | | | | input | | | | | | | |
| $37 | | | | | | | input | | | | | | | |
| $38 | | | | | | | output | | | | | | | |
| $39 | | | | | | | output | | | | | | | |
| $3a | | | | | | | output | | | | | | | |
| $3b | | | | | | | output | | | | | | | |
| $3c | | | | | | | output | | | | | | | |
| $3d | | | | | | | output | | | | | | | |
| $3e | | | | | | | output | | | | | | | |
| $3f | | | | | | | output | | | | | | | |
| $fd | | | | temporary | input | input | temporary | | | | temporary | | | |
| $fe | | | | temporary | | input | temporary | | | | temporary | | | |