2019-03-06 20:01:09 +01:00
|
|
|
;=----------------------------------------------------------------------------=;
|
|
|
|
; GNU GPL OS/K ;
|
|
|
|
; ;
|
|
|
|
; Desc: Basic Colored VGA Terminal Long mode Driver ;
|
|
|
|
; (x86_64 architecture only) ;
|
|
|
|
; ;
|
|
|
|
; ;
|
|
|
|
; Copyright © 2018-2019 The OS/K Team ;
|
|
|
|
; ;
|
|
|
|
; This file is part of OS/K. ;
|
|
|
|
; ;
|
|
|
|
; OS/K is free software: you can redistribute it and/or modify ;
|
|
|
|
; it under the terms of the GNU General Public License as published by ;
|
|
|
|
; the Free Software Foundation, either version 3 of the License, or ;
|
|
|
|
; (at your option) any later version. ;
|
|
|
|
; ;
|
|
|
|
; OS/K is distributed in the hope that it will be useful, ;
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
|
|
|
|
; GNU General Public License for more details. ;
|
|
|
|
; ;
|
|
|
|
; You should have received a copy of the GNU General Public License ;
|
|
|
|
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
|
|
|
;=----------------------------------------------------------------------------=;
|
2019-03-11 19:22:37 +01:00
|
|
|
[global testf]
|
2019-03-06 20:01:09 +01:00
|
|
|
|
|
|
|
;;VIDEO
|
2019-03-08 08:43:44 +01:00
|
|
|
%define TRAM 0xB8000 ; [T]ext[RAM]
|
|
|
|
%define VRAM 0xA0000 ; [V]ideo[RAM]
|
|
|
|
%define VGA_HEIGHT 80
|
2019-03-06 20:01:09 +01:00
|
|
|
|
|
|
|
;; GLOBAL DATA
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
NextTRAM dq 0xB8000 ; Last position of cursor
|
|
|
|
NextTRAM32 dq 0xB8000 ; Last position of cursor
|
|
|
|
VGA_X32 dq 0
|
|
|
|
VGA_HEIGHT64 dq VGA_HEIGHT
|
2019-03-06 20:01:09 +01:00
|
|
|
VGA_X dq 0
|
|
|
|
|
|
|
|
;; TEXT
|
|
|
|
|
|
|
|
[BITS 64]
|
|
|
|
|
2019-03-11 19:22:37 +01:00
|
|
|
testf:
|
|
|
|
push rsi
|
|
|
|
push rbx
|
|
|
|
mov esi, teststr
|
|
|
|
mov bl, 0xF
|
|
|
|
call write
|
|
|
|
pop rsi
|
|
|
|
pop rbx
|
|
|
|
ret
|
|
|
|
teststr: db "Salut",0
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
|
2019-03-06 20:01:09 +01:00
|
|
|
;-----------------------------------------------------------------------;
|
|
|
|
; x64/LM Clear Text Screen Function ;
|
|
|
|
;-----------------------------------------------------------------------;
|
2019-03-08 08:43:44 +01:00
|
|
|
clear:
|
2019-03-06 20:01:09 +01:00
|
|
|
mov qword [NextTRAM], TRAM
|
|
|
|
mov edi, TRAM
|
|
|
|
push rsi
|
|
|
|
push rdi
|
|
|
|
push rcx
|
|
|
|
mov ah, 0
|
|
|
|
mov al, 0
|
2019-03-08 08:43:44 +01:00
|
|
|
mov rcx, 0x4000 ; traditionnal value
|
|
|
|
rep stosw ; fill screen with al while cx > 0
|
2019-03-06 20:01:09 +01:00
|
|
|
pop rcx
|
|
|
|
pop rsi
|
|
|
|
pop rdi
|
|
|
|
ret
|
|
|
|
|
2019-03-08 08:43:44 +01:00
|
|
|
|
2019-03-06 20:01:09 +01:00
|
|
|
;-----------------------------------------------------------------------;
|
|
|
|
; x64/LM Text Printing Functions ;
|
|
|
|
; bl : color code ;
|
|
|
|
; esi : string address ;
|
|
|
|
;-----------------------------------------------------------------------;
|
2019-03-08 08:43:44 +01:00
|
|
|
write:
|
|
|
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
2019-03-06 20:01:09 +01:00
|
|
|
push rsi
|
|
|
|
push rdi
|
|
|
|
.pLoop:
|
|
|
|
lodsb
|
2019-03-08 08:43:44 +01:00
|
|
|
cmp al, 0 ; while @al, i.e. while we're not hitting '\0'
|
2019-03-06 20:01:09 +01:00
|
|
|
je .pEnd
|
2019-03-08 08:43:44 +01:00
|
|
|
cmp al, 0x0A ; LF
|
2019-03-06 20:01:09 +01:00
|
|
|
je .lf
|
2019-03-08 08:43:44 +01:00
|
|
|
cmp al, 0x0D ; CR
|
2019-03-06 20:01:09 +01:00
|
|
|
je .cr
|
2019-03-08 08:43:44 +01:00
|
|
|
stosb ; text subpixel
|
2019-03-06 20:01:09 +01:00
|
|
|
mov al, bl
|
2019-03-08 08:43:44 +01:00
|
|
|
stosb ; color subpixel
|
|
|
|
add qword [NextTRAM], 0x2 ; Cursor moving
|
|
|
|
add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels
|
2019-03-06 20:01:09 +01:00
|
|
|
jmp .pLoop
|
|
|
|
.pEnd:
|
|
|
|
pop rdi
|
|
|
|
pop rsi
|
|
|
|
ret
|
|
|
|
.lf:
|
|
|
|
mov rax, [VGA_HEIGHT64]
|
2019-03-08 08:43:44 +01:00
|
|
|
add [NextTRAM], rax ; Cursor moving
|
2019-03-06 20:01:09 +01:00
|
|
|
add [NextTRAM], rax
|
2019-03-08 08:43:44 +01:00
|
|
|
add edi, eax ; Address moving
|
2019-03-06 20:01:09 +01:00
|
|
|
add edi, eax
|
|
|
|
jmp .pLoop
|
|
|
|
.cr:
|
|
|
|
push rax
|
|
|
|
mov rax, qword [VGA_X]
|
2019-03-08 08:43:44 +01:00
|
|
|
sub qword [NextTRAM], rax ; pos = X + Y * VGA_HEIGHT64. Donc pos - X = début de ligne
|
2019-03-06 20:01:09 +01:00
|
|
|
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 512 bytes of a buffer ;
|
|
|
|
; bl : color code ;
|
|
|
|
; esi : buffer address ;
|
|
|
|
;-----------------------------------------------------------------------;
|
2019-03-08 08:43:44 +01:00
|
|
|
mov edi, [NextTRAM] ; TRAM ADDRESS
|
2019-03-06 20:01:09 +01:00
|
|
|
push rsi
|
|
|
|
push rdi
|
|
|
|
push rcx
|
|
|
|
mov rcx, 512
|
|
|
|
.pLoop:
|
|
|
|
lodsb
|
2019-03-08 08:43:44 +01:00
|
|
|
stosb ; text subpixel
|
2019-03-06 20:01:09 +01:00
|
|
|
mov al, bl
|
2019-03-08 08:43:44 +01:00
|
|
|
stosb ; color subpixel
|
2019-03-06 20:01:09 +01:00
|
|
|
loop .pLoop
|
|
|
|
pop rcx
|
|
|
|
pop rdi
|
|
|
|
pop rsi
|
2019-03-08 08:43:44 +01:00
|
|
|
add qword [NextTRAM], 1000 ; Cursor moving : 1120 = 80 * 2 * 7 lignes
|
|
|
|
ret
|
|
|
|
|
|
|
|
[BITS 32]
|
|
|
|
;-----------------------------------------------------------------------;
|
|
|
|
; x32 Text Printing Functions ;
|
|
|
|
; bl : color code ;
|
|
|
|
; esi : string address ;
|
|
|
|
;-----------------------------------------------------------------------;
|
|
|
|
write32:
|
|
|
|
mov edi, TRAM ; TRAM ADDRESS
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
.pLoop:
|
|
|
|
lodsb
|
|
|
|
cmp al, 0 ; while @al, i.e. while we're not hitting '\0'
|
|
|
|
je .pEnd
|
|
|
|
stosb ; text subpixel
|
|
|
|
mov al, bl
|
|
|
|
stosb ; color subpixel
|
|
|
|
jmp .pLoop
|
|
|
|
.pEnd:
|
|
|
|
pop edi
|
|
|
|
pop esi
|
2019-03-06 20:01:09 +01:00
|
|
|
ret
|
2019-03-08 08:43:44 +01:00
|
|
|
|
|
|
|
disable_cursor:
|
|
|
|
pushf
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
|
|
|
|
mov dx, 0x3D4
|
|
|
|
mov al, 0xA ; low cursor shape register
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
inc dx
|
|
|
|
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
|
|
|
|
out dx, al
|
|
|
|
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
popf
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
[BITS 64]
|