allocator + windows test

This commit is contained in:
Sarah Jamie Lewis 2021-11-14 16:49:45 -08:00
parent 04298f8659
commit 78f1b17358
4 changed files with 180 additions and 5 deletions

50
arch.md Normal file
View File

@ -0,0 +1,50 @@
# Op Code Structure
## Type 1 Register and Memory
Opcode | Register | Address Mask
-------|----------|---------
F | F | FFFFFF
## Type 2 Register and Register
Opcode | Register | Address Mask
-------|----------|---------
F | F | 00000F
## Type 3 Meta
Opcode | Register | Address Mask
-------|----------|---------
F | F | 000000
# Meta Instructions
Opcode | Type | Descriptions
-------|------|-------
0x00 | 3 |NOP
# 0x1 Store
Opcode | Type | Descriptions
-------|------|------------------
0x1N | 1 | Store word in Register N into Addr
# 0x2 Load
Opcode | Type | Descriptions
-------|------|------------------
0x2N | 1 | Load word @ Addr into Register
# 0x3 Load Immediate
Opcode | Type | Descriptions
-------|------|------------------
0x3N | 1 | Load Addr into Register N
# 0x9 Register Move (Transfer)
Opcode | Type | Descriptions
-------|------|------------------
0x7N00000R | 2 | Load word in Register `R` into Register `N`

View File

@ -37,15 +37,18 @@ import charset.asm ; charset + hex strings
import strings.asm ; draw_char, draw_string
import util.asm ; print_addr
import graphics.asm; draw_vline, draw_hline, draw_rect
import windows.asm
; Common Strings
data ascii TestWindow Test Window
data ascii TestWindow2 Test Window The Second
data ascii boo_os_version Boo OS v0.0.1
data ascii prompt [sarah@boo] >
data ascii Welcome !@#$%^&*()_+=-0987654321
data ascii Introspection We Can Now Do Introspection:
data ascii label_rax RAX:
data ascii label_rip RIP:
data ascii label_cycles Instruction Count:
data ascii label_cycles Allocated Memory:
data ascii label_keypress Current Key Pressed:
data image boo_os.png booos.png
data image boo_os_small.png booos-small.png
@ -358,9 +361,39 @@ label handle_keypress:
bappend $4 command_line_input
ret
label window_1:
nop
label window_2:
nop
label kernel_windows:
nop
; Kernel Begins
@ $CB000:
loadi $4 2
call FFFFF0 ; Allocate First Linked List
store $4 kernel_windows
loadi $4 $30
loadi $5 $30
loadi $6 $A0
loadi $7 $A0
loadi $8 TestWindow
call make_window
store $4 window_1
loadi $4 $55
loadi $5 $70
loadi $6 $F0
loadi $7 $A0
loadi $8 TestWindow2
call make_window
store $4 window_2
label kernel_loop:
loadi $9 $0; 640-64
loadi $A $0; 480-64
call set_pos
@ -374,6 +407,14 @@ label handle_keypress:
loadi $8 $222222
call draw_filled_rect
loadi $4 window_1
rload $4 $4
call draw_window
loadi $4 window_2
rload $4 $4
call draw_window
loadi $9 $5;
loadi $A $5;
call set_pos
@ -465,10 +506,10 @@ label handle_keypress:
call draw_string;
updsp
jmp $CB000;
jmp kernel_loop;
; Very Very Watermark Allocator
; Very Very Basic Watermark Memory Allocator
@ $FFFFF0:
; $4 contains a length which corresponds to number of bytes
label allocator:
@ -478,5 +519,4 @@ label handle_keypress:
loadi $2 $FFFFF0
sub $2 $1 $2
sub $2 $4 $4
ret

View File

@ -113,6 +113,7 @@ impl Machine {
if ptr > 0 {
self.memory[addr + 1] -= 1;
self.memory[addr + 2 + ptr - 1] = 0x00;
self.memory[addr + 2 + ptr - 1] = 0x00;
}
}
op => {
@ -156,7 +157,7 @@ impl Machine {
self.memory[addr] = self.memory[REGISTER_PAGE + input_reg];
}
0x07 => {
// LOAD R(X) = MEM(R(In))
// RLOAD R(X) = MEM(R(In))
let input_reg = ((instruction) >> 24 & 0x0F) as usize;
let reg = (instruction & 0x000000FF) as usize;
self.memory[REGISTER_PAGE + reg] =

84
windows.asm Normal file
View File

@ -0,0 +1,84 @@
; x,y, width, height; title
; returns the address of the window on the heap in $4
label make_window
tx $D $5
loadi $4 6
call $FFFFF0 ; allocate 6 bytes on the heap
rstore $D $4
inc $4
rstore $5 $4
inc $4
rstore $6 $4
inc $4
rstore $7 $4
inc $4
loadi $1 221122
rstore $1 $4
inc $4
rstore $8 $4
loadi $1 6
sub $4 $1 $4
ret
; 4 contains the address of the window
label _draw_window
nop
nop
nop
nop
label draw_window:
tx $C $4
inc $C
rload $C $4
store $4 _draw_window
inc $C
rload $C $5
store $5 _draw_window+1
inc $C
rload $C $6
store $6 _draw_window+2
inc $C
rload $C $7
store $7 _draw_window+3
inc $C
rload $C $8
call draw_filled_rect
inc $C ; now points to title buffer
load $4 _draw_window
load $5 _draw_window+1
load $6 _draw_window+2
load $7 _draw_window+3
loadi $8 020102
call draw_rect
load $4 _draw_window
load $5 _draw_window+1
loadi $1 2
add $4 $1 $4
loadi $1 2
add $5 $1 $5
load $6 _draw_window+2
loadi $1 4
sub $6 $1 $6
loadi $7 $A
loadi $8 554455
call draw_filled_rect
load $4 _draw_window
load $5 _draw_window+1
loadi $1 4
add $4 $1 $4
loadi $1 4
add $5 $1 $5
tx $9 $4
tx $A $5
call set_pos
rload $C $4
call draw_string
ret