forked from koniifer/ableos
200 lines
3.8 KiB
Plaintext
200 lines
3.8 KiB
Plaintext
|
import "sysdata/test-programs/hblib/std" as std;
|
||
|
|
||
|
fn print_register(reg){
|
||
|
std::Debug("-----------------");
|
||
|
let c0 = declabel();
|
||
|
let c1 = declabel();
|
||
|
let c2 = declabel();
|
||
|
let c3 = declabel();
|
||
|
let c4 = declabel();
|
||
|
let c5 = declabel();
|
||
|
let c6 = declabel();
|
||
|
let c7 = declabel();
|
||
|
let c8 = declabel();
|
||
|
let c9 = declabel();
|
||
|
let ca = declabel();
|
||
|
let cb = declabel();
|
||
|
let cc = declabel();
|
||
|
let cd = declabel();
|
||
|
let ce = declabel();
|
||
|
let cf = declabel();
|
||
|
let end = declabel();
|
||
|
|
||
|
cp(r32, reg);
|
||
|
li64(r35, 16);
|
||
|
|
||
|
let next_loop = label();
|
||
|
|
||
|
addi64(r35, r35, -1);
|
||
|
li64(r37, 4);
|
||
|
mul64(r36, r35, r37);
|
||
|
sru64(r34, r32, r36);
|
||
|
|
||
|
andi(r34, r34, 0xf);
|
||
|
li64(r33, 0);
|
||
|
|
||
|
jeq(r34, r33, c0);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c1);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c2);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c3);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c4);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c5);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c6);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c7);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c8);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, c9);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, ca);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, cb);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, cc);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, cd);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, ce);
|
||
|
addi64(r33, r33, 1);
|
||
|
jeq(r34, r33, cf);
|
||
|
|
||
|
std::Error("This should be an invalid state");
|
||
|
|
||
|
let next = label();
|
||
|
jne(r0, r35, next_loop);
|
||
|
jeq(r0, r0, end);
|
||
|
|
||
|
here(c0);
|
||
|
std::Debug("0");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c1);
|
||
|
std::Debug("1");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c2);
|
||
|
std::Debug("2");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c3);
|
||
|
std::Debug("3");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c4);
|
||
|
std::Debug("4");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c5);
|
||
|
std::Debug("5");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c6);
|
||
|
std::Debug("6");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c7);
|
||
|
std::Debug("7");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c8);
|
||
|
std::Debug("8");
|
||
|
jeq(r0, r0, next);
|
||
|
here(c9);
|
||
|
std::Debug("9");
|
||
|
jeq(r0, r0, next);
|
||
|
here(ca);
|
||
|
std::Debug("A");
|
||
|
jeq(r0, r0, next);
|
||
|
here(cb);
|
||
|
std::Debug("B");
|
||
|
jeq(r0, r0, next);
|
||
|
here(cc);
|
||
|
std::Debug("C");
|
||
|
jeq(r0, r0, next);
|
||
|
here(cd);
|
||
|
std::Debug("D");
|
||
|
jeq(r0, r0, next);
|
||
|
here(ce);
|
||
|
std::Debug("E");
|
||
|
jeq(r0, r0, next);
|
||
|
here(cf);
|
||
|
std::Debug("F");
|
||
|
jeq(r0, r0, next);
|
||
|
|
||
|
here(end);
|
||
|
std::Debug("-----------------");
|
||
|
}
|
||
|
|
||
|
fn get_keyboard_status(){
|
||
|
li64(r1, 5);
|
||
|
li64(r2, 0x64);
|
||
|
eca();
|
||
|
}
|
||
|
|
||
|
fn get_keyboard_input(){
|
||
|
li64(r1, 5);
|
||
|
li64(r2, 0x60);
|
||
|
eca();
|
||
|
}
|
||
|
|
||
|
fn is_keyup(rb, ra){
|
||
|
li64(rb, 15);
|
||
|
sru64(rb, ra, rb);
|
||
|
andi(rb, rb, 1);
|
||
|
}
|
||
|
|
||
|
fn dump_registers(){
|
||
|
li64(r1, 0xff);
|
||
|
eca();
|
||
|
}
|
||
|
|
||
|
fn to_ascii(rb, ra){
|
||
|
let str = data::str(
|
||
|
" 1234567890-= " +
|
||
|
"qwertyuiop[] " +
|
||
|
"asdfghjkl;'` \\" +
|
||
|
"zxcvbnm,./ " +
|
||
|
"* " +
|
||
|
"789-456+1230. "
|
||
|
);
|
||
|
andi(r33, ra, 0x00ff);
|
||
|
lra(rb, r0, str);
|
||
|
add64(rb, rb, r33);
|
||
|
ld(rb, rb, 0, 1);
|
||
|
}
|
||
|
|
||
|
fn display_key(ra){
|
||
|
andi(r33, ra, 0x00ff);
|
||
|
ori(r33, r33, 0x0200);
|
||
|
let location = 0x20000;
|
||
|
li64(r32, location);
|
||
|
st(r33, r32, 0, 2);
|
||
|
|
||
|
li64(r1, 3);
|
||
|
li64(r2, 1);
|
||
|
li64(r3, location);
|
||
|
li64(r4, 2);
|
||
|
eca();
|
||
|
}
|
||
|
|
||
|
fn main(){
|
||
|
let key_up = declabel();
|
||
|
let main_loop = label();
|
||
|
get_keyboard_status();
|
||
|
andi(r12, r3, 1);
|
||
|
li64(r13, 0x1);
|
||
|
jne(r13, r12, main_loop);
|
||
|
get_keyboard_input();
|
||
|
cp(r12, r3);
|
||
|
is_keyup(r14, r12);
|
||
|
jne(r0, r14, key_up);
|
||
|
to_ascii(r15, r12);
|
||
|
display_key(r15);
|
||
|
jeq(r0, r0, main_loop);
|
||
|
here(key_up);
|
||
|
jeq(r0, r0, main_loop);
|
||
|
|
||
|
tx();
|
||
|
}
|
||
|
|
||
|
main();
|