;-----------------;\r
; variables ;\r
;-----------------;\r
- screen_rows db 25 ; all comments assume\r
- screen_cols db 80 ; that this is 25 & 80\r
- cursor_pos dw 0\r
+ screen_rows db 25 ; all comments assume\r
+ screen_cols db 80 ; that this is 25 & 80\r
+ cursor_pos dw 0\r
\r
\r
;--------------------------------------;\r
; in: bx = cursor attribs ;\r
;--------------------------------------;\r
changecursor:\r
- push ax\r
- push dx\r
+ push ax\r
+ push dx\r
\r
- mov dx, 0x3D4\r
- mov al, 0x0A\r
- mov ah, bh\r
- out dx, ax\r
- inc ax\r
- mov ah, bl\r
- out dx, ax\r
+ mov dx, 0x3D4\r
+ mov al, 0x0A\r
+ mov ah, bh\r
+ out dx, ax\r
+ inc ax\r
+ mov ah, bl\r
+ out dx, ax\r
\r
- pop dx\r
- pop ax\r
- ret\r
+ pop dx\r
+ pop ax\r
+ ret\r
\r
\r
;----------------------;\r
; clear the screen ;\r
;----------------------;\r
cls:\r
- push bx\r
- push cx\r
+ push bx\r
+ push cx\r
\r
- movzx cx, [screen_rows]\r
+ movzx cx, [screen_rows]\r
.loop:\r
- call _scroll_up\r
- loop .loop\r
+ call _scroll_up\r
+ loop .loop\r
\r
- mov bx, 0\r
- call setcursor\r
+ mov bx, 0\r
+ call setcursor\r
\r
- pop cx\r
- pop bx\r
- ret\r
+ pop cx\r
+ pop bx\r
+ ret\r
\r
\r
;-----------------------------------;\r
; out: bh = x bl = y ;\r
;-----------------------------------;\r
getcursorxy:\r
- push ax\r
+ push ax\r
\r
- call getcursor\r
- mov ax, bx\r
- mov bl, [screen_cols]\r
- div bl\r
- mov bl, al\r
- mov bh, ah\r
+ call getcursor\r
+ mov ax, bx\r
+ mov bl, [screen_cols]\r
+ div bl\r
+ mov bl, al\r
+ mov bh, ah\r
\r
- pop ax\r
- ret\r
+ pop ax\r
+ ret\r
\r
\r
;-------------------------------;\r
; out: bx = offset ;\r
;-------------------------------;\r
getcursor:\r
- push ax\r
- push dx\r
-\r
- mov dx, 0x3D4\r
- mov al, 0x0E\r
- out dx, al\r
- inc dx\r
- in al, dx\r
- mov bh, al\r
- mov al, 0x0F\r
- dec dx\r
- out dx, al\r
- inc dx\r
- in al, dx\r
- mov bl, al\r
-\r
- pop dx\r
- pop ax\r
- ret\r
+ push ax\r
+ push dx\r
+\r
+ mov dx, 0x3D4\r
+ mov al, 0x0E\r
+ out dx, al\r
+ inc dx\r
+ in al, dx\r
+ mov bh, al\r
+ mov al, 0x0F\r
+ dec dx\r
+ out dx, al\r
+ inc dx\r
+ in al, dx\r
+ mov bl, al\r
+\r
+ pop dx\r
+ pop ax\r
+ ret\r
\r
\r
;------------------------------;\r
; bh = x bl = y ;\r
;------------------------------;\r
setcursorxy:\r
- push ax\r
- push bx\r
+ push ax\r
+ push bx\r
\r
- xor ax, ax\r
- mov al, [screen_cols]\r
- mul bl ; bl * al = ax\r
- movzx bx, bh\r
- add bx, ax\r
- call setcursor\r
+ xor ax, ax\r
+ mov al, [screen_cols]\r
+ mul bl ; bl * al = ax\r
+ movzx bx, bh\r
+ add bx, ax\r
+ call setcursor\r
\r
- pop bx\r
- pop ax\r
- ret\r
+ pop bx\r
+ pop ax\r
+ ret\r
\r
\r
;--------------------------;\r
; bx = offset ;\r
;--------------------------;\r
setcursor:\r
- push ax\r
- push bx\r
- push dx\r
+ push ax\r
+ push bx\r
+ push dx\r
\r
- mov al, 0x0E\r
- mov ah, bh\r
- mov dx, 0x3D4\r
- out dx, ax\r
- inc ax\r
- mov ah, bl\r
- out dx, ax\r
+ mov al, 0x0E\r
+ mov ah, bh\r
+ mov dx, 0x3D4\r
+ out dx, ax\r
+ inc ax\r
+ mov ah, bl\r
+ out dx, ax\r
\r
- pop dx\r
- pop bx\r
- pop ax\r
- ret\r
+ pop dx\r
+ pop bx\r
+ pop ax\r
+ ret\r
\r
\r
;-----------------------;\r
; cursor position +1 ;\r
;-----------------------;\r
inccursor:\r
- push ax\r
- push bx\r
+ push ax\r
+ push bx\r
\r
- mov al, [screen_cols]\r
- mov bl, [screen_rows]\r
- mul bl\r
- dec ax\r
+ mov al, [screen_cols]\r
+ mov bl, [screen_rows]\r
+ mul bl\r
+ dec ax\r
\r
- call getcursor\r
- cmp bx, ax ; 0x7CF = (80*25)-1\r
- jne .cont\r
- call scroll_up\r
- jmp .end\r
+ call getcursor\r
+ cmp bx, ax ; 0x7CF = (80*25)-1\r
+ jne .cont\r
+ call scroll_up\r
+ jmp .end\r
\r
- .cont:\r
- inc bx\r
- call setcursor\r
+ .cont:\r
+ inc bx\r
+ call setcursor\r
\r
- .end:\r
- pop bx\r
- pop ax\r
- ret\r
+ .end:\r
+ pop bx\r
+ pop ax\r
+ ret\r
\r
\r
;-----------------------;\r
; cursor position -1 ;\r
;-----------------------;\r
deccursor:\r
- push bx\r
+ push bx\r
\r
- call getcursor\r
- cmp bx, 0\r
- je .end\r
+ call getcursor\r
+ cmp bx, 0\r
+ je .end\r
\r
- dec bx\r
- call setcursor\r
+ dec bx\r
+ call setcursor\r
\r
- .end:\r
- pop bx\r
- ret\r
+ .end:\r
+ pop bx\r
+ ret\r
\r
\r
\r
; backspace - delete last typed char ;\r
;---------------------------------------;\r
backspace:\r
- push bx\r
+ push bx\r
\r
- call getcursor\r
- cmp bx, 0\r
- je .end\r
+ call getcursor\r
+ cmp bx, 0\r
+ je .end\r
\r
- call deccursor\r
+ call deccursor\r
\r
- mov bh, 0x07\r
- mov bl, 0\r
- call print_char\r
+ mov bh, 0x07\r
+ mov bl, 0\r
+ call print_char\r
\r
- call deccursor\r
+ call deccursor\r
\r
- .end:\r
- pop bx\r
- ret\r
+ .end:\r
+ pop bx\r
+ ret\r
\r
\r
\r
; in: bl = char, bh = attrib ;\r
;-----------------------------------------;\r
print_char:\r
- push eax\r
- push bx\r
+ push eax\r
+ push bx\r
\r
- cmp bl, 13\r
- jne .cont\r
- call new_line\r
- jmp .done\r
+ cmp bl, 13\r
+ jne .cont\r
+ call new_line\r
+ jmp .done\r
\r
- .cont:\r
- cmp bl, 10 ; ignore\r
- je .done\r
+ .cont:\r
+ cmp bl, 10 ; ignore\r
+ je .done\r
\r
- push bx\r
- call getcursor\r
- movzx eax, bx\r
- pop bx\r
+ push bx\r
+ call getcursor\r
+ movzx eax, bx\r
+ pop bx\r
\r
- mov [es:(eax*2 + 0xB8000)], bx\r
+ mov [es:(eax*2 + 0xB8000)], bx\r
\r
- call inccursor\r
- .done:\r
- pop bx\r
- pop eax\r
- ret\r
+ call inccursor\r
+ .done:\r
+ pop bx\r
+ pop eax\r
+ ret\r
\r
\r
\r
; in: ebx = value, cl = color ;\r
;------------------------------------------;\r
print_hex32:\r
- push eax\r
- push ebx\r
- push ecx\r
- push edx\r
-\r
- mov eax, ebx ; quick & dirty fix so\r
- mov bh, cl ; input reg != eax\r
- mov ecx, 8\r
-\r
- .print_it:\r
- rol eax, 4\r
- movzx edx, al\r
- and edx, 0x0F\r
- or edx, 0x30\r
- cmp edx, 0x39\r
- jna .cont\r
- add edx, 7\r
- .cont:\r
- mov bl, dl\r
- call print_char\r
- loop .print_it\r
-\r
- pop edx\r
- pop ecx\r
- pop ebx\r
- pop eax\r
- ret\r
+ push eax\r
+ push ebx\r
+ push ecx\r
+ push edx\r
+\r
+ mov eax, ebx ; quick & dirty fix so\r
+ mov bh, cl ; input reg != eax\r
+ mov ecx, 8\r
+\r
+ .print_it:\r
+ rol eax, 4\r
+ movzx edx, al\r
+ and edx, 0x0F\r
+ or edx, 0x30\r
+ cmp edx, 0x39\r
+ jna .cont\r
+ add edx, 7\r
+ .cont:\r
+ mov bl, dl\r
+ call print_char\r
+ loop .print_it\r
+\r
+ pop edx\r
+ pop ecx\r
+ pop ebx\r
+ pop eax\r
+ ret\r
\r
\r
\r
; in: esi = message, bl = color ;\r
;-------------------------------------------------;\r
print:\r
- push eax\r
- push bx\r
+ push eax\r
+ push bx\r
\r
- mov ah, bl\r
- call getcursor\r
- mov [cursor_pos], bx\r
+ mov ah, bl\r
+ call getcursor\r
+ mov [cursor_pos], bx\r
\r
- .displaychar:\r
- lodsb\r
- or al, al\r
- jz .done\r
+ .displaychar:\r
+ lodsb\r
+ or al, al\r
+ jz .done\r
\r
- cmp al, 13\r
- jne .cont\r
- mov bx, [cursor_pos]\r
- call setcursor\r
- call new_line\r
- call getcursor\r
- mov [cursor_pos], bx\r
- jmp .displaychar\r
+ cmp al, 13\r
+ jne .cont\r
+ mov bx, [cursor_pos]\r
+ call setcursor\r
+ call new_line\r
+ call getcursor\r
+ mov [cursor_pos], bx\r
+ jmp .displaychar\r
\r
- .cont:\r
- cmp al, 10 ; ignore\r
- je .displaychar\r
- movzx ebx, [cursor_pos]\r
- mov [es:(ebx*2 + 0xB8000)], ax\r
- inc [cursor_pos]\r
- jmp .displaychar\r
+ .cont:\r
+ cmp al, 10 ; ignore\r
+ je .displaychar\r
+ movzx ebx, [cursor_pos]\r
+ mov [es:(ebx*2 + 0xB8000)], ax\r
+ inc [cursor_pos]\r
+ jmp .displaychar\r
\r
- .done:\r
- mov bx, [cursor_pos]\r
- call setcursor ; update cursor on screen\r
+ .done:\r
+ mov bx, [cursor_pos]\r
+ call setcursor ; update cursor on screen\r
\r
- pop bx\r
- pop eax\r
- ret\r
+ pop bx\r
+ pop eax\r
+ ret\r
\r
\r
\r
; make a new line (CR, LF) ;\r
;-----------------------------;\r
new_line:\r
- push bx\r
+ push bx\r
\r
- call getcursorxy\r
- mov bh, [screen_rows]\r
- dec bh\r
- cmp bl, bh ; 24\r
- jb .newline\r
+ call getcursorxy\r
+ mov bh, [screen_rows]\r
+ dec bh\r
+ cmp bl, bh ; 24\r
+ jb .newline\r
\r
- call scroll_up\r
- jmp .done\r
+ call scroll_up\r
+ jmp .done\r
\r
- .newline:\r
- call getcursorxy\r
- mov bh, 0\r
- inc bl\r
- call setcursorxy\r
+ .newline:\r
+ call getcursorxy\r
+ mov bh, 0\r
+ inc bl\r
+ call setcursorxy\r
\r
- .done:\r
- pop bx\r
- ret\r
+ .done:\r
+ pop bx\r
+ ret\r
\r
\r
\r
; scrolling.. ;\r
;----------------;\r
scroll_up:\r
- call _scroll_up\r
-\r
- .mv_curs:\r
- push ax\r
- push bx\r
-\r
- xor ax, ax\r
- mov al, [screen_rows] ; mov bx, 80*24\r
- mov bl, [screen_cols]\r
- dec al\r
- mul bl\r
- mov bx, ax\r
- call setcursor\r
-\r
- pop bx\r
- pop ax\r
- ret\r
-\r
- _scroll_up:\r
- push eax\r
- push ecx\r
- push edi\r
- push esi\r
-\r
- mov edi, 0xB8000\r
- movzx esi, [screen_cols]\r
- shl esi, 1 ; 80*2 = 160\r
- mov cl, [screen_rows]\r
- dec cl\r
- mov eax, esi\r
- mul cl\r
- shr ax, 2 ; ax = (160*24)/4\r
- movzx ecx, ax ; ecx = - || -\r
- add esi, 0xB8000 ; esi = 0xB8000+160\r
-\r
- rep movsd\r
-\r
- mov cl, [screen_cols]\r
- shl cl, 1 ; 80*2 = 160\r
- mov al, [screen_rows]\r
- dec al ; al = 24\r
- mul cl\r
- movzx edi, ax\r
- add edi, 0xB8000 ; edi = 0xB8000+160*24\r
- movzx ecx, [screen_cols]\r
- shr ecx, 1 ; 80/2\r
- mov eax, 0x07000700 ; fill with zeros\r
- rep stosd\r
-\r
- pop esi\r
- pop edi\r
- pop ecx\r
- pop eax\r
- ret
\ No newline at end of file
+ call _scroll_up\r
+\r
+ .mv_curs:\r
+ push ax\r
+ push bx\r
+\r
+ xor ax, ax\r
+ mov al, [screen_rows] ; mov bx, 80*24\r
+ mov bl, [screen_cols]\r
+ dec al\r
+ mul bl\r
+ mov bx, ax\r
+ call setcursor\r
+\r
+ pop bx\r
+ pop ax\r
+ ret\r
+\r
+ _scroll_up:\r
+ push eax\r
+ push ecx\r
+ push edi\r
+ push esi\r
+\r
+ mov edi, 0xB8000\r
+ movzx esi, [screen_cols]\r
+ shl esi, 1 ; 80*2 = 160\r
+ mov cl, [screen_rows]\r
+ dec cl\r
+ mov eax, esi\r
+ mul cl\r
+ shr ax, 2 ; ax = (160*24)/4\r
+ movzx ecx, ax ; ecx = - || -\r
+ add esi, 0xB8000 ; esi = 0xB8000+160\r
+\r
+ rep movsd\r
+\r
+ mov cl, [screen_cols]\r
+ shl cl, 1 ; 80*2 = 160\r
+ mov al, [screen_rows]\r
+ dec al ; al = 24\r
+ mul cl\r
+ movzx edi, ax\r
+ add edi, 0xB8000 ; edi = 0xB8000+160*24\r
+ movzx ecx, [screen_cols]\r
+ shr ecx, 1 ; 80/2\r
+ mov eax, 0x07000700 ; fill with zeros\r
+ rep stosd\r
+\r
+ pop esi\r
+ pop edi\r
+ pop ecx\r
+ pop eax\r
+ ret
\ No newline at end of file