this image contains text
Smooth Scrolling
-Intro-
This article covers smooth scrolling in text mode. It actually does not
go into much depth of how to do anything useful, but it does give you every-
thing you need to know to do something worthwhile. But enough talk, lets
code smooth scrolling...
-Vertical Scrolling-
There are two main VGA registers involved in vertical scrolling. The first
is the vertical pel panning register. Register 08H of the CRT controller is
changed by first writing the register number to port 3D4H and then writing to
3D5H the value you wish to move up on the character. The maximum is 15 since
a VGA character is 16 pixels tall. This now lets us move up and down just in
one line. But thats not what we want. We want continuous smooth scrolling.
What we now need to do is change the start address of the screen in video
memory. This is done by accessing the CRT vertical start address set of
registers. Because the address is more that 8-bits it was split between reg
0CH and 0DH. But there is a slight twist thrown in just to trick you. 0CH
is not the low byte, but the high byte. You right the high byte and then the
low byte to 0DH. Not really confusing, but it is sorta backwards. Here is
the code just so you can follow what I mean.
outp0x3d4,0x0c //High byte of offset
outp0x3d5,a 8
outp0x3d4,0x0d //Low byte of offset
outp0x3d5,a
The value you will actually use will vary depending how you have the screen
set up. In 80x25 textmode 3 you will take the pixel line down divide by 16
and then multiply that by the characters per line. As I mention later, you
will probably have the screen set up wider than the default 80 chars. If
this is the case then you would multiply by 160 or whatever width you choose.
-Horizontal Scrolling-
This complicates everything a little more. I didnt include source code
for horizontal scrolling because this article is due in about 3 hours. But,
all you need to do horizontal scrolling is change the horizontal pel panning
register just like you did with the vertical scrolling. That is attribute
controller register 13H accessed through port 3C0H. There is a slight trick
here because the attribute controller will turn off the display if you dont
set bit 5 of the controller. The solution is to send 3C0H the value of 33H
register 13H plus bit 5. This will keep the screen from going black.
In VGA this register is going to hold a value from 0 to 8 because a text
character is 9 pixels wide. To scroll right are starting at 8 and then
decrement from 7 down to 0. A jump back up to 8 will move that final pixel.
To get continuous smooth scrolling you will need to set the memory up
correctly to allow the screen to scroll over to. This is done by changing
the CRT offset registers default value of 80 chars to something like 160
chars. This then lets you have a nice wide screen to scroll all over on.
-Glaring Omissions-
One major thing I left out was any sort of waiting for a retrace. It
can be fairly important because you get strange things happening when you
change to start address of video memory while its drawing the screen. Ill
leave it to you to put that in when you go to implement horizontal scrolling.
-Opiate-
If you are still here you probably are actually interested in implementing
some sort of smooth scrolling. For an example of how I used it go get PILL
from www.hornet.org It was Opiates first demo that was DQ at NAID 96. The
readme text scroller that is included has smooth text scrolling.
-Source Code-
Written in Watcom protected mode but should work pretty much in any C++
compiler.
include iostream.h
include conio.h
include i86.h
void startint a
outp0x3d4,0x0c //High byte of offset
outp0x3d5,a 8
outp0x3d4,0x0d //Low byte of offset
outp0x3d5,a
void vmoveshort int n
outp0x3d4,8
outp0x3d5,n
void mainvoid
for int x0x160x++
startx/16*80
vmovex 16
delay30
for x160x0x--
startx/16*80
vmovex 16
delay30
***THE END***
-Tyr / Opiate
davidl@ccwf.cc.utexas.edu
-Intro-
This article covers smooth scrolling in text mode. It actually does not
go into much depth of how to do anything useful, but it does give you every-
thing you need to know to do something worthwhile. But enough talk, lets
code smooth scrolling...
-Vertical Scrolling-
There are two main VGA registers involved in vertical scrolling. The first
is the vertical pel panning register. Register 08H of the CRT controller is
changed by first writing the register number to port 3D4H and then writing to
3D5H the value you wish to move up on the character. The maximum is 15 since
a VGA character is 16 pixels tall. This now lets us move up and down just in
one line. But thats not what we want. We want continuous smooth scrolling.
What we now need to do is change the start address of the screen in video
memory. This is done by accessing the CRT vertical start address set of
registers. Because the address is more that 8-bits it was split between reg
0CH and 0DH. But there is a slight twist thrown in just to trick you. 0CH
is not the low byte, but the high byte. You right the high byte and then the
low byte to 0DH. Not really confusing, but it is sorta backwards. Here is
the code just so you can follow what I mean.
outp0x3d4,0x0c //High byte of offset
outp0x3d5,a 8
outp0x3d4,0x0d //Low byte of offset
outp0x3d5,a
The value you will actually use will vary depending how you have the screen
set up. In 80x25 textmode 3 you will take the pixel line down divide by 16
and then multiply that by the characters per line. As I mention later, you
will probably have the screen set up wider than the default 80 chars. If
this is the case then you would multiply by 160 or whatever width you choose.
-Horizontal Scrolling-
This complicates everything a little more. I didnt include source code
for horizontal scrolling because this article is due in about 3 hours. But,
all you need to do horizontal scrolling is change the horizontal pel panning
register just like you did with the vertical scrolling. That is attribute
controller register 13H accessed through port 3C0H. There is a slight trick
here because the attribute controller will turn off the display if you dont
set bit 5 of the controller. The solution is to send 3C0H the value of 33H
register 13H plus bit 5. This will keep the screen from going black.
In VGA this register is going to hold a value from 0 to 8 because a text
character is 9 pixels wide. To scroll right are starting at 8 and then
decrement from 7 down to 0. A jump back up to 8 will move that final pixel.
To get continuous smooth scrolling you will need to set the memory up
correctly to allow the screen to scroll over to. This is done by changing
the CRT offset registers default value of 80 chars to something like 160
chars. This then lets you have a nice wide screen to scroll all over on.
-Glaring Omissions-
One major thing I left out was any sort of waiting for a retrace. It
can be fairly important because you get strange things happening when you
change to start address of video memory while its drawing the screen. Ill
leave it to you to put that in when you go to implement horizontal scrolling.
-Opiate-
If you are still here you probably are actually interested in implementing
some sort of smooth scrolling. For an example of how I used it go get PILL
from www.hornet.org It was Opiates first demo that was DQ at NAID 96. The
readme text scroller that is included has smooth text scrolling.
-Source Code-
Written in Watcom protected mode but should work pretty much in any C++
compiler.
include iostream.h
include conio.h
include i86.h
void startint a
outp0x3d4,0x0c //High byte of offset
outp0x3d5,a 8
outp0x3d4,0x0d //Low byte of offset
outp0x3d5,a
void vmoveshort int n
outp0x3d4,8
outp0x3d5,n
void mainvoid
for int x0x160x++
startx/16*80
vmovex 16
delay30
for x160x0x--
startx/16*80
vmovex 16
delay30
***THE END***
-Tyr / Opiate
davidl@ccwf.cc.utexas.edu
log in to add a comment.