X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=16%2Fdos_gfx.cpp;h=b3bd315594e0dc088b309c326588f44dc72c4df5;hb=118896f74475eb26539f1b32923d58f24f0f162f;hp=4fe962e6028317c54b5356889eb92898dde62134;hpb=fc7d63d3fc9f520cbd6c95ef2e070733dae4400d;p=16.git diff --git a/16/dos_gfx.cpp b/16/dos_gfx.cpp index 4fe962e6..b3bd3155 100644 --- a/16/dos_gfx.cpp +++ b/16/dos_gfx.cpp @@ -6,20 +6,20 @@ * * Simple graphics library to accompany the article * - * INTRODUCTION TO MODE X. + * INTRODUCTION TO MODE X. * * This library provides the basic functions for initializing and using * unchained (planar) 256-color VGA modes. Currently supported are: * - * - 320x200 - * - 320x240 + * - 320x200 + * - 320x240 * * Functions are provided for: * - * - initializing one of the available modes - * - setting the start address of the VGA refresh data - * - setting active and visible display pages - * - writing and reading a single pixel to/from video memory + * - initializing one of the available modes + * - setting the start address of the VGA refresh data + * - setting active and visible display pages + * - writing and reading a single pixel to/from video memory * * The library is provided as a demonstration only, and is not claimed * to be particularly efficient or suited for any purpose. It has only @@ -57,8 +57,6 @@ //code from old library! /*src\lib\*/ #include "dos_gfx.h" -//#include "lib\x\modex.h" -//#include "XPRIM.HPP" int old_mode; //color ‚Ä‚·‚Æ @@ -78,18 +76,18 @@ byte coor; /* * Define the port addresses of some VGA registers. */ -#define CRTC_ADDR 0x3d4 /* Base port of the CRT Controller (color) */ +#define CRTC_ADDR 0x3d4 /* Base port of the CRT Controller (color) */ -#define SEQU_ADDR 0x3c4 /* Base port of the Sequencer */ -#define GRAC_ADDR 0x3ce /* Base port of the Graphics Controller */ +#define SEQU_ADDR 0x3c4 /* Base port of the Sequencer */ +#define GRAC_ADDR 0x3ce /* Base port of the Graphics Controller */ #define STATUS_ADDR 0x3DA unsigned char *RowsX[600]; unsigned char write_plane, read_plane; unsigned short text_mask[16] = { 0x0002, 0x0102, 0x0202, 0x0302, - 0x0402, 0x0502, 0x0602, 0x0702, - 0x0802, 0x0902, 0x0A02, 0x0B02, - 0x0C02, 0x0D02, 0x0E02, 0x0F02 }; + 0x0402, 0x0502, 0x0602, 0x0702, + 0x0802, 0x0902, 0x0A02, 0x0B02, + 0x0C02, 0x0D02, 0x0E02, 0x0F02 }; /* @@ -114,8 +112,8 @@ unsigned actStart, visStart; /* * set320x200x256_X() - * sets mode 13h, then turns it into an unchained (planar), 4-page - * 320x200x256 mode. + * sets mode 13h, then turns it into an unchained (planar), 4-page + * 320x200x256 mode. */ void set320x200x256_X(void) { @@ -144,7 +142,7 @@ void set320x200x256_X(void) /* Update the global variables to reflect dimensions of this mode. This is needed by most future drawing operations. */ - width = 320; + width = 320; height = 200; /* Each byte addresses four pixels, so the width of a scan line @@ -193,7 +191,6 @@ OUT value TO PORT 3C0H (where "value" is the ----------------------------------------------- */ -//mxSetVirtualScreen(480,360); } /* @@ -216,9 +213,9 @@ void setActiveStart(unsigned offset) void setVisibleStart(unsigned offset) { visStart = offset; - outpw(CRTC_ADDR, 0x0C); /* set high byte */ + outpw(CRTC_ADDR, 0x0C); /* set high byte */ outpw(CRTC_ADDR+1, visStart >> 8); - outpw(CRTC_ADDR, 0x0D); /* set low byte */ + outpw(CRTC_ADDR, 0x0D); /* set low byte */ outpw(CRTC_ADDR+1, visStart & 0xff); } @@ -277,28 +274,30 @@ void set320x240x256_X(void) /* Modify the vertical timing registers to reflect the increased vertical resolution, and to center the image as good as possible: */ - outpw(0x3D4, 0x2C11); /* turn off write protect */ - outpw(0x3D4, 0x0D06); /* vertical total */ - outpw(0x3D4, 0x3E07); /* overflow register */ - outpw(0x3D4, 0xEA10); /* vertical retrace start */ - outpw(0x3D4, 0xAC11); /* vertical retrace end AND wr.prot */ - outpw(0x3D4, 0xDF12); /* vertical display enable end */ - outpw(0x3D4, 0xE715); /* start vertical blanking */ - outpw(0x3D4, 0x0616); /* end vertical blanking */ + outpw(0x3D4, 0x2C11); /* turn off write protect */ + outpw(0x3D4, 0x0D06); /* vertical total */ + outpw(0x3D4, 0x3E07); /* overflow register */ + outpw(0x3D4, 0xEA10); /* vertical retrace start */ + outpw(0x3D4, 0xAC11); /* vertical retrace end AND wr.prot */ + outpw(0x3D4, 0xDF12); /* vertical display enable end */ + outpw(0x3D4, 0xE715); /* start vertical blanking */ + outpw(0x3D4, 0x0616); /* end vertical blanking */ /* Update mode info, so future operations are aware of the resolution */ height = 240; +//*$pragma aux mxSetVirtualScreen "MXSETVIRTUALSCREEN" +//mxSetVirtualScreen(480,360); } /*-----------XXXX-------------*/ ///////////////////////////////////////////////////////////////////////////// -// // -// WaitRetrace() - This waits until you are in a Verticle Retrace. // -// // +// // +// WaitRetrace() - This waits until you are in a Verticle Retrace. // +// // ///////////////////////////////////////////////////////////////////////////// void wait_for_retrace(void) { @@ -306,11 +305,11 @@ void wait_for_retrace(void) } ///////////////////////////////////////////////////////////////////////////// -// // -// MoveTo() - This moves to position X*4 on a chain 4 screen. // -// Note: As soon as I find documentation, this function // -// will be better documented. - Snowman // -// // +// // +// MoveTo() - This moves to position X*4 on a chain 4 screen. // +// Note: As soon as I find documentation, this function // +// will be better documented. - Snowman // +// // ///////////////////////////////////////////////////////////////////////////// /* void MoveTo (word X, word Y) { @@ -339,58 +338,59 @@ void MoveTo (word X, word Y) { ; ;----------------------------------------------------------- ;WARN PRO -INCLUDE MODEX.DEF - -PUBLIC mxPan - -EXTRN mxWaitDisplay : FAR -EXTRN mxStartAddress : FAR - -MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' - ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING - -EXTRN mx_BytesPerLine : WORD - -;----------------------------------------------------------- -; -; Moves the screen. -; -; Input: -; X, Y = new X, Y coordinates of view screen -; Output: -; none -; -mxPan PROC FAR - ARG Y:WORD, \ - X:WORD = ARG_SIZE - ASSUME ds:NOTHING - .enter 0 - - mov ax, [Y] - mul [mx_BytesPerLine] - mov dx, [X] - shr dx, 1 - shr dx, 1 - add ax, dx - push ax ; Push the start address - call mxWaitDisplay - call mxStartAddress - - mov dx, 03DAh ; Set the pixel pan register - in al, dx - mov dx, 03C0h - mov al, 33h - out dx, al - mov al, BYTE PTR [X] - and al, 3 - shl al, 1 - out dx, al - - xor ax, ax - .leave ARG_SIZE -mxPan ENDP - -MX_TEXT ENDS +#pragma aux mxPan = \ +"INCLUDE MODEX.DEF" \ + + + +"EXTRN mxWaitDisplay : FAR" \ +"EXTRN mxStartAddress : FAR" \ + +"MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE' + ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING" \ + +"EXTRN mx_BytesPerLine : WORD" \ + +//;----------------------------------------------------------- +//; +//; Moves the screen. +//; +//; Input: +//; X, Y = new X, Y coordinates of view screen +//; Output: +//; none +//; +mxPan PROC FAR + ARG Y:WORD, \ + X:WORD = ARG_SIZE + ASSUME ds:NOTHING + .enter 0 + + mov ax, [Y] + mul [mx_BytesPerLine] + mov dx, [X] + shr dx, 1 + shr dx, 1 + add ax, dx + push ax ; Push the start address + call mxWaitDisplay + call mxStartAddress + + mov dx, 03DAh ; Set the pixel pan register + in al, dx + mov dx, 03C0h + mov al, 33h + out dx, al + mov al, BYTE PTR [X] + and al, 3 + shl al, 1 + out dx, al + + xor ax, ax + .leave ARG_SIZE +mxPan ENDP + +MX_TEXT ENDS END @@ -409,8 +409,8 @@ void Play() // for(loop1=0;loop1<=3;loop1++) // for(loop2=0;loop2<=5;loop2++) -// Putpic (loop1*160,loop2*66); // { This places the picture all over the - // chain-4 screen } +// Putpic (loop1*160,loop2*66); // { This places the picture all over the + // chain-4 screen } // getch(); // ch=0x0; // xpos=rand (78)+1; @@ -427,7 +427,7 @@ void Play() ypos=ypos+ydir; if( (xpos>79) || (xpos<1))xdir=-xdir; if( (ypos>199) || (ypos<1))ydir=-ydir; // { Hit a boundry, change - // direction! } + // direction! } // if(_bios_keybrd(_KEYBRD_READY))ch=getch(); // if(ch==0x71)break; // 'q' // if(ch==0x1b)break; // 'ESC' @@ -525,29 +525,29 @@ so we can draw off the edge of the screen. Perhaps a little diagram will clarify it. The following picture is of a standard X-mode addressing scheme with the OFFSET register set to 80. - ROW OFFSET - 0 0 ======================== - 1 80 [ ] - 2 160 [ ] - .. .. [ VISIBLE ] - [ SCREEN ] - [ ] - [ ] - .. .. [ ] - 199 15920 ======================== + ROW OFFSET + 0 0 ======================== + 1 80 [ ] + 2 160 [ ] + .. .. [ VISIBLE ] + [ SCREEN ] + [ ] + [ ] + .. .. [ ] + 199 15920 ======================== and the next diagram is of a modified addressing scheme with the OFFSET register set to 82 (to give us 4 extra pixels on each side of the screen) ROW OFFSET -0 0 ------========================------ -1 82 | V [ ] V | -2 164 | I [ ] I | -.. .. | N S [ VISIBLE ] N S | - | O I [ SCREEN ] O I | - | T B [ ] T B | - | L [ ] L | -.. .. | E [ ] E | +0 0 ------========================------ +1 82 | V [ ] V | +2 164 | I [ ] I | +.. .. | N S [ VISIBLE ] N S | + | O I [ SCREEN ] O I | + | T B [ ] T B | + | L [ ] L | +.. .. | E [ ] E | 199 16318 ------========================------ Beautiful!!! @@ -651,9 +651,9 @@ void putstringX(cord x, cord y, char *str, byte color) } ///////////////////////////////////////////////////////////////////////////// -// // -// setvideo() - This function Manages the video modes // -// // +// // +// setvideo() - This function Manages the video modes // +// // ///////////////////////////////////////////////////////////////////////////// void setvideo(/*byte mode, */int vq){ union REGS in, out; @@ -678,7 +678,7 @@ void setvideo(/*byte mode, */int vq){ ///////////////////////////////////////////////////////////////////////////// // // // cls() - This clears the screen to the specified color, on the VGA or on // -// the Virtual screen. // +// the Virtual screen. // // // ///////////////////////////////////////////////////////////////////////////// void cls(byte color, byte *Where){ @@ -697,7 +697,7 @@ int colortest(){ //color ‚Ä‚·‚Æ int colorz(){ if(gq < HGQ){ -//---- cls(gq, vaddr); +//---- cls(gq, vaddr); cls(gq, vga); gq++; }else gq = LGQ; @@ -743,27 +743,27 @@ int ding(int q){ if((q == 2 ||q==4 ||q==16 - ) && gq == BONK-1){ + ) && gq == BONK){ if(coor < HGQ && coor < LGQ) coor = LGQ; - if(coor < HGQ){ + if(coor < HGQ-1){ coor++; }else{ coor = LGQ; bakax = rand()%3; bakay = rand()%3; } } - if(q == 8){ colorz(); return gq; }else - if(q == 10){ ssd(q); /*printf("%d\n", coor);*/ }else - if(q == 5){ colortest(); return gq; }else - if(q == 11){ colorz(); delay(100); return gq; } - if(q == 6){ + if(q==8){ colorz(); return gq; }else + if(q==10){ ssd(q); /*printf("%d\n", coor);*/ }else + if(q==5){ colortest(); return gq; }else + if(q==11){ colorz(); delay(100); return gq; } + if(q==6){ coor = rand()%NUM_COLORS; -//---- cls(coor, vaddr); +//---- cls(coor, vaddr); cls(coor, vga); //updatevbuff(); } - if(q == 7 || q== 9){ + if(q==7||q==9){ if(gq < HGQ){ if(q == 7) ssd(q); if(q == 9){ ssd(q); coor++; } @@ -834,9 +834,9 @@ int ding(int q){ // fixer // if(q!=16){ //if(q!=16) - if(xx<(0/*-TILEWH*/)) xx=(width/*+TILEWH*/); +// if(xx<(0/*-(TILEWH/2)*/)) xx=(width/*+(TILEWH)*/); if(yy<0) yy=(height*3); - if(xx>(width/*+TILEWH*/)) xx=(0/*-TILEWH*/); +// if(xx>(width/*+(TILEWH)*/)) xx=(0/*-(TILEWH/2)*/); if(yy>(height*3)) yy=0; // } @@ -851,14 +851,14 @@ int ding(int q){ //printf("%d %d %d %d %d %d\n", xx, yy, tx, ty, TILEWH); // plot the pixel -//---- ppf(xx, yy, coor, vga); +//---- ppf(xx, yy, coor, vga); }else /*if(xx>=0 && xx=0 && yy<(height*3))*/{ // putColorBox_X(xx, yy, TILEWH, TILEWH, coor); //++++0000 putPixel_X(xx, yy, coor); } -//---- if(q==2) ppf(rand()%, rand()%height, 0, vga); +//---- if(q==2) ppf(rand()%, rand()%height, 0, vga); // if(q==2) putColorBox_X(rand()%width, rand()%(height*3), TILEWH, TILEWH, 0); //++++0000 if(q==2) putPixel_X(rand()%width, rand()%(height*3), 0); @@ -866,10 +866,10 @@ int ding(int q){ if(q==2||q==4||q==16){ bakax = rand()%3; bakay = rand()%3; } gq++; //if(xx<0||xx>320||yy<0||yy>(height*3)) -// printf("%d %d %d %d %d %d\n", xx, yy, coor, bakax, bakay, getPixel_X(xx,yy)); -// printf("%d\n", getPixel_X(xx,yy)); +// printf("%d %d %d %d %d %d\n", xx, yy, coor, bakax, bakay, getPixel_X(xx,yy)); +// printf("%d\n", getPixel_X(xx,yy)); //0000 -// drawText(0, 0, 15, getPixel_X(xx,yy)); +// drawText(0, 0, 15, getPixel_X(xx,yy)); }else gq = LGQ; return gq; } @@ -891,8 +891,9 @@ void doTest(void) /* This is the way to calculate the number of pages available. */ pages = 65536L/(widthBytes*height); // apparently this takes the A000 address +// if(height==240) pages++; - printf("%d\n", pages); +// printf("%d\n", pages); for (p = 0; p <= pages; ++p) { @@ -906,31 +907,28 @@ void doTest(void) { putPixel_X(x, 0, p+1); if(p!=pages) putPixel_X(x, height-1, p+1); - else putPixel_X(x, 99-1, p+1); + else if(height==240) putPixel_X(x, 99-1, p+1); } for (y = 0; y <= height; ++y) { putPixel_X(0, y, p+1); if(p!=pages) putPixel_X(width-1, y, p+1); - else putPixel_X(width-1, y, p+1); + else if(height==240) putPixel_X(width-1, y, p+1); } - for (x = 0; x < 16; ++x) - for (y = 0; y < 16; ++y) - putPixel_X(x+(p+2)*16, y+(p+2)*16, x + y*16); + for (x = 0; x < TILEWH; ++x) + for (y = 0; y < TILEWH; ++y) + putPixel_X(x+(p+2)*16, y+(p+2)*TILEWH, x + y*TILEWH); //} -// drawText(0, 0, 15, p); - } /* Each pages will now contain a different image. Let the user cycle through all the pages by pressing a key. */ - for (p = 0; p <= pages; ++p) + for (p = 0; p < pages; ++p) { setVisiblePage(p); - //drawText(0, 240, 15, "bakapi"); getch(); } @@ -947,17 +945,17 @@ int main(void) // main variables d=1; // switch variable key=4; // default screensaver number -// puts("First, have a look at the 320x200 mode. I will draw some rubbish"); -// puts("on all of the four pages, then let you cycle through them by"); -// puts("hitting a key on each page."); -// puts("Press a key when ready..."); -// getch(); +// puts("First, have a look at the 320x200 mode. I will draw some rubbish"); +// puts("on all of the four pages, then let you cycle through them by"); +// puts("hitting a key on each page."); +// puts("Press a key when ready..."); +// getch(); -// doTest(); +// doTest(); -// puts("Then, check out Mode X, 320x240 with 3 (and a half) pages."); -// puts("Press a key when ready..."); -// getch(); +// puts("Then, check out Mode X, 320x240 with 3 (and a half) pages."); +// puts("Press a key when ready..."); +// getch(); //++++0000 setvideo(1); @@ -983,23 +981,28 @@ int main(void) } }*/ // else off while(!kbhit()){ // conditions of screen saver - ding(2); + ding(4); } //end of screen savers -// doTest(); - getch(); + doTest(); +// getch(); while(!kbhit()){ // conditions of screen saver -// hScroll(1); - scrolly(1); - delay(100); + hScroll(1); +// scrolly(1); +// vScroll(1); +// delay(100); // Play(); } //++++0000 setvideo(0); + printf("Resolution:\n[%d][%d]\n", width,height); +// setvideo(0); //mxTerm(); -//mxGetVersion(); - puts("Where to next? It's your move! wwww"); +//mxGetVersion(); + + printf("[%d]\n", mxGetVersion()); + puts("where to next? It's your move! wwww"); printf("bakapi ver. 1.04.09.03\nis made by sparky4i†ƒÖ…j feel free to use it ^^\nLicence: GPL v2\n"); return 0; }