]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/modex16.c
replace inline asm with _fmemcpy to copy ROM font char.
[16.git] / src / lib / modex16.c
index b748ba9619fb8238f2dd590160ec640a507dbcd3..20c468e2372a2750bd37b33a977ce93b26eecd9c 100755 (executable)
@@ -80,7 +80,6 @@ vgaGetMode()
 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)\r
 {\r
        word i;\r
-       dword far*ptr=(dword far*)vga_state.vga_graphics_ram;//VGA;      /* used for faster screen clearing */\r
        struct vga_mode_params cm;\r
        int CRTParmCount;\r
 \r
@@ -94,9 +93,12 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
                case 1:\r
                        //CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]);\r
                        /* width and height */\r
-                       gv->video.page[0].sw=vga_state.vga_width = 320; // VGA lib currently does not update this\r
-                       gv->video.page[0].sh=vga_state.vga_height = 240; // VGA lib currently does not update this\r
+                       gv->video.page[0].sw = vga_state.vga_width = 320; // VGA lib currently does not update this\r
+                       gv->video.page[0].sh = vga_state.vga_height = 240; // VGA lib currently does not update this\r
 \r
+                       // mode X BYTE mode\r
+                       cm.word_mode = 0;\r
+                       cm.dword_mode = 0;\r
                        // 320x240 mode 60Hz\r
                        cm.horizontal_total=0x5f + 5; /* CRTC[0]             -5 */\r
                        cm.horizontal_display_end=0x4f + 1; /* CRTC[1]       -1 */\r
@@ -115,8 +117,7 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
                        cm.clock_select = 0; /* misc register = 0xE3  25MHz */\r
                        cm.vsync_neg = 1;\r
                        cm.hsync_neg = 1;\r
-                       vga_state.vga_stride=88;\r
-                       cm.offset=44;\r
+                       cm.offset = (vga_state.vga_width / (4 * 2)); // 320 wide (40 x 4 pixel groups x 2)\r
                        break;\r
                case 2: // TODO: 160x120 according to ModeX_160x120regs\r
                        return;\r
@@ -130,15 +131,18 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
                        return;\r
        }\r
 \r
+       vga_state.vga_stride = cm.offset * 2;\r
        vga_write_crtc_mode(&cm,0);\r
 \r
        /* clear video memory */\r
        switch (cmem)\r
        {\r
-               case 1:\r
-               /* clear video memory */\r
-               vga_write_sequencer(2/*map mask register*/,0xf/*all 4 planes*/);\r
-               for(i=0; i<0x8000; i++) ptr[i] = 0x0000;\r
+               case 1: {\r
+                       /* clear video memory */\r
+                       dword far*ptr=(dword far*)vga_state.vga_graphics_ram;//VGA;      /* used for faster screen clearing */\r
+                       vga_write_sequencer(2/*map mask register*/,0xf/*all 4 planes*/);\r
+                       for(i = 0;i < 0x4000; i++) ptr[i] = 0x0000; // 0x4000 x dword = 64KB\r
+               }\r
                break;\r
        }\r
        gv->video.page[0].tilesw = gv->video.page[0].sw/TILEWH;\r
@@ -873,23 +877,13 @@ byte modexgetPixel(page_t *page, int x, int y)
 \r
 }\r
 \r
-void modexhlin(page_t *page, word xl, word xh, word y, word color)\r
-{\r
-       word x;\r
-       word yy=0;\r
-\r
-       for(x=0;x<xh*4;x+=4)\r
-       {\r
-               if(x+4>=page[0].sw-1){ x=0; yy+=4; }\r
-               modexClearRegion(page, x+xl, y+yy, 4, 4, color);\r
-       }\r
-       //modexputPixel(page, x+xl, y, color);\r
-}\r
-\r
-void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str, boolean q)\r
+void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str)\r
 {\r
        word s, o, w;\r
+       word x_draw = x;\r
        word addr = (word) romFontsData.l;\r
+       word addrq = (page->width/4) * y + (x / 4) + ((word)page->data);\r
+       word addrr = addrq;\r
        byte c;\r
 \r
        s=romFonts[t].seg;\r
@@ -900,35 +894,23 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons
        for(; *str != '\0'; str++)\r
        {\r
        c = (*str);\r
-       if((c=='\n'/* || c=="\\r
-"*/) || romFontsData.chw\r
->=page->width)\r
+       if(c=='\n')\r
        {\r
-               romFontsData.chw=0;\r
-               y+=romFonts[t].charSize;\r
+               x = x_draw;\r
+               romFontsData.chw = 0;\r
+               addrq += (page->width / 4) * 8;\r
+               addrr = addrq;\r
+               y += 8;\r
                continue;\r
        }\r
-       //load the letter 'A'\r
-       __asm {\r
-               MOV DI, addr\r
-               MOV SI, o\r
-               MOV ES, s\r
-               SUB AH, AH\r
-               MOV AL, c       ; the letter\r
-               MOV CX, w\r
-               MUL CX\r
-               ADD SI, AX      ;the address of charcter\r
-       L1:     MOV AX, ES:SI\r
-               MOV DS:DI, AX\r
-               INC SI\r
-               INC DI\r
-               DEC CX\r
-               JNZ L1\r
-       }\r
-//TODO: OPTIMIZE THIS!!!!\r
-               modexDrawCharPBuf(page, x, y, t, col, bgcol, q);\r
 \r
-               //if(!q) getch();\r
+       // load the character into romFontsData.l\r
+       // no need for inline assembly!\r
+       // NTS: It might even be faster to just let the modexDrawChar point directly at ROM font than to copy per char! --J.C.\r
+               _fmemcpy(romFontsData.l,MK_FP(s,o)/*ROM font location*/,w/*char size*/);\r
+               modexDrawChar(page, x_draw/*for mode X planar use*/, t, col, bgcol, addrr);\r
+               x_draw += 8; /* track X for edge of screen */\r
+               addrr += 2; /* move 8 pixels over (2 x 4 planar pixels per byte) */\r
        }\r
 }\r
 \r
@@ -1037,7 +1019,7 @@ void modexcls(page_t *page, byte color, byte *Where)
        _fmemset(Where, color, page->width*(page->height)/4);\r
 }\r
 \r
-/*void\r
+void\r
 modexWaitBorder() {\r
     while(inp(INPUT_STATUS_1)  & 8)  {\r
        // spin\r
@@ -1046,7 +1028,7 @@ modexWaitBorder() {
     while(!(inp(INPUT_STATUS_1)  & 8))  {\r
        // spin\r
     }\r
-}*/\r
+}\r
 \r
 void bios_cls() {\r
        VGA_ALPHA_PTR ap;\r