2020-03-27 17:54:25 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
|
|
Copyright (C) 2018-20 divingkatae and maximum
|
|
|
|
(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/>.
|
|
|
|
*/
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
#include "displayid.h"
|
2020-03-27 17:54:25 +00:00
|
|
|
#include "endianswap.h"
|
2020-03-31 16:25:58 +00:00
|
|
|
#include "memreadwrite.h"
|
|
|
|
#include "pcidevice.h"
|
2020-05-12 18:55:45 +00:00
|
|
|
#include <atirage.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <thirdparty/loguru/loguru.hpp>
|
2020-04-13 23:04:37 +00:00
|
|
|
|
2020-03-27 17:54:25 +00:00
|
|
|
|
2020-08-26 03:07:02 +00:00
|
|
|
ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
|
|
|
this->vram_size = mem_amount << 20;
|
2020-05-28 21:47:20 +00:00
|
|
|
|
|
|
|
/*allocate video RAM */
|
|
|
|
this->vram_ptr = new uint8_t[this->vram_size];
|
|
|
|
|
|
|
|
/* configure PCI parameters */
|
2020-03-31 16:25:58 +00:00
|
|
|
WRITE_DWORD_BE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
|
|
|
WRITE_DWORD_BE_A(&this->pci_cfg[8], 0x0300005C);
|
|
|
|
WRITE_DWORD_BE_A(&this->pci_cfg[0x3C], 0x00080100);
|
2020-04-13 23:04:37 +00:00
|
|
|
|
2020-05-28 21:47:20 +00:00
|
|
|
/* initialize display identification */
|
2020-04-13 23:04:37 +00:00
|
|
|
this->disp_id = new DisplayID();
|
|
|
|
}
|
|
|
|
|
|
|
|
ATIRage::~ATIRage()
|
|
|
|
{
|
2020-05-28 21:47:20 +00:00
|
|
|
if (this->vram_ptr) {
|
|
|
|
delete this->vram_ptr;
|
|
|
|
}
|
|
|
|
|
2020-04-13 23:04:37 +00:00
|
|
|
delete (this->disp_id);
|
2020-03-27 17:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t ATIRage::size_dep_read(uint8_t* buf, uint32_t size) {
|
2020-04-13 23:04:37 +00:00
|
|
|
switch (size) {
|
2020-04-01 01:24:39 +00:00
|
|
|
case 4:
|
|
|
|
return READ_DWORD_LE_A(buf);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return READ_WORD_LE_A(buf);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return *buf;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(WARNING, "ATI Rage read: invalid size %d", size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void ATIRage::size_dep_write(uint8_t* buf, uint32_t value, uint32_t size) {
|
2020-03-31 19:19:10 +00:00
|
|
|
switch (size) {
|
|
|
|
case 4:
|
2020-04-01 01:24:39 +00:00
|
|
|
WRITE_DWORD_BE_A(buf, value);
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2020-04-01 01:24:39 +00:00
|
|
|
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
2020-04-01 01:24:39 +00:00
|
|
|
case 1:
|
|
|
|
*buf = value & 0xFF;
|
2020-03-31 19:19:10 +00:00
|
|
|
}
|
2020-04-01 01:24:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
2020-04-01 01:24:39 +00:00
|
|
|
const char* reg_name;
|
2020-03-31 19:19:10 +00:00
|
|
|
|
2020-04-13 23:04:37 +00:00
|
|
|
switch (reg_offset & ~3) {
|
|
|
|
case ATI_CRTC_H_TOTAL_DISP:
|
|
|
|
reg_name = "CRTC_H_TOTAL_DISP";
|
|
|
|
break;
|
|
|
|
case ATI_CRTC_H_SYNC_STRT_WID:
|
|
|
|
reg_name = "CRTC_H_SYNC_STRT_WID";
|
|
|
|
break;
|
|
|
|
case ATI_CRTC_V_TOTAL_DISP:
|
|
|
|
reg_name = "CRTC_V_TOTAL_DISP";
|
|
|
|
break;
|
|
|
|
case ATI_CRTC_V_SYNC_STRT_WID:
|
|
|
|
reg_name = "CRTC_V_SYNC_STRT_WID";
|
|
|
|
break;
|
2021-01-08 21:32:06 +00:00
|
|
|
case ATI_CRTC_VLINE_CRNT_VLINE:
|
|
|
|
reg_name = "CRTC_VLINE_CRNT_VLINE";
|
|
|
|
break;
|
2020-04-13 23:04:37 +00:00
|
|
|
case ATI_CRTC_OFF_PITCH:
|
|
|
|
reg_name = "CRTC_OFF_PITCH";
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
case ATI_CRTC_INT_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "CRTC_INT_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case ATI_CRTC_GEN_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "CRTC_GEN_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
2020-04-13 23:04:37 +00:00
|
|
|
case ATI_DSP_CONFIG:
|
|
|
|
reg_name = "DSP_CONFIG";
|
|
|
|
break;
|
|
|
|
case ATI_DSP_ON_OFF:
|
|
|
|
reg_name = "DSP_ON_OFF";
|
|
|
|
break;
|
2020-05-28 21:47:20 +00:00
|
|
|
case ATI_MEM_BUF_CNTL:
|
|
|
|
reg_name = "MEM_BUF_CNTL";
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
case ATI_MEM_ADDR_CFG:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "MEM_ADDR_CFG";
|
|
|
|
break;
|
2020-04-13 23:04:37 +00:00
|
|
|
case ATI_OVR_CLR:
|
|
|
|
reg_name = "OVR_CLR";
|
|
|
|
break;
|
|
|
|
case ATI_OVR_WID_LEFT_RIGHT:
|
|
|
|
reg_name = "OVR_WID_LEFT_RIGHT";
|
|
|
|
break;
|
|
|
|
case ATI_OVR_WID_TOP_BOTTOM:
|
|
|
|
reg_name = "OVR_WID_TOP_BOTTOM";
|
|
|
|
break;
|
|
|
|
case ATI_GP_IO:
|
|
|
|
reg_name = "GP_IO";
|
|
|
|
break;
|
2021-01-08 21:32:06 +00:00
|
|
|
case ATI_SCRATCH_REG0:
|
|
|
|
reg_name = "SCRATCH_REG0";
|
|
|
|
break;
|
|
|
|
case ATI_SCRATCH_REG1:
|
|
|
|
reg_name = "SCRATCH_REG1";
|
|
|
|
break;
|
|
|
|
case ATI_SCRATCH_REG2:
|
|
|
|
reg_name = "SCRATCH_REG2";
|
|
|
|
break;
|
|
|
|
case ATI_SCRATCH_REG3:
|
|
|
|
reg_name = "SCRATCH_REG3";
|
|
|
|
break;
|
2020-04-01 01:24:39 +00:00
|
|
|
case ATI_CLOCK_CNTL:
|
|
|
|
reg_name = "CLOCK_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case ATI_BUS_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "BUS_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case ATI_EXT_MEM_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "EXT_MEM_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case ATI_MEM_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "MEM_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
2020-05-28 21:47:20 +00:00
|
|
|
case ATI_DAC_REGS:
|
|
|
|
reg_name = "DAC_REGS";
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
case ATI_DAC_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "DAC_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
|
|
|
case ATI_GEN_TEST_CNTL:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "GEN_TEST_CNTL";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
2020-04-13 23:04:37 +00:00
|
|
|
case ATI_CFG_CHIP_ID:
|
|
|
|
reg_name = "CONFIG_CHIP_ID";
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
case ATI_CFG_STAT0:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "CONFIG_STAT0";
|
2020-03-31 19:19:10 +00:00
|
|
|
break;
|
2021-01-08 20:12:06 +00:00
|
|
|
case ATI_SCALE_3D_CNTL:
|
|
|
|
reg_name = "SCALE_3D_CNTL";
|
|
|
|
break;
|
|
|
|
case ATI_FIFO_STAT:
|
|
|
|
reg_name = "FIFO_STAT";
|
|
|
|
break;
|
|
|
|
case ATI_SRC_CNTL:
|
|
|
|
reg_name = "SRC_CNTL";
|
|
|
|
break;
|
|
|
|
case ATI_GUI_STAT:
|
|
|
|
reg_name = "GUI_STAT";
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
default:
|
2020-04-01 01:24:39 +00:00
|
|
|
reg_name = "unknown";
|
2020-03-31 19:19:10 +00:00
|
|
|
}
|
2020-04-01 01:24:39 +00:00
|
|
|
|
2020-04-13 23:04:37 +00:00
|
|
|
return reg_name;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
2020-04-13 23:04:37 +00:00
|
|
|
uint32_t res;
|
|
|
|
|
|
|
|
switch (offset & ~3) {
|
2020-10-14 14:55:38 +00:00
|
|
|
case ATI_GP_IO:
|
|
|
|
break;
|
2020-06-10 23:30:10 +00:00
|
|
|
case ATI_DAC_REGS:
|
|
|
|
if (offset == ATI_DAC_DATA) {
|
|
|
|
this->block_io_regs[ATI_DAC_DATA] =
|
|
|
|
this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index];
|
|
|
|
this->comp_index++; /* move to next color component */
|
|
|
|
if (this->comp_index >= 3) {
|
|
|
|
/* autoincrement reading index - move to next palette entry */
|
|
|
|
(this->block_io_regs[ATI_DAC_R_INDEX])++;
|
|
|
|
this->comp_index = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 23:04:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-05-12 18:55:45 +00:00
|
|
|
LOG_F(
|
|
|
|
INFO,
|
|
|
|
"ATI Rage: read I/O reg %s at 0x%X, size=%d, val=0x%X",
|
|
|
|
get_reg_name(offset),
|
|
|
|
offset,
|
|
|
|
size,
|
2020-04-13 23:04:37 +00:00
|
|
|
size_dep_read(&this->block_io_regs[offset], size));
|
|
|
|
}
|
|
|
|
|
|
|
|
res = size_dep_read(&this->block_io_regs[offset], size);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
2020-04-13 23:04:37 +00:00
|
|
|
uint32_t gpio_val;
|
|
|
|
uint16_t gpio_dir;
|
|
|
|
|
|
|
|
/* size-dependent endian conversion */
|
|
|
|
size_dep_write(&this->block_io_regs[offset], value, size);
|
|
|
|
|
|
|
|
switch (offset & ~3) {
|
|
|
|
case ATI_GP_IO:
|
|
|
|
if (offset < (ATI_GP_IO + 2)) {
|
|
|
|
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
|
|
|
gpio_dir = (gpio_val >> 16) & 0x3FFF;
|
2020-05-12 18:55:45 +00:00
|
|
|
WRITE_WORD_LE_A(
|
|
|
|
&this->block_io_regs[ATI_GP_IO],
|
2020-04-13 23:04:37 +00:00
|
|
|
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
|
|
|
}
|
|
|
|
break;
|
2020-06-10 23:30:10 +00:00
|
|
|
case ATI_DAC_REGS:
|
|
|
|
switch (offset) {
|
|
|
|
/* writing to read/write index registers resets color component index */
|
|
|
|
case ATI_DAC_W_INDEX:
|
|
|
|
case ATI_DAC_R_INDEX:
|
|
|
|
this->comp_index = 0;
|
|
|
|
break;
|
|
|
|
case ATI_DAC_DATA:
|
|
|
|
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
|
|
|
|
this->comp_index++; /* move to next color component */
|
|
|
|
if (this->comp_index >= 3) {
|
|
|
|
LOG_F(
|
|
|
|
INFO,
|
|
|
|
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
|
|
|
|
this->block_io_regs[ATI_DAC_W_INDEX],
|
|
|
|
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0],
|
|
|
|
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1],
|
|
|
|
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]);
|
|
|
|
/* autoincrement writing index - move to next palette entry */
|
|
|
|
(this->block_io_regs[ATI_DAC_W_INDEX])++;
|
|
|
|
this->comp_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-04-13 23:04:37 +00:00
|
|
|
default:
|
2020-05-12 18:55:45 +00:00
|
|
|
LOG_F(
|
|
|
|
INFO,
|
|
|
|
"ATI Rage: %s register at 0x%X set to 0x%X",
|
|
|
|
get_reg_name(offset),
|
|
|
|
offset & ~3,
|
2020-04-13 23:04:37 +00:00
|
|
|
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
|
|
|
|
}
|
2020-03-31 19:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
2020-03-31 16:25:58 +00:00
|
|
|
uint32_t res = 0;
|
|
|
|
|
|
|
|
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
|
|
|
|
2020-04-01 01:24:39 +00:00
|
|
|
res = size_dep_read(&this->pci_cfg[reg_offs], size);
|
2020-03-31 16:25:58 +00:00
|
|
|
|
|
|
|
LOG_F(INFO, "Return value: 0x%X", res);
|
|
|
|
return res;
|
2020-03-27 17:54:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
|
|
|
LOG_F(
|
|
|
|
INFO,
|
|
|
|
"Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
|
|
|
reg_offs,
|
|
|
|
BYTESWAP_32(value),
|
|
|
|
size);
|
2020-03-31 16:25:58 +00:00
|
|
|
|
|
|
|
switch (reg_offs) {
|
|
|
|
case 0x10: /* BAR 0 */
|
|
|
|
if (value == 0xFFFFFFFFUL) {
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-05-28 20:36:55 +00:00
|
|
|
this->aperture_base = BYTESWAP_32(value);
|
|
|
|
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
2020-06-10 22:49:00 +00:00
|
|
|
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
|
|
|
APERTURE_SIZE, this);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
|
|
|
if (value == 0xFFFFFFFFUL) {
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
case 0x18: /* BAR 2 */
|
|
|
|
if (value == 0xFFFFFFFFUL) {
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-03-31 19:19:10 +00:00
|
|
|
case CFG_REG_BAR3: /* unimplemented */
|
|
|
|
case CFG_REG_BAR4: /* unimplemented */
|
|
|
|
case CFG_REG_BAR5: /* unimplemented */
|
|
|
|
case CFG_EXP_BASE: /* no expansion ROM */
|
2020-05-28 20:36:55 +00:00
|
|
|
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
2020-03-31 16:25:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-01 01:24:39 +00:00
|
|
|
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|
2020-03-27 17:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
2020-04-01 01:24:39 +00:00
|
|
|
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
|
|
|
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-28 20:36:55 +00:00
|
|
|
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
2020-04-01 01:24:39 +00:00
|
|
|
|
2020-04-13 23:04:37 +00:00
|
|
|
if (offset < io_base || offset > (io_base + 0x100)) {
|
2020-04-01 01:24:39 +00:00
|
|
|
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p_io_base = io_base;
|
|
|
|
|
|
|
|
return true;
|
2020-03-31 19:19:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
2020-04-01 01:24:39 +00:00
|
|
|
uint32_t io_base;
|
2020-03-31 19:19:10 +00:00
|
|
|
|
2020-04-01 01:24:39 +00:00
|
|
|
if (!this->io_access_allowed(offset, &io_base)) {
|
2020-03-31 19:19:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-04-01 01:24:39 +00:00
|
|
|
|
2020-04-13 23:04:37 +00:00
|
|
|
*res = this->read_reg(offset - io_base, size);
|
2020-04-01 01:24:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
2020-04-01 01:24:39 +00:00
|
|
|
uint32_t io_base;
|
|
|
|
|
|
|
|
if (!this->io_access_allowed(offset, &io_base)) {
|
2020-03-31 19:19:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->write_reg(offset - io_base, value, size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-31 16:25:58 +00:00
|
|
|
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
|
|
|
{
|
2020-05-28 21:47:20 +00:00
|
|
|
//LOG_F(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
2020-05-28 20:36:55 +00:00
|
|
|
|
2020-06-10 22:49:00 +00:00
|
|
|
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
2020-05-28 21:47:20 +00:00
|
|
|
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
2020-05-28 20:36:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-28 21:47:20 +00:00
|
|
|
if (offset < this->vram_size) {
|
|
|
|
/* read from little-endian VRAM region */
|
|
|
|
return size_dep_read(this->vram_ptr + offset, size);
|
|
|
|
}
|
2020-06-10 22:49:00 +00:00
|
|
|
else if (offset >= MEMMAP_OFFSET) {
|
2020-05-28 21:47:20 +00:00
|
|
|
/* read from memory-mapped registers */
|
2020-06-10 22:49:00 +00:00
|
|
|
return this->read_reg(offset - MEMMAP_OFFSET, size);
|
2020-05-28 21:47:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG_F(WARNING, "ATI Rage: read attempt from unmapped aperture region at 0x%08X", offset);
|
2020-05-28 20:36:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 16:25:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
2020-05-28 21:47:20 +00:00
|
|
|
//LOG_F(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
2020-05-28 20:36:55 +00:00
|
|
|
|
2020-06-10 22:49:00 +00:00
|
|
|
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
2020-05-28 21:47:20 +00:00
|
|
|
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
2020-05-28 20:36:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-28 21:47:20 +00:00
|
|
|
if (offset < this->vram_size) {
|
|
|
|
/* write to little-endian VRAM region */
|
|
|
|
size_dep_write(this->vram_ptr + offset, value, size);
|
2020-06-10 22:49:00 +00:00
|
|
|
} else if (offset >= MEMMAP_OFFSET) {
|
2020-05-28 21:47:20 +00:00
|
|
|
/* write to memory-mapped registers */
|
2020-06-10 22:49:00 +00:00
|
|
|
this->write_reg(offset - MEMMAP_OFFSET, value, size);
|
2020-05-28 21:47:20 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
2020-05-28 20:36:55 +00:00
|
|
|
}
|
2020-03-31 16:25:58 +00:00
|
|
|
}
|