summaryrefslogtreecommitdiff
path: root/boot/common.asm
diff options
context:
space:
mode:
Diffstat (limited to 'boot/common.asm')
-rw-r--r--boot/common.asm105
1 files changed, 105 insertions, 0 deletions
diff --git a/boot/common.asm b/boot/common.asm
new file mode 100644
index 0000000..02e1a0b
--- /dev/null
+++ b/boot/common.asm
@@ -0,0 +1,105 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+[bits 16]
+
+
+;global data
+STR_HEX_OUT:
+ db "0x0000",0
+
+;print_string routine ([bx])
+;this routine will print a null terminated string at [bx] to the screen.
+print_string:
+
+ pusha ;push all registers
+ mov ah,0x0e
+
+ print_string_loop:
+
+ ;check if value at [bx] is "\0" (end of string)
+ mov cl,[bx]
+ cmp cl,0
+ je print_string_finish
+
+ ;otherwise instruct BIOS to print the current char
+ mov al,cl
+ int 0x10
+
+ ;proceed with next char
+ inc bx
+ jmp print_string_loop
+
+ print_string_finish:
+
+ popa ;pop all registers
+ ret ;return to caller
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;print_hex routine (dx)
+;will print the value of the bx register as hex to the screen
+print_hex:
+
+ pusha
+
+ ;begin with last hex val (hex_out[5])
+ mov bx,STR_HEX_OUT+5
+
+ ;lets loop throuth all 4 'digits'
+ print_hex_loop:
+
+ ;get least significan hex digit to cx
+ mov cx,dx
+ and cx,0x000F
+
+ ;check range (0-9 vs a-f)
+ cmp cx,10
+ jl print_hex_setnum
+
+ ;set hex a-f
+ mov al,'A'-10
+ add al,cl
+ jmp print_hex_al
+
+ ;set hex 0-9
+ print_hex_setnum:
+ mov al,'0'
+ add al,cl
+
+ ; set hex_out[bx] to al
+ print_hex_al:
+ mov [bx],al
+
+ ;proceed with the next significant hex 'digit'
+ dec bx
+ shr dx,4
+
+ ;check if finished (otherwise loop)
+ cmp bx,STR_HEX_OUT+1
+ jne print_hex_loop
+
+ ;output complete hex string and return to caller
+ mov bx,STR_HEX_OUT
+ call print_string
+ popa
+ ret
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;disk_load routune (load dh sectors from drive dl to es:bx)
+disk_load:
+
+ pusha
+
+ mov ah,0x02 ;BIOS read sector func
+ mov al,dh ;read dh sectors (amount)
+ mov ch,0x00 ;cyl 0
+ mov dh,0x00 ;head 0
+ mov cl,0x02 ;start at sector 2
+
+ int 0x13 ;bios interrupt
+
+ popa
+ ret
+