boo-os/example.asm

157 lines
3.2 KiB
NASM
Raw Normal View History

2021-11-09 02:19:34 +00:00
@ $00000:
label vbuf:
@ $4B000:
$CB000 ; Set Instruction Pointer to $5B000
2021-11-09 02:19:34 +00:00
label RAX:
$0000000 ; RAX
$0000000 ; R2 - Temp Scratch
$0000000 ; R3 - Temp Scratch
$0000000 ; R4 - ARG 1
$0000000 ; R5 - ARG 2
$0000000 ; R6 - ARG 3
$0000000 ; R7 - ARG 4
$0000000 ; R8 - ARG 5
$0000000 ; RX
$0000000 ; RY
label R(B):
2021-11-09 02:19:34 +00:00
$0000000 ; RVBUF (RY * 640) + RX
label R(c):
$0000001 ; Ghost Post
@ $4B040:
label CycleCount:
$0000000; Cycles
label KeyPressedState:
$0000000; The ID of a Key Being Pressed (If Any)
2021-11-09 02:19:34 +00:00
@ $4B0C0:
import display.asm ; setpos
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
2021-11-09 02:19:34 +00:00
; Common Strings
data ascii boo_os_version Boo OS v0.0.1
2021-11-09 02:19:34 +00:00
data ascii HelloWorld Welcome to Boo OS Running on Boo Byte Code!
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_keypress Current Key Pressed:
data image boo_os.png booos.png
data image boo_os_small.png booos-small.png
data image wallpaper.png wallpaper.png
data ascii quit_label QUIT
data buffer command_line_input 256
meta
; strcmp compares 2 strings in a byte-by-byte manner, incrementing ptrs as it goes. Returns 1 if both bytes
; point to 0. Returns 0 (fail) if it encounters 2 different bytes
; clobbers $1 $2 $4 $5
label strcmp:
label strcmp_loop:
ldstore $4 $1
ldstore $5 $2
jeq +3 ; if either of these differ then return 0 to indicate these strings don't match
loadi $1 0
ret
loadi $2 0
jneq +3 ; if both are 0 then we have reached the end of the string
loadi $1 1
ret
inc $4
inc $5
jmp strcmp_loop
label handle_keypress:
; Check for Backspace
loadi $1 $7F
tx $2 $4
jneq +3
bdelete $4 command_line_input
ret
; Check for Return
loadi $1 $0A
tx $2 $4
jneq +8
loadi $4 @command_line_input
loadi $5 quit_label
call strcmp
loadi $2 1
jneq +2 ; if the command is QUIT, then hlt the machine!! A shell is born
hlt
ret
2021-11-09 02:19:34 +00:00
bappend $4 command_line_input
ret
2021-11-09 02:19:34 +00:00
; Kernel Begins
@ $CB000:
loadi $9 $0; 640-64
loadi $A $0; 480-64
2021-11-09 02:19:34 +00:00
call set_pos
loadi $4 wallpaper.png
call draw_image
2021-11-09 02:19:34 +00:00
loadi $4 $0
loadi $5 $0
loadi $6 $280
loadi $7 $10
loadi $8 $222222
call draw_filled_rect
2021-11-09 02:19:34 +00:00
loadi $9 $5;
loadi $A $5;
2021-11-09 02:19:34 +00:00
call set_pos
loadi $4 boo_os_version
call draw_string;
2021-11-09 02:19:34 +00:00
loadi $9 $1A0;
loadi $A $5;
call set_pos
loadi $4 label_cycles
2021-11-09 02:19:34 +00:00
call draw_string;
loadi $4 $4B000
loadi $2 $40
add $2 $4 $4
call print_addr
2021-11-09 02:19:34 +00:00
loadi $9 1;
loadi $A 20;
call set_pos
loadi $4 HelloWorld
2021-11-09 02:19:34 +00:00
call draw_string;
loadi $1 0
load $2 KeyPressedState
store $1 KeyPressedState
jeq +3
tx $4 $2
call handle_keypress
2021-11-09 02:19:34 +00:00
loadi $9 1;
loadi $A 60;
2021-11-09 02:19:34 +00:00
call set_pos
loadi $4 @command_line_input
2021-11-09 02:19:34 +00:00
call draw_string;
2021-11-09 02:19:34 +00:00
updsp
clr
jmp $CB000;