我正在 fasm 程式集 R-OS 上撰寫作業系統,我想知道如何在沒有 bios 的情況下使用視頻記憶體。當前的作業系統如 Windows 或 MacOS 使我在內核中創建視頻系統,但我不知道如何。請幫忙。
引導.asm:
org 0x7C00
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0,7C00
cld
mov ax, 0x03
int 0x10
mov si, boot_msg
call printf
mov al, 0x04
mov bx, 0x7E00
mov cx, 0x0002
mov dh, 0x00
call disk_read
mov ax, 0x7E0
mov ds, ax
mov es, ax
mov sp, 0x7E00
jmp 0x7E0:0x0000
include 'disk.asm'
include 'printh.asm'
times 510-$ $$ db 0x00
dw 0xAA55
include 'kernel.asm'
times 65536-512-$ $$ db 0x00
內核.asm:
org 0x7E00
mov ax, 0x4F02
mov bx, 0x101
int 0x10
mov ah, 0x0C
mov al, 0x0F
mov cx, 0x10
mov dx, 0x10
int 0x10
msg0 db 'R-OS', 0x00
raf dd 0
wax dw 0
wah db 0
wal db 0
buff db 1024 dup (?)
jmp end2048
end2048:
cli
hlt
jmp $-2
times 2048-$ $$ db 0x00
disk.asm 只有內核加載函式和 printh.asm 只有 printf 和 printh funcs
uj5u.com熱心網友回復:
并非每個 BIOS 都適用于像 101h 這樣的擴展視頻模式!BIOS.WritePixel 函式 0Ch 通常只在 LEGACY 視頻模式下運行。這些是編號范圍從 0 到 19
的視頻模式。視頻模式 101h 是 640x480 256 色 VESA 定義的視頻模式。在不使用 BIOS 的情況下在螢屏上寫入像素需要學習很多關于 VESA、線性幀緩沖區、組切換等的知識。
您正在創建作業系統。而你正處于它的最開始。我認為你在這個階段應該盡量保持簡單,并選擇一種易于使用的傳統視頻模式:320x200 256 色視頻模式。
作業系統不僅僅是它的螢屏,所以將大部分時間投入到其他事情上,把輸出螢屏的細節留到最后。以后你會感謝我的。許多人以前迷失了自己撰寫漂亮的閃屏和特殊效果,但甚至沒有提供基本的輸入行(提示)。
這是一個如何將單個像素直接放置在 320x200 256 色螢屏上的示例。像素的地址計算公式為
AddressInVideoBuffer = (Y * BytesPerScanline) X
mov ax, 0013h ; BIOS.SetVideoMode 320x200x8
int 10h
...
; Puts a green dot in the middle of the screen
mov cl, 2 ; Color = Green
mov bx, 100 ; Y
mov ax, 160 ; X
call PutPixel
...
; IN (ax,bx,cl) OUT () MOD (ax)
PutPixel:
push ds bx ; Preserve registers, allow AX to get clobbered
imul bx, 320 ; Y * BytesPerScanline
add bx, ax ; X
mov ax, 0xA000 ; VideoBuffer
mov ds, ax
mov [bx], cl ; Write the color from CL
pop bx ds ; Restore registers
ret
這是另一個使用嵌套回圈用某種顏色填充螢屏的矩形區域的代碼:
; IN (ax,bx,cl,si,di)
; AX is UpperLeftX, BX is UpperLeftY, CL is Color, SI is Width, DI is Height
PaintRectangle:
push ds bx di ; Preserve registers, allow AX to get clobbered
imul bx, 320 ; UpperLeftY * BytesPerScanline
add bx, ax ; UpperLeftX
mov ax, 0xA000 ; VideoBuffer
mov ds, ax
.OuterLoop:
push si ; (1)
.InnerLoop:
dec si
mov [bx si], cl ; Write the color from CL
jnz .InnerLoop
pop si ; (1)
add bx, 320 ; Move to next scanline (line below)
dec di ; Decrement Height
jnz .OuterLoop
pop di bx ds ; Restore registers
ret
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/313757.html
上一篇:有沒有辦法從C64的KickAssembler中的宏訪問全域常量
下一篇:紅寶石陣列元素
