Here's how it works, simple pmode vesa demo
Vesa.asm
Code: Select all
;************************************
; Smallest pmode vesa demo
; By Craig Bamford (Dex)
;
; Assemble with fasm
; c:\fasm Vesa.asm Vesa.bin
;
; Use rawrite to put it on fdd
;
;************************************
org 0x7C00
use16
;****************************
; Realmode startup code.
;****************************
start:
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7C00
;****************************
; Vesa start code.
;****************************
mov bx,4112h
mov ax,4f01h
mov di,Mode_Info
mov cx,bx
int 10h
mov ax,4f02h
int 10h
;*****************************
; Setting up, to enter pmode.
;*****************************
cli
lgdt [gdtr]
mov eax, cr0
or al,0x1
mov cr0,eax
jmp 0x10: protected
;*****************************
; Pmode. ;-)
;*****************************
use32
protected:
mov ax,0x8
mov ds,ax
mov es,ax
mov ss,ax
mov esp,0x7C00
;*****************************
; Turn floppy off (if space).
;*****************************
mov dx,3F2h
mov al,0
out dx,al
;*****************************
; Do we have 32 BitsPerPixel.
;*****************************
cmp byte[ModeInfo_BitsPerPixel],32
jne ErrorStop
;*****************************
; fade background screen.
;*****************************
fill_screen:
mov edi,[ModeInfo_PhysBasePtr]
xor eax,eax
mov ecx,640*480
rep stosd
;*****************************
; Plot_pixel.
;*****************************
Plot_pixel:
mov edi,[ModeInfo_PhysBasePtr]
mov eax,0x00ffffff
mov ecx,10
rep stosd
;*****************************
; ErrorStop.
;*****************************
ErrorStop:
hlt
jmp $
;*************************************
; GDT.
;*************************************
gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:
gdtr: dw gdt_end - gdt - 1
dd gdt
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start) db 0
dw 0xaa55
;*************************************
; Put uninitialized data here.
;*************************************
include 'vesa.inc'
vesa.inc
Code: Select all
;=========================================================;
; Vesa Information Block 11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01 ;
; by Craig Bamford(Dex). ;
; ;
;=========================================================;
;============================== VESA MODE INFORMATION ===========================================
Mode_Info:
ModeInfo_ModeAttributes rw 1
ModeInfo_WinAAttributes rb 1
ModeInfo_WinBAttributes rb 1
ModeInfo_WinGranularity rw 1
ModeInfo_WinSize rw 1
ModeInfo_WinASegment rw 1
ModeInfo_WinBSegment rw 1
ModeInfo_WinFuncPtr rd 1
ModeInfo_BytesPerScanLine rw 1
ModeInfo_XResolution rw 1
ModeInfo_YResolution rw 1
ModeInfo_XCharSize rb 1
ModeInfo_YCharSize rb 1
ModeInfo_NumberOfPlanes rb 1
ModeInfo_BitsPerPixel rb 1
ModeInfo_NumberOfBanks rb 1
ModeInfo_MemoryModel rb 1
ModeInfo_BankSize rb 1
ModeInfo_NumberOfImagePages rb 1
ModeInfo_Reserved_page rb 1
ModeInfo_RedMaskSize rb 1
ModeInfo_RedMaskPos rb 1
ModeInfo_GreenMaskSize rb 1
ModeInfo_GreenMaskPos rb 1
ModeInfo_BlueMaskSize rb 1
ModeInfo_BlueMaskPos rb 1
ModeInfo_ReservedMaskSize rb 1
ModeInfo_ReservedMaskPos rb 1
ModeInfo_DirectColorModeInfo rb 1
; VBE 2.0 extensions
ModeInfo_PhysBasePtr rd 1
ModeInfo_OffScreenMemOffset rd 1
ModeInfo_OffScreenMemSize rw 1
Now to plot a pixel in vesa of that mode in pmode, you first get the lfb address from the vesa info block and mov it into the 32-bit destination reg, eg: EDI
Like so
Than you move the color of the pixel into EAX, in this case white (eg: 0x00ffffff)
Then move the number of pixels into ECX, (eg: 10)
Then we use the "rep" pre fix, which repeats the STOSD the number the number of times thats in ecx (in this case 10).
The STOSD is the same as move whats in eax, into the address that ES:EDI points to, then add 4 to EDI (note: as ES in this case is zero, as we have set it to zero a base).
So what this does is plot a row of 10 white pixels at the top left hand corner of the screen.
If you wanted to put them 1 row down you would ADD the size of a row to the LFB eg:
Code: Select all
mov edi,[ModeInfo_PhysBasePtr]
add edi,640*4
mov eax,0x00ffffff
mov ecx,10
rep stosd
Note: each pixel in this case is 4bytes long 32-bits, so we times the X by 4.
Please do not point out about things like 24-bit color or 'BytesPerScanLine' as i have try to keep it simple.