flat assembler
Message board for the users of flat assembler.

Index > DOS > VESA beginner (maybe ASM maybe C ...)

Author
Thread Post new topic Reply to topic
Anaminus



Joined: 01 Jul 2014
Posts: 3
Anaminus
Hello, this is the first time I post in this forum but I've been lurking for a while. I've been making simple programs under MSDOS using Borland's Turbo C. I'm familiar with VGA but I would like to program in resolutions higher than 320x200x256 or 640x480x16. I've read many online articles about VESA modes and I'm interested in 1280x1024x24bpp however, none of the articles I came across explains how to use VESA mode 0x11B which is the mode I mentioned earlier. I've always been programming in realmode, 16-bit and I never learned 32bit programming neither in realmode nor protected mode. I failed to find useful information online and my local library doesn't have any books older than 2007 or anything related to (S)VGA/DOS programming. If anyone could point me in the right direction or atleast give me a simple putpixel script, I will very much appreciate it. I wouldn't like someone to spoon-feed me as I won't learn anything from that. Thank you in advanced.
Post 01 Jul 2014, 22:24
View user's profile Send private message Reply with quote
axlucas



Joined: 02 May 2014
Posts: 66
Location: Argentina
axlucas
Hi, Anaminus! There are tons of information on VESA, but I understand you can be somewhat lost at the starting point. For example, I just found this:

http://www.monstersoft.com/tutorial1/VESA_intro.html

You could use it as a reference.
VESA functions that you can use to access and manage SVGA videos modes are normally available the same as standard video functions, at interrupt 10h. What you do is set the register AH to 4Fh, for VESA and store the VESA function number in AL, then call int 10h. The functions (which you can see in detail in the site I gave you as example) include one for activating the mode, another for getting information (such as dimensions) from a particular video mode and many other more specific ones.
In DOS you can directly access video memory while in a VESA SVGA mode the same way you would with standard modes: by reading and writing at the A000h segment. The problem is that these video modes usually use up a lot more memory than fits in that memory region. Because of this, there is a VESA function for banking. You call it to change the memory bank and continue to work on the same memory region. This is kind of slow.
VESA also provides a Linear Frame Buffer and there's a function that will give you its address in protected mode (extended) memory. How you are going to actually get to that memory in DOS depends on your preference. The LFB is a continuous block of memory that represents the whole screen.
True colour video modes use one byte for each register (red, green and blue) in sequence. 32bit modes actually have 24bit colour depth and skip a fourth byte every pixel, to keep the image aligned and simplify calculations, thus making blitting faster. You can put whatever you want at these skipped locations, but usually transparency information is stored there (alpha channel).

I've just quickly and blindly written this code as an example. I haven't tested it at all and it's been some time since I've used VESA banking functions, so I may have committed some mistakes... but I guess you'll get the idea of it.

Code:
        xcoor = 30      ; Set up to whatever pixel position you want
        ycoor = 9
        pixelcolour = 0ff00ffh

        org 100h

waitfornokey:           ; Make sure no key is being pressed
        in al, 60h
        test al, 80h
        jne waitfornokey

        mov ax, 4f02h   ; Set VESA video mode
        mov bx, 11bh    ; Your video mode number
        int 10h

        mov ax, 1280    ; Your screen width
        mov bx, ycoor
        mul bx
        and edx, 0ffffh ; Mask out higher EDX
        mov ebx, edx    ; EBX = DX:AX
        shl ebx, 16
        mov bx, ax
        add ebx, xcoor  ; Now EBX is the absolute pixel number
        shl ebx, 2      ; 4 bytes per pixel -> now ebx is buffer address

        mov di, bx      ; Address at corresponding window number
        shr ebx, 16     ; Now BL = bank/window number if granularity is 64K

        ; I'm assuming granularity is 64K, which is common, but not always
        ; the case. What you should actually do at this point is use function
        ; 1 to determine your mode's granularity and properly multiply EBX
        ; so that the bank number is correct.

        mov ax, 4f05h   ; Set window number
        xor bh, bh
        int 10h

        mov ax, 0a000h  ; Paint pixel
        mov ds, ax
        mov dword [di], pixelcolour

continuetopoll:         ; Wait for any key press
        in al, 60h
        test al, 80h
        je continuetopoll

        mov ax, 3       ; Set up regular text mode
        int 10h

        mov ax, 4c00h   ; Exit
        int 21h    


This is 5 minute code Razz I apologise if there are stupid mistakes. Hope it helps, though.
Post 02 Jul 2014, 00:26
View user's profile Send private message Reply with quote
Anaminus



