From: sparky4 Date: Fri, 25 Jul 2014 14:22:58 +0000 (-0500) Subject: renamed: 16/PCX_LIB.ZIP -> 16/PCX_LIB/PCX_LIB.ZIP X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=952bc98c5a1d6b2ea62aca99e4cf066daa8459f9;p=16.git renamed: 16/PCX_LIB.ZIP -> 16/PCX_LIB/PCX_LIB.ZIP modified: 16/Project 16.bfproject new file: 16/TEST.C modified: 16/dos_gfx.h new file: 16/ed.pcx new file: 16/gfx.pal renamed: 16/modex16/modex16.c -> 16/lib/MODEX16.C modified: 16/lib/MODEX16.H modified: 16/lib/TYPES.H new file: 16/lib/types.h new file: 16/makefile modified: 16/modex16/MODEX16.C modified: 16/modex16/MODEX16.H new file: 16/modex16/PALVIEW.EXE modified: 16/modex16/PCXTEST.C modified: 16/modex16/PCXTEST.EXE modified: 16/modex16/TEST.C modified: 16/modex16/TEST.EXE new file: 16/modex16/TEST2.EXE deleted: 16/modex16/modex16.h modified: 16/modex16/pcxtest.c deleted: 16/modex16/pcxtest.exe modified: 16/modex16/test.c deleted: 16/modex16/test.exe modified: 16/modex16/test2.c deleted: 16/modex16/test2.exe --- diff --git a/16/PCX_LIB.ZIP b/16/PCX_LIB/PCX_LIB.ZIP similarity index 100% rename from 16/PCX_LIB.ZIP rename to 16/PCX_LIB/PCX_LIB.ZIP diff --git a/16/Project 16.bfproject b/16/Project 16.bfproject index 2e220aa5..63ad23d1 100644 --- a/16/Project 16.bfproject +++ b/16/Project 16.bfproject @@ -1,19 +1,19 @@ c2e.convert_special: 0 e2c.convert_num: 0 -openfiles: /dos/z/16/16/dos_gfx.cpp:150:0:0: -openfiles: /dos/z/16/16/dos_gfx.h:156:0:0: -openfiles: /dos/z/16/16/dos_kb.c:1039:46:0: -openfiles: /dos/z/16/16/dos_kb.h:23:0:0: +openfiles: /dos/z/16/16/dos_gfx.cpp:187:0:0: +openfiles: /dos/z/16/16/dos_gfx.h:116:0:0: +openfiles: /dos/z/16/16/dos_kb.c:217:0:0: +openfiles: /dos/z/16/16/dos_kb.h:161:0:0: openfiles: /dos/z/16/16/lib/lib_com.cpp:2:0:0: openfiles: /dos/z/16/16/lib/lib_com.h:160:0:0: openfiles: /dos/z/16/16/scroll.txt:5256:4537:0: openfiles: /dos/z/16/16/project16.txt:8063:6091:0: openfiles: /dos/z/16/16/16.txt:0:0:0: -openfiles: /dos/z/16/16/lib/x/MODEX.H:5511:4684:0: -openfiles: /dos/z/16/16/modex16/PCXTEST.C:1143:421:0: -openfiles: /dos/z/16/16/lib/MODEX16.C:141:0:0: -openfiles: /dos/z/16/16/lib/MODEX16.H:444:0:0: -openfiles: /dos/z/16/16/lib/TYPES.H:277:0:1: +openfiles: /dos/z/16/16/lib/x/MODEX.H:5511:2798:0: +openfiles: /dos/z/16/16/modex16/PCXTEST.C:794:497:0: +openfiles: /dos/z/16/16/lib/MODEX16.C:2334:1895:0: +openfiles: /dos/z/16/16/lib/MODEX16.H:2926:2348:0: +openfiles: /dos/z/16/16/TEST.C:335:0:1: snr_recursion_level: 0 convertcolumn_horizontally: 0 adv_open_matchname: 0 @@ -28,13 +28,15 @@ c2e.convert_iso: 0 opendir: file:///dos/z/16/16/lib wrap_text_default: 0 bookmarks_filename_mode: 1 -ssearch_text: bitmap_t -snr_casesens: 0 +ssearch_text: gq +snr_casesens: 1 view_blocks: 1 name: project 16 replacelist: てすと replacelist: \t replacelist: putPixel_X +replacelist: SCREEN_WIDTH +replacelist: SCREEN_HEIGHT fb_show_hidden_f: 0 editor_tab_width: 4 show_visible_spacing: 1 @@ -48,11 +50,6 @@ ssearch_regex: 0 e2c.convert_iso: 0 ssearch_casesens: 0 charmap_block: 1 -recent_files: file:///dos/z/4x4_16/tauron/C_SRC/TESTS.CPP -recent_files: file:///dos/z/4x4_16/tauron/C_SRC/MODES.CPP -recent_files: file:///dos/z/4x4_16/tauron/C_SRC/FONT1.H -recent_files: file:///dos/z/4x4_16/tauron/C_SRC/FONT2.H -recent_files: file:///dos/z/4x4_16/tile.c recent_files: file:///dos/z/4x4_16/tile.h recent_files: file:///dos/z/16/16/lib_com.cpp recent_files: file:///dos/z/16/16/lib_com.h @@ -75,18 +72,7 @@ recent_files: file:///dos/z/16/16/lib/x/MODEX.DEF recent_files: file:///dos/z/4x4_16/modex/DEMO01.PAS recent_files: file:///dos/z/16/16/lib/x/MXCR.ASM recent_files: file:///dos/z/4x4_16/modex/DEMO07.PAS -recent_files: file:///dos/z/16/16/modex16/PCXTEST.C -recent_files: file:///dos/z/16/16/dos_gfx.cpp -recent_files: file:///dos/z/16/16/dos_gfx.h -recent_files: file:///dos/z/16/16/dos_kb.c -recent_files: file:///dos/z/16/16/dos_kb.h -recent_files: file:///dos/z/16/16/lib/lib_com.cpp -recent_files: file:///dos/z/16/16/lib/lib_com.h -recent_files: file:///dos/z/16/16/scroll.txt -recent_files: file:///dos/z/16/16/project16.txt -recent_files: file:///dos/z/16/16/16.txt recent_files: file:///dos/z/16/16/scrasm/MAIN.ASM -recent_files: file:///dos/z/16/16/lib/x/MODEX.H recent_files: file:///dos/z/16/16/lib/x/MXBB.ASM recent_files: file:///dos/z/16/src/lib/dos_gfx.h recent_files: file:///dos/z/16/16/lib/intro/lib.c @@ -95,9 +81,25 @@ recent_files: file:///dos/z/16/16/modex16/MODEX16.H recent_files: file:///dos/z/16/16/modex16/MODEX16.C recent_files: file:///dos/z/4x4_16/w_modex/MODEX.CPP recent_files: file:///dos/z/16/16/TYPES.H -recent_files: file:///dos/z/16/16/lib/MODEX16.H recent_files: file:///dos/z/16/16/lib/TYPES.H +recent_files: file:///dos/z/16/16/dos_gfx.cpp +recent_files: file:///dos/z/16/16/dos_gfx.h +recent_files: file:///dos/z/16/16/lib/lib_com.h +recent_files: file:///dos/z/16/16/dos_kb.c +recent_files: file:///dos/z/16/16/dos_kb.h +recent_files: file:///dos/z/16/16/lib/lib_com.cpp +recent_files: file:///dos/z/16/16/scroll.txt recent_files: file:///dos/z/16/16/lib/MODEX16.C +recent_files: file:///dos/z/16/16/project16.txt +recent_files: file:///dos/z/16/16/lib/MODEX16.H +recent_files: file:///dos/z/16/16/lib/x/MODEX.H +recent_files: file:///dos/z/16/16/16.txt +recent_files: file:///dos/z/16/16/modex16/PCXTEST.C +recent_files: file:///dos/z/16/16/test.c +recent_files: file:///dos/z/16/16/TEST.C +recent_files: file:///dos/z/16/16/MODEX16.H +recent_files: file:///dos/z/16/16/MODEX16.C +recent_files: file:///dos/z/16/16/lib/types.h snr_replacetype: 0 savedir: file:///dos/z/16/16/lib spell_check_default: 1 @@ -109,21 +111,21 @@ snr_escape_chars: 0 htmlbar_view: 0 spell_lang: en ssearch_dotmatchall: 0 -searchlist: main -searchlist: word -searchlist: syte -searchlist: unsigned short -searchlist: syte -searchlist: unsigned int -searchlist: #include "src\\lib\\lib_com.h" -searchlist: word -searchlist: sy -searchlist: word +searchlist: modexen +searchlist: modexClearRegion(page_t *page, (SW-palq)+palx+32, paly+32, TILEWH, TILEWH, palcol); +searchlist: mx +searchlist: sw +searchlist: SW +searchlist: SH +searchlist: QUADWH +searchlist: pdump +searchlist: #include "modex16.h"\r\n#include \r\n\r\nword far* clock= (word far*) 0x046C; /* 18.2hz clock */\r\n\r\nvoid main() {\r\n#include "modex16.h"\r\n#include \r\n\r\nword far* clock= (word far*) 0x046C; /* 18.2hz clock */\r\n\r\nvoid main() {\r\n +searchlist: extern searchlist: VGA -searchlist: Page -searchlist: modexll -searchlist: load -searchlist: bitmap_t +searchlist: vga +searchlist: clock +searchlist: setvideo +searchlist: gq autocomplete: 1 outputb_show_all_output: 0 bookmarks_show_mode: 0 @@ -157,7 +159,7 @@ c2e.convert_xml: 1 editor_indent_wspaces: 0 view_cline: 0 snr_type: 0 -snr_scope: 3 +snr_scope: 0 bmarksearchmode: 0 view_main_toolbar: 1 e2c.convert_symbol: 0 diff --git a/16/TEST.C b/16/TEST.C new file mode 100644 index 00000000..86cbf42f --- /dev/null +++ b/16/TEST.C @@ -0,0 +1,334 @@ +#include "lib\modex16.h" +#include + +#include +//#include + +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +//color てすと +short gq = LGQ; + +page_t page, page2; + +//てすと +short bakax = 0, bakay = 0; +sword xx = 0, yy = 0, sx = 0, sy = 0; +byte coor; + +//byte *vga = (byte *) MK_FP(0xA000, 0); + +/* + * Comment out the following #define if you don't want the testing main() + * to be included. + */ +//#define TILE + + +/*void pdump(){ + int mult=(QUADWH)/2; + int palq=(mult)*16; + int palcol=0; + for(int paly=0; paly0){ + yy++; + d3y--; + } + } + if(bakax<0){ + xx--; + }else + if(bakax>0){ + xx++; + } + }else{ + if(q==16) + { + if(!bakax){ + xx--; + }else if(bakax>0){ + xx++; + } + if(!bakay){ + yy--; + }else if(bakay>0){ + yy++; + } + }else{ + if(!bakax){ + #ifdef TILE + xx-=TILEWH; + #else + xx--; + #endif + }else if(bakax>1){ + #ifdef TILE + xx+=TILEWH; + #else + xx++; + #endif + } + if(!bakay){ + #ifdef TILE + yy-=TILEWH; + #else + yy--; + #endif + }else if(bakay>1){ + #ifdef TILE + yy+=TILEWH; + #else + yy++; + #endif + } + } + } + // fixer + if(q!=16){ + #ifdef TILE + if(xx<0) xx=(VW-TILEWH); + if(yy<0) yy=(VH-TILEWH); + if(xx>(VW-TILEWH)) xx=0; + if(yy>(VH-TILEWH)/*+(TILEWH*BUFFMX)*/) yy=0; + #else + if(xx<0) xx=VW; + if(yy<0) yy=VH; + if(xx>VW) xx=0; + if(yy>VH) yy=0; + #endif + } + +//interesting effects + if(q==16) + { + short tx=0,ty=0; + tx+=xx+16; + ty+=yy+16; + //mxPutPixel(tx, ty, coor); + modexClearRegion(page_t *page, tx, ty, 1, 1, coor); + //printf("%d %d %d %d %d %dÂ¥n", xx, yy, tx, ty, TILEWH); + + // plot the pixel + }else{ + #ifdef TILE + //mxFillBox(xx, yy, TILEWH, TILEWH, coor, OP_SET); + modexClearRegion(page_t *page, xx, yy, TILEWH, TILEWH, coor); + #else + //mxPutPixel(xx, yy, coor); + modexClearRegion(page_t *page, xx, yy, 1, 1, coor); + #endif + } + + if(q==2) + #ifdef TILE + //mxFillBox((rand()*TILEWH)%VW, (rand()*TILEWH)%(VH), TILEWH, TILEWH, 0, OP_SET); + modexClearRegion(page_t *page, (rand()*TILEWH)%VW, (rand()*TILEWH)%(VH), TILEWH, TILEWH, 0); + #else + //mxPutPixel(rand()%VW, rand()%(VH), 0); + modexClearRegion(page_t *page, rand()%VW, rand()%(VH), 1, 1, 0); + #endif + if(q==16) //mxPutPixel(rand()%VW, rand()%(VH), 0); + modexClearRegion(page_t *page, rand()%VW, rand()%(VH), 1, 1, 0); + if(q==2||q==4||q==16){ bakax = rand()%3; bakay = rand()%3; } //random 3 switch + gq++; +//if(xx<0||xx>320||yy<0||yy>(SCREEN_HEIGHT*3)) +// printf("%d %d %d %d %dÂ¥n", xx, yy, coor, bakax, bakay); + }else gq = LGQ; + return gq; +} + +void main() { + int i, j; + bitmap_t bmp; + word start, end; + //page_t page, page2; + float elapsed; + byte *pal, *pal2=NULL; + + /* load pcx file */ + bmp = modexLoadPcx("ed.pcx"); + + /* load our palette */ + modexLoadPalFile("gfx.pal", &pal2); + + /* save the palette */ + pal = modexNewPal(); + modexPalSave(pal); + modexFadeOff(1, pal); + modexPalBlack(); + + setvideo(1); + modexPalBlack(); + + /* set up the page, but with 16 pixels on all borders in offscreen mem */ + page=modexDefaultPage(); + page2 = modexNextPage(&page); + page.width += 32; + page.height += 32; + + + /* fill the page with one color, but with a black border */ + modexShowPage(&page2); + modexClearRegion(&page, 16, 16, SCREEN_WIDTH, SCREEN_HEIGHT, 128); + modexClearRegion(&page, 32, 32, SCREEN_WIDTH-32, SCREEN_HEIGHT-32, 42); + modexClearRegion(&page, 48, 48, SCREEN_WIDTH-64, SCREEN_HEIGHT-64, 128); + modexShowPage(&page); + + modexDrawSprite(&page, 20, 20, &bmp); + //modexDrawBmp(&page, xb, yb, &bmp); + + /* fade in */ + modexFadeOn(1, pal2); + + + start = *clock; + //for(i=0; i<5; i++) { + while (!kbhit()){ /* Wait for a keystroke */ + /* go right */ + for(j=0; j<32; j++) { + page.dx++; + modexShowPage(&page); + } + /* go left */ + for(j=0; j<32; j++) { + page.dx--; + modexShowPage(&page); + } + /* go up */ + for(j=0; j<32; j++) { + page.dy++; + modexShowPage(&page); + } + + /* go down */ + for(j=0; j<32; j++) { + page.dy--; + modexShowPage(&page); + } + } + + (void) getch(); /* Clear the keyboard buffer */ + end = *clock; + + /* fade back to text mode */ + modexFadeOff(1, pal2); + modexPalBlack(); + setvideo(0); + modexPalBlack(); + modexFadeOn(1, pal); +} diff --git a/16/dos_gfx.h b/16/dos_gfx.h index 6c59aa78..cb47dc91 100644 --- a/16/dos_gfx.h +++ b/16/dos_gfx.h @@ -4,7 +4,7 @@ #include #include "lib\lib_com.h" #include "lib\x\modex.h" -//#include "lib\modex16.h" //____ +#include "lib\modex16.h" //____ #define NUM_COLORS 256 // number of colors in vga mode //static lgq=NUM_COLORS/(1/8) diff --git a/16/ed.pcx b/16/ed.pcx new file mode 100644 index 00000000..41e56317 Binary files /dev/null and b/16/ed.pcx differ diff --git a/16/gfx.pal b/16/gfx.pal new file mode 100644 index 00000000..e98ae60e Binary files /dev/null and b/16/gfx.pal differ diff --git a/16/lib/MODEX16.C b/16/lib/MODEX16.C index 3bdc3fb7..d8b646e6 100644 --- a/16/lib/MODEX16.C +++ b/16/lib/MODEX16.C @@ -92,37 +92,102 @@ modexEnter() { ptr[i] = 0x0000; } } + +int old_mode; + +///////////////////////////////////////////////////////////////////////////// +// // +// setvideo() - This function Manages the video modes // +// // +///////////////////////////////////////////////////////////////////////////// +void setvideo(/*byte mode, */short vq){ + union REGS in, out; + + if(!vq){ // deinit the video + // change to the video mode we were in before we switched to mode 13h + in.h.ah = 0x00; + in.h.al = old_mode; + int86(0x10, &in, &out); + + }else if(vq==1){ // init the video + // get old video mode + in.h.ah = 0xf; + int86(0x10, &in, &out); + old_mode = out.h.al; + // enter mode + modexEnter(); + } +} + +page_t +modexDefaultPage() { + page_t page; + + /* default page values */ + page.data = VGA; + page.dx = 0; + page.dy = 0; + page.width = SCREEN_WIDTH; + page.height = SCREEN_HEIGHT; + + return page; +} +/* returns the next page in contiguous memory + * the next page will be the same size as p, by default + */ +page_t +modexNextPage(page_t *p) { + page_t result; -void -modexLeave() { - /* TODO restore original mode and palette */ - vgaSetMode(TEXT_MODE); + result.data = p->data + (p->width/4)*p->height; /* compute the offset */ + result.dx = 0; + result.dy = 0; + result.width = p->width; + result.height = p->height; + + return result; } void -modexShowPage(page_t page) { +modexShowPage(page_t *page) { word high_address; word low_address; + word offset; + byte crtcOffset; + + /* calculate offset */ + offset = (word) page->data; + offset += page->dy * (page->width >> 2 ); + offset += page->dx >> 2; - high_address = HIGH_ADDRESS | ((word)(page) & 0xff00); - low_address = LOW_ADDRESS | ((word)(page) << 8); + /* calculate crtcOffset according to virtual width */ + crtcOffset = page->width >> 3; - /* wait for appropriate timing */ + high_address = HIGH_ADDRESS | (offset & 0xff00); + low_address = LOW_ADDRESS | (offset << 8); + + /* wait for appropriate timing and then program CRTC */ while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); outpw(CRTC_INDEX, high_address); outpw(CRTC_INDEX, low_address); + outp(CRTC_INDEX, 0x13); + outp(CRTC_DATA, crtcOffset); /* wait for one retrace */ while (!(inp(INPUT_STATUS_1) & VRETRACE)); + + /* do PEL panning here */ + outp(AC_INDEX, 0x33); + outp(AC_INDEX, (page->dx & 0x03) << 1); } void modexPanPage(page_t *page, int dx, int dy) { - /* TODO figure out how the $@#! you do horizontal panning */ - *page += dy * SCREEN_WIDTH; + page->dx = dx; + page->dy = dy; } @@ -134,45 +199,219 @@ modexSelectPlane(byte plane) { void -modexClearRegion(page_t page, int x, int y, int w, int h, byte color) { - byte plane; - word endx = x + w; - word endy = y + h; - word dx, dy; - - /* TODO Make this fast. It's SLOOOOOOW */ - for(plane=0; plane < 4; plane++) { - modexSelectPlane(PLANE(plane+x)); - for(dx = x; dx < endx; dx+=4) { - for(dy=y; dydata; + word xoff=x/4; /* xoffset that begins each row */ + word scanCount=w/4; /* number of iterations per row (excluding right clip)*/ + word poffset = pageOff + y*(page->width/4) + xoff; /* starting offset */ + word nextRow = page->width/4-scanCount-1; /* loc of next row */ + byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */ + byte rclip[] = {0x00, 0x01, 0x03, 0x07}; + byte left = lclip[x&0x03]; + byte right = rclip[(x+w)&0x03]; + + /* handle the case which requires an extra group */ + if((x & 0x03) && !((x+w) & 0x03)) { + right=0x0f; + } + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + MOV DI, poffset ; go to the first pixel + MOV DX, SC_INDEX ; point to the map mask + MOV AL, MAP_MASK + OUT DX, AL + INC DX + MOV AL, color ; get ready to write colors + SCAN_START: + MOV CX, scanCount ; count the line + MOV BL, AL ; remember color + MOV AL, left ; do the left clip + OUT DX, AL ; set the left clip + MOV AL, BL ; restore color + STOSB ; write the color + DEC CX + JZ SCAN_DONE ; handle 1 group stuff + + ;-- write the main body of the scanline + MOV BL, AL ; remember color + MOV AL, 0x0f ; write to all pixels + OUT DX, AL + MOV AL, BL ; restore color + REP STOSB ; write the color + SCAN_DONE: + MOV BL, AL ; remeber color + MOV AL, right + OUT DX, AL ; do the right clip + MOV AL, BL ; restore color + STOSB ; write pixel + ADD DI, nextRow ; go to the next row + DEC h + JNZ SCAN_START } } void -modexDrawBmp(page_t page, int x, int y, bitmap_t *bmp, byte sprite) { - byte plane; - word px, py; - word offset; +modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the region (the entire freakin bitmap) */ + modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} - /* TODO Make this fast. It's SLOOOOOOW */ - for(plane=0; plane < 4; plane++) { - modexSelectPlane(PLANE(plane+x)); - for(px = plane; px < bmp->width; px+=4) { - offset=px; - for(py=0; pyheight; py++) { - if(!sprite || bmp->data[offset]) - page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset]; - offset+=bmp->width; - } - } + +void +modexDrawBmpRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word) page->data + y*(page->width/4) + x/4; + byte *data = bmp->data; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, MAP_MASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + MOVSB ; copy the pixel + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes } } +void +modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the whole sprite */ + modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawSpriteRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = bmp->data; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, MAP_MASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + LODSB + DEC SI + CMP AL, 0 + JNE DRAW_PIXEL ; draw non-zero pixels + + INC DI ; skip the transparent pixel + ADD SI, 1 + JMP NEXT_PIXEL + DRAW_PIXEL: + MOVSB ; copy the pixel + NEXT_PIXEL: + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + + +void +modexCopyPageRegion(page_t *dest, page_t src, + word sx, word sy, + word dx, word dy, + word width, word height) +{ + /* todo */ +} + + /* fade and flash */ void modexFadeOn(word fade, byte *palette) { diff --git a/16/lib/MODEX16.H b/16/lib/MODEX16.H index 880f2c8b..2adc5c43 100644 --- a/16/lib/MODEX16.H +++ b/16/lib/MODEX16.H @@ -4,12 +4,11 @@ #ifndef MODEX16_H #define MODEX16_H #include -#include "lib\types.h" - +#include "lib\types.h" + /* -========================== Types & Macros ==========================- */ #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2)) #define PLANE(x) (1<< (x&3)) -typedef byte far* page_t; #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02) typedef struct { byte *data; @@ -18,15 +17,28 @@ typedef struct { byte *palette; } bitmap_t; +typedef struct { + byte far* data; /* the data for the page */ + word dx; /* col we are viewing on the virtual screen */ + word dy; /* row we are viewing on the virtual screen */ + word width; /* virtual width of the page */ + word height; /* virtual height of the page */ +} page_t; + /* -============================ Functions =============================- */ /* mode switching, page, and plane functions */ -void modexEnter(); -void modexLeave(); -void modexShowPage(page_t page); +void modexEnter(); +void setvideo(/*byte mode, */short vq); +page_t modexDefaultPage(); +page_t modexNextPage(page_t *p); +void modexShowPage(page_t *page); void modexPanPage(page_t *page, int dx, int dy); void modexSelectPlane(byte plane); -void modexClearRegion(page_t page, int x, int y, int w, int h, byte color); -void modexDrawBmp(page_t page, int x, int y, bitmap_t *bmp, byte sprite); +void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color); +void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); +void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); /* Palette fade and flash effects */ void modexFadeOn(word fade, byte *palette); @@ -49,10 +61,11 @@ void modexPalUpdate(byte *p); void modexWaitBorder(); /* bitmap functions */ -bitmap_t modexLoadPcx(char *filename); +bitmap_t modexLoadPcx(char *filename); /* -======================= Constants & Vars ==========================- */ extern byte far* VGA; /* The VGA Memory */ +#define SCREEN_SEG 0xa000 #define VIDEO_INT 0x10 #define SET_MODE 0x00 #define VGA_256_COLOR_MODE 0x13 @@ -61,6 +74,7 @@ extern byte far* VGA; /* The VGA Memory */ #define SCREEN_HEIGHT 240 #define PAGE_SIZE (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT) +#define AC_INDEX 0x03c0 #define SC_INDEX 0x03c4 #define SC_DATA 0x03c5 #define CRTC_INDEX 0x03d4 @@ -75,5 +89,14 @@ extern byte far* VGA; /* The VGA Memory */ #define PAL_READ_REG 0x03C7 /* Color register, read address */ #define PAL_WRITE_REG 0x03C8 /* Color register, write address */ #define PAL_DATA_REG 0x03C9 /* Color register, data port */ -#define PAL_SIZE (256 * 3) +#define PAL_SIZE (256 * 3) + +#define NUM_COLORS 256 // number of colors in vga mode +#define BONK 400 +#define LGQ 32 +#define HGQ 55 +#define TILEWH 16 +#define QUADWH TILEWH/2 +#define VW (SCREEN_WIDTH+32) +#define VH (SCREEN_HEIGHT+32) #endif diff --git a/16/lib/TYPES.H b/16/lib/TYPES.H index f6443b1b..039653f2 100644 --- a/16/lib/TYPES.H +++ b/16/lib/TYPES.H @@ -8,4 +8,4 @@ typedef unsigned short word; typedef unsigned long dword; typedef signed char sbyte; typedef signed short sword; -typedef signed long sdword; +typedef signed long sdword; diff --git a/16/lib/types.h b/16/lib/types.h new file mode 100644 index 00000000..039653f2 --- /dev/null +++ b/16/lib/types.h @@ -0,0 +1,11 @@ +/* + * Just some handy typedefs that make it easier to think about the low + * level code + */ + +typedef unsigned char byte; +typedef unsigned short word; +typedef unsigned long dword; +typedef signed char sbyte; +typedef signed short sword; +typedef signed long sdword; diff --git a/16/makefile b/16/makefile new file mode 100644 index 00000000..e6469f24 --- /dev/null +++ b/16/makefile @@ -0,0 +1,15 @@ +FLAGS=-0 -d3 +all: test.exe + +test.exe: test.obj modex16.obj + wcl $(FLAGS) test.obj modex16.obj + +test.obj: test.c lib\modex16.h + wcl $(FLAGS) -c test.c + +modex16.obj: lib\modex16.h lib\modex16.c + wcl $(FLAGS) -c lib\modex16.c + +clean: + del *.obj + del *.exe diff --git a/16/modex16/MODEX16.C b/16/modex16/MODEX16.C index bdc089e5..f6ead33e 100644 --- a/16/modex16/MODEX16.C +++ b/16/modex16/MODEX16.C @@ -92,14 +92,32 @@ modexEnter() { ptr[i] = 0x0000; } } - - -void -modexLeave() { - /* TODO restore original mode and palette */ - vgaSetMode(TEXT_MODE); -} - + +int old_mode; + +///////////////////////////////////////////////////////////////////////////// +// // +// setvideo() - This function Manages the video modes // +// // +///////////////////////////////////////////////////////////////////////////// +void setvideo(/*byte mode, */short vq){ + union REGS in, out; + + if(!vq){ // deinit the video + // change to the video mode we were in before we switched to mode 13h + in.h.ah = 0x00; + in.h.al = old_mode; + int86(0x10, &in, &out); + + }else if(vq==1){ // init the video + // get old video mode + in.h.ah = 0xf; + int86(0x10, &in, &out); + old_mode = out.h.al; + // enter mode + modexEnter(); + } +} page_t modexDefaultPage() { diff --git a/16/modex16/MODEX16.H b/16/modex16/MODEX16.H index 81960dd8..cde4cd2f 100644 --- a/16/modex16/MODEX16.H +++ b/16/modex16/MODEX16.H @@ -4,8 +4,8 @@ #ifndef MODEX16_H #define MODEX16_H #include -#include "types.h" - +#include "types.h" + /* -========================== Types & Macros ==========================- */ #define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2)) #define PLANE(x) (1<< (x&3)) @@ -27,8 +27,8 @@ typedef struct { /* -============================ Functions =============================- */ /* mode switching, page, and plane functions */ -void modexEnter(); -void modexLeave(); +void modexEnter(); +void setvideo(/*byte mode, */short vq); page_t modexDefaultPage(); page_t modexNextPage(page_t *p); void modexShowPage(page_t *page); @@ -61,7 +61,7 @@ void modexPalUpdate(byte *p); void modexWaitBorder(); /* bitmap functions */ -bitmap_t modexLoadPcx(char *filename); +bitmap_t modexLoadPcx(char *filename); /* -======================= Constants & Vars ==========================- */ extern byte far* VGA; /* The VGA Memory */ @@ -89,5 +89,12 @@ extern byte far* VGA; /* The VGA Memory */ #define PAL_READ_REG 0x03C7 /* Color register, read address */ #define PAL_WRITE_REG 0x03C8 /* Color register, write address */ #define PAL_DATA_REG 0x03C9 /* Color register, data port */ -#define PAL_SIZE (256 * 3) +#define PAL_SIZE (256 * 3) + +#define NUM_COLORS 256 // number of colors in vga mode +#define BONK 400 +#define LGQ 32 +#define HGQ 55 +#define TILEWH 16 +#define QUADWH TILEWH/2 #endif diff --git a/16/modex16/PALVIEW.EXE b/16/modex16/PALVIEW.EXE new file mode 100644 index 00000000..4c721d3b Binary files /dev/null and b/16/modex16/PALVIEW.EXE differ diff --git a/16/modex16/PCXTEST.C b/16/modex16/PCXTEST.C index 6b88f581..45f783c6 100644 --- a/16/modex16/PCXTEST.C +++ b/16/modex16/PCXTEST.C @@ -33,7 +33,7 @@ void main() { page=modexDefaultPage(); bmp = modexLoadPcx("ed.pcx"); - modexEnter(); + setvideo(1); /* fix up the palette and everything */ modexPalUpdate(bmp.palette); @@ -65,7 +65,7 @@ void main() { modexDrawSprite(&page, 20, 20, &bmp); } t4 = (*clock-start) / 18.2; - modexLeave(); + setvideo(0); printf("Old non-sprite: %f\n", t1); printf("New non-sprite: %f\n", t2); diff --git a/16/modex16/PCXTEST.EXE b/16/modex16/PCXTEST.EXE index d49c06a4..e10ce68d 100644 Binary files a/16/modex16/PCXTEST.EXE and b/16/modex16/PCXTEST.EXE differ diff --git a/16/modex16/TEST.C b/16/modex16/TEST.C index 2d261b04..35909646 100644 --- a/16/modex16/TEST.C +++ b/16/modex16/TEST.C @@ -3,13 +3,17 @@ word far* clock= (word far*) 0x046C; /* 18.2hz clock */ -void main() { +void main() { + bitmap_t bmp; int i, j; word start, end; page_t page, page2; float elapsed; byte *pal, *pal2=NULL; + /* load pcx file */ + bmp = modexLoadPcx("ed.pcx"); + /* load our palette */ modexLoadPalFile("gfx.pal", &pal2); @@ -19,7 +23,7 @@ void main() { modexFadeOff(1, pal); modexPalBlack(); - modexEnter(); + setvideo(1); modexPalBlack(); /* set up the page, but with 16 pixels on all borders in offscreen mem */ @@ -36,12 +40,16 @@ void main() { modexClearRegion(&page, 48, 48, SCREEN_WIDTH-64, SCREEN_HEIGHT-64, 128); modexShowPage(&page); + modexDrawSprite(&page, 20, 20, &bmp); + //modexDrawBmp(&page, xb, yb, &bmp); + /* fade in */ modexFadeOn(1, pal2); start = *clock; - for(i=0; i<5; i++) { + //for(i=0; i<5; i++) { + while (!kbhit()){ /* Wait for a keystroke */ /* go right */ for(j=0; j<32; j++) { page.dx++; @@ -65,12 +73,13 @@ void main() { } } + (void) getch(); /* Clear the keyboard buffer */ end = *clock; /* fade back to text mode */ modexFadeOff(1, pal2); modexPalBlack(); - modexLeave(); + setvideo(0); modexPalBlack(); modexFadeOn(1, pal); } diff --git a/16/modex16/TEST.EXE b/16/modex16/TEST.EXE index 58538eb4..d19c48e9 100644 Binary files a/16/modex16/TEST.EXE and b/16/modex16/TEST.EXE differ diff --git a/16/modex16/TEST2.EXE b/16/modex16/TEST2.EXE new file mode 100644 index 00000000..57c13a9e Binary files /dev/null and b/16/modex16/TEST2.EXE differ diff --git a/16/modex16/modex16.c b/16/modex16/modex16.c deleted file mode 100644 index bdc089e5..00000000 --- a/16/modex16/modex16.c +++ /dev/null @@ -1,641 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "modex16.h" - - -byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */ - -static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette); -static byte tmppal[PAL_SIZE]; -static struct pcxHeader { - byte id; - byte version; - byte encoding; - byte bpp; - word xmin; - word ymin; - word xmax; - word ymax; - word hres; - word vres; - byte pal16[48]; - byte res1; - word bpplane; - word palType; - word hScreenSize; - word vScreenSize; - byte padding[54]; -}; - - -static void -vgaSetMode(byte mode) -{ - union REGS regs; - - regs.h.ah = SET_MODE; - regs.h.al = mode; - int86(VIDEO_INT, ®s, ®s); -} - - -/* -========================= Entry Points ==========================- */ -void -modexEnter() { - word i; - dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ - word CRTParms[] = { - 0x0d06, /* vertical total */ - 0x3e07, /* overflow (bit 8 of vertical counts) */ - 0x4109, /* cell height (2 to double-scan */ - 0xea10, /* v sync start */ - 0xac11, /* v sync end and protect cr0-cr7 */ - 0xdf12, /* vertical displayed */ - 0x0014, /* turn off dword mode */ - 0xe715, /* v blank start */ - 0x0616, /* v blank end */ - 0xe317 /* turn on byte mode */ - }; - int CRTParmCount = sizeof(CRTParms) / sizeof(CRTParms[0]); - - /* TODO save current video mode and palette */ - vgaSetMode(VGA_256_COLOR_MODE); - - /* disable chain4 mode */ - outpw(SC_INDEX, 0x0604); - - /* synchronous reset while setting Misc Output */ - outpw(SC_INDEX, 0x0100); - - /* select 25 MHz dot clock & 60 Hz scanning rate */ - outp(MISC_OUTPUT, 0xe3); - - /* undo reset (restart sequencer) */ - outpw(SC_INDEX, 0x0300); - - /* reprogram the CRT controller */ - outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */ - outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ - - /* send the CRTParms */ - for(i=0; idata + (p->width/4)*p->height; /* compute the offset */ - result.dx = 0; - result.dy = 0; - result.width = p->width; - result.height = p->height; - - return result; -} - - -void -modexShowPage(page_t *page) { - word high_address; - word low_address; - word offset; - byte crtcOffset; - - /* calculate offset */ - offset = (word) page->data; - offset += page->dy * (page->width >> 2 ); - offset += page->dx >> 2; - - /* calculate crtcOffset according to virtual width */ - crtcOffset = page->width >> 3; - - high_address = HIGH_ADDRESS | (offset & 0xff00); - low_address = LOW_ADDRESS | (offset << 8); - - /* wait for appropriate timing and then program CRTC */ - while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); - outpw(CRTC_INDEX, high_address); - outpw(CRTC_INDEX, low_address); - outp(CRTC_INDEX, 0x13); - outp(CRTC_DATA, crtcOffset); - - /* wait for one retrace */ - while (!(inp(INPUT_STATUS_1) & VRETRACE)); - - /* do PEL panning here */ - outp(AC_INDEX, 0x33); - outp(AC_INDEX, (page->dx & 0x03) << 1); -} - - -void -modexPanPage(page_t *page, int dx, int dy) { - page->dx = dx; - page->dy = dy; -} - - -void -modexSelectPlane(byte plane) { - outp(SC_INDEX, MAP_MASK); /* select plane */ - outp(SC_DATA, plane); -} - - -void -modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) { - word pageOff = (word) page->data; - word xoff=x/4; /* xoffset that begins each row */ - word scanCount=w/4; /* number of iterations per row (excluding right clip)*/ - word poffset = pageOff + y*(page->width/4) + xoff; /* starting offset */ - word nextRow = page->width/4-scanCount-1; /* loc of next row */ - byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */ - byte rclip[] = {0x00, 0x01, 0x03, 0x07}; - byte left = lclip[x&0x03]; - byte right = rclip[(x+w)&0x03]; - - /* handle the case which requires an extra group */ - if((x & 0x03) && !((x+w) & 0x03)) { - right=0x0f; - } - - __asm { - MOV AX, SCREEN_SEG ; go to the VGA memory - MOV ES, AX - MOV DI, poffset ; go to the first pixel - MOV DX, SC_INDEX ; point to the map mask - MOV AL, MAP_MASK - OUT DX, AL - INC DX - MOV AL, color ; get ready to write colors - SCAN_START: - MOV CX, scanCount ; count the line - MOV BL, AL ; remember color - MOV AL, left ; do the left clip - OUT DX, AL ; set the left clip - MOV AL, BL ; restore color - STOSB ; write the color - DEC CX - JZ SCAN_DONE ; handle 1 group stuff - - ;-- write the main body of the scanline - MOV BL, AL ; remember color - MOV AL, 0x0f ; write to all pixels - OUT DX, AL - MOV AL, BL ; restore color - REP STOSB ; write the color - SCAN_DONE: - MOV BL, AL ; remeber color - MOV AL, right - OUT DX, AL ; do the right clip - MOV AL, BL ; restore color - STOSB ; write pixel - ADD DI, nextRow ; go to the next row - DEC h - JNZ SCAN_START - } -} - - -void -modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { - /* draw the region (the entire freakin bitmap) */ - modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); -} - - -void -modexDrawBmpRegion(page_t *page, int x, int y, - int rx, int ry, int rw, int rh, bitmap_t *bmp) { - word poffset = (word) page->data + y*(page->width/4) + x/4; - byte *data = bmp->data; - word bmpOffset = (word) data + ry * bmp->width + rx; - word width = rw; - word height = rh; - byte plane = 1 << ((byte) x & 0x03); - word scanCount = width/4 + (width%4 ? 1 :0); - word nextPageRow = page->width/4 - scanCount; - word nextBmpRow = (word) bmp->width - width; - word rowCounter; - byte planeCounter = 4; - - __asm { - MOV AX, SCREEN_SEG ; go to the VGA memory - MOV ES, AX - - MOV DX, SC_INDEX ; point at the map mask register - MOV AL, MAP_MASK ; - OUT DX, AL ; - - PLANE_LOOP: - MOV DX, SC_DATA ; select the current plane - MOV AL, plane ; - OUT DX, AL ; - - ;-- begin plane painting - MOV AX, height ; start the row counter - MOV rowCounter, AX ; - MOV DI, poffset ; go to the first pixel - MOV SI, bmpOffset ; go to the bmp pixel - ROW_LOOP: - MOV CX, width ; count the columns - SCAN_LOOP: - MOVSB ; copy the pixel - SUB CX, 3 ; we skip the next 3 - ADD SI, 3 ; skip the bmp pixels - LOOP SCAN_LOOP ; finish the scan - - MOV AX, nextPageRow - ADD DI, AX ; go to the next row on screen - MOV AX, nextBmpRow - ADD SI, AX ; go to the next row on bmp - - DEC rowCounter - JNZ ROW_LOOP ; do all the rows - ;-- end plane painting - - MOV AL, plane ; advance to the next plane - SHL AL, 1 ; - AND AL, 0x0f ; mask the plane properly - MOV plane, AL ; store the plane - - INC bmpOffset ; start bmp at the right spot - - DEC planeCounter - JNZ PLANE_LOOP ; do all 4 planes - } -} - - -void -modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) { - /* draw the whole sprite */ - modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); -} - -void -modexDrawSpriteRegion(page_t *page, int x, int y, - int rx, int ry, int rw, int rh, bitmap_t *bmp) { - word poffset = (word)page->data + y*(page->width/4) + x/4; - byte *data = bmp->data; - word bmpOffset = (word) data + ry * bmp->width + rx; - word width = rw; - word height = rh; - byte plane = 1 << ((byte) x & 0x03); - word scanCount = width/4 + (width%4 ? 1 :0); - word nextPageRow = page->width/4 - scanCount; - word nextBmpRow = (word) bmp->width - width; - word rowCounter; - byte planeCounter = 4; - - __asm { - MOV AX, SCREEN_SEG ; go to the VGA memory - MOV ES, AX - - MOV DX, SC_INDEX ; point at the map mask register - MOV AL, MAP_MASK ; - OUT DX, AL ; - - PLANE_LOOP: - MOV DX, SC_DATA ; select the current plane - MOV AL, plane ; - OUT DX, AL ; - - ;-- begin plane painting - MOV AX, height ; start the row counter - MOV rowCounter, AX ; - MOV DI, poffset ; go to the first pixel - MOV SI, bmpOffset ; go to the bmp pixel - ROW_LOOP: - MOV CX, width ; count the columns - SCAN_LOOP: - LODSB - DEC SI - CMP AL, 0 - JNE DRAW_PIXEL ; draw non-zero pixels - - INC DI ; skip the transparent pixel - ADD SI, 1 - JMP NEXT_PIXEL - DRAW_PIXEL: - MOVSB ; copy the pixel - NEXT_PIXEL: - SUB CX, 3 ; we skip the next 3 - ADD SI, 3 ; skip the bmp pixels - LOOP SCAN_LOOP ; finish the scan - - MOV AX, nextPageRow - ADD DI, AX ; go to the next row on screen - MOV AX, nextBmpRow - ADD SI, AX ; go to the next row on bmp - - DEC rowCounter - JNZ ROW_LOOP ; do all the rows - ;-- end plane painting - - MOV AL, plane ; advance to the next plane - SHL AL, 1 ; - AND AL, 0x0f ; mask the plane properly - MOV plane, AL ; store the plane - - INC bmpOffset ; start bmp at the right spot - - DEC planeCounter - JNZ PLANE_LOOP ; do all 4 planes - } -} - - -void -modexCopyPageRegion(page_t *dest, page_t src, - word sx, word sy, - word dx, word dy, - word width, word height) -{ - /* todo */ -} - - -/* fade and flash */ -void -modexFadeOn(word fade, byte *palette) { - fadePalette(-fade, 64, 64/fade+1, palette); -} - - -void -modexFadeOff(word fade, byte *palette) { - fadePalette(fade, 0, 64/fade+1, palette); -} - - -void -modexFlashOn(word fade, byte *palette) { - fadePalette(fade, -64, 64/fade+1, palette); -} - - -void -modexFlashOff(word fade, byte *palette) { - fadePalette(-fade, 0, 64/fade+1, palette); -} - - -static void -fadePalette(sbyte fade, sbyte start, word iter, byte *palette) { - word i; - byte dim = start; - - /* handle the case where we just update */ - if(iter == 0) { - modexPalUpdate(palette); - return; - } - - while(iter > 0) { /* FadeLoop */ - for(i=0; i 127) { - tmppal[i] = 0; - } else if(tmppal[i] > 63) { - tmppal[i] = 63; - } - } - modexPalUpdate(tmppal); - iter--; - dim += fade; - } -} - - -/* save and load */ -void -modexPalSave(byte *palette) { - int i; - - outp(PAL_READ_REG, 0); /* start at palette entry 0 */ - for(i=0; i> 2; - } - } else { - /* use the 16 color palette */ - for(index=0; index<48; index++) { - result.palette[index] = head.pal16[index]; - } - } - - fclose(file); - - return result; -} diff --git a/16/modex16/modex16.h b/16/modex16/modex16.h deleted file mode 100644 index 81960dd8..00000000 --- a/16/modex16/modex16.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Functions for handling modex and doing other basic graphics stuff. - */ -#ifndef MODEX16_H -#define MODEX16_H -#include -#include "types.h" - -/* -========================== Types & Macros ==========================- */ -#define PAGE_OFFSET(x,y) (((y)<<6)+((y)<<4)+((x)>>2)) -#define PLANE(x) (1<< (x&3)) -#define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02) -typedef struct { - byte *data; - word width; - word height; - byte *palette; -} bitmap_t; - -typedef struct { - byte far* data; /* the data for the page */ - word dx; /* col we are viewing on the virtual screen */ - word dy; /* row we are viewing on the virtual screen */ - word width; /* virtual width of the page */ - word height; /* virtual height of the page */ -} page_t; - -/* -============================ Functions =============================- */ -/* mode switching, page, and plane functions */ -void modexEnter(); -void modexLeave(); -page_t modexDefaultPage(); -page_t modexNextPage(page_t *p); -void modexShowPage(page_t *page); -void modexPanPage(page_t *page, int dx, int dy); -void modexSelectPlane(byte plane); -void modexClearRegion(page_t *page, int x, int y, int w, int h, byte color); -void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp); -void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); -void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp); -void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); - -/* Palette fade and flash effects */ -void modexFadeOn(word fade, byte *palette); -void modexFadeOff(word fade, byte *palette); -void modexFlashOn(word fade, byte *palette); -void modexFlashOff(word fade, byte *palette); - -/* palette loading and saving */ -void modexPalSave(byte *palette); -byte *modexNewPal(); -void modexLoadPalFile(char *filename, byte **palette); -void modexSavePalFile(char *filename, byte *palette); - -/* fixed palette functions */ -void modexPalBlack(); -void modexPalWhite(); - -/* utility functions */ -void modexPalUpdate(byte *p); -void modexWaitBorder(); - -/* bitmap functions */ -bitmap_t modexLoadPcx(char *filename); - -/* -======================= Constants & Vars ==========================- */ -extern byte far* VGA; /* The VGA Memory */ -#define SCREEN_SEG 0xa000 -#define VIDEO_INT 0x10 -#define SET_MODE 0x00 -#define VGA_256_COLOR_MODE 0x13 -#define TEXT_MODE 0x03 -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 240 -#define PAGE_SIZE (word)(SCREEN_WIDTH/4 * SCREEN_HEIGHT) - -#define AC_INDEX 0x03c0 -#define SC_INDEX 0x03c4 -#define SC_DATA 0x03c5 -#define CRTC_INDEX 0x03d4 -#define CRTC_DATA 0x03d5 -#define MISC_OUTPUT 0x03c2 -#define HIGH_ADDRESS 0x0C -#define LOW_ADDRESS 0x0D -#define VRETRACE 0x08 -#define INPUT_STATUS_1 0x03da -#define DISPLAY_ENABLE 0x01 -#define MAP_MASK 0x02 -#define PAL_READ_REG 0x03C7 /* Color register, read address */ -#define PAL_WRITE_REG 0x03C8 /* Color register, write address */ -#define PAL_DATA_REG 0x03C9 /* Color register, data port */ -#define PAL_SIZE (256 * 3) -#endif diff --git a/16/modex16/pcxtest.c b/16/modex16/pcxtest.c index 6b88f581..45f783c6 100644 --- a/16/modex16/pcxtest.c +++ b/16/modex16/pcxtest.c @@ -33,7 +33,7 @@ void main() { page=modexDefaultPage(); bmp = modexLoadPcx("ed.pcx"); - modexEnter(); + setvideo(1); /* fix up the palette and everything */ modexPalUpdate(bmp.palette); @@ -65,7 +65,7 @@ void main() { modexDrawSprite(&page, 20, 20, &bmp); } t4 = (*clock-start) / 18.2; - modexLeave(); + setvideo(0); printf("Old non-sprite: %f\n", t1); printf("New non-sprite: %f\n", t2); diff --git a/16/modex16/pcxtest.exe b/16/modex16/pcxtest.exe deleted file mode 100644 index d49c06a4..00000000 Binary files a/16/modex16/pcxtest.exe and /dev/null differ diff --git a/16/modex16/test.c b/16/modex16/test.c index 2d261b04..35909646 100644 --- a/16/modex16/test.c +++ b/16/modex16/test.c @@ -3,13 +3,17 @@ word far* clock= (word far*) 0x046C; /* 18.2hz clock */ -void main() { +void main() { + bitmap_t bmp; int i, j; word start, end; page_t page, page2; float elapsed; byte *pal, *pal2=NULL; + /* load pcx file */ + bmp = modexLoadPcx("ed.pcx"); + /* load our palette */ modexLoadPalFile("gfx.pal", &pal2); @@ -19,7 +23,7 @@ void main() { modexFadeOff(1, pal); modexPalBlack(); - modexEnter(); + setvideo(1); modexPalBlack(); /* set up the page, but with 16 pixels on all borders in offscreen mem */ @@ -36,12 +40,16 @@ void main() { modexClearRegion(&page, 48, 48, SCREEN_WIDTH-64, SCREEN_HEIGHT-64, 128); modexShowPage(&page); + modexDrawSprite(&page, 20, 20, &bmp); + //modexDrawBmp(&page, xb, yb, &bmp); + /* fade in */ modexFadeOn(1, pal2); start = *clock; - for(i=0; i<5; i++) { + //for(i=0; i<5; i++) { + while (!kbhit()){ /* Wait for a keystroke */ /* go right */ for(j=0; j<32; j++) { page.dx++; @@ -65,12 +73,13 @@ void main() { } } + (void) getch(); /* Clear the keyboard buffer */ end = *clock; /* fade back to text mode */ modexFadeOff(1, pal2); modexPalBlack(); - modexLeave(); + setvideo(0); modexPalBlack(); modexFadeOn(1, pal); } diff --git a/16/modex16/test.exe b/16/modex16/test.exe deleted file mode 100644 index 58538eb4..00000000 Binary files a/16/modex16/test.exe and /dev/null differ diff --git a/16/modex16/test2.c b/16/modex16/test2.c index 19f05e09..a3669980 100644 --- a/16/modex16/test2.c +++ b/16/modex16/test2.c @@ -10,13 +10,13 @@ void main() { page=modexDefaultPage(); - modexEnter(); + setvideo(1); start = *clock; for(i=0; i<500; i++) { modexShowPage(&page); } t1 = (*clock - start)/18.2; - modexLeave(); + setvideo(0); printf("Time: %f\n", t1); } diff --git a/16/modex16/test2.exe b/16/modex16/test2.exe deleted file mode 100644 index 8b364604..00000000 Binary files a/16/modex16/test2.exe and /dev/null differ