diss command
This commit is contained in:
parent
9a1ce420ed
commit
63810446dc
|
@ -5,6 +5,10 @@ edition = "2018"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
[dependencies]
|
||||
minifb = "0.19.3"
|
||||
image = "0.23.14"
|
93
kernel.asm
93
kernel.asm
|
@ -50,7 +50,8 @@ data image boo_os_small.png booos-small.png
|
|||
data image wallpaper.png wallpaper.png
|
||||
|
||||
data ascii quit_label QUIT
|
||||
data ascii diss_label JUMP
|
||||
data ascii jump_label JUMP
|
||||
data ascii diss_label DISS
|
||||
|
||||
data buffer command_line_input 64
|
||||
|
||||
|
@ -91,6 +92,11 @@ label strcmp:
|
|||
|
||||
|
||||
label shift_terminal:
|
||||
|
||||
; copy terminal 0 to terminal 1
|
||||
loadi $4 terminal[2] ;src
|
||||
bcopy $4 terminal[3] ; dest
|
||||
|
||||
; copy terminal 0 to terminal 1
|
||||
loadi $4 terminal[1] ;src
|
||||
bcopy $4 terminal[2] ; dest
|
||||
|
@ -107,9 +113,66 @@ label shift_terminal:
|
|||
|
||||
ret
|
||||
|
||||
data ascii diss_load LOAD
|
||||
data ascii diss_call CALL
|
||||
data ascii diss_unknown UNKNOWN
|
||||
|
||||
label _disassemble_cmd:
|
||||
loadi $1 $20
|
||||
bappend $1 command_line_input ; space
|
||||
|
||||
loadi $1 1c ; 28 bits
|
||||
shift $4 $1 $2 ;
|
||||
loadi $5 diss_unknown
|
||||
|
||||
loadi $1 $3
|
||||
jneq +2
|
||||
loadi $5 diss_load
|
||||
|
||||
loadi $1 $C
|
||||
jneq +2
|
||||
loadi $5 diss_call
|
||||
|
||||
label _disassemble_cmd_inner:
|
||||
rload $5 $1
|
||||
loadi $2 0
|
||||
jneq +2
|
||||
ret
|
||||
bappend $1 command_line_input
|
||||
inc $5
|
||||
jmp _disassemble_cmd_inner
|
||||
|
||||
|
||||
label disassemble:
|
||||
call string_to_num
|
||||
; $1 contains a actual address we want to diss
|
||||
loadi $2 $FFFFFF;
|
||||
jlt +2
|
||||
ret
|
||||
rload $1 $8 ;
|
||||
call shift_terminal
|
||||
bzero command_line_input
|
||||
loadi $6 7
|
||||
label _disassemble_inner:
|
||||
tx $4 $8 ; temp store for command
|
||||
loadi $5 4 ; number of bits to shift
|
||||
mul $6 $5 $5 ; number of bits to shift command >> (count * 8) (3*8, 2*8, 1*8, 0*8)
|
||||
shift $4 $5 $1 ; do the actual shift
|
||||
loadi $5 $00000F
|
||||
and $1 $5 $4
|
||||
; clobbers 1 2 3 4
|
||||
call num_to_char;
|
||||
bappend $4 command_line_input
|
||||
tx $1 $6
|
||||
loadi $2 0
|
||||
jneq +4
|
||||
tx $4 $8
|
||||
call _disassemble_cmd
|
||||
ret
|
||||
dec $6
|
||||
jmp _disassemble_inner
|
||||
|
||||
label jump:
|
||||
call string_to_num
|
||||
ijmp $1 ;;lol
|
||||
ret
|
||||
|
@ -128,11 +191,23 @@ label do_shell:
|
|||
loadi $6 4
|
||||
call strcmp
|
||||
loadi $2 1
|
||||
jneq +5 ; if the command is QUIT, then hlt the machine!! A shell is born
|
||||
jneq +6 ; if the command is QUIT, then hlt the machine!! A shell is born
|
||||
loadi $4 @command_line_input
|
||||
loadi $5 5
|
||||
add $4 $5 $4
|
||||
call disassemble
|
||||
ret
|
||||
|
||||
loadi $4 @command_line_input
|
||||
loadi $5 jump_label
|
||||
loadi $6 4
|
||||
call strcmp
|
||||
loadi $2 1
|
||||
jneq +5 ; if the command is QUIT, then hlt the machine!! A shell is born
|
||||
loadi $4 @command_line_input
|
||||
loadi $5 5
|
||||
add $4 $5 $4
|
||||
call jump
|
||||
|
||||
ret
|
||||
|
||||
|
@ -204,6 +279,20 @@ label handle_keypress:
|
|||
tx $4 $2
|
||||
call handle_keypress
|
||||
|
||||
|
||||
; print some shell history
|
||||
loadi $9 5;
|
||||
loadi $A 180;
|
||||
call set_pos
|
||||
loadi $4 @terminal[3]
|
||||
call draw_string;
|
||||
|
||||
loadi $9 5;
|
||||
loadi $A 190;
|
||||
call set_pos
|
||||
loadi $4 @terminal[2]
|
||||
call draw_string;
|
||||
|
||||
loadi $9 5;
|
||||
loadi $A 1A0;
|
||||
call set_pos
|
||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -4,7 +4,7 @@ pub const VRAM: usize = 640 * 480;
|
|||
pub const REGISTER_PAGE: usize = VRAM;
|
||||
pub const INPUT_PAGE: usize = VRAM + 64;
|
||||
pub const OFFSET: usize = INPUT_PAGE;
|
||||
pub const MEM_SIZE: usize = 0x0FFFFF - OFFSET;
|
||||
pub const MEM_SIZE: usize = 0xFFFFFF - OFFSET;
|
||||
pub const MEMORY: usize = OFFSET + MEM_SIZE;
|
||||
|
||||
pub struct Machine {
|
||||
|
@ -20,6 +20,33 @@ impl Machine {
|
|||
Machine { memory }
|
||||
}
|
||||
|
||||
pub fn hlt(&self, ip: usize, instruction: u32) {
|
||||
println!("---");
|
||||
println!("{:x} {:x}", ip, instruction);
|
||||
println!(
|
||||
"REG 1:{:X} 2:{:X} 3:{:X} 4:{:X}",
|
||||
self.memory[REGISTER_PAGE + 1],
|
||||
self.memory[REGISTER_PAGE + 2],
|
||||
self.memory[REGISTER_PAGE + 3],
|
||||
self.memory[REGISTER_PAGE + 4]
|
||||
);
|
||||
println!(
|
||||
"REG 5:{:X} 6:{:X} 7:{:X} 8:{:X}",
|
||||
self.memory[REGISTER_PAGE + 5],
|
||||
self.memory[REGISTER_PAGE + 6],
|
||||
self.memory[REGISTER_PAGE + 7],
|
||||
self.memory[REGISTER_PAGE + 8],
|
||||
);
|
||||
println!(
|
||||
"REG 9:{:X} A:{:X} B:{:X} C:{:X}",
|
||||
self.memory[REGISTER_PAGE + 9],
|
||||
self.memory[REGISTER_PAGE + 10],
|
||||
self.memory[REGISTER_PAGE + 11],
|
||||
self.memory[REGISTER_PAGE + 12],
|
||||
);
|
||||
panic!("hlt")
|
||||
}
|
||||
|
||||
pub fn set_keypress(&mut self, char: u32) {
|
||||
self.memory[INPUT_PAGE + 1] = char
|
||||
}
|
||||
|
@ -38,6 +65,7 @@ impl Machine {
|
|||
let instruction = self.memory[ip];
|
||||
self.memory[INPUT_PAGE] += 1;
|
||||
|
||||
|
||||
match instruction >> 28 {
|
||||
0x0 => {
|
||||
match instruction >> 24 {
|
||||
|
@ -132,7 +160,7 @@ impl Machine {
|
|||
let input_reg = ((instruction) >> 24 & 0x0F) as usize;
|
||||
let reg = (instruction & 0x000000FF) as usize;
|
||||
self.memory[REGISTER_PAGE + reg] =
|
||||
self.memory[self.memory[REGISTER_PAGE + input_reg] as usize];
|
||||
self.memory.get(self.memory[REGISTER_PAGE + input_reg] as usize).unwrap_or_else(|| { println!("could not rload: {:x} {:x} {:x}", input_reg, reg, self.memory[REGISTER_PAGE + input_reg] as usize); self.hlt(ip, instruction); unreachable!()}).clone();
|
||||
}
|
||||
0x08 => {
|
||||
// TX R(In) => R(X)
|
||||
|
@ -193,7 +221,7 @@ impl Machine {
|
|||
let result = source & bits;
|
||||
self.memory[REGISTER_PAGE + dest_reg] = result;
|
||||
}
|
||||
// LSHIFT A >> B => C
|
||||
// LSHIFT A << B => C
|
||||
0xA7 => {
|
||||
let source_reg = ((instruction & 0x00FF0000) >> 16) as usize;
|
||||
let bit_reg = ((instruction & 0x0000FF00) >> 8) as usize;
|
||||
|
|
16
strings.asm
16
strings.asm
|
@ -137,7 +137,8 @@
|
|||
jneq draw_next_char
|
||||
ret
|
||||
|
||||
label num_to_char:
|
||||
|
||||
label num_to_charset:
|
||||
loadi $2 HEX_TABLE
|
||||
add $2 $4 $4
|
||||
rload 4 3; Load Arg 1 in 3
|
||||
|
@ -150,6 +151,19 @@ label num_to_char:
|
|||
tx $4 $1
|
||||
ret
|
||||
|
||||
label num_to_char:
|
||||
loadi $2 HEX_TABLE
|
||||
add $2 $4 $4
|
||||
rload 4 3; Load Arg 1 in 3
|
||||
loadi $2 $20 ; Load Addr of [SPACE] in $2
|
||||
sub $3 $2 $1 ; Sub the Character From Space
|
||||
;loadi $2 2
|
||||
;mul $1 $2 $1 ; Mull By 2
|
||||
;loadi $2 char_space
|
||||
;add $2 $1 $1 ; Add to Char Space
|
||||
tx $4 $3
|
||||
ret
|
||||
|
||||
; $4 contains pointer to a null terminated hex string
|
||||
; outputs num in $1
|
||||
label string_to_num:
|
||||
|
|
Loading…
Reference in New Issue