From: sparky4 Date: Fri, 25 Jul 2014 02:02:35 +0000 (-0500) Subject: modified: 16/MODEX16.ZIP X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=42b3ed060a69fb588c7b933748400f2a052add0c;p=16.git modified: 16/MODEX16.ZIP deleted: 16/modex16/DP_BPAL.$$$ deleted: 16/modex16/DP_CPAL.$$$ deleted: 16/modex16/DP_OPAL.$$$ deleted: 16/modex16/DP_PREFS deleted: 16/modex16/DP_SPAL.$$$ deleted: 16/modex16/EDw.PCX modified: 16/modex16/MAKEFILE modified: 16/modex16/MODEX16.C modified: 16/modex16/MODEX16.H deleted: 16/modex16/PALVIEW.EXE modified: 16/modex16/PCXTEST.C modified: 16/modex16/PCXTEST.EXE deleted: 16/modex16/PCXTEST.SMP modified: 16/modex16/TEST.C modified: 16/modex16/TEST.EXE deleted: 16/modex16/TEST.SMP deleted: 16/modex16/chikyuu.pcx new file: 16/modex16/ed.pcx deleted: 16/modex16/ed2.pcx deleted: 16/modex16/flower.pcx new file: 16/modex16/gfx.pal deleted: 16/modex16/koishi.pcx deleted: 16/modex16/koishi^^.pcx new file: 16/modex16/makefile new file: 16/modex16/modex16.c new file: 16/modex16/modex16.h deleted: 16/modex16/palette.c deleted: 16/modex16/palette.h new file: 16/modex16/palettec.c new file: 16/modex16/pcxtest.c new file: 16/modex16/pcxtest.exe deleted: 16/modex16/q.pcx new file: 16/modex16/test.c new file: 16/modex16/test.exe new file: 16/modex16/test.txt new file: 16/modex16/test2.c new file: 16/modex16/test2.exe new file: 16/modex16/types.h deleted: 16/modex16/w.pcx modified: 16/w_modex/M.BAT modified: 16/w_modex/TEST.CPP modified: 16/w_modex/TEST.EXE --- diff --git a/16/MODEX16.ZIP b/16/MODEX16.ZIP index feed2125..a1480fab 100644 Binary files a/16/MODEX16.ZIP and b/16/MODEX16.ZIP differ diff --git a/16/modex16/DP_BPAL.$$$ b/16/modex16/DP_BPAL.$$$ deleted file mode 100644 index 06d74050..00000000 Binary files a/16/modex16/DP_BPAL.$$$ and /dev/null differ diff --git a/16/modex16/DP_CPAL.$$$ b/16/modex16/DP_CPAL.$$$ deleted file mode 100644 index 06d74050..00000000 Binary files a/16/modex16/DP_CPAL.$$$ and /dev/null differ diff --git a/16/modex16/DP_OPAL.$$$ b/16/modex16/DP_OPAL.$$$ deleted file mode 100644 index 1edf0273..00000000 Binary files a/16/modex16/DP_OPAL.$$$ and /dev/null differ diff --git a/16/modex16/DP_PREFS b/16/modex16/DP_PREFS deleted file mode 100644 index 2ea33836..00000000 Binary files a/16/modex16/DP_PREFS and /dev/null differ diff --git a/16/modex16/DP_SPAL.$$$ b/16/modex16/DP_SPAL.$$$ deleted file mode 100644 index 06d74050..00000000 Binary files a/16/modex16/DP_SPAL.$$$ and /dev/null differ diff --git a/16/modex16/EDw.PCX b/16/modex16/EDw.PCX deleted file mode 100644 index 2427b5da..00000000 Binary files a/16/modex16/EDw.PCX and /dev/null differ diff --git a/16/modex16/MAKEFILE b/16/modex16/MAKEFILE index b073c98f..c48885b8 100644 --- a/16/modex16/MAKEFILE +++ b/16/modex16/MAKEFILE @@ -1,17 +1,27 @@ -FLAGS=-0 -d2 -all: test.exe pcxtest.exe +FLAGS=-0 -d3 +all: test.exe pcxtest.exe test2.exe test.exe: test.obj modex16.obj wcl $(FLAGS) test.obj modex16.obj +test2.exe: test2.obj modex16.obj + wcl $(FLAGS) test2.obj modex16.obj + pcxtest.exe: pcxtest.obj modex16.obj wcl $(FLAGS) pcxtest.obj modex16.obj test.obj: test.c modex16.h wcl $(FLAGS) -c test.c +test2.obj: test2.c modex16.h + wcl $(FLAGS) -c test2.c + pcxtest.obj: pcxtest.c modex16.h wcl $(FLAGS) -c pcxtest.c modex16.obj: modex16.h modex16.c wcl $(FLAGS) -c modex16.c + +clean: + del *.obj + del *.exe diff --git a/16/modex16/MODEX16.C b/16/modex16/MODEX16.C index 364ff3d2..bdc089e5 100644 --- a/16/modex16/MODEX16.C +++ b/16/modex16/MODEX16.C @@ -101,28 +101,75 @@ modexLeave() { } +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; + + 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; - high_address = HIGH_ADDRESS | ((word)(page) & 0xff00); - low_address = LOW_ADDRESS | ((word)(page) << 8); + /* calculate offset */ + offset = (word) page->data; + offset += page->dy * (page->width >> 2 ); + offset += page->dx >> 2; - /* wait for appropriate timing */ + /* 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) { - /* TODO figure out how the $@#! you do horizontal panning */ - *page += dy * SCREEN_WIDTH; + page->dx = dx; + page->dy = dy; } @@ -134,45 +181,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/modex16/MODEX16.H b/16/modex16/MODEX16.H index 7bd92bc1..81960dd8 100644 --- a/16/modex16/MODEX16.H +++ b/16/modex16/MODEX16.H @@ -9,7 +9,6 @@ /* -========================== 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); +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); @@ -53,6 +65,7 @@ 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 diff --git a/16/modex16/PALVIEW.EXE b/16/modex16/PALVIEW.EXE deleted file mode 100644 index 4c721d3b..00000000 Binary files a/16/modex16/PALVIEW.EXE and /dev/null differ diff --git a/16/modex16/PCXTEST.C b/16/modex16/PCXTEST.C index 3e4f501d..6b88f581 100644 --- a/16/modex16/PCXTEST.C +++ b/16/modex16/PCXTEST.C @@ -1,60 +1,76 @@ #include #include "modex16.h" +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +void +oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite) { + byte plane; + word px, py; + word offset; + + /* 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 main() { bitmap_t bmp; - //bitmap_t bmp2; - //bitmap_t bmp3; - //bitmap_t bmp4; -// int index; - //int ch=0x0; - - //bmp = modexLoadPcx("ed.pcx"); - //bmp = modexLoadPcx("w.pcx"); - //bmp2 = modexLoadPcx("q.pcx"); - printf("=\n"); - bmp = modexLoadPcx("chikyuu.pcx"); - printf("==\n"); - /*bmp2 = modexLoadPcx("ed2.pcx"); - bmp3 = modexLoadPcx("flower.pcx"); - bmp4 = modexLoadPcx("koishi^^.pcx");*/ - printf("===\n"); - modexEnter(); - printf("====\n"); - - /* fix up the palette and everything */ - printf("=====\n"); - modexPalUpdate(bmp.palette); - printf("======\n"); - - /* don't show the drawing page */ -// printf("=======\n"); - //modexShowPage(VGA + PAGE_SIZE); -// printf("========\n"); - - /* clear and draw one sprite and one bitmap */ -// printf("=========\n"); - //modexClearRegion(VGA, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); -// printf("==========\n"); - /*modexDrawBmp(VGA, 20, 20, &bmp2, 0); - modexDrawBmp(VGA, 180, 20, &bmp, 1); - modexDrawBmp(VGA, 180, 0, &bmp3, 1); - modexDrawBmp(VGA, 170, 100, &bmp4, 1);*/ - modexDrawBmp(VGA, 0, 0, &bmp, 0); - //modexDrawBmp(VGA, 100, 40, &bmp2, 1); - //modexDrawBmp(VGA, 0, 20, &bmp3, 0); - //modexDrawBmp(VGA, 120, 60, &bmp3, 1); - //modexShowPage(VGA); -// for(index = 0; index<500; index++) { - //while(1/*!kbhit()*/){ // conditions of screen saver - while (!kbhit()){ /* Wait for a keystroke */ - modexWaitBorder(); - //ch=getch(); - //if(ch==0x71)break; // 'q' - //if(ch==0x1b)break; // 'ESC' - } - (void) getch(); /* Clear the keyboard buffer */ - modexLeave(); + int i; + float t1, t2, t3, t4; + word start; + page_t page; + + page=modexDefaultPage(); + + bmp = modexLoadPcx("ed.pcx"); + modexEnter(); + + /* fix up the palette and everything */ + modexPalUpdate(bmp.palette); + + /* clear and draw one sprite and one bitmap */ + modexClearRegion(&page, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 1); + + /* non sprite comparison */ + start = *clock; + for(i=0; i<100 ;i++) { + oldDrawBmp(VGA, 20, 20, &bmp, 0); + } + t1 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + modexDrawBmp(&page, 20, 20, &bmp); + } + t2 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + oldDrawBmp(VGA, 20, 20, &bmp, 1); + } + t3 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + modexDrawSprite(&page, 20, 20, &bmp); + } + t4 = (*clock-start) / 18.2; + modexLeave(); + + printf("Old non-sprite: %f\n", t1); + printf("New non-sprite: %f\n", t2); + printf("Old Sprite: %f\n", t3); + printf("New Sprite: %f\n", t4); return; } diff --git a/16/modex16/PCXTEST.EXE b/16/modex16/PCXTEST.EXE index 05ff8048..d49c06a4 100644 Binary files a/16/modex16/PCXTEST.EXE and b/16/modex16/PCXTEST.EXE differ diff --git a/16/modex16/PCXTEST.SMP b/16/modex16/PCXTEST.SMP deleted file mode 100644 index 9eb89a12..00000000 Binary files a/16/modex16/PCXTEST.SMP and /dev/null differ diff --git a/16/modex16/TEST.C b/16/modex16/TEST.C index 74a9b801..2d261b04 100644 --- a/16/modex16/TEST.C +++ b/16/modex16/TEST.C @@ -4,11 +4,9 @@ word far* clock= (word far*) 0x046C; /* 18.2hz clock */ void main() { - int plane; - int x, y, i; + int i, j; word start, end; page_t page, page2; - word far* ptr; float elapsed; byte *pal, *pal2=NULL; @@ -19,32 +17,54 @@ void main() { pal = modexNewPal(); modexPalSave(pal); modexFadeOff(1, pal); - modexPalBlack();; + modexPalBlack(); modexEnter(); modexPalBlack(); - page= VGA; - page2=VGA+PAGE_SIZE; + /* 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 */ - modexShowPage(page2); - modexClearRegion(page, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 42); - modexClearRegion(page, 17, 12, 30, 30, 19); - modexShowPage(page); + /* 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); /* fade in */ modexFadeOn(1, pal2); - /* fill page2 up */ - modexClearRegion(page2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 128); - start = *clock; - for(i=0; i<500; i++) { - modexShowPage(page); - page+=SCREEN_WIDTH/4; + for(i=0; i<5; i++) { + /* 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); + } } + end = *clock; /* fade back to text mode */ @@ -53,6 +73,4 @@ void main() { modexLeave(); modexPalBlack(); modexFadeOn(1, pal); - elapsed = (end-start)/18.2; - printf("500 frames in %f seconds for %f fps\n", elapsed, 500.0/elapsed); } diff --git a/16/modex16/TEST.EXE b/16/modex16/TEST.EXE index b1f173e9..58538eb4 100644 Binary files a/16/modex16/TEST.EXE and b/16/modex16/TEST.EXE differ diff --git a/16/modex16/TEST.SMP b/16/modex16/TEST.SMP deleted file mode 100644 index 65f59bb6..00000000 Binary files a/16/modex16/TEST.SMP and /dev/null differ diff --git a/16/modex16/chikyuu.pcx b/16/modex16/chikyuu.pcx deleted file mode 100644 index 610a6c32..00000000 Binary files a/16/modex16/chikyuu.pcx and /dev/null differ diff --git a/16/modex16/ed.pcx b/16/modex16/ed.pcx new file mode 100644 index 00000000..41e56317 Binary files /dev/null and b/16/modex16/ed.pcx differ diff --git a/16/modex16/ed2.pcx b/16/modex16/ed2.pcx deleted file mode 100644 index b35305e3..00000000 Binary files a/16/modex16/ed2.pcx and /dev/null differ diff --git a/16/modex16/flower.pcx b/16/modex16/flower.pcx deleted file mode 100644 index 92616daf..00000000 Binary files a/16/modex16/flower.pcx and /dev/null differ diff --git a/16/modex16/gfx.pal b/16/modex16/gfx.pal new file mode 100644 index 00000000..e98ae60e Binary files /dev/null and b/16/modex16/gfx.pal differ diff --git a/16/modex16/koishi.pcx b/16/modex16/koishi.pcx deleted file mode 100644 index 76d05160..00000000 Binary files a/16/modex16/koishi.pcx and /dev/null differ diff --git a/16/modex16/koishi^^.pcx b/16/modex16/koishi^^.pcx deleted file mode 100644 index 0dbbc0da..00000000 Binary files a/16/modex16/koishi^^.pcx and /dev/null differ diff --git a/16/modex16/makefile b/16/modex16/makefile new file mode 100644 index 00000000..c48885b8 --- /dev/null +++ b/16/modex16/makefile @@ -0,0 +1,27 @@ +FLAGS=-0 -d3 +all: test.exe pcxtest.exe test2.exe + +test.exe: test.obj modex16.obj + wcl $(FLAGS) test.obj modex16.obj + +test2.exe: test2.obj modex16.obj + wcl $(FLAGS) test2.obj modex16.obj + +pcxtest.exe: pcxtest.obj modex16.obj + wcl $(FLAGS) pcxtest.obj modex16.obj + +test.obj: test.c modex16.h + wcl $(FLAGS) -c test.c + +test2.obj: test2.c modex16.h + wcl $(FLAGS) -c test2.c + +pcxtest.obj: pcxtest.c modex16.h + wcl $(FLAGS) -c pcxtest.c + +modex16.obj: modex16.h modex16.c + wcl $(FLAGS) -c modex16.c + +clean: + del *.obj + del *.exe diff --git a/16/modex16/modex16.c b/16/modex16/modex16.c new file mode 100644 index 00000000..bdc089e5 --- /dev/null +++ b/16/modex16/modex16.c @@ -0,0 +1,641 @@ +#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 new file mode 100644 index 00000000..81960dd8 --- /dev/null +++ b/16/modex16/modex16.h @@ -0,0 +1,93 @@ +/* + * 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/palette.c b/16/modex16/palette.c deleted file mode 100644 index 7a7e7342..00000000 --- a/16/modex16/palette.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * File: PALETTE.C - * Purpose: This file contains routines for manipulating the VGA palette. - */ -#include -#include -#include -#include "palette.h" - -static void fadePalette(byte fade, byte start, word iter, byte *palette); -static byte tmppal[PAL_SIZE]; - -/* fade and flash */ -void -fadeOn(word fade, byte *palette) { - fadePalette(-fade, 64, 64/fade+1, palette); -} - - -void -fadeOff(word fade, byte *palette) { - fadePalette(fade, 0, 64/fade+1, palette); -} - - -void -flashOn(word fade, byte *palette) { - fadePalette(fade, -64, 64/fade+1, palette); -} - - -void -flashOff(word fade, byte *palette) { - fadePalette(-fade, 0, 64/fade+1, palette); -} - - -static void -fadePalette(byte fade, byte start, word iter, byte *palette) { - word i; - byte dim = start; - - /* handle the case where we just update */ - if(iter == 0) { - palUpdate(palette); - return; - } - - while(iter > 0) { /* FadeLoop */ - for(i=0; i 127) { - tmppal[i] = 0; - } else if(tmppal[i] > 63) { - tmppal[i] = 63; - } - } - palUpdate(tmppal); - iter--; - dim += fade; - } -} - - -/* save and load */ -void -palSave(byte *palette) { - int i; - - outp(PEL_READ_REG, 0); /* start at palette entry 0 */ - for(i=0; i +#include "modex16.h" + +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +void +oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite) { + byte plane; + word px, py; + word offset; + + /* 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 main() { + bitmap_t bmp; + int i; + float t1, t2, t3, t4; + word start; + page_t page; + + page=modexDefaultPage(); + + bmp = modexLoadPcx("ed.pcx"); + modexEnter(); + + /* fix up the palette and everything */ + modexPalUpdate(bmp.palette); + + /* clear and draw one sprite and one bitmap */ + modexClearRegion(&page, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 1); + + /* non sprite comparison */ + start = *clock; + for(i=0; i<100 ;i++) { + oldDrawBmp(VGA, 20, 20, &bmp, 0); + } + t1 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + modexDrawBmp(&page, 20, 20, &bmp); + } + t2 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + oldDrawBmp(VGA, 20, 20, &bmp, 1); + } + t3 = (*clock-start) / 18.2; + + start = *clock; + for(i=0; i<100 ;i++) { + modexDrawSprite(&page, 20, 20, &bmp); + } + t4 = (*clock-start) / 18.2; + modexLeave(); + + printf("Old non-sprite: %f\n", t1); + printf("New non-sprite: %f\n", t2); + printf("Old Sprite: %f\n", t3); + printf("New Sprite: %f\n", t4); + + return; +} diff --git a/16/modex16/pcxtest.exe b/16/modex16/pcxtest.exe new file mode 100644 index 00000000..d49c06a4 Binary files /dev/null and b/16/modex16/pcxtest.exe differ diff --git a/16/modex16/q.pcx b/16/modex16/q.pcx deleted file mode 100644 index a51d634c..00000000 Binary files a/16/modex16/q.pcx and /dev/null differ diff --git a/16/modex16/test.c b/16/modex16/test.c new file mode 100644 index 00000000..2d261b04 --- /dev/null +++ b/16/modex16/test.c @@ -0,0 +1,76 @@ +#include "modex16.h" +#include + +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +void main() { + int i, j; + word start, end; + page_t page, page2; + float elapsed; + byte *pal, *pal2=NULL; + + /* load our palette */ + modexLoadPalFile("gfx.pal", &pal2); + + /* save the palette */ + pal = modexNewPal(); + modexPalSave(pal); + modexFadeOff(1, pal); + modexPalBlack(); + + modexEnter(); + 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); + + /* fade in */ + modexFadeOn(1, pal2); + + + start = *clock; + for(i=0; i<5; i++) { + /* 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); + } + } + + end = *clock; + + /* fade back to text mode */ + modexFadeOff(1, pal2); + modexPalBlack(); + modexLeave(); + modexPalBlack(); + modexFadeOn(1, pal); +} diff --git a/16/modex16/test.exe b/16/modex16/test.exe new file mode 100644 index 00000000..58538eb4 Binary files /dev/null and b/16/modex16/test.exe differ diff --git a/16/modex16/test.txt b/16/modex16/test.txt new file mode 100644 index 00000000..05adc9ec --- /dev/null +++ b/16/modex16/test.txt @@ -0,0 +1,258 @@ +64 x 64 Pixels + +0 0 0 +20 0 0 +0 20 0 +20 20 0 +0 0 20 +20 0 20 +0 20 20 +30 30 30 +30 37 30 +29 32 3c +3f 3f 33 +3f 3f 26 +3f 3f 19 +3f 3f c +3f 33 3f +3f 33 33 +3f 33 26 +3f 33 19 +3f 33 c +3f 33 0 +3f 26 3f +3f 26 33 +3f 26 26 +3f 26 19 +3f 26 c +3f 26 0 +3f 19 3f +3f 19 33 +3f 19 26 +3f 19 19 +3f 19 c +3f 19 0 +3f c 3f +3f c 33 +3f c 26 +3f c 19 +3f c c +3f c 0 +3f 0 33 +3f 0 26 +3f 0 19 +3f 0 c +33 3f 3f +33 3f 33 +33 3f 26 +33 3f 19 +33 3f c +33 3f 0 +33 33 3f +33 33 33 +33 33 26 +33 33 19 +33 33 c +33 33 0 +33 26 3f +33 26 33 +33 26 26 +33 26 19 +33 26 c +33 26 0 +33 19 3f +33 19 33 +33 19 26 +33 19 19 +33 19 c +33 19 0 +33 c 3f +33 c 33 +33 c 26 +33 c 19 +33 c c +33 c 0 +33 0 3f +33 0 33 +33 0 26 +33 0 19 +33 0 c +33 0 0 +26 3f 3f +26 3f 33 +26 3f 26 +26 3f 19 +26 3f c +26 3f 0 +26 33 3f +26 33 33 +26 33 26 +26 33 19 +26 33 c +26 33 0 +26 26 3f +26 26 33 +26 26 26 +26 26 19 +26 26 c +26 26 0 +26 19 3f +26 19 33 +26 19 26 +26 19 19 +26 19 c +26 19 0 +26 c 3f +26 c 33 +26 c 26 +26 c 19 +26 c c +26 c 0 +26 0 3f +26 0 33 +26 0 26 +26 0 19 +26 0 c +26 0 0 +19 3f 3f +19 3f 33 +19 3f 26 +19 3f 19 +19 3f c +19 3f 0 +19 33 3f +19 33 33 +19 33 26 +19 33 19 +19 33 c +19 33 0 +19 26 3f +19 26 33 +19 26 26 +19 26 19 +19 26 c +19 26 0 +19 19 3f +19 19 33 +19 19 26 +19 19 19 +19 19 c +19 19 0 +19 c 3f +19 c 33 +19 c 26 +19 c 19 +19 c c +19 c 0 +19 0 3f +19 0 33 +19 0 26 +19 0 19 +19 0 c +19 0 0 +c 3f 3f +c 3f 33 +c 3f 26 +c 3f 19 +c 3f c +c 3f 0 +c 33 3f +c 33 33 +c 33 26 +c 33 19 +c 33 c +c 33 0 +c 26 3f +c 26 33 +c 26 26 +c 26 19 +c 26 c +c 26 0 +c 19 3f +c 19 33 +c 19 26 +c 19 19 +c 19 c +c 19 0 +c c 3f +c c 33 +c c 26 +c c 19 +c c c +c c 0 +c 0 3f +c 0 33 +c 0 26 +c 0 19 +c 0 c +c 0 0 +0 3f 33 +0 3f 26 +0 3f 19 +0 3f c +0 33 3f +0 33 33 +0 33 26 +0 33 19 +0 33 c +0 33 0 +0 26 3f +0 26 33 +0 26 26 +0 26 19 +0 26 c +0 26 0 +0 19 3f +0 19 33 +0 19 26 +0 19 19 +0 19 c +0 19 0 +0 c 3f +0 c 33 +0 c 26 +0 c 19 +0 c c +0 c 0 +0 0 33 +0 0 26 +0 0 19 +0 0 c +20 3f 3f +10 20 20 +20 3f 0 +10 10 0 +3f 3f 20 +3f 20 0 +3f 20 20 +20 10 0 +20 0 3f +20 0 10 +10 20 3f +0 10 20 +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 +3f 3e 3c +28 28 29 +20 20 20 +3f 0 0 +0 3f 0 +3f 3f 0 +0 0 3f +3f 0 3f +0 3f 3f +3f 3f 3f \ No newline at end of file diff --git a/16/modex16/test2.c b/16/modex16/test2.c new file mode 100644 index 00000000..19f05e09 --- /dev/null +++ b/16/modex16/test2.c @@ -0,0 +1,22 @@ +#include "modex16.h" + +word far* clock= (word far*) 0x046C; /* 18.2hz clock */ + +void main() { + int i; + word start; + float t1, t2; + page_t page; + + page=modexDefaultPage(); + + modexEnter(); + start = *clock; + for(i=0; i<500; i++) { + modexShowPage(&page); + } + t1 = (*clock - start)/18.2; + modexLeave(); + + printf("Time: %f\n", t1); +} diff --git a/16/modex16/test2.exe b/16/modex16/test2.exe new file mode 100644 index 00000000..8b364604 Binary files /dev/null and b/16/modex16/test2.exe differ diff --git a/16/modex16/types.h b/16/modex16/types.h new file mode 100644 index 00000000..039653f2 --- /dev/null +++ b/16/modex16/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/modex16/w.pcx b/16/modex16/w.pcx deleted file mode 100644 index ad808796..00000000 Binary files a/16/modex16/w.pcx and /dev/null differ diff --git a/16/w_modex/M.BAT b/16/w_modex/M.BAT index a5d88f5d..5bcb63a5 100644 --- a/16/w_modex/M.BAT +++ b/16/w_modex/M.BAT @@ -1,3 +1,2 @@ -wcl /0 test modex xprim xpal xblitbuf -rem fixed32 +wcl386 test modex xprim xpal xblitbuf fixed32 erase *.obj diff --git a/16/w_modex/TEST.CPP b/16/w_modex/TEST.CPP index 2e357b4d..63d1c46d 100644 --- a/16/w_modex/TEST.CPP +++ b/16/w_modex/TEST.CPP @@ -5,7 +5,7 @@ #include #include -//#include "fixed32.hpp" +#include "fixed32.hpp" #include "modex.hpp" #include "xprim.hpp" #include "xpal.hpp" @@ -326,7 +326,7 @@ main(void) unsigned char pal[768]; COORD x1, y1, x2, y2; Iangle theta1, theta2; - //----Fixed32 trigSin, trigCos; + Fixed32 trigSin, trigCos; blitbuf blit_image, sprite_image; clock_t begin, end; short int x, y, temp, done; @@ -535,7 +535,7 @@ main(void) aligned_bitblitX(84, 36, &sprite_image); getch(); - //----initFixed32(); + initFixed32(); theta1=0; count=0; diff --git a/16/w_modex/TEST.EXE b/16/w_modex/TEST.EXE index ce4555c1..903a5a1e 100644 Binary files a/16/w_modex/TEST.EXE and b/16/w_modex/TEST.EXE differ