X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=b8f733be22b581f1748cffffa04e1f60e988b3be;hb=70fe32e01a3eeac5230aa562ab9b8062c6f3d30d;hp=429d5fb60fb374af9f8b75f56c6280baaf58bdb8;hpb=afc76a02fbb1d134aee4cedee173a61d3aea0b0f;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index 429d5fb6..b8f733be 100755 --- a/src/lib/modex16.c +++ b/src/lib/modex16.c @@ -1,11 +1,11 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 + * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * * 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 verson 3 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Project 16 is distributed in the hope that it will be useful, @@ -119,7 +119,7 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv) 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 *///skewing ^^; +// cm.horizontal_blank_end=0x82 + 1; /* CRTC[3] bit 0-4 & CRTC[5] bit 7 *///skewing ^^; 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 */ @@ -198,7 +198,8 @@ modexDefaultPage(page_t *p) page.tilemidposscreenx = page.tw/2; page.tilemidposscreeny = (page.th/2)+1; page.stridew=page.width/4; - page.pagesize = (word)(page.width/4)*page.height; + page.pagesize = (word)(page.stridew)*page.height; + page.pi=page.width*4; page.id = 0; return page; @@ -222,9 +223,10 @@ modexNextPage(page_t *p) { result.th = p->th; result.tilesw = p->tilesw; result.tilesh = p->tilesh; - result.id = p->id+1; result.stridew=p->stridew; result.pagesize = p->pagesize; + result.pi=result.width*4; + result.id = p->id+1; return result; } @@ -247,8 +249,17 @@ modexNextPageFlexibleSize(page_t *p, word x, word y) result.tilesw=result.width/TILEWH; result.tilesh=result.height/TILEWH; result.id = p->id+1; - result.stridew=result.width/4; - result.pagesize = (word)(result.width/4)*result.height; + result.stridew=p->sw/4;//result.width/4; + result.pagesize = (word)(result.stridew)*result.height; + switch(result.id) + { + case 2: + result.pi=p->width*4; + break; + case 3: + result.pi=p->pi; + break; + } return result; } @@ -271,7 +282,10 @@ void modexHiganbanaPageSetup(video_t *video) video->num_of_pages=0; (video->page[0]) = modexDefaultPage(&(video->page[0])); video->num_of_pages++; //video->page[0].width += (TILEWHD); video->page[0].height += (TILEWHD); (video->page[1]) = modexNextPage(&(video->page[0])); video->num_of_pages++; +//0000 (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), (video->page[0]).width, TILEWH*4); video->num_of_pages++; +//0000 (video->page[3]) = (video->page[2]); video->num_of_pages++; (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), TILEWH*4, TILEWH*4); video->num_of_pages++; +// (video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), video->page[0].width, 176); video->num_of_pages++; (video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), video->page[0].sw, 208); video->num_of_pages++; // (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), video->page[0].width, 172); video->num_of_pages++; // (video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), 72, 128); video->num_of_pages++; @@ -299,14 +313,14 @@ modexShowPage(page_t *page) { low_address = LOW_ADDRESS | (offset << 8); /* wait for appropriate timing and then program CRTC */ - while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); + //while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); outpw(CRTC_INDEX, high_address); outpw(CRTC_INDEX, low_address); outp(CRTC_INDEX, 0x13); outp(CRTC_DATA, crtcOffset); /* wait for one retrace */ - while (!(inp(INPUT_STATUS_1) & VRETRACE)); + //while (!(inp(INPUT_STATUS_1) & VRETRACE)); /* do PEL panning here */ outp(AC_INDEX, 0x33); @@ -342,6 +356,8 @@ modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) { right=0x0f; } + //printf("modexClearRegion(x=%u, y=%u, w=%u, h=%u, left=%u, right=%u)\n", x, y, w, h, left, right); + __asm { PUSHF PUSH ES @@ -409,14 +425,21 @@ modexCopyPageRegion(page_t *dest, page_t *src, { word doffset = (word)dest->data + dy*(dest->stridew) + dx/4; word soffset = (word)src->data + sy*(src->stridew) + sx/4; - word scans = vga_state.vga_stride; + word scans = vga_state.vga_stride; //++++0000 the quick and dirty fix of the major issue with p16 video display wwww word nextSrcRow = src->stridew - scans - 1; word nextDestRow = dest->stridew - scans - 1; byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08}; /* clips for rectangles not on 4s */ - byte rclip[] = {0x0f, 0x01, 0x03, 0x07}; + byte rclip[] = {0x00, 0x01, 0x03, 0x07}; byte left = lclip[sx&0x03]; byte right = rclip[(sx+width)&0x03]; + /* handle the case which requires an extra group */ + if((sx & 0x03) && !((sx+width) & 0x03)) { + right=0x0f; + } + +// printf("modexCopyPageRegion(src->stridew=%u, dest->stridew=%u, sx=%u, sy=%u, dx=%u, dy=%u, width=%u, height=%u, left=%u, right=%u)\n", src->stridew, dest->stridew, sx, sy, dx, dy, width, height, left, right); + __asm { PUSHF PUSH ES @@ -1136,33 +1159,6 @@ modexWaitBorder() { } } -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"); - } -} - void modexprintmeminfo(video_t *v) { byte i; @@ -1172,136 +1168,10 @@ void modexprintmeminfo(video_t *v) { printf(" [%u]=", i); printf("(%Fp)", (v->page[i].data)); - printf(" size=%u", v->page[i].pagesize); - printf(" sw=%lu sh=%lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh); - printf(" width=%lu height=%lu", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height); + printf(" size=%u ", v->page[i].pagesize); + printf("w=%lu h=%lu ", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height); + printf("sw=%lu sh=%lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh); + printf("pi=%u", v->page[i].pi); printf("\n"); } } - -void update_state_from_vga_() { - unsigned char c; - - vga_state.vga_pos_x = 0; - vga_state.vga_pos_y = 0; - vga_state.vga_stride = 80; - vga_state.vga_height = 25; - vga_state.vga_width = 80; - vga_state.vga_9wide = 0; - - if (vga_state.vga_flags & VGA_IS_VGA) { /* VGA only. EGA cards DO have the misc. output reg but it's write-only */ - /* update state from H/W which I/O port */ - c = inp(0x3CC); - if (c & 1) { - vga_state.vga_base_3x0 = 0x3D0; - } - else { - vga_state.vga_base_3x0 = 0x3B0; - } - - /* now ask the graphics controller where/how VGA memory is mapped */ - c = vga_read_GC(6); - /* bit 0 = alpha disable (if set, graphics) */ - vga_state.vga_alpha_mode = ((c & 1) == 0); - /* bits 2-3 memory map select */ - update_state_vga_memory_map_select((c>>2)&3); - - /* read the sequencer: are we in 8 or 9 dot mode? */ - c = vga_read_sequencer(0x1); - vga_state.vga_9wide = (c & 1) == 0; - - /* read from the CRTC controller the stride, width, and height */ - vga_state.vga_stride = vga_read_CRTC(0x13) * 2; /* "offset" register */ - if (vga_state.vga_alpha_mode) { - vga_state.vga_width = vga_state.vga_stride; - vga_sync_hw_cursor(); - /* TODO: read vertical blank values and calculate active area, then divide by scan line height, to get alpha height */ - /* TODO: read horizontal blank values to calculate active area, then visible width */ - } - else { - /* TODO: similar semantics for graphics mode */ - } - } - else if (vga_state.vga_flags & VGA_IS_EGA) { - /* Well the EGA has similar registers BUT they aren't readable. So we have to - * guess based on other information handed to us */ - - /* reading the misc. output register doesn't work, use BIOS data area */ - c = *((unsigned char far*)MK_FP(0x40,0x63)); - if ((c&0xF0) == 0xD0) - vga_state.vga_base_3x0 = 0x3D0; - else if ((c&0xF0) == 0xB0) - vga_state.vga_base_3x0 = 0x3B0; - else { - vga_state.vga_base_3x0 = 0x3D0; - } - - /* reading from the graphics controller (0x3CE) doesn't work, deduce from BIOS mode */ - c = int10_getmode(); - switch (c) { - case 0: case 1: case 2: case 3: case 7: - vga_state.vga_alpha_mode = 1; - - /* the best we can do is assume B0000 if CRTC is at 3Bx or B8000 if at 3Dx even though it's possible to map at B8000 and 3Bx */ - if (vga_state.vga_base_3x0 == 0x3B0) - update_state_vga_memory_map_select(2); - else - update_state_vga_memory_map_select(3); - break; - case 4: case 5: case 6: - vga_state.vga_alpha_mode = 0; - update_state_vga_memory_map_select(3); - break; - case 13: case 14: case 15: case 16: case 17: case 18: default: - vga_state.vga_alpha_mode = 0; - update_state_vga_memory_map_select(1); - break; - } - - /* read from the CRTC controller the stride, width, and height */ - vga_state.vga_stride = vga_read_CRTC(0x13) * 2; /* "offset" register */ - if (vga_state.vga_alpha_mode) { - vga_state.vga_width = vga_state.vga_stride; - vga_sync_hw_cursor(); - /* TODO: read vertical blank values and calculate active area, then divide by scan line height, to get alpha height */ - /* TODO: read horizontal blank values to calculate active area, then visible width */ - } - else { - /* TODO: similar semantics for graphics mode */ - } - } - else if (vga_state.vga_flags & VGA_IS_CGA) { - vga_state.vga_base_3x0 = 0x3D0; /* always at 0x3Dx */ - - /* TODO: If Tandy, detect state */ - - /* read the status register to determine the state of the CGA... oh wait... we can't. - * fine. deduce it from the BIOS video mode. */ - c = int10_getmode(); - switch (c) { - case 0: case 1: case 2: case 3: case 7: - vga_state.vga_alpha_mode = 1; - break; - default: - vga_state.vga_alpha_mode = 0; - break; - } - - if (c <= 1) { - vga_state.vga_stride = 40; - vga_state.vga_width = 40; - } - - update_state_vga_memory_map_select(3); /* 0xB8000 */ - } - else if (vga_state.vga_flags & VGA_IS_MDA) { - vga_state.vga_base_3x0 = 0x3B0; /* always at 0x3Bx */ - vga_state.vga_alpha_mode = 1; /* stock MDA doesn't have graphics */ - - /* Hercules MDA: It would be nice to be able to read bit 2 of the display control, - * except that the port is write-only. Thanks >:( */ - update_state_vga_memory_map_select(2); /* 0xB0000 */ - } - - vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride; -}