Joined: 01 Jul 2014
Posts: 3
Anaminus
Thank you for the relatively quick reply. I'm going to cautiously read the link you posted and I'll try to continue on my own. If the latter doesn't occur, I'll post a reply again.
Post 02 Jul 2014, 01:48
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
Hello.
Anaminus wrote:
I've read many online articles about VESA modes and I'm interested in 1280x1024x24bpp however, none of the articles I came across explains how to use VESA mode 0x11B which is the mode I mentioned earlier.

Starting with VBE2 we can not say this modenumber is exactly for 1280x1024x24bpp, or another resolution, or if we have to use another modenumber for to get this resolution.

With VBE2 and VBE3 we have to get the the VBE-Info in a buffer of 512 bytes with function 4F00 and then we have to get the pointer of the modetable from this Buffer+0Eh and then we have to get the modenumber by number. And with the numbers we have to get the mode specific information with function 4F01 in an other buffer of 256 bytes. Now we can check the properties of each modenumber, for to find the resolution we are searching for.

Hint: For calculating an address of a pixel we have to use the bytes of the scanline, or the scanline for the LFB from the Mode_info_buffer(+10h BytesPerScanLine, or +32h LinBytesPerScanLine) and not the horizontal resolution of the mode, because one part of each scanline is maybe outside of the visible view.

All information about VBE can be found in the costfree "vbe3.pdf" document from vesa.org in the public section (need register/login).

...

In this following pure DOS aplication i show how to get the EDID via DDC from an analog CRT-monitor, for to check the maximal capacity of the monitor, how to use the resolution of 1024x768x32@100 hz refreshrate using an own CRT parameter table and how to use the VBE hardware triple buffering together with the linear framebuffer with the 16 bit Big-Real-Mode. I program this application with a Geforce 4 Ti 4200(AGPx4;64MB) and with a 19" CRT monitor with 96 khz and 160 hz and with a MMX-CPU AMD K6-2 with 550 mhz and with MSDOS 6.22 with disabled emm386.exe in the config.sys.
http://www.alice-dsl.net/freecracmaps/Tool/Neutrip.zip

If no error occur, then some collored balls are moving across the screen and if they reach the border, then they change their direction.

This following documents can also be found on vesa.org:
EEDIDguideV1.pdf
EEDIDverifGuideRa.pdf

Dirk
Post 02 Jul 2014, 05:45
View user's profile Send private message Send e-mail Reply with quote
Anaminus



Joined: 01 Jul 2014
Posts: 3
Anaminus
I'm beginning to understand programming with VESA, thanks! Although I'm not a big fan of Assembly (I prefer C), I'm understanding what's being written although I'm not sure if I can write every assembly code I need with inline assembly. What compiler do you guys recommend using? TASM or FASM?
Post 02 Jul 2014, 11:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16847
Location: In your JS exploiting you and your system
revolution
Anaminus wrote:
What compiler do you guys recommend using? TASM or FASM?
Is TASM still available and updated?

Hehe you are asking this on the fasm board so I can't imagine what answer you were expecting. Wink
Post 02 Jul 2014, 12:18
View user's profile Send private message Visit poster's website Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
Hello.
Anaminus wrote:
I'm beginning to understand programming with VESA, thanks! Although I'm not a big fan of Assembly (I prefer C), I'm understanding what's being written although I'm not sure if I can write every assembly code I need with inline assembly. What compiler do you guys recommend using? TASM or FASM?

I never use a Compiler and i am only a fan of Assemlby and i do not like the C language. My demo above is assembled with the MASM 5.1 Assembler(masm.exe) and the objectfile is linked with the 16 bit linker from MASM 5.1.

For newer versions of MASM (6+) we can use this 16 bit linker:
http://download.microsoft.com/download/vc15/Update/1/WIN98/EN-US/Lnk563.exe

Dirk
Post 02 Jul 2014, 12:22
View user's profile Send private message Send e-mail Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
> Hello, this is the first time I post in this forum but

Welcome Smile

> I've been making simple programs under MSDOS using Borlan

Check out FreeDOS Smile

> resolutions higher than 320x200x256 or 640x480x16. I've
> read many online articles about VESA modes and I'm
> interested in 1280x1024x24bpp however, none of the
> articles I came across explains how to use VESA mode 0x11B

1. don't use fixed mode numbers
2. you must support both 24 bpp and 32 bpp

> Although I'm not a big fan of Assembly (I prefer C)

Get CC386. http://ladsoft.tripod.com/cc386_compiler.html

> write every assembly code I need with inline assembly.

CC386 supports inline ASM. But why not pure ASM ?

> What compiler do you guys recommend using? TASM or FASM?

FASM, surprisingly.

Check out the FAQ thread on the top.

http://board.flatassembler.net/topic.php?t=9738
http://board.flatassembler.net/download.php?id=3915 (ugly C code)
http://board.flatassembler.net/download.php?id=3913
Post 09 Jul 2014, 12:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.