DOS VGA Tricks

Discussion of development of software for any "obsolete" computer or video game system.
User avatar
Nikku4211
Posts: 378
Joined: Sun Dec 15, 2019 1:28 pm
Location: Bronx, New York
Contact:

Re: DOS VGA Tricks

Post by Nikku4211 » Tue Nov 24, 2020 4:32 pm

rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
Nikku4211 wrote:
Tue Nov 24, 2020 6:43 am
I heard that 60hz 320x240 actually does have quite a bit of flicker, at least on actual DOS machines. 60hz is better for modern monitors, though.
I don't know why you've heard that? 60hz looks perfectly fine on old monitors. CGA and EGA cards were also 60hz at 320x200. 60hz was never a problem.
I've heard that from multiple people, so I'm not sure where it came from.
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
If you're making something that people are going to play in emulators (or even just an old computer with a modern display), 60hz helps a lot with smoothness since most people won't be able to actually display at 70hz, and 320x240 has a square pixel aspect ratio like everything uses now. It's kinda win/win/win to me, and like I said, works perfectly on old hardware too.
I know it's just me, but if I decided to do everything in software, I'd probably benefit more from having 12,800 less pixels to update than from using square pixels. If I wanted square pixels, I'd probably also want to use a bigger resolution like 400x300(or 800x600 if my game was made for 16 colours).
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
Nikku4211 wrote:
Tue Nov 24, 2020 6:43 am
4 actual video pages might be used for actual smooth hardware scrolling, if you manage to do both horizontal and vertical.
Hardware scrolling is done by repositioning a single page within the 64k/256k window. It doesn't directly have anything to do with having more than one page, unless you want to restrict your scrolling to within a small pre-drawn field that fits in your total memory... though in that case "pages" isn't particularly meaningful, the virtual field size is just anything that arbitrarily fits in memory, not separate pages.

Making scrolling smooth is mostly about doing the update efficiently enough for the target CPU. For something like Commander Keen, using hardware scrolling meant it only had to update the edges of the visible screen and any moving sprites.

Once your CPU is fast enough to copy the whole screen in vblank, there's less and less point to using hardware scrolling. The optimization of using hardware scrolling to limit your needed updates becomes very unnecessary. Even for Keen, the stuff it was doing only really helped the game play more smoothly on older model computers.
If your computer can copy the whole screen in vblank at 50-70 fps(Yes, some resolutions in VGA run at 50hz), I can see your point. Though some DOS developers may want to target older computers for their greater nostalgia factor.
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
So... using hardware scrolling on VGA only really makes sense to me for a very narrow range of target CPU hardware. It can be done, but for it to be a tangible optimization advantage, it's a rather situational thing?
How many DOS computers (and I mean computers that can run actual official MS-DOS) that have VGA can copy 320x240 at 60 fps? I don't know if Jazz Jackrabbit does software or hardware scrolling.

Yeah, of course you have the computers that were made to run Windows 95 and Windows 98, which can also boot in DOS mode.
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
Nikku4211 wrote:
Tue Nov 24, 2020 1:16 pm
Though it's probably better to just use 3 'pages' for the scrolling background while the first 'page' contains the HUD at the top for a raster split...
Are raster splits actually possible on VGA? I'm not sure if I've ever seen this demonstrated, and I didn't think the VGA registers worked this way.

I've seen talk of mid frame palette splits, but that's it? ...and even that seems like a lot of work for very limited utility, especially with 256 colours to work with already.
The Mode X game engine I linked a few posts above you uses raster splits for the title screen and the HUD. This split technique allows only part of the screen to scroll, while the rest of the screen doesn't scroll. I've heard conflicting information on whether you can split multiple times or only once, though.
lidnariq wrote:
Tue Nov 24, 2020 4:03 pm
There's the hardware split screen register (3d4 idx 18h) which resets scrolling to 0 at a configured time.

I'm not clear if there's enough else. There's all the effects in Copper, which tentatively appears to be:
Plasma (no idea)
Kefrens Bars (probably setting 3d4 idx 13h to 0)
bottom branding (3d4 idx 18h)
Parallax bars (I assume 3d8/9 across multiple colors)
"traditional" raster bars (3d8/9 on one color)
Changing display start relative to hsync (3d4 idx 1-5)
Brightness control per scanline (3c0 idx 14h; reportedly only works on some Tseng cards)
Not clear how the "pour" effect works
Y zooming (3d4 idx 9)
water effects (same)
Not clear how the X zooming works
That demo is really awesome. I watched it myself. It partially inspired this thread in the 1st place.
Joe wrote:
Tue Nov 24, 2020 4:19 pm
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
Are raster splits actually possible on VGA?
Yes, but you can only scroll the top part of the screen. There's an entire chapter about it in the aforementioned Black Book. (And you can abuse it for various effects by triggering the split more than once per frame!)
I didn't know EGA had raster splits and hardware scrolling too. Guess that explains the Keen hexology.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.

User avatar
rainwarrior
Posts: 8000
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS VGA Tricks

Post by rainwarrior » Tue Nov 24, 2020 4:32 pm

lidnariq wrote:
Tue Nov 24, 2020 4:03 pm
There's the hardware split screen register (3d4 idx 18h) which resets scrolling to 0 at a configured time.

I'm not clear if there's enough else. There's all the effects in Copper...
Ah! So there was a separate register to reset it! Interesting.

That demo looks really cool. Though... sadly I tested it on my DOS PC and it doesn't really work very well on that.

Aside from that "beautiful picture by joe" bouncedown, any effect that worked had some serious vertical jittering up and down and/or snow. Every horizontal wobble effect caused my monitor to lose picture (yes it's an LCD screen... probably a CRT would have fared better), and the "line fading" and scrolling text effects were just completely black. :(
lidnariq wrote:
Tue Nov 24, 2020 4:03 pm
Not clear how the "pour" effect works
Not clear how the X zooming works
By "pour" do you mean the one the demo calls "flood"? Isn't that just using Y scroll to duplicate lines?

For X zooming, can the horizontal resolution timing be adjusted per-scanline?
Last edited by rainwarrior on Tue Nov 24, 2020 5:23 pm, edited 1 time in total.

User avatar
rainwarrior
Posts: 8000
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS VGA Tricks

Post by rainwarrior » Tue Nov 24, 2020 5:07 pm

Joe wrote:
Tue Nov 24, 2020 4:19 pm
Even if your CPU is fast enough, your video card might not be, especially for 256-color graphics. For 60Hz 320x240, you need to write around 4.4MB/s to update the entire screen, and that's assuming you can double-buffer (so you don't need to wait for vblank) and don't need to spend any CPU time doing anything else. Good luck doing that with any ISA video card.
Ah, that's an good point.

Though, now I'm trying to think of any VGA games I had that actually ran at 60fps on my 286. Not sure if I had any. Maybe Wolfenstein did if I shrunk the view window to the tiniest setting...
Ah, thanks for the reference link. I actually have a copy of that book on my shelf nearby, but it's been 20 years since I read it. :S

lidnariq
Posts: 10241
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: DOS VGA Tricks

Post by lidnariq » Tue Nov 24, 2020 6:32 pm

rainwarrior wrote:
Tue Nov 24, 2020 4:32 pm
or snow.
I remember snow on a Paradise VGA card. Also slop in the raster effects any time the music replayer stole cycles, because 386sx at 16MHz.
rainwarrior wrote:
Tue Nov 24, 2020 4:32 pm
By "pour" do you mean the one the demo calls "flood"? Isn't that just using Y scroll to duplicate lines?
Could be? I was getting stuck on a maximum of 62 scanlines for Y stretching via 3d4 idx 9. But they could instead have used 3d4 idx 13h to change it between "infinite stretch" and normal size...
For X zooming, can the horizontal resolution timing be adjusted per-scanline?
Horizontal scanlines have to be more-or-less constant duration, so that can't be it. There are a choice of 4 different pixel clocks, but that's no-where near the 26 different apparent sizes I see in the video capture.

I should clearly go make a custom build of dosbox that logs VGA register access.
rainwarrior wrote:
Tue Nov 24, 2020 2:38 pm
I don't know why you've heard that? 60hz looks perfectly fine on old monitors. CGA and EGA cards were also 60hz at 320x200. 60hz was never a problem.
I mean, I did just confirm it myself. Maybe multisync monitors used phosphors were often tuned for higher sync rates, or they were bigger, or brighter, and trying to display 60Hz on them was definitely a bit flickery.
But the older VGA-only monitor I had I don't think had that problem.
some resolutions in VGA run at 50hz
Lowest standard refresh rate was 800x600 at 56Hz, or the various interlaced modes (e.g. 1024x768 @ 43i). Unlike VGA which was "just" doublescanned NTSC, timing-wise, there was never a standardized video mode that was doublescanned PAL.

User avatar
rainwarrior
Posts: 8000
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS VGA Tricks

Post by rainwarrior » Tue Nov 24, 2020 7:16 pm

lidnariq wrote:
Tue Nov 24, 2020 6:32 pm
For X zooming, can the horizontal resolution timing be adjusted per-scanline?
Horizontal scanlines have to be more-or-less constant duration, so that can't be it. There are a choice of 4 different pixel clocks, but that's no-where near the 26 different apparent sizes I see in the video capture.
It occurs to me that the text that is zooming is really only a few pixels tall. They could pre-render it in a bunch of different horizontal scalings offscreen and then tiling it vertically would reduce it to another Y-split effect.
Last edited by rainwarrior on Tue Nov 24, 2020 11:44 pm, edited 1 time in total.

Oziphantom
Posts: 1077
Joined: Tue Feb 07, 2017 2:03 am

Re: DOS VGA Tricks

Post by Oziphantom » Tue Nov 24, 2020 11:34 pm

Nikku4211 wrote:
Tue Nov 24, 2020 9:08 am
Oziphantom wrote:
Tue Nov 24, 2020 8:23 am
Adding a 4th Buffer does nothing as now you have
First Buffer <- visible on screen
Second Buffer <- fully drawn ready to display when the screen is ready
Third Buffer <- ready to be draw upon at any time.
Forth Buffer <- if you are drawing here, just draw on the Third instead. If the Third is done and the Second is not displayed then you are to far ahead and need to wait for the frames to catch up anyway.
That would be a good point, if I didn't say hardware scrolling.

Hardware scrolling alone doesn't require continually drawing to buffers because you can just change the initial screen offset so that you can scroll pretty smoothly vertically without taking much CPU time at all.

This is what my demo does.

Now, if you were able to do horizontal and vertical hardware scrolling like Root42 did, then 4 pages would now be pretty useful.

Both of these demos do nothing more than scroll, though, so there's no software sprites or anything like that.
Even with hardware scrolling you would still want to double buffer. Unless you don't have anything in the scene you want to update as per the example in the video you linked. As that is a Single Buffer.
But if you have sprites that move, such as a player that stays fixed in a single spot on the screen. Then you will need to shift with hardware and then clear and redraw your sprites. So typically you shift each buffer by 2*delta as you flip between them.

However their use of Pages is not a Buffer. The demo shown only has 1 buffer, but that buffer is made up of 4 memory pages, ie their screen is 4 screens in size. They are using the terms interchangeable which makes it confusing.

tepples
Posts: 22280
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: DOS VGA Tricks

Post by tepples » Wed Nov 25, 2020 8:09 am

Assuming standard VGA with 256 KiB VRAM, 8bpp display modes resembling MCGA/VGA mode 13h, and an ISA bus in the 7 to 11 MHz range:

For hardware-accelerated scrolling in eight directions, you need to make the virtual screen slightly larger in both dimensions than the actual screen. Let's say 336x224 for mode Y (320x200) or 336x256 for mode X (320x240).

If you're scrolling vertically, you need an additional screen's worth of space for the vertical scroll position to vary to avoid wrapping. That's what the third buffer is for, not for "triple buffering" in the sense of allowing for frame rates between 31 and 59 fps. Three 336x256 pixel Mode X buffers occupy 258048 bytes, which just barely fits into the VGA's 262144 bytes of VRAM. This means you don't get to use accelerated VRAM-to-VRAM copies for background tiles when erasing sprites. (Mode Y takes 225792 bytes.)

There are a couple other tricks to do. One is to set mode Y and extend the top and bottom borders to give 525 total lines for 60 Hz. I seem to remember Jazz Jackrabbit doing something like this. Another is to use hardware split screen to set a bottom status bar. This means that 16 or 32 of your vertical pixels can be single-buffered, not triple-buffered. Jazz did this as well. Mode Y with a 24-line bottom status bar can use three 336x192 buffers and one 336x24 status bar for 201600 bytes, leaving 59 KiB for background tiles.

krzysiobal
Posts: 829
Joined: Sun Jun 12, 2011 12:06 pm
Location: Poland

Re: DOS VGA Tricks

Post by krzysiobal » Wed Nov 25, 2020 12:50 pm

This will be about tricks in text mode.

0) As far as I remember, DOS can offer 3 video modes for text display:
* 8x16 characters (most typically used)
* 8x14 characters (used quite rarely, for example - in the BIOS start screen (when EPA Pollution Preventer logo is shown)
* 8x8 characters

1) There is an old DOS antivirus software called MKS_VIR with database of known viruses that contain descriptions and special effects presentations that those viruse produced. One of them, Delver Stealth, displays red-white bars in background that are scrolling much finer that 8x16 grid. Also, their color is smooth. I was always curious how they did it and I found out this demo was not displayed correctly in DosBox so i asked Dosbox Community to check it out and they found the reason and they explained how it was done:
https://www.vogons.org/viewtopic.php?t=27344
Image

2) Going back to the BIOS Epa Pollution Preventer logo
Image
I was wondering as a kid how this image is displayed, if this is text mode? It turns out both logos are built up using text-characters, but their appearance is Character Generator is redefined to display unique 8x14 portion of image. It can be up to: 136x126 pixels which consumes 17 * 9 = 153 characters.
I even found a program that allows to create custom logo and embeed them in the BIOS.BIN file that can be later used to "uprade" bios by AWDFLASH.EXE

3) Various disc tools from Norton Utillities packed used semi-graphical interface in text-mode. The most beautiful part of it is the mouse cursor, which with each mouse movement moves with granularity of 1 pixel! So it must draw the arrow on top of four surrounding text-characters on the fly.
Image

User avatar
Nikku4211
Posts: 378
Joined: Sun Dec 15, 2019 1:28 pm
Location: Bronx, New York
Contact:

Re: DOS VGA Tricks

Post by Nikku4211 » Wed Nov 25, 2020 1:45 pm

krzysiobal wrote:
Wed Nov 25, 2020 12:50 pm
This will be about tricks in text mode.

0) As far as I remember, DOS can offer 3 video modes for text display:
* 8x16 characters (most typically used)
* 8x14 characters (used quite rarely, for example - in the BIOS start screen (when EPA Pollution Preventer logo is shown)
* 8x8 characters

1) There is an old DOS antivirus software called MKS_VIR with database of known viruses that contain descriptions and special effects presentations that those viruse produced. One of them, Delver Stealth, displays red-white bars in background that are scrolling much finer that 8x16 grid. Also, their color is smooth. I was always curious how they did it and I found out this demo was not displayed correctly in DosBox so i asked Dosbox Community to check it out and they found the reason and they explained how it was done:
https://www.vogons.org/viewtopic.php?t=27344
Image

2) Going back to the BIOS Epa Pollution Preventer logo
Image
I was wondering as a kid how this image is displayed, if this is text mode? It turns out both logos are built up using text-characters, but their appearance is Character Generator is redefined to display unique 8x14 portion of image. It can be up to: 136x126 pixels which consumes 17 * 9 = 153 characters.
I even found a program that allows to create custom logo and embeed them in the BIOS.BIN file that can be later used to "uprade" bios by AWDFLASH.EXE

3) Various disc tools from Norton Utillities packed used semi-graphical interface in text-mode. The most beautiful part of it is the mouse cursor, which with each mouse movement moves with granularity of 1 pixel! So it must draw the arrow on top of four surrounding text-characters on the fly.
Image
Woah. Yeah, text mode tricks count, too, since I'm not going to bother making another thread for that. I guess I'll say that for the sake of only having 1 thread, EGA, MCGA, MDA, and CGA tricks count for here as well.

By the way, here's Exhibit 1 being run on a real DOS computer in a video by Danooct1(I recommend his channel, he documents a lot of retro computer viruses).

Notice how the border is affected, too, and how it has the same colour as the text. Notice how the bottom rectangle isn't a gradient, but is just the bottom scanline of the effect duplicated enough to make a whole rectangle.

I think the Kela DOS virus has a very similar effect in graphics mode, with the gradient on the big 'KELA' logo. Here's it running on a real DOS computer, also recorded by Danooct1.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.

lidnariq
Posts: 10241
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: DOS VGA Tricks

Post by lidnariq » Wed Nov 25, 2020 1:52 pm

krzysiobal wrote:
Wed Nov 25, 2020 12:50 pm
* 8x16 characters (most typically used)
* 8x14 characters (used quite rarely, for example - in the BIOS start screen (when EPA Pollution Preventer logo is shown)
* 8x8 characters
These pre-provided modes come from the VGA, EGA, and CGA cards respectively. Importantly, the 16-scanline-high characters are almost always drawn for 9 columns in each character cell, and uses the VGA (and MDA)'s special stretching rules to fill a 9-pixel-wide character cell from 8 bits of data. (Namely: the 9th column is clear, except for specific characters, where it's a copy of the 8th). The fonts were often drawn to take advantage of this, and displaying the same characters in just an 8-pixel wide cell would blob together.

For any software that relied on composing fancy graphics using the character generator, this padding was inconvenient, and games (or the EnergyStar logo) often switched to the 640x350 text mode with a 8x14 font to get around it. (However, this functionality wasn't strictly tied: one could use 8x16 characters, as long as you had a font that would look ok. Fewer developers did this; I assume the other solution was discovered first, or was enough simpler).

The VGA itself supports anywhere from 1 to 32 scanlines of character generator data, although real hardware is still limited by the constraints of the monitor. However, for virtual machines of old operating systems, VirtualBox's VGA emulation means I can use a 720x1080 text mode and get nicer letter forms - as long as I can find a font that looks good.

Joe
Posts: 445
Joined: Mon Apr 01, 2013 11:17 pm

Re: DOS VGA Tricks

Post by Joe » Wed Nov 25, 2020 4:07 pm

lidnariq wrote:
Wed Nov 25, 2020 1:52 pm
Importantly, the 16-scanline-high characters are almost always drawn for 9 columns in each character cell, and uses the VGA (and MDA)'s special stretching rules to fill a 9-pixel-wide character cell from 8 bits of data.
VGA had separate 8x8, 8x14, 9x14, 8x16, and 9x16 fonts, although only a handful of glyphs had specific 8-pixel-wide or 9-pixel-wide variants.
lidnariq wrote:
Wed Nov 25, 2020 1:52 pm
I assume the other solution was discovered first, or was enough simpler
My bet is on simpler. I've read a lot of VGA documentation and getting 8x14 characters is two BIOS calls: one to select 350 lines and one to (re)set text mode. I'm not sure if it's even possible to get 8x16 characters in text mode using only BIOS calls.

Oziphantom
Posts: 1077
Joined: Tue Feb 07, 2017 2:03 am

Re: DOS VGA Tricks

Post by Oziphantom » Wed Nov 25, 2020 10:47 pm

tepples wrote:
Wed Nov 25, 2020 8:09 am
If you're scrolling vertically, you need an additional screen's worth of space for the vertical scroll position to vary to avoid wrapping. That's what the third buffer is for, not for "triple buffering" in the sense of allowing for frame rates between 31 and 59 fps. Three 336x256 pixel Mode X buffers occupy 258048 bytes, which just barely fits into the VGA's 262144 bytes of VRAM. This means you don't get to use accelerated VRAM-to-VRAM copies for background tiles when erasing sprites. (Mode Y takes 225792 bytes.)
Here by 3rd buffer you mean "make the first buffer twice as high"?

User avatar
Nikku4211
Posts: 378
Joined: Sun Dec 15, 2019 1:28 pm
Location: Bronx, New York
Contact:

Re: DOS VGA Tricks

Post by Nikku4211 » Sun Nov 29, 2020 12:11 am

lidnariq wrote:
Wed Nov 25, 2020 1:52 pm
hese pre-provided modes come from the VGA, EGA, and CGA cards respectively. Importantly, the 16-scanline-high characters are almost always drawn for 9 columns in each character cell, and uses the VGA (and MDA)'s special stretching rules to fill a 9-pixel-wide character cell from 8 bits of data. (Namely: the 9th column is clear, except for specific characters, where it's a copy of the 8th). The fonts were often drawn to take advantage of this, and displaying the same characters in just an 8-pixel wide cell would blob together.
Oh, you mean like this?
FreeVGA wrote:
LGA - Line Graphics Enable

This field is used in 9 bit wide character modes to provide continuity for the horizontal line characters in the range C0h-DFh. If this field is set to 0, then the 9th column of these characters is replicated from the 8th column of the character. Otherwise, if it is set to 1 then the 9th column is set to the background like the rest of the characters.
This page has a couple other cool registers. I recommend the whole FreeVGA site, really. It's very useful for this thread.
Oziphantom wrote:
Wed Nov 25, 2020 10:47 pm
tepples wrote:
Wed Nov 25, 2020 8:09 am
If you're scrolling vertically, you need an additional screen's worth of space for the vertical scroll position to vary to avoid wrapping. That's what the third buffer is for, not for "triple buffering" in the sense of allowing for frame rates between 31 and 59 fps. Three 336x256 pixel Mode X buffers occupy 258048 bytes, which just barely fits into the VGA's 262144 bytes of VRAM. This means you don't get to use accelerated VRAM-to-VRAM copies for background tiles when erasing sprites. (Mode Y takes 225792 bytes.)
Here by 3rd buffer you mean "make the first buffer twice as high"?
According to the context, I'm pretty sure it's safe to assume that's what he meant.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.

lidnariq
Posts: 10241
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: DOS VGA Tricks

Post by lidnariq » Sun Nov 29, 2020 12:13 am

Yup, that register.

Because I learned these things during the BBS era, I mostly just like to refer to VGA.TXT, where it is instead referred to as "9-bit wide characters if set"

User avatar
Nikku4211
Posts: 378
Joined: Sun Dec 15, 2019 1:28 pm
Location: Bronx, New York
Contact:

Re: DOS VGA Tricks

Post by Nikku4211 » Sun Nov 29, 2020 12:55 pm

lidnariq wrote:
Sun Nov 29, 2020 12:13 am
Yup, that register.

Because I learned these things during the BBS era, I mostly just like to refer to VGA.TXT, where it is instead referred to as "9-bit wide characters if set"
Oh, that's a cooler resource.

Oh, and by the way, I went on the Tweak DOS program and compared its unchained Mode Y with a similar 256x224 256-colour VGA mode the program had as one of its presets.
320vs256.png
The differences are underlined in orange.
Last edited by Nikku4211 on Mon Nov 30, 2020 7:04 pm, edited 1 time in total.
I have an ASD, so empathy is not natural for me. If I hurt you, I apologise.

Post Reply