]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/modex16.c
palette utilities made ^^
[16.git] / src / lib / modex16.c
index eaf9966c805f047ddb35804d6967d2161d086277..cb5102c8077c32d55f79c065f1bcb896cc386dbb 100755 (executable)
@@ -83,6 +83,7 @@ modexEnter() {
         0xea10,         /* v sync start */\r
         0xac11,         /* v sync end and protect cr0-cr7 */\r
         0xdf12,         /* vertical displayed */\r
+//             0x2013,         /* offset/logical width */\r
         0x0014,         /* turn off dword mode */\r
         0xe715,         /* v blank start */\r
         0x0616,         /* v blank end */\r
@@ -139,7 +140,9 @@ modexDefaultPage() {
     page.dy = 0;\r
     page.width = SCREEN_WIDTH;\r
     page.height = SCREEN_HEIGHT;\r
-        page.id = 0;\r
+       page.tw = page.width/TILEWH;\r
+       page.th = page.height/TILEWH;\r
+       page.id = 0;\r
 \r
     return page;\r
 }\r
@@ -151,30 +154,35 @@ page_t
 modexNextPage(page_t *p) {\r
     page_t result;\r
 \r
-    result.data = p->data + (p->width/4)*p->height;  /* compute the offset */\r
+    result.data = p->data + (p->width/4)*p->height;\r
     result.dx = 0;\r
     result.dy = 0;\r
     result.width = p->width;\r
     result.height = p->height;\r
-        result.id = p->id+1;\r
+       result.tw = p->width/TILEWH;\r
+       result.th = p->height/TILEWH;\r
+       result.id = p->id+1;\r
 \r
-    return result;\r
+       return result;\r
+//     return modexNextPageFlexibleSize(&p, p->width, p->height);\r
 }\r
 \r
 //next page with defined dimentions~\r
 page_t\r
-modexNextPage0(page_t *p, word x, word y)\r
+modexNextPageFlexibleSize(page_t *p, word x, word y)\r
 {\r
-        page_t result;\r
-\r
-        result.data = p->data + (p->width/4)*p->height;  /* compute the offset */\r
-        result.dx = 0;\r
-        result.dy = 0;\r
-        result.width = x;\r
-        result.height = y;\r
-        result.id = p->id+1;\r
-\r
-    return result;\r
+       page_t result;\r
+\r
+       result.data = p->data + (p->width/4)*p->height;  /* compute the offset */\r
+       result.dx = 0;\r
+       result.dy = 0;\r
+       result.width = x;\r
+       result.height = y;\r
+       result.tw = p->width/TILEWH;\r
+       result.th = p->height/TILEWH;\r
+       result.id = p->id+1;\r
+\r
+       return result;\r
 }\r
 \r
 \r
@@ -399,6 +407,72 @@ modexDrawBmpRegion(page_t *page, int x, int y,
     }\r
 }\r
 \r
+void\r
+modex_sparky4_DrawBmpRegion(page_t *page, int x, int y,\r
+                   int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
+    word poffset = (word) page->data  + y*(page->width/4) + x/4;\r
+    byte far *data = bmp->data;//+bmp->offset;\r
+    word bmpOffset = (word) data + ry * bmp->width + rx;\r
+    word width = rw;\r
+    word height = rh;\r
+    byte plane = 1 << ((byte) x & 0x03);\r
+    word scanCount = width/4 + (width%4 ? 1 :0);\r
+    word nextPageRow = page->width/4 - scanCount;\r
+    word nextBmpRow = (word) bmp->width - width;\r
+    word rowCounter;\r
+    byte planeCounter = 4;\r
+\r
+/*     printf("bmp->data=%Fp\n",bmp->data);\r
+       printf("*bmp->data=%Fp\n",*(bmp->data));\r
+       printf("&bmp->data=%Fp\n",&(bmp->data));*/\r
+\r
+        //code is a bit slow here\r
+    __asm {\r
+                MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+                MOV ES, AX\r
+\r
+                MOV DX, SC_INDEX        ; point at the map mask register\r
+                MOV AL, MAP_MASK        ;\r
+                OUT DX, AL              ;\r
+\r
+        PLANE_LOOP:\r
+                MOV DX, SC_DATA         ; select the current plane\r
+                MOV AL, plane           ;\r
+                OUT DX, AL              ;\r
+\r
+                ;-- begin plane painting\r
+                MOV AX, height          ; start the row counter\r
+                MOV rowCounter, AX      ;\r
+                MOV DI, poffset         ; go to the first pixel\r
+                MOV SI, bmpOffset       ; go to the bmp pixel\r
+        ROW_LOOP:\r
+                MOV CX, width           ; count the columns\r
+        SCAN_LOOP:\r
+                MOVSB                   ; copy the pixel\r
+                SUB CX, 3               ; we skip the next 3\r
+                ADD SI, 3               ; skip the bmp pixels\r
+                LOOP SCAN_LOOP          ; finish the scan\r
+\r
+                MOV AX, nextPageRow\r
+                ADD DI, AX              ; go to the next row on screen\r
+                MOV AX, nextBmpRow\r
+                ADD SI, AX              ; go to the next row on bmp\r
+\r
+                DEC rowCounter\r
+                JNZ ROW_LOOP            ; do all the rows\r
+                ;-- end plane painting\r
+\r
+                MOV AL, plane           ; advance to the next plane\r
+                SHL AL, 1               ;\r
+                AND AL, 0x0f            ; mask the plane properly\r
+                MOV plane, AL           ; store the plane\r
+\r
+                INC bmpOffset           ; start bmp at the right spot\r
+\r
+                DEC planeCounter\r
+                JNZ PLANE_LOOP          ; do all 4 planes\r
+    }\r
+}\r
 \r
 void\r
 modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) {\r