\r
static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette);\r
static byte tmppal[PAL_SIZE];\r
-static struct pcxHeader {\r
- byte id;\r
- byte version;\r
- byte encoding;\r
- byte bpp;\r
- word xmin;\r
- word ymin;\r
- word xmax;\r
- word ymax;\r
- word hres;\r
- word vres;\r
- byte pal16[48];\r
- byte res1;\r
- word bpplane;\r
- word palType;\r
- word hScreenSize;\r
- word vScreenSize;\r
- byte padding[54];\r
-};\r
-\r
\r
static void\r
vgaSetMode(byte mode)\r
}\r
\r
\r
+/* copy a region of video memory from one page to another.\r
+ * It assumes that the left edge of the tile is the same on both\r
+ * regions and the memory areas do not overlap.\r
+ */\r
void\r
-modexCopyPageRegion(page_t *dest, page_t src,\r
+modexCopyPageRegion(page_t *dest, page_t *src,\r
word sx, word sy,\r
word dx, word dy,\r
word width, word height)\r
{\r
- /* todo */\r
+ word doffset = (word)dest->data + dy*(dest->width/4) + dx/4;\r
+ word soffset = (word)src->data + sy*(src->width/4) + sx/4;\r
+ word scans = width/4;\r
+ word nextSrcRow = src->width/4 - scans - 1;\r
+ word nextDestRow = dest->width/4 - scans - 1;\r
+ byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */\r
+ byte rclip[] = {0x0f, 0x01, 0x03, 0x07};\r
+ byte left = lclip[sx&0x03];\r
+ byte right = rclip[(sx+width)&0x03];\r
+\r
+ __asm {\r
+ MOV AX, SCREEN_SEG ; work in the vga space\r
+ MOV ES, AX ;\r
+ MOV DI, doffset ;\r
+ MOV SI, soffset ;\r
+\r
+ MOV DX, GC_INDEX ; turn off cpu bits\r
+ MOV AX, 0008h ;\r
+ OUT DX, AX\r
+\r
+ MOV AX, SC_INDEX ; point to the mask register\r
+ MOV DX, AX ;\r
+ MOV AL, MAP_MASK ;\r
+ OUT DX, AL ;\r
+ INC DX ;\r
+\r
+ ROW_START:\r
+ PUSH DS\r
+ MOV AX, ES\r
+ MOV DS, AX\r
+ MOV CX, scans ; the number of latches\r
+\r
+ MOV AL, left ; do the left column\r
+ OUT DX, AL ;\r
+ MOVSB ;\r
+ DEC CX ;\r
+\r
+ MOV AL, 0fh ; do the inner columns\r
+ OUT DX, AL\r
+ REP MOVSB ; copy the pixels\r
+\r
+ MOV AL, right ; do the right column\r
+ OUT DX, AL\r
+ MOVSB\r
+ POP DS\r
+\r
+ MOV AX, SI ; go the start of the next row\r
+ ADD AX, nextSrcRow ;\r
+ MOV SI, AX ;\r
+ MOV AX, DI ;\r
+ ADD AX, nextDestRow ;\r
+ MOV DI, AX ;\r
+\r
+ DEC height ; do the rest of the actions\r
+ JNZ ROW_START ;\r
+\r
+ MOV DX, GC_INDEX+1 ; go back to CPU data\r
+ MOV AL, 0ffh ; none from latches\r
+ OUT DX, AL ;\r
+ }\r
}\r
\r
\r
/* spin */\r
}\r
}\r
-\r
-\r
-bitmap_t\r
-modexLoadPcx(char *filename) {\r
- FILE *file;\r
- bitmap_t result;\r
- struct pcxHeader head;\r
- long bufSize;\r
- int index;\r
- byte count, val;\r
-\r
- /* open the PCX file for reading */\r
- file = fopen(filename, "rb");\r
- if(!file) {\r
- printf("Could not open %s for reading.\n", filename);\r
- exit(-2);\r
- }\r
-\r
- /* read the header */\r
- fread(&head, sizeof(char), sizeof(struct pcxHeader), file);\r
-\r
- /* make sure this is 8bpp */\r
- if(head.bpp != 8) {\r
- printf("I only know how to handle 8bpp pcx files!\n");\r
- fclose(file);\r
- exit(-2);\r
- }\r
-\r
- /* allocate the buffer */\r
- result.width = head.xmax - head.xmin + 1;\r
- result.height = head.ymax - head.ymin + 1;\r
- bufSize = result.width * result.height;\r
- result.data = malloc(bufSize);\r
- if(!result.data) {\r
- printf("Could not allocate memory for bitmap data.");\r
- fclose(file);\r
- exit(-1);\r
- }\r
-\r
- /* read the buffer in */\r
- index = 0;\r
- do {\r
- /* get the run length and the value */\r
- count = fgetc(file);\r
- if(0xC0 == (count & 0xC0)) { /* this is the run count */\r
- count &= 0x3f;\r
- val = fgetc(file);\r
- } else {\r
- val = count;\r
- count = 1;\r
- }\r
-\r
- /* write the pixel the specified number of times */\r
- for(; count && index < bufSize; count--,index++) {\r
- result.data[index] = val;\r
- }\r
- } while(index < bufSize);\r
-\r
- /* handle the palette */\r
- fseek(file, -769, SEEK_END);\r
- val = fgetc(file);\r
- result.palette = modexNewPal();\r
- if(head.version == 5 && val == 12) {\r
- /* use the vga palette */\r
- for(index=0; !feof(file) && index < PAL_SIZE; index++) {\r
- val = fgetc(file);\r
- result.palette[index] = val >> 2;\r
- }\r
- } else {\r
- /* use the 16 color palette */\r
- for(index=0; index<48; index++) {\r
- result.palette[index] = head.pal16[index];\r
- }\r
- }\r
-\r
- fclose(file);\r
-\r
- return result;\r
-}\r