159 lines
2.4 KiB
Plaintext
159 lines
2.4 KiB
Plaintext
|
|
|
|
const fl_zero 0x1
|
|
const fl_eq 0x2
|
|
const fl_be 0x4
|
|
const fl_lt 0x8
|
|
const fl_err 0xa
|
|
|
|
const vcd_base 0x2000
|
|
|
|
const kbd_status 0x1ffc
|
|
const kbd_code 0x1ffe
|
|
const kbd_flag_is_release 0x1
|
|
|
|
const counter 0x600
|
|
|
|
_start:
|
|
mov rsp, 0x1000
|
|
mov rbp, rsp
|
|
|
|
mov r0, 512
|
|
mov r1, 1
|
|
dskr r0, r1
|
|
|
|
; setup video character display (VCD)
|
|
; descriptor table structure:
|
|
; [addr + 0] memory map base
|
|
mov r0, vcd_base
|
|
mov [0x700], r0
|
|
lvcd 0x700
|
|
|
|
; setup keyboard (KBD)
|
|
; descriptor table structure:
|
|
; [addr + 0] status address
|
|
; [addr + 2] keycode address
|
|
; [addr + 4] keyboard interrupt handler
|
|
mov r0, kbd_status
|
|
mov [0x702], r0
|
|
mov r0, kbd_code
|
|
mov [0x704], r0
|
|
mov r0, key_press_int
|
|
mov [0x706], r0
|
|
lkbd 0x702
|
|
|
|
; character counter
|
|
mov r0, 0
|
|
mov [counter], r0
|
|
|
|
main_loop:
|
|
hlt
|
|
jmp main_loop
|
|
|
|
key_press_int:
|
|
mov r0, [kbd_status]
|
|
and r0, kbd_flag_is_release
|
|
jnz r0, .leave
|
|
|
|
mov r0, [counter]
|
|
add r0, vcd_base
|
|
mov r1, [kbd_code]
|
|
cmp r1, 44 ; spacebar
|
|
mov r2, rfl
|
|
and r2, fl_eq
|
|
jnz r2, .print_space
|
|
add r1, 61 ; scancode letter -> ascii
|
|
|
|
mov [rsp], r1
|
|
add rsp, 2
|
|
;call print_char
|
|
call print_u16
|
|
sub rsp, 2
|
|
|
|
jmp .leave
|
|
.print_space:
|
|
mov r1, ' '
|
|
|
|
mov [rsp], r1
|
|
add rsp, 2
|
|
call print_char
|
|
sub rsp, 2
|
|
|
|
.leave:
|
|
reti
|
|
|
|
print_char:
|
|
mov [rsp], rbp
|
|
add rsp, 2
|
|
mov rbp, rsp
|
|
|
|
mov r1, [rbp-6]
|
|
|
|
mov r0, [counter]
|
|
add r0, vcd_base
|
|
cmp r1, ' '
|
|
mov r2, rfl
|
|
and r2, fl_eq
|
|
jnz r2, .incr
|
|
mov byte [r0], r1
|
|
.incr:
|
|
mov r0, [counter]
|
|
add r0, 1
|
|
mov [counter], r0
|
|
.leave:
|
|
mov rsp, rbp
|
|
sub rsp, 2
|
|
mov rbp, [rsp]
|
|
ret
|
|
|
|
print_u16:
|
|
mov [rsp], rbp
|
|
add rsp, 2
|
|
mov rbp, rsp
|
|
|
|
mov r1, [rbp-6] ; value to print
|
|
mov r4, 0 ; place index
|
|
|
|
jmp .digits_cond
|
|
.digits_body:
|
|
mov r2, .places
|
|
add r2, r4
|
|
mov r2, [r2] ; place
|
|
|
|
mov r3, 0 ; place occurences
|
|
jmp .place_cond
|
|
.place_body:
|
|
add r3, 1
|
|
sub r1, r2
|
|
.place_cond:
|
|
cmp r2, r1
|
|
mov r0, rfl
|
|
and r0, fl_eq | fl_lt
|
|
jnz r0, .place_body
|
|
|
|
mov r0, r3
|
|
add r0, 48
|
|
mov [rsp], r0
|
|
add rsp, 2
|
|
call print_char
|
|
sub rsp, 2
|
|
|
|
add r4, 2
|
|
.digits_cond:
|
|
cmp r4, 10
|
|
mov r0, rfl
|
|
and r0, fl_lt
|
|
jnz r0, .digits_body
|
|
|
|
.leave:
|
|
mov rsp, rbp
|
|
sub rsp, 2
|
|
mov rbp, [rsp]
|
|
ret
|
|
|
|
.places:
|
|
dw 10000, 1000, 100, 10, 1
|
|
|
|
|
|
|