2022-04-13 21:25:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-06-02 08:23:21 +00:00
|
|
|
Copyright (C) 2018-24 divingkatae and maximum
|
2022-04-13 21:25:28 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** ATI Mach64 GX emulation.
|
|
|
|
It emulates an ATI88800GX controller with an IBM RGB514 style RAMDAC.
|
2023-04-10 20:19:55 +00:00
|
|
|
Emulation is limited to a basic frame buffer for now.
|
2022-04-13 21:25:28 +00:00
|
|
|
*/
|
|
|
|
|
2023-04-10 20:19:55 +00:00
|
|
|
#include <core/bitops.h>
|
2022-07-17 03:44:19 +00:00
|
|
|
#include <devices/deviceregistry.h>
|
2022-04-13 21:25:28 +00:00
|
|
|
#include <devices/video/atimach64gx.h>
|
|
|
|
#include <devices/video/displayid.h>
|
|
|
|
#include <devices/video/rgb514defs.h>
|
|
|
|
#include <loguru.hpp>
|
|
|
|
#include <memaccess.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2024-02-28 02:14:57 +00:00
|
|
|
/* Human readable Mach64 HW register names for easier debugging. */
|
|
|
|
static const std::map<uint16_t, std::string> mach64_reg_names = {
|
|
|
|
#define one_reg_name(x) {ATI_ ## x, #x}
|
|
|
|
one_reg_name(CRTC_H_TOTAL_DISP),
|
|
|
|
one_reg_name(CRTC_H_SYNC_STRT_WID),
|
|
|
|
one_reg_name(CRTC_V_TOTAL_DISP),
|
|
|
|
one_reg_name(CRTC_V_SYNC_STRT_WID),
|
|
|
|
one_reg_name(CRTC_VLINE_CRNT_VLINE),
|
|
|
|
one_reg_name(CRTC_OFF_PITCH),
|
|
|
|
one_reg_name(CRTC_INT_CNTL),
|
|
|
|
one_reg_name(CRTC_GEN_CNTL),
|
|
|
|
one_reg_name(DSP_CONFIG),
|
|
|
|
one_reg_name(DSP_ON_OFF),
|
|
|
|
one_reg_name(MEM_BUF_CNTL),
|
|
|
|
one_reg_name(MEM_ADDR_CFG),
|
|
|
|
one_reg_name(OVR_CLR),
|
|
|
|
one_reg_name(OVR_WID_LEFT_RIGHT),
|
|
|
|
one_reg_name(OVR_WID_TOP_BOTTOM),
|
|
|
|
one_reg_name(CUR_CLR0),
|
|
|
|
one_reg_name(CUR_CLR1),
|
|
|
|
one_reg_name(CUR_OFFSET),
|
|
|
|
one_reg_name(CUR_HORZ_VERT_POSN),
|
|
|
|
one_reg_name(CUR_HORZ_VERT_OFF),
|
|
|
|
one_reg_name(GP_IO),
|
|
|
|
one_reg_name(HW_DEBUG),
|
|
|
|
one_reg_name(SCRATCH_REG0),
|
|
|
|
one_reg_name(SCRATCH_REG1),
|
|
|
|
one_reg_name(SCRATCH_REG2),
|
|
|
|
one_reg_name(SCRATCH_REG3),
|
|
|
|
one_reg_name(CLOCK_CNTL),
|
|
|
|
one_reg_name(BUS_CNTL),
|
|
|
|
one_reg_name(EXT_MEM_CNTL),
|
|
|
|
one_reg_name(MEM_CNTL),
|
|
|
|
one_reg_name(DAC_REGS),
|
|
|
|
one_reg_name(DAC_CNTL),
|
|
|
|
one_reg_name(GEN_TEST_CNTL),
|
|
|
|
one_reg_name(CUSTOM_MACRO_CNTL),
|
|
|
|
one_reg_name(CONFIG_CNTL),
|
|
|
|
one_reg_name(CONFIG_CHIP_ID),
|
|
|
|
one_reg_name(CONFIG_STAT0),
|
|
|
|
one_reg_name(DST_OFF_PITCH),
|
|
|
|
one_reg_name(DST_X),
|
|
|
|
one_reg_name(DST_Y),
|
|
|
|
one_reg_name(DST_WIDTH),
|
|
|
|
one_reg_name(DST_HEIGHT),
|
|
|
|
one_reg_name(SRC_CNTL),
|
|
|
|
one_reg_name(SCALE_3D_CNTL),
|
|
|
|
one_reg_name(PAT_REG0),
|
|
|
|
one_reg_name(PAT_REG1),
|
|
|
|
one_reg_name(SC_LEFT),
|
|
|
|
one_reg_name(SC_RIGHT),
|
|
|
|
one_reg_name(SC_TOP),
|
|
|
|
one_reg_name(SC_BOTTOM),
|
|
|
|
one_reg_name(DP_BKGD_CLR),
|
|
|
|
one_reg_name(DP_FRGD_CLR), // also DP_FOG_CLR for GT
|
|
|
|
one_reg_name(DP_WRITE_MSK),
|
|
|
|
one_reg_name(DP_PIX_WIDTH),
|
|
|
|
one_reg_name(DP_MIX),
|
|
|
|
one_reg_name(DP_SRC),
|
|
|
|
one_reg_name(CLR_CMP_CNTL),
|
|
|
|
one_reg_name(FIFO_STAT),
|
|
|
|
one_reg_name(GUI_TRAJ_CNTL),
|
|
|
|
one_reg_name(GUI_STAT),
|
|
|
|
one_reg_name(MPP_CONFIG),
|
|
|
|
one_reg_name(MPP_STROBE_SEQ),
|
|
|
|
one_reg_name(MPP_ADDR),
|
|
|
|
one_reg_name(MPP_DATA),
|
|
|
|
one_reg_name(TVO_CNTL),
|
|
|
|
one_reg_name(SETUP_CNTL),
|
|
|
|
#undef one_reg_name
|
|
|
|
};
|
|
|
|
|
|
|
|
static const std::map<uint16_t, std::string> rgb514_reg_names = {
|
|
|
|
#define one_reg_name(x) {Rgb514::x, #x}
|
|
|
|
one_reg_name(MISC_CLK_CNTL),
|
|
|
|
one_reg_name(HOR_SYNC_POS),
|
|
|
|
one_reg_name(PWR_MNMGMT),
|
|
|
|
one_reg_name(PIX_FORMAT),
|
|
|
|
one_reg_name(PLL_CTL_1),
|
|
|
|
one_reg_name(F0_M0),
|
|
|
|
one_reg_name(F1_N0),
|
|
|
|
one_reg_name(MISC_CNTL_1),
|
|
|
|
one_reg_name(MISC_CNTL_2),
|
|
|
|
one_reg_name(VRAM_MASK_LO),
|
|
|
|
one_reg_name(VRAM_MASK_HI),
|
|
|
|
#undef one_reg_name
|
|
|
|
};
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
AtiMach64Gx::AtiMach64Gx()
|
2024-04-23 12:14:46 +00:00
|
|
|
: PCIDevice("ati-mach64-gx"), VideoCtrlBase()
|
2022-04-13 21:25:28 +00:00
|
|
|
{
|
|
|
|
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
|
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
// set up PCI configuration space header
|
2022-04-13 21:25:28 +00:00
|
|
|
this->vendor_id = PCI_VENDOR_ATI;
|
|
|
|
this->device_id = ATI_MACH64_GX_DEV_ID;
|
2024-02-28 05:19:54 +00:00
|
|
|
this->class_rev = (0x030000 << 8) | 0x03;
|
2024-04-16 08:57:19 +00:00
|
|
|
this->irq_pin = 1;
|
2024-02-28 05:19:54 +00:00
|
|
|
for (int i = 0; i < this->aperture_count; i++) {
|
|
|
|
this->bars_cfg[i] = (uint32_t)(-this->aperture_size[i] | this->aperture_flag[i]);
|
|
|
|
}
|
|
|
|
this->finish_config_bars();
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
this->pci_notify_bar_change = [this](int bar_num) {
|
|
|
|
this->notify_bar_change(bar_num);
|
|
|
|
};
|
|
|
|
|
|
|
|
// declare expansion ROM containing FCode and Mac OS drivers
|
|
|
|
if (this->attach_exp_rom_image(std::string("113-32900-004_Apple_MACH64.bin"))) {
|
2024-04-21 21:16:10 +00:00
|
|
|
LOG_F(WARNING, "%s: could not load ROM - this device may not work properly!",
|
|
|
|
this->name.c_str());
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initialize display identification
|
2024-04-20 07:55:29 +00:00
|
|
|
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
// allocate video RAM
|
2024-04-20 07:55:29 +00:00
|
|
|
this->vram_size = GET_INT_PROP("gfxmem_size") << 20; // convert MBs to bytes
|
2022-04-13 21:25:28 +00:00
|
|
|
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
2023-04-10 20:19:55 +00:00
|
|
|
|
|
|
|
// set up RAMDAC identification
|
2023-04-10 23:23:40 +00:00
|
|
|
this->regs[ATI_CONFIG_STAT0] = 1 << 9;
|
2024-02-28 06:11:55 +00:00
|
|
|
|
|
|
|
// stuff default values into chip registers
|
|
|
|
// this->regs[ATI_CONFIG_CHIP_ID] = (asic_id << ATI_CFG_CHIP_MAJOR) | (dev_id << ATI_CFG_CHIP_TYPE);
|
|
|
|
|
|
|
|
// set the FIFO
|
|
|
|
insert_bits<uint32_t>(this->regs[ATI_GUI_STAT], 32, ATI_FIFO_CNT, ATI_FIFO_CNT_size);
|
2024-02-28 06:12:23 +00:00
|
|
|
|
|
|
|
set_bit(regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS); // because blank_on is true
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-04-21 21:16:10 +00:00
|
|
|
void AtiMach64Gx::change_one_bar(uint32_t &aperture, uint32_t aperture_size,
|
|
|
|
uint32_t aperture_new, int bar_num)
|
|
|
|
{
|
2024-02-28 05:19:54 +00:00
|
|
|
if (aperture != aperture_new) {
|
|
|
|
if (aperture)
|
|
|
|
this->host_instance->pci_unregister_mmio_region(aperture, aperture_size, this);
|
|
|
|
|
|
|
|
aperture = aperture_new;
|
|
|
|
if (aperture)
|
|
|
|
this->host_instance->pci_register_mmio_region(aperture, aperture_size, this);
|
|
|
|
|
|
|
|
LOG_F(INFO, "%s: aperture[%d] set to 0x%08X", this->name.c_str(), bar_num, aperture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
void AtiMach64Gx::notify_bar_change(int bar_num)
|
|
|
|
{
|
|
|
|
if (bar_num) // only BAR0 is supported
|
|
|
|
return;
|
|
|
|
|
2024-04-21 21:16:10 +00:00
|
|
|
change_one_bar(this->aperture_base[bar_num], this->aperture_size[bar_num],
|
|
|
|
this->bars[bar_num] & ~15, bar_num);
|
|
|
|
// copy aperture address to CONFIG_CNTL:CFG_MEM_AP_LOC
|
2024-04-20 07:53:32 +00:00
|
|
|
insert_bits<uint32_t>(this->config_cntl[0], this->aperture_base[0] >> 22,
|
2024-04-21 21:16:10 +00:00
|
|
|
ATI_CFG_MEM_AP_LOC, ATI_CFG_MEM_AP_LOC_size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 05:24:30 +00:00
|
|
|
#if 0
|
|
|
|
uint32_t AtiMach64Gx::pci_cfg_read(uint32_t reg_offs, AccessDetails &details)
|
|
|
|
{
|
|
|
|
if (reg_offs < 64) {
|
|
|
|
return PCIDevice::pci_cfg_read(reg_offs, details);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reg_offs) {
|
|
|
|
default:
|
|
|
|
LOG_READ_UNIMPLEMENTED_CONFIG_REGISTER();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtiMach64Gx::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details)
|
|
|
|
{
|
|
|
|
if (reg_offs < 64) {
|
|
|
|
PCIDevice::pci_cfg_write(reg_offs, value, details);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reg_offs) {
|
|
|
|
default:
|
|
|
|
LOG_WRITE_UNIMPLEMENTED_CONFIG_REGISTER();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
// map I/O register index to MMIO register offset
|
|
|
|
static const uint32_t io_idx_to_reg_offset[32] = {
|
2024-02-28 02:16:19 +00:00
|
|
|
ATI_CRTC_H_TOTAL_DISP,
|
|
|
|
ATI_CRTC_H_SYNC_STRT_WID,
|
|
|
|
ATI_CRTC_V_TOTAL_DISP,
|
|
|
|
ATI_CRTC_V_SYNC_STRT_WID,
|
|
|
|
ATI_CRTC_VLINE_CRNT_VLINE,
|
|
|
|
ATI_CRTC_OFF_PITCH,
|
|
|
|
ATI_CRTC_INT_CNTL,
|
|
|
|
ATI_CRTC_GEN_CNTL,
|
|
|
|
ATI_OVR_CLR,
|
|
|
|
ATI_OVR_WID_LEFT_RIGHT,
|
|
|
|
ATI_OVR_WID_TOP_BOTTOM,
|
|
|
|
ATI_CUR_CLR0,
|
|
|
|
ATI_CUR_CLR1,
|
|
|
|
ATI_CUR_OFFSET,
|
|
|
|
ATI_CUR_HORZ_VERT_POSN,
|
|
|
|
ATI_CUR_HORZ_VERT_OFF,
|
|
|
|
ATI_SCRATCH_REG0,
|
|
|
|
ATI_SCRATCH_REG1,
|
|
|
|
ATI_CLOCK_CNTL,
|
|
|
|
ATI_BUS_CNTL,
|
|
|
|
ATI_MEM_CNTL,
|
|
|
|
ATI_MEM_VGA_WP_SEL,
|
|
|
|
ATI_MEM_VGA_RP_SEL,
|
|
|
|
ATI_DAC_REGS,
|
|
|
|
ATI_DAC_CNTL,
|
|
|
|
ATI_GEN_TEST_CNTL,
|
|
|
|
ATI_CONFIG_CNTL,
|
|
|
|
ATI_CONFIG_CHIP_ID,
|
|
|
|
ATI_CONFIG_STAT0,
|
|
|
|
ATI_GX_CONFIG_STAT1,
|
|
|
|
ATI_INVALID,
|
|
|
|
ATI_CRTC_H_TOTAL_DISP,
|
2022-04-13 21:25:28 +00:00
|
|
|
};
|
|
|
|
|
2024-02-28 05:27:56 +00:00
|
|
|
enum {
|
|
|
|
SPARSE_IO_BASE = 0x2EC
|
|
|
|
};
|
|
|
|
|
|
|
|
bool AtiMach64Gx::io_access_allowed(uint32_t offset) {
|
|
|
|
if ((offset & 0xFFFF03FC) == SPARSE_IO_BASE) {
|
|
|
|
if (this->command & 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
bool AtiMach64Gx::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
|
|
|
{
|
2024-02-28 05:27:56 +00:00
|
|
|
if (!this->io_access_allowed(offset)) {
|
2022-04-13 21:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-28 05:27:56 +00:00
|
|
|
uint32_t result = 0;
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
// convert ISA-style I/O address to MMIO register offset
|
2023-04-10 23:23:40 +00:00
|
|
|
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] * 4 + (offset & 3);
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
// CONFIG_CNTL is accessible from I/O space only
|
2023-04-10 23:23:40 +00:00
|
|
|
if ((offset >> 2) == ATI_CONFIG_CNTL) {
|
2024-02-28 05:27:56 +00:00
|
|
|
result = read_mem(((uint8_t *)&this->config_cntl) + (offset & 3), size);
|
2022-04-13 21:25:28 +00:00
|
|
|
} else {
|
2024-02-28 05:27:56 +00:00
|
|
|
result = BYTESWAP_SIZED(this->read_reg(offset, size), size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 05:27:56 +00:00
|
|
|
*res = result;
|
2022-04-13 21:25:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtiMach64Gx::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
|
|
|
{
|
2024-02-28 05:27:56 +00:00
|
|
|
if (!this->io_access_allowed(offset)) {
|
2022-04-13 21:25:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert ISA-style I/O address to MMIO register offset
|
2023-04-10 23:23:40 +00:00
|
|
|
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] * 4 + (offset & 3);
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
// CONFIG_CNTL is accessible from I/O space only
|
2023-04-10 23:23:40 +00:00
|
|
|
if ((offset >> 2) == ATI_CONFIG_CNTL) {
|
2024-04-20 07:53:32 +00:00
|
|
|
if (size + (offset & 3) > 4)
|
|
|
|
LOG_F(ERROR, "%s: size + offset > 4!", this->name.c_str());
|
2022-04-13 21:25:28 +00:00
|
|
|
write_mem(((uint8_t *)&this->config_cntl) + (offset & 3), value, size);
|
2024-04-20 07:53:32 +00:00
|
|
|
if (offset == ATI_CONFIG_CNTL << 2) {
|
|
|
|
switch (extract_bits<uint32_t>(this->config_cntl[0], ATI_CFG_MEM_AP_SIZE, ATI_CFG_MEM_AP_SIZE_size)) {
|
|
|
|
case 0:
|
|
|
|
LOG_F(WARNING, "%s: CONFIG_CNTL linear aperture disabled!", this->name.c_str());
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
LOG_F(INFO, "%s: CONFIG_CNTL aperture size set to 4MB", this->name.c_str());
|
|
|
|
this->mm_regs_offset = MM_REGS_2_OFF;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
LOG_F(INFO, "%s: CONFIG_CNTL aperture size set to 8MB", this->name.c_str());
|
|
|
|
this->mm_regs_offset = MM_REGS_0_OFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(ERROR, "%s: CONFIG_CNTL invalid aperture size", this->name.c_str());
|
|
|
|
}
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
2024-04-20 07:53:32 +00:00
|
|
|
|
|
|
|
LOG_F(INFO, "%s: write %s %04x.%c = %0*x = %08x", this->name.c_str(),
|
|
|
|
get_reg_name(offset >> 2), offset, SIZE_ARG(size), size * 2,
|
|
|
|
value, this->config_cntl[0]
|
|
|
|
);
|
2022-04-13 21:25:28 +00:00
|
|
|
} else {
|
2023-04-10 20:19:55 +00:00
|
|
|
this->write_reg(offset, BYTESWAP_SIZED(value, size), size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-02-28 02:14:57 +00:00
|
|
|
const char* AtiMach64Gx::get_reg_name(uint32_t reg_num) {
|
|
|
|
auto iter = mach64_reg_names.find(reg_num);
|
|
|
|
if (iter != mach64_reg_names.end()) {
|
|
|
|
return iter->second.c_str();
|
|
|
|
} else {
|
|
|
|
return "unknown Mach64 register";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:19:55 +00:00
|
|
|
uint32_t AtiMach64Gx::read_reg(uint32_t reg_offset, uint32_t size)
|
2022-04-13 21:25:28 +00:00
|
|
|
{
|
2024-02-28 08:43:14 +00:00
|
|
|
uint32_t reg_num = reg_offset >> 2;
|
2023-04-10 20:19:55 +00:00
|
|
|
uint32_t offset = reg_offset & 3;
|
2024-02-28 08:43:14 +00:00
|
|
|
uint64_t result = this->regs[reg_num];
|
2023-04-10 20:19:55 +00:00
|
|
|
|
2024-02-28 08:43:14 +00:00
|
|
|
if (offset || size != 4) { // slow path
|
2023-04-10 20:19:55 +00:00
|
|
|
if ((offset + size) > 4) {
|
2024-02-28 08:43:14 +00:00
|
|
|
result |= (uint64_t)(this->regs[reg_num + 1]) << 32;
|
2023-04-10 20:19:55 +00:00
|
|
|
}
|
2024-02-28 08:43:14 +00:00
|
|
|
result = extract_bits<uint64_t>(result, offset * 8, size * 8);
|
2023-04-10 20:19:55 +00:00
|
|
|
}
|
2024-02-28 08:43:14 +00:00
|
|
|
|
|
|
|
return static_cast<uint32_t>(result);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 23:45:45 +00:00
|
|
|
#define WRITE_VALUE_AND_LOG() \
|
|
|
|
do { \
|
|
|
|
this->regs[reg_num] = new_value; \
|
|
|
|
LOG_F(9, "%s: write %s %04x.%c = %0*x = %08x", this->name.c_str(), \
|
|
|
|
get_reg_name(reg_num), reg_offset, SIZE_ARG(size), size * 2, \
|
|
|
|
(uint32_t)extract_bits<uint64_t>(value, offset * 8, size * 8), new_value \
|
|
|
|
); \
|
|
|
|
} while (0)
|
|
|
|
|
2023-04-10 20:19:55 +00:00
|
|
|
void AtiMach64Gx::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size)
|
2022-04-13 21:25:28 +00:00
|
|
|
{
|
2024-02-28 08:43:14 +00:00
|
|
|
uint32_t reg_num = reg_offset >> 2;
|
2023-04-10 20:19:55 +00:00
|
|
|
uint32_t offset = reg_offset & 3;
|
2024-02-28 08:43:14 +00:00
|
|
|
uint32_t old_value = this->regs[reg_num];
|
|
|
|
uint32_t new_value;
|
2022-04-13 21:25:28 +00:00
|
|
|
|
2023-04-10 20:19:55 +00:00
|
|
|
if (offset || size != 4) { // slow path
|
|
|
|
if ((offset + size) > 4) {
|
|
|
|
ABORT_F("%s: unaligned DWORD writes not implemented", this->name.c_str());
|
|
|
|
}
|
2024-02-28 08:43:14 +00:00
|
|
|
uint64_t val = old_value;
|
|
|
|
insert_bits<uint64_t>(val, value, offset * 8, size * 8);
|
|
|
|
value = static_cast<uint32_t>(val);
|
2023-04-10 20:19:55 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 08:43:14 +00:00
|
|
|
switch (reg_num) {
|
2024-02-28 23:40:21 +00:00
|
|
|
case ATI_CRTC_H_TOTAL_DISP:
|
|
|
|
new_value = value;
|
|
|
|
LOG_F(9, "%s: ATI_CRTC_H_TOTAL_DISP set to 0x%08X", this->name.c_str(), value);
|
|
|
|
break;
|
2024-02-28 23:40:51 +00:00
|
|
|
case ATI_CRTC_VLINE_CRNT_VLINE:
|
|
|
|
new_value = old_value;
|
|
|
|
insert_bits<uint32_t>(new_value, value, ATI_CRTC_VLINE, ATI_CRTC_VLINE_size);
|
|
|
|
break;
|
2023-04-10 20:19:55 +00:00
|
|
|
case ATI_CRTC_OFF_PITCH:
|
2024-02-28 08:43:14 +00:00
|
|
|
new_value = value;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-02-29 00:08:32 +00:00
|
|
|
this->crtc_update();
|
2024-02-28 23:51:20 +00:00
|
|
|
return;
|
|
|
|
case ATI_CRTC_INT_CNTL:
|
|
|
|
{
|
|
|
|
uint32_t bits_read_only =
|
|
|
|
(1 << ATI_CRTC_VBLANK) |
|
|
|
|
(1 << ATI_CRTC_VLINE_SYNC) |
|
|
|
|
(1 << ATI_CRTC_FRAME) |
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
(1 << ATI_CRTC2_VBLANK) |
|
|
|
|
(1 << ATI_CRTC2_VLINE_SYNC) |
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
|
|
|
|
uint32_t bits_AK =
|
|
|
|
(1 << ATI_CRTC_VBLANK_INT_AK) |
|
|
|
|
(1 << ATI_CRTC_VLINE_INT_AK) |
|
|
|
|
#if 1
|
|
|
|
(1 << ATI_VIDEOIN_EVEN_INT_AK) |
|
|
|
|
(1 << ATI_VIDEOIN_ODD_INT_AK) |
|
|
|
|
(1 << ATI_OVERLAY_EOF_INT_AK) |
|
|
|
|
(1 << ATI_VMC_EC_INT_AK) |
|
|
|
|
#else
|
|
|
|
(1 << ATI_SNAPSHOT_INT_AK) |
|
|
|
|
(1 << ATI_I2C_INT_AK) |
|
|
|
|
(1 << ATI_CRTC2_VBLANK_INT_AK) |
|
|
|
|
(1 << ATI_CRTC2_VLINE_INT_AK) |
|
|
|
|
(1 << ATI_CUPBUF0_INT_AK) |
|
|
|
|
(1 << ATI_CUPBUF1_INT_AK) |
|
|
|
|
(1 << ATI_OVERLAY_EOF_INT_AK) |
|
|
|
|
(1 << ATI_ONESHOT_CAP_INT_AK) |
|
|
|
|
(1 << ATI_BUSMASTER_EOL_INT_AK) |
|
|
|
|
(1 << ATI_GP_INT_AK) |
|
|
|
|
(1 << ATI_SNAPSHOT2_INT_AK) |
|
|
|
|
(1 << ATI_VBLANK_BIT2_INT_AK) |
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
/*
|
|
|
|
uint32_t bits_EN =
|
|
|
|
(1 << ATI_CRTC_VBLANK_INT_EN) |
|
|
|
|
(1 << ATI_CRTC_VLINE_INT_EN) |
|
|
|
|
#if 1
|
|
|
|
(1 << ATI_VIDEOIN_EVEN_INT_EN) |
|
|
|
|
(1 << ATI_VIDEOIN_ODD_INT_EN) |
|
|
|
|
(1 << ATI_OVERLAY_EOF_INT_EN) |
|
|
|
|
(1 << ATI_VMC_EC_INT_EN) |
|
|
|
|
#else
|
|
|
|
(1 << ATI_SNAPSHOT_INT_EN) |
|
|
|
|
(1 << ATI_I2C_INT_EN) |
|
|
|
|
(1 << ATI_CRTC2_VBLANK_INT_EN) |
|
|
|
|
(1 << ATI_CRTC2_VLINE_INT_EN) |
|
|
|
|
(1 << ATI_CUPBUF0_INT_EN) |
|
|
|
|
(1 << ATI_CUPBUF1_INT_EN) |
|
|
|
|
(1 << ATI_OVERLAY_EOF_INT_EN) |
|
|
|
|
(1 << ATI_ONESHOT_CAP_INT_EN) |
|
|
|
|
(1 << ATI_BUSMASTER_EOL_INT_EN) |
|
|
|
|
(1 << ATI_GP_INT_EN) |
|
|
|
|
(1 << ATI_SNAPSHOT2_INT_EN) |
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
*/
|
|
|
|
uint32_t bits_AKed = bits_AK & value; // AK bits that are to be AKed
|
|
|
|
uint32_t bits_not_AKed = bits_AK & ~value; // AK bits that are not to be AKed
|
|
|
|
|
|
|
|
new_value = value & ~bits_AKed; // clear the AKed bits
|
|
|
|
bits_read_only |= bits_not_AKed; // the not AKed bits will remain unchanged
|
|
|
|
|
|
|
|
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
|
2023-04-10 20:19:55 +00:00
|
|
|
break;
|
2024-02-28 23:51:20 +00:00
|
|
|
}
|
2022-04-13 21:25:28 +00:00
|
|
|
case ATI_CRTC_GEN_CNTL:
|
2024-02-28 08:43:14 +00:00
|
|
|
{
|
2024-02-28 23:23:31 +00:00
|
|
|
uint32_t bits_AK =
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
(1 << ATI_CRTC_VSYNC_INT_AK) |
|
|
|
|
(1 << ATI_CRTC2_VSYNC_INT_AK) |
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
/*
|
|
|
|
uint32_t bits_EN =
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
(1 << ATI_CRTC_VSYNC_INT_EN) |
|
|
|
|
(1 << ATI_CRTC2_VSYNC_INT_EN) |
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
*/
|
|
|
|
uint32_t bits_AKed = bits_AK & value; // AK bits that are to be AKed
|
|
|
|
uint32_t bits_not_AKed = bits_AK & ~value; // AK bits that are not to be AKed
|
|
|
|
|
|
|
|
new_value = value & ~bits_AKed; // clear the AKed bits
|
|
|
|
uint32_t bits_read_only = bits_not_AKed; // the not AKed bits will remain unchanged
|
|
|
|
|
|
|
|
new_value = (old_value & bits_read_only) | (new_value & ~bits_read_only);
|
|
|
|
|
|
|
|
this->regs[reg_num] = new_value;
|
|
|
|
|
2024-02-28 08:43:14 +00:00
|
|
|
if (bit_changed(old_value, new_value, ATI_CRTC_DISPLAY_DIS)) {
|
|
|
|
if (bit_set(new_value, ATI_CRTC_DISPLAY_DIS)) {
|
2023-04-10 20:19:55 +00:00
|
|
|
this->blank_on = true;
|
|
|
|
this->blank_display();
|
|
|
|
} else {
|
|
|
|
this->blank_on = false;
|
|
|
|
}
|
2023-04-01 15:38:11 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 08:43:14 +00:00
|
|
|
if (bit_changed(old_value, new_value, ATI_CRTC_ENABLE)) {
|
2024-02-28 23:23:31 +00:00
|
|
|
this->crtc_update();
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2024-02-28 08:43:14 +00:00
|
|
|
}
|
2024-04-20 10:40:08 +00:00
|
|
|
case ATI_OVR_CLR:
|
|
|
|
case ATI_OVR_WID_LEFT_RIGHT:
|
|
|
|
case ATI_OVR_WID_TOP_BOTTOM:
|
|
|
|
new_value = value;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-04-20 10:40:08 +00:00
|
|
|
if (value != 0) {
|
|
|
|
LOG_F(ERROR, "%s: Unhandled value 0x%08x.", this->name.c_str(), value);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case ATI_CUR_CLR0:
|
|
|
|
case ATI_CUR_CLR1:
|
|
|
|
new_value = value;
|
|
|
|
this->cursor_dirty = true;
|
|
|
|
draw_fb = true;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-04-20 10:40:08 +00:00
|
|
|
return;
|
|
|
|
case ATI_CUR_OFFSET:
|
|
|
|
new_value = value;
|
|
|
|
if (old_value != new_value)
|
|
|
|
this->cursor_dirty = true;
|
|
|
|
draw_fb = true;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-04-20 10:40:08 +00:00
|
|
|
return;
|
|
|
|
case ATI_CUR_HORZ_VERT_OFF:
|
|
|
|
new_value = value;
|
|
|
|
if (
|
|
|
|
extract_bits<uint32_t>(new_value, ATI_CUR_VERT_OFF, ATI_CUR_VERT_OFF_size) !=
|
|
|
|
extract_bits<uint32_t>(old_value, ATI_CUR_VERT_OFF, ATI_CUR_VERT_OFF_size)
|
|
|
|
)
|
|
|
|
this->cursor_dirty = true;
|
|
|
|
draw_fb = true;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-04-20 10:40:08 +00:00
|
|
|
return;
|
|
|
|
case ATI_CUR_HORZ_VERT_POSN:
|
|
|
|
new_value = value;
|
|
|
|
draw_fb = true;
|
2024-02-28 23:45:45 +00:00
|
|
|
WRITE_VALUE_AND_LOG();
|
2024-04-20 10:40:08 +00:00
|
|
|
return;
|
2022-04-13 21:25:28 +00:00
|
|
|
case ATI_DAC_REGS:
|
2024-02-28 08:43:14 +00:00
|
|
|
new_value = old_value; // no change
|
2022-04-13 21:25:28 +00:00
|
|
|
if (size == 1) { // only byte accesses are allowed for DAC registers
|
2023-04-10 23:23:40 +00:00
|
|
|
int dac_reg_addr = ((this->regs[ATI_DAC_CNTL] & 1) << 2) | offset;
|
2023-04-10 20:19:55 +00:00
|
|
|
rgb514_write_reg(dac_reg_addr, extract_bits<uint32_t>(value, offset * 8, 8));
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATI_DAC_CNTL:
|
2024-02-28 08:43:14 +00:00
|
|
|
new_value = value;
|
2022-04-13 21:25:28 +00:00
|
|
|
// monitor ID is usually accessed using 8bit writes
|
2024-02-28 08:48:25 +00:00
|
|
|
if (offset <= 3 && offset + size > 3) {
|
2024-04-21 21:16:10 +00:00
|
|
|
uint8_t gpio_dirs = extract_bits<uint32_t>(new_value, ATI_DAC_GIO_DIR,
|
|
|
|
ATI_DAC_GIO_DIR_size);
|
|
|
|
uint8_t gpio_levels = extract_bits<uint32_t>(new_value, ATI_DAC_GIO_STATE,
|
|
|
|
ATI_DAC_GIO_STATE_size);
|
2022-04-13 21:25:28 +00:00
|
|
|
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
|
2024-04-21 21:16:10 +00:00
|
|
|
insert_bits<uint32_t>(new_value, gpio_levels, ATI_DAC_GIO_STATE,
|
|
|
|
ATI_DAC_GIO_STATE_size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
break;
|
2023-04-10 20:19:55 +00:00
|
|
|
case ATI_CONFIG_STAT0:
|
2024-02-28 08:43:14 +00:00
|
|
|
new_value = old_value; // prevent writes to this read-only register
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
new_value = value;
|
|
|
|
break;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
2023-04-10 20:19:55 +00:00
|
|
|
|
2024-02-28 08:43:14 +00:00
|
|
|
this->regs[reg_num] = new_value;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
|
|
|
|
{
|
2024-02-28 05:19:54 +00:00
|
|
|
if (rgn_start == this->aperture_base[0]) {
|
2022-04-13 21:25:28 +00:00
|
|
|
if (offset < this->vram_size) {
|
|
|
|
return read_mem(&this->vram_ptr[offset], size);
|
2024-02-28 05:19:54 +00:00
|
|
|
}
|
2024-04-20 08:04:05 +00:00
|
|
|
if (offset >= this->mm_regs_offset && offset < this->mm_regs_offset + 0x400) {
|
2023-04-10 20:19:55 +00:00
|
|
|
return BYTESWAP_SIZED(read_reg(offset - this->mm_regs_offset, size), size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
2024-02-28 05:19:54 +00:00
|
|
|
return 0;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// memory mapped expansion ROM region
|
2024-02-28 05:19:54 +00:00
|
|
|
if (rgn_start == this->exp_rom_addr) {
|
|
|
|
if (offset < this->exp_rom_size)
|
|
|
|
return read_mem(&this->exp_rom_data[offset], size);
|
|
|
|
return 0;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtiMach64Gx::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
2024-02-28 05:19:54 +00:00
|
|
|
if (rgn_start == this->aperture_base[0]) {
|
2022-04-13 21:25:28 +00:00
|
|
|
if (offset < this->vram_size) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = true;
|
2024-02-28 05:19:54 +00:00
|
|
|
return write_mem(&this->vram_ptr[offset], value, size);
|
|
|
|
}
|
2024-04-20 08:04:05 +00:00
|
|
|
if (offset >= this->mm_regs_offset && offset < this->mm_regs_offset + 0x400) {
|
2024-02-28 05:19:54 +00:00
|
|
|
return write_reg(offset - this->mm_regs_offset, BYTESWAP_SIZED(value, size), size);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
2024-02-28 05:19:54 +00:00
|
|
|
return;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 06:09:00 +00:00
|
|
|
void AtiMach64Gx::verbose_pixel_format(int crtc_index) {
|
|
|
|
if (crtc_index) {
|
|
|
|
LOG_F(ERROR, "CRTC2 not supported yet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pix_fmt = this->pixel_format;
|
|
|
|
|
|
|
|
const char* what = "Pixel format:";
|
|
|
|
|
|
|
|
switch (pix_fmt) {
|
|
|
|
case 2:
|
|
|
|
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
LOG_F(INFO, "%s 15 bpp direct color (RGB555)", what);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
LOG_F(INFO, "%s 24 bpp direct color (RGB888)", what);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
LOG_F(INFO, "%s 32 bpp direct color (ARGB8888)", what);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(ERROR, "%s: CRTC pixel format %d not supported", this->name.c_str(), pix_fmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 09:22:47 +00:00
|
|
|
void AtiMach64Gx::crtc_update()
|
2022-04-13 21:25:28 +00:00
|
|
|
{
|
2023-04-10 20:19:55 +00:00
|
|
|
uint32_t new_width, new_height;
|
2022-04-13 21:25:28 +00:00
|
|
|
|
2024-02-28 09:34:37 +00:00
|
|
|
if (!bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_ENABLE) ||
|
|
|
|
bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:19:55 +00:00
|
|
|
// check for unsupported modes and fail early
|
2024-02-28 07:47:15 +00:00
|
|
|
if (!bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_EXT_DISP_EN))
|
2024-02-28 09:36:03 +00:00
|
|
|
ABORT_F("%s: Current mode is VGA which is not supported", this->name.c_str());
|
2023-04-10 20:19:55 +00:00
|
|
|
|
2024-02-28 09:43:58 +00:00
|
|
|
bool need_recalc = false;
|
|
|
|
|
2024-04-21 21:16:10 +00:00
|
|
|
new_width = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP],
|
|
|
|
ATI_CRTC_H_DISP, ATI_CRTC_H_DISP_size) + 1) * 8;
|
|
|
|
new_height = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP],
|
|
|
|
ATI_CRTC_V_DISP, ATI_CRTC_V_DISP_size) + 1;
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
if (new_width != this->active_width || new_height != this->active_height) {
|
2023-04-10 20:19:55 +00:00
|
|
|
this->create_display_window(new_width, new_height);
|
2024-02-28 09:43:58 +00:00
|
|
|
need_recalc = true;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 09:43:58 +00:00
|
|
|
uint32_t new_htotal, new_vtotal;
|
2024-04-21 21:16:10 +00:00
|
|
|
new_htotal = (extract_bits<uint32_t>(this->regs[ATI_CRTC_H_TOTAL_DISP],
|
|
|
|
ATI_CRTC_H_TOTAL, ATI_CRTC_H_TOTAL_size) + 1) * 8;
|
|
|
|
new_vtotal = extract_bits<uint32_t>(this->regs[ATI_CRTC_V_TOTAL_DISP],
|
|
|
|
ATI_CRTC_V_TOTAL, ATI_CRTC_V_TOTAL_size) + 1;
|
2024-02-28 09:43:58 +00:00
|
|
|
|
|
|
|
if (new_htotal != this->hori_total || new_vtotal != this->vert_total) {
|
|
|
|
this->hori_total = new_htotal;
|
|
|
|
this->vert_total = new_vtotal;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
2022-04-13 21:25:28 +00:00
|
|
|
|
2024-02-29 00:09:02 +00:00
|
|
|
uint32_t new_vert_blank = new_vtotal - new_height;
|
|
|
|
if (new_vert_blank != this->vert_blank) {
|
|
|
|
this->vert_blank = vert_blank;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
|
|
|
|
2024-02-28 09:52:12 +00:00
|
|
|
int new_pixel_format = this->dac_regs[Rgb514::PIX_FORMAT];
|
|
|
|
if (new_pixel_format != this->pixel_format) {
|
|
|
|
this->pixel_format = new_pixel_format;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
|
|
|
|
2024-02-29 00:08:32 +00:00
|
|
|
static uint8_t bits_per_pixel[8] = {0, 0, 4, 8, 16, 24, 32, 0};
|
|
|
|
|
2024-04-21 21:16:10 +00:00
|
|
|
int new_fb_pitch = extract_bits<uint32_t>(this->regs[ATI_CRTC_OFF_PITCH],
|
|
|
|
ATI_CRTC_PITCH, ATI_CRTC_PITCH_size) * bits_per_pixel[this->pixel_format];
|
2024-02-29 00:08:32 +00:00
|
|
|
if (new_fb_pitch != this->fb_pitch) {
|
|
|
|
this->fb_pitch = new_fb_pitch;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
2024-04-21 21:16:10 +00:00
|
|
|
uint8_t* new_fb_ptr = &this->vram_ptr[extract_bits<uint32_t>(this->regs[ATI_CRTC_OFF_PITCH],
|
|
|
|
ATI_CRTC_OFFSET, ATI_CRTC_OFFSET_size) * 8];
|
2024-02-29 00:08:32 +00:00
|
|
|
if (new_fb_ptr != this->fb_ptr) {
|
|
|
|
this->fb_ptr = new_fb_ptr;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
|
|
|
|
2024-02-28 09:48:16 +00:00
|
|
|
// pixel clock = source_freq / post_div
|
|
|
|
int m = 8 >> (this->dac_regs[Rgb514::F0_M0] >> 6);
|
|
|
|
int vco_div = (this->dac_regs[Rgb514::F0_M0] & 0x3F) + 65;
|
|
|
|
int ref_div = (this->dac_regs[Rgb514::F1_N0] & 0x1F) * m;
|
|
|
|
float new_pixel_clock = ATI_XTAL * vco_div / ref_div;
|
|
|
|
if (new_pixel_clock != this->pixel_clock) {
|
|
|
|
this->pixel_clock = new_pixel_clock;
|
|
|
|
need_recalc = true;
|
|
|
|
}
|
|
|
|
|
2024-02-28 09:43:58 +00:00
|
|
|
if (!need_recalc)
|
|
|
|
return;
|
|
|
|
|
2024-04-20 10:40:08 +00:00
|
|
|
this->draw_fb = true;
|
|
|
|
|
2024-02-28 09:43:58 +00:00
|
|
|
// calculate display refresh rate
|
2023-04-10 20:19:55 +00:00
|
|
|
this->refresh_rate = this->pixel_clock / this->hori_total / this->vert_total;
|
2022-04-13 21:25:28 +00:00
|
|
|
|
2024-02-28 09:55:54 +00:00
|
|
|
if (this->refresh_rate < 24 || this->refresh_rate > 120) {
|
|
|
|
LOG_F(ERROR, "%s: Refresh rate is weird. Will try 60 Hz", this->name.c_str());
|
|
|
|
this->refresh_rate = 60;
|
|
|
|
this->pixel_clock = this->refresh_rate * this->hori_total / this->vert_total;
|
|
|
|
}
|
|
|
|
|
2024-02-28 09:52:12 +00:00
|
|
|
// set up frame buffer converter
|
|
|
|
switch (this->pixel_format) {
|
|
|
|
case 2:
|
|
|
|
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = false;
|
2024-02-28 09:52:12 +00:00
|
|
|
this->convert_frame_4bpp_indexed(dst_buf, dst_pitch);
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 3:
|
2022-04-13 21:25:28 +00:00
|
|
|
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = false;
|
2023-09-19 00:34:23 +00:00
|
|
|
this->convert_frame_8bpp_indexed(dst_buf, dst_pitch);
|
2022-04-13 21:25:28 +00:00
|
|
|
};
|
|
|
|
break;
|
2024-02-28 09:52:12 +00:00
|
|
|
case 4:
|
|
|
|
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = false;
|
2024-02-28 09:52:12 +00:00
|
|
|
this->convert_frame_15bpp_BE(dst_buf, dst_pitch);
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = false;
|
2024-02-28 09:52:12 +00:00
|
|
|
this->convert_frame_24bpp(dst_buf, dst_pitch);
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = false;
|
2024-02-28 09:52:12 +00:00
|
|
|
this->convert_frame_32bpp_BE(dst_buf, dst_pitch);
|
|
|
|
};
|
|
|
|
break;
|
2022-04-13 21:25:28 +00:00
|
|
|
default:
|
2024-02-28 09:52:12 +00:00
|
|
|
LOG_F(ERROR, "%s: unsupported pixel format %d", this->name.c_str(), this->pixel_format);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 01:52:17 +00:00
|
|
|
this->stop_refresh_task();
|
|
|
|
this->start_refresh_task();
|
2022-04-13 21:25:28 +00:00
|
|
|
|
|
|
|
this->crtc_on = true;
|
|
|
|
}
|
|
|
|
|
2024-03-20 12:00:21 +00:00
|
|
|
void AtiMach64Gx::draw_hw_cursor(uint8_t *dst_row, int dst_pitch) {
|
2024-04-21 21:16:10 +00:00
|
|
|
int vert_offset = extract_bits<uint32_t>(this->regs[ATI_CUR_HORZ_VERT_OFF],
|
|
|
|
ATI_CUR_VERT_OFF, ATI_CUR_VERT_OFF_size);
|
2024-02-28 23:51:56 +00:00
|
|
|
int cur_height = 64 - vert_offset;
|
|
|
|
|
|
|
|
uint32_t color0 = this->regs[ATI_CUR_CLR0] | 0x000000FFUL;
|
|
|
|
uint32_t color1 = this->regs[ATI_CUR_CLR1] | 0x000000FFUL;
|
|
|
|
|
2024-03-20 12:00:21 +00:00
|
|
|
uint64_t *src_row = (uint64_t *)&this->vram_ptr[this->regs[ATI_CUR_OFFSET] * 8];
|
|
|
|
dst_pitch -= 64 * 4;
|
2024-02-28 23:51:56 +00:00
|
|
|
|
2024-03-20 12:00:21 +00:00
|
|
|
for (int h = cur_height; h > 0; h--) {
|
|
|
|
for (int x = 2; x > 0; x--) {
|
|
|
|
uint64_t px = *src_row++;
|
|
|
|
for (int p = 32; p > 0; p--, px >>= 2, dst_row += 4) {
|
|
|
|
switch(px & 3) {
|
2024-02-28 23:51:56 +00:00
|
|
|
case 0: // cursor color 0
|
|
|
|
WRITE_DWORD_BE_A(dst_row, color0);
|
|
|
|
break;
|
|
|
|
case 1: // cursor color 1
|
|
|
|
WRITE_DWORD_BE_A(dst_row, color1);
|
|
|
|
break;
|
|
|
|
case 2: // transparent
|
|
|
|
WRITE_DWORD_BE_A(dst_row, 0);
|
|
|
|
break;
|
|
|
|
case 3: // 1's complement of display pixel
|
2024-03-20 12:00:21 +00:00
|
|
|
WRITE_DWORD_BE_A(dst_row, 0x0000007F);
|
2024-02-28 23:51:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-20 12:00:21 +00:00
|
|
|
dst_row += dst_pitch;
|
2024-02-28 23:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AtiMach64Gx::get_cursor_position(int& x, int& y) {
|
2024-03-20 11:56:11 +00:00
|
|
|
x = extract_bits<uint32_t>(this->regs[ATI_CUR_HORZ_VERT_POSN], ATI_CUR_HORZ_POSN, ATI_CUR_HORZ_POSN_size) -
|
|
|
|
extract_bits<uint32_t>(this->regs[ATI_CUR_HORZ_VERT_OFF ], ATI_CUR_HORZ_OFF , ATI_CUR_HORZ_OFF_size );
|
2024-02-28 23:51:56 +00:00
|
|
|
y = extract_bits<uint32_t>(this->regs[ATI_CUR_HORZ_VERT_POSN], ATI_CUR_VERT_POSN, ATI_CUR_VERT_POSN_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AtiMach64Gx::device_postinit()
|
|
|
|
{
|
|
|
|
this->vbl_cb = [this](uint8_t irq_line_state) {
|
2024-04-16 08:57:19 +00:00
|
|
|
insert_bits<uint32_t>(this->regs[ATI_CRTC_INT_CNTL], irq_line_state, ATI_CRTC_VBLANK, irq_line_state);
|
2024-02-28 23:51:56 +00:00
|
|
|
if (irq_line_state) {
|
|
|
|
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT);
|
|
|
|
set_bit(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT);
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
set_bit(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_VSYNC_INT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool do_interrupt =
|
|
|
|
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VBLANK_INT_EN) ||
|
|
|
|
bit_set(this->regs[ATI_CRTC_INT_CNTL], ATI_CRTC_VLINE_INT_EN) ||
|
|
|
|
#if 1
|
|
|
|
#else
|
|
|
|
bit_set(this->regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_VSYNC_INT_EN) ||
|
|
|
|
#endif
|
|
|
|
0;
|
|
|
|
|
2024-04-21 21:16:10 +00:00
|
|
|
LOG_F(WARNING, "%s: irq_line_state:%d do_interrupt:%d CRTC_INT_CNTL:%08x",
|
|
|
|
this->name.c_str(), irq_line_state, do_interrupt,
|
|
|
|
this->regs[ATI_CRTC_INT_CNTL]);
|
2024-02-28 23:51:56 +00:00
|
|
|
|
|
|
|
if (do_interrupt) {
|
|
|
|
this->pci_interrupt(irq_line_state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
// ========================== IBM RGB514 related code ==========================
|
|
|
|
void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
|
|
|
|
{
|
|
|
|
switch (reg_addr) {
|
|
|
|
case Rgb514::CLUT_ADDR_WR:
|
|
|
|
this->clut_index = value;
|
2024-04-16 08:55:19 +00:00
|
|
|
this->comp_index = 0;
|
2022-04-13 21:25:28 +00:00
|
|
|
break;
|
|
|
|
case Rgb514::CLUT_DATA:
|
|
|
|
this->clut_color[this->comp_index++] = value;
|
|
|
|
if (this->comp_index >= 3) {
|
2023-04-01 10:08:25 +00:00
|
|
|
this->set_palette_color(this->clut_index, clut_color[0],
|
|
|
|
clut_color[1], clut_color[2], 0xFF);
|
2022-04-13 21:25:28 +00:00
|
|
|
this->clut_index++;
|
|
|
|
this->comp_index = 0;
|
2024-04-20 10:40:08 +00:00
|
|
|
draw_fb = true;
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Rgb514::CLUT_MASK:
|
|
|
|
if (value != 0xFF) {
|
|
|
|
LOG_F(WARNING, "RGB514: pixel mask set to 0x%X", value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Rgb514::INDEX_LOW:
|
|
|
|
this->dac_idx_lo = value;
|
|
|
|
break;
|
|
|
|
case Rgb514::INDEX_HIGH:
|
|
|
|
this->dac_idx_hi = value;
|
|
|
|
break;
|
|
|
|
case Rgb514::INDEX_DATA:
|
|
|
|
this->rgb514_write_ind_reg((this->dac_idx_hi << 8) + this->dac_idx_lo, value);
|
|
|
|
break;
|
|
|
|
default:
|
2023-04-10 20:19:55 +00:00
|
|
|
ABORT_F("RGB514: access to unimplemented register at 0x%X", reg_addr);
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 02:14:57 +00:00
|
|
|
const char* AtiMach64Gx::rgb514_get_reg_name(uint32_t reg_addr)
|
|
|
|
{
|
|
|
|
auto iter = rgb514_reg_names.find(reg_addr);
|
|
|
|
if (iter != rgb514_reg_names.end()) {
|
|
|
|
return iter->second.c_str();
|
|
|
|
} else {
|
|
|
|
return "unknown rgb514 register";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 21:25:28 +00:00
|
|
|
void AtiMach64Gx::rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value)
|
|
|
|
{
|
|
|
|
this->dac_regs[reg_addr] = value;
|
|
|
|
|
|
|
|
switch (reg_addr) {
|
|
|
|
case Rgb514::MISC_CLK_CNTL:
|
|
|
|
if (value & PLL_ENAB) {
|
|
|
|
if ((this->dac_regs[Rgb514::PLL_CTL_1] & 3) != 1)
|
|
|
|
ABORT_F("RGB514: unsupported PLL source");
|
2024-02-28 09:48:16 +00:00
|
|
|
this->crtc_update();
|
2022-04-13 21:25:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Rgb514::PIX_FORMAT:
|
2024-02-28 09:52:12 +00:00
|
|
|
this->crtc_update();
|
2022-04-13 21:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-17 03:44:19 +00:00
|
|
|
|
2024-04-20 07:55:29 +00:00
|
|
|
static const PropMap AtiMach64gx_Properties = {
|
|
|
|
{"gfxmem_size",
|
|
|
|
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
|
|
|
{"mon_id",
|
|
|
|
new StrProperty("")},
|
|
|
|
};
|
|
|
|
|
2022-07-17 03:44:19 +00:00
|
|
|
static const DeviceDescription AtiMach64Gx_Descriptor = {
|
2024-04-20 07:55:29 +00:00
|
|
|
AtiMach64Gx::create, {}, AtiMach64gx_Properties
|
2022-07-17 03:44:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_DEVICE(AtiMach64Gx, AtiMach64Gx_Descriptor);
|