Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
back2root:archives:denthor:part-01 [2021/08/26 21:52] – créée frater | back2root:archives:denthor:part-01 [2024/08/27 08:43] (Version actuelle) – [Putting a pixel on the screen (two different methoods)] frater | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ===== PART 1 : MCGA ===== | + | ===== PART 01 : MCGA ===== |
Hi there! This is Denthor of ASPHYXIA, AKA Grant Smith. This training program is aimed at all those budding young demo coders out there. I am assuming that the reader is fairly young, has a bit of basic Std. 6 math | Hi there! This is Denthor of ASPHYXIA, AKA Grant Smith. This training program is aimed at all those budding young demo coders out there. I am assuming that the reader is fairly young, has a bit of basic Std. 6 math | ||
Ligne 13: | Ligne 13: | ||
- | <WRAP center round info 80%> | + | <WRAP center round info> |
I drop source code all through my explanations. You needn' | I drop source code all through my explanations. You needn' | ||
</ | </ | ||
Ligne 82: | Ligne 82: | ||
< | < | ||
- | Writes a pixel dot of a specified color at a specified screen | + | Writes a pixel dot of a specified color at a specified screen coordinate. |
- | | + | |
On entry: | On entry: | ||
Ligne 116: | Ligne 115: | ||
you how to alter it in my next lesson, but for now you will have to hunt for colors that fit in for what you want to do. Luckily, a byte is 0 to 255, so that is what we pass to the col variable. Have a look at the following. | you how to alter it in my next lesson, but for now you will have to hunt for colors that fit in for what you want to do. Luckily, a byte is 0 to 255, so that is what we pass to the col variable. Have a look at the following. | ||
+ | < | ||
CGA = 4 colours. | CGA = 4 colours. | ||
4x4 = 16 | 4x4 = 16 | ||
Ligne 122: | Ligne 122: | ||
VGA = 256 colors. | VGA = 256 colors. | ||
Therefore an EGA is a CGA squared, and a VGA is an EGA squared ;-) | Therefore an EGA is a CGA squared, and a VGA is an EGA squared ;-) | ||
+ | </ | ||
Anyway, back to reality. Even though the abouve procedure is written in assembly language, it is slooow. Why? I hear your enquiring minds cry. The reason is simple : It uses interrupts (It calls INT 10h). Interrupts are sloooow ... which is okay for getting into MCGA mode, but not for trying to put down a pixel lickety-split. So, why not try the following ... | Anyway, back to reality. Even though the abouve procedure is written in assembly language, it is slooow. Why? I hear your enquiring minds cry. The reason is simple : It uses interrupts (It calls INT 10h). Interrupts are sloooow ... which is okay for getting into MCGA mode, but not for trying to put down a pixel lickety-split. So, why not try the following ... | ||
Ligne 144: | Ligne 145: | ||
Denthor | Denthor | ||
+ | ==== Code Source | ||
+ | |||
+ | === PASCAL === | ||
+ | |||
+ | <code pascal> | ||
+ | (*****************************************************************************) | ||
+ | (* *) | ||
+ | (* TUTPROG1.CPP - VGA Trainer Program 1 (in Pascal) | ||
+ | (* *) | ||
+ | (* "The VGA Trainer Program" | ||
+ | (* was limited to Pascal only in its first run. All I have done is taken *) | ||
+ | (* his original release, translated it to C++, and touched up a few things. | ||
+ | (* I take absolutely no credit for the concepts presented in this code, and *) | ||
+ | (* am NOT the person to ask for help if you are having trouble. | ||
+ | (* *) | ||
+ | (* Program Notes : This program presents some basic video concepts: kicking | ||
+ | (* the computer into graphics mode, testing out two differ- | ||
+ | (* ent methods of putting pixels to the screen, and finally | ||
+ | (* | ||
+ | (* *) | ||
+ | (* Author | ||
+ | (* *) | ||
+ | (* *) | ||
+ | (*****************************************************************************) | ||
+ | |||
+ | {$X+} (* This is a handy little trick to know. If you put this at the top | ||
+ | of your program, you do not have to set a variable when calling | ||
+ | a function, i.e. you may just say ' | ||
+ | ' | ||
+ | |||
+ | USES Crt; (* This has a few nice functions in it, such as the | ||
+ | | ||
+ | |||
+ | CONST VGA = $a000; | ||
+ | VGA screen. | ||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure SetMCGA; | ||
+ | BEGIN | ||
+ | asm | ||
+ | | ||
+ | | ||
+ | end; | ||
+ | END; | ||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure SetText; | ||
+ | BEGIN | ||
+ | asm | ||
+ | | ||
+ | | ||
+ | end; | ||
+ | END; | ||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure Cls (Col : Byte); | ||
+ | { This clears the screen to the specified color } | ||
+ | BEGIN | ||
+ | Fillchar (Mem [$a000: | ||
+ | END; | ||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure INTPutpixel (X,Y : Integer; Col : Byte); | ||
+ | { This puts a pixel on the screen using interrupts. } | ||
+ | BEGIN | ||
+ | asm | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | end; | ||
+ | END; | ||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure TestINTPutpixel; | ||
+ | { This tests out the speed of the INTPutpixel procedure. } | ||
+ | VAR loop1,loop2 : Integer; | ||
+ | BEGIN | ||
+ | For loop1:=0 to 319 do | ||
+ | For loop2:=0 to 199 do | ||
+ | INTPutpixel (loop1, | ||
+ | Readkey; | ||
+ | Cls (0); | ||
+ | END; | ||
+ | |||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure MEMPutpixel (X,Y : Integer; Col : Byte); | ||
+ | { This puts a pixel on the screen by writing directly to memory. } | ||
+ | BEGIN | ||
+ | Mem [VGA: | ||
+ | END; | ||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | Procedure TestMEMPutpixel; | ||
+ | { This tests out the speed of the MEMPutpixel procedure. } | ||
+ | VAR loop1,loop2 : Integer; | ||
+ | BEGIN | ||
+ | For loop1:=0 to 319 do | ||
+ | For loop2:=0 to 199 do | ||
+ | MEMPutpixel (loop1, | ||
+ | Readkey; | ||
+ | Cls (0); | ||
+ | END; | ||
+ | |||
+ | |||
+ | |||
+ | {ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ} | ||
+ | BEGIN (* Of the main program *) | ||
+ | ClrScr; | ||
+ | Writeln ('What will happen is that I will clear the screen twice. After' | ||
+ | Writeln ('each clear screen you will have to hit a key. I will then fill' | ||
+ | Writeln ('the screen twice with randomlly colored pixels using two different' | ||
+ | Writeln (' | ||
+ | Writeln ('then return you to text mode.' | ||
+ | Writeln; Writeln; | ||
+ | Write ('Hit any kay to continue ...'); | ||
+ | Readkey; | ||
+ | |||
+ | SetMCGA; | ||
+ | CLS (32); | ||
+ | Readkey; | ||
+ | CLS (90); | ||
+ | Readkey; | ||
+ | TestINTPutpixel; | ||
+ | TestMEMPutpixel; | ||
+ | SetText; | ||
+ | |||
+ | Writeln ('All done. This concludes the first sample program in the ASPHYXIA' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln (' | ||
+ | Writeln ('I hope to hear from you soon!' | ||
+ | Writeln; Writeln; | ||
+ | Write | ||
+ | Readkey; | ||
+ | END. (* Of the main program *) | ||
+ | </ | ||
+ | |||
+ | === C === | ||
+ | |||
+ | <code cpp> | ||
+ | / | ||
+ | /* */ | ||
+ | /* TUTPROG1.CPP - VGA Trainer Program 1 (in Turbo C++ 3.0) */ | ||
+ | /* */ | ||
+ | /* "The VGA Trainer Program" | ||
+ | /* was limited to Pascal only in its first run. All I have done is taken */ | ||
+ | /* his original release, translated it to C++, and touched up a few things. | ||
+ | /* I take absolutely no credit for the concepts presented in this code, and */ | ||
+ | /* am NOT the person to ask for help if you are having trouble. | ||
+ | /* */ | ||
+ | /* Program Notes : This program presents some basic video concepts: kicking | ||
+ | /* the computer into graphics mode, testing out two differ- | ||
+ | /* ent methods of putting pixels to the screen, and finally | ||
+ | /* | ||
+ | /* */ | ||
+ | /* If you are compiling this code command line, be sure to */ | ||
+ | /* use the " | ||
+ | /* the program will compile and link, but will lock your */ | ||
+ | /* | ||
+ | /* */ | ||
+ | /* Author | ||
+ | /* Translated by : Christopher (Snowman) Mann - r3cgm@dax.cc.uakron.edu | ||
+ | /* */ | ||
+ | /* Last Modified : October 21st, 1994 */ | ||
+ | /* */ | ||
+ | / | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | void SetMCGA(); | ||
+ | void SetText(); | ||
+ | void Cls(unsigned char Col); | ||
+ | void TestINTPutpixel(); | ||
+ | void TestMEMPutpixel(); | ||
+ | void INTPutpixel(int x, int y, unsigned char Col); | ||
+ | void MEMPutpixel(int x, int y, unsigned char Col); | ||
+ | |||
+ | // declare a pointer to the offset of VGA memory | ||
+ | unsigned char *vga = (unsigned char *) MK_FP(0xA000, | ||
+ | |||
+ | // | ||
+ | // SetMCGA() - This function gets you into 320x200x256 mode. | ||
+ | // | ||
+ | |||
+ | void SetMCGA() { | ||
+ | _AX = 0x0013; | ||
+ | geninterrupt (0x10); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // SetText() - This function gets you into text mode. | ||
+ | // | ||
+ | |||
+ | void SetText() { | ||
+ | _AX = 0x0003; | ||
+ | geninterrupt (0x10); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // Cls() - This clears the screen to the specified color. | ||
+ | // | ||
+ | |||
+ | void Cls(unsigned char Col) { | ||
+ | memset(vga, Col, 0xffff); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // INTPutpixel() - This puts a pixel on the screen using inturrupts. | ||
+ | // | ||
+ | |||
+ | void INTPutpixel(int x, int y, unsigned char Col) { | ||
+ | _AH = 0x0C; | ||
+ | _AL = Col; | ||
+ | _CX = x; | ||
+ | _DX = y; | ||
+ | _BX = 0x01; | ||
+ | geninterrupt (0x10); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // TestINTPutpixel() - This tests out the speed of the INTPutpixel function. | ||
+ | // | ||
+ | |||
+ | void TestINTPutpixel() { | ||
+ | |||
+ | int loop1, | ||
+ | |||
+ | for (loop1=0; | ||
+ | for (loop2=0; | ||
+ | INTPutpixel (loop1, | ||
+ | } | ||
+ | } | ||
+ | getch(); | ||
+ | Cls(0); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // MEMPutpixel() - This puts a pixel on the screen by writing directly to | ||
+ | // | ||
+ | // | ||
+ | |||
+ | void MEMPutpixel (int x, int y, unsigned char Col) { | ||
+ | memset(vga+x+(y*320), | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // TestMEMPutpixel() - This tests out the speed of the MEMPutpixel function. | ||
+ | // | ||
+ | |||
+ | void TestMEMPutpixel () { | ||
+ | |||
+ | int loop1, | ||
+ | |||
+ | for (loop1=0; | ||
+ | for (loop2=0; | ||
+ | MEMPutpixel (loop1, | ||
+ | } | ||
+ | } | ||
+ | getch(); | ||
+ | Cls(0); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // MAIN FUNCTION | ||
+ | // | ||
+ | |||
+ | void main() { | ||
+ | clrscr(); | ||
+ | printf ("What will happen is that I will clear the screen twice. | ||
+ | printf ("each clear screen you will have to hit a key. I will then fill\n" | ||
+ | printf ("the screen twice with randomly colored pixels using 2 different\n" | ||
+ | printf (" | ||
+ | printf ("then return you to text mode.\n\n" | ||
+ | printf ("Hit any key to continue ...\n" | ||
+ | getch(); | ||
+ | |||
+ | SetMCGA(); | ||
+ | Cls(32); | ||
+ | getch(); | ||
+ | Cls(90); | ||
+ | getch(); | ||
+ | TestINTPutpixel(); | ||
+ | TestMEMPutpixel(); | ||
+ | SetText(); | ||
+ | |||
+ | printf ("All done. This concludes the 1st sample program in the ASPHYXIA\n" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf (" | ||
+ | printf ("I hope to hear from you soon!\n\n\n" | ||
+ | printf ("Hit any key to exit ..."); | ||
+ | getch(); | ||
+ | } | ||
+ | </ | ||
+ | <nspages back2root/ |