Commit 1d44ef6e by malcolm

Merge branch 'hexprint' into 'master'

Hexprint

It finally works!

May not be too useful, as its for real mode with bios syscalls only. I tried to preserve the si register so its more easily debugged, but haven't gotten to restoring the other general registers. We should switch to proper function calls at some point so as to not mess up state.

See merge request !4
parents 10f6f815 84c08b23
Showing with 41 additions and 6 deletions
...@@ -14,11 +14,11 @@ st: ...@@ -14,11 +14,11 @@ st:
mov cx, 0x0002 ; floppy cylinder mov cx, 0x0002 ; floppy cylinder
call read_sectors_16 ; read with above args call read_sectors_16 ; read with above args
jnc 0x7e00 ; jump to actual code jnc 0x7e00 ; jump to actual code
halt: halt:
cli ; halt if failed, loop cli ; halt if failed, loop
hlt hlt
jmp halt jmp halt
read_sectors_16: read_sectors_16:
pusha pusha
mov si, 0x02 ; maximum attempts - 1 mov si, 0x02 ; maximum attempts - 1
...@@ -34,7 +34,7 @@ read_sectors_16: ...@@ -34,7 +34,7 @@ read_sectors_16:
.end: .end:
popa popa
retn retn
read_fail db 'Failure to read from disk.', 13, 10, 0 read_fail db 'Failure to read from disk.', 13, 10, 0
; $ is current line, $$ is first line, db 0 is a 00000000 byte ; $ is current line, $$ is first line, db 0 is a 00000000 byte
; So, pad the code with 0s until you reach 510 bytes ; So, pad the code with 0s until you reach 510 bytes
...@@ -44,8 +44,9 @@ times 510 - ($ - $$) db 0 ...@@ -44,8 +44,9 @@ times 510 - ($ - $$) db 0
;---------------- BOOTLOADER CODE ----------------; ;---------------- BOOTLOADER CODE ----------------;
ls: mov si, str1 ; pointer to string in si ls: mov si, str1 ; pointer to string in si
call PrintStr ; print string call PrintStr ; print string
jmp Main ; jmp Main ;
hlt hlt
;---------------- SCREEN FUNCTIONS ---------------; ;---------------- SCREEN FUNCTIONS ---------------;
PrintStr: ; print string at SI PrintStr: ; print string at SI
nextChar: nextChar:
...@@ -64,13 +65,47 @@ PrintChar: ; print char at AL ...@@ -64,13 +65,47 @@ PrintChar: ; print char at AL
mov bl, 0x07 ; light gray mov bl, 0x07 ; light gray
int 0x10 ; print character int 0x10 ; print character
ret ret
;------------------ DATA BLOCK ------------------;
str1 db 'Hello World', 0 ;stuff PrintHexStr: ; print <ax> bytes starting at [si]
mov di, si ; initilize the loop registers
mov dx, si
add dx, ax
nexthchar:
cmp di, dx
jge exith ; NO IDEA HOW THIS WORKS
mov al, BYTE [di] ; grab next char
call PrintHexChar ; else print char
inc di
jmp nexthchar ; loop
exith:
ret
PrintHexChar:
;; call PrintChar
xor ebx, ebx
mov cl, al
mov bl, al
and bl, 0xf0
shr bl, 4
mov al, BYTE [hexChars + ebx]
call PrintChar
mov bl, cl
and bl, 0x0f
mov al, BYTE [hexChars + ebx]
call PrintChar
ret
;------------------ DATA BLOCK ------------------;
str1 db 'Hello World', 0 ; Hello World
str2 db 'WHY IS THIS', 0 str2 db 'WHY IS THIS', 0
hexChars db '0123456789abcdef' ; Used for hex formatting
Main: ;main section Main: ;main section
nop nop
nop nop
mov si, str2 mov si, str2
call PrintStr call PrintStr
mov si, str1
mov ax, 10
call PrintHexStr ; print string
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment