Page 1 of 1

How does smooth scrolling work on VGA-DOS games?

Posted: Sun Dec 03, 2017 12:04 pm
by maduino
Hi there,

I'm going to build me a retro DOS game using Turbo C 2.01 - just for fun and the sake of entertainment. Currently I've a problem with performance: I've a big tile map (bigger than the screen) which should be scrollable by the user with the cursor keys. My current method of redrawing the screen is to write all information directly to 0xA0000000 + [y * 320 + x] which is very slow (redraw the entire screen).

My vision is to build a game which scrolls very smoothly over the tile map. I already found an example how it should work out: http://www.doshaven.eu/game/dark-quest/.

I then researched a little bit online about scrolling and found information about an attribute controller register for VGA where one can write to 13h a 4-bit pixel offset value. Using the following snippet I was able to move the screen:

Code: Select all

inp(0x3da);             
outp(0x3c0, 0x13 | 0x20);
outp(0x3c0, offset_in_x);
But I could not move the screen very far - only a couple of pixels. I then continues online research and found out that the number to scroll is limited to a small value.

So I came here with the hope that you can tell me how this can be done (properly) and where I can find further information.

Any ideas?

Regards!

Re: How does smooth scrolling work on VGA-DOS games?

Posted: Sun Dec 03, 2017 8:00 pm
by Schol-R-LEA
The first place to start is to ask if you are already using double buffering or not. You really can't get smooth motion across the screen of any kind if you aren't. The basic idea is to have two copies of the video display memory, one which is in use by the monitor, the other of which is 'shadowed', preferably both inside the video buffer but on different memory 'pages'. You would draw to the shadowed copy, then 'flip' them by changing which of the video memory pages is being used.

You might actually want to have a third copy in main memory as well; this allows you to perform the editing there, then copy it to the shadowed page before flipping. On modern systems, unless the system is using an integrated GPU that is 'sharing' main memory with the CPU, main memory is usually faster to access than video memory even when the video memory has a faster clock rate (since the main memory is connected more immediately to the CPU through what is called the 'memory local bus', and doesn't have to pass through the PCI bridge), and for non-integrated video, it also leaves the bus connection free more of the time.

(This doesn't mean that integrated video is better; quite the opposite, usually, as the CPU and GPU can end up fighting for contention over the shared memory local bus, and with most local bus arrangements the GPU usually accesses it slower than the CPU even if the CPU is idle. Integrated video with a separate video memory might be slightly faster than an expansion bus card, but the CPU generally still won't get local bus speeds accessing that, so it's pretty much the same as with the separate video card.)

Similarly, you probably will need to sync or latch the vertical refresh, to ensure that you are only writing to the video memory between refresh cycles. This goes hand in hand with double buffering, as the former allows you to create a new image off-screen, but you still need to make sure that you don't flip the pages during a vrefresh, as that could lead to screen tearing (which isn't as serious for 2D games as it is for 3D games, unless it is happening so often that it makes it hard to make out what is going on, but it still looks sloppy).

Most video display systems today have hardware support for this, and much more besides, but for a retro VGA program, you probably won't want (or be able) to use those, especially if it is actually running it under MS-DOS or a workalike such as FreeDOS (since pretty much no one has been providing MS-DOS drivers for their new video cards in the past twenty years, and even if you were willing to write one yourself, you'd have trouble getting the necessary information even for an 'open' one). Just what you'll be able to use in terms of card-specific hardware will depend on which card you are using, the availability of a driver, and just how 'authentic' you mean to make it (i.e., if you stick to just the VBE routines, then you will be limited to the common set of operations supported by VBE).

Re: How does smooth scrolling work on VGA-DOS games?

Posted: Sun Dec 03, 2017 9:17 pm
by Brendan
Hi,
maduino wrote:My vision is to build a game which scrolls very smoothly over the tile map. I already found an example how it should work out: http://www.doshaven.eu/game/dark-quest/.

I then researched a little bit online about scrolling and found information about an attribute controller register for VGA where one can write to 13h a 4-bit pixel offset value. Using the following snippet I was able to move the screen:

Code: Select all

inp(0x3da);             
outp(0x3c0, 0x13 | 0x20);
outp(0x3c0, offset_in_x);
Usually there's a "display start" (which can be used for scrolling but works on entire bytes) and then there's something smaller (the "Horizontal PEL Panning Register" you're looking at) that is only intended for video modes where scrolling by an entire byte is too much (e.g. modes like text mode, 4-colour mode and 16-colour mode where an entire byte is more than one pixel).
maduino wrote:So I came here with the hope that you can tell me how this can be done (properly) and where I can find further information.

Any ideas?
First you need to find an extremely rare book. It's a relatively thick book with a black cover and no title, and it's contents are written in Latin. Within this book you'll find a spell that you can cast to speak to dead people. Use this spell to talk to a man named Ralph McDreagle, and ask him to tell you of the horror of his death. Be warned, it's a gruesome tale involving a sadistic form of torture where extremely poor quality video modes are used to rupture a person's eyes (the victim slowly bleeds to death from their eye sockets).


Cheers,

Brendan

Re: How does smooth scrolling work on VGA-DOS games?

Posted: Mon Dec 04, 2017 5:23 pm
by Thomas
Hi maduino,
Retro DOS game development is much fun!. I started programming this way, Books I found interesting are the following.


--Thomas

Re: How does smooth scrolling work on VGA-DOS games?

Posted: Mon Dec 04, 2017 7:31 pm
by Thomas
Hi maduino,

It is worth looking into VGA Mode X documentation, Page Flipping can be achieved with Mode X which can help with scrolling games.

Simpler way to do is to use an of screen buffer , ( you blit it before each update <- there some turbo c specific functions - fmemcpy or something to do far pointer copy, you can also write these routines in assembler for better efficiency, Also need to wait for vertical retrace like other poster mentioned ). Then you can use something like a 2d camera like system ( just like the 3d counter part) to show the appropriate portions of the game world ( you may chose to use a tile map here ). Hope some of my ramblings is useful to you. Andre Lamothe book has a sample for some of this :).

--Thomas