X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=cab1376675720d225ca62f6d01f1204c020a5ce4;hb=cb4574433d1faa6a5345362d66211108f9aaaa3c;hp=8637d7111e4636f4c39a290bff2bd6838eda7b27;hpb=b85e69ad19bcc1ef45494d60b2ffd47fc2eeb4a3;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index 8637d711..cab13766 100755 --- a/src/lib/modex16.c +++ b/src/lib/modex16.c @@ -1,11 +1,11 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669 + * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 * * This file is part of Project 16. * * Project 16 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or + * the Free Software Foundation; either verson 3 of the License, or * (at your option) any later version. * * Project 16 is distributed in the hope that it will be useful, @@ -35,7 +35,7 @@ static byte tmppal[PAL_SIZE]; // setvideo() - This function Manages the video modes // // // ///////////////////////////////////////////////////////////////////////////// -void VGAmodeX(sword vq, global_game_variables_t *gv) +void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv) { union REGS in, out; @@ -54,7 +54,7 @@ void VGAmodeX(sword vq, global_game_variables_t *gv) //int86(0x10, &in, &out); gv->video.old_mode = vgaGetMode();//out.h.al; // enter mode - modexEnter(vq, gv); + modexEnter(vq, cmem, gv); break; } } @@ -62,11 +62,7 @@ void VGAmodeX(sword vq, global_game_variables_t *gv) static void vgaSetMode(byte mode) { - union REGS regs; - - regs.h.ah = SET_MODE; - regs.h.al = mode; - int86(VIDEO_INT, ®s, ®s); + int10_setmode(mode); } //--------------------------------------------------- @@ -74,113 +70,79 @@ vgaSetMode(byte mode) // Use the bios to get the current video mode // -long +byte/*FIXME: why long? "long" is 32-bit datatype, VGA modes are 8-bit numbers. */ vgaGetMode() { - union REGS rg; - - rg.h.ah = 0x0f; - int86(VIDEO_INT, &rg, &rg); - - return rg.h.al; + return int10_getmode(); } /* -========================= Entry Points ==========================- */ -void -modexEnter(sword vq, global_game_variables_t *gv) +void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv) { word i; - dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ + struct vga_mode_params cm; int CRTParmCount; - /* common mode X initiation stuff~ */ - modexsetBaseXMode(gv->video.page); + + vgaSetMode(VGA_256_COLOR_MODE); + vga_enable_256color_modex(); + update_state_from_vga(); + vga_read_crtc_mode(&cm); switch(vq) { case 1: - CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]); - /* width and height */ - gv->video.page[0].sw=320; - gv->video.page[0].sh=240; - - /* send the CRTParms */ - for(i=0; ivideo.page[0].sw=120; - gv->video.page[0].sh=160; - - /* send the CRTParms */ - for(i=0; ivideo.page[0].sw=320; - gv->video.page[0].sh=200; - - /* send the CRTParms */ - for(i=0; ivideo.page[0].sw=192; - gv->video.page[0].sh=144; - - /* send the CRTParms */ - for(i=0; ivideo.page[0].sw=256; - gv->video.page[0].sh=192; + gv->video.page[0].sw = vga_state.vga_width = 320; // VGA lib currently does not update this + gv->video.page[0].sh = vga_state.vga_height = 240; // VGA lib currently does not update this + + // mode X BYTE mode + cm.word_mode = 0; + cm.dword_mode = 0; + // 320x240 mode 60Hz + cm.horizontal_total=0x5f + 5; /* CRTC[0] -5 */ + cm.horizontal_display_end=0x4f + 1; /* CRTC[1] -1 */ + cm.horizontal_blank_start=0x50 + 1; /* CRTC[2] */ + cm.horizontal_blank_end=0x82 + 1; /* CRTC[3] bit 0-4 & CRTC[5] bit 7 */ + cm.horizontal_start_retrace=0x54;/* CRTC[4] */ + cm.horizontal_end_retrace=0x80; /* CRTC[5] bit 0-4 */ + //cm.horizontal_start_delay_after_total=0x3e; /* CRTC[3] bit 5-6 */ + //cm.horizontal_start_delay_after_retrace=0x41; /* CRTC[5] bit 5-6 */ + cm.vertical_total = 0x20D + 2; + cm.vertical_start_retrace = 0x1EA; + cm.vertical_end_retrace = 0x1EC; + cm.vertical_display_end = 480; + cm.vertical_blank_start = 0x1E7 + 1; + cm.vertical_blank_end = 0x206 + 1; + cm.clock_select = 0; /* misc register = 0xE3 25MHz */ + cm.vsync_neg = 1; + cm.hsync_neg = 1; + cm.offset = (vga_state.vga_width / (4 * 2)); // 320 wide (40 x 4 pixel groups x 2) + break; + case 2: // TODO: 160x120 according to ModeX_160x120regs + return; + case 3: // TODO: 160x120 according to ModeX_320x200regs + return; + case 4: // TODO: 160x120 according to ModeX_192x144regs + return; + case 5: // TODO: 160x120 according to ModeX_256x192regs + return; + default: + return; + } - /* send the CRTParms */ - for(i=0; ivideo.page[0].tilesw = gv->video.page[0].sw/TILEWH; @@ -193,39 +155,8 @@ modexEnter(sword vq, global_game_variables_t *gv) void modexLeave() { - /* TODO restore original mode and palette */ - vgaSetMode(TEXT_MODE); -} - -// setBaseXMode() does the initialization to make the VGA ready to -// accept any combination of configuration register settings. This -// involves enabling writes to index 0 to 7 of the CRT controller (port -// 0x3D4), by clearing the most significant bit (bit 7) of index 0x11. -void -modexsetBaseXMode(page_t *page) -{ - word temp; - /* 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 */ -// temp = inp(CRTC_DATA) & 0x7F; -// outp(CRTC_INDEX, 0x11); - outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ -// outp(CRTC_DATA, temp); /* get current write protect on varios regs */ + /* TODO restore original mode and palette */ + vgaSetMode(TEXT_MODE); } page_t @@ -234,7 +165,7 @@ modexDefaultPage(page_t *p) page_t page; /* default page values */ - page.data = VGA; + page.data = vga_state.vga_graphics_ram;//VGA; page.dx = 0; page.dy = 0; page.sw = p->sw; @@ -620,7 +551,8 @@ modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset) static word a[PAL_SIZE]; //palette array of change values! word z=0, aq=0, aa=0, pp=0; - modexWaitBorder(); + //modexWaitBorder(); + vga_wait_for_vsync(); if((*i)==0) { memset(a, -1, sizeof(a)); @@ -670,7 +602,8 @@ modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqoffset) //if(qp>0) printf("qp=%d\n", qp); //if(qp>0) printf(" (*i)=%d\n", (*i)/3); } - modexWaitBorder(); /* waits one retrace -- less flicker */ + //modexWaitBorder(); /* waits one retrace -- less flicker */ + vga_wait_for_vsync(); if((*i)>=PAL_SIZE/2 && w==0) { for(; (*i)=page[0].sw-1){ x=0; yy+=4; } - modexClearRegion(page, x+xl, y+yy, 4, 4, color); - } - //modexputPixel(page, x+xl, y, color); -} - -void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str, boolean q) -{ - word i, s, o, w, j, k, xp; - byte l[1024]; - word addr = (word) l; - word chw=0; + word s, o, w; + word addr = (word) romFontsData.l; + word addrq = (page->width/4) * y + (x / 4) + ((word)page->data); byte c; - byte z[10]; - //byte near *bakapee; - - switch(t) - { - case 0: - w=14; - break; - case 1: - w=8; - break; - case 2: - w=8; - break; - case 3: - w=16; - break; - default: - t=3; - w=16; - break; - } s=romFonts[t].seg; o=romFonts[t].off; + w=romFonts[t].charSize; + romFontsData.chw=0; for(; *str != '\0'; str++) { c = (*str); if((c=='\n'/* || c=="\ -"*/) || chw +"*/) || romFontsData.chw >=page->width) { - chw=0; - y+=w; + romFontsData.chw=0; + y+=romFonts[t].charSize; continue; } //load the letter 'A' @@ -1013,44 +917,12 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons DEC CX JNZ L1 } - //bakapee = _nmalloc(sizeof(byte)*8); //TODO: OPTIMIZE THIS!!!! - for(i=0; idata + (((page->width/4) * (y+page->dy+i)) + ((x+page->dx+chw) / 4)), bakapee, 8);*/ - j=1<<8; - k=0; - xp=0; - //every "pixel" row - while(j) - { - if(q) - //_fmemcpy(page->data + (((page->width/4) * (y)) + ((x) / 4)), l[i] & j ? col:bgcol, 8); - modexputPixel(page, x+xp+chw, y+i, l[i] & j ? col:bgcol); - else - //printf("l[i]=%c j=%02u l[i] & j=%02u %c\n", l[i] , j, l[i] & j, l[i] & j ? '*':' '); - //printf("%c", l[i] & j ? '*':' '); - z[k]=l[i] & j ? '*':' '; - xp++; - j>>=1; - k++; - } - if(!q) - { - for(k=0;k<10;k++) - { - printf("%c", z[k]); - } - printf("\n"); - } - } - if(!q) getch(); - chw += xp; + modexDrawCharPBuf(page, x/*for mode X planar use*/, y/*redunant, remove*/, t, col, bgcol, addrq); + addrq += 2; /* move 8 pixels over (2 x 4 planar pixels per byte) */ + + //if(!q) getch(); } - //_nfree(bakapee); } void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str) @@ -1129,7 +1001,7 @@ void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, c } /* palette dump on display! */ -void pdump(page_t *pee) +void modexpdump(page_t *pee) { int mult=(QUADWH); int palq=(mult)*TILEWH; @@ -1149,22 +1021,49 @@ void pdump(page_t *pee) // the Virtual screen. // // // ///////////////////////////////////////////////////////////////////////////// -void cls(page_t *page, byte color, byte *Where) +void modexcls(page_t *page, byte color, byte *Where) { //modexClearRegion(page, 0, 0, page->width, page->height, color); /* set map mask to all 4 planes */ outpw(SC_INDEX, 0xff02); //_fmemset(VGA, color, 16000); - _fmemset(Where, color, page->width*(page->height)); + _fmemset(Where, color, page->width*(page->height)/4); } -void +/*void modexWaitBorder() { while(inp(INPUT_STATUS_1) & 8) { - /* spin */ + // spin } while(!(inp(INPUT_STATUS_1) & 8)) { - /* spin */ + // spin } +}*/ + +void bios_cls() { + VGA_ALPHA_PTR ap; + VGA_RAM_PTR rp; + unsigned char m; + + m = int10_getmode(); + if ((rp=vga_state.vga_graphics_ram) != NULL && !(m <= 3 || m == 7)) { + unsigned int i,im; + + im = (FP_SEG(vga_state.vga_graphics_ram_fence) - FP_SEG(vga_state.vga_graphics_ram)); + if (im > 0xFFE) im = 0xFFE; + im <<= 4; + for (i=0;i < im;i++) vga_state.vga_graphics_ram[i] = 0; + } + else if ((ap=vga_state.vga_alpha_ram) != NULL) { + unsigned int i,im; + + im = (FP_SEG(vga_state.vga_alpha_ram_fence) - FP_SEG(vga_state.vga_alpha_ram)); + if (im > 0x7FE) im = 0x7FE; + im <<= 4 - 1; /* because ptr is type uint16_t */ + for (i=0;i < im;i++) vga_state.vga_alpha_ram[i] = 0x0720; + } + else { + printf("WARNING: bios cls no ptr\n"); + } }