From 70cfb9d79f2c8b4722e4961cd8fed23c9f3dc98f Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 4 Dec 2019 07:20:58 +0100 Subject: [PATCH 1/3] Various (S)VGA and Cirrus Logic fixes. --- src/video/vid_cl54xx.c | 78 +++----- src/video/vid_svga.c | 422 +++++++++++++++++------------------------ src/video/vid_svga.h | 11 +- 3 files changed, 205 insertions(+), 306 deletions(-) diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index 7ae3fd431..615e3cf5b 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -9,7 +9,7 @@ * Emulation of select Cirrus Logic cards (CL-GD 5428, * CL-GD 5429, CL-GD 5430, CL-GD 5434 and CL-GD 5436 are supported). * - * Version: @(#)vid_cl_54xx.c 1.0.30 2019/09/30 + * Version: @(#)vid_cl_54xx.c 1.0.31 2019/12/03 * * Authors: TheCollector1995, * Miran Grca, @@ -338,28 +338,6 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) if (svga->crtc[0x27] < CIRRUS_ID_CLGD5429) gd54xx->unlocked = (svga->seqregs[6] == 0x12); break; - - case 0x0a: - if (gd54xx_is_5434(svga)) - svga->seqregs[0x0a] = val; - else { /* Hack to force memory size on some GD-542x BIOSes*/ - val &= 0xe7; - switch (gd54xx->vram_size) { - case 0x80000: - svga->seqregs[0x0a] = val | 0x08; - break; - - case 0x100000: - svga->seqregs[0x0a] = val | 0x10; - break; - - case 0x200000: - svga->seqregs[0x0a] = val | 0x18; - break; - } - } - break; - case 0x0b: case 0x0c: case 0x0d: case 0x0e: /* VCLK stuff */ gd54xx->vclk_n[svga->seqaddr-0x0b] = val; break; @@ -400,26 +378,6 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) else svga->hwcursor.addr = ((gd54xx->vram_size - 0x4000) + ((val & 0x3f) * 256)); break; - case 0x15: - if (gd54xx_is_5434(svga)) { - /* Hack to force memory size on some GD-543x BIOSes*/ - val &= 0xf8; - switch (gd54xx->vram_size) { - case 0x100000: - svga->seqregs[0x15] = val | 0x2; - break; - - case 0x200000: - svga->seqregs[0x15] = val | 0x3; - break; - - case 0x400000: - svga->seqregs[0x15] = val | 0x4; - break; - } - } else - return; - break; case 0x07: if (gd54xx_is_5422(svga)) gd543x_recalc_mapping(gd54xx); @@ -448,7 +406,11 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) } gd54xx->ramdac.state = 0; break; + case 0x3c7: case 0x3c8: + gd54xx->ramdac.state = 0; + break; case 0x3c9: + gd54xx->ramdac.state = 0; svga->dac_status = 0; svga->fullchange = changeframecount; switch (svga->dac_pos) { @@ -540,16 +502,18 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) } else { switch (svga->gdcaddr) { case 0x09: case 0x0a: case 0x0b: - gd54xx_recalc_banking(gd54xx); if (svga->gdcreg[0xb] & 0x04) svga->writemode = svga->gdcreg[5] & 7; else svga->writemode = svga->gdcreg[5] & 3; - svga->adv_flags = FLAG_EXTRA_BANKS; + svga->adv_flags = 0; + if (svga->gdcreg[0xb] & 0x01) + svga->adv_flags = FLAG_EXTRA_BANKS; if (svga->gdcreg[0xb] & 0x02) svga->adv_flags |= FLAG_ADDR_BY8; if (svga->gdcreg[0xb] & 0x08) svga->adv_flags |= FLAG_LATCH8; + gd54xx_recalc_banking(gd54xx); break; case 0x10: @@ -751,14 +715,24 @@ gd54xx_in(uint16_t addr, void *p) if (!gd54xx->unlocked) ret = svga_in(addr, svga); else if (gd54xx->ramdac.state == 4) { - gd54xx->ramdac.state = 0; + /* CL-GD 5428 does not lock the register when it's read. */ + if (svga->crtc[0x27] != CIRRUS_ID_CLGD5428) + gd54xx->ramdac.state = 0; ret = gd54xx->ramdac.ctrl; } else { gd54xx->ramdac.state++; - ret = svga_in(addr, svga); + if (gd54xx->ramdac.state == 4) + ret = gd54xx->ramdac.ctrl; + else + ret = svga_in(addr, svga); } break; + case 0x3c7: case 0x3c8: + gd54xx->ramdac.state = 0; + ret = svga_in(addr, svga); + break; case 0x3c9: + gd54xx->ramdac.state = 0; svga->dac_status = 3; index = (svga->dac_addr - 1) & 0xff; if (svga->seqregs[0x12] & 2) @@ -918,7 +892,7 @@ gd54xx_in(uint16_t addr, void *p) else switch (svga->crtcreg) { case 0x22: /*Graphis Data Latches Readback Register*/ /*Should this be & 7 if 8 byte latch is enabled? */ - ret = (svga->latch >> ((svga->gdcreg[4] & 3) << 3)) & 0xff; + ret = svga->latch.b[svga->gdcreg[4] & 3]; break; case 0x24: /*Attribute controller toggle readback (R)*/ ret = svga->attrff << 7; @@ -972,6 +946,8 @@ gd54xx_recalc_banking(gd54xx_t *gd54xx) } else svga->extra_banks[1] = svga->extra_banks[0] + 0x8000; } + + svga->write_bank = svga->read_bank = svga->extra_banks[0]; } @@ -1163,10 +1139,7 @@ gd54xx_recalctimings(svga_t *svga) svga->clock = (cpuclock * (double)(1ull << 32)) / freq; } - if (gd54xx->vram_size == (1 << 19)) /* Note : why 512Kb VRAM cards do not wrap */ - svga->vram_display_mask = gd54xx->vram_mask; - else - svga->vram_display_mask = (svga->crtc[0x1b] & 2) ? gd54xx->vram_mask : 0x3ffff; + svga->vram_display_mask = (svga->crtc[0x1b] & 2) ? gd54xx->vram_mask : 0x3ffff; } @@ -3094,7 +3067,6 @@ static void gd54xx->pci_regs[0x33] = 0x00; svga->crtc[0x27] = id; - svga->adv_flags = FLAG_EXTRA_BANKS; svga->seqregs[6] = 0x0f; if (svga->crtc[0x27] >= CIRRUS_ID_CLGD5429) diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index d2f7e45a3..5de05c59e 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -11,7 +11,7 @@ * This is intended to be used by another SVGA driver, * and not as a card in it's own right. * - * Version: @(#)vid_svga.c 1.0.38 2019/11/19 + * Version: @(#)vid_svga.c 1.0.39 2019/12/03 * * Authors: Sarah Walker, * Miran Grca, @@ -45,13 +45,6 @@ extern uint8_t edatlookup[4][4]; uint8_t svga_rotate[8][256]; -static const uint64_t mask16[16] = { - 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, - 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, - 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, - 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff -}; - /*Primary SVGA device. As multiple video cards are not yet supported this is the only SVGA device.*/ static svga_t *svga_pri; @@ -345,16 +338,16 @@ svga_in(uint16_t addr, void *p) /* The spec says GDC addresses 0xF8 to 0xFB return the latch. */ switch(svga->gdcaddr) { case 0xf8: - ret = (svga->latch & 0xFF); + ret = svga->latch.b[0]; break; case 0xf9: - ret = ((svga->latch & 0xFF00) >> 8); + ret = svga->latch.b[1]; break; case 0xfa: - ret = ((svga->latch & 0xFF0000) >> 16); + ret = svga->latch.b[2]; break; case 0xfb: - ret = ((svga->latch & 0xFF000000) >> 24); + ret = svga->latch.b[3]; break; default: ret = svga->gdcreg[svga->gdcaddr & 0xf]; @@ -896,14 +889,57 @@ svga_close(svga_t *svga) } +static uint32_t +svga_decode_addr(svga_t *svga, uint32_t addr, int write) +{ + int memory_map_mode = (svga->gdcreg[6] >> 2) & 3; + + addr &= 0x1ffff; + + switch (memory_map_mode) { + case 0: + break; + case 1: + if (addr >= 0x10000) + return 0xffffffff; + break; + case 2: + addr -= 0x10000; + if (addr >= 0x8000) + return 0xffffffff; + break; + default: + case 3: + addr -= 0x18000; + if (addr >= 0x8000) + return 0xffffffff; + break; + } + + if (memory_map_mode <= 1) { + if (svga->adv_flags & FLAG_EXTRA_BANKS) + addr = (addr & 0x17fff) + svga->extra_banks[(addr >> 15) & 1]; + else { + if (write) + addr += svga->write_bank; + else + addr += svga->read_bank; + } + } + + return addr; +} + + void svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; - int func_select, writemask2 = svga->writemask; - int memory_map_mode; - uint64_t write_mask, bit_mask, set_mask, mask0, la, val32 = (uint64_t) val; + int writemask2 = svga->writemask, reset_wm = 0; + latch_t vall; + uint8_t wm = svga->writemask; + uint8_t count, i; if (svga->adv_flags & FLAG_ADDR_BY8) writemask2 = svga->seqregs[2]; @@ -913,33 +949,10 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) sub_cycles(video_timing_write_b); if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; + addr = svga_decode_addr(svga, addr, 1); - addr &= 0x1ffff; - - switch (memory_map_mode) { - case 0: - break; - case 1: - if (addr >= 0x10000) - return; - else if (svga->adv_flags & FLAG_EXTRA_BANKS) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr += svga->write_bank; - break; - case 2: - addr -= 0x10000; - if (addr >= 0x8000) - return; - break; - default: - case 3: - addr -= 0x18000; - if (addr >= 0x8000) - return; - break; - } + if (addr == 0xffffffff) + return; } if (!(svga->gdcreg[6] & 1)) @@ -968,142 +981,93 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) svga->changedvram[addr >> 12] = changeframecount; - /* standard VGA latched access */ - func_select = (svga->gdcreg[3] >> 3) & 3; + count = 4; + if (svga->adv_flags & FLAG_LATCH8) + count = 8; switch (svga->writemode) { case 0: - /* rotate */ - if (svga->gdcreg[3] & 7) - val32 = svga_rotate[svga->gdcreg[3] & 7][val32]; - - /* apply set/reset mask */ - bit_mask = svga->gdcreg[8]; - - val32 |= (val32 << 8); - val32 |= (val32 << 16); - if (svga->adv_flags & FLAG_ADDR_BY8) - val32 |= (val32 << 32); - - if (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && - (!svga->gdcreg[1] || svga->set_reset_disabled)) { - /* mask data according to sr[2] */ - write_mask = mask16[writemask2 & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) { - write_mask |= (mask16[(writemask2 & 0xf0) >> 4] << 32); - addr >>= 3; - - ((uint64_t *)(svga->vram))[addr] &= ~write_mask; - ((uint64_t *)(svga->vram))[addr] |= (val32 & write_mask); - } else { - addr >>= 2; - - ((uint32_t *)(svga->vram))[addr] &= ~write_mask; - ((uint32_t *)(svga->vram))[addr] |= (val32 & write_mask); + if (svga->gdcreg[3] & 7) + val = svga_rotate[svga->gdcreg[3] & 7][val]; + if ((svga->gdcreg[8] == 0xff) && !(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) { + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = val; } return; + } else { + for (i = 0; i < count; i++) { + if (svga->gdcreg[1] & (1 << i)) + vall.b[i] = !!(svga->gdcreg[0] & (1 << i)) * 0xff; + else + vall.b[i] = val; + } } - - set_mask = mask16[svga->gdcreg[1] & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) - set_mask |= (mask16[(svga->gdcreg[1] & 0xf0) >> 4] << 32); - - mask0 = mask16[svga->gdcreg[0] & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) - mask0 |= (mask16[(svga->gdcreg[0] & 0xf0) >> 4] << 32); - - val32 = (val32 & ~set_mask) | (mask0 & set_mask); break; case 1: - val32 = svga->latch; - - /* mask data according to sr[2] */ - write_mask = mask16[writemask2 & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) { - write_mask |= (mask16[(writemask2 & 0xf0) >> 4] << 32); - addr >>= 3; - - ((uint64_t *)(svga->vram))[addr] &= ~write_mask; - ((uint64_t *)(svga->vram))[addr] |= (val32 & write_mask); - } else { - addr >>= 2; - - ((uint32_t *)(svga->vram))[addr] &= ~write_mask; - ((uint32_t *)(svga->vram))[addr] |= (val32 & write_mask); + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = svga->latch.b[i]; } return; case 2: - mask0 = mask16[val32 & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) - mask0 |= (mask16[(val32 & 0xf0) >> 4] << 32); - val32 = mask0; - bit_mask = svga->gdcreg[8]; + for (i = 0; i < count; i++) + vall.b[i] = !!(val & (1 << i)) * 0xff; - if (!(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) - func_select = 0; + if (!(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) { + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | (svga->latch.b[i] & ~svga->gdcreg[8]); + } + return; + } break; case 3: - /* rotate */ - if (svga->gdcreg[3] & 7) - val32 = svga_rotate[svga->gdcreg[3] & 7][val]; + if (svga->gdcreg[3] & 7) + val = svga_rotate[svga->gdcreg[3] & 7][val]; + wm = svga->gdcreg[8]; + svga->gdcreg[8] &= val; - bit_mask = svga->gdcreg[8] & val32; - val32 = mask16[svga->gdcreg[0] & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) - val32 |= (mask16[(svga->gdcreg[0] & 0xf0) >> 4] << 32); - break; + for (i = 0; i < count; i++) + vall.b[i] = !!(svga->gdcreg[0] & (1 << i)) * 0xff; + + reset_wm = 1; + break; default: if (svga->ven_write) svga->ven_write(svga, val, addr); return; } - /* apply bit mask */ - bit_mask |= bit_mask << 8; - bit_mask |= bit_mask << 16; - if (svga->adv_flags & FLAG_ADDR_BY8) - bit_mask |= bit_mask << 32; - - la = svga->latch; - if (!(svga->adv_flags & FLAG_LATCH8)) - la &= 0xffffffff; - - /* apply logical operation */ - switch(func_select) { - case 0: - default: - /* set */ - val32 &= bit_mask; - val32 |= (la & ~bit_mask); + switch (svga->gdcreg[3] & 0x18) { + case 0x00: /* Set */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | (svga->latch.b[i] & ~svga->gdcreg[8]); + } break; - case 1: - /* and */ - val32 |= ~bit_mask; - val32 &= la; + case 0x08: /* AND */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] | ~svga->gdcreg[8]) & svga->latch.b[i]; + } break; - case 2: - /* or */ - val32 &= bit_mask; - val32 |= la; + case 0x10: /* OR */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) | svga->latch.b[i]; + } break; - case 3: - /* xor */ - val32 &= bit_mask; - val32 ^= la; + case 0x18: /* XOR */ + for (i = 0; i < count; i++) { + if (writemask2 & (1 << i)) + svga->vram[addr | i] = (vall.b[i] & svga->gdcreg[8]) ^ svga->latch.b[i]; + } break; } - /* mask data according to sr[2] */ - write_mask = mask16[writemask2 & 0x0f]; - if (svga->adv_flags & FLAG_ADDR_BY8) - write_mask |= (mask16[(writemask2 & 0xf0) >> 4] << 32); - - addr >>= ((svga->adv_flags & FLAG_ADDR_BY8) ? 3 : 2); - - if (svga->adv_flags & FLAG_ADDR_BY8) - ((uint64_t *)(svga->vram))[addr] = (((uint64_t *)(svga->vram))[addr] & ~write_mask) | (val32 & write_mask); - else - ((uint32_t *)(svga->vram))[addr] = (((uint32_t *)(svga->vram))[addr] & ~write_mask) | (val32 & write_mask); + if (reset_wm) + svga->gdcreg[8] = wm; } @@ -1112,9 +1076,10 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; uint32_t latch_addr = 0; - int memory_map_mode, readplane = svga->readplane; - uint32_t mask0, mask1; - uint64_t ret; + int readplane = svga->readplane; + uint8_t count, i; + uint8_t plane, pixel; + uint8_t temp, ret; if (svga->adv_flags & FLAG_ADDR_BY8) readplane = svga->gdcreg[4] & 7; @@ -1124,40 +1089,19 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) egareads++; if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; + addr = svga_decode_addr(svga, addr, 0); - addr &= 0x1ffff; - - switch(memory_map_mode) { - case 0: - break; - case 1: - if (addr >= 0x10000) - return 0xff; - else if (svga->adv_flags & FLAG_EXTRA_BANKS) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr += svga->read_bank; - break; - case 2: - addr -= 0x10000; - if (addr >= 0x8000) - return 0xff; - break; - default: - case 3: - addr -= 0x18000; - if (addr >= 0x8000) - return 0xff; - break; - } - - if (svga->adv_flags & FLAG_ADDR_BY8) - latch_addr = (addr << 3) & svga->decode_mask; - else - latch_addr = (addr << 2) & svga->decode_mask; + if (addr == 0xffffffff) + return 0xff; } + count = 2; + if (svga->adv_flags & FLAG_LATCH8) + count = 3; + + latch_addr = (addr << count) & svga->decode_mask; + count = (1 << count); + if (svga->adv_flags & FLAG_ADDR_BY8) addr <<= 3; else if (svga->chain4 || svga->fb_only) { @@ -1169,12 +1113,6 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) readplane = (readplane & 2) | (addr & 1); addr &= ~1; addr <<= 2; - addr |= readplane; - addr &= svga->decode_mask; - if (addr >= svga->vram_max) - return 0xff; - addr &= svga->vram_mask; - return svga->vram[addr]; } else addr <<= 2; @@ -1187,28 +1125,17 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->vram_mask; - if (svga->adv_flags & FLAG_ADDR_BY8) { - if (svga->adv_flags & FLAG_LATCH8) - svga->latch = ((uint64_t *)(svga->vram))[addr >> 3]; - else - svga->latch = (svga->latch & 0xffffffff00000000ULL) | (((uint64_t *)(svga->vram))[addr >> 3] & 0xffffffff); - } else - svga->latch = (svga->latch & 0xffffffff00000000ULL) | ((uint32_t *)(svga->vram))[addr >> 2]; + for (i = 0; i < count; i++) + svga->latch.b[i] = svga->vram[addr | i]; } else { - if (latch_addr > svga->vram_max) - if (svga->adv_flags & FLAG_LATCH8) - svga->latch = 0xffffffffffffffffULL; - else - svga->latch = (svga->latch & 0xffffffff00000000ULL) | 0xffffffff; - else { + if (latch_addr >= svga->vram_max) { + for (i = 0; i < count; i++) + svga->latch.b[i] = 0xff; + } else { latch_addr &= svga->vram_mask; - if (svga->adv_flags & FLAG_ADDR_BY8) { - if (svga->adv_flags & FLAG_LATCH8) - svga->latch = ((uint64_t *)(svga->vram))[latch_addr >> 3]; - else - svga->latch = (svga->latch & 0xffffffff00000000ULL) | (((uint64_t *)(svga->vram))[latch_addr >> 3] & 0xffffffff); - } else - svga->latch = (svga->latch & 0xffffffff00000000ULL) | ((uint32_t *)(svga->vram))[latch_addr >> 2]; + + for (i = 0; i < count; i++) + svga->latch.b[i] = svga->vram[latch_addr | i]; } if (addr >= svga->vram_max) @@ -1217,23 +1144,24 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->vram_mask; } - if (!(svga->gdcreg[5] & 8)) { - /* read mode 0 */ - return (svga->latch >> (readplane * 8)) & 0xff; - } else { - /* read mode 1 */ - if (svga->adv_flags & FLAG_LATCH8) { - mask0 = mask16[svga->colourcompare & 0x0f] | (mask16[(svga->colourcompare & 0xf0) >> 4] << 32); - mask1 = mask16[svga->colournocare & 0x0f] | (mask16[(svga->colournocare & 0xf0) >> 4] << 32); - ret = (svga->latch ^ mask0) & mask1; - ret |= ret >> 32; - } else - ret = (svga->latch ^ mask16[svga->colourcompare & 0x0f]) & mask16[svga->colournocare & 0x0f]; - ret |= ret >> 16; - ret |= ret >> 8; - ret = (~ret) & 0xff; - return(ret); - } + if (svga->readmode) { + temp = 0xff; + + for (pixel = 0; pixel < 8; pixel++) { + for (plane = 0; plane < count; plane++) { + if (svga->colournocare & (1 << plane)) { + /* If we care about a plane, and the pixel has a mismatch on it, clear its bit. */ + if (((svga->latch.b[plane] >> pixel) & 1) != ((svga->colourcompare >> plane) & 1)) + temp &= ~(1 << pixel); + } + } + } + + ret = temp; + } else + ret = svga->vram[addr | readplane]; + + return ret; } @@ -1362,7 +1290,6 @@ void svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; - int memory_map_mode; if (!svga->fast) { svga_write_common(addr, val, linear, p); @@ -1375,11 +1302,10 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) sub_cycles(video_timing_write_w); if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; - if ((memory_map_mode == 1) && (svga->adv_flags & FLAG_EXTRA_BANKS)) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr = (addr & svga->banked_mask) + svga->write_bank; + addr = svga_decode_addr(svga, addr, 1); + + if (addr == 0xffffffff) + return; } addr &= svga->decode_mask; @@ -1410,7 +1336,6 @@ void svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; - int memory_map_mode; if (!svga->fast) { svga_write_common(addr, val, linear, p); @@ -1425,11 +1350,10 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) sub_cycles(video_timing_write_l); if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; - if ((memory_map_mode == 1) && (svga->adv_flags & FLAG_EXTRA_BANKS)) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr = (addr & svga->banked_mask) + svga->write_bank; + addr = svga_decode_addr(svga, addr, 1); + + if (addr == 0xffffffff) + return; } addr &= svga->decode_mask; @@ -1478,7 +1402,6 @@ uint16_t svga_readw_common(uint32_t addr, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; - int memory_map_mode; if (!svga->fast) return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8); @@ -1488,11 +1411,10 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) sub_cycles(video_timing_read_w); if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; - if ((memory_map_mode == 1) && (svga->adv_flags & FLAG_EXTRA_BANKS)) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr = (addr & svga->banked_mask) + svga->read_bank; + addr = svga_decode_addr(svga, addr, 0); + + if (addr == 0xffffffff) + return 0xffff; } addr &= svga->decode_mask; @@ -1521,7 +1443,6 @@ uint32_t svga_readl_common(uint32_t addr, uint8_t linear, void *p) { svga_t *svga = (svga_t *)p; - int memory_map_mode; if (!svga->fast) { return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8) | @@ -1533,11 +1454,10 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) sub_cycles(video_timing_read_l); if (!linear) { - memory_map_mode = (svga->gdcreg[6] >> 2) & 3; - if ((memory_map_mode == 1) && (svga->adv_flags & FLAG_EXTRA_BANKS)) - addr = (addr & 0x7fff) + svga->extra_banks[(addr >> 15) & 1]; - else - addr = (addr & svga->banked_mask) + svga->read_bank; + addr = svga_decode_addr(svga, addr, 0); + + if (addr == 0xffffffff) + return 0xffffffff; } addr &= svga->decode_mask; diff --git a/src/video/vid_svga.h b/src/video/vid_svga.h index e47a3dc2e..589039d3d 100644 --- a/src/video/vid_svga.h +++ b/src/video/vid_svga.h @@ -30,6 +30,13 @@ typedef struct { uint32_t addr, pitch; } hwcursor_t; +typedef union { + uint64_t q; + uint32_t d[2]; + uint16_t w[4]; + uint8_t b[8]; +} latch_t; + typedef struct svga_t { mem_mapping_t mapping; @@ -74,8 +81,8 @@ typedef struct svga_t PALETTE vgapal; - uint64_t latch, - dispontime, dispofftime; + uint64_t dispontime, dispofftime; + latch_t latch; pc_timer_t timer; From e121515458a1ac3b0fe4046355510368afa41581 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 4 Dec 2019 07:36:08 +0100 Subject: [PATCH 2/3] Fixed the Video 7 / HT-2xx code so that it compiles again. --- src/video/vid_ht216.c | 149 ++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 78 deletions(-) diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index c7b19dcc9..a0479a696 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -8,7 +8,7 @@ * * Video 7 VGA 1024i emulation. * - * Version: @(#)vid_ht216.c 1.0.2 2019/10/01 + * Version: @(#)vid_ht216.c 1.0.3 2019/12/04 * * Authors: Sarah Walker, * Miran Grca, @@ -168,16 +168,16 @@ ht216_out(uint16_t addr, uint8_t val, void *p) break; case 0xa0: - svga->latch = (svga->latch & 0xffffff00) | val; + svga->latch.b[0] = val; break; case 0xa1: - svga->latch = (svga->latch & 0xffff00ff) | (val << 8); + svga->latch.b[1] = val; break; case 0xa2: - svga->latch = (svga->latch & 0xff00ffff) | (val << 16); + svga->latch.b[2] = val; break; case 0xa3: - svga->latch = (svga->latch & 0x00ffffff) | (val << 24); + svga->latch.b[3] = val; break; case 0xa4: ht216->clk_sel = (val >> 2) & 0xf; @@ -305,20 +305,13 @@ ht216_in(uint16_t addr, void *p) case 0x8f: return (ht216->id >> 8) & 0xff; case 0xa0: - return svga->latch & 0xff; + return svga->latch.b[0]; case 0xa1: - return (svga->latch >> 8) & 0xff; + return svga->latch.b[1]; case 0xa2: - return (svga->latch >> 16) & 0xff; + return svga->latch.b[2]; case 0xa3: - return (svga->latch >> 24) & 0xff; - -#if 0 - case 0xf7: - return 0x01; - case 0xff: - return 0x80; -#endif + return svga->latch.b[3]; } return ht216->ht_regs[svga->seqaddr & 0xff]; } else @@ -537,10 +530,10 @@ ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_u switch (svga->writemode) { case 1: - if (writemask2 & 1) svga->vram[addr] = svga->latch & 0xff; - if (writemask2 & 2) svga->vram[addr | 0x1] = (svga->latch >> 8) & 0xff; - if (writemask2 & 4) svga->vram[addr | 0x2] = (svga->latch >> 16) & 0xff; - if (writemask2 & 8) svga->vram[addr | 0x3] = (svga->latch >> 24) & 0xff; + if (writemask2 & 1) svga->vram[addr] = svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = svga->latch.b[3]; break; case 0: if (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && @@ -561,38 +554,38 @@ ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_u switch (svga->gdcreg[3] & 0x18) { case 0: /*Set*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | ((svga->latch & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (((svga->latch >> 8) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (((svga->latch >> 16) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (((svga->latch >> 24) & 0xff) & ~svga->gdcreg[8]); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch.b[0] & ~svga->gdcreg[8]); + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (svga->latch.b[1] & ~svga->gdcreg[8]); + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (svga->latch.b[2] & ~svga->gdcreg[8]); + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (svga->latch.b[3] & ~svga->gdcreg[8]); break; case 8: /*AND*/ - if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & svga->latch.b[3]; break; case 0x10: /*OR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | svga->latch.b[3]; break; case 0x18: /*XOR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ svga->latch.b[3]; break; } } break; case 2: if (!(svga->gdcreg[3] & 0x18) && (!svga->gdcreg[1] || svga->set_reset_disabled)) { - if (writemask2 & 1) svga->vram[addr] = (((cpu_dat & 1) ? 0xff : 0) & svga->gdcreg[8]) | ((svga->latch & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 2) svga->vram[addr | 0x1] = (((cpu_dat & 2) ? 0xff : 0) & svga->gdcreg[8]) | (((svga->latch >> 8) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 4) svga->vram[addr | 0x2] = (((cpu_dat & 4) ? 0xff : 0) & svga->gdcreg[8]) | (((svga->latch >> 16) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 8) svga->vram[addr | 0x3] = (((cpu_dat & 8) ? 0xff : 0) & svga->gdcreg[8]) | (((svga->latch >> 24) & 0xff) & ~svga->gdcreg[8]); + if (writemask2 & 1) svga->vram[addr] = (((cpu_dat & 1) ? 0xff : 0) & svga->gdcreg[8]) | (svga->latch.b[0] & ~svga->gdcreg[8]); + if (writemask2 & 2) svga->vram[addr | 0x1] = (((cpu_dat & 2) ? 0xff : 0) & svga->gdcreg[8]) | (svga->latch.b[1] & ~svga->gdcreg[8]); + if (writemask2 & 4) svga->vram[addr | 0x2] = (((cpu_dat & 4) ? 0xff : 0) & svga->gdcreg[8]) | (svga->latch.b[2] & ~svga->gdcreg[8]); + if (writemask2 & 8) svga->vram[addr | 0x3] = (((cpu_dat & 8) ? 0xff : 0) & svga->gdcreg[8]) | (svga->latch.b[3] & ~svga->gdcreg[8]); } else { vala = ((cpu_dat & 1) ? 0xff : 0); valb = ((cpu_dat & 2) ? 0xff : 0); @@ -600,28 +593,28 @@ ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_u vald = ((cpu_dat & 8) ? 0xff : 0); switch (svga->gdcreg[3] & 0x18) { case 0: /*Set*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | ((svga->latch & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (((svga->latch >> 8) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (((svga->latch >> 16) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (((svga->latch >> 24) & 0xff) & ~svga->gdcreg[8]); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch.b[0] & ~svga->gdcreg[8]); + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (svga->latch.b[1] & ~svga->gdcreg[8]); + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (svga->latch.b[2] & ~svga->gdcreg[8]); + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (svga->latch.b[3] & ~svga->gdcreg[8]); break; case 8: /*AND*/ - if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & svga->latch.b[3]; break; case 0x10: /*OR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | svga->latch.b[3]; break; case 0x18: /*XOR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ svga->latch.b[3]; break; } } @@ -636,28 +629,28 @@ ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_u vald = (svga->gdcreg[0] & 8) ? 0xff : 0; switch (svga->gdcreg[3] & 0x18) { case 0: /*Set*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | ((svga->latch & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (((svga->latch >> 8) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (((svga->latch >> 16) & 0xff) & ~svga->gdcreg[8]); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (((svga->latch >> 24) & 0xff) & ~svga->gdcreg[8]); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch.b[0] & ~svga->gdcreg[8]); + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | (svga->latch.b[1] & ~svga->gdcreg[8]); + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | (svga->latch.b[2] & ~svga->gdcreg[8]); + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | (svga->latch.b[3] & ~svga->gdcreg[8]); break; case 8: /*AND*/ - if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala | ~svga->gdcreg[8]) & svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb | ~svga->gdcreg[8]) & svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc | ~svga->gdcreg[8]) & svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald | ~svga->gdcreg[8]) & svga->latch.b[3]; break; case 0x10: /*OR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) | svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) | svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) | svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) | svga->latch.b[3]; break; case 0x18: /*XOR*/ - if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ (svga->latch & 0xff); - if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ ((svga->latch >> 8) & 0xff); - if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ ((svga->latch >> 16) & 0xff); - if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ ((svga->latch >> 24) & 0xff); + if (writemask2 & 1) svga->vram[addr] = (vala & svga->gdcreg[8]) ^ svga->latch.b[0]; + if (writemask2 & 2) svga->vram[addr | 0x1] = (valb & svga->gdcreg[8]) ^ svga->latch.b[1]; + if (writemask2 & 4) svga->vram[addr | 0x2] = (valc & svga->gdcreg[8]) ^ svga->latch.b[2]; + if (writemask2 & 8) svga->vram[addr | 0x3] = (vald & svga->gdcreg[8]) ^ svga->latch.b[3]; break; } svga->gdcreg[8] = wm; @@ -977,19 +970,19 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) ht216->bg_latch[7] = svga->vram[latch_addr | 7]; } or = addr & 4; - svga->latch = ht216->bg_latch[0 | or] | (ht216->bg_latch[1 | or] << 8) | - (ht216->bg_latch[2 | or] << 16) | (ht216->bg_latch[3 | or] << 24); + svga->latch.d[0] = ht216->bg_latch[0 | or] | (ht216->bg_latch[1 | or] << 8) | + (ht216->bg_latch[2 | or] << 16) | (ht216->bg_latch[3 | or] << 24); if (svga->readmode) { - temp = svga->latch & 0xff; + temp = svga->latch.b[0]; temp ^= (svga->colourcompare & 1) ? 0xff : 0; temp &= (svga->colournocare & 1) ? 0xff : 0; - temp2 = (svga->latch >> 8) & 0xff; + temp2 = svga->latch.b[1]; temp2 ^= (svga->colourcompare & 2) ? 0xff : 0; temp2 &= (svga->colournocare & 2) ? 0xff : 0; - temp3 = (svga->latch >> 16) & 0xff; + temp3 = svga->latch.b[2]; temp3 ^= (svga->colourcompare & 4) ? 0xff : 0; temp3 &= (svga->colournocare & 4) ? 0xff : 0; - temp4 = (svga->latch >> 24) & 0xff; + temp4 = svga->latch.b[3]; temp4 ^= (svga->colourcompare & 8) ? 0xff : 0; temp4 &= (svga->colournocare & 8) ? 0xff : 0; return ~(temp | temp2 | temp3 | temp4); From 26c0a5d2eaaf3a87f48ecb34ca862e4bf1e88d34 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 5 Dec 2019 00:51:07 +0100 Subject: [PATCH 3/3] Removes the legacy DirectDraw and Direct3D 9 renderers, and instead adds SDL (Hardware) and renames the existing SDL renderer to SDL (Software). --- src/win/86Box.rc | 7 +- src/win/Makefile.mingw | 20 ++--- src/win/Makefile_ndr.mingw | 20 ++--- src/win/resource.h | 23 +++-- src/win/win.c | 59 +++++-------- src/win/win.h | 17 ++-- src/win/win_sdl.c | 167 +++++++++++++------------------------ src/win/win_sdl.h | 8 +- src/win/win_ui.c | 40 +++------ 9 files changed, 128 insertions(+), 233 deletions(-) diff --git a/src/win/86Box.rc b/src/win/86Box.rc index d28c34767..a9dedccdd 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -8,7 +8,7 @@ * * Application resource script for Windows. * - * Version: @(#)86Box.rc 1.0.54 2019/11/19 + * Version: @(#)86Box.rc 1.0.55 2019/12/05 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -66,12 +66,11 @@ BEGIN MENUITEM SEPARATOR POPUP "Re&nderer" BEGIN - MENUITEM "&DirectDraw", IDM_VID_DDRAW + MENUITEM "&SDL (Software)", IDM_VID_SDL_SW + MENUITEM "&SDL (Hardware)", IDM_VID_SDL_HW #ifdef USE_D2D MENUITEM "Direct&2D 1.0", IDM_VID_D2D #endif - MENUITEM "Direct&3D 9", IDM_VID_D3D - MENUITEM "&SDL", IDM_VID_SDL #ifdef USE_VNC MENUITEM "&VNC", IDM_VID_VNC #endif diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index e37ba29a6..a44791823 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -8,7 +8,7 @@ # # Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.138 2019/10/23 +# Version: @(#)Makefile.mingw 1.0.139 2019/12/05 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -369,7 +369,7 @@ ifneq ($(WX), n) UIOBJ := wx_main.o wx_ui.o wx_stbar.o wx_render.o else UIOBJ := win_ui.o win_stbar.o \ - win_ddraw.o win_d3d.o win_sdl.o \ + win_sdl.o \ win_dialog.o win_about.o \ win_settings.o win_devconf.o win_snd_gain.o \ win_new_floppy.o win_jsconf.o @@ -688,15 +688,8 @@ ifdef EXOBJ OBJ += $(EXOBJ) endif -LIBS := -mwindows \ - -lddraw -ldxguid -ld3d9 \ - -lcomctl32 - -ifeq ($(STATIC), y) -LIBS += -lopenal -lole32 -lwinmm -else -LIBS += -lwinmm -lopenal.dll -endif +LIBS := -mwindows -lcomctl32 \ + -lopenal -lole32 ifeq ($(D2D), y) LIBS += $(D2DLIB) @@ -710,8 +703,7 @@ endif ifneq ($(WX), n) LIBS += $(WX_LIBS) -lm endif -LIBS += -lpng -lz -lwsock32 -liphlpapi -ldinput8 -LIBS += -static -lstdc++ +LIBS += -lpng -lz -lwsock32 -liphlpapi -ldinput8 -lSDL2 -limm32 -lhid -lsetupapi -loleaut32 -lversion -lwinmm -static -lstdc++ ifneq ($(X64), y) LIBS += -Wl,--large-address-aware endif @@ -719,9 +711,7 @@ ifneq ($(DINPUT), y) LIBS += -lxinput endif -ifeq ($(STATIC), y) LIBS += -static -endif # Build module rules. ifeq ($(AUTODEP), y) diff --git a/src/win/Makefile_ndr.mingw b/src/win/Makefile_ndr.mingw index 466bf472f..71c19c605 100644 --- a/src/win/Makefile_ndr.mingw +++ b/src/win/Makefile_ndr.mingw @@ -8,7 +8,7 @@ # # Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.138 2019/10/23 +# Version: @(#)Makefile.mingw 1.0.139 2019/12/05 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -375,7 +375,7 @@ ifneq ($(WX), n) UIOBJ := wx_main.o wx_ui.o wx_stbar.o wx_render.o else UIOBJ := win_ui.o win_stbar.o \ - win_ddraw.o win_d3d.o win_sdl.o \ + win_sdl.o \ win_dialog.o win_about.o \ win_settings.o win_devconf.o win_snd_gain.o \ win_new_floppy.o win_jsconf.o @@ -694,15 +694,8 @@ ifdef EXOBJ OBJ += $(EXOBJ) endif -LIBS := -mwindows \ - -lddraw -ldxguid -ld3d9 \ - -lcomctl32 - -ifeq ($(STATIC), y) -LIBS += -lopenal -lole32 -lwinmm -else -LIBS += -lwinmm -lopenal.dll -endif +LIBS := -mwindows -lcomctl32 \ + -lopenal -lole32 ifeq ($(D2D), y) LIBS += $(D2DLIB) @@ -716,8 +709,7 @@ endif ifneq ($(WX), n) LIBS += $(WX_LIBS) -lm endif -LIBS += -lpng -lz -lwsock32 -liphlpapi -ldinput8 -LIBS += -static -lstdc++ +LIBS += -lpng -lz -lwsock32 -liphlpapi -ldinput8 -lSDL2 -limm32 -lhid -lsetupapi -loleaut32 -lversion -lwinmm -static -lstdc++ ifneq ($(X64), y) LIBS += -Wl,--large-address-aware endif @@ -725,9 +717,7 @@ ifneq ($(DINPUT), y) LIBS += -lxinput endif -ifeq ($(STATIC), y) LIBS += -static -endif # Build module rules. ifeq ($(AUTODEP), y) diff --git a/src/win/resource.h b/src/win/resource.h index c2b58ed69..422771a19 100644 --- a/src/win/resource.h +++ b/src/win/resource.h @@ -8,16 +8,16 @@ * * Windows resource defines. * - * Version: @(#)resource.h 1.0.30 2019/01/19 + * Version: @(#)resource.h 1.0.31 2019/12/05 * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * David Hrdlička, * - * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. - * Copyright 2018 David Hrdlička. + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2018,2019 David Hrdlička. */ #ifndef WIN_RESOURCE_H # define WIN_RESOURCE_H @@ -266,18 +266,17 @@ #define IDM_UPDATE_ICONS 40030 #define IDM_VID_RESIZE 40040 #define IDM_VID_REMEMBER 40041 -#define IDM_VID_DDRAW 40050 +#define IDM_VID_SDL_SW 40050 +#define IDM_VID_SDL_HW 40051 #ifdef USE_D2D -#define IDM_VID_D2D 40051 -#define IDM_VID_D3D 40052 -#define IDM_VID_SDL 40053 -#define IDM_VID_VNC 40054 -#else -#define IDM_VID_D3D 40051 -#define IDM_VID_SDL 40052 +#define IDM_VID_D2D 40052 #ifdef USE_VNC #define IDM_VID_VNC 40053 #endif +#else +#ifdef USE_VNC +#define IDM_VID_VNC 40052 +#endif #endif #define IDM_VID_SCALE_1X 40055 #define IDM_VID_SCALE_2X 40056 diff --git a/src/win/win.c b/src/win/win.c index f4481feed..2f421412b 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.59 2019/11/02 + * Version: @(#)win.c 1.0.60 2019/12/05 * * Authors: Sarah Walker, * Miran Grca, @@ -43,9 +43,7 @@ #ifdef USE_VNC # include "../vnc.h" #endif -# include "win_ddraw.h" # include "win_d2d.h" -# include "win_d3d.h" # include "win_sdl.h" #include "win.h" @@ -87,25 +85,23 @@ static const struct { void (*enable)(int enable); } vid_apis[2][RENDERERS_NUM] = { { - { "DDraw", 1, (int(*)(void*))ddraw_init, ddraw_close, NULL, ddraw_pause, ddraw_enable }, + { "SDL_Software", 1, (int(*)(void*))sdl_inits, sdl_close, NULL, sdl_pause, sdl_enable }, + { "SDL_Hardware", 1, (int(*)(void*))sdl_inith, sdl_close, NULL, sdl_pause, sdl_enable } #ifdef USE_D2D - { "D2D", 1, (int(*)(void*))d2d_init, d2d_close, NULL, d2d_pause, d2d_enable }, + ,{ "D2D", 1, (int(*)(void*))d2d_init, d2d_close, NULL, d2d_pause, d2d_enable } #endif - { "D3D", 1, (int(*)(void*))d3d_init, d3d_close, d3d_resize, d3d_pause, d3d_enable }, - { "SDL", 1, (int(*)(void*))sdl_init, sdl_close, NULL, sdl_pause, sdl_enable } #ifdef USE_VNC - ,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL } + ,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL } #endif }, { - { "DDraw", 1, (int(*)(void*))ddraw_init_fs, ddraw_close, NULL, ddraw_pause, ddraw_enable }, + { "SDL_Software", 1, (int(*)(void*))sdl_inits_fs, sdl_close, sdl_resize, sdl_pause, sdl_enable }, + { "SDL_Hardware", 1, (int(*)(void*))sdl_inith_fs, sdl_close, sdl_resize, sdl_pause, sdl_enable } #ifdef USE_D2D - { "D2D", 1, (int(*)(void*))d2d_init_fs, d2d_close, NULL, d2d_pause, d2d_enable }, + ,{ "D2D", 1, (int(*)(void*))d2d_init_fs, d2d_close, NULL, d2d_pause, d2d_enable } #endif - { "D3D", 1, (int(*)(void*))d3d_init_fs, d3d_close, NULL, d3d_pause, d3d_enable }, - { "SDL", 1, (int(*)(void*))sdl_init_fs, sdl_close, sdl_resize, sdl_pause, sdl_enable } #ifdef USE_VNC - ,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL } + ,{ "VNC", 0, vnc_init, vnc_close, vnc_resize, vnc_pause, NULL } #endif }, }; @@ -664,11 +660,11 @@ plat_vidapi(char *name) { int i; -#ifdef USE_D2D - if (!strcasecmp(name, "default") || !strcasecmp(name, "system")) return(2); -#else + /* Default/System is SDL Hardware. */ if (!strcasecmp(name, "default") || !strcasecmp(name, "system")) return(1); -#endif + + /* If DirectDraw or plain SDL was specified, return SDL Software. */ + if (!strcasecmp(name, "ddraw") || !strcasecmp(name, "sdl")) return(1); for (i = 0; i < RENDERERS_NUM; i++) { if (vid_apis[0][i].name && @@ -676,7 +672,7 @@ plat_vidapi(char *name) } /* Default value. */ - return(0); + return(1); } @@ -688,38 +684,29 @@ plat_vidapi_name(int api) switch(api) { case 0: - name = "ddraw"; + name = "sdl_software"; + break; + case 1: break; #ifdef USE_D2D - case 1: + case 2: name = "d2d"; break; - - case 2: - break; - - case 3: - name = "sdl"; - break; -#else - case 1: - break; - - case 2: - name = "sdl"; - break; #endif #ifdef USE_VNC #ifdef USE_D2D - case 4: -#else case 3: +#else + case 2: #endif name = "vnc"; break; #endif + default: + fatal("Unknown renderer: %i\n", api); + break; } return(name); diff --git a/src/win/win.h b/src/win/win.h index 05ce73978..c3717e72b 100644 --- a/src/win/win.h +++ b/src/win/win.h @@ -8,7 +8,7 @@ * * Platform support defintions for Win32. * - * Version: @(#)win.h 1.0.28 2019/11/02 + * Version: @(#)win.h 1.0.29 2019/12/05 * * Authors: Sarah Walker, * Miran Grca, @@ -49,8 +49,7 @@ and 0x8895 with WPARAM = followed by 0x8896 with WPARAM = 0. All shutdowns will send an 0x8897. */ -#define WM_RESETD3D WM_USER -#define WM_LEAVEFULLSCREEN WM_USER+1 +#define WM_LEAVEFULLSCREEN WM_USER #define WM_SAVESETTINGS 0x8888 #define WM_SHOWSETTINGS 0x8889 #define WM_PAUSE 0x8890 @@ -67,16 +66,16 @@ #ifdef USE_VNC #ifdef USE_D2D -#define RENDERERS_NUM 5 -#else -#define RENDERERS_NUM 4 -#endif -#else -#ifdef USE_D2D #define RENDERERS_NUM 4 #else #define RENDERERS_NUM 3 #endif +#else +#ifdef USE_D2D +#define RENDERERS_NUM 3 +#else +#define RENDERERS_NUM 2 +#endif #endif diff --git a/src/win/win_sdl.c b/src/win/win_sdl.c index 7a58fa2e6..c8147cdc7 100644 --- a/src/win/win_sdl.c +++ b/src/win/win_sdl.c @@ -12,7 +12,7 @@ * we will not use that, but, instead, use a new window which * coverrs the entire desktop. * - * Version: @(#)win_sdl.c 1.0.8 2019/10/22 + * Version: @(#)win_sdl.c 1.0.9 2019/12/05 * * Authors: Fred N. van Kempen, * Michael Dring, @@ -72,10 +72,10 @@ #include "win_sdl.h" -#define PATH_SDL_DLL "SDL2.dll" +#define RENDERER_FULL_SCREEN 1 +#define RENDERER_HARDWARE 2 -static void *sdl_handle = NULL; /* handle to libSDL2 DLL */ static SDL_Window *sdl_win = NULL; static SDL_Renderer *sdl_render = NULL; static SDL_Texture *sdl_tex = NULL; @@ -88,71 +88,6 @@ static volatile int sdl_enabled = 0; static SDL_mutex* sdl_mutex = NULL; -/* Pointers to the real functions. */ -static void (*sdl_GetVersion)(SDL_version *ver); -static char *const (*sdl_GetError)(void); -static int (*sdl_Init)(Uint32 flags); -static void (*sdl_Quit)(void); -static SDL_Window *(*sdl_CreateWindowFrom)(const void *data); -static void (*sdl_DestroyWindow)(SDL_Window *window); -static SDL_Renderer *(*sdl_CreateRenderer)(SDL_Window *window, - int index, Uint32 flags); -static void (*sdl_DestroyRenderer)(SDL_Renderer *renderer); -static SDL_Texture *(*sdl_CreateTexture)(SDL_Renderer *renderer, - Uint32 format, int access, - int w, int h); -static void (*sdl_DestroyTexture)(SDL_Texture *texture); -static int (*sdl_LockTexture)(SDL_Texture *texture, - const SDL_Rect *rect, - void **pixels, int *pitch); -static void (*sdl_UnlockTexture)(SDL_Texture *texture); -static int (*sdl_RenderCopy)(SDL_Renderer *renderer, - SDL_Texture *texture, - const SDL_Rect *srcrect, - const SDL_Rect *dstrect); -static void (*sdl_RenderPresent)(SDL_Renderer *renderer); -static void (*sdl_GetWindowSize)(SDL_Window* window, - int* w, - int* h); -static int (*sdl_RenderReadPixels)(SDL_Renderer* renderer, - const SDL_Rect* rect, - Uint32 format, - void* pixels, - int pitch); -static SDL_bool (*sdl_SetHint)(const char* name, - const char* value); -static SDL_mutex* (*sdl_CreateMutex)(void); -static void (*sdl_DestroyMutex)(SDL_mutex* mutex); -static int (*sdl_LockMutex)(SDL_mutex* mutex); -static int (*sdl_UnlockMutex)(SDL_mutex* mutex); - - -static dllimp_t sdl_imports[] = { - { "SDL_GetVersion", &sdl_GetVersion }, - { "SDL_GetError", &sdl_GetError }, - { "SDL_Init", &sdl_Init }, - { "SDL_Quit", &sdl_Quit }, - { "SDL_CreateWindowFrom", &sdl_CreateWindowFrom }, - { "SDL_DestroyWindow", &sdl_DestroyWindow }, - { "SDL_CreateRenderer", &sdl_CreateRenderer }, - { "SDL_DestroyRenderer", &sdl_DestroyRenderer }, - { "SDL_CreateTexture", &sdl_CreateTexture }, - { "SDL_DestroyTexture", &sdl_DestroyTexture }, - { "SDL_LockTexture", &sdl_LockTexture }, - { "SDL_UnlockTexture", &sdl_UnlockTexture }, - { "SDL_RenderCopy", &sdl_RenderCopy }, - { "SDL_RenderPresent", &sdl_RenderPresent }, - { "SDL_GetWindowSize", &sdl_GetWindowSize }, - { "SDL_RenderReadPixels", &sdl_RenderReadPixels }, - { "SDL_SetHint", &sdl_SetHint }, - { "SDL_CreateMutex", &sdl_CreateMutex }, - { "SDL_DestroyMutex", &sdl_DestroyMutex }, - { "SDL_LockMutex", &sdl_LockMutex }, - { "SDL_UnlockMutex", &sdl_UnlockMutex }, - { NULL, NULL } -}; - - #ifdef ENABLE_SDL_LOG int sdl_do_log = ENABLE_SDL_LOG; @@ -257,14 +192,14 @@ sdl_blit(int x, int y, int y1, int y2, int w, int h) return; } - sdl_LockMutex(sdl_mutex); + SDL_LockMutex(sdl_mutex); /* * TODO: * SDL_UpdateTexture() might be better here, as it is * (reportedly) slightly faster. */ - sdl_LockTexture(sdl_tex, 0, &pixeldata, &pitch); + SDL_LockTexture(sdl_tex, 0, &pixeldata, &pitch); for (yy = y1; yy < y2; yy++) { if ((y + yy) >= 0 && (y + yy) < buffer32->h) { @@ -277,7 +212,7 @@ sdl_blit(int x, int y, int y1, int y2, int w, int h) video_blit_complete(); - sdl_UnlockTexture(sdl_tex); + SDL_UnlockTexture(sdl_tex); if (sdl_fs) { sdl_log("sdl_blit(%i, %i, %i, %i, %i, %i) (%i, %i)\n", x, y, y1, y2, w, h, unscaled_size_x, efscrnsz_y); @@ -291,13 +226,13 @@ sdl_blit(int x, int y, int y1, int y2, int w, int h) r_src.w = w; r_src.h = h; - ret = sdl_RenderCopy(sdl_render, sdl_tex, &r_src, 0); + ret = SDL_RenderCopy(sdl_render, sdl_tex, &r_src, 0); if (ret) sdl_log("SDL: unable to copy texture to renderer (%s)\n", sdl_GetError()); - sdl_RenderPresent(sdl_render); + SDL_RenderPresent(sdl_render); - sdl_UnlockMutex(sdl_mutex); + SDL_UnlockMutex(sdl_mutex); } @@ -311,22 +246,22 @@ sdl_close(void) sdl_enabled = 0; if (sdl_mutex != NULL) { - sdl_DestroyMutex(sdl_mutex); + SDL_DestroyMutex(sdl_mutex); sdl_mutex = NULL; } if (sdl_tex != NULL) { - sdl_DestroyTexture(sdl_tex); + SDL_DestroyTexture(sdl_tex); sdl_tex = NULL; } if (sdl_render != NULL) { - sdl_DestroyRenderer(sdl_render); + SDL_DestroyRenderer(sdl_render); sdl_render = NULL; } if (sdl_win != NULL) { - sdl_DestroyWindow(sdl_win); + SDL_DestroyWindow(sdl_win); sdl_win = NULL; } @@ -347,13 +282,8 @@ sdl_close(void) sdl_parent_hwnd = NULL; } - /* Quit and unload the DLL if possible. */ - if (sdl_handle != NULL) { - sdl_Quit(); - - dynld_close(sdl_handle); - sdl_handle = NULL; - } + /* Quit. */ + SDL_Quit(); } @@ -361,7 +291,7 @@ static int old_capture = 0; static int -sdl_init_common(int fs) +sdl_init_common(int flags) { wchar_t temp[128]; SDL_version ver; @@ -370,24 +300,21 @@ sdl_init_common(int fs) sdl_log("SDL: init (fs=%d)\n", fs); - /* Try loading the DLL. */ - sdl_handle = dynld_module(PATH_SDL_DLL, sdl_imports); - if (sdl_handle == NULL) { - ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2120); - return(0); - } - /* Get and log the version of the DLL we are using. */ - sdl_GetVersion(&ver); + SDL_GetVersion(&ver); sdl_log("SDL: version %d.%d.%d\n", ver.major, ver.minor, ver.patch); /* Initialize the SDL system. */ - if (sdl_Init(SDL_INIT_VIDEO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { sdl_log("SDL: initialization failed (%s)\n", sdl_GetError()); return(0); } - if (fs) { + if (flags & RENDERER_HARDWARE) + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d"); + /* TODO: why is this necessary to avoid black screen on Win7/8/10? */ + + if (flags & RENDERER_FULL_SCREEN) { /* Get the size of the (current) desktop. */ sdl_w = GetSystemMetrics(SM_CXSCREEN); sdl_h = GetSystemMetrics(SM_CYSCREEN); @@ -431,7 +358,7 @@ sdl_init_common(int fs) x, y, w, h, SWP_SHOWWINDOW); /* Now create the SDL window from that. */ - sdl_win = sdl_CreateWindowFrom((void *)sdl_hwnd); + sdl_win = SDL_CreateWindowFrom((void *)sdl_hwnd); old_capture = mouse_capture; @@ -442,7 +369,7 @@ sdl_init_common(int fs) mouse_capture = 1; } else { /* Create the SDL window from the render window. */ - sdl_win = sdl_CreateWindowFrom((void *)hwndRender); + sdl_win = SDL_CreateWindowFrom((void *)hwndRender); mouse_capture = old_capture; @@ -453,7 +380,7 @@ sdl_init_common(int fs) } } if (sdl_win == NULL) { - sdl_log("SDL: unable to CreateWindowFrom (%s)\n", sdl_GetError()); + sdl_log("SDL: unable to CreateWindowFrom (%s)\n", SDL_GetError()); sdl_close(); return(0); } @@ -465,9 +392,14 @@ sdl_init_common(int fs) * trying to switch to fullscreen even though the window is * not a fullscreen window?) */ - sdl_render = sdl_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE); + if (flags & RENDERER_HARDWARE) { + sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED); + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + } else + sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE); + if (sdl_render == NULL) { - sdl_log("SDL: unable to create renderer (%s)\n", sdl_GetError()); + sdl_log("SDL: unable to create renderer (%s)\n", SDL_GetError()); sdl_close(); return(0); } @@ -478,10 +410,10 @@ sdl_init_common(int fs) * channel seems to be set to 255 everywhere, so ARGB8888 works * just as well. */ - sdl_tex = sdl_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888, + sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 2048, 2048); if (sdl_tex == NULL) { - sdl_log("SDL: unable to create texture (%s)\n", sdl_GetError()); + sdl_log("SDL: unable to create texture (%s)\n", SDL_GetError()); sdl_close(); return(0); } @@ -492,27 +424,41 @@ sdl_init_common(int fs) /* Register our renderer! */ video_setblit(sdl_blit); - sdl_fs = fs; + sdl_fs = !!(flags & RENDERER_FULL_SCREEN); sdl_enabled = 1; - sdl_mutex = sdl_CreateMutex(); + sdl_mutex = SDL_CreateMutex(); return(1); } int -sdl_init(HWND h) +sdl_inits(HWND h) { return sdl_init_common(0); } int -sdl_init_fs(HWND h) +sdl_inith(HWND h) { - return sdl_init_common(1); + return sdl_init_common(RENDERER_HARDWARE); +} + + +int +sdl_inits_fs(HWND h) +{ + return sdl_init_common(RENDERER_FULL_SCREEN); +} + + +int +sdl_inith_fs(HWND h) +{ + return sdl_init_common(RENDERER_FULL_SCREEN | RENDERER_HARDWARE); } @@ -533,10 +479,11 @@ sdl_resize(int x, int y) ww = x; wh = y; - sdl_stretch(&ww, &wh, &wx, &wy); - if (sdl_fs) + if (sdl_fs) { + sdl_stretch(&ww, &wh, &wx, &wy); MoveWindow(sdl_hwnd, wx, wy, ww, wh, TRUE); + } cur_w = x; cur_h = y; diff --git a/src/win/win_sdl.h b/src/win/win_sdl.h index 9a0645455..896b3b8ef 100644 --- a/src/win/win_sdl.h +++ b/src/win/win_sdl.h @@ -8,7 +8,7 @@ * * Definitions for the libSDL2 rendering module. * - * Version: @(#)win_sdl.h 1.0.1 2019/10/12 + * Version: @(#)win_sdl.h 1.0.2 2019/12/05 * * Authors: Fred N. van Kempen, * Michael Dring, @@ -51,8 +51,10 @@ extern void sdl_close(void); -extern int sdl_init(HWND h); -extern int sdl_init_fs(HWND h); +extern int sdl_inits(HWND h); +extern int sdl_inith(HWND h); +extern int sdl_inits_fs(HWND h); +extern int sdl_inith_fs(HWND h); extern int sdl_pause(void); extern void sdl_resize(int x, int y); extern void sdl_enable(int enable); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 312a76826..1f9eedcb8 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -8,7 +8,7 @@ * * user Interface module for WinAPI on Windows. * - * Version: @(#)win_ui.c 1.0.44 2019/11/02 + * Version: @(#)win_ui.c 1.0.45 2019/12/05 * * Authors: Sarah Walker, * Miran Grca, @@ -39,7 +39,6 @@ #include "../plat_midi.h" #include "../ui.h" #include "win.h" -#include "win_d3d.h" #define TIMER_1SEC 1 /* ID of the one-second timer */ @@ -156,20 +155,13 @@ ResetAllMenus(void) CheckMenuItem(menuMain, IDM_VID_INVERT, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_RESIZE, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_DDRAW+0, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SDL_SW, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_SDL_HW, MF_UNCHECKED); #ifdef USE_D2D - CheckMenuItem(menuMain, IDM_VID_DDRAW+1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_DDRAW+2, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_DDRAW+3, MF_UNCHECKED); -#ifdef USE_VNC - CheckMenuItem(menuMain, IDM_VID_DDRAW+4, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_VID_D2D, MF_UNCHECKED); #endif -#else - CheckMenuItem(menuMain, IDM_VID_DDRAW+1, MF_UNCHECKED); - CheckMenuItem(menuMain, IDM_VID_DDRAW+2, MF_UNCHECKED); #ifdef USE_VNC - CheckMenuItem(menuMain, IDM_VID_DDRAW+3, MF_UNCHECKED); -#endif + CheckMenuItem(menuMain, IDM_VID_VNC, MF_UNCHECKED); #endif CheckMenuItem(menuMain, IDM_VID_FS_FULL+0, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_FS_FULL+1, MF_UNCHECKED); @@ -226,7 +218,7 @@ ResetAllMenus(void) if (vid_resize) CheckMenuItem(menuMain, IDM_VID_RESIZE, MF_CHECKED); - CheckMenuItem(menuMain, IDM_VID_DDRAW+vid_api, MF_CHECKED); + CheckMenuItem(menuMain, IDM_VID_SDL_SW+vid_api, MF_CHECKED); CheckMenuItem(menuMain, IDM_VID_FS_FULL+video_fullscreen_scale, MF_CHECKED); CheckMenuItem(menuMain, IDM_VID_REMEMBER, window_remember?MF_CHECKED:MF_UNCHECKED); CheckMenuItem(menuMain, IDM_VID_SCALE_1X+scale, MF_CHECKED); @@ -440,18 +432,17 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) config_save(); break; - case IDM_VID_DDRAW: + case IDM_VID_SDL_SW: + case IDM_VID_SDL_HW: #ifdef USE_D2D case IDM_VID_D2D: #endif - case IDM_VID_D3D: - case IDM_VID_SDL: #ifdef USE_VNC case IDM_VID_VNC: #endif - CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_UNCHECKED); - plat_setvid(LOWORD(wParam) - IDM_VID_DDRAW); - CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_CHECKED); + CheckMenuItem(hmenu, IDM_VID_SDL_SW + vid_api, MF_UNCHECKED); + plat_setvid(LOWORD(wParam) - IDM_VID_SDL_SW); + CheckMenuItem(hmenu, IDM_VID_SDL_SW + vid_api, MF_CHECKED); config_save(); break; @@ -673,15 +664,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ui_sb_timer_callback(wParam & 0xff); break; - case WM_RESETD3D: - startblit(); - if (video_fullscreen) - d3d_reset_fs(); - else - d3d_reset(); - endblit(); - break; - case WM_LEAVEFULLSCREEN: plat_setfullscreen(0); config_save();