Some file restructuring

This commit is contained in:
2023-12-25 16:57:09 +01:00
parent d170d66512
commit cb2d8b2790
10 changed files with 22 additions and 22 deletions
+89
View File
@@ -0,0 +1,89 @@
;
; Prints a string
; si - Pointer to NULL terminated string
;
print:
pusha
mov ah, 0x0e
mov bl, 0x0f
mov bh, 0
.loop:
lodsb ; Load [si] into al; Increment si
or al, al
jz .done
int 0x10
jmp .loop
.done:
popa
ret
;
; Prints a hex value
; dx - Value to print in Hex
;
printHex:
pusha
xor cx, cx ; Init counter
.loop:
cmp cx, 4 ; Check for loop end
je .done
mov ax, dx ; Copy dx to ax
and ax, 0x000f ; Get last nibble (4 bits) of ax
add ax, '0' ; Convert number to an ASCII number (0-9)
cmp ax, '9' ; Check if number was less than 9, meaning we can use it
jle .addChar
add ax, 0x07 ; Convert to letter (A-F)
.addChar:
mov bx, hexString + 5
sub bx, cx ; Get position of current hex character
mov [bx], al
ror dx, 4 ; Rotate bits of dx (0x1a2b -> 0xb1a2)
inc cx ; Increment the counter
jmp .loop
.done:
mov si, hexString
call print
popa
ret
;
; Prints a hex byte
; dl - Hex byte
;
printHexByte:
pusha
xor cx, cx
.loop:
mov al, dl
and al, 0xF0
ror al, 4
add al, '0'
cmp al, '9'
jle .hexNum
add al, 7
.hexNum:
mov ah, 0x0e
int 0x10
inc cx
cmp cx, 2
je .done
ror dl, 4
jmp .loop
.done:
popa
ret
hexString: db "0x0000", 0
;
; Clears the screen
;
clear:
pusha
; TODO: Make this function
popa
ret
; Usefull definitions
%define ENDL 0x0a, 0x0d
newline: db ENDL, 0 ; CRLF
+24
View File
@@ -0,0 +1,24 @@
resetTextMode:
pusha
mov ah, 0 ; Set mode
mov al, 0x03 ; 25x80, Text mode
int 0x10
mov ah, 0x0b ; Change color/palette
mov bh, 0x00 ; Change BG color
mov bl, 0x01 ; Blue BG
int 0x10
popa
ret
resetGraphicsMode:
pusha
mov ah, 0 ; Set mode
mov al, 0x13 ; 320x200, 256 color graphics mode
int 0x10
popa
ret