Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added basic bytecode documentation

  • Loading branch information...
sphinxc0re committed Jun 22, 2017
1 parent 6ecec2f commit f67f1f94f0285f6a650ae59dca6c52a28704cead
@@ -105,52 +105,62 @@ pub fn start(
if config.input_enabled {
match event {
SDL2Event::KeyDown { keycode: Some(key), .. } => {
event_sender
.send(Event::KeyDown(key as Address))
.chain_err(|| "unable to send event")?;
let res = event_sender.send(Event::KeyDown(key as Address));

if let Err(..) = res {
break 'main;
}
}
SDL2Event::KeyUp { keycode: Some(key), .. } => {
event_sender
.send(Event::KeyUp(key as Address))
.chain_err(|| "unable to send event")?;
let res = event_sender.send(Event::KeyUp(key as Address));

if let Err(..) = res {
break 'main;
}
}
SDL2Event::MouseButtonDown { x, y, mouse_btn, .. } => {
event_sender
.send(
Event::MouseDown {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
button: mouse_btn as Address,
},
)
.chain_err(|| "unable to send event")?;
let res = event_sender.send(
Event::MouseDown {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
button: mouse_btn as Address,
},
);

if let Err(..) = res {
break 'main;
}
}
SDL2Event::MouseButtonUp { x, y, mouse_btn, .. } => {
event_sender
.send(
Event::MouseUp {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
button: mouse_btn as Address,
},
)
.chain_err(|| "unable to send event")?;
let res = event_sender.send(
Event::MouseUp {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
button: mouse_btn as Address,
},
);

if let Err(..) = res {
break 'main;
}
}
SDL2Event::MouseMotion { x, y, .. } => {
event_sender
.send(
Event::MouseMove {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
},
)
.chain_err(|| "unable to send event")?;
let res = event_sender.send(
Event::MouseMove {
x: (x as Float / config.display.default_scale).floor() as
Address,
y: (y as Float / config.display.default_scale).floor() as
Address,
},
);

if let Err(..) = res {
break 'main;
}
}
_ => {}
}
@@ -0,0 +1,59 @@
include! ../std/index

call start
halt

.start
call clear
push $st, #FFFFFF

push $st, 1.0
push $st, 1.0

push $st, 4.0
push $st, 4.0

call std.graphics.draw_line

push $st, #FFFFFF

push $st, 4.0
push $st, 4.0

push $st, 1.0
push $st, 7.0

call std.graphics.draw_line


push $st, #FFFFFF

push $st, 6.0
push $st, 7.0

push $st, 11.0
push $st, 7.0

call std.graphics.draw_line



sig %flush_frame%
pause
jmp start
ret

.clear
push $st, @1
add $bp, $st
push $vi(20), @16000
push $vi(0), @0
.clear__loop
push $fb, #000000
push $st, @1
add $vi(0), $st
cmp $vi(0), $vi(20)
jmplteq clear__loop
push $st, @1
sub $bp, $st
ret
BIN -388 KB (0.61%) bakervm/stock.img
Binary file not shown.
@@ -114,6 +114,6 @@ hudson compile --basm path/to/main.basm
| `call label` | label: Label | Calls the function at the given label, pushing the return address to the call-stack |
| `ret` | - | Returns from a function call |
| `halt` | - | Halts the execution of the current program and causes the VM to shut down |
| `pause` | - | Pauses the execution of the current program until a signal is received |
| `pause` | - | Pauses the execution of the current program until an event is received |
| `nop` | - | Does nothing. Good for optimizing code |
| `sig signal` | signal: Signal | Triggers the given internal signal |
@@ -0,0 +1,62 @@
# The bakerVM instruction set
The bakerVM implements its very own highly performant instruction set. Every instruction has a designated functionality. The instructions are defined by the file `instruction.rs`:
```rust
pub enum Instruction {
Add(Target, Target),
Sub(Target, Target),
Div(Target, Target),
Mul(Target, Target),
Rem(Target, Target),
Cmp(Target, Target),
Jmp(Address),
JmpLt(Address),
JmpGt(Address),
JmpEq(Address),
JmpLtEq(Address),
JmpGtEq(Address),
Cast(Target, Type),
Push(Target, Value),
Mov(Target, Target),
Swp(Target, Target),
Dup(Target),
Call(Address),
Ret,
Halt,
Pause,
Nop,
Sig(Signal),
}
```

## Instruction listing

| Instruction | Mnemonic | State<br>[before] → [after] | Description |
|-------------------------:|--------------------------------------|----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| Add(Target,&nbsp;Target) | add&nbsp;`dest`,&nbsp;`src` | **dest**: `value`&nbsp;→&nbsp;`value`<br>**src**: `value`&nbsp;→ | Adds the values of the `src` and `dest` targets |
| Sub(Target,&nbsp;Target) | sub&nbsp;`dest`,&nbsp;`src` | **dest**: `value`&nbsp;→&nbsp;`value`<br>**src**: `value`&nbsp;→ | Subtracts the value of the `src` target from the value of the `dest` target |
| Div(Target,&nbsp;Target) | div&nbsp;`dest`,&nbsp;`src` | **dest**: `value`&nbsp;→&nbsp;`value`<br>**src**: `value`&nbsp;→ | Divides the value of the `dest` target through the value of the `src` target |
| Mul(Target,&nbsp;Target) | mul&nbsp;`dest`,&nbsp;`src` | **dest**: `value`&nbsp;→&nbsp;`value`<br>**src**: `value`&nbsp;→ | Multiplies the values of the `src` and `dest` targets |
| Rem(Target,&nbsp;Target) | rem&nbsp;`dest`,&nbsp;`src` | **dest**: `value`&nbsp;→&nbsp;`value`<br>**src**: `value`&nbsp;→ | Calulates the remainder of the division `dest`/`src` |
| Cmp(Target,&nbsp;Target) | cmp&nbsp;`target_a`,&nbsp;`target_b` | **cmp_register**: `ordering`&nbsp;→&nbsp;`ordering` | Compares the two targets saving the result into the `cmp_register` |
| Jmp(Address) | jmp&nbsp;`jump_target` | [no&nbsp;change] | Jumps unconditionally to the specified `jump_target` |
| JmpLt(Address) | jmplt&nbsp;`jump_target` | [no&nbsp;change] | Jumps to the specified `jump_target` if the result of the last comparison is `less` |
| JmpGt(Address) | jmpgt&nbsp;`jump_target` | [no&nbsp;change] | Jumps to the specified `jump_target` if the result of the last comparison is `greater` |
| JmpEq(Address) | jmpeq&nbsp;`jump_target` | [no&nbsp;change] | Jumps to the specified `jump_target` if the result of the last comparison is `equal` |
| JmpLtEq(Address) | jmplteq&nbsp;`jump_target` | [no&nbsp;change] | Jumps to the specified `jump_target` if the result of the last comparison is either `less` or `equal` |
| JmpGtEq(Address) | jmpgteq&nbsp;`jump_target` | [no&nbsp;change] | Jumps to the specified `jump_target` if the result of the last comparison is either `greater` or `equal` |
| Cast(Target, Type) | cast&nbsp;`target`, `type` | **target**: `value`&nbsp;→&nbsp;`value` | Casts the value of the `target` into the specified `type` in-place |
| Push(Target, Value) | push&nbsp;`target`,&nbsp;`value` | **target**: →&nbsp;`value` | Writes the `value` to the target |
| Mov(Target, Target) | mov&nbsp;`dest`,&nbsp;`src` | **dest**: →&nbsp;`value`<br>**src**: `value`&nbsp;→ | Moves the value of the `src` target to the `dest` target |
| Swp(Target, Target) | swp&nbsp;`target_a`,&nbsp;`target_b` | **target_a**: `value`&nbsp;→&nbsp;`value`<br>**target_b**: `value`&nbsp;→&nbsp;`value` | Swaps the values of `target_a` and `target_b` |
| Dup(Target) | dup&nbsp;`target` | **stack**: →&nbsp;`value` | Duplicates the value of `target` to the `stack` |
| Call(Address) | call&nbsp;`call_target` | **call_stack**: →&nbsp;`address` | Calls the `call_target` pushing the return address to the `call_stack` |
| Ret | ret | **call_stack**: `address`&nbsp;→ | Returns from a call using the top most address on the `call_stack` |
| Halt | halt | [no&nbsp;change] | Halts the execution of the current program and causes the VM to shut down |
| Pause | pause | [no&nbsp;change] | Pauses the execution of the current program until an event is received |
| Nop | nop | [no&nbsp;change] | Does nothing. Good for optimizing code |
| Sig(Signal) | sig&nbsp;`signal` | [no&nbsp;change] | Triggers the given `signal` |
@@ -11,8 +11,5 @@ include! new_bakervm.png
call assets.images.draw_new_bakervm.png
sig %flush_frame%
pause
pause
pause
pause
pause
jmp start
ret
@@ -1,14 +1,9 @@
include! ../../../std/index

push $st, @1
add $bp, $st
push $vi(20), @16000
push $vi(0), @0
call start
halt

.start
push $vi(0), @0
call clear
pause
push $st, #FF00FF
@@ -28,9 +23,16 @@ halt
ret

.clear
push $st, @1
add $bp, $st
push $vi(20), @16000
push $vi(0), @0
.clear__loop
push $fb, #000000
push $st, @1
add $vi(0), $st
cmp $vi(0), $vi(20)
jmplteq clear
jmplteq clear__loop
push $st, @1
sub $bp, $st
ret

0 comments on commit f67f1f9

Please sign in to comment.
You can’t perform that action at this time.