News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

VGA Planes -Plot Pixel and Page Flipping

Started by tda0626, June 22, 2024, 03:28:48 AM

Previous topic - Next topic

tda0626

What compelled the engineers to design this monstrosity? Jk  :biggrin:

I have been trying to wrap my head around the plot pixel and Page flip in unchain mode for the last week or so by reading everything I can find on the subject to understand the fundamentals but I am scratching my head.

So there is 256KB in VGA memory divided up into 4 planes but each plane is 16000 bytes. The math of that doesn't make sense to me or is it writing 4 pixels when I plot one pixel? Confused...

The page flip as far as I can tell is done through the CRT Controller high and low address registers but how do I calculate the address of the plane I am on?

Also, if I want to write to a certain plane, do I need to switch the plane with the Map Mask register?



Tim


NoCforMe

Have you read Michael Abrash's chapter on programming the VGA?
I haven't read it, but the guy has a knack for explaining things clearly, in plain English.
Assembly language programming should be fun. That's why I do it.

FORTRANS

Hi Tim,

Quote from: tda0626 on June 22, 2024, 03:28:48 AMSo there is 256KB in VGA memory divided up into 4 planes but each plane is 16000 bytes. The math of that doesn't make sense to me or is it writing 4 pixels when I plot one pixel? Confused...

   In the VGA 320x200 256 color mode you have 320*200 = 64,000 bytes.
Divide into four planes and each plane holds 16,000 bytes (unchained).
When you write a pixel you select which plane(s) to write to.

Regards,

Steve N.

tda0626

Quote from: NoCforMe on June 22, 2024, 05:28:48 AMHave you read Michael Abrash's chapter on programming the VGA?
I haven't read it, but the guy has a knack for explaining things clearly, in plain English.

I read the section explains it but it still puzzles me on certain aspects.

Also found these sites:

https://uchicago-cs.github.io/pintos/specs/freevga/vga/vga.htm

http://qzx.com/pc-gpe/



Quote from: FORTRANS on June 22, 2024, 06:43:12 AMHi Tim,

Quote from: tda0626 on June 22, 2024, 03:28:48 AMSo there is 256KB in VGA memory divided up into 4 planes but each plane is 16000 bytes. The math of that doesn't make sense to me or is it writing 4 pixels when I plot one pixel? Confused...

   In the VGA 320x200 256 color mode you have 320*200 = 64,000 bytes.
Divide into four planes and each plane holds 16,000 bytes (unchained).
When you write a pixel you select which plane(s) to write to.

Regards,

Steve N.

How does that relate to 256KB of video memory if all 4 planes are just 16000 bytes? Guess that is where I getting hung up on, Steve.


I made some notes that I think are right for writing to a video plane. Does it look right?


Write to Video Plane:
1. Plane 0 = width * height / 4 * 0 or just 0
2. Plane 1 = width * height / 4 * 1
3. Plane 2 = width * height / 4 * 2
4. Plane 3= width * height / 4 * 3
5. Set Sequencer Controller 0x3c4 to register 2 - Map Mask Register
6. Map Mask Register - set 0x3c5 to (   SHL 1 ( X & 3) )
7. Write color to plane ( Plane + width * Y / 4 + X )



 

daydreamer

I prefer more rewarding how you use svga modes ,with more colours and higher resolution
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

FORTRANS

Hi,

Quote from: tda0626 on June 22, 2024, 07:42:22 AMHow does that relate to 256KB of video memory if all 4 planes are just 16000 bytes? Guess that is where I getting hung up on, Steve.

   Well that is where the 16,000 bytes came from.  Abrash
and Richard Wilton show how to program the VGA to get a
higher resolution display.  I think Abrash calls those
Mode X.  Wilton in "Programmer's Guide to PC Video systems"
just calls them non-BIOS modes.  He shows six such modes
with the highest resolution being 360x480.  That is
172,000 bytes.  Not quite 256k but needing it.  And mode
12H requires 153,000 bytes.  Make sense?

Regards,

Steve N.

sinsi

The 4 planes are used in 16-colour (4-bit) modes, each plane is a colour (R,G,B and ?intensity?).
If a bit in a plane is set then the colour is on, so none set gives us black and all set gives us white.

I always visualised it as a vertical stack, with the pixel at 0,0 being made up of the first bit of each plane stacked on top of one another. This means that the first byte at A000 is actually 8 pixels.

It's been a long time, I might be remembering incorrectly  :rolleyes:

tda0626

Quote from: FORTRANS on June 22, 2024, 09:12:38 PMHi,

Quote from: tda0626 on June 22, 2024, 07:42:22 AMHow does that relate to 256KB of video memory if all 4 planes are just 16000 bytes? Guess that is where I getting hung up on, Steve.

   Well that is where the 16,000 bytes came from.  Abrash
and Richard Wilton show how to program the VGA to get a
higher resolution display.  I think Abrash calls those
Mode X.  Wilton in "Programmer's Guide to PC Video systems"
just calls them non-BIOS modes.  He shows six such modes
with the highest resolution being 360x480.  That is
172,000 bytes.  Not quite 256k but needing it.  And mode
12H requires 153,000 bytes.  Make sense?

Regards,

Steve N.

