home *** CD-ROM | disk | FTP | other *** search
- // DRAW.C
-
- #include <dos.h>
- #include <conio.h>
- #include "draw.h"
-
- #define VIDEO 0x10
- #define ESC 27
-
- typedef struct tagDrawPattern
- {
- unsigned left, top, width, height;
- unsigned color;
- unsigned char *ptrPattern;
- } DrawPattern;
-
- DrawPattern PatD;
-
- static unsigned char DataD[40*40] = {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
- // | | | | | | | |
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,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,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,
- // | | | | | | | |
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- };
-
-
- void _MovePalette(unsigned int, unsigned int, unsigned int);
- void _ShowPattern(void);
- void _PokeDot(unsigned uX, unsigned uY, unsigned uColor);
-
- //
- // DRAW_LeadtekPattern
- //
- void DRAW_LeadtekPattern()
- {
-
- int idx1, idx2;
- unsigned int wColor;
-
- PatD.width = 40;
- PatD.height = 40;
-
- for(idx1 = 20; idx1 < 600; idx1 += 40) {
- wColor = 31;
- for(idx2 = 0; idx2 < 480; idx2 += 40) {
- wColor = 32 + (idx2 / 40) + ((idx1-20) / 100);
-
- PatD.left = idx1;
- PatD.top = idx2;
- PatD.color = wColor;
- PatD.ptrPattern = DataD;
-
- _ShowPattern();
- }
- }
- }
-
-
- //
- // DRAW_Delay_MovPal_WaitKey
- //
- int DRAW_Delay_MovPal_WaitKey()
- {
- int iCount = 0;
-
- while(!kbhit()) {
- DRAW_Delay(2);
- _MovePalette(32, 55, 1);
- if(iCount++==25) return 1;
- }
- while(kbhit()) if(getch()==ESC) return 0;
- }
-
-
- //
- // DRAW_MovPal_WaitKey
- //
- void DRAW_MovPal_WaitKey()
- {
- while(!kbhit()) {
- DRAW_Delay(2);
- _MovePalette(32, 55, 1);
- }
- while(kbhit()) if(getch()==ESC) return;
- }
-
- //
- // _MovePalette
- //
- void _MovePalette(unsigned int wStart, unsigned int wEnd, unsigned int wDistance)
- {
- static const unsigned DAC_ADDR_READ = 0x3c7;
- static const unsigned DAC_ADDR_WRITE = 0x3c8;
- static const unsigned DAC_DATA = 0x3c9;
-
- unsigned wFirstRed, wFirstGreen, wFirstBlue;
- unsigned wRed, wGreen, wBlue;
- unsigned idx;
-
- _outp(DAC_ADDR_READ, wStart);
- wFirstRed = _inp(DAC_DATA);
- wFirstGreen = _inp(DAC_DATA);
- wFirstBlue = _inp(DAC_DATA);
-
- for(idx = wStart + wDistance; idx<= wEnd; idx += wDistance) {
- _outp(DAC_ADDR_READ, idx);
- wRed = _inp(DAC_DATA);
- wGreen = _inp(DAC_DATA);
- wBlue = _inp(DAC_DATA);
-
- _outp(DAC_ADDR_WRITE, idx - wDistance);
- _outp(DAC_DATA, wRed);
- _outp(DAC_DATA, wGreen);
- _outp(DAC_DATA, wBlue);
- }
- _outp(DAC_ADDR_WRITE,wEnd);
- _outp(DAC_DATA, wFirstRed);
- _outp(DAC_DATA, wFirstGreen);
- _outp(DAC_DATA, wFirstBlue);
- }
-
-
- /*---------------------------------------------------------------------------
- | |
- | Function: void _CheckKB(void) |
- | |
- | Purpose: Check keyboard: |
- | 1. Press ESC key to exit any time. |
- | 2. First times, key is pressed to pause. |
- | 3. Second times, key is pressed to continue. |
- | |
- ---------------------------------------------------------------------------*/
- int DRAW_CheckKB()
- {
- if(!kbhit()) return 1;
- while(kbhit()) if(getch()==ESC) return 0;
- while(!kbhit());
- while(kbhit()) if(getch()==ESC) return 0;
- return 1;
- }
-
-
- /*---------------------------------------------------------------------------
- | |
- | Function: DRAW_Delay(int) |
- | |
- | Purpose: Delay a little time. |
- | |
- ---------------------------------------------------------------------------*/
- void DRAW_Delay(int iDelay) //delay is in 1/10 seconds
- {
- register int i, k;
-
- k = iDelay;
- if(iDelay > 0)
- for(i=0; i<k; i++) {
- while(!(inp(0x3da) & 0x08));
- while((inp(0x3da) & 0x08));
- }
- }
-
-
- //
- // _ShowPattern
- //
- void _ShowPattern()
- {
- unsigned idx1, idx2;
-
- for(idx1 = 0; idx1 < PatD.height; idx1++) {
- for(idx2 = 0; idx2 < PatD.width; idx2++) {
- if(PatD.ptrPattern[idx1 * PatD.width + idx2])
- _PokeDot(idx2 + PatD.left, idx1 + PatD.top, PatD.color);
- }
- }
- }
-
-
- //
- // _PokeDot
- //
- #define _P_SEG 0x3cd
- #define _X_RES 640L
- #define _BASE_SEG 0xa0000000L
-
- void _PokeDot(unsigned uX, unsigned uY, unsigned uColor)
- {
- static int iSeg = 0;
- unsigned char _far *lpData;
-
- if(iSeg != (int)(((unsigned long)uY * _X_RES + (unsigned long)uX) >> 16)) {
- iSeg = (int)(((unsigned long)uY * _X_RES + (unsigned long)uX) >> 16);
- _outp(_P_SEG, iSeg);
- }
- lpData = (unsigned char _far*)( _BASE_SEG |
- (((unsigned long)uY * _X_RES + (unsigned long)uX) & 0xffffL) );
- *lpData = (unsigned char) uColor;
- }
-