static void\r
vgaSetMode(byte mode)\r
{\r
- union REGS regs;\r
-\r
- regs.h.ah = SET_MODE;\r
- regs.h.al = mode;\r
- int86(VIDEO_INT, ®s, ®s);\r
+ int10_setmode(mode);\r
}\r
\r
//---------------------------------------------------\r
// Use the bios to get the current video mode\r
//\r
\r
-long\r
+byte/*FIXME: why long? "long" is 32-bit datatype, VGA modes are 8-bit numbers. */\r
vgaGetMode()\r
{\r
- union REGS rg;\r
-\r
- rg.h.ah = 0x0f;\r
- int86(VIDEO_INT, &rg, &rg);\r
-\r
- return rg.h.al;\r
+ return int10_getmode();\r
}\r
\r
/* -========================= Entry Points ==========================- */\r
void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)\r
{\r
word i;\r
- dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */\r
+ struct vga_mode_params cm;\r
int CRTParmCount;\r
- /* common mode X initiation stuff~ */\r
- modexsetBaseXMode();\r
+\r
+ vgaSetMode(VGA_256_COLOR_MODE);\r
+ vga_enable_256color_modex();\r
+ update_state_from_vga();\r
+ vga_read_crtc_mode(&cm);\r
\r
switch(vq)\r
{\r
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
-\r
- /* send the CRTParms */\r
- /*for(i=0; i<CRTParmCount; i++) {\r
- outpw(CRTC_INDEX, ModeX_320x240regs[i]);\r
- }*/\r
- {\r
- struct vga_mode_params cm;\r
- vga_read_crtc_mode(&cm);\r
-\r
-// 0x5f00, /* Horizontal total */\r
-// 0x4f01, /* horizontal display enable end */\r
-// 0x5002, /* Start horizontal blanking */\r
-// 0x8203, /* End horizontal blanking */\r
-// 0x5404, /* Start horizontal retrace */\r
-// 0x8005, /* End horizontal retrace */\r
-// 0x0d06, /* vertical total */\r
-// 0x3e07, /* overflow (bit 8 of vertical counts) */\r
-// 0x4109, /* cell height (2 to double-scan */\r
-// 0xea10, /* v sync start */\r
-// 0xac11, /* v sync end and protect cr0-cr7 */\r
-// 0xdf12, /* vertical displayed */\r
-// 0x2813, /* offset/logical width */\r
-// 0x0014, /* turn off dword mode */\r
-// 0xe715, /* v blank start */\r
-// 0x0616, /* v blank end */\r
-// 0xe317 /* turn on byte mode */\r
-\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
+ /* virtual width and height. match screen, at first */\r
+ gv->video.page[0].height = gv->video.page[0].sh;\r
+ gv->video.page[0].width = gv->video.page[0].sw;\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
cm.clock_select = 0; /* misc register = 0xE3 25MHz */\r
cm.vsync_neg = 1;\r
cm.hsync_neg = 1;\r
-\r
- vga_write_crtc_mode(&cm,0);\r
- }\r
- break;\r
- case 2:\r
- CRTParmCount = sizeof(ModeX_160x120regs) / sizeof(ModeX_160x120regs[0]);\r
- /* width and height */\r
- gv->video.page[0].sw=120;\r
- gv->video.page[0].sh=160;\r
-\r
- /* send the CRTParms */\r
- for(i=0; i<CRTParmCount; i++) {\r
- outpw(CRTC_INDEX, ModeX_160x120regs[i]);\r
- }\r
- break;\r
- case 3:\r
- CRTParmCount = sizeof(ModeX_320x200regs) / sizeof(ModeX_320x200regs[0]);\r
- /* width and height */\r
- gv->video.page[0].sw=320;\r
- gv->video.page[0].sh=200;\r
-\r
- /* send the CRTParms */\r
- for(i=0; i<CRTParmCount; i++) {\r
- outpw(CRTC_INDEX, ModeX_320x200regs[i]);\r
- }\r
- break;\r
- case 4:\r
- CRTParmCount = sizeof(ModeX_192x144regs) / sizeof(ModeX_192x144regs[0]);\r
- /* width and height */\r
- gv->video.page[0].sw=192;\r
- gv->video.page[0].sh=144;\r
-\r
- /* send the CRTParms */\r
- for(i=0; i<CRTParmCount; i++) {\r
- outpw(CRTC_INDEX, ModeX_192x144regs[i]);\r
- }\r
- break;\r
- case 5:\r
- CRTParmCount = sizeof(ModeX_256x192regs) / sizeof(ModeX_256x192regs[0]);\r
- /* width and height */\r
- gv->video.page[0].sw=256;\r
- gv->video.page[0].sh=192;\r
-\r
- /* send the CRTParms */\r
- for(i=0; i<CRTParmCount; i++) {\r
- outpw(CRTC_INDEX, ModeX_256x192regs[i]);\r
- }\r
- break;\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
+ case 3: // TODO: 160x120 according to ModeX_320x200regs\r
+ return;\r
+ case 4: // TODO: 160x120 according to ModeX_192x144regs\r
+ return;\r
+ case 5: // TODO: 160x120 according to ModeX_256x192regs\r
+ return;\r
+ default:\r
+ 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
- gv->video.page[0].tilesh = gv->video.page[0].sh/TILEWH;\r
+\r
+// gv->video.page[0].tw = gv->video.page[0].sw/TILEWH;\r
+// gv->video.page[0].th = gv->video.page[0].sh/TILEWH;\r
+\r
//TODO MAKE FLEXIBLE~\r
- gv->video.page[0].tilemidposscreenx = gv->video.page[0].tilesw;\r
- gv->video.page[0].tilemidposscreeny = (gv->video.page[0].tilesh/2)+1;\r
- #define PAGE_SIZE (word)(gv->video.page[0].sw/4 * gv->video.page[0].sh)\r
+// gv->video.page[0].tilemidposscreenx = gv->video.page[0].tilesw;\r
+// gv->video.page[0].tilemidposscreeny = (gv->video.page[0].tilesh/2)+1;\r
}\r
\r
void\r
modexLeave() {\r
- /* TODO restore original mode and palette */\r
+ /* VGAmodeX restores original mode and palette */\r
vgaSetMode(TEXT_MODE);\r
}\r
\r
-// setBaseXMode() does the initialization to make the VGA ready to\r
-// accept any combination of configuration register settings. This\r
-// involves enabling writes to index 0 to 7 of the CRT controller (port\r
-// 0x3D4), by clearing the most significant bit (bit 7) of index 0x11.\r
-void\r
-modexsetBaseXMode()\r
-{\r
- /* TODO save current video mode and palette */\r
- vgaSetMode(VGA_256_COLOR_MODE);\r
- vga_enable_256color_modex();\r
- update_state_from_vga();\r
-}\r
-\r
page_t\r
modexDefaultPage(page_t *p)\r
{\r
page_t page;\r
\r
/* default page values */\r
- page.data = VGA;\r
+ //page.data = VGA;\r
+ //page.data = (byte far *)(vga_state.vga_graphics_ram);\r
+ page.data = (vga_state.vga_graphics_ram);\r
page.dx = 0;\r
page.dy = 0;\r
page.sw = p->sw;\r
page.sh = p->sh;\r
- page.width = p->sw;\r
- page.height = p->sh;\r
+ page.width = p->sw+TILEWHD;\r
+ page.height = p->sh+TILEWHD;\r
page.tw = page.sw/TILEWH;\r
page.th = page.sh/TILEWH;\r
+ page.tilesw=page.width/TILEWH;\r
+ page.tilesh=page.height/TILEWH;\r
page.tilemidposscreenx = page.tw/2;\r
page.tilemidposscreeny = (page.th/2)+1;\r
- page.tilesw=p->tilesw;\r
- page.tilesh=p->tilesh;\r
- //pageSize = p->sw*p->sh;\r
+ page.pagesize = (sdiword)(page.width/4)*page.height;\r
page.id = 0;\r
\r
return page;\r
modexNextPage(page_t *p) {\r
page_t result;\r
\r
- result.data = p->data + (p->width/4)*p->height;\r
+ result.data = p->data + (p->pagesize);\r
result.dx = 0;\r
result.dy = 0;\r
result.width = p->width;\r
result.height = p->height;\r
- result.tw = p->width/TILEWH;\r
- result.th = p->height/TILEWH;\r
+ result.tw = p->tw;\r
+ result.th = p->th;\r
+ result.tilesw = p->tilesw;\r
+ result.tilesh = p->tilesh;\r
result.id = p->id+1;\r
+ result.pagesize = p->pagesize;\r
\r
return result;\r
-// return modexNextPageFlexibleSize(&p, p->width, p->height);\r
}\r
\r
//next page with defined dimentions~\r
{\r
page_t result;\r
\r
- result.data = p->data + (p->width/4)*p->height; /* compute the offset */\r
+ result.data = p->data + (p->pagesize); /* 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.tw = result.sw/TILEWH;\r
+ result.th = result.sh/TILEWH;\r
+ result.tilesw=result.width/TILEWH;\r
+ result.tilesh=result.height/TILEWH;\r
result.id = p->id+1;\r
+ result.pagesize = (sdiword)(result.width/4)*result.height;\r
\r
return result;\r
}\r
\r
+void modexCalcVmemRemain(video_t *video)\r
+{\r
+ byte i;\r
+ //printf("\n\n 1st vmem_remain=%ld\n", video->vmem_remain);\r
+ for(i=0; i<=video->num_of_pages-1; i++)\r
+ {\r
+ video->vmem_remain-=video->page[i].pagesize;\r
+ //printf(" [%u], video->page[i].pagesize=%ld\n", i, video->page[i].pagesize);\r
+ //printf(" [%u], vmem_remain=%ld\n", i, video->vmem_remain);\r
+ }\r
+}\r
+\r
+void modexHiganbanaPageSetup(video_t *video)\r
+{\r
+ video->vmem_remain=262144L;\r
+ video->num_of_pages=0;\r
+ (video->page[0]) = modexDefaultPage(&(video->page[0])); video->num_of_pages++;\r
+ //video->page[0].width += (TILEWHD); video->page[0].height += (TILEWHD);\r
+ (video->page[1]) = modexNextPage(&(video->page[0])); video->num_of_pages++;\r
+ //(video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), video->page[0].width, video->page[0].sh-40); video->num_of_pages++;\r
+ //(video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), TILEWH, TILEWH); video->num_of_pages++;\r
+ modexCalcVmemRemain(video);\r
+ video->p=0;\r
+}\r
\r
void\r
modexShowPage(page_t *page) {\r
outp(AC_INDEX, (page->dx & 0x03) << 1);\r
}\r
\r
-\r
void\r
modexPanPage(page_t *page, int dx, int dy) {\r
page->dx = dx;\r
page->dy = dy;\r
}\r
\r
-\r
void\r
modexSelectPlane(byte plane) {\r
outp(SC_INDEX, MAP_MASK); /* select plane */\r
outp(SC_DATA, plane);\r
}\r
\r
-\r
void\r
modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) {\r
word pageOff = (word) page->data;\r
}\r
\r
__asm {\r
+ PUSHF\r
+ PUSH ES\r
+ PUSH AX\r
+ PUSH BX\r
+ PUSH CX\r
+ PUSH DX\r
+ PUSH SI\r
+ PUSH DI\r
MOV AX, SCREEN_SEG ; go to the VGA memory\r
MOV ES, AX\r
MOV DI, poffset ; go to the first pixel\r
ADD DI, nextRow ; go to the next row\r
DEC h\r
JNZ SCAN_START\r
+ POP DI\r
+ POP SI\r
+ POP DX\r
+ POP CX\r
+ POP BX\r
+ POP AX\r
+ POP ES\r
+ POPF\r
}\r
}\r
\r
{\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 scans = vga_state.vga_stride;\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
static word a[PAL_SIZE]; //palette array of change values!\r
word z=0, aq=0, aa=0, pp=0;\r
\r
- modexWaitBorder();\r
+ //modexWaitBorder();\r
+ vga_wait_for_vsync();\r
if((*i)==0)\r
{\r
memset(a, -1, sizeof(a));\r
//if(qp>0) printf("qp=%d\n", qp);\r
//if(qp>0) printf(" (*i)=%d\n", (*i)/3);\r
}\r
- modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ //modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ vga_wait_for_vsync();\r
if((*i)>=PAL_SIZE/2 && w==0)\r
{\r
for(; (*i)<PAL_SIZE; (*i)++)\r
pp = q;\r
//printf("1(*i)=%02d\n", (*i)/3);\r
//printf("1z=%02d\n", z/3);\r
- chkcolor(bmp, &q, &a, &aa, &z, i);\r
+ modexchkcolor(bmp, &q, &a, &aa, &z, i);\r
//printf("2(*i)=%02d\n", (*i)/3);\r
//printf("2z=%02d\n", z/3);\r
aq=0;\r
modexPalUpdate1(byte *p)\r
{\r
int i;\r
- modexWaitBorder();\r
+ //modexWaitBorder();\r
+ vga_wait_for_vsync();\r
outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */\r
for(i=0; i<PAL_SIZE/2; i++)\r
{\r
outp(PAL_DATA_REG, p[i]);\r
}\r
- modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ //modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ vga_wait_for_vsync();\r
for(; i<PAL_SIZE; i++)\r
{\r
outp(PAL_DATA_REG, p[(i)]);\r
modexPalUpdate0(byte *p)\r
{\r
int i;\r
- modexWaitBorder();\r
+ //modexWaitBorder();\r
+ vga_wait_for_vsync();\r
outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */\r
for(i=0; i<PAL_SIZE/2; i++)\r
{\r
outp(PAL_DATA_REG, rand());\r
}\r
- modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ //modexWaitBorder(); /* waits one retrace -- less flicker */\r
+ vga_wait_for_vsync();\r
for(; i<PAL_SIZE; i++)\r
{\r
outp(PAL_DATA_REG, rand());\r
void\r
modexPalOverscan(byte *p, word col)\r
{\r
- modexWaitBorder();\r
+ //modexWaitBorder();\r
+ vga_wait_for_vsync();\r
outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */\r
outp(PAL_DATA_REG, col);\r
}\r
\r
//color checker~\r
//i want to make another vesion that checks the palette when the palette is being appened~\r
-void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/)\r
+void modexchkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/)\r
{\r
byte *pal;\r
word zz=0;\r
\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
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+(w*c))/*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
}\r
\r
/* palette dump on display! */\r
-void pdump(page_t *pee)\r
+void modexpdump(page_t *pee)\r
{\r
int mult=(QUADWH);\r
int palq=(mult)*TILEWH;\r
// the Virtual screen. //\r
// //\r
/////////////////////////////////////////////////////////////////////////////\r
-void cls(page_t *page, byte color, byte *Where)\r
+void modexcls(page_t *page, byte color, byte *Where)\r
{\r
//modexClearRegion(page, 0, 0, page->width, page->height, color);\r
/* set map mask to all 4 planes */\r
void\r
modexWaitBorder() {\r
while(inp(INPUT_STATUS_1) & 8) {\r
- /* spin */\r
+ // spin\r
}\r
\r
while(!(inp(INPUT_STATUS_1) & 8)) {\r
- /* spin */\r
+ // spin\r
}\r
}\r
+\r
+void bios_cls() {\r
+ VGA_ALPHA_PTR ap;\r
+ VGA_RAM_PTR rp;\r
+ unsigned char m;\r
+\r
+ m = int10_getmode();\r
+ if ((rp=vga_state.vga_graphics_ram) != NULL && !(m <= 3 || m == 7)) {\r
+ unsigned int i,im;\r
+\r
+ im = (FP_SEG(vga_state.vga_graphics_ram_fence) - FP_SEG(vga_state.vga_graphics_ram));\r
+ if (im > 0xFFE) im = 0xFFE;\r
+ im <<= 4;\r
+ for (i=0;i < im;i++) vga_state.vga_graphics_ram[i] = 0;\r
+ }\r
+ else if ((ap=vga_state.vga_alpha_ram) != NULL) {\r
+ unsigned int i,im;\r
+\r
+ im = (FP_SEG(vga_state.vga_alpha_ram_fence) - FP_SEG(vga_state.vga_alpha_ram));\r
+ if (im > 0x7FE) im = 0x7FE;\r
+ im <<= 4 - 1; /* because ptr is type uint16_t */\r
+ for (i=0;i < im;i++) vga_state.vga_alpha_ram[i] = 0x0720;\r
+ }\r
+ else {\r
+ printf("WARNING: bios cls no ptr\n");\r
+ }\r
+}\r