OK I think it does. So each plane is 64kb in size but you can only access 16kb of each plane in mode Y ( 320 x 200 unchained) because that is the maximum amount of bytes for that resolution 16kb x 4. I was under the impression that you could access all of the video memory regardless of resolution like it was regular memory. At 360x480, would you use A000:0000 to B800:FFFF plot a pixel on screen?



Quote from: sinsi on June 22, 2024, 09:28:32 PMThe 4 planes are used in 16-colour (4-bit) modes, each plane is a colour (R,G,B and ?intensity?).
If a bit in a plane is set then the colour is on, so none set gives us black and all set gives us white.

I always visualised it as a vertical stack, with the pixel at 0,0 being made up of the first bit of each plane stacked on top of one another. This means that the first byte at A000 is actually 8 pixels.

It's been a long time, I might be remembering incorrectly  :rolleyes:

I know it has been a long time since everyone has done any of this and I appreciate the help on the subject. Once I learn some of these graphic basics, I plan on moving to 32bit with that knowledge.

sinsi

Do you mean 32-bit colour in DOS or Windows?
Either way, you won't have to worry about VGA registers, planes etc. it's all reading/writing to a frame buffer.

DOS would need to use the VESA interface which, unless you are using banked mode (VBE2), would require some sort of protected mode to access the linear frame buffer (VBE3) e.g. a 1024x768 32-bit colour mode needs 3MB of memory.

Windows is even more abstracted, with GDI and DirectX/OpenGL.

zedd151

@tda0626: Why don't you simply move onto 32 bit now, rather than dealing with old antiquated code that most (still living)  folks don't remember much about anymore? As you said, you will be moving to 32 bit anyway...

daydreamer

If you go 32 bit windows,r8g8b8 24 bit color mode is what you should learn ,old 12h bit manipulation is waste of time
Low level api for windows use for this low level drawing, winapi GDI for conversion between array of pixel data <> bitmap before bitblt to screen
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

tda0626

Quote from: zedd151 on June 23, 2024, 12:00:57 AM@tda0626: Why don't you simply move onto 32 bit now, rather than dealing with old antiquated code that most (still living)  folks don't remember much about anymore? As you said, you will be moving to 32 bit anyway...


True. I hate to quit because I know eventually, with some persistence, I would get it but I guess the frustration at this point is not worth it. I have learned some basic skills from this that can translate so I won't be exactly starting from scratch and that is a good thing so all of this wasn't in vain. Thanks to everyone that helped me with my antiquated code and subjects.  :biggrin:

Quote from: sinsi on June 22, 2024, 11:56:21 PMDo you mean 32-bit colour in DOS or Windows?
Either way, you won't have to worry about VGA registers, planes etc. it's all reading/writing to a frame buffer.

DOS would need to use the VESA interface which, unless you are using banked mode (VBE2), would require some sort of protected mode to access the linear frame buffer (VBE3) e.g. a 1024x768 32-bit colour mode needs 3MB of memory.

Windows is even more abstracted, with GDI and DirectX/OpenGL.

Windows. Eventually I would like to program a simple game like Pong to get the basics down.

Quote from: daydreamer on June 23, 2024, 12:33:29 AMIf you go 32 bit windows,r8g8b8 24 bit color mode is what you should learn ,old 12h bit manipulation is waste of time
Low level api for windows use for this low level drawing, winapi GDI for conversion between array of pixel data <> bitmap before bitblt to screen


Thanks. Yep that is way to go. Are there any tutorials that you recommend for the Windows GDI?


Tim

NoCforMe

For learning GDI, I could whip up a small demo that would get you started. In some ways it's much more straightforward than DOS video programming: you don't deal with any low-level stuff like accessing registers.

I hope you don't give up your EGA/VGA experiments; that's a pretty fascinating aspect of programming. I'm going to read Abrash's chapter and see if I can't figure it out, maybe give you some pointers.
Assembly language programming should be fun. That's why I do it.

daydreamer

Check avcaballero source code for manipulate array and convert to bitmap demos ,if you want to continue on low level write pixels to screen,setpixel is too slow for fast drawing code ,milliseconds vs clock cycles
Check Microsoft pages on GDI drawing circle,rectangle for your simple pong game


my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

tda0626

Quote from: NoCforMe on June 23, 2024, 05:19:16 AMFor learning GDI, I could whip up a small demo that would get you started. In some ways it's much more straightforward than DOS video programming: you don't deal with any low-level stuff like accessing registers.

A demo would be great.

Quote from: NoCforMe on June 23, 2024, 05:19:16 AMI hope you don't give up your EGA/VGA experiments; that's a pretty fascinating aspect of programming. I'm going to read Abrash's chapter and see if I can't figure it out, maybe give you some pointers.

If you do, please let me know. I still would like to know how to draw and page flip in unchained mode.

Quote from: daydreamer on June 23, 2024, 05:44:56 AMCheck avcaballero source code for manipulate array and convert to bitmap demos ,if you want to continue on low level write pixels to screen,setpixel is too slow for fast drawing code ,milliseconds vs clock cycles
Check Microsoft pages on GDI drawing circle,rectangle for your simple pong game

avcaballero is that a user on this site or is it something else?