home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 15
/
CD_ASCQ_15_070894.iso
/
news
/
sorcpak
/
bs_hwscr
/
explain.doc
< prev
next >
Wrap
Text File
|
1993-10-17
|
20KB
|
448 lines
▓▓▒▒░░ Hardware Scrollies .... Everything You Might Dream Of .... ░░▒▒▓▓
Released : 17/10/93
Doc & Code : Binary Slave
Last Minute: Living Nature
Binary Slave presents his first source-code to Public Domain.
It mainly consist of the so called Hardware scroll... .
A Hardware scroll is a characteristic of the standard VGA-card.
It does not take hudge CPU time just a few port writes and the rest is up
to another VGA characteristic nl. Vertical retrace which does all the
synchronisation.
I will give you an idea/example how to make a hardware scrolly... .
So you'll be able to make very fast scrollers (I sure hope so) on
your PC even on an XT! Just like in some demos.
All you need is some knowledge about programming pascal/assembly,
graphic environments,image processing.
The code is written in TP & ASM, and may easyly be converted into C
language or similar languages. The complete source is given and you need
at least TP version 6.0.
For the assembly procedures I just saved the DS if it's changed, but if
you want to work 100% properly this doesn't fit. Cause if you don't ....
God may be with you...lazy me.
You propably need to preserve the following registers:
- Base pointer BP.
- Stack Segment SS.
- Stack pointer SP.
- Data Segment DS.
An asm statement can freely modify these registers:
- AX,BX,CX,DX
- SI,DI
- ES
- Flags
On entry to the asm statement, the built-in assembler knows only the BP, SP,
SS, and DS registers; it can assume nothing else about register contents.
I've chosen those languages for several reasons.
Turbo Pascal : - one of the most popular languages...
- very easy to read/write/learn and understand some techniques.
ASM : For the fast actions... such page flipping/filling/drawing routines.
It was not the intention to make a super fast scrolling, no, it is
intended to make Hardware scrolling a fact and understandable to all coders,
not just the asm-speed freaks (who already know the hardware scrollies).
The speed of the actual scroll is not so important due to the synchronisations
Learning to make smooth animations is perhaps more important than the speed of
the animation!
Also try not to make too much procedure calls because TP's internal memory
management slows (due to the activation records) down the animation.
The scrolling is performed in tweaked video mode, it is also perfectly
possible that you make your scrollers in normal graphics mode (13H -
320*200*256colors), but I think mode X has got its charms...
First Let me tell you something about your PC...
On the base level of your PC there exist things called I/O ports.
These ports makes it possible to rebuild/change the entire
graphic evironment.
I Some general functions of the VGA
=================================
I.1 The Graphics Controller
---------------------------
The graphics controller is a VLSI circuit that resides in the data path
between the processor and the display memory. In its default state, the
graphics controller is transparent. As a programmer you should be able to
modify this port in order to let it assist in drawing operations. Like
logically combine,rotate processor data with the display memory data
(PROCESSOR READ LATCHES, which can be verry usefull...).
Color compare functions (rep scasb ex.sprites),Data serializer,Logical Unit.
I.2 The Crt Controller Registers
---------------------------------
The CRT controller controls the crt (Cathode Ray Tube) by generating the
syncing and blanking signals that define the display raster.
It displays colors that are generated by a beam of electrons that strike
the phosphorus coating on the back of the crt screen and cause it to glow.
The electron beam is swept across the display screen from the left to the
right in a series of horizontal lines. At the same time, it's intensity is
modulated to produce display patterns. The electron beam must continiously
redraw the pattern on the screen 50,60,70 or more times a second, depending
on the display used (=REFRESH TIME). The sweep pattern of the electron
beam is called RASTER LINES.
The beam begins in the upper left corner of the display and sweeps right.
When it reaches the right edge of the screen, the beam is shut off (HORIZONTAL
BLANKING) and then rapidly brought back to the left edge of the screen
(HORIZONTAL RETRACE) to begin the next horizontal scan just below the previous
one. After all the horizontal scans have been completed (HORIZONTAL TOTAL),
the electron beam will end up in the lower right corner of the screen.
At this point the beam is shut off once again (VERTIKAL BLANKING) and then
rapidly brought back up to the upper left corner (VERTIKAL RETRACE) so the
next raster can begin.
This last effect is normally very synchronic on all VGA-cards, so this
effect should be very good to synchronize all our animation...Ok?
I.3 Display Memory
------------------
The nowadays VGA contains up to 256Kb or more display memory, divided into
four independent 64Kb sections of memory! These are called color planes.
These color planes all reside in the same processor memory space.
Which color planes are being written to or read from at any time is
determined by several I/O ports.
I.4 Attribute Controller
------------------------
The attribute controller determines wich color will be displayed for both text
and graphic mode. The heart of the controller is the color look-up table that
translate four bit information from display memory into 6 bit color information
mation (EGA) or 12 bit color information (VGA).
I.5 Sequencer
-------------
The sequencer controls the sequencing of all functions. It generates the dot
and character clocks that control display refresh timing. It controls the
timing of display memory read and write cycles, and generate wait-states
if necessary.
II The VGA Mode
============
The standard (MCGA) or bios 13H mode has a resolution of 320*200 and
256 colors. You can call this mode by a simple BIOS-call. The BIOS takes
care of all the additional settings, no prob.
To get into tweaked video mode which has a resolution of 320*200*4 and
256 colors, we have to do some old tricks.
-->"unchain" the vga mode, disable the "odd/even adressing".<--
These setting enable us to use 256kb of display memory.
Yes, 4 * 64Kb color planes are available, this results in a smooth page
flipping animation scenes...(if handled properly ofcoz).
As you all know the VGA memory adress area starts from 0A000:0000H.
In tweaked mode we have:
0A000:0000 equals 1th pixel + 2nd pixel + 3th pixel + 4th pixel!
0A000:0001 equals 5th pixel + 6th pixel + 7th pixel + 8th pixel!
etc...
The only thing distinguishing the pixels is the memory adress and the color
planes which they are in.
As we know we have 4 planes ... 4 pixel
0A000:0000 1th plane .... 1th pixel
0A000:0000 2nd plane .... 2nd pixel
0A000:0000 3th plane .... 3th pixel
0A000:0000 4th plane .... 4th pixel
0A000:0001 1th plane .... 5th pixel
0A000:0001 2nd plane .... 6th pixel
0A000:0001 3th plane .... 7th pixel
0A000:0001 4th plane .... 8th pixel
etc etc... ok?
Remark: In our case this means that the physical screen is only 80 memory
adress spaces (pixels) in width!! No longer 320!!
200 in height remains the same.
III The used i/o ports:
===================
III.1 Plane reading/writing
---------------------------
The Graphics controller: port 3CEH
index 00 : Set/reset register
01 : Set/reset enable register
02 : Color compare register
03 : Data rotate & Function Select
04 : Read plane Select register
05 : Mode register
06 : Miscellaneous register
07 : Color Don't care register
08 : Bit mask register...
Writing on the screen...
Write to plane ... plane enable (port 3CEH index 01).
p.e.: mov DX,3ceH ; select port 3CEH
mov al,01 ; select index 01
out dx,al ; write selections to port
inc dx
d0 d1 d2 d3 * * * *
port 3CEH index 1 ╚══╩══╩══╩══╩══╩══╩══╩══╝
0 1 2 3 4 5 6 7
* = Not used by plane switching.
d0=1 : plane 0 write enbale
d0=0 : plane 0 write disabled!
d1... plane 1.
d2... plane 2.
d3... plane 3.
Yes, it is possible to write with one movsb to write 4 pixels at
once... (yes even eight if you enable double word mode).
Such routines are used to clear verry fast the screen in graphics
mode just imagine 4 64Kb display memory screen cleared at the
speed of clearing 2 screens (4K) in text mode !!!
OR
mov al,00 --> in al,dx
and al,11110000B force all planes on write disabled.
or al,1 force bit 0 on 1 to make plane 0
write enable..
out dx,al ; write changes to port.
For planes 1..3 the same code san be used.
plane 1: mov al,02H
plane 2: mov al,04H
plane 3: mov al,08H
all planes: mov al,0FH
Reading from memory/screen:
Read plane select register... (port 3CEH index 04)
This one differs from the plane enable :-)
d0 d1 * * * * * *
port 3CEH index 04 ╚══╩══╩══╩══╩══╩══╩══╩══╝
0 1 2 3 4 5 6 7
* = Not used by plane switching.
d0&d1=00 : plane 0 read enbale.
01 : plane 1 read enable.
10 : plane 2 read enable.
11 : plane 3 read enbale.
you are not allowed to read from more than one plane at a time since
this would not be meaningfull.
So, in this way you are able to read from the screen.
III.2 The Logical Screen Width
-------------------------------
In graphics mode, it defines the logical distance, in either 16 bit
memory words or 32 bit double words between successive scan lines.
In all standard operating modes,the logical screen width is equal to
the physical screen width.
You can change the width of the screen to make you screen wider so you
can update you scrolly (animation) out of the screen so nobody will
see it!!
In the example we use 40*4=160 words this means 320 bytes in width.
Actually *4 =1280 bytes wide!!!!
You can change all these settings for example zooming or the hardware
scroll ( Panning) page flipping animation.
You can alther the screen width with the CRT controller... .
PORT 3B4/3D4H
-------------
index 00H Horizontal total 0CH Start adress high
01H Horizontal display end 0DH Start adress low
02H Start horizontal blank 0EH Cursor location high
03H End horizontal blank 0FH Cursor location low
04H Start horizontal retrace 10H Vertikal retrace start
05H End horizontal retrace 11H Vertikal Retrace end
06H Vertical total 12H Vertikal Display end
07H Overflow 13H Logical Screen width
08H Preset row scan 14H Underline location
09H Maximum scan line 15H Start Vertikal Blank
0AH Cursor Start 16H End Vertikal Blank
0BH Cursor end 17H Mode Control register
18H Line Compare register
Handle these ports with care because some of them can damage your
monitor screen!!!
Well the index we are intersted in is 13H:
ex. in TP:
port[$3d4]:=$13 ;select port 3D4H index 13H = logical screen width.
port[$3d5]:=..... length of the screen ... in our case 40*4 =160 words.
IV The Actual Hardware Scroll
==========================
a) Byte Panning
---------------
If we take a look at the CRT controller port 3D4H we see the index
0CH and 0DH.
The start adress high and Start adress low... .
This is a 16 bit read/write register that defines the adress in
display memory of the data that will be displayed in the upper left
corner of the screen (starting position).
This register can be used to byte-panning an image on the screen or to do
the page-flipping.
1 word equals High Low
╚════╩════╝
0CH = Start addres (high byte).
0DH = Start addres (low byte).
b) But Panning
--------------
For smooth scrolling in text mode for example we can add the index 08H
Preset row scan, so that characters can be scrolled up or down one pixel
at a time! See also Horizontal Pel Pan register.
d0 d1 d2 d3 d4 * * *
port 3CEH index 08 ╚══╩══╩══╩══╩══╩══╩══╩══╝
0 1 2 3 4 5 6 7
* = Not used by panning.
d4-d0: Preset Row scan for panning one pixel at a time.
Note we wont use this because this realy isn't nessecary in
graphics mode to perform smooth panning.
Horizontal Pel Pan Register
---------------------------
First of all this register is situated at port 3C0H (= Attribute Contr-
oller Register.)
PORT 3C0H:
----------
register 00H Color palette Register 0 0AH Color palete Register 10
01H Color palette Register 1 0BH Color palete Register 11
02H Color palette Register 2 0CH Color palete Register 12
03H Color palette Register 3 0DH Color palete Register 13
04H Color palette Register 4 0EH Color palete Register 14
05H Color palette Register 5 0FH Color palete Register 15
06H Color palette Register 6 10H Mode Control Register
07H Color palette Register 7 11H Screen Border color
08H Color palette Register 8 12H Color plane enable register
09H Color palette Register 9 13H Horizontal Panning regsiter
14H Color Select register
d0 d1 d2 d3 * * * *
port 3C0H index 13H ╚══╩══╩══╩══╩══╩══╩══╩══╝
0 1 2 3 4 5 6 7
* = Reserved.
d3-d0: Allows the display to be shifted horizontally one pixel at
a time. Up to 16 pixels the rest is performed by the start
address register increasing 2 times or 2 words. or 2*8=16!
This might all sound pretty confusing but the following pic should
clear things up...
ex. in text mode: 1 ░░░▓▓░░░
2 ░░▓░░▓░░
3 ░▓░░░░▓░
4 ░▓░░░░▓░
5 ░▓°▓▓▓▓░ °= left upper corner.
6 ░▓░░░░▓░ Preset row Scan = 5 -- VERTICAL.
7 ░▓░░░░▓░ Horiz. Pel Pan = 3 -- HORIZONTAL.
8 ░░░░░░░░ These pixel per pixel.
12345678
While Start adress register byte per
byte... .
if ° (the upper left corner) reaches the 8,8 then it is time to clear
the preset row scan and the Hor.pel pan reg. and increase the Start
adress register. OK?
Note: If you make a split screen you are able to put an image on the screen
and let the Hardware scrolly scroll on top above the split screen.
The linecounter ignores the split screen and so the VGA is fooled.
So the panning has now effect on the splitscreen!
Just like in the MN2-Dentro...
The Line compare register enables us to use a split screen.
The line compare register has several overflow bits seperated
in different ports, what a genius plan!!
Just put the correct value in the line compare and off we go... .
Upper left corner : --> ┌────────────────────────┐
Start adress register │----- │
│---------- │
│-------------- │
│ │
Line compare register: --->│========================│
Begin of the display │---- ---- ---- ---- ----│
memory. │---- ---- ---- ---- ----│
│-------------- │
│---- ---- . │
│ │
│ │
└────────────────────────┘
In the MN2-dentro I used the upper part of the screen as hardware
scrolly. The scrolly is on the buttom of each page .
So I could leave the big pix on the top of page 2 and made
it pan the way you saw it.
Well if you find something interesting, or if you make some scrollies yourself
with this source, I would be pleased if you upload them at MN2.
Also if you have an idea/comment please upload it at MN2 in the
Binary Slave conference...
Still having trouble?
Leave a msg at MN2 and I'll see what I can do...
Files:
------
- Cijf.pcx
- Multa-u.pcx
- Multv-.pcx {GFX files made by Wolf. My personal gfx man!}
- Example.hdw {"Modulated" scroll text}
- Example.txt {Scroll text}
- Explain.doc {This file}
- Hscroll.exe {Compiled example file}
- Hscroll.pas {Example source}
- Meat.exe {MN2 publicement file}
- Meat.pas {Source from this file}
- Txt2scr.exe {Converts example.txt 2 example.hdw ascii# 33 - 100}
- Txt2scr.pas {Source for this file
Note: I don't have the official documents of the Vga, only some books.
I'm not responsable for any faults in these docs!
Take care with some ports because they might cause damage!
The only method to learn such things is trail and error!
Be sure you get the whole and correct source and D/L it from MN2!
| MultiNet 2: +32 (0)50/36.33.96 [HST 24/24] |
| FidoNet : 2:291/1800.12 [Bart Vanderostyne] |
| F A X : +32 (0)50/34.73.79 [Write to Binary Slave] |
Hi's and Ho's to - D.H.
------------- - Tasmaniac
- Shadowlord
- Overlord 0f House
- Living Nature
- El Presidento
Greetings to all wich I humbly forgot on the MN2 greetingslist...
<EOF>