117 lines
3.9 KiB
NASM
117 lines
3.9 KiB
NASM
|
;=----------------------------------------------------------------------------=;
|
||
|
; GNU GPL OS/K ;
|
||
|
; ;
|
||
|
; Authors: spectral` ;
|
||
|
; NeoX ;
|
||
|
; ;
|
||
|
; Desc: Basic Colored VGA Terminal Long mode Driver ;
|
||
|
; (x86_64 architecture only) ;
|
||
|
;=----------------------------------------------------------------------------=;
|
||
|
|
||
|
;;VIDEO
|
||
|
%define TRAM 0x0B8000 ; [T]ext[RAM]
|
||
|
%define VRAM 0x0A0000 ; [V]ideo[RAM]
|
||
|
|
||
|
;; GLOBAL DATA
|
||
|
|
||
|
VGA_HEIGHT dq 0
|
||
|
VIDEO_MODE dw 0
|
||
|
VIDEO_MODE32 dw 0
|
||
|
VGA_HEIGHT32 dw 0
|
||
|
NextTRAM dq 0x0B8000 ; Last position of cursor
|
||
|
VIDEO_MODE64 dq 0
|
||
|
VGA_HEIGHT64 dq 0
|
||
|
VGA_X dq 0
|
||
|
|
||
|
;; TEXT
|
||
|
|
||
|
[BITS 64]
|
||
|
|
||
|
clear:
|
||
|
;-----------------------------------------------------------------------;
|
||
|
; x64/LM Clear Text Screen Function ;
|
||
|
;-----------------------------------------------------------------------;
|
||
|
mov qword [NextTRAM], TRAM
|
||
|
mov edi, TRAM
|
||
|
push rsi
|
||
|
push rdi
|
||
|
push rcx
|
||
|
mov ah, 0
|
||
|
mov al, 0
|
||
|
mov rcx, 0x4000 ; traditionnal value
|
||
|
rep stosw ; fill screen with al while cx > 0
|
||
|
pop rcx
|
||
|
pop rsi
|
||
|
pop rdi
|
||
|
ret
|
||
|
|
||
|
write:
|
||
|
;-----------------------------------------------------------------------;
|
||
|
; x64/LM Text Printing Functions ;
|
||
|
; bl : color code ;
|
||
|
; esi : string address ;
|
||
|
;-----------------------------------------------------------------------;
|
||
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
||
|
push rsi
|
||
|
push rdi
|
||
|
.pLoop:
|
||
|
lodsb
|
||
|
cmp al, 0 ; while @al, i.e. while we're not hitting '\0'
|
||
|
je .pEnd
|
||
|
cmp al, 0x0A ; LF
|
||
|
je .lf
|
||
|
cmp al, 0x0D ; CR
|
||
|
je .cr
|
||
|
stosb ; text subpixel
|
||
|
mov al, bl
|
||
|
stosb ; color subpixel
|
||
|
add qword [NextTRAM], 0x2 ; Cursor moving
|
||
|
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
|
||
|
jmp .pLoop
|
||
|
.pEnd:
|
||
|
pop rdi
|
||
|
pop rsi
|
||
|
ret
|
||
|
.lf:
|
||
|
mov rax, [VGA_HEIGHT64]
|
||
|
add [NextTRAM], rax ; Cursor moving
|
||
|
add [NextTRAM], rax
|
||
|
add edi, eax ; Address moving
|
||
|
add edi, eax
|
||
|
jmp .pLoop
|
||
|
.cr:
|
||
|
push rax
|
||
|
mov rax, qword [VGA_X]
|
||
|
sub qword [NextTRAM], rax ; pos = X + Y * VGA_HEIGHT64. Donc pos - X = début de ligne
|
||
|
sub edi, edx
|
||
|
mov qword [VGA_X], 0
|
||
|
pop rax
|
||
|
jmp .pLoop
|
||
|
.scroll:
|
||
|
; XXX I don't think I'll implement this, but never know...;
|
||
|
jmp .pLoop
|
||
|
|
||
|
dump:
|
||
|
;-----------------------------------------------------------------------;
|
||
|
; x64/LM Dump Printing Functions ;
|
||
|
; bl : color code ;
|
||
|
; esi : string address ;
|
||
|
;-----------------------------------------------------------------------;
|
||
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
||
|
push rsi
|
||
|
push rdi
|
||
|
push rcx
|
||
|
mov rcx, 512
|
||
|
.pLoop:
|
||
|
lodsb
|
||
|
stosb ; text subpixel
|
||
|
mov al, bl
|
||
|
stosb ; color subpixel
|
||
|
add qword [NextTRAM], 0x2 ; Cursor moving
|
||
|
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
|
||
|
loop .pLoop
|
||
|
pop rcx
|
||
|
pop rdi
|
||
|
pop rsi
|
||
|
ret
|