From edb8c03171e571c82a18ee0d7d1fc6bb6c88cfe2 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 29 Aug 2022 14:57:12 +0600 Subject: [PATCH 01/14] machine: Add MSI MS-5124 --- src/include/86box/machine.h | 1 + src/machine/m_at_socket7_3v.c | 31 +++++++++++++++++++++++++++++ src/machine/machine_table.c | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 656809932..32163142f 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -581,6 +581,7 @@ extern int machine_at_p5vxb_init(const machine_t *); extern int machine_at_gw2kte_init(const machine_t *); extern int machine_at_ap5s_init(const machine_t *); +extern int machine_at_ms5124_init(const machine_t *); extern int machine_at_vectra54_init(const machine_t *); /* m_at_socket7.c */ diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 21550ce89..9e84ec6c0 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -506,6 +506,37 @@ machine_at_ap5s_init(const machine_t *model) return ret; } + +int +machine_at_ms5124_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/ms5124/AG77.ROM", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + pci_init(PCI_CONFIG_TYPE_1); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x10, PCI_CARD_NORMAL, 41, 42, 43, 44); + pci_register_slot(0x11, PCI_CARD_NORMAL, 44, 41, 42, 43); + pci_register_slot(0x12, PCI_CARD_NORMAL, 43, 44, 41, 42); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 42, 43, 44, 41); + + device_add(&sis_5511_device); + device_add(&keyboard_ps2_ami_pci_device); + device_add(&w83787f_device); + device_add(&sst_flash_29ee010_device); + + return ret; +} + + int machine_at_vectra54_init(const machine_t *model) { diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index ef1c2a566..efd4a4895 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -8476,6 +8476,43 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has AMIKey H KBC firmware (AMIKey-2). */ + { + .name = "[SiS 5511] MSI MS-5124", + .internal_name = "ms5124", + .type = MACHINE_TYPE_SOCKET7_3V, + .chipset = MACHINE_CHIPSET_SIS_5511, + .init = machine_at_ms5124_init, + .pad = 0, + .pad0 = 0, + .pad1 = MACHINE_AVAILABLE, + .pad2 = 0, + .cpu = { + .package = CPU_PKG_SOCKET5_7, + .block = CPU_BLOCK_NONE, + .min_bus = 50000000, + .max_bus = 66666667, + .min_voltage = 3380, + .max_voltage = 3520, + .min_multi = 1.5, + .max_multi = 3.0 + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE_DUAL, + .ram = { + .min = 8192, + .max = 524288, + .step = 8192 + }, + .nvrmask = 127, + .kbc = KBC_UNKNOWN, + .kbc_p1 = 0, + .gpio = 0, + .device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Socket 7 (Dual Voltage) machines */ /* 430HX */ From d6a8950f8a78a6b644991db2f3ae51f83b971faf Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 31 Aug 2022 00:36:15 +0600 Subject: [PATCH 02/14] Correct INTX value base --- src/machine/m_at_socket7_3v.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 9e84ec6c0..69d325aaf 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -523,10 +523,10 @@ machine_at_ms5124_init(const machine_t *model) pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x10, PCI_CARD_NORMAL, 41, 42, 43, 44); - pci_register_slot(0x11, PCI_CARD_NORMAL, 44, 41, 42, 43); - pci_register_slot(0x12, PCI_CARD_NORMAL, 43, 44, 41, 42); - pci_register_slot(0x0F, PCI_CARD_NORMAL, 42, 43, 44, 41); + pci_register_slot(0x10, PCI_CARD_NORMAL, 0x41, 0x42, 0x43, 0x44); + pci_register_slot(0x11, PCI_CARD_NORMAL, 0x44, 0x41, 0x42, 0x43); + pci_register_slot(0x12, PCI_CARD_NORMAL, 0x43, 0x44, 0x41, 0x42); + pci_register_slot(0x0F, PCI_CARD_NORMAL, 0x42, 0x43, 0x44, 0x41); device_add(&sis_5511_device); device_add(&keyboard_ps2_ami_pci_device); From 79ede777c6580256244efe1c18f27c25142e7050 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 31 Aug 2022 13:48:13 +0600 Subject: [PATCH 03/14] Correct INTA and INTB pins for southbridge --- src/machine/m_at_socket7_3v.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 69d325aaf..ef43077b5 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -522,7 +522,7 @@ machine_at_ms5124_init(const machine_t *model) pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0xFE, 0xFF, 0, 0); pci_register_slot(0x10, PCI_CARD_NORMAL, 0x41, 0x42, 0x43, 0x44); pci_register_slot(0x11, PCI_CARD_NORMAL, 0x44, 0x41, 0x42, 0x43); pci_register_slot(0x12, PCI_CARD_NORMAL, 0x43, 0x44, 0x41, 0x42); From c3f6a461429a9fff28c479aa48ad478594fa0059 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Thu, 1 Sep 2022 17:52:51 +0200 Subject: [PATCH 04/14] XGA: Revert to the rom_init routine to load the XGA-1/XGA-2 bios, this fixes intermittent hangs on the XGA-2 end (MCA only, ISA version is intact). --- src/video/vid_xga.c | 1080 ++++++++++++++++++++++--------------------- 1 file changed, 550 insertions(+), 530 deletions(-) diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index f8787fa53..df145743c 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -35,10 +35,10 @@ #include <86box/vid_xga_device.h> #include "cpu.h" -#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" +#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" #define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" -static void xga_ext_outb(uint16_t addr, uint8_t val, void *p); +static void xga_ext_outb(uint16_t addr, uint8_t val, void *p); static uint8_t xga_ext_inb(uint16_t addr, void *p); static void @@ -46,7 +46,7 @@ xga_updatemapping(svga_t *svga) { xga_t *xga = &svga->xga; - // pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, opmodereset1 = %d, access mode = %x, map = %x.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->op_mode_reset, xga->access_mode, svga->gdcreg[6] & 0x0c); + //pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, opmodereset1 = %d, access mode = %x, map = %x.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->op_mode_reset, xga->access_mode, svga->gdcreg[6] & 0x0c); if ((xga->op_mode & 7) >= 4) { if (xga->aperture_cntl == 1) { mem_mapping_disable(&svga->mapping); @@ -72,7 +72,7 @@ linear: mem_mapping_disable(&xga->linear_mapping); } xga->on = 0; - vga_on = 1; + vga_on = 1; if (((xga->op_mode & 7) == 4) && ((svga->gdcreg[6] & 0x0c) == 0x0c) && !xga->a5_test) xga->linear_endian_reverse = 1; } else { @@ -99,7 +99,7 @@ linear: } mem_mapping_disable(&xga->linear_mapping); xga->on = 0; - vga_on = 1; + vga_on = 1; } } @@ -109,10 +109,10 @@ xga_recalctimings(svga_t *svga) xga_t *xga = &svga->xga; if (xga->on) { - xga->v_total = xga->vtotal + 1; - xga->dispend = xga->vdispend + 1; - xga->v_syncstart = xga->vsyncstart + 1; - xga->split = xga->linecmp + 1; + xga->v_total = xga->vtotal + 1; + xga->dispend = xga->vdispend + 1; + xga->v_syncstart = xga->vsyncstart + 1; + xga->split = xga->linecmp + 1; xga->v_blankstart = xga->vblankstart + 1; xga->h_disp = (xga->hdisp + 1) << 3; @@ -120,7 +120,7 @@ xga_recalctimings(svga_t *svga) xga->rowoffset = (xga->hdisp + 1); xga->interlace = !!(xga->disp_cntl_1 & 0x08); - xga->rowcount = (xga->disp_cntl_2 & 0xc0) >> 6; + xga->rowcount = (xga->disp_cntl_2 & 0xc0) >> 6; if (xga->interlace) { xga->v_total >>= 1; @@ -135,16 +135,16 @@ xga_recalctimings(svga_t *svga) switch (xga->clk_sel_1 & 0x0c) { case 0: if (xga->clk_sel_2 & 0x80) { - svga->clock = (cpuclock * (double) (1ull << 32)) / 41539000.0; + svga->clock = (cpuclock * (double)(1ull << 32)) / 41539000.0; } else { - svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; + svga->clock = (cpuclock * (double)(1ull << 32)) / 25175000.0; } break; case 4: - svga->clock = (cpuclock * (double) (1ull << 32)) / 28322000.0; + svga->clock = (cpuclock * (double)(1ull << 32)) / 28322000.0; break; case 0x0c: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double)(1ull << 32)) / 44900000.0; break; } } else { @@ -215,11 +215,11 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x30: - xga->hwc_pos_x = (xga->hwc_pos_x & 0x0700) | val; + xga->hwc_pos_x = (xga->hwc_pos_x & 0x0700) | val; xga->hwcursor.x = xga->hwc_pos_x; break; case 0x31: - xga->hwc_pos_x = (xga->hwc_pos_x & 0xff) | ((val & 0x07) << 8); + xga->hwc_pos_x = (xga->hwc_pos_x & 0xff) | ((val & 0x07) << 8); xga->hwcursor.x = xga->hwc_pos_x; break; @@ -229,11 +229,11 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x33: - xga->hwc_pos_y = (xga->hwc_pos_y & 0x0700) | val; + xga->hwc_pos_y = (xga->hwc_pos_y & 0x0700) | val; xga->hwcursor.y = xga->hwc_pos_y; break; case 0x34: - xga->hwc_pos_y = (xga->hwc_pos_y & 0xff) | ((val & 0x07) << 8); + xga->hwc_pos_y = (xga->hwc_pos_y & 0xff) | ((val & 0x07) << 8); xga->hwcursor.y = xga->hwc_pos_y; break; @@ -243,7 +243,7 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x36: - xga->hwc_control = val; + xga->hwc_control = val; xga->hwcursor.ena = xga->hwc_control & 1; break; @@ -306,12 +306,12 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x60: xga->sprite_pal_addr_idx = (xga->sprite_pal_addr_idx & 0x3f00) | val; - svga->dac_pos = 0; - svga->dac_addr = val & 0xff; + svga->dac_pos = 0; + svga->dac_addr = val & 0xff; break; case 0x61: xga->sprite_pal_addr_idx = (xga->sprite_pal_addr_idx & 0xff) | ((val & 0x3f) << 8); - xga->sprite_pos = xga->sprite_pal_addr_idx & 0x1ff; + xga->sprite_pos = xga->sprite_pal_addr_idx & 0x1ff; if ((xga->sprite_pos >= 0) && (xga->sprite_pos <= 16)) { if ((xga->op_mode & 7) >= 5) xga->cursor_data_on = 1; @@ -333,17 +333,17 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->cursor_data_on = 0; } } - // pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); + //pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); break; case 0x62: xga->sprite_pal_addr_idx_prefetch = (xga->sprite_pal_addr_idx_prefetch & 0x3f00) | val; - svga->dac_pos = 0; - svga->dac_addr = val & 0xff; + svga->dac_pos = 0; + svga->dac_addr = val & 0xff; break; case 0x63: xga->sprite_pal_addr_idx_prefetch = (xga->sprite_pal_addr_idx_prefetch & 0xff) | ((val & 0x3f) << 8); - xga->sprite_pos_prefetch = xga->sprite_pal_addr_idx_prefetch & 0x1ff; + xga->sprite_pos_prefetch = xga->sprite_pal_addr_idx_prefetch & 0x1ff; break; case 0x64: @@ -362,14 +362,14 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga->dac_pos++; break; case 2: - xga->pal_b = val; - index = svga->dac_addr & 0xff; + xga->pal_b = val; + index = svga->dac_addr & 0xff; svga->vgapal[index].r = svga->dac_r; svga->vgapal[index].g = svga->dac_g; svga->vgapal[index].b = xga->pal_b; - svga->pallook[index] = makecol32(svga->vgapal[index].r, svga->vgapal[index].g, svga->vgapal[index].b); - svga->dac_pos = 0; - svga->dac_addr = (svga->dac_addr + 1) & 0xff; + svga->pallook[index] = makecol32(svga->vgapal[index].r, svga->vgapal[index].g, svga->vgapal[index].b); + svga->dac_pos = 0; + svga->dac_addr = (svga->dac_addr + 1) & 0xff; break; } break; @@ -390,7 +390,7 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x6a: xga->sprite_data[xga->sprite_pos] = val; - xga->sprite_pos = (xga->sprite_pos + 1) & 0x3ff; + xga->sprite_pos = (xga->sprite_pos + 1) & 0x3ff; break; case 0x70: @@ -403,10 +403,10 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) static void xga_ext_outb(uint16_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; - // pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); + //pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); switch (addr & 0x0f) { case 0: xga->op_mode = val; @@ -421,17 +421,17 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) xga->aperture_cntl = 0; break; case 6: - vga_on = 0; + vga_on = 0; xga->on = 1; break; case 8: xga->ap_idx = val; - // pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); + //pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); if ((xga->op_mode & 7) < 4) { xga->write_bank = xga->read_bank = 0; } else { xga->write_bank = (xga->ap_idx & 0x3f) << 16; - xga->read_bank = xga->write_bank; + xga->read_bank = xga->write_bank; } break; case 9: @@ -454,8 +454,8 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) static uint8_t xga_ext_inb(uint16_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; uint8_t ret, index; switch (addr & 0x0f) { @@ -629,9 +629,9 @@ xga_ext_inb(uint16_t addr, void *p) ret = svga->vgapal[index].g; break; case 2: - svga->dac_pos = 0; + svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 0xff; - ret = svga->vgapal[index].b; + ret = svga->vgapal[index].b; break; } break; @@ -651,8 +651,8 @@ xga_ext_inb(uint16_t addr, void *p) break; case 0x6a: - // pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); - ret = xga->sprite_data[xga->sprite_pos_prefetch]; + //pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); + ret = xga->sprite_data[xga->sprite_pos_prefetch]; xga->sprite_pos_prefetch = (xga->sprite_pos_prefetch + 1) & 0x3ff; break; @@ -667,114 +667,70 @@ xga_ext_inb(uint16_t addr, void *p) break; } - // pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); + //pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); return ret; } + #define READ(addr, dat) \ dat = xga->vram[(addr) & (xga->vram_mask)]; -#define WRITE(addr, dat) \ - xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITE(addr, dat) \ + xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; #define READW(addr, dat) \ - dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; + dat = *(uint16_t *)&xga->vram[(addr) & (xga->vram_mask)]; -#define READW_REVERSE(addr, dat) \ +#define READW_REVERSE(addr, dat) \ dat = xga->vram[(addr + 1) & (xga->vram_mask - 1)] & 0xff; \ dat |= (xga->vram[(addr) & (xga->vram_mask - 1)] << 8); -#define WRITEW(addr, dat) \ - *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITEW(addr, dat) \ + *(uint16_t *)&xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; -#define WRITEW_REVERSE(addr, dat) \ - xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ - xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ +#define WRITEW_REVERSE(addr, dat) \ + xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ + xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; -#define ROP(mix, d, s) \ - { \ - switch ((mix) ? (xga->accel.frgd_mix & 0x1f) : (xga->accel.bkgd_mix & 0x1f)) { \ - case 0x00: \ - d = 0; \ - break; \ - case 0x01: \ - d = s & d; \ - break; \ - case 0x02: \ - d = s & ~d; \ - break; \ - case 0x03: \ - d = s; \ - break; \ - case 0x04: \ - d = ~s & d; \ - break; \ - case 0x05: \ - d = d; \ - break; \ - case 0x06: \ - d = s ^ d; \ - break; \ - case 0x07: \ - d = s | d; \ - break; \ - case 0x08: \ - d = ~s & ~d; \ - break; \ - case 0x09: \ - d = s ^ ~d; \ - break; \ - case 0x0a: \ - d = ~d; \ - break; \ - case 0x0b: \ - d = s | ~d; \ - break; \ - case 0x0c: \ - d = ~s; \ - break; \ - case 0x0d: \ - d = ~s | d; \ - break; \ - case 0x0e: \ - d = ~s | ~d; \ - break; \ - case 0x0f: \ - d = ~0; \ - break; \ - case 0x10: \ - d = MAX(s, d); \ - break; \ - case 0x11: \ - d = MIN(s, d); \ - break; \ - case 0x12: \ - d = MIN(0xff, s + d); \ - break; \ - case 0x13: \ - d = MAX(0, d - s); \ - break; \ - case 0x14: \ - d = MAX(0, s - d); \ - break; \ - case 0x15: \ - d = (s + d) >> 1; \ - break; \ - } \ - } +#define ROP(mix, d, s) { \ + switch ((mix) ? (xga->accel.frgd_mix & 0x1f) : (xga->accel.bkgd_mix & 0x1f)) { \ + case 0x00: d = 0; break; \ + case 0x01: d = s & d; break; \ + case 0x02: d = s & ~d; break; \ + case 0x03: d = s; break; \ + case 0x04: d = ~s & d; break; \ + case 0x05: d = d; break; \ + case 0x06: d = s ^ d; break; \ + case 0x07: d = s | d; break; \ + case 0x08: d = ~s & ~d; break; \ + case 0x09: d = s ^ ~d; break; \ + case 0x0a: d = ~d; break; \ + case 0x0b: d = s | ~d; break; \ + case 0x0c: d = ~s; break; \ + case 0x0d: d = ~s | d; break; \ + case 0x0e: d = ~s | ~d; break; \ + case 0x0f: d = ~0; break; \ + case 0x10: d = MAX(s, d); break; \ + case 0x11: d = MIN(s, d); break; \ + case 0x12: d = MIN(0xff, s + d); break; \ + case 0x13: d = MAX(0, d - s); break; \ + case 0x14: d = MAX(0, s - d); break; \ + case 0x15: d = (s + d) >> 1; break; \ + } \ + } static uint32_t xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - int bits; + int bits; uint32_t byte; - uint8_t px; - int skip = 0; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -803,15 +759,16 @@ xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t b return px; } + static uint32_t xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - int bits; + int bits; uint32_t byte; - uint8_t px; - int skip = 0; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -874,10 +831,10 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int static void xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, uint32_t pixel, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - uint8_t byte, mask; - int skip = 0; + uint8_t byte, mask; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -891,11 +848,11 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui case 0: /*1-bit*/ addr += (y * (width) >> 3); addr += (x >> 3); - if (!skip) { + if (!skip) { READ(addr, byte); - } else { + } else { byte = mem_readb_phys(addr); - } + } if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { if (xga->linear_endian_reverse) mask = 1 << (7 - (x & 7)); @@ -948,15 +905,15 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui static void xga_short_stroke(svga_t *svga, uint8_t ssv) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - int y = ssv & 0x0f; - int x = 0; - int dx, dy, dirx = 0, diry = 0; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + int y = ssv & 0x0f; + int x = 0; + int dx, dy, dirx = 0, diry = 0; dx = xga->accel.dst_map_x & 0x1fff; if (xga->accel.dst_map_x & 0x1800) @@ -1004,11 +961,18 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { - if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && + (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1025,10 +989,16 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1061,40 +1031,37 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) xga->accel.dst_map_y = dy; } -#define SWAP(a, b) \ - tmpswap = a; \ - a = b; \ - b = tmpswap; +#define SWAP(a,b) tmpswap = a; a = b; b = tmpswap; static void xga_line_draw_write(svga_t *svga) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - int dminor, destxtmp, dmajor, err, tmpswap; - int steep = 1; - int xdir, ydir; - int y = xga->accel.blt_width; - int x = 0; - int dx, dy; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + int dminor, destxtmp, dmajor, err, tmpswap; + int steep = 1; + int xdir, ydir; + int y = xga->accel.blt_width; + int x = 0; + int dx, dy; - dminor = ((int16_t) xga->accel.bres_k1); - if (xga->accel.bres_k1 & 0x2000) + dminor = ((int16_t)xga->accel.bres_k1); + if (xga->accel.bres_k1 & 0x2000) dminor |= ~0x1fff; - dminor >>= 1; + dminor >>= 1; - destxtmp = ((int16_t) xga->accel.bres_k2); - if (xga->accel.bres_k2 & 0x2000) + destxtmp = ((int16_t)xga->accel.bres_k2); + if (xga->accel.bres_k2 & 0x2000) destxtmp |= ~0x1fff; dmajor = -(destxtmp - (dminor << 1)) >> 1; - err = ((int16_t) xga->accel.bres_err_term); - if (xga->accel.bres_err_term & 0x2000) + err = ((int16_t)xga->accel.bres_err_term); + if (xga->accel.bres_err_term & 0x2000) destxtmp |= ~0x1fff; if (xga->accel.octant & 0x02) { @@ -1118,20 +1085,27 @@ xga_line_draw_write(svga_t *svga) dy |= ~0x17ff; if (xga->accel.octant & 0x01) { - steep = 0; - SWAP(dx, dy); - SWAP(xdir, ydir); + steep = 0; + SWAP(dx, dy); + SWAP(xdir, ydir); } if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { if (steep) { - if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && + (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1144,11 +1118,18 @@ xga_line_draw_write(svga_t *svga) } } } else { - if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && + (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1163,10 +1144,16 @@ xga_line_draw_write(svga_t *svga) } } else { if (steep) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1178,10 +1165,16 @@ xga_line_draw_write(svga_t *svga) xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map] + 1); } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1221,6 +1214,7 @@ xga_line_draw_write(svga_t *svga) } } + static int16_t xga_dst_wrap(int16_t addr) { @@ -1231,20 +1225,20 @@ xga_dst_wrap(int16_t addr) static void xga_bitblt(svga_t *svga) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; - uint32_t dstwidth = xga->accel.px_map_width[xga->accel.dst_map]; - uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; - uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; - uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; - int mix = 0; - int xdir, ydir; + uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; + uint32_t dstwidth = xga->accel.px_map_width[xga->accel.dst_map]; + uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; + uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; + uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; + int mix = 0; + int xdir, ydir; if (xga->accel.octant & 0x02) { ydir = -1; @@ -1283,15 +1277,22 @@ xga_bitblt(svga_t *svga) } } - // pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); + //pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); + //pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); while (xga->accel.y >= 0) { if (xga->accel.command & 0xc0) { - if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; + if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && + (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1299,10 +1300,16 @@ xga_bitblt(svga_t *svga) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1361,13 +1368,14 @@ xga_bitblt(svga_t *svga) } } - // pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); + //pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); + //pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.pat_src, patbase, patwidth + 1); if (xga->accel.command & 0xc0) { - if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && + (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { if (mix) src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; else @@ -1375,7 +1383,13 @@ xga_bitblt(svga_t *svga) dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1390,7 +1404,13 @@ xga_bitblt(svga_t *svga) dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || + ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || + ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || + ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || + ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || + ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || + ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1398,6 +1418,7 @@ xga_bitblt(svga_t *svga) } } + xga->accel.sx += xdir; if (xga->accel.pattern) xga->accel.px = ((xga->accel.px + xdir) & patwidth) | (xga->accel.px & ~patwidth); @@ -1466,7 +1487,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x18: if (len == 4) { - xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; + xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; xga->accel.px_map_height[xga->accel.px_map_idx] = (val >> 16) & 0xffff; } else if (len == 2) { xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; @@ -1543,13 +1564,13 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x2c: if (len == 4) { - xga->accel.short_stroke = val; + xga->accel.short_stroke = val; xga->accel.short_stroke_vector1 = xga->accel.short_stroke & 0xff; xga->accel.short_stroke_vector2 = (xga->accel.short_stroke >> 8) & 0xff; xga->accel.short_stroke_vector3 = (xga->accel.short_stroke >> 16) & 0xff; xga->accel.short_stroke_vector4 = (xga->accel.short_stroke >> 24) & 0xff; - // pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); + //pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); xga_short_stroke(svga, xga->accel.short_stroke_vector1); xga_short_stroke(svga, xga->accel.short_stroke_vector2); xga_short_stroke(svga, xga->accel.short_stroke_vector3); @@ -1579,7 +1600,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) xga->accel.frgd_mix = val & 0xff; if (len == 4) { xga->accel.bkgd_mix = (val >> 8) & 0xff; - xga->accel.cc_cond = (val >> 16) & 0x07; + xga->accel.cc_cond = (val >> 16) & 0x07; } else if (len == 2) { xga->accel.bkgd_mix = (val >> 8) & 0xff; } @@ -1687,7 +1708,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x60: if (len == 4) { - xga->accel.blt_width = val & 0xffff; + xga->accel.blt_width = val & 0xffff; xga->accel.blt_height = (val >> 16) & 0xffff; } else if (len == 2) { xga->accel.blt_width = val; @@ -1814,30 +1835,30 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) if (len == 4) { xga->accel.command = val; exec_command: - xga->accel.octant = xga->accel.command & 0x07; + xga->accel.octant = xga->accel.command & 0x07; xga->accel.draw_mode = xga->accel.command & 0x30; xga->accel.mask_mode = xga->accel.command & 0xc0; - xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); - xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); - xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); + xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); + xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); + xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); - // if (xga->accel.pat_src) { - // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", - // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], - // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], - // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], - // xga->accel.px_map_height[xga->accel.src_map], - // xga->accel.pat_map_x, xga->accel.pat_map_y, - // xga->accel.dst_map_x, xga->accel.dst_map_y, - // xga->accel.src_map_x, xga->accel.src_map_y, - // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, - // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], - // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); - // //pclog("\n"); - // } + //if (xga->accel.pat_src) { + // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", + // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], + // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], + // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], + // xga->accel.px_map_height[xga->accel.src_map], + // xga->accel.pat_map_x, xga->accel.pat_map_y, + // xga->accel.dst_map_x, xga->accel.dst_map_y, + // xga->accel.src_map_x, xga->accel.src_map_y, + // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, + // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], + // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); + // //pclog("\n"); + //} switch ((xga->accel.command >> 24) & 0x0f) { case 3: /*Bresenham Line Draw Read*/ - // pclog("Line Draw Read\n"); + //pclog("Line Draw Read\n"); break; case 4: /*Short Stroke Vectors*/ break; @@ -1848,7 +1869,7 @@ exec_command: xga_bitblt(svga); break; case 9: /*Inverting BitBLT*/ - // pclog("Inverting BitBLT\n"); + //pclog("Inverting BitBLT\n"); break; } } else if (len == 2) { @@ -1880,31 +1901,31 @@ exec_command: static void xga_memio_writeb(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 1); - // pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); + //pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); } static void xga_memio_writew(uint32_t addr, uint16_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 2); - // pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); + //pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); } static void xga_memio_writel(uint32_t addr, uint32_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 4); - // pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); + //pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); } static uint8_t @@ -1981,35 +2002,35 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) static uint8_t xga_memio_readb(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; uint8_t temp; temp = xga_mem_read(addr, xga, svga); - // pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); + //pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); return temp; } static uint16_t xga_memio_readw(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; uint16_t temp; temp = xga_mem_read(addr, xga, svga); temp |= (xga_mem_read(addr + 1, xga, svga) << 8); - // pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); + //pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); return temp; } static uint32_t xga_memio_readl(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; uint32_t temp; temp = xga_mem_read(addr, xga, svga); @@ -2017,59 +2038,59 @@ xga_memio_readl(uint32_t addr, void *p) temp |= (xga_mem_read(addr + 2, xga, svga) << 16); temp |= (xga_mem_read(addr + 3, xga, svga) << 24); - // pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); + //pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); return temp; } static void xga_hwcursor_draw(svga_t *svga, int displine) { - xga_t *xga = &svga->xga; - uint8_t dat = 0; - int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; - int x, x_pos, y_pos; - int comb = 0; + xga_t *xga = &svga->xga; + uint8_t dat = 0; + int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; + int x, x_pos, y_pos; + int comb = 0; uint32_t *p; - int idx = (xga->cursor_data_on) ? 32 : 0; + int idx = (xga->cursor_data_on) ? 32 : 0; if (xga->interlace && xga->hwcursor_oddeven) - xga->hwcursor_latch.addr += 16; + xga->hwcursor_latch.addr += 16; y_pos = displine; x_pos = offset + svga->x_add; - p = buffer32->line[y_pos]; + p = buffer32->line[y_pos]; for (x = 0; x < xga->hwcursor_latch.cur_xsize; x++) { - if (x >= idx) { - if (!(x & 0x03)) - dat = xga->sprite_data[xga->hwcursor_latch.addr & 0x3ff]; + if (x >= idx) { + if (!(x & 0x03)) + dat = xga->sprite_data[xga->hwcursor_latch.addr & 0x3ff]; - comb = (dat >> ((x & 0x03) << 1)) & 0x03; + comb = (dat >> ((x & 0x03) << 1)) & 0x03; - x_pos = offset + svga->x_add + x; + x_pos = offset + svga->x_add + x; - switch (comb) { - case 0x00: - /* Cursor Color 1 */ - p[x_pos] = xga->hwc_color0; - break; - case 0x01: - /* Cursor Color 2 */ - p[x_pos] = xga->hwc_color1; - break; - case 0x03: - /* Complement */ - p[x_pos] ^= 0xffffff; - break; - } + switch (comb) { + case 0x00: + /* Cursor Color 1 */ + p[x_pos] = xga->hwc_color0; + break; + case 0x01: + /* Cursor Color 2 */ + p[x_pos] = xga->hwc_color1; + break; + case 0x03: + /* Complement */ + p[x_pos] ^= 0xffffff; + break; } + } - if ((x & 0x03) == 0x03) - xga->hwcursor_latch.addr++; + if ((x & 0x03) == 0x03) + xga->hwcursor_latch.addr++; } if (xga->interlace && !xga->hwcursor_oddeven) - xga->hwcursor_latch.addr += 16; + xga->hwcursor_latch.addr += 16; } static void @@ -2078,13 +2099,13 @@ xga_render_overscan_left(xga_t *xga, svga_t *svga) int i; if ((xga->displine + svga->y_add) < 0) - return; + return; if (svga->scrblank || (xga->h_disp == 0)) - return; + return; for (i = 0; i < svga->x_add; i++) - buffer32->line[xga->displine + svga->y_add][i] = svga->overscan_color; + buffer32->line[xga->displine + svga->y_add][i] = svga->overscan_color; } static void @@ -2093,62 +2114,62 @@ xga_render_overscan_right(xga_t *xga, svga_t *svga) int i, right; if ((xga->displine + svga->y_add) < 0) - return; + return; if (svga->scrblank || (xga->h_disp == 0)) - return; + return; right = (overscan_x >> 1); for (i = 0; i < right; i++) - buffer32->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp + i] = svga->overscan_color; + buffer32->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp + i] = svga->overscan_color; } static void xga_render_8bpp(xga_t *xga, svga_t *svga) { - int x; + int x; uint32_t *p; - uint32_t dat; + uint32_t dat; if ((xga->displine + svga->y_add) < 0) - return; + return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { - p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; + p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; - if (xga->firstline_draw == 2000) - xga->firstline_draw = xga->displine; - xga->lastline_draw = xga->displine; + if (xga->firstline_draw == 2000) + xga->firstline_draw = xga->displine; + xga->lastline_draw = xga->displine; - for (x = 0; x <= xga->h_disp; x += 8) { - dat = *(uint32_t *) (&xga->vram[xga->ma & xga->vram_mask]); - p[0] = svga->pallook[dat & 0xff]; - p[1] = svga->pallook[(dat >> 8) & 0xff]; - p[2] = svga->pallook[(dat >> 16) & 0xff]; - p[3] = svga->pallook[(dat >> 24) & 0xff]; + for (x = 0; x <= xga->h_disp; x += 8) { + dat = *(uint32_t *)(&xga->vram[xga->ma & xga->vram_mask]); + p[0] = svga->pallook[dat & 0xff]; + p[1] = svga->pallook[(dat >> 8) & 0xff]; + p[2] = svga->pallook[(dat >> 16) & 0xff]; + p[3] = svga->pallook[(dat >> 24) & 0xff]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + 4) & xga->vram_mask]); - p[4] = svga->pallook[dat & 0xff]; - p[5] = svga->pallook[(dat >> 8) & 0xff]; - p[6] = svga->pallook[(dat >> 16) & 0xff]; - p[7] = svga->pallook[(dat >> 24) & 0xff]; + dat = *(uint32_t *)(&xga->vram[(xga->ma + 4) & xga->vram_mask]); + p[4] = svga->pallook[dat & 0xff]; + p[5] = svga->pallook[(dat >> 8) & 0xff]; + p[6] = svga->pallook[(dat >> 16) & 0xff]; + p[7] = svga->pallook[(dat >> 24) & 0xff]; - xga->ma += 8; - p += 8; - } - xga->ma &= xga->vram_mask; + xga->ma += 8; + p += 8; + } + xga->ma &= xga->vram_mask; } } static void xga_render_16bpp(xga_t *xga, svga_t *svga) { - int x; + int x; uint32_t *p; - uint32_t dat; + uint32_t dat; if ((xga->displine + svga->y_add) < 0) - return; + return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; @@ -2158,19 +2179,19 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) xga->lastline_draw = xga->displine; for (x = 0; x <= (xga->h_disp); x += 8) { - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); - p[x] = video_16to32[dat & 0xffff]; + dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); + p[x] = video_16to32[dat & 0xffff]; p[x + 1] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); + dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); p[x + 2] = video_16to32[dat & 0xffff]; p[x + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 8) & xga->vram_mask]); + dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 8) & xga->vram_mask]); p[x + 4] = video_16to32[dat & 0xffff]; p[x + 5] = video_16to32[dat >> 16]; - dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 12) & xga->vram_mask]); + dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 12) & xga->vram_mask]); p[x + 6] = video_16to32[dat & 0xffff]; p[x + 7] = video_16to32[dat >> 16]; } @@ -2182,8 +2203,8 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) static void xga_write(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_write(addr, val, svga); @@ -2199,20 +2220,20 @@ xga_write(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; - xga->vram[addr & xga->vram_mask] = val; + xga->vram[addr & xga->vram_mask] = val; } static void xga_writeb(uint32_t addr, uint8_t val, void *p) { - // pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); + //pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); xga_write(addr, val, p); } static void xga_writew(uint32_t addr, uint16_t val, void *p) { - // pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); + //pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); } @@ -2220,7 +2241,7 @@ xga_writew(uint32_t addr, uint16_t val, void *p) static void xga_writel(uint32_t addr, uint32_t val, void *p) { - // pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); + //pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); xga_write(addr + 2, val >> 16, p); @@ -2230,8 +2251,8 @@ xga_writel(uint32_t addr, uint32_t val, void *p) static void xga_write_linear(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_write_linear(addr, val, svga); @@ -2246,14 +2267,14 @@ xga_write_linear(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; - xga->vram[addr & xga->vram_mask] = val; + xga->vram[addr & xga->vram_mask] = val; } static void xga_writew_linear(uint32_t addr, uint16_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_writew_linear(addr, val, svga); @@ -2288,8 +2309,8 @@ xga_writew_linear(uint32_t addr, uint16_t val, void *p) static void xga_writel_linear(uint32_t addr, uint32_t val, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_writel_linear(addr, val, svga); @@ -2305,8 +2326,8 @@ xga_writel_linear(uint32_t addr, uint32_t val, void *p) static uint8_t xga_read(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_read(addr, svga); @@ -2359,8 +2380,8 @@ xga_readl(uint32_t addr, void *p) static uint8_t xga_read_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_read_linear(addr, svga); @@ -2378,8 +2399,8 @@ xga_read_linear(uint32_t addr, void *p) static uint16_t xga_readw_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; uint16_t ret; if (!xga->on) @@ -2406,13 +2427,14 @@ xga_readw_linear(uint32_t addr, void *p) static uint32_t xga_readl_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_readl_linear(addr, svga); - return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); + return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | + (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); } static void @@ -2429,16 +2451,16 @@ xga_do_render(svga_t *svga) break; } - svga->x_add = (overscan_x >> 1); - xga_render_overscan_left(xga, svga); - xga_render_overscan_right(xga, svga); - svga->x_add = (overscan_x >> 1); + svga->x_add = (overscan_x >> 1); + xga_render_overscan_left(xga, svga); + xga_render_overscan_right(xga, svga); + svga->x_add = (overscan_x >> 1); if (xga->hwcursor_on) { - xga_hwcursor_draw(svga, xga->displine + svga->y_add); - xga->hwcursor_on--; - if (xga->hwcursor_on && xga->interlace) - xga->hwcursor_on--; + xga_hwcursor_draw(svga, xga->displine + svga->y_add); + xga->hwcursor_on--; + if (xga->hwcursor_on && xga->interlace) + xga->hwcursor_on--; } } @@ -2446,158 +2468,160 @@ void xga_poll(xga_t *xga, svga_t *svga) { uint32_t x; - int wx, wy; + int wx, wy; if (!xga->linepos) { - if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 32 : 0); - xga->hwcursor_oddeven = 0; + if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 32 : 0); + xga->hwcursor_oddeven = 0; + } + + if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && + xga->interlace) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 33 : 1); + xga->hwcursor_oddeven = 1; + } + + timer_advance_u64(&svga->timer, svga->dispofftime); + xga->linepos = 1; + + if (xga->dispon) { + xga->h_disp_on = 1; + + xga->ma &= xga->vram_mask; + + if (xga->firstline == 2000) { + xga->firstline = xga->displine; + video_wait_for_buffer(); } - if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 33 : 1); - xga->hwcursor_oddeven = 1; + if (xga->hwcursor_on) { + xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = + xga->interlace ? 3 : 2; } - timer_advance_u64(&svga->timer, svga->dispofftime); - xga->linepos = 1; + xga_do_render(svga); - if (xga->dispon) { - xga->h_disp_on = 1; - - xga->ma &= xga->vram_mask; - - if (xga->firstline == 2000) { - xga->firstline = xga->displine; - video_wait_for_buffer(); - } - - if (xga->hwcursor_on) { - xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = xga->interlace ? 3 : 2; - } - - xga_do_render(svga); - - if (xga->lastline < xga->displine) - xga->lastline = xga->displine; - } + if (xga->lastline < xga->displine) + xga->lastline = xga->displine; + } + xga->displine++; + if (xga->interlace) xga->displine++; - if (xga->interlace) - xga->displine++; - if (xga->displine > 1500) - xga->displine = 0; + if (xga->displine > 1500) + xga->displine = 0; } else { - timer_advance_u64(&svga->timer, svga->dispontime); - xga->h_disp_on = 0; - - xga->linepos = 0; - if (xga->dispon) { - if (xga->sc == xga->rowcount) { - xga->sc = 0; - - if ((xga->disp_cntl_2 & 7) == 4) { - xga->maback += (xga->rowoffset << 4); - if (xga->interlace) - xga->maback += (xga->rowoffset << 4); - } else { - xga->maback += (xga->rowoffset << 3); - if (xga->interlace) - xga->maback += (xga->rowoffset << 3); - } - xga->maback &= xga->vram_mask; - xga->ma = xga->maback; - } else { - xga->sc++; - xga->sc &= 0x1f; - xga->ma = xga->maback; - } - } - - xga->vc++; - xga->vc &= 2047; - - if (xga->vc == xga->split) { - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = (xga->rowoffset << 1); - else - xga->ma = xga->maback = 0; - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); + timer_advance_u64(&svga->timer, svga->dispontime); + xga->h_disp_on = 0; + xga->linepos = 0; + if (xga->dispon) { + if (xga->sc == xga->rowcount) { xga->sc = 0; - } - if (xga->vc == xga->dispend) { - xga->dispon = 0; - for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { - if (xga->changedvram[x]) - xga->changedvram[x]--; + if ((xga->disp_cntl_2 & 7) == 4) { + xga->maback += (xga->rowoffset << 4); + if (xga->interlace) + xga->maback += (xga->rowoffset << 4); + } else { + xga->maback += (xga->rowoffset << 3); + if (xga->interlace) + xga->maback += (xga->rowoffset << 3); } - if (svga->fullchange) - svga->fullchange--; + xga->maback &= xga->vram_mask; + xga->ma = xga->maback; + } else { + xga->sc++; + xga->sc &= 0x1f; + xga->ma = xga->maback; } - if (xga->vc == xga->v_syncstart) { - xga->dispon = 0; - x = xga->h_disp; + } - if (xga->interlace && !xga->oddeven) - xga->lastline++; - if (xga->interlace && xga->oddeven) - xga->firstline--; + xga->vc++; + xga->vc &= 2047; - wx = x; + if (xga->vc == xga->split) { + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = (xga->rowoffset << 1); + else + xga->ma = xga->maback = 0; + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); - wy = xga->lastline - xga->firstline; - svga_doblit(wx, wy, svga); + xga->sc = 0; + } + if (xga->vc == xga->dispend) { + xga->dispon = 0; - xga->firstline = 2000; - xga->lastline = 0; - - xga->firstline_draw = 2000; - xga->lastline_draw = 0; - - xga->oddeven ^= 1; - - changeframecount = xga->interlace ? 3 : 2; - - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); - else - xga->ma = xga->maback = xga->ma_latch; - - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); + for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { + if (xga->changedvram[x]) + xga->changedvram[x]--; } - if (xga->vc == xga->v_total) { - xga->vc = 0; - xga->sc = 0; - xga->dispon = 1; - xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + if (svga->fullchange) + svga->fullchange--; + } + if (xga->vc == xga->v_syncstart) { + xga->dispon = 0; + x = xga->h_disp; - svga->x_add = (overscan_x >> 1); + if (xga->interlace && !xga->oddeven) + xga->lastline++; + if (xga->interlace && xga->oddeven) + xga->firstline--; - xga->hwcursor_on = 0; - xga->hwcursor_latch = xga->hwcursor; - } + wx = x; + + wy = xga->lastline - xga->firstline; + svga_doblit(wx, wy, svga); + + xga->firstline = 2000; + xga->lastline = 0; + + xga->firstline_draw = 2000; + xga->lastline_draw = 0; + + xga->oddeven ^= 1; + + changeframecount = xga->interlace ? 3 : 2; + + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); + else + xga->ma = xga->maback = xga->ma_latch; + + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); + } + if (xga->vc == xga->v_total) { + xga->vc = 0; + xga->sc = 0; + xga->dispon = 1; + xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + + svga->x_add = (overscan_x >> 1); + + xga->hwcursor_on = 0; + xga->hwcursor_latch = xga->hwcursor; + } } } static uint8_t xga_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)priv; + xga_t *xga = &svga->xga; - // pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); + //pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); return (xga->pos_regs[port & 7]); } static void xga_mca_write(int port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)priv; + xga_t *xga = &svga->xga; /* MCA does not write registers below 0x0100. */ if (port < 0x0102) @@ -2607,22 +2631,23 @@ xga_mca_write(int port, uint8_t val, void *priv) mem_mapping_disable(&xga->bios_rom.mapping); mem_mapping_disable(&xga->memio_mapping); xga->on = 0; - vga_on = 1; + vga_on = 1; /* Save the MCA register value. */ xga->pos_regs[port & 7] = val; if (!(xga->pos_regs[4] & 1)) /*MCA 4MB addressing on systems with more than 16MB of memory*/ xga->pos_regs[4] |= 1; - // pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); + //pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); if (xga->pos_regs[2] & 1) { - xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; + xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->base_addr_1mb = (xga->pos_regs[5] & 0x0f) << 20; - xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); - xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); + xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); + xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); - mem_mapping_set_addr(&xga->bios_rom.mapping, xga->rom_addr, 0x2000); + if ((port & 7) == 2) + mem_mapping_set_addr(&xga->bios_rom.mapping, xga->rom_addr, 0x2000); mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); } } @@ -2630,8 +2655,8 @@ xga_mca_write(int port, uint8_t val, void *priv) static uint8_t xga_mca_feedb(void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)priv; + xga_t *xga = &svga->xga; return xga->pos_regs[2] & 1; } @@ -2639,7 +2664,7 @@ xga_mca_feedb(void *priv) static void xga_mca_reset(void *p) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *)p; xga_mca_write(0x102, 0, svga); } @@ -2647,48 +2672,47 @@ xga_mca_reset(void *p) static uint8_t xga_pos_in(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *) priv; + svga_t *svga = (svga_t *)priv; return (xga_mca_read(addr, svga)); } static void - * - xga_init(const device_t *info) +*xga_init(const device_t *info) { - svga_t *svga = svga_get_pri(); - xga_t *xga = &svga->xga; - FILE *f; + svga_t *svga = svga_get_pri(); + xga_t *xga = &svga->xga; + FILE *f; uint32_t temp; uint32_t initial_bios_addr = device_get_config_hex20("init_bios_addr"); - uint8_t *rom = NULL; + uint8_t *rom = NULL; xga->type = device_get_config_int("type"); - xga->bus = info->flags; + xga->bus = info->flags; - xga->vram_size = (1024 << 10); - xga->vram_mask = xga->vram_size - 1; - xga->vram = calloc(xga->vram_size, 1); - xga->changedvram = calloc(xga->vram_size >> 12, 1); - xga->on = 0; - xga->hwcursor.cur_xsize = 64; - xga->hwcursor.cur_ysize = 64; - xga->bios_rom.sz = 0x2000; + xga->vram_size = (1024 << 10); + xga->vram_mask = xga->vram_size - 1; + xga->vram = calloc(xga->vram_size, 1); + xga->changedvram = calloc(xga->vram_size >> 12, 1); + xga->on = 0; + xga->hwcursor.cur_xsize = 64; + xga->hwcursor.cur_ysize = 64; + xga->bios_rom.sz = 0x2000; xga->linear_endian_reverse = 0; - xga->a5_test = 0; + xga->a5_test = 0; f = rom_fopen(xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, "rb"); - (void) fseek(f, 0L, SEEK_END); + (void)fseek(f, 0L, SEEK_END); temp = ftell(f); - (void) fseek(f, 0L, SEEK_SET); + (void)fseek(f, 0L, SEEK_SET); rom = malloc(xga->bios_rom.sz); memset(rom, 0xff, xga->bios_rom.sz); - (void) !fread(rom, xga->bios_rom.sz, 1, f); + (void)fread(rom, xga->bios_rom.sz, 1, f); temp -= xga->bios_rom.sz; - (void) fclose(f); + (void)fclose(f); - xga->bios_rom.rom = rom; + xga->bios_rom.rom = rom; xga->bios_rom.mask = xga->bios_rom.sz - 1; if (f != NULL) { free(rom); @@ -2697,29 +2721,25 @@ static void xga->base_addr_1mb = 0; if (info->flags & DEVICE_MCA) { xga->linear_base = 0; - xga->instance = 0; - xga->rom_addr = 0; - mem_mapping_add(&xga->bios_rom.mapping, - initial_bios_addr, xga->bios_rom.sz, - rom_read, rom_readw, rom_readl, - NULL, NULL, NULL, - xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, &xga->bios_rom); + xga->instance = 0; + xga->rom_addr = 0; + rom_init(&xga->bios_rom, xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, initial_bios_addr, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); } else { xga->pos_regs[2] = 1 | 0x0c | 0xf0; - xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; + xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->pos_regs[4] = 1 | 2; xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); - xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); + xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); } mem_mapping_add(&xga->video_mapping, 0, 0, xga_readb, xga_readw, xga_readl, xga_writeb, xga_writew, xga_writel, NULL, MEM_MAPPING_EXTERNAL, svga); - mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, + mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, xga_write_linear, xga_writew_linear, xga_writel_linear, - NULL, MEM_MAPPING_EXTERNAL, svga); + NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&xga->memio_mapping, 0, 0, xga_memio_readb, xga_memio_readw, xga_memio_readl, - xga_memio_writeb, xga_memio_writew, xga_memio_writel, + xga_memio_writeb, xga_memio_writew, xga_memio_writel, xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, svga); mem_mapping_disable(&xga->video_mapping); @@ -2743,8 +2763,8 @@ static void static void xga_close(void *p) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *)p; + xga_t *xga = &svga->xga; if (svga) { free(xga->vram); @@ -2761,7 +2781,7 @@ xga_available(void) static void xga_speed_changed(void *p) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *)p; svga_recalctimings(svga); } @@ -2769,13 +2789,13 @@ xga_speed_changed(void *p) static void xga_force_redraw(void *p) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *)p; svga->fullchange = changeframecount; } static const device_config_t xga_configuration[] = { - // clang-format off + // clang-format off { .name = "init_bios_addr", .description = "Initial MCA BIOS Address (before POS configuration)", @@ -2816,35 +2836,35 @@ static const device_config_t xga_configuration[] = { } }, { .name = "", .description = "", .type = CONFIG_END } -// clang-format on + // clang-format on }; const device_t xga_device = { - .name = "XGA (MCA)", + .name = "XGA (MCA)", .internal_name = "xga_mca", - .flags = DEVICE_MCA, - .local = 0, - .init = xga_init, - .close = xga_close, - .reset = NULL, + .flags = DEVICE_MCA, + .local = 0, + .init = xga_init, + .close = xga_close, + .reset = NULL, { .available = xga_available }, .speed_changed = xga_speed_changed, - .force_redraw = xga_force_redraw, - .config = xga_configuration + .force_redraw = xga_force_redraw, + .config = xga_configuration }; const device_t xga_isa_device = { - .name = "XGA (ISA)", + .name = "XGA (ISA)", .internal_name = "xga_isa", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = xga_init, - .close = xga_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = xga_init, + .close = xga_close, + .reset = NULL, { .available = xga_available }, .speed_changed = xga_speed_changed, - .force_redraw = xga_force_redraw, - .config = xga_configuration + .force_redraw = xga_force_redraw, + .config = xga_configuration }; void From 32220dab84d213f85135e7742e43bfc25fab05fb Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 6 Sep 2022 23:39:37 +0200 Subject: [PATCH 05/14] XGA: made the source file compatible with the 86box clang-format style (ident) and actually fixed the 40 25 POST hang (the key element was bit 0 of MCA port 0x103). --- src/video/vid_xga.c | 1094 +++++++++++++++++++++---------------------- 1 file changed, 537 insertions(+), 557 deletions(-) diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index df145743c..e41430c86 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -14,31 +14,31 @@ * * Copyright 2022 TheCollector1995. */ -#include -#include -#include -#include -#include -#include <86box/bswap.h> +#include "cpu.h" #include <86box/86box.h> +#include <86box/bswap.h> +#include <86box/device.h> +#include <86box/dma.h> #include <86box/io.h> #include <86box/machine.h> -#include <86box/mem.h> -#include <86box/dma.h> -#include <86box/rom.h> #include <86box/mca.h> -#include <86box/device.h> +#include <86box/mem.h> +#include <86box/rom.h> #include <86box/timer.h> -#include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> #include <86box/vid_xga_device.h> -#include "cpu.h" +#include <86box/video.h> +#include +#include +#include +#include +#include -#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" +#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" #define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" -static void xga_ext_outb(uint16_t addr, uint8_t val, void *p); +static void xga_ext_outb(uint16_t addr, uint8_t val, void *p); static uint8_t xga_ext_inb(uint16_t addr, void *p); static void @@ -46,7 +46,7 @@ xga_updatemapping(svga_t *svga) { xga_t *xga = &svga->xga; - //pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, opmodereset1 = %d, access mode = %x, map = %x.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->op_mode_reset, xga->access_mode, svga->gdcreg[6] & 0x0c); + // pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, opmodereset1 = %d, access mode = %x, map = %x.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->op_mode_reset, xga->access_mode, svga->gdcreg[6] & 0x0c); if ((xga->op_mode & 7) >= 4) { if (xga->aperture_cntl == 1) { mem_mapping_disable(&svga->mapping); @@ -72,7 +72,7 @@ linear: mem_mapping_disable(&xga->linear_mapping); } xga->on = 0; - vga_on = 1; + vga_on = 1; if (((xga->op_mode & 7) == 4) && ((svga->gdcreg[6] & 0x0c) == 0x0c) && !xga->a5_test) xga->linear_endian_reverse = 1; } else { @@ -99,7 +99,7 @@ linear: } mem_mapping_disable(&xga->linear_mapping); xga->on = 0; - vga_on = 1; + vga_on = 1; } } @@ -109,10 +109,10 @@ xga_recalctimings(svga_t *svga) xga_t *xga = &svga->xga; if (xga->on) { - xga->v_total = xga->vtotal + 1; - xga->dispend = xga->vdispend + 1; - xga->v_syncstart = xga->vsyncstart + 1; - xga->split = xga->linecmp + 1; + xga->v_total = xga->vtotal + 1; + xga->dispend = xga->vdispend + 1; + xga->v_syncstart = xga->vsyncstart + 1; + xga->split = xga->linecmp + 1; xga->v_blankstart = xga->vblankstart + 1; xga->h_disp = (xga->hdisp + 1) << 3; @@ -120,7 +120,7 @@ xga_recalctimings(svga_t *svga) xga->rowoffset = (xga->hdisp + 1); xga->interlace = !!(xga->disp_cntl_1 & 0x08); - xga->rowcount = (xga->disp_cntl_2 & 0xc0) >> 6; + xga->rowcount = (xga->disp_cntl_2 & 0xc0) >> 6; if (xga->interlace) { xga->v_total >>= 1; @@ -135,16 +135,16 @@ xga_recalctimings(svga_t *svga) switch (xga->clk_sel_1 & 0x0c) { case 0: if (xga->clk_sel_2 & 0x80) { - svga->clock = (cpuclock * (double)(1ull << 32)) / 41539000.0; + svga->clock = (cpuclock * (double) (1ull << 32)) / 41539000.0; } else { - svga->clock = (cpuclock * (double)(1ull << 32)) / 25175000.0; + svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; } break; case 4: - svga->clock = (cpuclock * (double)(1ull << 32)) / 28322000.0; + svga->clock = (cpuclock * (double) (1ull << 32)) / 28322000.0; break; case 0x0c: - svga->clock = (cpuclock * (double)(1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; break; } } else { @@ -215,11 +215,11 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x30: - xga->hwc_pos_x = (xga->hwc_pos_x & 0x0700) | val; + xga->hwc_pos_x = (xga->hwc_pos_x & 0x0700) | val; xga->hwcursor.x = xga->hwc_pos_x; break; case 0x31: - xga->hwc_pos_x = (xga->hwc_pos_x & 0xff) | ((val & 0x07) << 8); + xga->hwc_pos_x = (xga->hwc_pos_x & 0xff) | ((val & 0x07) << 8); xga->hwcursor.x = xga->hwc_pos_x; break; @@ -229,11 +229,11 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x33: - xga->hwc_pos_y = (xga->hwc_pos_y & 0x0700) | val; + xga->hwc_pos_y = (xga->hwc_pos_y & 0x0700) | val; xga->hwcursor.y = xga->hwc_pos_y; break; case 0x34: - xga->hwc_pos_y = (xga->hwc_pos_y & 0xff) | ((val & 0x07) << 8); + xga->hwc_pos_y = (xga->hwc_pos_y & 0xff) | ((val & 0x07) << 8); xga->hwcursor.y = xga->hwc_pos_y; break; @@ -243,7 +243,7 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) break; case 0x36: - xga->hwc_control = val; + xga->hwc_control = val; xga->hwcursor.ena = xga->hwc_control & 1; break; @@ -306,12 +306,12 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x60: xga->sprite_pal_addr_idx = (xga->sprite_pal_addr_idx & 0x3f00) | val; - svga->dac_pos = 0; - svga->dac_addr = val & 0xff; + svga->dac_pos = 0; + svga->dac_addr = val & 0xff; break; case 0x61: xga->sprite_pal_addr_idx = (xga->sprite_pal_addr_idx & 0xff) | ((val & 0x3f) << 8); - xga->sprite_pos = xga->sprite_pal_addr_idx & 0x1ff; + xga->sprite_pos = xga->sprite_pal_addr_idx & 0x1ff; if ((xga->sprite_pos >= 0) && (xga->sprite_pos <= 16)) { if ((xga->op_mode & 7) >= 5) xga->cursor_data_on = 1; @@ -333,17 +333,17 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->cursor_data_on = 0; } } - //pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); + // pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); break; case 0x62: xga->sprite_pal_addr_idx_prefetch = (xga->sprite_pal_addr_idx_prefetch & 0x3f00) | val; - svga->dac_pos = 0; - svga->dac_addr = val & 0xff; + svga->dac_pos = 0; + svga->dac_addr = val & 0xff; break; case 0x63: xga->sprite_pal_addr_idx_prefetch = (xga->sprite_pal_addr_idx_prefetch & 0xff) | ((val & 0x3f) << 8); - xga->sprite_pos_prefetch = xga->sprite_pal_addr_idx_prefetch & 0x1ff; + xga->sprite_pos_prefetch = xga->sprite_pal_addr_idx_prefetch & 0x1ff; break; case 0x64: @@ -362,14 +362,14 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga->dac_pos++; break; case 2: - xga->pal_b = val; - index = svga->dac_addr & 0xff; + xga->pal_b = val; + index = svga->dac_addr & 0xff; svga->vgapal[index].r = svga->dac_r; svga->vgapal[index].g = svga->dac_g; svga->vgapal[index].b = xga->pal_b; - svga->pallook[index] = makecol32(svga->vgapal[index].r, svga->vgapal[index].g, svga->vgapal[index].b); - svga->dac_pos = 0; - svga->dac_addr = (svga->dac_addr + 1) & 0xff; + svga->pallook[index] = makecol32(svga->vgapal[index].r, svga->vgapal[index].g, svga->vgapal[index].b); + svga->dac_pos = 0; + svga->dac_addr = (svga->dac_addr + 1) & 0xff; break; } break; @@ -390,7 +390,7 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x6a: xga->sprite_data[xga->sprite_pos] = val; - xga->sprite_pos = (xga->sprite_pos + 1) & 0x3ff; + xga->sprite_pos = (xga->sprite_pos + 1) & 0x3ff; break; case 0x70: @@ -403,10 +403,10 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) static void xga_ext_outb(uint16_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; - //pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); + // pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); switch (addr & 0x0f) { case 0: xga->op_mode = val; @@ -421,17 +421,17 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) xga->aperture_cntl = 0; break; case 6: - vga_on = 0; + vga_on = 0; xga->on = 1; break; case 8: xga->ap_idx = val; - //pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); + // pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); if ((xga->op_mode & 7) < 4) { xga->write_bank = xga->read_bank = 0; } else { xga->write_bank = (xga->ap_idx & 0x3f) << 16; - xga->read_bank = xga->write_bank; + xga->read_bank = xga->write_bank; } break; case 9: @@ -454,8 +454,8 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) static uint8_t xga_ext_inb(uint16_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; uint8_t ret, index; switch (addr & 0x0f) { @@ -629,9 +629,9 @@ xga_ext_inb(uint16_t addr, void *p) ret = svga->vgapal[index].g; break; case 2: - svga->dac_pos = 0; + svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 0xff; - ret = svga->vgapal[index].b; + ret = svga->vgapal[index].b; break; } break; @@ -651,8 +651,8 @@ xga_ext_inb(uint16_t addr, void *p) break; case 0x6a: - //pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); - ret = xga->sprite_data[xga->sprite_pos_prefetch]; + // pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); + ret = xga->sprite_data[xga->sprite_pos_prefetch]; xga->sprite_pos_prefetch = (xga->sprite_pos_prefetch + 1) & 0x3ff; break; @@ -667,70 +667,114 @@ xga_ext_inb(uint16_t addr, void *p) break; } - //pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); + // pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); return ret; } - #define READ(addr, dat) \ dat = xga->vram[(addr) & (xga->vram_mask)]; -#define WRITE(addr, dat) \ - xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITE(addr, dat) \ + xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; #define READW(addr, dat) \ - dat = *(uint16_t *)&xga->vram[(addr) & (xga->vram_mask)]; + dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; -#define READW_REVERSE(addr, dat) \ +#define READW_REVERSE(addr, dat) \ dat = xga->vram[(addr + 1) & (xga->vram_mask - 1)] & 0xff; \ dat |= (xga->vram[(addr) & (xga->vram_mask - 1)] << 8); -#define WRITEW(addr, dat) \ - *(uint16_t *)&xga->vram[((addr)) & (xga->vram_mask)] = dat; \ +#define WRITEW(addr, dat) \ + *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; -#define WRITEW_REVERSE(addr, dat) \ - xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ - xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ +#define WRITEW_REVERSE(addr, dat) \ + xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ + xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = changeframecount; -#define ROP(mix, d, s) { \ - switch ((mix) ? (xga->accel.frgd_mix & 0x1f) : (xga->accel.bkgd_mix & 0x1f)) { \ - case 0x00: d = 0; break; \ - case 0x01: d = s & d; break; \ - case 0x02: d = s & ~d; break; \ - case 0x03: d = s; break; \ - case 0x04: d = ~s & d; break; \ - case 0x05: d = d; break; \ - case 0x06: d = s ^ d; break; \ - case 0x07: d = s | d; break; \ - case 0x08: d = ~s & ~d; break; \ - case 0x09: d = s ^ ~d; break; \ - case 0x0a: d = ~d; break; \ - case 0x0b: d = s | ~d; break; \ - case 0x0c: d = ~s; break; \ - case 0x0d: d = ~s | d; break; \ - case 0x0e: d = ~s | ~d; break; \ - case 0x0f: d = ~0; break; \ - case 0x10: d = MAX(s, d); break; \ - case 0x11: d = MIN(s, d); break; \ - case 0x12: d = MIN(0xff, s + d); break; \ - case 0x13: d = MAX(0, d - s); break; \ - case 0x14: d = MAX(0, s - d); break; \ - case 0x15: d = (s + d) >> 1; break; \ - } \ - } +#define ROP(mix, d, s) \ + { \ + switch ((mix) ? (xga->accel.frgd_mix & 0x1f) : (xga->accel.bkgd_mix & 0x1f)) { \ + case 0x00: \ + d = 0; \ + break; \ + case 0x01: \ + d = s & d; \ + break; \ + case 0x02: \ + d = s & ~d; \ + break; \ + case 0x03: \ + d = s; \ + break; \ + case 0x04: \ + d = ~s & d; \ + break; \ + case 0x05: \ + d = d; \ + break; \ + case 0x06: \ + d = s ^ d; \ + break; \ + case 0x07: \ + d = s | d; \ + break; \ + case 0x08: \ + d = ~s & ~d; \ + break; \ + case 0x09: \ + d = s ^ ~d; \ + break; \ + case 0x0a: \ + d = ~d; \ + break; \ + case 0x0b: \ + d = s | ~d; \ + break; \ + case 0x0c: \ + d = ~s; \ + break; \ + case 0x0d: \ + d = ~s | d; \ + break; \ + case 0x0e: \ + d = ~s | ~d; \ + break; \ + case 0x0f: \ + d = ~0; \ + break; \ + case 0x10: \ + d = MAX(s, d); \ + break; \ + case 0x11: \ + d = MIN(s, d); \ + break; \ + case 0x12: \ + d = MIN(0xff, s + d); \ + break; \ + case 0x13: \ + d = MAX(0, d - s); \ + break; \ + case 0x14: \ + d = MAX(0, s - d); \ + break; \ + case 0x15: \ + d = (s + d) >> 1; \ + break; \ + } \ + } static uint32_t xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - int bits; + int bits; uint32_t byte; - uint8_t px; - int skip = 0; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -759,16 +803,15 @@ xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t b return px; } - static uint32_t xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - int bits; + int bits; uint32_t byte; - uint8_t px; - int skip = 0; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -831,10 +874,10 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int static void xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, uint32_t pixel, int width) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t addr = base; - uint8_t byte, mask; - int skip = 0; + uint8_t byte, mask; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -848,11 +891,11 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui case 0: /*1-bit*/ addr += (y * (width) >> 3); addr += (x >> 3); - if (!skip) { + if (!skip) { READ(addr, byte); - } else { + } else { byte = mem_readb_phys(addr); - } + } if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { if (xga->linear_endian_reverse) mask = 1 << (7 - (x & 7)); @@ -905,15 +948,15 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui static void xga_short_stroke(svga_t *svga, uint8_t ssv) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - int y = ssv & 0x0f; - int x = 0; - int dx, dy, dirx = 0, diry = 0; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + int y = ssv & 0x0f; + int x = 0; + int dx, dy, dirx = 0, diry = 0; dx = xga->accel.dst_map_x & 0x1fff; if (xga->accel.dst_map_x & 0x1800) @@ -961,18 +1004,11 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { - if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && - (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -989,16 +1025,10 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1031,37 +1061,40 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) xga->accel.dst_map_y = dy; } -#define SWAP(a,b) tmpswap = a; a = b; b = tmpswap; +#define SWAP(a, b) \ + tmpswap = a; \ + a = b; \ + b = tmpswap; static void xga_line_draw_write(svga_t *svga) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - int dminor, destxtmp, dmajor, err, tmpswap; - int steep = 1; - int xdir, ydir; - int y = xga->accel.blt_width; - int x = 0; - int dx, dy; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + int dminor, destxtmp, dmajor, err, tmpswap; + int steep = 1; + int xdir, ydir; + int y = xga->accel.blt_width; + int x = 0; + int dx, dy; - dminor = ((int16_t)xga->accel.bres_k1); - if (xga->accel.bres_k1 & 0x2000) + dminor = ((int16_t) xga->accel.bres_k1); + if (xga->accel.bres_k1 & 0x2000) dminor |= ~0x1fff; - dminor >>= 1; + dminor >>= 1; - destxtmp = ((int16_t)xga->accel.bres_k2); - if (xga->accel.bres_k2 & 0x2000) + destxtmp = ((int16_t) xga->accel.bres_k2); + if (xga->accel.bres_k2 & 0x2000) destxtmp |= ~0x1fff; dmajor = -(destxtmp - (dminor << 1)) >> 1; - err = ((int16_t)xga->accel.bres_err_term); - if (xga->accel.bres_err_term & 0x2000) + err = ((int16_t) xga->accel.bres_err_term); + if (xga->accel.bres_err_term & 0x2000) destxtmp |= ~0x1fff; if (xga->accel.octant & 0x02) { @@ -1085,27 +1118,20 @@ xga_line_draw_write(svga_t *svga) dy |= ~0x17ff; if (xga->accel.octant & 0x01) { - steep = 0; - SWAP(dx, dy); - SWAP(xdir, ydir); + steep = 0; + SWAP(dx, dy); + SWAP(xdir, ydir); } if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { if (steep) { - if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && - (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1118,18 +1144,11 @@ xga_line_draw_write(svga_t *svga) } } } else { - if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && - (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1144,16 +1163,10 @@ xga_line_draw_write(svga_t *svga) } } else { if (steep) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1165,16 +1178,10 @@ xga_line_draw_write(svga_t *svga) xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map] + 1); } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1214,7 +1221,6 @@ xga_line_draw_write(svga_t *svga) } } - static int16_t xga_dst_wrap(int16_t addr) { @@ -1225,20 +1231,20 @@ xga_dst_wrap(int16_t addr) static void xga_bitblt(svga_t *svga) { - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; uint32_t src_dat, dest_dat, old_dest_dat; - uint32_t color_cmp = xga->accel.color_cmp; + uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; - uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; - uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; - uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; - uint32_t dstwidth = xga->accel.px_map_width[xga->accel.dst_map]; - uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; - uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; - uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; - int mix = 0; - int xdir, ydir; + uint32_t patbase = xga->accel.px_map_base[xga->accel.pat_src]; + uint32_t dstbase = xga->accel.px_map_base[xga->accel.dst_map]; + uint32_t srcbase = xga->accel.px_map_base[xga->accel.src_map]; + uint32_t patwidth = xga->accel.px_map_width[xga->accel.pat_src]; + uint32_t dstwidth = xga->accel.px_map_width[xga->accel.dst_map]; + uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; + uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; + uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; + int mix = 0; + int xdir, ydir; if (xga->accel.octant & 0x02) { ydir = -1; @@ -1277,22 +1283,15 @@ xga_bitblt(svga_t *svga) } } - //pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); - //pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); + // pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); + // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); while (xga->accel.y >= 0) { if (xga->accel.command & 0xc0) { - if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && - (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; + if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1300,16 +1299,10 @@ xga_bitblt(svga_t *svga) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1368,14 +1361,13 @@ xga_bitblt(svga_t *svga) } } - //pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); - //pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); + // pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); + // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.pat_src, patbase, patwidth + 1); if (xga->accel.command & 0xc0) { - if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && - (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { + if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { if (mix) src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; else @@ -1383,13 +1375,7 @@ xga_bitblt(svga_t *svga) dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1404,13 +1390,7 @@ xga_bitblt(svga_t *svga) dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - if ((xga->accel.cc_cond == 4) || - ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || - ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || - ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || - ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || - ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || - ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { + if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); @@ -1418,7 +1398,6 @@ xga_bitblt(svga_t *svga) } } - xga->accel.sx += xdir; if (xga->accel.pattern) xga->accel.px = ((xga->accel.px + xdir) & patwidth) | (xga->accel.px & ~patwidth); @@ -1487,7 +1466,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x18: if (len == 4) { - xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; + xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; xga->accel.px_map_height[xga->accel.px_map_idx] = (val >> 16) & 0xffff; } else if (len == 2) { xga->accel.px_map_width[xga->accel.px_map_idx] = val & 0xffff; @@ -1564,13 +1543,13 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x2c: if (len == 4) { - xga->accel.short_stroke = val; + xga->accel.short_stroke = val; xga->accel.short_stroke_vector1 = xga->accel.short_stroke & 0xff; xga->accel.short_stroke_vector2 = (xga->accel.short_stroke >> 8) & 0xff; xga->accel.short_stroke_vector3 = (xga->accel.short_stroke >> 16) & 0xff; xga->accel.short_stroke_vector4 = (xga->accel.short_stroke >> 24) & 0xff; - //pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); + // pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); xga_short_stroke(svga, xga->accel.short_stroke_vector1); xga_short_stroke(svga, xga->accel.short_stroke_vector2); xga_short_stroke(svga, xga->accel.short_stroke_vector3); @@ -1600,7 +1579,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) xga->accel.frgd_mix = val & 0xff; if (len == 4) { xga->accel.bkgd_mix = (val >> 8) & 0xff; - xga->accel.cc_cond = (val >> 16) & 0x07; + xga->accel.cc_cond = (val >> 16) & 0x07; } else if (len == 2) { xga->accel.bkgd_mix = (val >> 8) & 0xff; } @@ -1708,7 +1687,7 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) case 0x60: if (len == 4) { - xga->accel.blt_width = val & 0xffff; + xga->accel.blt_width = val & 0xffff; xga->accel.blt_height = (val >> 16) & 0xffff; } else if (len == 2) { xga->accel.blt_width = val; @@ -1835,30 +1814,30 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) if (len == 4) { xga->accel.command = val; exec_command: - xga->accel.octant = xga->accel.command & 0x07; + xga->accel.octant = xga->accel.command & 0x07; xga->accel.draw_mode = xga->accel.command & 0x30; xga->accel.mask_mode = xga->accel.command & 0xc0; - xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); - xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); - xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); + xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); + xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); + xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); - //if (xga->accel.pat_src) { - // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", - // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], - // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], - // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], - // xga->accel.px_map_height[xga->accel.src_map], - // xga->accel.pat_map_x, xga->accel.pat_map_y, - // xga->accel.dst_map_x, xga->accel.dst_map_y, - // xga->accel.src_map_x, xga->accel.src_map_y, - // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, - // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], - // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); - // //pclog("\n"); - //} + // if (xga->accel.pat_src) { + // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", + // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], + // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], + // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], + // xga->accel.px_map_height[xga->accel.src_map], + // xga->accel.pat_map_x, xga->accel.pat_map_y, + // xga->accel.dst_map_x, xga->accel.dst_map_y, + // xga->accel.src_map_x, xga->accel.src_map_y, + // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, + // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], + // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); + // //pclog("\n"); + // } switch ((xga->accel.command >> 24) & 0x0f) { case 3: /*Bresenham Line Draw Read*/ - //pclog("Line Draw Read\n"); + // pclog("Line Draw Read\n"); break; case 4: /*Short Stroke Vectors*/ break; @@ -1869,7 +1848,7 @@ exec_command: xga_bitblt(svga); break; case 9: /*Inverting BitBLT*/ - //pclog("Inverting BitBLT\n"); + // pclog("Inverting BitBLT\n"); break; } } else if (len == 2) { @@ -1901,31 +1880,31 @@ exec_command: static void xga_memio_writeb(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 1); - //pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); + // pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); } static void xga_memio_writew(uint32_t addr, uint16_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 2); - //pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); + // pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); } static void xga_memio_writel(uint32_t addr, uint32_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 4); - //pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); + // pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); } static uint8_t @@ -2002,35 +1981,35 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) static uint8_t xga_memio_readb(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; uint8_t temp; temp = xga_mem_read(addr, xga, svga); - //pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); + // pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); return temp; } static uint16_t xga_memio_readw(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; uint16_t temp; temp = xga_mem_read(addr, xga, svga); temp |= (xga_mem_read(addr + 1, xga, svga) << 8); - //pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); + // pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); return temp; } static uint32_t xga_memio_readl(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; uint32_t temp; temp = xga_mem_read(addr, xga, svga); @@ -2038,59 +2017,59 @@ xga_memio_readl(uint32_t addr, void *p) temp |= (xga_mem_read(addr + 2, xga, svga) << 16); temp |= (xga_mem_read(addr + 3, xga, svga) << 24); - //pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); + // pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); return temp; } static void xga_hwcursor_draw(svga_t *svga, int displine) { - xga_t *xga = &svga->xga; - uint8_t dat = 0; - int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; - int x, x_pos, y_pos; - int comb = 0; + xga_t *xga = &svga->xga; + uint8_t dat = 0; + int offset = xga->hwcursor_latch.x - xga->hwcursor_latch.xoff; + int x, x_pos, y_pos; + int comb = 0; uint32_t *p; - int idx = (xga->cursor_data_on) ? 32 : 0; + int idx = (xga->cursor_data_on) ? 32 : 0; if (xga->interlace && xga->hwcursor_oddeven) - xga->hwcursor_latch.addr += 16; + xga->hwcursor_latch.addr += 16; y_pos = displine; x_pos = offset + svga->x_add; - p = buffer32->line[y_pos]; + p = buffer32->line[y_pos]; for (x = 0; x < xga->hwcursor_latch.cur_xsize; x++) { - if (x >= idx) { - if (!(x & 0x03)) - dat = xga->sprite_data[xga->hwcursor_latch.addr & 0x3ff]; + if (x >= idx) { + if (!(x & 0x03)) + dat = xga->sprite_data[xga->hwcursor_latch.addr & 0x3ff]; - comb = (dat >> ((x & 0x03) << 1)) & 0x03; + comb = (dat >> ((x & 0x03) << 1)) & 0x03; - x_pos = offset + svga->x_add + x; + x_pos = offset + svga->x_add + x; - switch (comb) { - case 0x00: - /* Cursor Color 1 */ - p[x_pos] = xga->hwc_color0; - break; - case 0x01: - /* Cursor Color 2 */ - p[x_pos] = xga->hwc_color1; - break; - case 0x03: - /* Complement */ - p[x_pos] ^= 0xffffff; - break; + switch (comb) { + case 0x00: + /* Cursor Color 1 */ + p[x_pos] = xga->hwc_color0; + break; + case 0x01: + /* Cursor Color 2 */ + p[x_pos] = xga->hwc_color1; + break; + case 0x03: + /* Complement */ + p[x_pos] ^= 0xffffff; + break; + } } - } - if ((x & 0x03) == 0x03) - xga->hwcursor_latch.addr++; + if ((x & 0x03) == 0x03) + xga->hwcursor_latch.addr++; } if (xga->interlace && !xga->hwcursor_oddeven) - xga->hwcursor_latch.addr += 16; + xga->hwcursor_latch.addr += 16; } static void @@ -2099,13 +2078,13 @@ xga_render_overscan_left(xga_t *xga, svga_t *svga) int i; if ((xga->displine + svga->y_add) < 0) - return; + return; if (svga->scrblank || (xga->h_disp == 0)) - return; + return; for (i = 0; i < svga->x_add; i++) - buffer32->line[xga->displine + svga->y_add][i] = svga->overscan_color; + buffer32->line[xga->displine + svga->y_add][i] = svga->overscan_color; } static void @@ -2114,62 +2093,62 @@ xga_render_overscan_right(xga_t *xga, svga_t *svga) int i, right; if ((xga->displine + svga->y_add) < 0) - return; + return; if (svga->scrblank || (xga->h_disp == 0)) - return; + return; right = (overscan_x >> 1); for (i = 0; i < right; i++) - buffer32->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp + i] = svga->overscan_color; + buffer32->line[xga->displine + svga->y_add][svga->x_add + xga->h_disp + i] = svga->overscan_color; } static void xga_render_8bpp(xga_t *xga, svga_t *svga) { - int x; + int x; uint32_t *p; - uint32_t dat; + uint32_t dat; if ((xga->displine + svga->y_add) < 0) - return; + return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { - p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; + p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; - if (xga->firstline_draw == 2000) - xga->firstline_draw = xga->displine; - xga->lastline_draw = xga->displine; + if (xga->firstline_draw == 2000) + xga->firstline_draw = xga->displine; + xga->lastline_draw = xga->displine; - for (x = 0; x <= xga->h_disp; x += 8) { - dat = *(uint32_t *)(&xga->vram[xga->ma & xga->vram_mask]); - p[0] = svga->pallook[dat & 0xff]; - p[1] = svga->pallook[(dat >> 8) & 0xff]; - p[2] = svga->pallook[(dat >> 16) & 0xff]; - p[3] = svga->pallook[(dat >> 24) & 0xff]; + for (x = 0; x <= xga->h_disp; x += 8) { + dat = *(uint32_t *) (&xga->vram[xga->ma & xga->vram_mask]); + p[0] = svga->pallook[dat & 0xff]; + p[1] = svga->pallook[(dat >> 8) & 0xff]; + p[2] = svga->pallook[(dat >> 16) & 0xff]; + p[3] = svga->pallook[(dat >> 24) & 0xff]; - dat = *(uint32_t *)(&xga->vram[(xga->ma + 4) & xga->vram_mask]); - p[4] = svga->pallook[dat & 0xff]; - p[5] = svga->pallook[(dat >> 8) & 0xff]; - p[6] = svga->pallook[(dat >> 16) & 0xff]; - p[7] = svga->pallook[(dat >> 24) & 0xff]; + dat = *(uint32_t *) (&xga->vram[(xga->ma + 4) & xga->vram_mask]); + p[4] = svga->pallook[dat & 0xff]; + p[5] = svga->pallook[(dat >> 8) & 0xff]; + p[6] = svga->pallook[(dat >> 16) & 0xff]; + p[7] = svga->pallook[(dat >> 24) & 0xff]; - xga->ma += 8; - p += 8; - } - xga->ma &= xga->vram_mask; + xga->ma += 8; + p += 8; + } + xga->ma &= xga->vram_mask; } } static void xga_render_16bpp(xga_t *xga, svga_t *svga) { - int x; + int x; uint32_t *p; - uint32_t dat; + uint32_t dat; if ((xga->displine + svga->y_add) < 0) - return; + return; if (xga->changedvram[xga->ma >> 12] || xga->changedvram[(xga->ma >> 12) + 1] || svga->fullchange) { p = &buffer32->line[xga->displine + svga->y_add][svga->x_add]; @@ -2179,19 +2158,19 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) xga->lastline_draw = xga->displine; for (x = 0; x <= (xga->h_disp); x += 8) { - dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); - p[x] = video_16to32[dat & 0xffff]; + dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1)) & xga->vram_mask]); + p[x] = video_16to32[dat & 0xffff]; p[x + 1] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 4) & xga->vram_mask]); p[x + 2] = video_16to32[dat & 0xffff]; p[x + 3] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 8) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 8) & xga->vram_mask]); p[x + 4] = video_16to32[dat & 0xffff]; p[x + 5] = video_16to32[dat >> 16]; - dat = *(uint32_t *)(&xga->vram[(xga->ma + (x << 1) + 12) & xga->vram_mask]); + dat = *(uint32_t *) (&xga->vram[(xga->ma + (x << 1) + 12) & xga->vram_mask]); p[x + 6] = video_16to32[dat & 0xffff]; p[x + 7] = video_16to32[dat >> 16]; } @@ -2203,8 +2182,8 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) static void xga_write(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_write(addr, val, svga); @@ -2220,20 +2199,20 @@ xga_write(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; - xga->vram[addr & xga->vram_mask] = val; + xga->vram[addr & xga->vram_mask] = val; } static void xga_writeb(uint32_t addr, uint8_t val, void *p) { - //pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); + // pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); xga_write(addr, val, p); } static void xga_writew(uint32_t addr, uint16_t val, void *p) { - //pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); + // pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); } @@ -2241,7 +2220,7 @@ xga_writew(uint32_t addr, uint16_t val, void *p) static void xga_writel(uint32_t addr, uint32_t val, void *p) { - //pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); + // pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); xga_write(addr, val, p); xga_write(addr + 1, val >> 8, p); xga_write(addr + 2, val >> 16, p); @@ -2251,8 +2230,8 @@ xga_writel(uint32_t addr, uint32_t val, void *p) static void xga_write_linear(uint32_t addr, uint8_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_write_linear(addr, val, svga); @@ -2267,14 +2246,14 @@ xga_write_linear(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; xga->changedvram[(addr & xga->vram_mask) >> 12] = changeframecount; - xga->vram[addr & xga->vram_mask] = val; + xga->vram[addr & xga->vram_mask] = val; } static void xga_writew_linear(uint32_t addr, uint16_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_writew_linear(addr, val, svga); @@ -2309,8 +2288,8 @@ xga_writew_linear(uint32_t addr, uint16_t val, void *p) static void xga_writel_linear(uint32_t addr, uint32_t val, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) { svga_writel_linear(addr, val, svga); @@ -2326,8 +2305,8 @@ xga_writel_linear(uint32_t addr, uint32_t val, void *p) static uint8_t xga_read(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_read(addr, svga); @@ -2380,8 +2359,8 @@ xga_readl(uint32_t addr, void *p) static uint8_t xga_read_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_read_linear(addr, svga); @@ -2399,8 +2378,8 @@ xga_read_linear(uint32_t addr, void *p) static uint16_t xga_readw_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; uint16_t ret; if (!xga->on) @@ -2427,14 +2406,13 @@ xga_readw_linear(uint32_t addr, void *p) static uint32_t xga_readl_linear(uint32_t addr, void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (!xga->on) return svga_readl_linear(addr, svga); - return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | - (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); + return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); } static void @@ -2451,16 +2429,16 @@ xga_do_render(svga_t *svga) break; } - svga->x_add = (overscan_x >> 1); - xga_render_overscan_left(xga, svga); - xga_render_overscan_right(xga, svga); - svga->x_add = (overscan_x >> 1); + svga->x_add = (overscan_x >> 1); + xga_render_overscan_left(xga, svga); + xga_render_overscan_right(xga, svga); + svga->x_add = (overscan_x >> 1); if (xga->hwcursor_on) { - xga_hwcursor_draw(svga, xga->displine + svga->y_add); - xga->hwcursor_on--; - if (xga->hwcursor_on && xga->interlace) - xga->hwcursor_on--; + xga_hwcursor_draw(svga, xga->displine + svga->y_add); + xga->hwcursor_on--; + if (xga->hwcursor_on && xga->interlace) + xga->hwcursor_on--; } } @@ -2468,160 +2446,158 @@ void xga_poll(xga_t *xga, svga_t *svga) { uint32_t x; - int wx, wy; + int wx, wy; if (!xga->linepos) { - if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 32 : 0); - xga->hwcursor_oddeven = 0; - } - - if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && - xga->interlace) { - xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 33 : 1); - xga->hwcursor_oddeven = 1; - } - - timer_advance_u64(&svga->timer, svga->dispofftime); - xga->linepos = 1; - - if (xga->dispon) { - xga->h_disp_on = 1; - - xga->ma &= xga->vram_mask; - - if (xga->firstline == 2000) { - xga->firstline = xga->displine; - video_wait_for_buffer(); + if (xga->displine == xga->hwcursor_latch.y && xga->hwcursor_latch.ena) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 32 : 0); + xga->hwcursor_oddeven = 0; } - if (xga->hwcursor_on) { - xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = - xga->interlace ? 3 : 2; + if (xga->displine == (xga->hwcursor_latch.y + 1) && xga->hwcursor_latch.ena && xga->interlace) { + xga->hwcursor_on = xga->hwcursor_latch.cur_ysize - (xga->cursor_data_on ? 33 : 1); + xga->hwcursor_oddeven = 1; } - xga_do_render(svga); + timer_advance_u64(&svga->timer, svga->dispofftime); + xga->linepos = 1; - if (xga->lastline < xga->displine) - xga->lastline = xga->displine; - } + if (xga->dispon) { + xga->h_disp_on = 1; - xga->displine++; - if (xga->interlace) - xga->displine++; - if (xga->displine > 1500) - xga->displine = 0; - } else { - timer_advance_u64(&svga->timer, svga->dispontime); - xga->h_disp_on = 0; + xga->ma &= xga->vram_mask; - xga->linepos = 0; - if (xga->dispon) { - if (xga->sc == xga->rowcount) { - xga->sc = 0; - - if ((xga->disp_cntl_2 & 7) == 4) { - xga->maback += (xga->rowoffset << 4); - if (xga->interlace) - xga->maback += (xga->rowoffset << 4); - } else { - xga->maback += (xga->rowoffset << 3); - if (xga->interlace) - xga->maback += (xga->rowoffset << 3); + if (xga->firstline == 2000) { + xga->firstline = xga->displine; + video_wait_for_buffer(); } - xga->maback &= xga->vram_mask; - xga->ma = xga->maback; - } else { - xga->sc++; - xga->sc &= 0x1f; - xga->ma = xga->maback; + + if (xga->hwcursor_on) { + xga->changedvram[xga->ma >> 12] = xga->changedvram[(xga->ma >> 12) + 1] = xga->interlace ? 3 : 2; + } + + xga_do_render(svga); + + if (xga->lastline < xga->displine) + xga->lastline = xga->displine; } - } - xga->vc++; - xga->vc &= 2047; + xga->displine++; + if (xga->interlace) + xga->displine++; + if (xga->displine > 1500) + xga->displine = 0; + } else { + timer_advance_u64(&svga->timer, svga->dispontime); + xga->h_disp_on = 0; - if (xga->vc == xga->split) { - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = (xga->rowoffset << 1); - else - xga->ma = xga->maback = 0; - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); + xga->linepos = 0; + if (xga->dispon) { + if (xga->sc == xga->rowcount) { + xga->sc = 0; - xga->sc = 0; - } - if (xga->vc == xga->dispend) { - xga->dispon = 0; - - for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { - if (xga->changedvram[x]) - xga->changedvram[x]--; + if ((xga->disp_cntl_2 & 7) == 4) { + xga->maback += (xga->rowoffset << 4); + if (xga->interlace) + xga->maback += (xga->rowoffset << 4); + } else { + xga->maback += (xga->rowoffset << 3); + if (xga->interlace) + xga->maback += (xga->rowoffset << 3); + } + xga->maback &= xga->vram_mask; + xga->ma = xga->maback; + } else { + xga->sc++; + xga->sc &= 0x1f; + xga->ma = xga->maback; + } } - if (svga->fullchange) - svga->fullchange--; - } - if (xga->vc == xga->v_syncstart) { - xga->dispon = 0; - x = xga->h_disp; - if (xga->interlace && !xga->oddeven) - xga->lastline++; - if (xga->interlace && xga->oddeven) - xga->firstline--; + xga->vc++; + xga->vc &= 2047; - wx = x; + if (xga->vc == xga->split) { + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = (xga->rowoffset << 1); + else + xga->ma = xga->maback = 0; + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); - wy = xga->lastline - xga->firstline; - svga_doblit(wx, wy, svga); + xga->sc = 0; + } + if (xga->vc == xga->dispend) { + xga->dispon = 0; - xga->firstline = 2000; - xga->lastline = 0; + for (x = 0; x < ((xga->vram_mask + 1) >> 12); x++) { + if (xga->changedvram[x]) + xga->changedvram[x]--; + } + if (svga->fullchange) + svga->fullchange--; + } + if (xga->vc == xga->v_syncstart) { + xga->dispon = 0; + x = xga->h_disp; - xga->firstline_draw = 2000; - xga->lastline_draw = 0; + if (xga->interlace && !xga->oddeven) + xga->lastline++; + if (xga->interlace && xga->oddeven) + xga->firstline--; - xga->oddeven ^= 1; + wx = x; - changeframecount = xga->interlace ? 3 : 2; + wy = xga->lastline - xga->firstline; + svga_doblit(wx, wy, svga); - if (xga->interlace && xga->oddeven) - xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); - else - xga->ma = xga->maback = xga->ma_latch; + xga->firstline = 2000; + xga->lastline = 0; - xga->ma = (xga->ma << 2); - xga->maback = (xga->maback << 2); - } - if (xga->vc == xga->v_total) { - xga->vc = 0; - xga->sc = 0; - xga->dispon = 1; - xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + xga->firstline_draw = 2000; + xga->lastline_draw = 0; - svga->x_add = (overscan_x >> 1); + xga->oddeven ^= 1; - xga->hwcursor_on = 0; - xga->hwcursor_latch = xga->hwcursor; - } + changeframecount = xga->interlace ? 3 : 2; + + if (xga->interlace && xga->oddeven) + xga->ma = xga->maback = xga->ma_latch + (xga->rowoffset << 1); + else + xga->ma = xga->maback = xga->ma_latch; + + xga->ma = (xga->ma << 2); + xga->maback = (xga->maback << 2); + } + if (xga->vc == xga->v_total) { + xga->vc = 0; + xga->sc = 0; + xga->dispon = 1; + xga->displine = (xga->interlace && xga->oddeven) ? 1 : 0; + + svga->x_add = (overscan_x >> 1); + + xga->hwcursor_on = 0; + xga->hwcursor_latch = xga->hwcursor; + } } } static uint8_t xga_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *)priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; - //pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); + // pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); return (xga->pos_regs[port & 7]); } static void xga_mca_write(int port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *)priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; /* MCA does not write registers below 0x0100. */ if (port < 0x0102) @@ -2631,32 +2607,35 @@ xga_mca_write(int port, uint8_t val, void *priv) mem_mapping_disable(&xga->bios_rom.mapping); mem_mapping_disable(&xga->memio_mapping); xga->on = 0; - vga_on = 1; + vga_on = 1; /* Save the MCA register value. */ xga->pos_regs[port & 7] = val; if (!(xga->pos_regs[4] & 1)) /*MCA 4MB addressing on systems with more than 16MB of memory*/ xga->pos_regs[4] |= 1; - //pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); if (xga->pos_regs[2] & 1) { - xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; + xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->base_addr_1mb = (xga->pos_regs[5] & 0x0f) << 20; - xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); - xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); + xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); + xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); - if ((port & 7) == 2) + + if (xga->pos_regs[3] & 1) { mem_mapping_set_addr(&xga->bios_rom.mapping, xga->rom_addr, 0x2000); - mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); + } else { + mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); + } } + // pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); } static uint8_t xga_mca_feedb(void *priv) { - svga_t *svga = (svga_t *)priv; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + xga_t *xga = &svga->xga; return xga->pos_regs[2] & 1; } @@ -2664,7 +2643,7 @@ xga_mca_feedb(void *priv) static void xga_mca_reset(void *p) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *) p; xga_mca_write(0x102, 0, svga); } @@ -2672,47 +2651,48 @@ xga_mca_reset(void *p) static uint8_t xga_pos_in(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *)priv; + svga_t *svga = (svga_t *) priv; return (xga_mca_read(addr, svga)); } static void -*xga_init(const device_t *info) + * + xga_init(const device_t *info) { - svga_t *svga = svga_get_pri(); - xga_t *xga = &svga->xga; - FILE *f; + svga_t *svga = svga_get_pri(); + xga_t *xga = &svga->xga; + FILE *f; uint32_t temp; uint32_t initial_bios_addr = device_get_config_hex20("init_bios_addr"); - uint8_t *rom = NULL; + uint8_t *rom = NULL; xga->type = device_get_config_int("type"); - xga->bus = info->flags; + xga->bus = info->flags; - xga->vram_size = (1024 << 10); - xga->vram_mask = xga->vram_size - 1; - xga->vram = calloc(xga->vram_size, 1); - xga->changedvram = calloc(xga->vram_size >> 12, 1); - xga->on = 0; - xga->hwcursor.cur_xsize = 64; - xga->hwcursor.cur_ysize = 64; - xga->bios_rom.sz = 0x2000; + xga->vram_size = (1024 << 10); + xga->vram_mask = xga->vram_size - 1; + xga->vram = calloc(xga->vram_size, 1); + xga->changedvram = calloc(xga->vram_size >> 12, 1); + xga->on = 0; + xga->hwcursor.cur_xsize = 64; + xga->hwcursor.cur_ysize = 64; + xga->bios_rom.sz = 0x2000; xga->linear_endian_reverse = 0; - xga->a5_test = 0; + xga->a5_test = 0; f = rom_fopen(xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, "rb"); - (void)fseek(f, 0L, SEEK_END); + (void) fseek(f, 0L, SEEK_END); temp = ftell(f); - (void)fseek(f, 0L, SEEK_SET); + (void) fseek(f, 0L, SEEK_SET); rom = malloc(xga->bios_rom.sz); memset(rom, 0xff, xga->bios_rom.sz); - (void)fread(rom, xga->bios_rom.sz, 1, f); + (void) fread(rom, xga->bios_rom.sz, 1, f); temp -= xga->bios_rom.sz; - (void)fclose(f); + (void) fclose(f); - xga->bios_rom.rom = rom; + xga->bios_rom.rom = rom; xga->bios_rom.mask = xga->bios_rom.sz - 1; if (f != NULL) { free(rom); @@ -2721,25 +2701,25 @@ static void xga->base_addr_1mb = 0; if (info->flags & DEVICE_MCA) { xga->linear_base = 0; - xga->instance = 0; - xga->rom_addr = 0; + xga->instance = 0; + xga->rom_addr = 0; rom_init(&xga->bios_rom, xga->type ? XGA2_BIOS_PATH : XGA_BIOS_PATH, initial_bios_addr, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); } else { xga->pos_regs[2] = 1 | 0x0c | 0xf0; - xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; + xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->pos_regs[4] = 1 | 2; xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); - xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); + xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); } mem_mapping_add(&xga->video_mapping, 0, 0, xga_readb, xga_readw, xga_readl, xga_writeb, xga_writew, xga_writel, NULL, MEM_MAPPING_EXTERNAL, svga); - mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, + mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, xga_write_linear, xga_writew_linear, xga_writel_linear, - NULL, MEM_MAPPING_EXTERNAL, svga); + NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&xga->memio_mapping, 0, 0, xga_memio_readb, xga_memio_readw, xga_memio_readl, - xga_memio_writeb, xga_memio_writew, xga_memio_writel, + xga_memio_writeb, xga_memio_writew, xga_memio_writel, xga->bios_rom.rom, MEM_MAPPING_EXTERNAL, svga); mem_mapping_disable(&xga->video_mapping); @@ -2763,8 +2743,8 @@ static void static void xga_close(void *p) { - svga_t *svga = (svga_t *)p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) p; + xga_t *xga = &svga->xga; if (svga) { free(xga->vram); @@ -2781,7 +2761,7 @@ xga_available(void) static void xga_speed_changed(void *p) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *) p; svga_recalctimings(svga); } @@ -2789,13 +2769,13 @@ xga_speed_changed(void *p) static void xga_force_redraw(void *p) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *) p; svga->fullchange = changeframecount; } static const device_config_t xga_configuration[] = { - // clang-format off + // clang-format off { .name = "init_bios_addr", .description = "Initial MCA BIOS Address (before POS configuration)", @@ -2836,35 +2816,35 @@ static const device_config_t xga_configuration[] = { } }, { .name = "", .description = "", .type = CONFIG_END } - // clang-format on +// clang-format on }; const device_t xga_device = { - .name = "XGA (MCA)", + .name = "XGA (MCA)", .internal_name = "xga_mca", - .flags = DEVICE_MCA, - .local = 0, - .init = xga_init, - .close = xga_close, - .reset = NULL, + .flags = DEVICE_MCA, + .local = 0, + .init = xga_init, + .close = xga_close, + .reset = NULL, { .available = xga_available }, .speed_changed = xga_speed_changed, - .force_redraw = xga_force_redraw, - .config = xga_configuration + .force_redraw = xga_force_redraw, + .config = xga_configuration }; const device_t xga_isa_device = { - .name = "XGA (ISA)", + .name = "XGA (ISA)", .internal_name = "xga_isa", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = xga_init, - .close = xga_close, - .reset = NULL, + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = xga_init, + .close = xga_close, + .reset = NULL, { .available = xga_available }, .speed_changed = xga_speed_changed, - .force_redraw = xga_force_redraw, - .config = xga_configuration + .force_redraw = xga_force_redraw, + .config = xga_configuration }; void From 3a77be3820f1077052f0856ef5611b1fee319b1d Mon Sep 17 00:00:00 2001 From: TC1995 Date: Tue, 6 Sep 2022 23:48:10 +0200 Subject: [PATCH 06/14] Clang-format fixes... --- src/video/vid_xga.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index e41430c86..b83d6467d 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -14,26 +14,26 @@ * * Copyright 2022 TheCollector1995. */ -#include "cpu.h" -#include <86box/86box.h> +#include +#include +#include +#include +#include #include <86box/bswap.h> -#include <86box/device.h> -#include <86box/dma.h> +#include <86box/86box.h> #include <86box/io.h> #include <86box/machine.h> -#include <86box/mca.h> #include <86box/mem.h> +#include <86box/dma.h> #include <86box/rom.h> +#include <86box/mca.h> +#include <86box/device.h> #include <86box/timer.h> +#include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> #include <86box/vid_xga_device.h> -#include <86box/video.h> -#include -#include -#include -#include -#include +#include "cpu.h" #define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" #define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" From 3d7fdf0eda0a8dd0f318e29974319ffe3a3f88a0 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Thu, 8 Sep 2022 11:19:37 -0400 Subject: [PATCH 07/14] qt: Fix searching for icon packs in roms dir --- src/qt/qt_progsettings.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 0b4f0e955..dcfdbab85 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -33,6 +33,8 @@ extern "C" #include <86box/version.h> #include <86box/config.h> #include <86box/plat.h> +#include <86box/mem.h> +#include <86box/rom.h> } @@ -43,24 +45,25 @@ ProgSettings::CustomTranslator* ProgSettings::translator = nullptr; QTranslator* ProgSettings::qtTranslator = nullptr; QString ProgSettings::getIconSetPath() { - QString roms_root; - if (rom_path[0]) - roms_root = rom_path; - else { - roms_root = QString("%1/roms").arg(exe_path); - } - - if (iconset_to_qt.isEmpty()) - { + if (iconset_to_qt.isEmpty()) { + QVector roms_dirs; + // Walk rom_paths to get the candidates + for (rom_path_t *emu_rom_path = &rom_paths; emu_rom_path != nullptr; emu_rom_path = emu_rom_path->next) { + roms_dirs.append(QFileInfo(emu_rom_path->path)); + } + // Always include default bundled icons iconset_to_qt.insert("", ":/settings/win/icons"); - QDir dir(roms_root + "/icons/"); - if (dir.isReadable()) - { - auto dirList = dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable); - for (auto &curIconSet : dirList) - { - if (curIconSet == "." || curIconSet == "..") continue; - iconset_to_qt.insert(curIconSet, (dir.canonicalPath() + '/') + curIconSet); + for (auto &checked_dir : roms_dirs) { + // Check for icons subdir in each candidate + QDir roms_icons_dir(checked_dir.filePath() + "/icons"); + if (roms_icons_dir.isReadable()) { + auto dirList = roms_icons_dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable); + for (auto &curIconSet : dirList) { + if (curIconSet == "." || curIconSet == "..") { + continue; + } + iconset_to_qt.insert(curIconSet, (roms_icons_dir.canonicalPath() + '/') + curIconSet); + } } } } From 2cdc63e83aed5da8e0d96ce275a55d2de0a34529 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 10 Sep 2022 14:53:00 +0600 Subject: [PATCH 08/14] 808x: Switch to __builtin_parity for parity flag setting --- src/cpu/808x.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/cpu/808x.c b/src/cpu/808x.c index 96b184bc4..219bb4b67 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -1310,25 +1310,7 @@ set_sf(int bits) static void set_pf(void) { - static uint8_t table[0x100] = { - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, - 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4}; - - cpu_state.flags = (cpu_state.flags & ~4) | table[cpu_data & 0xff]; + cpu_state.flags = (cpu_state.flags & ~4) | (!__builtin_parity(cpu_data & 0xFF) << 2); } From 7dd8c96ffc34ccd8e80681caa219800da2f0d77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 10 Sep 2022 13:32:46 +0200 Subject: [PATCH 09/14] config: Refactor the INI parser out --- src/CMakeLists.txt | 2 +- src/config.c | 1802 +++++++++++------------------------- src/device.c | 1 + src/include/86box/config.h | 44 +- src/include/86box/ini.h | 81 ++ src/ini.c | 795 ++++++++++++++++ src/network/net_slirp.c | 1 + src/qt/qt_deviceconfig.cpp | 1 + src/sound/midi_rtmidi.cpp | 1 + 9 files changed, 1446 insertions(+), 1282 deletions(-) create mode 100644 src/include/86box/ini.h create mode 100644 src/ini.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 01de9a473..18302d6fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ endif() add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c dma.c ddma.c discord.c nmi.c pic.c pit.c pit_fast.c port_6x.c port_92.c ppi.c pci.c - mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c machine_status.c) + mca.c usb.c fifo8.c device.c nvr.c nvr_at.c nvr_ps2.c machine_status.c ini.c) if(CMAKE_SYSTEM_NAME MATCHES "Linux") add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1) diff --git a/src/config.c b/src/config.c index 0cc782854..01710ebc4 100644 --- a/src/config.c +++ b/src/config.c @@ -41,6 +41,7 @@ #include <86box/cassette.h> #include <86box/cartridge.h> #include <86box/nvr.h> +#include <86box/ini.h> #include <86box/config.h> #include <86box/isamem.h> #include <86box/isartc.h> @@ -74,53 +75,7 @@ static int cx, cy, cw, ch; - - -typedef struct _list_ { - struct _list_ *next; -} list_t; - -typedef struct { - list_t list; - - char name[128]; - - list_t entry_head; -} section_t; - -typedef struct { - list_t list; - - char name[128]; - char data[512]; - wchar_t wdata[512]; -} entry_t; - -#define list_add(new, head) \ - { \ - list_t *next = head; \ - \ - while (next->next != NULL) \ - next = next->next; \ - \ - (next)->next = new; \ - (new)->next = NULL; \ - } - -#define list_delete(old, head) \ - { \ - list_t *next = head; \ - \ - while ((next)->next != old) { \ - next = (next)->next; \ - } \ - \ - (next)->next = (old)->next; \ - if ((next) == (head)) \ - (head)->next = (old)->next; \ - } - -static list_t config_head; +static ini_t config; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ static int backwards_compat = 0; @@ -144,432 +99,55 @@ config_log(const char *fmt, ...) # define config_log(fmt, ...) #endif -static section_t * -find_section(char *name) -{ - section_t *sec; - char blank[] = ""; - - sec = (section_t *) config_head.next; - if (name == NULL) - name = blank; - - while (sec != NULL) { - if (!strncmp(sec->name, name, sizeof(sec->name))) - return (sec); - - sec = (section_t *) sec->list.next; - } - - return (NULL); -} - -void * -config_find_section(char *name) -{ - return (void *) find_section(name); -} - -void -config_rename_section(void *priv, char *name) -{ - section_t *sec = (section_t *) priv; - - memset(sec->name, 0x00, sizeof(sec->name)); - memcpy(sec->name, name, MIN(128, strlen(name) + 1)); -} - -static entry_t * -find_entry(section_t *section, char *name) -{ - entry_t *ent; - - ent = (entry_t *) section->entry_head.next; - - while (ent != NULL) { - if (!strncmp(ent->name, name, sizeof(ent->name))) - return (ent); - - ent = (entry_t *) ent->list.next; - } - - return (NULL); -} - -static int -entries_num(section_t *section) -{ - entry_t *ent; - int i = 0; - - ent = (entry_t *) section->entry_head.next; - - while (ent != NULL) { - if (strlen(ent->name) > 0) - i++; - - ent = (entry_t *) ent->list.next; - } - - return (i); -} - -static void -delete_section_if_empty(char *head) -{ - section_t *section; - - section = find_section(head); - if (section == NULL) - return; - - if (entries_num(section) == 0) { - list_delete(§ion->list, &config_head); - free(section); - } -} - -static section_t * -create_section(char *name) -{ - section_t *ns = malloc(sizeof(section_t)); - - memset(ns, 0x00, sizeof(section_t)); - memcpy(ns->name, name, strlen(name) + 1); - list_add(&ns->list, &config_head); - - return (ns); -} - -static entry_t * -create_entry(section_t *section, char *name) -{ - entry_t *ne = malloc(sizeof(entry_t)); - - memset(ne, 0x00, sizeof(entry_t)); - memcpy(ne->name, name, strlen(name) + 1); - list_add(&ne->list, §ion->entry_head); - - return (ne); -} - -#if 0 -static void -config_free(void) -{ - section_t *sec, *ns; - entry_t *ent; - - sec = (section_t *)config_head.next; - while (sec != NULL) { - ns = (section_t *)sec->list.next; - ent = (entry_t *)sec->entry_head.next; - - while (ent != NULL) { - entry_t *nent = (entry_t *)ent->list.next; - - free(ent); - ent = nent; - } - - free(sec); - sec = ns; - } -} -#endif - -static int -config_detect_bom(char *fn) -{ - FILE *f; - unsigned char bom[4] = { 0, 0, 0, 0 }; - -#if defined(ANSI_CFG) || !defined(_WIN32) - f = plat_fopen(fn, "rt"); -#else - f = plat_fopen(fn, "rt, ccs=UTF-8"); -#endif - if (f == NULL) - return (0); - (void) !fread(bom, 1, 3, f); - if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { - fclose(f); - return 1; - } - fclose(f); - return 0; -} - -#ifdef __HAIKU__ -/* Local version of fgetws to avoid a crash */ -static wchar_t * -config_fgetws(wchar_t *str, int count, FILE *stream) -{ - int i = 0; - if (feof(stream)) - return NULL; - for (i = 0; i < count; i++) { - wint_t curChar = fgetwc(stream); - if (curChar == WEOF) { - if (i + 1 < count) - str[i + 1] = 0; - return feof(stream) ? str : NULL; - } - str[i] = curChar; - if (curChar == '\n') - break; - } - if (i + 1 < count) - str[i + 1] = 0; - return str; -} -#endif - -/* Read and parse the configuration file into memory. */ -static int -config_read(char *fn) -{ - char sname[128], ename[128]; - wchar_t buff[1024]; - section_t *sec, *ns; - entry_t *ne; - int c, d, bom; - FILE *f; - - bom = config_detect_bom(fn); -#if defined(ANSI_CFG) || !defined(_WIN32) - f = plat_fopen(fn, "rt"); -#else - f = plat_fopen(fn, "rt, ccs=UTF-8"); -#endif - if (f == NULL) - return (0); - - sec = malloc(sizeof(section_t)); - memset(sec, 0x00, sizeof(section_t)); - memset(&config_head, 0x00, sizeof(list_t)); - list_add(&sec->list, &config_head); - if (bom) - fseek(f, 3, SEEK_SET); - - while (1) { - memset(buff, 0x00, sizeof(buff)); -#ifdef __HAIKU__ - config_fgetws(buff, sizeof_w(buff), f); -#else - (void) !fgetws(buff, sizeof_w(buff), f); -#endif - if (feof(f)) - break; - - /* Make sure there are no stray newlines or hard-returns in there. */ - if (wcslen(buff) > 0) - if (buff[wcslen(buff) - 1] == L'\n') - buff[wcslen(buff) - 1] = L'\0'; - if (wcslen(buff) > 0) - if (buff[wcslen(buff) - 1] == L'\r') - buff[wcslen(buff) - 1] = L'\0'; - - /* Skip any leading whitespace. */ - c = 0; - while ((buff[c] == L' ') || (buff[c] == L'\t')) - c++; - - /* Skip empty lines. */ - if (buff[c] == L'\0') - continue; - - /* Skip lines that (only) have a comment. */ - if ((buff[c] == L'#') || (buff[c] == L';')) - continue; - - if (buff[c] == L'[') { /*Section*/ - c++; - d = 0; - while (buff[c] != L']' && buff[c]) - (void) !wctomb(&(sname[d++]), buff[c++]); - sname[d] = L'\0'; - - /* Is the section name properly terminated? */ - if (buff[c] != L']') - continue; - - /* Create a new section and insert it. */ - ns = malloc(sizeof(section_t)); - memset(ns, 0x00, sizeof(section_t)); - memcpy(ns->name, sname, 128); - list_add(&ns->list, &config_head); - - /* New section is now the current one. */ - sec = ns; - continue; - } - - /* Get the variable name. */ - d = 0; - while ((buff[c] != L'=') && (buff[c] != L' ') && buff[c]) - (void) !wctomb(&(ename[d++]), buff[c++]); - ename[d] = L'\0'; - - /* Skip incomplete lines. */ - if (buff[c] == L'\0') - continue; - - /* Look for =, skip whitespace. */ - while ((buff[c] == L'=' || buff[c] == L' ') && buff[c]) - c++; - - /* Skip incomplete lines. */ - if (buff[c] == L'\0') - continue; - - /* This is where the value part starts. */ - d = c; - - /* Allocate a new variable entry.. */ - ne = malloc(sizeof(entry_t)); - memset(ne, 0x00, sizeof(entry_t)); - memcpy(ne->name, ename, 128); - wcsncpy(ne->wdata, &buff[d], sizeof_w(ne->wdata) - 1); - ne->wdata[sizeof_w(ne->wdata) - 1] = L'\0'; -#ifdef _WIN32 /* Make sure the string is converted to UTF-8 rather than a legacy codepage */ - c16stombs(ne->data, ne->wdata, sizeof(ne->data)); -#else - wcstombs(ne->data, ne->wdata, sizeof(ne->data)); -#endif - ne->data[sizeof(ne->data) - 1] = '\0'; - - /* .. and insert it. */ - list_add(&ne->list, &sec->entry_head); - } - - (void) fclose(f); - - if (do_dump_config) - config_dump(); - - return (1); -} - -/* - * Write the in-memory configuration to disk. - * This is a public function, because the Settings UI - * want to directly write the configuration after it - * has changed it. - */ -void -config_write(char *fn) -{ - wchar_t wtemp[512]; - section_t *sec; - FILE *f; - int fl = 0; - -#if defined(ANSI_CFG) || !defined(_WIN32) - f = plat_fopen(fn, "wt"); -#else - f = plat_fopen(fn, "wt, ccs=UTF-8"); -#endif - if (f == NULL) - return; - - sec = (section_t *) config_head.next; - while (sec != NULL) { - entry_t *ent; - - if (sec->name[0]) { - mbstowcs(wtemp, sec->name, strlen(sec->name) + 1); - if (fl) - fwprintf(f, L"\n[%ls]\n", wtemp); - else - fwprintf(f, L"[%ls]\n", wtemp); - fl++; - } - - ent = (entry_t *) sec->entry_head.next; - while (ent != NULL) { - if (ent->name[0] != '\0') { - mbstowcs(wtemp, ent->name, 128); - if (ent->wdata[0] == L'\0') - fwprintf(f, L"%ls = \n", wtemp); - else - fwprintf(f, L"%ls = %ls\n", wtemp, ent->wdata); - fl++; - } - - ent = (entry_t *) ent->list.next; - } - - sec = (section_t *) sec->list.next; - } - - (void) fclose(f); -} - -#if NOT_USED -static void -config_new(void) -{ -# if defined(ANSI_CFG) || !defined(_WIN32) - FILE *f = _wfopen(config_file, L"wt"); -# else - FILE *f = _wfopen(config_file, L"wt, ccs=UTF-8"); -# endif - - if (file != NULL) - (void) fclose(f); -} -#endif - /* Load "General" section. */ static void load_general(void) { - char *cat = "General"; + ini_section_t cat = ini_find_section(config, "General"); char temp[512]; char *p; - vid_resize = config_get_int(cat, "vid_resize", 0); + vid_resize = ini_section_get_int(cat, "vid_resize", 0); if (vid_resize & ~3) vid_resize &= 3; memset(temp, '\0', sizeof(temp)); - p = config_get_string(cat, "vid_renderer", "default"); + p = ini_section_get_string(cat, "vid_renderer", "default"); vid_api = plat_vidapi(p); - config_delete_var(cat, "vid_api"); + ini_section_delete_var(cat, "vid_api"); - video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0); + video_fullscreen_scale = ini_section_get_int(cat, "video_fullscreen_scale", 0); - video_fullscreen_first = config_get_int(cat, "video_fullscreen_first", 1); + video_fullscreen_first = ini_section_get_int(cat, "video_fullscreen_first", 1); - video_filter_method = config_get_int(cat, "video_filter_method", 1); + video_filter_method = ini_section_get_int(cat, "video_filter_method", 1); - force_43 = !!config_get_int(cat, "force_43", 0); - scale = config_get_int(cat, "scale", 1); + force_43 = !!ini_section_get_int(cat, "force_43", 0); + scale = ini_section_get_int(cat, "scale", 1); if (scale > 3) scale = 3; - dpi_scale = config_get_int(cat, "dpi_scale", 1); + dpi_scale = ini_section_get_int(cat, "dpi_scale", 1); - enable_overscan = !!config_get_int(cat, "enable_overscan", 0); - vid_cga_contrast = !!config_get_int(cat, "vid_cga_contrast", 0); - video_grayscale = config_get_int(cat, "video_grayscale", 0); - video_graytype = config_get_int(cat, "video_graytype", 0); + enable_overscan = !!ini_section_get_int(cat, "enable_overscan", 0); + vid_cga_contrast = !!ini_section_get_int(cat, "vid_cga_contrast", 0); + video_grayscale = ini_section_get_int(cat, "video_grayscale", 0); + video_graytype = ini_section_get_int(cat, "video_graytype", 0); - rctrl_is_lalt = config_get_int(cat, "rctrl_is_lalt", 0); - update_icons = config_get_int(cat, "update_icons", 1); + rctrl_is_lalt = ini_section_get_int(cat, "rctrl_is_lalt", 0); + update_icons = ini_section_get_int(cat, "update_icons", 1); - window_remember = config_get_int(cat, "window_remember", 0); + window_remember = ini_section_get_int(cat, "window_remember", 0); if (window_remember || (vid_resize & 2)) { if (!window_remember) - config_delete_var(cat, "window_remember"); + ini_section_delete_var(cat, "window_remember"); } else { - config_delete_var(cat, "window_remember"); + ini_section_delete_var(cat, "window_remember"); window_w = window_h = window_x = window_y = 0; } if (vid_resize & 2) { - p = config_get_string(cat, "window_fixed_res", NULL); + p = ini_section_get_string(cat, "window_fixed_res", NULL); if (p == NULL) p = "120x120"; sscanf(p, "%ix%i", &fixed_size_x, &fixed_size_y); @@ -582,70 +160,73 @@ load_general(void) if (fixed_size_y > 2048) fixed_size_y = 2048; } else { - config_delete_var(cat, "window_fixed_res"); + ini_section_delete_var(cat, "window_fixed_res"); fixed_size_x = fixed_size_y = 120; } - sound_gain = config_get_int(cat, "sound_gain", 0); + sound_gain = ini_section_get_int(cat, "sound_gain", 0); - kbd_req_capture = config_get_int(cat, "kbd_req_capture", 0); - hide_status_bar = config_get_int(cat, "hide_status_bar", 0); - hide_tool_bar = config_get_int(cat, "hide_tool_bar", 0); + kbd_req_capture = ini_section_get_int(cat, "kbd_req_capture", 0); + hide_status_bar = ini_section_get_int(cat, "hide_status_bar", 0); + hide_tool_bar = ini_section_get_int(cat, "hide_tool_bar", 0); - confirm_reset = config_get_int(cat, "confirm_reset", 1); - confirm_exit = config_get_int(cat, "confirm_exit", 1); - confirm_save = config_get_int(cat, "confirm_save", 1); + confirm_reset = ini_section_get_int(cat, "confirm_reset", 1); + confirm_exit = ini_section_get_int(cat, "confirm_exit", 1); + confirm_save = ini_section_get_int(cat, "confirm_save", 1); - p = config_get_string(cat, "language", NULL); + p = ini_section_get_string(cat, "language", NULL); if (p != NULL) lang_id = plat_language_code(p); - mouse_sensitivity = config_get_double(cat, "mouse_sensitivity", 1.0); + mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0); if (mouse_sensitivity < 0.5) mouse_sensitivity = 0.5; else if (mouse_sensitivity > 2.0) mouse_sensitivity = 2.0; - p = config_get_string(cat, "iconset", NULL); + p = ini_section_get_string(cat, "iconset", NULL); if (p != NULL) strcpy(icon_set, p); else strcpy(icon_set, ""); - enable_discord = !!config_get_int(cat, "enable_discord", 0); + enable_discord = !!ini_section_get_int(cat, "enable_discord", 0); - open_dir_usr_path = config_get_int(cat, "open_dir_usr_path", 0); + open_dir_usr_path = ini_section_get_int(cat, "open_dir_usr_path", 0); - video_framerate = config_get_int(cat, "video_gl_framerate", -1); - video_vsync = config_get_int(cat, "video_gl_vsync", 0); - strncpy(video_shader, config_get_string(cat, "video_gl_shader", ""), sizeof(video_shader)); + video_framerate = ini_section_get_int(cat, "video_gl_framerate", -1); + video_vsync = ini_section_get_int(cat, "video_gl_vsync", 0); + strncpy(video_shader, ini_section_get_string(cat, "video_gl_shader", ""), sizeof(video_shader)); - window_remember = config_get_int(cat, "window_remember", 0); + window_remember = ini_section_get_int(cat, "window_remember", 0); if (window_remember) { - p = config_get_string(cat, "window_coordinates", NULL); + p = ini_section_get_string(cat, "window_coordinates", NULL); if (p == NULL) p = "0, 0, 0, 0"; sscanf(p, "%i, %i, %i, %i", &cw, &ch, &cx, &cy); } else { cw = ch = cx = cy = 0; - config_delete_var(cat, "window_remember"); + ini_section_delete_var(cat, "window_remember"); } - config_delete_var(cat, "window_coordinates"); + ini_section_delete_var(cat, "window_coordinates"); } /* Load monitor section. */ static void load_monitor(int monitor_index) { - char cat[512], temp[512]; + ini_section_t cat; + char name[512], temp[512]; char *p = NULL; - sprintf(cat, "Monitor #%i", monitor_index + 1); + sprintf(name, "Monitor #%i", monitor_index + 1); sprintf(temp, "%i, %i, %i, %i", cx, cy, cw, ch); - p = config_get_string(cat, "window_coordinates", NULL); + cat = ini_find_section(config, name); + + p = ini_section_get_string(cat, "window_coordinates", NULL); if (p == NULL) p = temp; @@ -654,7 +235,7 @@ load_monitor(int monitor_index) sscanf(p, "%i, %i, %i, %i", &monitor_settings[monitor_index].mon_window_x, &monitor_settings[monitor_index].mon_window_y, &monitor_settings[monitor_index].mon_window_w, &monitor_settings[monitor_index].mon_window_h); - monitor_settings[monitor_index].mon_window_maximized = !!config_get_int(cat, "window_maximized", 0); + monitor_settings[monitor_index].mon_window_maximized = !!ini_section_get_int(cat, "window_maximized", 0); } else { monitor_settings[monitor_index].mon_window_maximized = 0; } @@ -664,12 +245,12 @@ load_monitor(int monitor_index) static void load_machine(void) { - char *cat = "Machine"; + ini_section_t cat = ini_find_section(config, "Machine"); char *p, *migrate_from = NULL; int c, i, j, speed, legacy_mfg, legacy_cpu; double multi; - p = config_get_string(cat, "machine", NULL); + p = ini_section_get_string(cat, "machine", NULL); if (p != NULL) { migrate_from = p; if (!strcmp(p, "8500ttc")) /* migrate typo... */ @@ -754,7 +335,7 @@ load_machine(void) machine = 0; /* This is for backwards compatibility. */ - p = config_get_string(cat, "model", NULL); + p = ini_section_get_string(cat, "model", NULL); if (p != NULL) { migrate_from = p; if (!strcmp(p, "p55r2p4")) /* migrate typo */ @@ -763,7 +344,7 @@ load_machine(void) machine = machine_get_machine_from_internal_name(p); migrate_from = NULL; } - config_delete_var(cat, "model"); + ini_section_delete_var(cat, "model"); } if (machine >= machine_count()) machine = machine_count() - 1; @@ -808,9 +389,9 @@ load_machine(void) } } - cpu_override = config_get_int(cat, "cpu_override", 0); + cpu_override = ini_section_get_int(cat, "cpu_override", 0); cpu_f = NULL; - p = config_get_string(cat, "cpu_family", NULL); + p = ini_section_get_string(cat, "cpu_family", NULL); if (p) { if (!strcmp(p, "enh_am486dx2")) /* migrate modified names */ cpu_f = cpu_get_family("am486dx2_slenh"); @@ -823,8 +404,8 @@ load_machine(void) cpu_f = NULL; } else { /* Backwards compatibility with the previous CPU model system. */ - legacy_mfg = config_get_int(cat, "cpu_manufacturer", 0); - legacy_cpu = config_get_int(cat, "cpu", 0); + legacy_mfg = ini_section_get_int(cat, "cpu_manufacturer", 0); + legacy_cpu = ini_section_get_int(cat, "cpu", 0); /* Check if either legacy ID is present, and if they are within bounds. */ if (((legacy_mfg > 0) || (legacy_cpu > 0)) && (legacy_mfg >= 0) && (legacy_mfg < 4) && (legacy_cpu >= 0)) { @@ -852,17 +433,17 @@ load_machine(void) cpu_f = cpu_get_family(legacy_table_entry->family); if (cpu_f) { /* Save the new values. */ - config_set_string(cat, "cpu_family", (char *) legacy_table_entry->family); - config_set_int(cat, "cpu_speed", legacy_table_entry->rspeed); - config_set_double(cat, "cpu_multi", legacy_table_entry->multi); + ini_section_set_string(cat, "cpu_family", (char *) legacy_table_entry->family); + ini_section_set_int(cat, "cpu_speed", legacy_table_entry->rspeed); + ini_section_set_double(cat, "cpu_multi", legacy_table_entry->multi); } } } } if (cpu_f) { - speed = config_get_int(cat, "cpu_speed", 0); - multi = config_get_double(cat, "cpu_multi", 0); + speed = ini_section_get_int(cat, "cpu_speed", 0); + multi = ini_section_get_double(cat, "cpu_multi", 0); /* Find the configured CPU. */ cpu = 0; @@ -902,12 +483,12 @@ load_machine(void) } cpu_s = (CPU *) &cpu_f->cpus[cpu]; - cpu_waitstates = config_get_int(cat, "cpu_waitstates", 0); + cpu_waitstates = ini_section_get_int(cat, "cpu_waitstates", 0); - p = (char *) config_get_string(cat, "fpu_type", "none"); + p = (char *) ini_section_get_string(cat, "fpu_type", "none"); fpu_type = fpu_get_type(cpu_f, cpu, p); - mem_size = config_get_int(cat, "mem_size", 64); + mem_size = ini_section_get_int(cat, "mem_size", 64); #if 0 if (mem_size < ((machine_has_bus(machine, MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram)) @@ -917,9 +498,9 @@ load_machine(void) if (mem_size > 2097152) mem_size = 2097152; - cpu_use_dynarec = !!config_get_int(cat, "cpu_use_dynarec", 0); + cpu_use_dynarec = !!ini_section_get_int(cat, "cpu_use_dynarec", 0); - p = config_get_string(cat, "time_sync", NULL); + p = ini_section_get_string(cat, "time_sync", NULL); if (p != NULL) { if (!strcmp(p, "disabled")) time_sync = TIME_SYNC_DISABLED; @@ -930,28 +511,28 @@ load_machine(void) else time_sync = TIME_SYNC_ENABLED; } else - time_sync = !!config_get_int(cat, "enable_sync", 1); + time_sync = !!ini_section_get_int(cat, "enable_sync", 1); - pit_mode = config_get_int(cat, "pit_mode", -1); + pit_mode = ini_section_get_int(cat, "pit_mode", -1); /* Remove this after a while.. */ - config_delete_var(cat, "nvr_path"); - config_delete_var(cat, "enable_sync"); + ini_section_delete_var(cat, "nvr_path"); + ini_section_delete_var(cat, "enable_sync"); } /* Load "Video" section. */ static void load_video(void) { - char *cat = "Video"; + ini_section_t cat = ini_find_section(config, "Video"); char *p; int free_p = 0; if (machine_has_flags(machine, MACHINE_VIDEO_ONLY)) { - config_delete_var(cat, "gfxcard"); + ini_section_delete_var(cat, "gfxcard"); gfxcard = VID_INTERNAL; } else { - p = config_get_string(cat, "gfxcard", NULL); + p = ini_section_get_string(cat, "gfxcard", NULL); if (p == NULL) { if (machine_has_flags(machine, MACHINE_VIDEO)) { p = (char *) malloc((strlen("internal") + 1) * sizeof(char)); @@ -970,13 +551,13 @@ load_video(void) free(p); } - voodoo_enabled = !!config_get_int(cat, "voodoo", 0); - ibm8514_enabled = !!config_get_int(cat, "8514a", 0); - xga_enabled = !!config_get_int(cat, "xga", 0); - show_second_monitors = !!config_get_int(cat, "show_second_monitors", 1); - video_fullscreen_scale_maximized = !!config_get_int(cat, "video_fullscreen_scale_maximized", 0); + voodoo_enabled = !!ini_section_get_int(cat, "voodoo", 0); + ibm8514_enabled = !!ini_section_get_int(cat, "8514a", 0); + xga_enabled = !!ini_section_get_int(cat, "xga", 0); + show_second_monitors = !!ini_section_get_int(cat, "show_second_monitors", 1); + video_fullscreen_scale_maximized = !!ini_section_get_int(cat, "video_fullscreen_scale_maximized", 0); - p = config_get_string(cat, "gfxcard_2", NULL); + p = ini_section_get_string(cat, "gfxcard_2", NULL); if (!p) p = "none"; gfxcard_2 = video_get_video_from_internal_name(p); @@ -986,18 +567,18 @@ load_video(void) static void load_input_devices(void) { - char *cat = "Input devices"; + ini_section_t cat = ini_find_section(config, "Input devices"); char temp[512]; int c, d; char *p; - p = config_get_string(cat, "mouse_type", NULL); + p = ini_section_get_string(cat, "mouse_type", NULL); if (p != NULL) mouse_type = mouse_get_from_internal_name(p); else mouse_type = 0; - p = config_get_string(cat, "joystick_type", NULL); + p = ini_section_get_string(cat, "joystick_type", NULL); if (p != NULL) { if (!strcmp(p, "standard_2button")) /* migrate renamed types */ joystick_type = joystick_get_from_internal_name("2axis_2button"); @@ -1014,10 +595,10 @@ load_input_devices(void) if (!joystick_type) { /* Try to read an integer for backwards compatibility with old configs */ - if (!strcmp(p, "0")) /* workaround for config_get_int returning 0 on non-integer data */ + if (!strcmp(p, "0")) /* workaround for ini_section_get_int returning 0 on non-integer data */ joystick_type = joystick_get_from_internal_name("2axis_2button"); else { - c = config_get_int(cat, "joystick_type", 8); + c = ini_section_get_int(cat, "joystick_type", 8); switch (c) { case 1: joystick_type = joystick_get_from_internal_name("2axis_4button"); @@ -1051,20 +632,20 @@ load_input_devices(void) for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { sprintf(temp, "joystick_%i_nr", c); - joystick_state[c].plat_joystick_nr = config_get_int(cat, temp, 0); + joystick_state[c].plat_joystick_nr = ini_section_get_int(cat, temp, 0); if (joystick_state[c].plat_joystick_nr) { for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { sprintf(temp, "joystick_%i_axis_%i", c, d); - joystick_state[c].axis_mapping[d] = config_get_int(cat, temp, d); + joystick_state[c].axis_mapping[d] = ini_section_get_int(cat, temp, d); } for (d = 0; d < joystick_get_button_count(joystick_type); d++) { sprintf(temp, "joystick_%i_button_%i", c, d); - joystick_state[c].button_mapping[d] = config_get_int(cat, temp, d); + joystick_state[c].button_mapping[d] = ini_section_get_int(cat, temp, d); } for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { sprintf(temp, "joystick_%i_pov_%i", c, d); - p = config_get_string(cat, temp, "0, 0"); + p = ini_section_get_string(cat, temp, "0, 0"); joystick_state[c].pov_mapping[d][0] = joystick_state[c].pov_mapping[d][1] = 0; sscanf(p, "%i, %i", &joystick_state[c].pov_mapping[d][0], &joystick_state[c].pov_mapping[d][1]); } @@ -1076,11 +657,11 @@ load_input_devices(void) static void load_sound(void) { - char *cat = "Sound"; + ini_section_t cat = ini_find_section(config, "Sound"); char temp[512]; char *p; - p = config_get_string(cat, "sndcard", NULL); + p = ini_section_get_string(cat, "sndcard", NULL); /* FIXME: Hack to not break configs with the Sound Blaster 128 PCI set. */ if ((p != NULL) && (!strcmp(p, "sbpci128") || !strcmp(p, "sb128pci"))) p = "es1371"; @@ -1089,26 +670,26 @@ load_sound(void) else sound_card_current = 0; - p = config_get_string(cat, "midi_device", NULL); + p = ini_section_get_string(cat, "midi_device", NULL); if (p != NULL) midi_output_device_current = midi_out_device_get_from_internal_name(p); else midi_output_device_current = 0; - p = config_get_string(cat, "midi_in_device", NULL); + p = ini_section_get_string(cat, "midi_in_device", NULL); if (p != NULL) midi_input_device_current = midi_in_device_get_from_internal_name(p); else midi_input_device_current = 0; - mpu401_standalone_enable = !!config_get_int(cat, "mpu401_standalone", 0); + mpu401_standalone_enable = !!ini_section_get_int(cat, "mpu401_standalone", 0); - SSI2001 = !!config_get_int(cat, "ssi2001", 0); - GAMEBLASTER = !!config_get_int(cat, "gameblaster", 0); - GUS = !!config_get_int(cat, "gus", 0); + SSI2001 = !!ini_section_get_int(cat, "ssi2001", 0); + GAMEBLASTER = !!ini_section_get_int(cat, "gameblaster", 0); + GUS = !!ini_section_get_int(cat, "gus", 0); memset(temp, '\0', sizeof(temp)); - p = config_get_string(cat, "sound_type", "float"); + p = ini_section_get_string(cat, "sound_type", "float"); if (strlen(p) > 511) fatal("load_sound(): strlen(p) > 511\n"); else @@ -1118,7 +699,7 @@ load_sound(void) else sound_is_float = 0; - p = config_get_string(cat, "fm_driver", "nuked"); + p = ini_section_get_string(cat, "fm_driver", "nuked"); if (!strcmp(p, "ymfm")) { fm_driver = FM_DRV_YMFM; } else { @@ -1130,17 +711,17 @@ load_sound(void) static void load_network(void) { - char *cat = "Network"; + ini_section_t cat = ini_find_section(config, "Network"); char *p; char temp[512]; int c = 0, min = 0; /* Handle legacy configuration which supported only one NIC */ - p = config_get_string(cat, "net_card", NULL); + p = ini_section_get_string(cat, "net_card", NULL); if (p != NULL) { net_cards_conf[c].device_num = network_card_get_from_internal_name(p); - p = config_get_string(cat, "net_type", NULL); + p = ini_section_get_string(cat, "net_type", NULL); if (p != NULL) { if (!strcmp(p, "pcap") || !strcmp(p, "1")) net_cards_conf[c].net_type = NET_TYPE_PCAP; @@ -1152,7 +733,7 @@ load_network(void) net_cards_conf[c].net_type = NET_TYPE_NONE; } - p = config_get_string(cat, "net_host_device", NULL); + p = ini_section_get_string(cat, "net_host_device", NULL); if (p != NULL) { if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { if (network_ndev == 1) { @@ -1171,13 +752,13 @@ load_network(void) min++; } - config_delete_var(cat, "net_card"); - config_delete_var(cat, "net_type"); - config_delete_var(cat, "net_host_device"); + ini_section_delete_var(cat, "net_card"); + ini_section_delete_var(cat, "net_type"); + ini_section_delete_var(cat, "net_host_device"); for (c = min; c < NET_CARD_MAX; c++) { sprintf(temp, "net_%02i_card", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) { net_cards_conf[c].device_num = network_card_get_from_internal_name(p); } else { @@ -1185,7 +766,7 @@ load_network(void) } sprintf(temp, "net_%02i_net_type", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) { if (!strcmp(p, "pcap") || !strcmp(p, "1")) { net_cards_conf[c].net_type = NET_TYPE_PCAP; @@ -1199,7 +780,7 @@ load_network(void) } sprintf(temp, "net_%02i_host_device", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) { if ((network_dev_to_id(p) == -1) || (network_ndev == 1)) { if (network_ndev == 1) { @@ -1216,7 +797,7 @@ load_network(void) } sprintf(temp, "net_%02i_link", c +1); - net_cards_conf[c].link_state = config_get_int(cat, temp, + net_cards_conf[c].link_state = ini_section_get_int(cat, temp, (NET_LINK_10_HD|NET_LINK_10_FD|NET_LINK_100_HD|NET_LINK_100_FD|NET_LINK_1000_HD|NET_LINK_1000_FD)); } @@ -1226,77 +807,77 @@ load_network(void) static void load_ports(void) { - char *cat = "Ports (COM & LPT)"; + ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)"); char *p; char temp[512]; int c, d; for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); - com_ports[c].enabled = !!config_get_int(cat, temp, (c >= 2) ? 0 : 1); + com_ports[c].enabled = !!ini_section_get_int(cat, temp, (c >= 2) ? 0 : 1); /* sprintf(temp, "serial%d_device", c + 1); - p = (char *) config_get_string(cat, temp, "none"); + p = (char *) ini_section_get_string(cat, temp, "none"); com_ports[c].device = com_device_get_from_internal_name(p); */ } for (c = 0; c < PARALLEL_MAX; c++) { sprintf(temp, "lpt%d_enabled", c + 1); - lpt_ports[c].enabled = !!config_get_int(cat, temp, (c == 0) ? 1 : 0); + lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); sprintf(temp, "lpt%d_device", c + 1); - p = (char *) config_get_string(cat, temp, "none"); + p = (char *) ini_section_get_string(cat, temp, "none"); lpt_ports[c].device = lpt_device_get_from_internal_name(p); } /* Legacy config compatibility. */ - d = config_get_int(cat, "lpt_enabled", 2); + d = ini_section_get_int(cat, "lpt_enabled", 2); if (d < 2) { for (c = 0; c < PARALLEL_MAX; c++) lpt_ports[c].enabled = d; } - config_delete_var(cat, "lpt_enabled"); + ini_section_delete_var(cat, "lpt_enabled"); } /* Load "Storage Controllers" section. */ static void load_storage_controllers(void) { - char *cat = "Storage controllers"; + ini_section_t cat = ini_find_section(config, "Storage controllers"); char *p, temp[512]; int c, min = 0; int free_p = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ - backwards_compat2 = (find_section(cat) == NULL); + backwards_compat2 = (cat == NULL); /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ - p = config_get_string(cat, "scsicard", NULL); + p = ini_section_get_string(cat, "scsicard", NULL); if (p != NULL) { scsi_card_current[0] = scsi_card_get_from_internal_name(p); min++; } - config_delete_var(cat, "scsi_card"); + ini_section_delete_var(cat, "scsi_card"); for (c = min; c < SCSI_BUS_MAX; c++) { sprintf(temp, "scsicard_%d", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) scsi_card_current[c] = scsi_card_get_from_internal_name(p); else scsi_card_current[c] = 0; } - p = config_get_string(cat, "fdc", NULL); + p = ini_section_get_string(cat, "fdc", NULL); if (p != NULL) fdc_type = fdc_card_get_from_internal_name(p); else fdc_type = FDC_INTERNAL; - p = config_get_string(cat, "hdc", NULL); + p = ini_section_get_string(cat, "hdc", NULL); if (p == NULL) { if (machine_has_flags(machine, MACHINE_HDC)) { p = (char *) malloc((strlen("internal") + 1) * sizeof(char)); @@ -1325,30 +906,30 @@ load_storage_controllers(void) p = NULL; } - ide_ter_enabled = !!config_get_int(cat, "ide_ter", 0); - ide_qua_enabled = !!config_get_int(cat, "ide_qua", 0); + ide_ter_enabled = !!ini_section_get_int(cat, "ide_ter", 0); + ide_qua_enabled = !!ini_section_get_int(cat, "ide_qua", 0); /* TODO: Re-enable by default after we actually have a proper machine flag for this. */ - cassette_enable = !!config_get_int(cat, "cassette_enabled", 0); - p = config_get_string(cat, "cassette_file", ""); + cassette_enable = !!ini_section_get_int(cat, "cassette_enabled", 0); + p = ini_section_get_string(cat, "cassette_file", ""); if (strlen(p) > 511) fatal("load_storage_controllers(): strlen(p) > 511\n"); else strncpy(cassette_fname, p, MIN(512, strlen(p) + 1)); - p = config_get_string(cat, "cassette_mode", ""); + p = ini_section_get_string(cat, "cassette_mode", ""); if (strlen(p) > 511) fatal("load_storage_controllers(): strlen(p) > 511\n"); else strncpy(cassette_mode, p, MIN(512, strlen(p) + 1)); - cassette_pos = config_get_int(cat, "cassette_position", 0); - cassette_srate = config_get_int(cat, "cassette_srate", 44100); - cassette_append = !!config_get_int(cat, "cassette_append", 0); - cassette_pcm = config_get_int(cat, "cassette_pcm", 0); - cassette_ui_writeprot = !!config_get_int(cat, "cassette_writeprot", 0); + cassette_pos = ini_section_get_int(cat, "cassette_position", 0); + cassette_srate = ini_section_get_int(cat, "cassette_srate", 44100); + cassette_append = !!ini_section_get_int(cat, "cassette_append", 0); + cassette_pcm = ini_section_get_int(cat, "cassette_pcm", 0); + cassette_ui_writeprot = !!ini_section_get_int(cat, "cassette_writeprot", 0); for (c = 0; c < 2; c++) { sprintf(temp, "cartridge_%02i_fn", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); #if 0 /* @@ -1378,7 +959,7 @@ load_storage_controllers(void) static void load_hard_disks(void) { - char *cat = "Hard disks"; + ini_section_t cat = ini_find_section(config, "Hard disks"); char temp[512], tmp2[512]; char s[512]; int c; @@ -1389,7 +970,7 @@ load_hard_disks(void) memset(temp, '\0', sizeof(temp)); for (c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); - p = config_get_string(cat, temp, "0, 0, 0, 0, none"); + p = ini_section_get_string(cat, temp, "0, 0, 0, 0, none"); sscanf(p, "%u, %u, %u, %i, %s", &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, (int *) &hdd[c].wp, s); @@ -1448,35 +1029,35 @@ load_hard_disks(void) sprintf(tmp2, "ramdisk"); break; } - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); hdd[c].speed_preset = hdd_preset_get_from_internal_name(p); /* MFM/RLL */ sprintf(temp, "hdd_%02i_mfm_channel", c + 1); if (hdd[c].bus == HDD_BUS_MFM) - hdd[c].mfm_channel = !!config_get_int(cat, temp, c & 1); + hdd[c].mfm_channel = !!ini_section_get_int(cat, temp, c & 1); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); /* XTA */ sprintf(temp, "hdd_%02i_xta_channel", c + 1); if (hdd[c].bus == HDD_BUS_XTA) - hdd[c].xta_channel = !!config_get_int(cat, temp, c & 1); + hdd[c].xta_channel = !!ini_section_get_int(cat, temp, c & 1); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); /* ESDI */ sprintf(temp, "hdd_%02i_esdi_channel", c + 1); if (hdd[c].bus == HDD_BUS_ESDI) - hdd[c].esdi_channel = !!config_get_int(cat, temp, c & 1); + hdd[c].esdi_channel = !!ini_section_get_int(cat, temp, c & 1); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); /* IDE */ sprintf(temp, "hdd_%02i_ide_channel", c + 1); if (hdd[c].bus == HDD_BUS_IDE) { sprintf(tmp2, "%01u:%01u", c >> 1, c & 1); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; @@ -1485,19 +1066,19 @@ load_hard_disks(void) if (hdd[c].ide_channel > 7) hdd[c].ide_channel = 7; } else { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } /* SCSI */ if (hdd[c].bus == HDD_BUS_SCSI) { sprintf(temp, "hdd_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%02u", &board, &dev); if (board >= SCSI_BUS_MAX) { /* Invalid bus - check legacy ID */ sprintf(temp, "hdd_%02i_scsi_id", c + 1); - hdd[c].scsi_id = config_get_int(cat, temp, c + 2); + hdd[c].scsi_id = ini_section_get_int(cat, temp, c + 2); if (hdd[c].scsi_id > 15) hdd[c].scsi_id = 15; @@ -1508,16 +1089,16 @@ load_hard_disks(void) } } else { sprintf(temp, "hdd_%02i_scsi_location", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "hdd_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); sprintf(temp, "hdd_%02i_fn", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); #if 0 /* @@ -1551,26 +1132,26 @@ load_hard_disks(void) /* If disk is empty or invalid, mark it for deletion. */ if (!hdd_is_valid(c)) { sprintf(temp, "hdd_%02i_parameters", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_preide_channels", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_ide_channels", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_fn", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "hdd_%02i_mfm_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } } @@ -1579,7 +1160,7 @@ load_hard_disks(void) static void load_floppy_drives(void) { - char *cat = "Floppy drives"; + ini_section_t cat = ini_find_section(config, "Floppy drives"); char temp[512], *p; int c; @@ -1588,15 +1169,15 @@ load_floppy_drives(void) for (c = 0; c < FDD_NUM; c++) { sprintf(temp, "fdd_%02i_type", c + 1); - p = config_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); + p = ini_section_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); fdd_set_type(c, fdd_get_from_internal_name(p)); if (fdd_get_type(c) > 13) fdd_set_type(c, 13); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "fdd_%02i_fn", c + 1); - p = config_get_string(cat, temp, ""); - config_delete_var(cat, temp); + p = ini_section_get_string(cat, temp, ""); + ini_section_delete_var(cat, temp); #if 0 /* @@ -1623,42 +1204,42 @@ load_floppy_drives(void) /* if (*wp != L'\0') config_log("Floppy%d: %ls\n", c, floppyfns[c]); */ sprintf(temp, "fdd_%02i_writeprot", c + 1); - ui_writeprot[c] = !!config_get_int(cat, temp, 0); - config_delete_var(cat, temp); + ui_writeprot[c] = !!ini_section_get_int(cat, temp, 0); + ini_section_delete_var(cat, temp); sprintf(temp, "fdd_%02i_turbo", c + 1); - fdd_set_turbo(c, !!config_get_int(cat, temp, 0)); - config_delete_var(cat, temp); + fdd_set_turbo(c, !!ini_section_get_int(cat, temp, 0)); + ini_section_delete_var(cat, temp); sprintf(temp, "fdd_%02i_check_bpb", c + 1); - fdd_set_check_bpb(c, !!config_get_int(cat, temp, 1)); - config_delete_var(cat, temp); + fdd_set_check_bpb(c, !!ini_section_get_int(cat, temp, 1)); + ini_section_delete_var(cat, temp); } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Load "Floppy and CD-ROM Drives" section. */ static void load_floppy_and_cdrom_drives(void) { - char *cat = "Floppy and CD-ROM drives"; + ini_section_t cat = ini_find_section(config, "Floppy and CD-ROM drives"); char temp[512], tmp2[512], *p; char s[512]; unsigned int board = 0, dev = 0; int c, d = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ - backwards_compat = (find_section(cat) == NULL); + backwards_compat = (cat == NULL); memset(temp, 0x00, sizeof(temp)); for (c = 0; c < FDD_NUM; c++) { sprintf(temp, "fdd_%02i_type", c + 1); - p = config_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); + p = ini_section_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); fdd_set_type(c, fdd_get_from_internal_name(p)); if (fdd_get_type(c) > 13) fdd_set_type(c, 13); sprintf(temp, "fdd_%02i_fn", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); #if 0 /* @@ -1685,43 +1266,43 @@ load_floppy_and_cdrom_drives(void) /* if (*wp != L'\0') config_log("Floppy%d: %ls\n", c, floppyfns[c]); */ sprintf(temp, "fdd_%02i_writeprot", c + 1); - ui_writeprot[c] = !!config_get_int(cat, temp, 0); + ui_writeprot[c] = !!ini_section_get_int(cat, temp, 0); sprintf(temp, "fdd_%02i_turbo", c + 1); - fdd_set_turbo(c, !!config_get_int(cat, temp, 0)); + fdd_set_turbo(c, !!ini_section_get_int(cat, temp, 0)); sprintf(temp, "fdd_%02i_check_bpb", c + 1); - fdd_set_check_bpb(c, !!config_get_int(cat, temp, 1)); + fdd_set_check_bpb(c, !!ini_section_get_int(cat, temp, 1)); /* Check whether each value is default, if yes, delete it so that only non-default values will later be saved. */ if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) { sprintf(temp, "fdd_%02i_type", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (strlen(floppyfns[c]) == 0) { sprintf(temp, "fdd_%02i_fn", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (ui_writeprot[c] == 0) { sprintf(temp, "fdd_%02i_writeprot", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (fdd_get_turbo(c) == 0) { sprintf(temp, "fdd_%02i_turbo", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (fdd_get_check_bpb(c) == 1) { sprintf(temp, "fdd_%02i_check_bpb", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } } memset(temp, 0x00, sizeof(temp)); for (c = 0; c < CDROM_NUM; c++) { sprintf(temp, "cdrom_%02i_host_drive", c + 1); - cdrom[c].host_drive = config_get_int(cat, temp, 0); + cdrom[c].host_drive = ini_section_get_int(cat, temp, 0); cdrom[c].prev_host_drive = cdrom[c].host_drive; sprintf(temp, "cdrom_%02i_parameters", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) sscanf(p, "%01u, %s", &d, s); else if (c == 0) @@ -1733,7 +1314,7 @@ load_floppy_and_cdrom_drives(void) cdrom[c].bus_type = hdd_string_to_bus(s, 1); sprintf(temp, "cdrom_%02i_speed", c + 1); - cdrom[c].speed = config_get_int(cat, temp, 8); + cdrom[c].speed = ini_section_get_int(cat, temp, 8); /* Default values, needed for proper operation of the Settings dialog. */ cdrom[c].ide_channel = cdrom[c].scsi_device_id = c + 2; @@ -1741,7 +1322,7 @@ load_floppy_and_cdrom_drives(void) if (cdrom[c].bus_type == CDROM_BUS_ATAPI) { sprintf(temp, "cdrom_%02i_ide_channel", c + 1); sprintf(tmp2, "%01u:%01u", (c + 2) >> 1, (c + 2) & 1); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; @@ -1752,12 +1333,12 @@ load_floppy_and_cdrom_drives(void) } else if (cdrom[c].bus_type == CDROM_BUS_SCSI) { sprintf(temp, "cdrom_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%02u", &board, &dev); if (board >= SCSI_BUS_MAX) { /* Invalid bus - check legacy ID */ sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - cdrom[c].scsi_device_id = config_get_int(cat, temp, c + 2); + cdrom[c].scsi_device_id = ini_section_get_int(cat, temp, c + 2); if (cdrom[c].scsi_device_id > 15) cdrom[c].scsi_device_id = 15; @@ -1770,19 +1351,19 @@ load_floppy_and_cdrom_drives(void) if (cdrom[c].bus_type != CDROM_BUS_ATAPI) { sprintf(temp, "cdrom_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (cdrom[c].bus_type != CDROM_BUS_SCSI) { sprintf(temp, "cdrom_%02i_scsi_location", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_image_path", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); #if 0 /* @@ -1812,28 +1393,28 @@ load_floppy_and_cdrom_drives(void) /* If the CD-ROM is disabled, delete all its variables. */ if (cdrom[c].bus_type == CDROM_BUS_DISABLED) { sprintf(temp, "cdrom_%02i_host_drive", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_parameters", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_image_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "cdrom_%02i_iso_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); for (int i = 0; i < MAX_PREV_IMAGES; i++) { cdrom[c].image_history[i] = (char *) calloc(MAX_IMAGE_PATH_LEN + 1, sizeof(char)); sprintf(temp, "cdrom_%02i_image_history_%02i", c + 1, i + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if(p) { sprintf(cdrom[c].image_history[i], "%s", p); } @@ -1845,7 +1426,7 @@ load_floppy_and_cdrom_drives(void) static void load_other_removable_devices(void) { - char *cat = "Other removable devices"; + ini_section_t cat = ini_find_section(config, "Other removable devices"); char temp[512], tmp2[512], *p; char s[512]; unsigned int board = 0, dev = 0; @@ -1856,32 +1437,32 @@ load_other_removable_devices(void) memset(temp, 0x00, sizeof(temp)); for (c = 0; c < CDROM_NUM; c++) { sprintf(temp, "cdrom_%02i_host_drive", c + 1); - cdrom[c].host_drive = config_get_int(cat, temp, 0); + cdrom[c].host_drive = ini_section_get_int(cat, temp, 0); cdrom[c].prev_host_drive = cdrom[c].host_drive; - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_parameters", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) sscanf(p, "%01u, %s", &d, s); else sscanf("0, none", "%01u, %s", &d, s); cdrom[c].sound_on = d; cdrom[c].bus_type = hdd_string_to_bus(s, 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_speed", c + 1); - cdrom[c].speed = config_get_int(cat, temp, 8); - config_delete_var(cat, temp); + cdrom[c].speed = ini_section_get_int(cat, temp, 8); + ini_section_delete_var(cat, temp); /* Default values, needed for proper operation of the Settings dialog. */ cdrom[c].ide_channel = cdrom[c].scsi_device_id = c + 2; - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); if (cdrom[c].bus_type == CDROM_BUS_ATAPI) { sprintf(temp, "cdrom_%02i_ide_channel", c + 1); sprintf(tmp2, "%01u:%01u", (c + 2) >> 1, (c + 2) & 1); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; @@ -1890,20 +1471,20 @@ load_other_removable_devices(void) if (cdrom[c].ide_channel > 7) cdrom[c].ide_channel = 7; - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else if (cdrom[c].bus_type == CDROM_BUS_SCSI) { sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - cdrom[c].scsi_device_id = config_get_int(cat, temp, c + 2); + cdrom[c].scsi_device_id = ini_section_get_int(cat, temp, c + 2); if (cdrom[c].scsi_device_id > 15) cdrom[c].scsi_device_id = 15; - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "cdrom_%02i_image_path", c + 1); - p = config_get_string(cat, temp, ""); - config_delete_var(cat, temp); + p = ini_section_get_string(cat, temp, ""); + ini_section_delete_var(cat, temp); #if 0 /* @@ -1936,7 +1517,7 @@ load_other_removable_devices(void) memset(temp, 0x00, sizeof(temp)); for (c = 0; c < ZIP_NUM; c++) { sprintf(temp, "zip_%02i_parameters", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) sscanf(p, "%01u, %s", &zip_drives[c].is_250, s); else @@ -1949,7 +1530,7 @@ load_other_removable_devices(void) if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) { sprintf(temp, "zip_%02i_ide_channel", c + 1); sprintf(tmp2, "%01u:%01u", (c + 2) >> 1, (c + 2) & 1); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; @@ -1960,12 +1541,12 @@ load_other_removable_devices(void) } else if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { sprintf(temp, "zip_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%02u", &board, &dev); if (board >= SCSI_BUS_MAX) { /* Invalid bus - check legacy ID */ sprintf(temp, "zip_%02i_scsi_id", c + 1); - zip_drives[c].scsi_device_id = config_get_int(cat, temp, c + 2); + zip_drives[c].scsi_device_id = ini_section_get_int(cat, temp, c + 2); if (zip_drives[c].scsi_device_id > 15) zip_drives[c].scsi_device_id = 15; @@ -1978,19 +1559,19 @@ load_other_removable_devices(void) if (zip_drives[c].bus_type != ZIP_BUS_ATAPI) { sprintf(temp, "zip_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (zip_drives[c].bus_type != ZIP_BUS_SCSI) { sprintf(temp, "zip_%02i_scsi_location", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "zip_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_image_path", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); #if 0 /* @@ -2014,29 +1595,29 @@ load_other_removable_devices(void) /* If the CD-ROM is disabled, delete all its variables. */ if (zip_drives[c].bus_type == ZIP_BUS_DISABLED) { sprintf(temp, "zip_%02i_host_drive", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_parameters", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_image_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "zip_%02i_iso_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } memset(temp, 0x00, sizeof(temp)); for (c = 0; c < MO_NUM; c++) { sprintf(temp, "mo_%02i_parameters", c + 1); - p = config_get_string(cat, temp, NULL); + p = ini_section_get_string(cat, temp, NULL); if (p != NULL) sscanf(p, "%u, %s", &mo_drives[c].type, s); else @@ -2049,7 +1630,7 @@ load_other_removable_devices(void) if (mo_drives[c].bus_type == MO_BUS_ATAPI) { sprintf(temp, "mo_%02i_ide_channel", c + 1); sprintf(tmp2, "%01u:%01u", (c + 2) >> 1, (c + 2) & 1); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; @@ -2060,12 +1641,12 @@ load_other_removable_devices(void) } else if (mo_drives[c].bus_type == MO_BUS_SCSI) { sprintf(temp, "mo_%02i_scsi_location", c + 1); sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c + 2); - p = config_get_string(cat, temp, tmp2); + p = ini_section_get_string(cat, temp, tmp2); sscanf(p, "%01u:%02u", &board, &dev); if (board >= SCSI_BUS_MAX) { /* Invalid bus - check legacy ID */ sprintf(temp, "mo_%02i_scsi_id", c + 1); - mo_drives[c].scsi_device_id = config_get_int(cat, temp, c + 2); + mo_drives[c].scsi_device_id = ini_section_get_int(cat, temp, c + 2); if (mo_drives[c].scsi_device_id > 15) mo_drives[c].scsi_device_id = 15; @@ -2078,42 +1659,42 @@ load_other_removable_devices(void) if (mo_drives[c].bus_type != MO_BUS_ATAPI) { sprintf(temp, "mo_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } if (mo_drives[c].bus_type != MO_BUS_SCSI) { sprintf(temp, "mo_%02i_scsi_location", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "mo_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_image_path", c + 1); - p = config_get_string(cat, temp, ""); + p = ini_section_get_string(cat, temp, ""); strncpy(mo_drives[c].image_path, p, sizeof(mo_drives[c].image_path) - 1); /* If the CD-ROM is disabled, delete all its variables. */ if (mo_drives[c].bus_type == MO_BUS_DISABLED) { sprintf(temp, "mo_%02i_host_drive", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_parameters", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_ide_channel", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_image_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "mo_%02i_iso_path", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } } @@ -2121,27 +1702,27 @@ load_other_removable_devices(void) static void load_other_peripherals(void) { - char *cat = "Other peripherals"; + ini_section_t cat = ini_find_section(config, "Other peripherals"); char *p; char temp[512]; int c, free_p = 0; if (backwards_compat2) { - p = config_get_string(cat, "scsicard", NULL); + p = ini_section_get_string(cat, "scsicard", NULL); if (p != NULL) scsi_card_current[0] = scsi_card_get_from_internal_name(p); else scsi_card_current[0] = 0; - config_delete_var(cat, "scsicard"); + ini_section_delete_var(cat, "scsicard"); - p = config_get_string(cat, "fdc", NULL); + p = ini_section_get_string(cat, "fdc", NULL); if (p != NULL) fdc_type = fdc_card_get_from_internal_name(p); else fdc_type = FDC_INTERNAL; - config_delete_var(cat, "fdc"); + ini_section_delete_var(cat, "fdc"); - p = config_get_string(cat, "hdc", NULL); + p = ini_section_get_string(cat, "hdc", NULL); if (p == NULL) { if (machine_has_flags(machine, MACHINE_HDC)) { p = (char *) malloc((strlen("internal") + 1) * sizeof(char)); @@ -2164,31 +1745,31 @@ load_other_peripherals(void) hdc_current = hdc_get_from_internal_name("ide_vlb_2ch"); else hdc_current = hdc_get_from_internal_name(p); - config_delete_var(cat, "hdc"); + ini_section_delete_var(cat, "hdc"); if (free_p) { free(p); p = NULL; } - ide_ter_enabled = !!config_get_int(cat, "ide_ter", 0); - config_delete_var(cat, "ide_ter"); - ide_qua_enabled = !!config_get_int(cat, "ide_qua", 0); - config_delete_var(cat, "ide_qua"); + ide_ter_enabled = !!ini_section_get_int(cat, "ide_ter", 0); + ini_section_delete_var(cat, "ide_ter"); + ide_qua_enabled = !!ini_section_get_int(cat, "ide_qua", 0); + ini_section_delete_var(cat, "ide_qua"); } backwards_compat2 = 0; - bugger_enabled = !!config_get_int(cat, "bugger_enabled", 0); - postcard_enabled = !!config_get_int(cat, "postcard_enabled", 0); + bugger_enabled = !!ini_section_get_int(cat, "bugger_enabled", 0); + postcard_enabled = !!ini_section_get_int(cat, "postcard_enabled", 0); for (c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); - p = config_get_string(cat, temp, "none"); + p = ini_section_get_string(cat, temp, "none"); isamem_type[c] = isamem_get_from_internal_name(p); } - p = config_get_string(cat, "isartc_type", "none"); + p = ini_section_get_string(cat, "isartc_type", "none"); isartc_type = isartc_get_from_internal_name(p); } @@ -2207,7 +1788,10 @@ config_load(void) #endif memset(zip_drives, 0, sizeof(zip_drive_t)); - if (!config_read(cfg_path)) { + config = ini_read(cfg_path); + + if (!config) { + config = ini_new(); config_changed = 1; cpu_f = (cpu_family_t *) &cpu_families[0]; @@ -2297,171 +1881,171 @@ config_load(void) static void save_general(void) { - char *cat = "General"; + ini_section_t cat = ini_find_or_create_section(config, "General"); char temp[512], buffer[512] = { 0 }; char *va_name; - config_set_int(cat, "vid_resize", vid_resize); + ini_section_set_int(cat, "vid_resize", vid_resize); if (vid_resize == 0) - config_delete_var(cat, "vid_resize"); + ini_section_delete_var(cat, "vid_resize"); va_name = plat_vidapi_name(vid_api); if (!strcmp(va_name, "default")) - config_delete_var(cat, "vid_renderer"); + ini_section_delete_var(cat, "vid_renderer"); else - config_set_string(cat, "vid_renderer", va_name); + ini_section_set_string(cat, "vid_renderer", va_name); if (video_fullscreen_scale == 0) - config_delete_var(cat, "video_fullscreen_scale"); + ini_section_delete_var(cat, "video_fullscreen_scale"); else - config_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); + ini_section_set_int(cat, "video_fullscreen_scale", video_fullscreen_scale); if (video_fullscreen_first == 1) - config_delete_var(cat, "video_fullscreen_first"); + ini_section_delete_var(cat, "video_fullscreen_first"); else - config_set_int(cat, "video_fullscreen_first", video_fullscreen_first); + ini_section_set_int(cat, "video_fullscreen_first", video_fullscreen_first); if (video_filter_method == 1) - config_delete_var(cat, "video_filter_method"); + ini_section_delete_var(cat, "video_filter_method"); else - config_set_int(cat, "video_filter_method", video_filter_method); + ini_section_set_int(cat, "video_filter_method", video_filter_method); if (force_43 == 0) - config_delete_var(cat, "force_43"); + ini_section_delete_var(cat, "force_43"); else - config_set_int(cat, "force_43", force_43); + ini_section_set_int(cat, "force_43", force_43); if (scale == 1) - config_delete_var(cat, "scale"); + ini_section_delete_var(cat, "scale"); else - config_set_int(cat, "scale", scale); + ini_section_set_int(cat, "scale", scale); if (dpi_scale == 1) - config_delete_var(cat, "dpi_scale"); + ini_section_delete_var(cat, "dpi_scale"); else - config_set_int(cat, "dpi_scale", dpi_scale); + ini_section_set_int(cat, "dpi_scale", dpi_scale); if (enable_overscan == 0) - config_delete_var(cat, "enable_overscan"); + ini_section_delete_var(cat, "enable_overscan"); else - config_set_int(cat, "enable_overscan", enable_overscan); + ini_section_set_int(cat, "enable_overscan", enable_overscan); if (vid_cga_contrast == 0) - config_delete_var(cat, "vid_cga_contrast"); + ini_section_delete_var(cat, "vid_cga_contrast"); else - config_set_int(cat, "vid_cga_contrast", vid_cga_contrast); + ini_section_set_int(cat, "vid_cga_contrast", vid_cga_contrast); if (video_grayscale == 0) - config_delete_var(cat, "video_grayscale"); + ini_section_delete_var(cat, "video_grayscale"); else - config_set_int(cat, "video_grayscale", video_grayscale); + ini_section_set_int(cat, "video_grayscale", video_grayscale); if (video_graytype == 0) - config_delete_var(cat, "video_graytype"); + ini_section_delete_var(cat, "video_graytype"); else - config_set_int(cat, "video_graytype", video_graytype); + ini_section_set_int(cat, "video_graytype", video_graytype); if (rctrl_is_lalt == 0) - config_delete_var(cat, "rctrl_is_lalt"); + ini_section_delete_var(cat, "rctrl_is_lalt"); else - config_set_int(cat, "rctrl_is_lalt", rctrl_is_lalt); + ini_section_set_int(cat, "rctrl_is_lalt", rctrl_is_lalt); if (update_icons == 1) - config_delete_var(cat, "update_icons"); + ini_section_delete_var(cat, "update_icons"); else - config_set_int(cat, "update_icons", update_icons); + ini_section_set_int(cat, "update_icons", update_icons); if (window_remember || (vid_resize & 2)) { if (window_remember) - config_set_int(cat, "window_remember", window_remember); + ini_section_set_int(cat, "window_remember", window_remember); else - config_delete_var(cat, "window_remember"); + ini_section_delete_var(cat, "window_remember"); } else - config_delete_var(cat, "window_remember"); + ini_section_delete_var(cat, "window_remember"); if (vid_resize & 2) { sprintf(temp, "%ix%i", fixed_size_x, fixed_size_y); - config_set_string(cat, "window_fixed_res", temp); + ini_section_set_string(cat, "window_fixed_res", temp); } else - config_delete_var(cat, "window_fixed_res"); + ini_section_delete_var(cat, "window_fixed_res"); if (sound_gain != 0) - config_set_int(cat, "sound_gain", sound_gain); + ini_section_set_int(cat, "sound_gain", sound_gain); else - config_delete_var(cat, "sound_gain"); + ini_section_delete_var(cat, "sound_gain"); if (kbd_req_capture != 0) - config_set_int(cat, "kbd_req_capture", kbd_req_capture); + ini_section_set_int(cat, "kbd_req_capture", kbd_req_capture); else - config_delete_var(cat, "kbd_req_capture"); + ini_section_delete_var(cat, "kbd_req_capture"); if (hide_status_bar != 0) - config_set_int(cat, "hide_status_bar", hide_status_bar); + ini_section_set_int(cat, "hide_status_bar", hide_status_bar); else - config_delete_var(cat, "hide_status_bar"); + ini_section_delete_var(cat, "hide_status_bar"); if (hide_tool_bar != 0) - config_set_int(cat, "hide_tool_bar", hide_tool_bar); + ini_section_set_int(cat, "hide_tool_bar", hide_tool_bar); else - config_delete_var(cat, "hide_tool_bar"); + ini_section_delete_var(cat, "hide_tool_bar"); if (confirm_reset != 1) - config_set_int(cat, "confirm_reset", confirm_reset); + ini_section_set_int(cat, "confirm_reset", confirm_reset); else - config_delete_var(cat, "confirm_reset"); + ini_section_delete_var(cat, "confirm_reset"); if (confirm_exit != 1) - config_set_int(cat, "confirm_exit", confirm_exit); + ini_section_set_int(cat, "confirm_exit", confirm_exit); else - config_delete_var(cat, "confirm_exit"); + ini_section_delete_var(cat, "confirm_exit"); if (confirm_save != 1) - config_set_int(cat, "confirm_save", confirm_save); + ini_section_set_int(cat, "confirm_save", confirm_save); else - config_delete_var(cat, "confirm_save"); + ini_section_delete_var(cat, "confirm_save"); if (mouse_sensitivity != 1.0) - config_set_double(cat, "mouse_sensitivity", mouse_sensitivity); + ini_section_set_double(cat, "mouse_sensitivity", mouse_sensitivity); else - config_delete_var(cat, "mouse_sensitivity"); + ini_section_delete_var(cat, "mouse_sensitivity"); if (lang_id == DEFAULT_LANGUAGE) - config_delete_var(cat, "language"); + ini_section_delete_var(cat, "language"); else { plat_language_code_r(lang_id, buffer, 511); - config_set_string(cat, "language", buffer); + ini_section_set_string(cat, "language", buffer); } if (!strcmp(icon_set, "")) - config_delete_var(cat, "iconset"); + ini_section_delete_var(cat, "iconset"); else - config_set_string(cat, "iconset", icon_set); + ini_section_set_string(cat, "iconset", icon_set); if (enable_discord) - config_set_int(cat, "enable_discord", enable_discord); + ini_section_set_int(cat, "enable_discord", enable_discord); else - config_delete_var(cat, "enable_discord"); + ini_section_delete_var(cat, "enable_discord"); if (open_dir_usr_path) - config_set_int(cat, "open_dir_usr_path", open_dir_usr_path); + ini_section_set_int(cat, "open_dir_usr_path", open_dir_usr_path); else - config_delete_var(cat, "open_dir_usr_path"); + ini_section_delete_var(cat, "open_dir_usr_path"); if (video_framerate != -1) - config_set_int(cat, "video_gl_framerate", video_framerate); + ini_section_set_int(cat, "video_gl_framerate", video_framerate); else - config_delete_var(cat, "video_gl_framerate"); + ini_section_delete_var(cat, "video_gl_framerate"); if (video_vsync != 0) - config_set_int(cat, "video_gl_vsync", video_vsync); + ini_section_set_int(cat, "video_gl_vsync", video_vsync); else - config_delete_var(cat, "video_gl_vsync"); + ini_section_delete_var(cat, "video_gl_vsync"); if (strlen(video_shader) > 0) - config_set_string(cat, "video_gl_shader", video_shader); + ini_section_set_string(cat, "video_gl_shader", video_shader); else - config_delete_var(cat, "video_gl_shader"); + ini_section_delete_var(cat, "video_gl_shader"); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save monitor section. */ @@ -2477,15 +2061,15 @@ save_monitor(int monitor_index) monitor_settings[monitor_index].mon_window_x, monitor_settings[monitor_index].mon_window_y, monitor_settings[monitor_index].mon_window_w, monitor_settings[monitor_index].mon_window_h); - config_set_string(cat, "window_coordinates", temp); + ini_section_set_string(cat, "window_coordinates", temp); if (monitor_settings[monitor_index].mon_window_maximized != 0) { - config_set_int(cat, "window_maximized", monitor_settings[monitor_index].mon_window_maximized); + ini_section_set_int(cat, "window_maximized", monitor_settings[monitor_index].mon_window_maximized); } else { - config_delete_var(cat, "window_maximized"); + ini_section_delete_var(cat, "window_maximized"); } } else { - config_delete_var(cat, "window_coordinates"); - config_delete_var(cat, "window_maximized"); + ini_section_delete_var(cat, "window_coordinates"); + ini_section_delete_var(cat, "window_maximized"); } } @@ -2493,24 +2077,24 @@ save_monitor(int monitor_index) static void save_machine(void) { - char *cat = "Machine"; + ini_section_t cat = ini_find_or_create_section(config, "Machine"); char *p; int c, i = 0, legacy_mfg, legacy_cpu = -1, closest_legacy_cpu = -1; p = machine_get_internal_name(); - config_set_string(cat, "machine", p); + ini_section_set_string(cat, "machine", p); - config_set_string(cat, "cpu_family", (char *) cpu_f->internal_name); - config_set_int(cat, "cpu_speed", cpu_f->cpus[cpu].rspeed); - config_set_double(cat, "cpu_multi", cpu_f->cpus[cpu].multi); + ini_section_set_string(cat, "cpu_family", (char *) cpu_f->internal_name); + ini_section_set_int(cat, "cpu_speed", cpu_f->cpus[cpu].rspeed); + ini_section_set_double(cat, "cpu_multi", cpu_f->cpus[cpu].multi); if (cpu_override) - config_set_int(cat, "cpu_override", cpu_override); + ini_section_set_int(cat, "cpu_override", cpu_override); else - config_delete_var(cat, "cpu_override"); + ini_section_delete_var(cat, "cpu_override"); /* Forwards compatibility with the previous CPU model system. */ - config_delete_var(cat, "cpu_manufacturer"); - config_delete_var(cat, "cpu"); + ini_section_delete_var(cat, "cpu_manufacturer"); + ini_section_delete_var(cat, "cpu"); /* Look for a machine entry on the legacy table. */ c = 0; @@ -2554,193 +2138,193 @@ save_machine(void) /* Set legacy values if a match was found. */ if (legacy_cpu > -1) { if (legacy_mfg) - config_set_int(cat, "cpu_manufacturer", legacy_mfg); + ini_section_set_int(cat, "cpu_manufacturer", legacy_mfg); if (legacy_cpu) - config_set_int(cat, "cpu", legacy_cpu); + ini_section_set_int(cat, "cpu", legacy_cpu); } } if (cpu_waitstates == 0) - config_delete_var(cat, "cpu_waitstates"); + ini_section_delete_var(cat, "cpu_waitstates"); else - config_set_int(cat, "cpu_waitstates", cpu_waitstates); + ini_section_set_int(cat, "cpu_waitstates", cpu_waitstates); if (fpu_type == 0) - config_delete_var(cat, "fpu_type"); + ini_section_delete_var(cat, "fpu_type"); else - config_set_string(cat, "fpu_type", (char *) fpu_get_internal_name(cpu_f, cpu, fpu_type)); + ini_section_set_string(cat, "fpu_type", (char *) fpu_get_internal_name(cpu_f, cpu, fpu_type)); // Write the mem_size explicitly to the setttings in order to help managers to display it without having the actual machine table - config_delete_var(cat, "mem_size"); - config_set_int(cat, "mem_size", mem_size); + ini_section_delete_var(cat, "mem_size"); + ini_section_set_int(cat, "mem_size", mem_size); - config_set_int(cat, "cpu_use_dynarec", cpu_use_dynarec); + ini_section_set_int(cat, "cpu_use_dynarec", cpu_use_dynarec); if (time_sync & TIME_SYNC_ENABLED) if (time_sync & TIME_SYNC_UTC) - config_set_string(cat, "time_sync", "utc"); + ini_section_set_string(cat, "time_sync", "utc"); else - config_set_string(cat, "time_sync", "local"); + ini_section_set_string(cat, "time_sync", "local"); else - config_set_string(cat, "time_sync", "disabled"); + ini_section_set_string(cat, "time_sync", "disabled"); if (pit_mode == -1) - config_delete_var(cat, "pit_mode"); + ini_section_delete_var(cat, "pit_mode"); else - config_set_int(cat, "pit_mode", pit_mode); + ini_section_set_int(cat, "pit_mode", pit_mode); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Video" section. */ static void save_video(void) { - char *cat = "Video"; + ini_section_t cat = ini_find_or_create_section(config, "Video"); - config_set_string(cat, "gfxcard", + ini_section_set_string(cat, "gfxcard", video_get_internal_name(gfxcard)); if (voodoo_enabled == 0) - config_delete_var(cat, "voodoo"); + ini_section_delete_var(cat, "voodoo"); else - config_set_int(cat, "voodoo", voodoo_enabled); + ini_section_set_int(cat, "voodoo", voodoo_enabled); if (ibm8514_enabled == 0) - config_delete_var(cat, "8514a"); + ini_section_delete_var(cat, "8514a"); else - config_set_int(cat, "8514a", ibm8514_enabled); + ini_section_set_int(cat, "8514a", ibm8514_enabled); if (xga_enabled == 0) - config_delete_var(cat, "xga"); + ini_section_delete_var(cat, "xga"); else - config_set_int(cat, "xga", xga_enabled); + ini_section_set_int(cat, "xga", xga_enabled); if (gfxcard_2 == 0) - config_delete_var(cat, "gfxcard_2"); + ini_section_delete_var(cat, "gfxcard_2"); else - config_set_string(cat, "gfxcard_2", video_get_internal_name(gfxcard_2)); + ini_section_set_string(cat, "gfxcard_2", video_get_internal_name(gfxcard_2)); if (show_second_monitors == 1) - config_delete_var(cat, "show_second_monitors"); + ini_section_delete_var(cat, "show_second_monitors"); else - config_set_int(cat, "show_second_monitors", show_second_monitors); + ini_section_set_int(cat, "show_second_monitors", show_second_monitors); if (video_fullscreen_scale_maximized == 0) - config_delete_var(cat, "video_fullscreen_scale_maximized"); + ini_section_delete_var(cat, "video_fullscreen_scale_maximized"); else - config_set_int(cat, "video_fullscreen_scale_maximized", video_fullscreen_scale_maximized); + ini_section_set_int(cat, "video_fullscreen_scale_maximized", video_fullscreen_scale_maximized); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Input Devices" section. */ static void save_input_devices(void) { - char *cat = "Input devices"; + ini_section_t cat = ini_find_or_create_section(config, "Input devices"); char temp[512], tmp2[512]; int c, d; - config_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); + ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); if (!joystick_type) { - config_delete_var(cat, "joystick_type"); + ini_section_delete_var(cat, "joystick_type"); for (c = 0; c < 16; c++) { sprintf(tmp2, "joystick_%i_nr", c); - config_delete_var(cat, tmp2); + ini_section_delete_var(cat, tmp2); for (d = 0; d < 16; d++) { sprintf(tmp2, "joystick_%i_axis_%i", c, d); - config_delete_var(cat, tmp2); + ini_section_delete_var(cat, tmp2); } for (d = 0; d < 16; d++) { sprintf(tmp2, "joystick_%i_button_%i", c, d); - config_delete_var(cat, tmp2); + ini_section_delete_var(cat, tmp2); } for (d = 0; d < 16; d++) { sprintf(tmp2, "joystick_%i_pov_%i", c, d); - config_delete_var(cat, tmp2); + ini_section_delete_var(cat, tmp2); } } } else { - config_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type)); + ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type)); for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { sprintf(tmp2, "joystick_%i_nr", c); - config_set_int(cat, tmp2, joystick_state[c].plat_joystick_nr); + ini_section_set_int(cat, tmp2, joystick_state[c].plat_joystick_nr); if (joystick_state[c].plat_joystick_nr) { for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { sprintf(tmp2, "joystick_%i_axis_%i", c, d); - config_set_int(cat, tmp2, joystick_state[c].axis_mapping[d]); + ini_section_set_int(cat, tmp2, joystick_state[c].axis_mapping[d]); } for (d = 0; d < joystick_get_button_count(joystick_type); d++) { sprintf(tmp2, "joystick_%i_button_%i", c, d); - config_set_int(cat, tmp2, joystick_state[c].button_mapping[d]); + ini_section_set_int(cat, tmp2, joystick_state[c].button_mapping[d]); } for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { sprintf(tmp2, "joystick_%i_pov_%i", c, d); sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); - config_set_string(cat, tmp2, temp); + ini_section_set_string(cat, tmp2, temp); } } } } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Sound" section. */ static void save_sound(void) { - char *cat = "Sound"; + ini_section_t cat = ini_find_or_create_section(config, "Sound"); if (sound_card_current == 0) - config_delete_var(cat, "sndcard"); + ini_section_delete_var(cat, "sndcard"); else - config_set_string(cat, "sndcard", sound_card_get_internal_name(sound_card_current)); + ini_section_set_string(cat, "sndcard", sound_card_get_internal_name(sound_card_current)); if (!strcmp(midi_out_device_get_internal_name(midi_output_device_current), "none")) - config_delete_var(cat, "midi_device"); + ini_section_delete_var(cat, "midi_device"); else - config_set_string(cat, "midi_device", midi_out_device_get_internal_name(midi_output_device_current)); + ini_section_set_string(cat, "midi_device", midi_out_device_get_internal_name(midi_output_device_current)); if (!strcmp(midi_in_device_get_internal_name(midi_input_device_current), "none")) - config_delete_var(cat, "midi_in_device"); + ini_section_delete_var(cat, "midi_in_device"); else - config_set_string(cat, "midi_in_device", midi_in_device_get_internal_name(midi_input_device_current)); + ini_section_set_string(cat, "midi_in_device", midi_in_device_get_internal_name(midi_input_device_current)); if (mpu401_standalone_enable == 0) - config_delete_var(cat, "mpu401_standalone"); + ini_section_delete_var(cat, "mpu401_standalone"); else - config_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); + ini_section_set_int(cat, "mpu401_standalone", mpu401_standalone_enable); if (SSI2001 == 0) - config_delete_var(cat, "ssi2001"); + ini_section_delete_var(cat, "ssi2001"); else - config_set_int(cat, "ssi2001", SSI2001); + ini_section_set_int(cat, "ssi2001", SSI2001); if (GAMEBLASTER == 0) - config_delete_var(cat, "gameblaster"); + ini_section_delete_var(cat, "gameblaster"); else - config_set_int(cat, "gameblaster", GAMEBLASTER); + ini_section_set_int(cat, "gameblaster", GAMEBLASTER); if (GUS == 0) - config_delete_var(cat, "gus"); + ini_section_delete_var(cat, "gus"); else - config_set_int(cat, "gus", GUS); + ini_section_set_int(cat, "gus", GUS); if (sound_is_float == 1) - config_delete_var(cat, "sound_type"); + ini_section_delete_var(cat, "sound_type"); else - config_set_string(cat, "sound_type", (sound_is_float == 1) ? "float" : "int16"); + ini_section_set_string(cat, "sound_type", (sound_is_float == 1) ? "float" : "int16"); - config_set_string(cat, "fm_driver", (fm_driver == FM_DRV_NUKED) ? "nuked" : "ymfm"); + ini_section_set_string(cat, "fm_driver", (fm_driver == FM_DRV_NUKED) ? "nuked" : "ymfm"); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Network" section. */ @@ -2749,77 +2333,77 @@ save_network(void) { int c = 0; char temp[512]; - char *cat = "Network"; + ini_section_t cat = ini_find_or_create_section(config, "Network"); - config_delete_var(cat, "net_type"); - config_delete_var(cat, "net_host_device"); - config_delete_var(cat, "net_card"); + ini_section_delete_var(cat, "net_type"); + ini_section_delete_var(cat, "net_host_device"); + ini_section_delete_var(cat, "net_card"); for (c = 0; c < NET_CARD_MAX; c++) { sprintf(temp, "net_%02i_card", c + 1); if (net_cards_conf[c].device_num == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, network_card_get_internal_name(net_cards_conf[c].device_num)); + ini_section_set_string(cat, temp, network_card_get_internal_name(net_cards_conf[c].device_num)); } sprintf(temp, "net_%02i_net_type", c + 1); if (net_cards_conf[c].net_type == NET_TYPE_NONE) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, + ini_section_set_string(cat, temp, (net_cards_conf[c].net_type == NET_TYPE_SLIRP) ? "slirp" : "pcap"); } sprintf(temp, "net_%02i_host_device", c + 1); if (net_cards_conf[c].host_dev_name[0] != '\0') { if (!strcmp(net_cards_conf[c].host_dev_name, "none")) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, net_cards_conf[c].host_dev_name); + ini_section_set_string(cat, temp, net_cards_conf[c].host_dev_name); } else { - /* config_set_string(cat, temp, "none"); */ - config_delete_var(cat, temp); + /* ini_section_set_string(cat, temp, "none"); */ + ini_section_delete_var(cat, temp); } sprintf(temp, "net_%02i_link", c + 1); if (net_cards_conf[c].link_state == (NET_LINK_10_HD|NET_LINK_10_FD|NET_LINK_100_HD|NET_LINK_100_FD|NET_LINK_1000_HD|NET_LINK_1000_FD)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_int(cat, temp, net_cards_conf[c].link_state); + ini_section_set_int(cat, temp, net_cards_conf[c].link_state); } } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Ports" section. */ static void save_ports(void) { - char *cat = "Ports (COM & LPT)"; + ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)"); char temp[512]; int c, d; for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); if (((c < 2) && com_ports[c].enabled) || ((c >= 2) && !com_ports[c].enabled)) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_int(cat, temp, com_ports[c].enabled); + ini_section_set_int(cat, temp, com_ports[c].enabled); /* sprintf(temp, "serial%d_type", c + 1); if (!com_ports[c].enabled)) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); // else -// config_set_string(cat, temp, (char *) serial_type[c]) +// ini_section_set_string(cat, temp, (char *) serial_type[c]) sprintf(temp, "serial%d_device", c + 1); if (com_ports[c].device == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, + ini_section_set_string(cat, temp, (char *) com_device_get_internal_name(com_ports[c].device)); */ } @@ -2828,108 +2412,108 @@ save_ports(void) sprintf(temp, "lpt%d_enabled", c + 1); d = (c == 0) ? 1 : 0; if (lpt_ports[c].enabled == d) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_int(cat, temp, lpt_ports[c].enabled); + ini_section_set_int(cat, temp, lpt_ports[c].enabled); sprintf(temp, "lpt%d_device", c + 1); if (lpt_ports[c].device == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, + ini_section_set_string(cat, temp, (char *) lpt_device_get_internal_name(lpt_ports[c].device)); } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Storage Controllers" section. */ static void save_storage_controllers(void) { - char *cat = "Storage controllers"; + ini_section_t cat = ini_find_or_create_section(config, "Storage controllers"); char temp[512]; int c; - config_delete_var(cat, "scsicard"); + ini_section_delete_var(cat, "scsicard"); for (c = 0; c < SCSI_BUS_MAX; c++) { sprintf(temp, "scsicard_%d", c + 1); if (scsi_card_current[c] == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, + ini_section_set_string(cat, temp, scsi_card_get_internal_name(scsi_card_current[c])); } if (fdc_type == FDC_INTERNAL) - config_delete_var(cat, "fdc"); + ini_section_delete_var(cat, "fdc"); else - config_set_string(cat, "fdc", + ini_section_set_string(cat, "fdc", fdc_card_get_internal_name(fdc_type)); - config_set_string(cat, "hdc", + ini_section_set_string(cat, "hdc", hdc_get_internal_name(hdc_current)); if (ide_ter_enabled == 0) - config_delete_var(cat, "ide_ter"); + ini_section_delete_var(cat, "ide_ter"); else - config_set_int(cat, "ide_ter", ide_ter_enabled); + ini_section_set_int(cat, "ide_ter", ide_ter_enabled); if (ide_qua_enabled == 0) - config_delete_var(cat, "ide_qua"); + ini_section_delete_var(cat, "ide_qua"); else - config_set_int(cat, "ide_qua", ide_qua_enabled); + ini_section_set_int(cat, "ide_qua", ide_qua_enabled); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); if (cassette_enable == 0) - config_delete_var(cat, "cassette_enabled"); + ini_section_delete_var(cat, "cassette_enabled"); else - config_set_int(cat, "cassette_enabled", cassette_enable); + ini_section_set_int(cat, "cassette_enabled", cassette_enable); if (strlen(cassette_fname) == 0) - config_delete_var(cat, "cassette_file"); + ini_section_delete_var(cat, "cassette_file"); else - config_set_string(cat, "cassette_file", cassette_fname); + ini_section_set_string(cat, "cassette_file", cassette_fname); if (strlen(cassette_mode) == 0) - config_delete_var(cat, "cassette_mode"); + ini_section_delete_var(cat, "cassette_mode"); else - config_set_string(cat, "cassette_mode", cassette_mode); + ini_section_set_string(cat, "cassette_mode", cassette_mode); if (cassette_pos == 0) - config_delete_var(cat, "cassette_position"); + ini_section_delete_var(cat, "cassette_position"); else - config_set_int(cat, "cassette_position", cassette_pos); + ini_section_set_int(cat, "cassette_position", cassette_pos); if (cassette_srate == 44100) - config_delete_var(cat, "cassette_srate"); + ini_section_delete_var(cat, "cassette_srate"); else - config_set_int(cat, "cassette_srate", cassette_srate); + ini_section_set_int(cat, "cassette_srate", cassette_srate); if (cassette_append == 0) - config_delete_var(cat, "cassette_append"); + ini_section_delete_var(cat, "cassette_append"); else - config_set_int(cat, "cassette_append", cassette_append); + ini_section_set_int(cat, "cassette_append", cassette_append); if (cassette_pcm == 0) - config_delete_var(cat, "cassette_pcm"); + ini_section_delete_var(cat, "cassette_pcm"); else - config_set_int(cat, "cassette_pcm", cassette_pcm); + ini_section_set_int(cat, "cassette_pcm", cassette_pcm); if (cassette_ui_writeprot == 0) - config_delete_var(cat, "cassette_writeprot"); + ini_section_delete_var(cat, "cassette_writeprot"); else - config_set_int(cat, "cassette_writeprot", cassette_ui_writeprot); + ini_section_set_int(cat, "cassette_writeprot", cassette_ui_writeprot); for (c = 0; c < 2; c++) { sprintf(temp, "cartridge_%02i_fn", c + 1); if (strlen(cart_fns[c]) == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, cart_fns[c]); + ini_section_set_string(cat, temp, cart_fns[c]); } } @@ -2937,43 +2521,43 @@ save_storage_controllers(void) static void save_other_peripherals(void) { - char *cat = "Other peripherals"; + ini_section_t cat = ini_find_or_create_section(config, "Other peripherals"); char temp[512]; int c; if (bugger_enabled == 0) - config_delete_var(cat, "bugger_enabled"); + ini_section_delete_var(cat, "bugger_enabled"); else - config_set_int(cat, "bugger_enabled", bugger_enabled); + ini_section_set_int(cat, "bugger_enabled", bugger_enabled); if (postcard_enabled == 0) - config_delete_var(cat, "postcard_enabled"); + ini_section_delete_var(cat, "postcard_enabled"); else - config_set_int(cat, "postcard_enabled", postcard_enabled); + ini_section_set_int(cat, "postcard_enabled", postcard_enabled); for (c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); if (isamem_type[c] == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, + ini_section_set_string(cat, temp, (char *) isamem_get_internal_name(isamem_type[c])); } if (isartc_type == 0) - config_delete_var(cat, "isartc_type"); + ini_section_delete_var(cat, "isartc_type"); else - config_set_string(cat, "isartc_type", + ini_section_set_string(cat, "isartc_type", isartc_get_internal_name(isartc_type)); - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Hard Disks" section. */ static void save_hard_disks(void) { - char *cat = "Hard disks"; + ini_section_t cat = ini_find_or_create_section(config, "Hard disks"); char temp[32], tmp2[512]; char *p; int c; @@ -2985,268 +2569,268 @@ save_hard_disks(void) p = hdd_bus_to_string(hdd[c].bus, 0); sprintf(tmp2, "%u, %u, %u, %i, %s", hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } else { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } sprintf(temp, "hdd_%02i_mfm_channel", c + 1); if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_MFM)) - config_set_int(cat, temp, hdd[c].mfm_channel); + ini_section_set_int(cat, temp, hdd[c].mfm_channel); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_xta_channel", c + 1); if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_XTA)) - config_set_int(cat, temp, hdd[c].xta_channel); + ini_section_set_int(cat, temp, hdd[c].xta_channel); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_esdi_channel", c + 1); if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_ESDI)) - config_set_int(cat, temp, hdd[c].esdi_channel); + ini_section_set_int(cat, temp, hdd[c].esdi_channel); else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_ide_channel", c + 1); if (!hdd_is_valid(c) || (hdd[c].bus != HDD_BUS_IDE)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { sprintf(tmp2, "%01u:%01u", hdd[c].ide_channel >> 1, hdd[c].ide_channel & 1); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "hdd_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_scsi_location", c + 1); if (hdd[c].bus != HDD_BUS_SCSI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", hdd[c].scsi_id >> 4, hdd[c].scsi_id & 15); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "hdd_%02i_fn", c + 1); if (hdd_is_valid(c) && (strlen(hdd[c].fn) != 0)) { path_normalize(hdd[c].fn); if (!strnicmp(hdd[c].fn, usr_path, strlen(usr_path))) - config_set_string(cat, temp, &hdd[c].fn[strlen(usr_path)]); + ini_section_set_string(cat, temp, &hdd[c].fn[strlen(usr_path)]); else - config_set_string(cat, temp, hdd[c].fn); + ini_section_set_string(cat, temp, hdd[c].fn); } else - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "hdd_%02i_speed", c + 1); if (!hdd_is_valid(c) || (hdd[c].bus != HDD_BUS_IDE && hdd[c].bus != HDD_BUS_ESDI)) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); + ini_section_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Floppy Drives" section. */ static void save_floppy_and_cdrom_drives(void) { - char *cat = "Floppy and CD-ROM drives"; + ini_section_t cat = ini_find_or_create_section(config, "Floppy and CD-ROM drives"); char temp[512], tmp2[512]; int c; for (c = 0; c < FDD_NUM; c++) { sprintf(temp, "fdd_%02i_type", c + 1); if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_string(cat, temp, + ini_section_set_string(cat, temp, fdd_get_internal_name(fdd_get_type(c))); sprintf(temp, "fdd_%02i_fn", c + 1); if (strlen(floppyfns[c]) == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); ui_writeprot[c] = 0; sprintf(temp, "fdd_%02i_writeprot", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, floppyfns[c]); + ini_section_set_string(cat, temp, floppyfns[c]); } sprintf(temp, "fdd_%02i_writeprot", c + 1); if (ui_writeprot[c] == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_int(cat, temp, ui_writeprot[c]); + ini_section_set_int(cat, temp, ui_writeprot[c]); sprintf(temp, "fdd_%02i_turbo", c + 1); if (fdd_get_turbo(c) == 0) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_int(cat, temp, fdd_get_turbo(c)); + ini_section_set_int(cat, temp, fdd_get_turbo(c)); sprintf(temp, "fdd_%02i_check_bpb", c + 1); if (fdd_get_check_bpb(c) == 1) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else - config_set_int(cat, temp, fdd_get_check_bpb(c)); + ini_section_set_int(cat, temp, fdd_get_check_bpb(c)); } for (c = 0; c < CDROM_NUM; c++) { sprintf(temp, "cdrom_%02i_host_drive", c + 1); if ((cdrom[c].bus_type == 0) || (cdrom[c].host_drive != 200)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_int(cat, temp, cdrom[c].host_drive); + ini_section_set_int(cat, temp, cdrom[c].host_drive); } sprintf(temp, "cdrom_%02i_speed", c + 1); if ((cdrom[c].bus_type == 0) || (cdrom[c].speed == 8)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_int(cat, temp, cdrom[c].speed); + ini_section_set_int(cat, temp, cdrom[c].speed); } sprintf(temp, "cdrom_%02i_parameters", c + 1); if (cdrom[c].bus_type == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { sprintf(tmp2, "%u, %s", cdrom[c].sound_on, hdd_bus_to_string(cdrom[c].bus_type, 1)); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_ide_channel", c + 1); if (cdrom[c].bus_type != CDROM_BUS_ATAPI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%01u", cdrom[c].ide_channel >> 1, cdrom[c].ide_channel & 1); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_scsi_location", c + 1); if (cdrom[c].bus_type != CDROM_BUS_SCSI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", cdrom[c].scsi_device_id >> 4, cdrom[c].scsi_device_id & 15); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_image_path", c + 1); if ((cdrom[c].bus_type == 0) || (strlen(cdrom[c].image_path) == 0)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, cdrom[c].image_path); + ini_section_set_string(cat, temp, cdrom[c].image_path); } for (int i = 0; i < MAX_PREV_IMAGES; i++) { sprintf(temp, "cdrom_%02i_image_history_%02i", c + 1, i + 1); if((cdrom[c].image_history[i] == 0) || strlen(cdrom[c].image_history[i]) == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, cdrom[c].image_history[i]); + ini_section_set_string(cat, temp, cdrom[c].image_history[i]); } } } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } /* Save "Other Removable Devices" section. */ static void save_other_removable_devices(void) { - char *cat = "Other removable devices"; + ini_section_t cat = ini_find_or_create_section(config, "Other removable devices"); char temp[512], tmp2[512]; int c; for (c = 0; c < ZIP_NUM; c++) { sprintf(temp, "zip_%02i_parameters", c + 1); if (zip_drives[c].bus_type == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { sprintf(tmp2, "%u, %s", zip_drives[c].is_250, hdd_bus_to_string(zip_drives[c].bus_type, 1)); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "zip_%02i_ide_channel", c + 1); if (zip_drives[c].bus_type != ZIP_BUS_ATAPI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%01u", zip_drives[c].ide_channel >> 1, zip_drives[c].ide_channel & 1); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "zip_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "zip_%02i_scsi_location", c + 1); if (zip_drives[c].bus_type != ZIP_BUS_SCSI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", zip_drives[c].scsi_device_id >> 4, zip_drives[c].scsi_device_id & 15); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "zip_%02i_image_path", c + 1); if ((zip_drives[c].bus_type == 0) || (strlen(zip_drives[c].image_path) == 0)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, zip_drives[c].image_path); + ini_section_set_string(cat, temp, zip_drives[c].image_path); } } for (c = 0; c < MO_NUM; c++) { sprintf(temp, "mo_%02i_parameters", c + 1); if (mo_drives[c].bus_type == 0) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { sprintf(tmp2, "%u, %s", mo_drives[c].type, hdd_bus_to_string(mo_drives[c].bus_type, 1)); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "mo_%02i_ide_channel", c + 1); if (mo_drives[c].bus_type != MO_BUS_ATAPI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%01u", mo_drives[c].ide_channel >> 1, mo_drives[c].ide_channel & 1); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "mo_%02i_scsi_id", c + 1); - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); sprintf(temp, "mo_%02i_scsi_location", c + 1); if (mo_drives[c].bus_type != MO_BUS_SCSI) - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); else { sprintf(tmp2, "%01u:%02u", mo_drives[c].scsi_device_id >> 4, mo_drives[c].scsi_device_id & 15); - config_set_string(cat, temp, tmp2); + ini_section_set_string(cat, temp, tmp2); } sprintf(temp, "mo_%02i_image_path", c + 1); if ((mo_drives[c].bus_type == 0) || (strlen(mo_drives[c].image_path) == 0)) { - config_delete_var(cat, temp); + ini_section_delete_var(cat, temp); } else { - config_set_string(cat, temp, mo_drives[c].image_path); + ini_section_set_string(cat, temp, mo_drives[c].image_path); } } - delete_section_if_empty(cat); + ini_delete_section_if_empty(config, cat); } void @@ -3269,317 +2853,11 @@ config_save(void) save_other_removable_devices(); /* Other removable devices */ save_other_peripherals(); /* Other peripherals */ - config_write(cfg_path); + ini_write(config, cfg_path); } -void -config_dump(void) +ini_t +config_get_ini(void) { - section_t *sec; - - sec = (section_t *) config_head.next; - while (sec != NULL) { - entry_t *ent; - - if (sec->name[0]) - config_log("[%s]\n", sec->name); - - ent = (entry_t *) sec->entry_head.next; - while (ent != NULL) { - config_log("%s = %s\n", ent->name, ent->data); - - ent = (entry_t *) ent->list.next; - } - - sec = (section_t *) sec->list.next; - } -} - -void -config_delete_var(char *head, char *name) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - if (section == NULL) - return; - - entry = find_entry(section, name); - if (entry != NULL) { - list_delete(&entry->list, §ion->entry_head); - free(entry); - } -} - -int -config_get_int(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - int value; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - sscanf(entry->data, "%i", &value); - - return (value); -} - -double -config_get_double(char *head, char *name, double def) -{ - section_t *section; - entry_t *entry; - double value; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - sscanf(entry->data, "%lg", &value); - - return (value); -} - -int -config_get_hex16(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - unsigned int value; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - sscanf(entry->data, "%04X", &value); - - return (value); -} - -int -config_get_hex20(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - unsigned int value; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - sscanf(entry->data, "%05X", &value); - - return (value); -} - -int -config_get_mac(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - unsigned int val0 = 0, val1 = 0, val2 = 0; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); - - return ((val0 << 16) + (val1 << 8) + val2); -} - -char * -config_get_string(char *head, char *name, char *def) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - return (entry->data); -} - -wchar_t * -config_get_wstring(char *head, char *name, wchar_t *def) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - if (section == NULL) - return (def); - - entry = find_entry(section, name); - if (entry == NULL) - return (def); - - return (entry->wdata); -} - -void -config_set_int(char *head, char *name, int val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - sprintf(ent->data, "%i", val); - mbstowcs(ent->wdata, ent->data, 512); -} - -void -config_set_double(char *head, char *name, double val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - sprintf(ent->data, "%lg", val); - mbstowcs(ent->wdata, ent->data, 512); -} - -void -config_set_hex16(char *head, char *name, int val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - sprintf(ent->data, "%04X", val); - mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); -} - -void -config_set_hex20(char *head, char *name, int val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - sprintf(ent->data, "%05X", val); - mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); -} - -void -config_set_mac(char *head, char *name, int val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - sprintf(ent->data, "%02x:%02x:%02x", - (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); - mbstowcs(ent->wdata, ent->data, 512); -} - -void -config_set_string(char *head, char *name, char *val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - if ((strlen(val) + 1) <= sizeof(ent->data)) - memcpy(ent->data, val, strlen(val) + 1); - else - memcpy(ent->data, val, sizeof(ent->data)); -#ifdef _WIN32 /* Make sure the string is converted from UTF-8 rather than a legacy codepage */ - mbstoc16s(ent->wdata, ent->data, sizeof_w(ent->wdata)); -#else - mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); -#endif -} - -void -config_set_wstring(char *head, char *name, wchar_t *val) -{ - section_t *section; - entry_t *ent; - - section = find_section(head); - if (section == NULL) - section = create_section(head); - - ent = find_entry(section, name); - if (ent == NULL) - ent = create_entry(section, name); - - memcpy(ent->wdata, val, sizeof_w(ent->wdata)); -#ifdef _WIN32 /* Make sure the string is converted to UTF-8 rather than a legacy codepage */ - c16stombs(ent->data, ent->wdata, sizeof(ent->data)); -#else - wcstombs(ent->data, ent->wdata, sizeof(ent->data)); -#endif + return config; } diff --git a/src/device.c b/src/device.c index c69acaad0..0eace721e 100644 --- a/src/device.c +++ b/src/device.c @@ -45,6 +45,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include <86box/ini.h> #include <86box/config.h> #include <86box/device.h> #include <86box/machine.h> diff --git a/src/include/86box/config.h b/src/include/86box/config.h index 86bf39dce..1cddddaab 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -136,27 +136,33 @@ typedef struct { extern void config_load(void); extern void config_save(void); -extern void config_write(char *fn); -extern void config_dump(void); -extern void config_delete_var(char *head, char *name); -extern int config_get_int(char *head, char *name, int def); -extern double config_get_double(char *head, char *name, double def); -extern int config_get_hex16(char *head, char *name, int def); -extern int config_get_hex20(char *head, char *name, int def); -extern int config_get_mac(char *head, char *name, int def); -extern char *config_get_string(char *head, char *name, char *def); -extern wchar_t *config_get_wstring(char *head, char *name, wchar_t *def); -extern void config_set_int(char *head, char *name, int val); -extern void config_set_double(char *head, char *name, double val); -extern void config_set_hex16(char *head, char *name, int val); -extern void config_set_hex20(char *head, char *name, int val); -extern void config_set_mac(char *head, char *name, int val); -extern void config_set_string(char *head, char *name, char *val); -extern void config_set_wstring(char *head, char *name, wchar_t *val); +#ifdef EMU_INI_H +extern ini_t config_get_ini(void); +#else +extern void *config_get_ini(void); +#endif -extern void *config_find_section(char *name); -extern void config_rename_section(void *priv, char *name); +#define config_delete_var(head, name) ini_delete_var(config_get_ini(), head, name) + +#define config_get_int(head, name, def) ini_get_int(config_get_ini(), head, name, def) +#define config_get_double(head, name, def) ini_get_double(config_get_ini(), head, name, def) +#define config_get_hex16(head, name, def) ini_get_hex16(config_get_ini(), head, name, def) +#define config_get_hex20(head, name, def) ini_get_hex20(config_get_ini(), head, name, def) +#define config_get_mac(head, name, def) ini_get_mac(config_get_ini(), head, name, def) +#define config_get_string(head, name, def) ini_get_string(config_get_ini(), head, name, def) +#define config_get_wstring(head, name, def) ini_get_wstring(config_get_ini(), head, name, def) + +#define config_set_int(head, name, val) ini_set_int(config_get_ini(), head, name, val) +#define config_set_double(head, name, val) ini_set_double(config_get_ini(), head, name, val) +#define config_set_hex16(head, name, val) ini_set_hex16(config_get_ini(), head, name, val) +#define config_set_hex20(head, name, val) ini_set_hex20(config_get_ini(), head, name, val) +#define config_set_mac(head, name, val) ini_set_mac(config_get_ini(), head, name, val) +#define config_set_string(head, name, val) ini_set_string(config_get_ini(), head, name, val) +#define config_set_wstring(head, name, val) ini_set_wstring(config_get_ini(), head, name, val) + +#define config_find_section(name) ini_find_section(config_get_ini(), name) +#define config_rename_section ini_rename_section #ifdef __cplusplus } diff --git a/src/include/86box/ini.h b/src/include/86box/ini.h new file mode 100644 index 000000000..43b71f357 --- /dev/null +++ b/src/include/86box/ini.h @@ -0,0 +1,81 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Configuration file handler header. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Fred N. van Kempen, + * Overdoze, + * + * Copyright 2008-2017 Sarah Walker. + * Copyright 2016,2017 Miran Grca. + * + */ +#ifndef EMU_INI_H +#define EMU_INI_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *ini_t; +typedef void *ini_section_t; + +extern ini_t ini_new(void); +extern ini_t ini_read(char *fn); +extern void ini_write(ini_t ini, char *fn); +extern void ini_dump(ini_t ini); +extern void ini_close(ini_t ini); + +extern void ini_section_delete_var(ini_section_t section, char *name); +extern int ini_section_get_int(ini_section_t section, char *name, int def); +extern double ini_section_get_double(ini_section_t section, char *name, double def); +extern int ini_section_get_hex16(ini_section_t section, char *name, int def); +extern int ini_section_get_hex20(ini_section_t section, char *name, int def); +extern int ini_section_get_mac(ini_section_t section, char *name, int def); +extern char *ini_section_get_string(ini_section_t section, char *name, char *def); +extern wchar_t *ini_section_get_wstring(ini_section_t section, char *name, wchar_t *def); +extern void ini_section_set_int(ini_section_t section, char *name, int val); +extern void ini_section_set_double(ini_section_t section, char *name, double val); +extern void ini_section_set_hex16(ini_section_t section, char *name, int val); +extern void ini_section_set_hex20(ini_section_t section, char *name, int val); +extern void ini_section_set_mac(ini_section_t section, char *name, int val); +extern void ini_section_set_string(ini_section_t section, char *name, char *val); +extern void ini_section_set_wstring(ini_section_t section, char *name, wchar_t *val); + +#define ini_delete_var(ini, head, name) ini_section_delete_var(ini_find_section(ini, head), name) + +#define ini_get_int(ini, head, name, def) ini_section_get_int(ini_find_section(ini, head), name, def) +#define ini_get_double(ini, head, name, def) ini_section_get_double(ini_find_section(ini, head), name, def) +#define ini_get_hex16(ini, head, name, def) ini_section_get_hex16(ini_find_section(ini, head), name, def) +#define ini_get_hex20(ini, head, name, def) ini_section_get_hex20(ini_find_section(ini, head), name, def) +#define ini_get_mac(ini, head, name, def) ini_section_get_mac(ini_find_section(ini, head), name, def) +#define ini_get_string(ini, head, name, def) ini_section_get_string(ini_find_section(ini, head), name, def) +#define ini_get_wstring(ini, head, name, def) ini_section_get_wstring(ini_find_section(ini, head), name, def) + +#define ini_set_int(ini, head, name, val) ini_section_set_int(ini_find_or_create_section(ini, head), name, val) +#define ini_set_double(ini, head, name, val) ini_section_set_double(ini_find_or_create_section(ini, head), name, val) +#define ini_set_hex16(ini, head, name, val) ini_section_set_hex16(ini_find_or_create_section(ini, head), name, val) +#define ini_set_hex20(ini, head, name, val) ini_section_set_hex20(ini_find_or_create_section(ini, head), name, val) +#define ini_set_mac(ini, head, name, val) ini_section_set_mac(ini_find_or_create_section(ini, head), name, val) +#define ini_set_string(ini, head, name, val) ini_section_set_string(ini_find_or_create_section(ini, head), name, val) +#define ini_set_wstring(ini, head, name, val) ini_section_set_wstring(ini_find_or_create_section(ini, head), name, val) + +extern ini_section_t ini_find_section(ini_t ini, char *name); +extern ini_section_t ini_find_or_create_section(ini_t ini, char *name); +extern void ini_rename_section(ini_section_t section, char *name); +extern void ini_delete_section_if_empty(ini_t ini, ini_section_t section); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/ini.c b/src/ini.c new file mode 100644 index 000000000..167d3c67e --- /dev/null +++ b/src/ini.c @@ -0,0 +1,795 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Configuration file handler. + * + * + * + * Authors: Sarah Walker, + * Miran Grca, + * Fred N. van Kempen, + * Overdoze, + * David Hrdlička, + * + * Copyright 2008-2019 Sarah Walker. + * Copyright 2016-2019 Miran Grca. + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2018,2019 David Hrdlička. + * + * NOTE: Forcing config files to be in Unicode encoding breaks + * it on Windows XP, and possibly also Vista. Use the + * -DANSI_CFG for use on these systems. + */ + +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/ini.h> +#include <86box/plat.h> + +typedef struct _list_ { + struct _list_ *next; +} list_t; + +typedef struct { + list_t list; + + char name[128]; + + list_t entry_head; +} section_t; + +typedef struct { + list_t list; + + char name[128]; + char data[512]; + wchar_t wdata[512]; +} entry_t; + +#define list_add(new, head) \ + { \ + list_t *next = head; \ + \ + while (next->next != NULL) \ + next = next->next; \ + \ + (next)->next = new; \ + (new)->next = NULL; \ + } + +#define list_delete(old, head) \ + { \ + list_t *next = head; \ + \ + while ((next)->next != old) { \ + next = (next)->next; \ + } \ + \ + (next)->next = (old)->next; \ + if ((next) == (head)) \ + (head)->next = (old)->next; \ + } + +#ifdef ENABLE_INI_LOG +int ini_do_log = ENABLE_INI_LOG; + +static void +ini_log(const char *fmt, ...) +{ + va_list ap; + + if (ini_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ini_log(fmt, ...) +#endif + +static section_t * +find_section(list_t *head, char *name) +{ + section_t *sec = (section_t *) head->next; + char blank[] = ""; + + if (name == NULL) + name = blank; + + while (sec != NULL) { + if (!strncmp(sec->name, name, sizeof(sec->name))) + return (sec); + + sec = (section_t *) sec->list.next; + } + + return NULL; +} + +ini_section_t +ini_find_section(ini_t ini, char *name) +{ + if (ini == NULL) + return NULL; + + return (ini_section_t) find_section((list_t *) ini, name); +} + +void +ini_rename_section(ini_section_t section, char *name) +{ + section_t *sec = (section_t *) section; + + if (sec == NULL) + return; + + memset(sec->name, 0x00, sizeof(sec->name)); + memcpy(sec->name, name, MIN(128, strlen(name) + 1)); +} + +static entry_t * +find_entry(section_t *section, char *name) +{ + entry_t *ent; + + ent = (entry_t *) section->entry_head.next; + + while (ent != NULL) { + if (!strncmp(ent->name, name, sizeof(ent->name))) + return (ent); + + ent = (entry_t *) ent->list.next; + } + + return (NULL); +} + +static int +entries_num(section_t *section) +{ + entry_t *ent; + int i = 0; + + ent = (entry_t *) section->entry_head.next; + + while (ent != NULL) { + if (strlen(ent->name) > 0) + i++; + + ent = (entry_t *) ent->list.next; + } + + return (i); +} + +static void +delete_section_if_empty(list_t *head, section_t *section) +{ + if (section == NULL) + return; + + if (entries_num(section) == 0) { + list_delete(§ion->list, head); + free(section); + } +} + +void +ini_delete_section_if_empty(ini_t ini, ini_section_t section) +{ + if (ini == NULL || section == NULL) + return; + + delete_section_if_empty((list_t *) ini, (section_t *) section); +} + +static section_t * +create_section(list_t *head, char *name) +{ + section_t *ns = malloc(sizeof(section_t)); + + memset(ns, 0x00, sizeof(section_t)); + memcpy(ns->name, name, strlen(name) + 1); + list_add(&ns->list, head); + + return (ns); +} + +ini_section_t +ini_find_or_create_section(ini_t ini, char *name) +{ + if (ini == NULL) + return NULL; + + section_t *section = find_section((list_t *) ini, name); + if (section == NULL) + section = create_section((list_t *) ini, name); + + return (ini_section_t) section; +} + +static entry_t * +create_entry(section_t *section, char *name) +{ + entry_t *ne = malloc(sizeof(entry_t)); + + memset(ne, 0x00, sizeof(entry_t)); + memcpy(ne->name, name, strlen(name) + 1); + list_add(&ne->list, §ion->entry_head); + + return (ne); +} + +static void +ini_close(ini_t ini) +{ + section_t *sec, *ns; + entry_t *ent; + list_t *list = (list_t *) ini; + + if (list == NULL) + return; + + sec = (section_t *) list->next; + while (sec != NULL) { + ns = (section_t *) sec->list.next; + ent = (entry_t *) sec->entry_head.next; + + while (ent != NULL) { + entry_t *nent = (entry_t *) ent->list.next; + + free(ent); + ent = nent; + } + + free(sec); + sec = ns; + } + + free(list); +} + +static int +ini_detect_bom(char *fn) +{ + FILE *f; + unsigned char bom[4] = { 0, 0, 0, 0 }; + +#if defined(ANSI_CFG) || !defined(_WIN32) + f = plat_fopen(fn, "rt"); +#else + f = plat_fopen(fn, "rt, ccs=UTF-8"); +#endif + if (f == NULL) + return (0); + fread(bom, 1, 3, f); + if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { + fclose(f); + return 1; + } + fclose(f); + return 0; +} + +#ifdef __HAIKU__ +/* Local version of fgetws to avoid a crash */ +static wchar_t * +ini_fgetws(wchar_t *str, int count, FILE *stream) +{ + int i = 0; + if (feof(stream)) + return NULL; + for (i = 0; i < count; i++) { + wint_t curChar = fgetwc(stream); + if (curChar == WEOF) { + if (i + 1 < count) + str[i + 1] = 0; + return feof(stream) ? str : NULL; + } + str[i] = curChar; + if (curChar == '\n') + break; + } + if (i + 1 < count) + str[i + 1] = 0; + return str; +} +#endif + +/* Read and parse the configuration file into memory. */ +ini_t +ini_read(char *fn) +{ + char sname[128], ename[128]; + wchar_t buff[1024]; + section_t *sec, *ns; + entry_t *ne; + int c, d, bom; + FILE *f; + list_t *head; + + bom = ini_detect_bom(fn); +#if defined(ANSI_CFG) || !defined(_WIN32) + f = plat_fopen(fn, "rt"); +#else + f = plat_fopen(fn, "rt, ccs=UTF-8"); +#endif + if (f == NULL) + return NULL; + + head = malloc(sizeof(list_t)); + memset(head, 0x00, sizeof(list_t)); + + sec = malloc(sizeof(section_t)); + memset(sec, 0x00, sizeof(section_t)); + + list_add(&sec->list, head); + if (bom) + fseek(f, 3, SEEK_SET); + + while (1) { + memset(buff, 0x00, sizeof(buff)); +#ifdef __HAIKU__ + ini_fgetws(buff, sizeof_w(buff), f); +#else + (void) !fgetws(buff, sizeof_w(buff), f); +#endif + if (feof(f)) + break; + + /* Make sure there are no stray newlines or hard-returns in there. */ + if (wcslen(buff) > 0) + if (buff[wcslen(buff) - 1] == L'\n') + buff[wcslen(buff) - 1] = L'\0'; + if (wcslen(buff) > 0) + if (buff[wcslen(buff) - 1] == L'\r') + buff[wcslen(buff) - 1] = L'\0'; + + /* Skip any leading whitespace. */ + c = 0; + while ((buff[c] == L' ') || (buff[c] == L'\t')) + c++; + + /* Skip empty lines. */ + if (buff[c] == L'\0') + continue; + + /* Skip lines that (only) have a comment. */ + if ((buff[c] == L'#') || (buff[c] == L';')) + continue; + + if (buff[c] == L'[') { /*Section*/ + c++; + d = 0; + while (buff[c] != L']' && buff[c]) + (void) !wctomb(&(sname[d++]), buff[c++]); + sname[d] = L'\0'; + + /* Is the section name properly terminated? */ + if (buff[c] != L']') + continue; + + /* Create a new section and insert it. */ + ns = malloc(sizeof(section_t)); + memset(ns, 0x00, sizeof(section_t)); + memcpy(ns->name, sname, 128); + list_add(&ns->list, head); + + /* New section is now the current one. */ + sec = ns; + continue; + } + + /* Get the variable name. */ + d = 0; + while ((buff[c] != L'=') && (buff[c] != L' ') && buff[c]) + (void) !wctomb(&(ename[d++]), buff[c++]); + ename[d] = L'\0'; + + /* Skip incomplete lines. */ + if (buff[c] == L'\0') + continue; + + /* Look for =, skip whitespace. */ + while ((buff[c] == L'=' || buff[c] == L' ') && buff[c]) + c++; + + /* Skip incomplete lines. */ + if (buff[c] == L'\0') + continue; + + /* This is where the value part starts. */ + d = c; + + /* Allocate a new variable entry.. */ + ne = malloc(sizeof(entry_t)); + memset(ne, 0x00, sizeof(entry_t)); + memcpy(ne->name, ename, 128); + wcsncpy(ne->wdata, &buff[d], sizeof_w(ne->wdata) - 1); + ne->wdata[sizeof_w(ne->wdata) - 1] = L'\0'; +#ifdef _WIN32 /* Make sure the string is converted to UTF-8 rather than a legacy codepage */ + c16stombs(ne->data, ne->wdata, sizeof(ne->data)); +#else + wcstombs(ne->data, ne->wdata, sizeof(ne->data)); +#endif + ne->data[sizeof(ne->data) - 1] = '\0'; + + /* .. and insert it. */ + list_add(&ne->list, &sec->entry_head); + } + + (void) fclose(f); + + return (ini_t) head; +} + +/* Write the in-memory configuration to disk. */ +void +ini_write(ini_t ini, char *fn) +{ + wchar_t wtemp[512]; + list_t *list = (list_t *) ini; + section_t *sec; + FILE *f; + int fl = 0; + + if (list == NULL) + return; + + sec = (section_t *) list->next; + +#if defined(ANSI_CFG) || !defined(_WIN32) + f = plat_fopen(fn, "wt"); +#else + f = plat_fopen(fn, "wt, ccs=UTF-8"); +#endif + if (f == NULL) + return; + + while (sec != NULL) { + entry_t *ent; + + if (sec->name[0]) { + mbstowcs(wtemp, sec->name, strlen(sec->name) + 1); + if (fl) + fwprintf(f, L"\n[%ls]\n", wtemp); + else + fwprintf(f, L"[%ls]\n", wtemp); + fl++; + } + + ent = (entry_t *) sec->entry_head.next; + while (ent != NULL) { + if (ent->name[0] != '\0') { + mbstowcs(wtemp, ent->name, 128); + if (ent->wdata[0] == L'\0') + fwprintf(f, L"%ls = \n", wtemp); + else + fwprintf(f, L"%ls = %ls\n", wtemp, ent->wdata); + fl++; + } + + ent = (entry_t *) ent->list.next; + } + + sec = (section_t *) sec->list.next; + } + + (void) fclose(f); +} + +ini_t +ini_new() +{ + ini_t ini = malloc(sizeof(list_t)); + memset(ini, 0, sizeof(list_t)); + return ini; +} + +void +ini_dump(ini_t ini) +{ + section_t *sec = (section_t *) ini; + while (sec != NULL) { + entry_t *ent; + + if (sec->name[0]) + ini_log("[%s]\n", sec->name); + + ent = (entry_t *) sec->entry_head.next; + while (ent != NULL) { + ini_log("%s = %s\n", ent->name, ent->data); + + ent = (entry_t *) ent->list.next; + } + + sec = (section_t *) sec->list.next; + } +} + +void +ini_section_delete_var(ini_section_t self, char *name) +{ + section_t *section = (section_t *) self; + entry_t *entry; + + if (section == NULL) + return; + + entry = find_entry(section, name); + if (entry != NULL) { + list_delete(&entry->list, §ion->entry_head); + free(entry); + } +} + +int +ini_section_get_int(ini_section_t self, char *name, int def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + int value; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + sscanf(entry->data, "%i", &value); + + return (value); +} + +double +ini_section_get_double(ini_section_t self, char *name, double def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + double value; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + sscanf(entry->data, "%lg", &value); + + return (value); +} + +int +ini_section_get_hex16(ini_section_t self, char *name, int def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + unsigned int value; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + sscanf(entry->data, "%04X", &value); + + return (value); +} + +int +ini_section_get_hex20(ini_section_t self, char *name, int def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + unsigned int value; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + sscanf(entry->data, "%05X", &value); + + return (value); +} + +int +ini_section_get_mac(ini_section_t self, char *name, int def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + unsigned int val0 = 0, val1 = 0, val2 = 0; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); + + return ((val0 << 16) + (val1 << 8) + val2); +} + +char * +ini_section_get_string(ini_section_t self, char *name, char *def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + return (entry->data); +} + +wchar_t * +ini_section_get_wstring(ini_section_t self, char *name, wchar_t *def) +{ + section_t *section = (section_t *) self; + entry_t *entry; + + if (section == NULL) + return (def); + + entry = find_entry(section, name); + if (entry == NULL) + return (def); + + return (entry->wdata); +} + +void +ini_section_set_int(ini_section_t self, char *name, int val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + sprintf(ent->data, "%i", val); + mbstowcs(ent->wdata, ent->data, 512); +} + +void +ini_section_set_double(ini_section_t self, char *name, double val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + sprintf(ent->data, "%lg", val); + mbstowcs(ent->wdata, ent->data, 512); +} + +void +ini_section_set_hex16(ini_section_t self, char *name, int val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + sprintf(ent->data, "%04X", val); + mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); +} + +void +ini_section_set_hex20(ini_section_t self, char *name, int val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + sprintf(ent->data, "%05X", val); + mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); +} + +void +ini_section_set_mac(ini_section_t self, char *name, int val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + sprintf(ent->data, "%02x:%02x:%02x", + (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); + mbstowcs(ent->wdata, ent->data, 512); +} + +void +ini_section_set_string(ini_section_t self, char *name, char *val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + if ((strlen(val) + 1) <= sizeof(ent->data)) + memcpy(ent->data, val, strlen(val) + 1); + else + memcpy(ent->data, val, sizeof(ent->data)); +#ifdef _WIN32 /* Make sure the string is converted from UTF-8 rather than a legacy codepage */ + mbstoc16s(ent->wdata, ent->data, sizeof_w(ent->wdata)); +#else + mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata)); +#endif +} + +void +ini_section_set_wstring(ini_section_t self, char *name, wchar_t *val) +{ + section_t *section = (section_t *) self; + entry_t *ent; + + if (section == NULL) + return; + + ent = find_entry(section, name); + if (ent == NULL) + ent = create_entry(section, name); + + memcpy(ent->wdata, val, sizeof_w(ent->wdata)); +#ifdef _WIN32 /* Make sure the string is converted to UTF-8 rather than a legacy codepage */ + c16stombs(ent->data, ent->wdata, sizeof(ent->data)); +#else + wcstombs(ent->data, ent->wdata, sizeof(ent->data)); +#endif +} diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 24b75e208..0bbd534b3 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -35,6 +35,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/machine.h> +#include <86box/ini.h> #include <86box/config.h> #include <86box/video.h> #ifdef _WIN32 diff --git a/src/qt/qt_deviceconfig.cpp b/src/qt/qt_deviceconfig.cpp index 6ebc59b5d..7218aab6e 100644 --- a/src/qt/qt_deviceconfig.cpp +++ b/src/qt/qt_deviceconfig.cpp @@ -28,6 +28,7 @@ extern "C" { #include <86box/86box.h> +#include <86box/ini.h> #include <86box/config.h> #include <86box/device.h> #include <86box/midi_rtmidi.h> diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index c60f224ab..16538cf9e 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -34,6 +34,7 @@ extern "C" #include <86box/device.h> #include <86box/midi.h> #include <86box/midi_rtmidi.h> +#include <86box/ini.h> #include <86box/config.h> // Disable c99-designator to avoid the warnings in rtmidi_*_device From 08f48b8b00256ad6b475b3099d12fbecbb6d4ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 10 Sep 2022 13:47:36 +0200 Subject: [PATCH 10/14] ini: Fix `ini_close` definition --- src/ini.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ini.c b/src/ini.c index 167d3c67e..6c4565bb9 100644 --- a/src/ini.c +++ b/src/ini.c @@ -233,7 +233,7 @@ create_entry(section_t *section, char *name) return (ne); } -static void +void ini_close(ini_t ini) { section_t *sec, *ns; From 2cc7fc666bf38e68f00ad1be36abbc07a3e0f8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 10 Sep 2022 13:48:48 +0200 Subject: [PATCH 11/14] ini: Add to legacy makefile --- src/win/Makefile.mingw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 6d5fb92fe..cdc59e485 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -536,7 +536,7 @@ CXXFLAGS := $(CFLAGS) ######################################################################### MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \ nmi.o pic.o pit.o pit_fast.o port_6x.o port_92.o ppi.o pci.o mca.o fifo8.o \ - usb.o device.o nvr.o nvr_at.o nvr_ps2.o machine_status.o \ + usb.o device.o nvr.o nvr_at.o nvr_ps2.o machine_status.o ini.o \ $(VNCOBJ) MEMOBJ := catalyst_flash.o i2c_eeprom.o intel_flash.o mem.o rom.o smram.o spd.o sst_flash.o From 70711759751380875c16a27058a8d98750760791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 10 Sep 2022 14:46:47 +0200 Subject: [PATCH 12/14] ini: Fix the legacy Windows UI --- src/win/win_devconf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/win_devconf.c b/src/win/win_devconf.c index c5ddf9cb6..602aaa174 100644 --- a/src/win/win_devconf.c +++ b/src/win/win_devconf.c @@ -22,6 +22,7 @@ #include #include #include <86box/86box.h> +#include <86box/ini.h> #include <86box/config.h> #include <86box/device.h> #include <86box/plat.h> From e5d6430ec8375276550ce1cdb32e9942d1e24345 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Mon, 12 Sep 2022 09:48:14 -0400 Subject: [PATCH 13/14] qt: Fix potential null pointer access in media history --- src/qt/qt_mediahistorymanager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qt/qt_mediahistorymanager.cpp b/src/qt/qt_mediahistorymanager.cpp index a672c0843..884a13de5 100644 --- a/src/qt/qt_mediahistorymanager.cpp +++ b/src/qt/qt_mediahistorymanager.cpp @@ -132,8 +132,9 @@ void MediaHistoryManager::serializeImageHistoryType(ui::MediaType type) continue; } for ( int slot = 0; slot < MAX_PREV_IMAGES; slot++) { - strncpy(device_history_ptr[slot], master_list[type][device][slot].toUtf8().constData(), MAX_IMAGE_PATH_LEN); - + if (device_history_ptr[slot] != nullptr) { + strncpy(device_history_ptr[slot], master_list[type][device][slot].toUtf8().constData(), MAX_IMAGE_PATH_LEN); + } } } } From dc046c5b5f5ffa5e3a50eb853d5b57bbc4f0d535 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Mon, 12 Sep 2022 10:10:22 -0400 Subject: [PATCH 14/14] qt: Use a single loop for icon dir search --- src/qt/qt_progsettings.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index dcfdbab85..6018b0158 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -46,16 +46,12 @@ QTranslator* ProgSettings::qtTranslator = nullptr; QString ProgSettings::getIconSetPath() { if (iconset_to_qt.isEmpty()) { - QVector roms_dirs; - // Walk rom_paths to get the candidates - for (rom_path_t *emu_rom_path = &rom_paths; emu_rom_path != nullptr; emu_rom_path = emu_rom_path->next) { - roms_dirs.append(QFileInfo(emu_rom_path->path)); - } // Always include default bundled icons iconset_to_qt.insert("", ":/settings/win/icons"); - for (auto &checked_dir : roms_dirs) { + // Walk rom_paths to get the candidates + for (rom_path_t *emu_rom_path = &rom_paths; emu_rom_path != nullptr; emu_rom_path = emu_rom_path->next) { // Check for icons subdir in each candidate - QDir roms_icons_dir(checked_dir.filePath() + "/icons"); + QDir roms_icons_dir(QString(emu_rom_path->path) + "/icons"); if (roms_icons_dir.isReadable()) { auto dirList = roms_icons_dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable); for (auto &curIconSet : dirList) {