How to...

These topics come from my own programming experiences. I have written them all by my selve, so if you have questions, do not mind to mail me.


The basics of VGA-programming (like a moving star screen)

The general idea behind VGA programming is simple. Your monitor presents a screen by printing pixel by pixel from the left to the right from your screen, and then RETRACES (horizontal retrace) back to the left to print the next line form the left to the right, until the last screen line is printed. The next time the monitor wants to refresh your screen it will need a VERTICAL RETRACE to begin at the left-upper corner.

Now take the horizontal moving star screen for example...
This vertical retrace takes a certain time, which you will need to recalculate your stars and print them in the VGA's memory. After the vertical retrace your monitor will present the new screen.
The reason why you should do this in the monitor's vertical retrace is that otherwise you will see your program recalculating the stars. This will not give a flicker free screen! And another thing is that your stars won't move much faster on a pentium as on a 386 machine, because the speed depends on the monitor.

Here is how you should wait for the start of a vertical retrace:

	mov	dx,3dah		;wait for vertical retrace
vrt:
	in	al,dx		;wait for end
	test	al,8
	jnz	vrt
novrt:
	in	al,dx		;wait for start
	test	al,8
	jz	novrt

So a horizontal moving star_screen code could look like this

hierheen:
	wait for vertical retrace
	delete old stars	;the speed of this program code should 
	print the new ones	;always fit in the vertical retrace time 
				;no matter how slow the computer is (it
				;should run perfectly on a 386 machine!)
	jump hierheen

Note: from my VGA programming experience I have experienced that changing a certain color register with a BIOS function like function 10h, subfunction 10h from int10h, will automatically include the "wait for vertical retrace"-code. So the horizontal moving star-screen code could look like this too:

hierheenII:
	change a certain color register with BIOS
	delete old stars
	print the new ones

	jmp hierheenII
If you did NOT understand the part about what your monitor does etc... just keep in mind:
  1. Before you change anything to the VGA-memory, wait for a vertical retrace
  2. The VGA's memory should be refreshed before the end of the vertical retrace! Even on a 386 machine!

A programming example of VGA-programming is available now! It is a Moving StarScreen, download it NOW!

Back to the top of this Page


How to make your own boot code (DOS will really recognize your disk!):

When your computer starts up it will do a self-test and then tries to load the bootsector (512 bytes) of your harddrive/floppy disk in the memory at 0000h:7C00h, and jumps to 0000h:7C00h. You should make a 512 byte long code, but the last word of the 512 bytes should be AA55h because otherwise your computer will not detect that this is a valid bootsector code. The offset 7C00h will make it difficult to jump or access variables, because a normal .COM file will think it will start at offset 100h. To solve this problem you could use "ORG" in your code. Example:

(.COM file)
	org	100h		;for stacks (NOT used in this program!)
	jmp	verder

	org	7C3Eh		;!!! the +3Eh is expained in *1
verder:
	.. . .			;your code...
	... . .. .

	org	7DFEh
	dw	AA55h		;Valid-bootsector-code indentifier

*1 The structure of the Bootsector
   From HELPPC 2.0 by David Jurgens

Offset   Size      Description

00       3 bytes   jump to executable code
03       8 bytes   OEM name and version
0B       1 word    bytes per sector
0D       1 byte    sectors per cluster (allocation unit size)
0E       1 word    number of reserved sectors (starting at 0)
10       1 byte    number of FAT's on disk
11       1 word    number of root directory entries (directory size)
13       1 word    number of total sectors (0 if partition > 32Mb)
15       1 byte    media descriptor byte  (see MEDIA DESCRIPTOR)
16       1 word    sectors per FAT
18       1 word    sectors per track  (DOS 3.0+)
1A       1 word    number of heads  (DOS 3.0+)
1C       1 word    number of hidden sectors  (DOS 3.0+)
20       1 dword   (DOS 4+) number of sectors if offset 13 was 0
24       1 byte    (DOS 4+) physical drive number
25       1 byte    (DOS 4+) reserved
26       1 byte    (DOS 4+) signature byte (29h)
27       4 bytes   (DOS 4+) volume serial number
2B       11 bytes  (DOS 4+) volume label
36       8 bytes   (DOS 4+) reserved

Now you should copy 450 bytes of this .COM file beginning at 7B00h and put this in the first sector (the bootsector) of your floppy disk(/HARDDRIVE???(not recommended, it will no longer be a DOS startup system)) at the offset 3Eh. Use my bootsector writing utility! If you refuse to use my utility you should write the following bytes to the bootsector at the offset 0000h:

db EBh 	;JMP RELATIVE instruction
db 3Ch 	;JMP to +003Ch
db 90h 	;NOP instruction (do nothing), important
	;because if this is not 90h then DOS
	;will NOT recognize your disk
(This is a standard code for MS-DOS Formatted disks)

You should now have a valid bootdisk.

Back to the top of this Page


This is how you can make your own Quick Boot routine...

  1. Make a bootsector code (see: How to make your own boot code) that saves the interrupt-vector-table (0000h:0000h - 0000h:03CFh (2 sectors, 1024 bytes)) to the 2nd & 3th sector of your floppy disk(1).


  2. Give a hard-reset on your computer with your floppy disk(1) in your disk drive, so that you will save your computers interrupt-vector-table on the 2nd & 3th sector of your floppy disk(1).


  3. Make a file on your harddrive called 'VECTORS.INT' that is 1024 bytes long and store the 2nd & 3th sector of your floppy disk(1) in it.


  4. Make a program called 'QREBOOT.COM' that
    1. loads 'VECTORS.INT' somewhere in the memory (I will refer to it as 'A'), but NOT directly in the interrupt-vector-table!
    2. disables the Hardware interrupts (CLI)
    3. copies 'VECTORS.INT' from memory(A) to the real interrupt-vector-table location (0000h:0000h - 0000h:03CFh (1024 bytes))
    4. sets screen mode 03h (text mode)
    5. sets SS, DS, ES, DI to zero, SI to 00d5h and BP to 0E00h (I found these values with another bootsector program)
    6. calls interrupt 19h (this will handle the rest like loading the bootsector from drive X to 7C00h:0000h, clearing memory etc.)

IMPORTANT NOTES:

This is only what you should do to make it work, the next time I will update this page (for you: soon I hope) I will add my source code and compiled files that are needed to make a Quick boot to this page. Now you may try to make them yourself, without an example (MUCH MORE FUN!!!)!

Back to the top of this Page


Do you know a nice subject that can be added to this page, please let me know by
sending E-mail to [email protected]