updates to dsa libs

This commit is contained in:
2025-06-26 00:51:20 +01:00
parent 620584488b
commit e9f04824ea
4 changed files with 152 additions and 26 deletions
+36
View File
@@ -29,6 +29,8 @@
// jmp print::print_word
//
include maths "../maths/core.dsa"
dw display: 0x20000
dw current: 0x20000
@@ -155,6 +157,40 @@ _print_hex_nibble_number:
addi rg1, 1
return
// ------------------------------------------
// print whitespace
print_whitespace:
push bpr
mov spr, bpr
ldw current, rg1
lli 0x20, rg0
stb rg0, rg1
addi rg1, 1
jmp _end
// ------------------------------------------
// print newline
print_newline:
push bpr
mov spr, bpr
ldw display, rg0
ldw current, rg1
sub rg1, rg0, rg0
lwi 80, rg2
push rg0
push rg2
call maths::divmod
pop rg2
addi rg2, 80
ldw display, rg1
add rg1, rg2, rg1
// _end saves the display state
jmp _end
// ------------------------------------------
// resets the cursor position on the screen to 0x20000. (0,0)
reset:
+21 -9
View File
@@ -1,18 +1,30 @@
fib_n:
pop ret
pop rg0 // n
include print "../io/print.dsa"
fib_n:
push bpr
mov spr, bpr
ldw bpr, rg1, 8 // load op 2
lli 0, rg1
lli 1, rg2
start:
mov rg1, rg2
add rg1, rg2, acc
pusha 4
push rg1
call print::print_hex_word
pop rg1
popa 4
mov rg2, rg1
mov acc, rg2
cmp rg0, zero
dec rg0
jgt start
jmp 4, ret
stw rg1, bpr, 8
mov bpr, spr
pop bpr
return
@@ -1,33 +1,28 @@
include print "./lib/io/print.dsa"
dw idt: 0xFFFF0000
dw stack: 0x10000
db interrupt: "INT: Hello world"
init:
// setup interrupt handlers
ldw idt, idr
lwi handle_hard_fault, rg0
stw rg0, idr, 4
// set up a stack.
ldw stack, bpr
mov bpr, spr
start:
ldw idt, idr
lwi handle_hard_fault, rg0
stw rg0, idr, 4
lwi 0x1234abcd, rg0
push rg0
call print::print_hex_word
pop zero
hlt
lwi 10, rg0
push rg0
call maths::fib_n
pop zero
hlt
// fault handler in case we fail DSA.
dw hard_fault_err: "FATAL: Illegal Instruction or Memory Access!"
handle_hard_fault:
call print::clear
call print::reset
lwi hard_fault_err, rg0
push rg0
call print::print
pop zero
hlt
hlt
+83
View File
@@ -0,0 +1,83 @@
include print "./lib/io/print.dsa"
dw idt: 0xFFFF0000
dw stack: 0x10000
init:
// setup interrupt handlers
ldw idt, idr
lwi handle_hard_fault, rg0
stw rg0, idr, 4
// set up a stack.
ldw stack, bpr
mov bpr, spr
db string: "I won, the game!"
db hexbyte: 0xab
dw hexword: 0x1234abcd
db replace: "I lost"
start:
// test print string
lwi string, rg0
push rg0
call print::print
pop zero
// test print hex byte.
ldb hexbyte, rg0
push rg0
call print::print_hex_byte
pop zero
// test print hex word.
ldw hexword, rg0
push rg0
call print::print_hex_word
pop zero
// test print char
lli 0x40, rg0 // print @
push rg0
call print::print_byte
pop zero
// test newline
call print::print_newline
lwi string rg0
push rg0
call print::print
// test print word
lwi 0x31323334, rg0 // print 1234
push rg0
call print::print_word
pop zero
// test reset cursor pos
call print::reset
// test print string at reset pos
lwi replace, rg0
push rg0
call print::print
pop zero
lli 3, rg0
ldw rg0, rg0
hlt
// fault handler in case we fail DSA.
dw hard_fault_err: "FATAL: Illegal Instruction or Memory Access!"
handle_hard_fault:
call print::clear
call print::reset
lwi hard_fault_err, rg0
push rg0
call print::print
pop zero
hlt