From af0498569cea7c982054a6d3135eca4ddd1008ad Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 21 Jul 2025 06:07:34 +0200 Subject: [PATCH] All the changes. --- src/codegen/codegen_ops_x86-64.h | 24 +- src/codegen_new/codegen_backend_x86-64_uops.c | 7 +- src/config.c | 18 + src/floppy/fdd.c | 1 + src/include/86box/machine_status.h | 1 + src/include/86box/ui.h | 1 + src/qt/qt_iconindicators.cpp | 8 +- src/qt/qt_iconindicators.hpp | 2 + src/qt/qt_machinestatus.cpp | 34 +- src/qt/qt_mediamenu.cpp | 7 +- src/qt/qt_ui.cpp | 28 + src/qt_resources.qrc | 1 + src/scsi/scsi_pcscsi.c | 187 ++-- src/unix/unix.c | 5 + src/video/vid_paradise.c | 26 +- src/video/vid_xga.c | 842 ++++++++---------- 16 files changed, 608 insertions(+), 584 deletions(-) diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 129d9a740..5d6a62c7a 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -3875,19 +3875,31 @@ FP_LOAD_IMM_Q(uint64_t v) static __inline void FP_FCHS(void) { + addbyte(0x48); /* MOVABS RAX, 0x8000000000000000 */ + addbyte(0xb8); + addquad(0x8000000000000000); + addbyte(0x66); /* MOVQ XMM15, RAX */ + addbyte(0x4c); + addbyte(0x0f); + addbyte(0x6e); + addbyte(0xf8); + addbyte(0x48); /* XOR RAX, RAX */ + addbyte(0x31); + addbyte(0xc0); addbyte(0x8b); /*MOV EAX, TOP*/ addbyte(0x45); addbyte((uint8_t) cpu_state_offset(TOP)); - addbyte(0xf2); /*SUBSD XMM0, XMM0*/ + addbyte(0xf3); /*MOVQ XMM0, ST[EAX*8]*/ addbyte(0x0f); - addbyte(0x5c); - addbyte(0xc0); - addbyte(0xf2); /*SUBSD XMM0, ST[EAX*8]*/ - addbyte(0x0f); - addbyte(0x5c); + addbyte(0x7e); addbyte(0x44); addbyte(0xc5); addbyte((uint8_t) cpu_state_offset(ST)); + addbyte(0x66); /* PXOR XMM0, XMM15 */ + addbyte(0x41); + addbyte(0x0F); + addbyte(0xEF); + addbyte(0xC7); addbyte(0x80); /*AND tag[EAX], ~TAG_UINT64*/ addbyte(0x64); addbyte(0x05); diff --git a/src/codegen_new/codegen_backend_x86-64_uops.c b/src/codegen_new/codegen_backend_x86-64_uops.c index 6b68434a0..356c8bcde 100644 --- a/src/codegen_new/codegen_backend_x86-64_uops.c +++ b/src/codegen_new/codegen_backend_x86-64_uops.c @@ -636,9 +636,10 @@ codegen_FCHS(codeblock_t *block, uop_t *uop) int src_size_a = IREG_GET_SIZE(uop->src_reg_a_real); if (REG_IS_D(dest_size) && REG_IS_D(src_size_a)) { - host_x86_MOVQ_XREG_XREG(block, REG_XMM_TEMP, src_reg_a); - host_x86_PXOR_XREG_XREG(block, dest_reg, dest_reg); - host_x86_SUBSD_XREG_XREG(block, dest_reg, REG_XMM_TEMP); + host_x86_MOVQ_XREG_XREG(block, dest_reg, src_reg_a); + host_x86_MOV64_REG_IMM(block, REG_RCX, 0x8000000000000000); + host_x86_MOVQ_XREG_REG(block, REG_XMM_TEMP, REG_RCX); + host_x86_PXOR_XREG_XREG(block, dest_reg, REG_XMM_TEMP); } # ifdef RECOMPILER_DEBUG else diff --git a/src/config.c b/src/config.c index acfbec758..95362bc06 100644 --- a/src/config.c +++ b/src/config.c @@ -1517,6 +1517,9 @@ load_other_removable_devices(void) sprintf(temp, "zip_%02i_image_path", c + 1); p = ini_section_get_string(cat, temp, ""); + + sprintf(temp, "zip_%02i_writeprot", c + 1); + zip_drives[c].read_only = ini_section_get_int(cat, temp, 0); if (!strcmp(p, usr_path)) p[0] = 0x00; @@ -1630,6 +1633,9 @@ load_other_removable_devices(void) sprintf(temp, "mo_%02i_image_path", c + 1); p = ini_section_get_string(cat, temp, ""); + sprintf(temp, "mo_%02i_writeprot", c + 1); + mo_drives[c].read_only = ini_section_get_int(cat, temp, 0); + if (!strcmp(p, usr_path)) p[0] = 0x00; @@ -3090,6 +3096,12 @@ save_other_removable_devices(void) sprintf(temp, "zip_%02i_scsi_id", c + 1); ini_section_delete_var(cat, temp); + sprintf(temp, "zip_%02i_writeprot", c + 1); + if (zip_drives[c].read_only) + ini_section_set_int(cat, temp, zip_drives[c].read_only); + else + ini_section_delete_var(cat, temp); + sprintf(temp, "zip_%02i_scsi_location", c + 1); if (zip_drives[c].bus_type != ZIP_BUS_SCSI) ini_section_delete_var(cat, temp); @@ -3146,6 +3158,12 @@ save_other_removable_devices(void) sprintf(temp, "mo_%02i_scsi_id", c + 1); ini_section_delete_var(cat, temp); + sprintf(temp, "mo_%02i_writeprot", c + 1); + if (mo_drives[c].read_only) + ini_section_set_int(cat, temp, mo_drives[c].read_only); + else + ini_section_delete_var(cat, temp); + sprintf(temp, "mo_%02i_scsi_location", c + 1); if (mo_drives[c].bus_type != MO_BUS_SCSI) ini_section_delete_var(cat, temp); diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index 1623f932a..b5eb8c8fc 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -483,6 +483,7 @@ fdd_load(int drive, char *fn) drive_empty[drive] = 0; fdd_forced_seek(drive, 0); fdd_changed[drive] = 1; + ui_sb_update_icon_wp(SB_FLOPPY | drive, ui_writeprot[drive]); return; } c++; diff --git a/src/include/86box/machine_status.h b/src/include/86box/machine_status.h index e6e9e6acd..66805e653 100644 --- a/src/include/86box/machine_status.h +++ b/src/include/86box/machine_status.h @@ -5,6 +5,7 @@ typedef struct dev_status_empty_active_t { atomic_bool_t empty; atomic_bool_t active; atomic_bool_t write_active; + atomic_bool_t write_prot; } dev_status_empty_active_t; typedef struct dev_status_active_t { diff --git a/src/include/86box/ui.h b/src/include/86box/ui.h index 783400ebc..f4efd6ec1 100644 --- a/src/include/86box/ui.h +++ b/src/include/86box/ui.h @@ -67,6 +67,7 @@ extern void ui_sb_update_tip(int meaning); extern void ui_sb_update_icon(int tag, int active); extern void ui_sb_update_icon_write(int tag, int write); extern void ui_sb_update_icon_state(int tag, int state); +extern void ui_sb_update_icon_wp(int tag, int state); extern void ui_sb_set_text_w(wchar_t *wstr); extern void ui_sb_set_text(char *str); extern void ui_sb_bugui(char *str); diff --git a/src/qt/qt_iconindicators.cpp b/src/qt/qt_iconindicators.cpp index d5d22c78d..8440af7dc 100644 --- a/src/qt/qt_iconindicators.cpp +++ b/src/qt/qt_iconindicators.cpp @@ -12,6 +12,8 @@ getIndicatorIcon(IconIndicator indicator) return QIcon(":/settings/qt/icons/write_active.ico"); case Disabled: return QIcon(":/settings/qt/icons/disabled.ico"); + case WriteProtected: + return QIcon(":/settings/qt/icons/write_protected.ico"); default: return QIcon(); } @@ -26,11 +28,11 @@ getIconWithIndicator(const QIcon &icon, const QSize &size, QIcon::Mode iconMode, return iconPixmap; auto painter = QPainter(&iconPixmap); - auto indicatorPixmap = getIndicatorIcon(indicator == ReadWriteActive ? Active : indicator).pixmap(size); + auto indicatorPixmap = getIndicatorIcon((indicator == ReadWriteActive || indicator == WriteProtectedActive) ? Active : indicator).pixmap(size); painter.drawPixmap(0, 0, indicatorPixmap); - if (indicator == ReadWriteActive) { - auto writeIndicatorPixmap = getIndicatorIcon(WriteActive).pixmap(size); + if (indicator == ReadWriteActive || indicator == WriteProtectedActive) { + auto writeIndicatorPixmap = getIndicatorIcon(indicator == WriteProtectedActive ? WriteProtected : WriteActive).pixmap(size); painter.drawPixmap(0, 0, writeIndicatorPixmap); } painter.end(); diff --git a/src/qt/qt_iconindicators.hpp b/src/qt/qt_iconindicators.hpp index 12f82f259..d2232fc77 100644 --- a/src/qt/qt_iconindicators.hpp +++ b/src/qt/qt_iconindicators.hpp @@ -10,6 +10,8 @@ enum IconIndicator { WriteActive, ReadWriteActive, Disabled, + WriteProtected, + WriteProtectedActive, }; QPixmap getIconWithIndicator(const QIcon &icon, const QSize &size, QIcon::Mode iconMode, IconIndicator indicator); diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index db32569f3..5a731c188 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -91,6 +91,8 @@ struct PixmapSetEmptyActive { QPixmap read_write_active; QPixmap empty_write_active; QPixmap empty_read_write_active; + QPixmap wp; + QPixmap wp_active; void load(const QIcon &icon); }; struct Pixmaps { @@ -168,6 +170,7 @@ struct StateEmptyActive { bool empty = false; bool active = false; bool write_active = false; + bool wp = false; void setActive(bool b) { @@ -193,6 +196,14 @@ struct StateEmptyActive { empty = b; refresh(); } + void setWriteProtected(bool b) + { + if (!label || b == wp) + return; + + wp = b; + refresh(); + } void refresh() { if (!label) @@ -203,7 +214,9 @@ struct StateEmptyActive { else label->setPixmap(write_active ? pixmaps->empty_write_active : (active ? pixmaps->empty_active : pixmaps->empty)); } else { - if (active && write_active) + if (wp) + label->setPixmap(active ? pixmaps->wp_active : pixmaps->wp); + else if (active && write_active) label->setPixmap(pixmaps->read_write_active); else label->setPixmap(write_active ? pixmaps->write_active : (active ? pixmaps->active : pixmaps->normal)); @@ -241,6 +254,8 @@ void PixmapSetEmptyActive::load(const QIcon &icon) { normal = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, None); + wp = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, WriteProtected); + wp_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, WriteProtectedActive); active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, Active); write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, WriteActive); read_write_active = getIconWithIndicator(icon, pixmap_size, QIcon::Normal, ReadWriteActive); @@ -454,16 +469,23 @@ MachineStatus::refreshEmptyIcons() if (!sbar_initialized) return; - for (size_t i = 0; i < FDD_NUM; ++i) + for (size_t i = 0; i < FDD_NUM; ++i) { d->fdd[i].setEmpty(machine_status.fdd[i].empty); + d->fdd[i].setWriteProtected(machine_status.fdd[i].write_prot); + } for (size_t i = 0; i < CDROM_NUM; ++i) d->cdrom[i].setEmpty(machine_status.cdrom[i].empty); - for (size_t i = 0; i < ZIP_NUM; i++) + for (size_t i = 0; i < ZIP_NUM; i++) { d->zip[i].setEmpty(machine_status.zip[i].empty); - for (size_t i = 0; i < MO_NUM; i++) + d->zip[i].setWriteProtected(machine_status.zip[i].write_prot); + } + for (size_t i = 0; i < MO_NUM; i++) { d->mo[i].setEmpty(machine_status.mo[i].empty); + d->mo[i].setWriteProtected(machine_status.mo[i].write_prot); + } d->cassette.setEmpty(machine_status.cassette.empty); + d->cassette.setWriteProtected(machine_status.cassette.write_prot); for (size_t i = 0; i < NET_CARD_MAX; i++) d->net[i].setEmpty(machine_status.net[i].empty); @@ -595,6 +617,7 @@ MachineStatus::refresh(QStatusBar *sbar) if (cassette_enable) { d->cassette.label = std::make_unique(); d->cassette.setEmpty(QString(cassette_fname).isEmpty()); + d->cassette.setWriteProtected(cassette_ui_writeprot); d->cassette.refresh(); connect((ClickableLabel *) d->cassette.label.get(), &ClickableLabel::clicked, [](QPoint pos) { MediaMenu::ptr->cassetteMenu->popup(pos - QPoint(0, MediaMenu::ptr->cassetteMenu->sizeHint().height())); @@ -635,6 +658,7 @@ MachineStatus::refresh(QStatusBar *sbar) } d->fdd[i].label = std::make_unique(); d->fdd[i].setEmpty(QString(floppyfns[i]).isEmpty()); + d->fdd[i].setWriteProtected(ui_writeprot[i]); d->fdd[i].setActive(false); d->fdd[i].setWriteActive(false); d->fdd[i].refresh(); @@ -669,6 +693,7 @@ MachineStatus::refresh(QStatusBar *sbar) iterateZIP([this, sbar](int i) { d->zip[i].label = std::make_unique(); d->zip[i].setEmpty(QString(zip_drives[i].image_path).isEmpty()); + d->zip[i].setWriteProtected(zip_drives[i].read_only); d->zip[i].setActive(false); d->zip[i].setWriteActive(false); d->zip[i].refresh(); @@ -686,6 +711,7 @@ MachineStatus::refresh(QStatusBar *sbar) iterateMO([this, sbar](int i) { d->mo[i].label = std::make_unique(); d->mo[i].setEmpty(QString(mo_drives[i].image_path).isEmpty()); + d->mo[i].setWriteProtected(mo_drives[i].read_only); d->mo[i].setActive(false); d->mo[i].setWriteActive(false); d->mo[i].refresh(); diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 11fac2a70..c9d658fb2 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -282,6 +282,7 @@ MediaMenu::cassetteMount(const QString &filename, bool wp) } ui_sb_update_icon_state(SB_CASSETTE, filename.isEmpty() ? 1 : 0); + ui_sb_update_icon_wp(SB_CASSETTE, cassette_ui_writeprot); mhm.addImageToHistory(0, ui::MediaType::Cassette, previous_image.filePath(), filename); cassetteUpdateMenu(); ui_sb_update_tip(SB_CASSETTE); @@ -446,6 +447,7 @@ MediaMenu::floppyMount(int i, const QString &filename, bool wp) fdd_load(i, filenameBytes.data()); } ui_sb_update_icon_state(SB_FLOPPY | i, filename.isEmpty() ? 1 : 0); + ui_sb_update_icon_wp(SB_FLOPPY | i, ui_writeprot[i]); mhm.addImageToHistory(i, ui::MediaType::Floppy, previous_image.filePath(), filename); floppyUpdateMenu(i); ui_sb_update_tip(SB_FLOPPY | i); @@ -822,6 +824,7 @@ MediaMenu::zipMount(int i, const QString &filename, bool wp) mhm.addImageToHistory(i, ui::MediaType::Zip, zip_drives[i].prev_image_path, zip_drives[i].image_path); ui_sb_update_icon_state(SB_ZIP | i, filename.isEmpty() ? 1 : 0); + ui_sb_update_icon_wp(SB_ZIP | i, wp); zipUpdateMenu(i); ui_sb_update_tip(SB_ZIP | i); @@ -858,6 +861,7 @@ MediaMenu::zipReloadPrev(int i) } else { ui_sb_update_icon_state(SB_ZIP | i, 0); } + ui_sb_update_icon_wp(SB_ZIP | i, zip_drives[i].read_only); zipUpdateMenu(i); ui_sb_update_tip(SB_ZIP | i); @@ -869,7 +873,7 @@ void MediaMenu::zipReload(int index, int slot) { const QString filename = mhm.getImageForSlot(index, slot, ui::MediaType::Zip); - zipMount(index, filename, false); + zipMount(index, filename, zip_drives[index].read_only); zipUpdateMenu(index); ui_sb_update_tip(SB_ZIP | index); } @@ -995,6 +999,7 @@ MediaMenu::moReloadPrev(int i) } else { ui_sb_update_icon_state(SB_MO | i, 0); } + ui_sb_update_icon_state(SB_MO | i, mo_drives[i].read_only); moUpdateMenu(i); ui_sb_update_tip(SB_MO | i); diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 6e0b3cfbb..337b438f3 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -262,6 +262,34 @@ ui_sb_set_ready(int ready) } } +void +ui_sb_update_icon_wp(int tag, int state) +{ + const auto temp = static_cast(tag); + const int category = static_cast(temp & 0xfffffff0); + const int item = tag & 0xf; + + switch (category) { + default: + break; + case SB_CASSETTE: + machine_status.cassette.write_prot = state > 0 ? true : false; + break; + case SB_FLOPPY: + machine_status.fdd[item].write_prot = state > 0 ? true : false; + break; + case SB_ZIP: + machine_status.zip[item].write_prot = state > 0 ? true : false; + break; + case SB_MO: + machine_status.mo[item].write_prot = state > 0 ? true : false; + break; + } + + if (main_window != nullptr) + main_window->updateStatusEmptyIcons(); +} + void ui_sb_update_icon_state(int tag, int state) { diff --git a/src/qt_resources.qrc b/src/qt_resources.qrc index 51518b8f6..9291892b5 100644 --- a/src/qt_resources.qrc +++ b/src/qt_resources.qrc @@ -28,6 +28,7 @@ qt/icons/zip.ico qt/icons/zip_disabled.ico qt/icons/active.ico + qt/icons/write_protected.ico qt/icons/write_active.ico qt/icons/disabled.ico qt/icons/86Box-gray.ico diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index 7c991bdb1..1b1f6113d 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -54,6 +54,12 @@ #define ESP_FIFO_SZ 16 #define ESP_CMDFIFO_SZ 32 +enum ESPASCMode { + ESP_ASC_MODE_DIS = 0, /* Disconnected */ + ESP_ASC_MODE_INI = 1, /* Initiator */ + ESP_ASC_MODE_TGT = 2 /* Target */ +}; + #define ESP_TCLO 0x0 #define ESP_TCMID 0x1 #define ESP_FIFO 0x2 @@ -80,6 +86,13 @@ #define CMD_DMA 0x80 #define CMD_CMD 0x7f +#define CMD_GRP_MASK 0x70 + +#define CMD_GRP_MISC 0x00 +#define CMD_GRP_INIT 0x01 +#define CMD_GRP_TRGT 0x02 +#define CMD_GRP_DISC 0x04 + #define CMD_NOP 0x00 #define CMD_FLUSH 0x01 #define CMD_RESET 0x02 @@ -114,7 +127,7 @@ #define INTR_FC 0x08 #define INTR_BS 0x10 #define INTR_DC 0x20 -#define INTR_ILL 0x40 +#define INTR_IL 0x40 #define INTR_RST 0x80 #define SEQ_0 0x0 @@ -176,6 +189,7 @@ typedef struct esp_t { uint8_t id, lun; Fifo8 cmdfifo; uint8_t cmdfifo_cdb_offset; + uint8_t asc_mode; int data_ready; int32_t xfer_counter; @@ -435,12 +449,14 @@ esp_select(esp_t *dev) esp_log("ESP SCSI no devices on ID %d, LUN %d\n", dev->id, dev->lun); /* No such drive */ dev->rregs[ESP_RSTAT] = 0; + dev->asc_mode = ESP_ASC_MODE_DIS; dev->rregs[ESP_RINTR] = INTR_DC; esp_raise_irq(dev); return -1; } else esp_log("ESP SCSI device present on ID %d, LUN %d\n", dev->id, dev->lun); + dev->asc_mode = ESP_ASC_MODE_INI; return 0; } @@ -460,9 +476,10 @@ esp_transfer_data(esp_t *dev) * Initial incoming data xfer is complete for sequencer command * so raise deferred bus service and function complete interrupt */ - dev->rregs[ESP_RINTR] |= (INTR_BS | INTR_FC); - dev->rregs[ESP_RSEQ] = SEQ_CD; - break; + dev->rregs[ESP_RINTR] |= (INTR_BS | INTR_FC); + dev->rregs[ESP_RSEQ] = SEQ_CD; + esp_raise_irq(dev); + break; case CMD_SELATNS: case (CMD_SELATNS | CMD_DMA): @@ -470,22 +487,26 @@ esp_transfer_data(esp_t *dev) * Initial incoming data xfer is complete so raise command * completion interrupt */ - dev->rregs[ESP_RINTR] |= INTR_BS; - dev->rregs[ESP_RSEQ] = SEQ_MO; - break; + dev->rregs[ESP_RINTR] |= INTR_BS; + dev->rregs[ESP_RSEQ] = SEQ_MO; + esp_raise_irq(dev); + break; case CMD_TI: case (CMD_TI | CMD_DMA): /* - * Bus service interrupt raised because of initial change to - * DATA phase + * If the final COMMAND phase data was transferred using a TI + * command, clear ESP_CMD to terminate the TI command and raise + * the completion interrupt */ dev->rregs[ESP_CMD] = 0; dev->rregs[ESP_RINTR] |= INTR_BS; + esp_raise_irq(dev); + break; + + default: break; } - - esp_raise_irq(dev); } /* @@ -574,6 +595,7 @@ esp_do_message_phase(esp_t *dev) /* We only support LUN 0 */ esp_log("LUN = %i\n", dev->lun); dev->rregs[ESP_RSTAT] = 0; + dev->asc_mode = ESP_ASC_MODE_DIS; dev->rregs[ESP_RINTR] = INTR_DC; dev->rregs[ESP_RSEQ] = SEQ_0; esp_raise_irq(dev); @@ -631,6 +653,7 @@ esp_hard_reset(esp_t *dev) fifo8_reset(&dev->cmdfifo); dev->dma = 0; dev->tchi_written = 0; + dev->asc_mode = ESP_ASC_MODE_DIS; dev->rregs[ESP_CFG1] = dev->mca ? dev->HostID : 7; esp_log("ESP Reset\n"); @@ -686,18 +709,20 @@ esp_do_dma(esp_t *dev) switch (esp_get_phase(dev)) { case STAT_MO: len = MIN(len, fifo8_num_free(&dev->cmdfifo)); - if (dev->mca) { - dma_set_drq(dev->DmaChannel, 1); - while (dev->dma_86c01.pos < len) { - int val = dma_channel_read(dev->DmaChannel); - buf[dev->dma_86c01.pos++] = val & 0xff; - } - dev->dma_86c01.pos = 0; - dma_set_drq(dev->DmaChannel, 0); - } else - esp_pci_dma_memory_rw(dev, buf, len, WRITE_TO_DEVICE); + if (len) { + if (dev->mca) { + dma_set_drq(dev->DmaChannel, 1); + while (dev->dma_86c01.pos < len) { + int val = dma_channel_read(dev->DmaChannel); + buf[dev->dma_86c01.pos++] = val & 0xff; + } + dev->dma_86c01.pos = 0; + dma_set_drq(dev->DmaChannel, 0); + } else + esp_pci_dma_memory_rw(dev, buf, len, WRITE_TO_DEVICE); - esp_set_tc(dev, esp_get_tc(dev) - len); + esp_set_tc(dev, esp_get_tc(dev) - len); + } fifo8_push_all(&dev->cmdfifo, buf, len); dev->cmdfifo_cdb_offset += len; @@ -745,19 +770,21 @@ esp_do_dma(esp_t *dev) case STAT_CD: len = MIN(len, fifo8_num_free(&dev->cmdfifo)); - if (dev->mca) { - dma_set_drq(dev->DmaChannel, 1); - while (dev->dma_86c01.pos < len) { - int val = dma_channel_read(dev->DmaChannel); - buf[dev->dma_86c01.pos++] = val & 0xff; - } - dev->dma_86c01.pos = 0; - dma_set_drq(dev->DmaChannel, 0); - } else - esp_pci_dma_memory_rw(dev, buf, len, WRITE_TO_DEVICE); + if (len) { + if (dev->mca) { + dma_set_drq(dev->DmaChannel, 1); + while (dev->dma_86c01.pos < len) { + int val = dma_channel_read(dev->DmaChannel); + buf[dev->dma_86c01.pos++] = val & 0xff; + } + dev->dma_86c01.pos = 0; + dma_set_drq(dev->DmaChannel, 0); + } else + esp_pci_dma_memory_rw(dev, buf, len, WRITE_TO_DEVICE); - fifo8_push_all(&dev->cmdfifo, buf, len); - esp_set_tc(dev, esp_get_tc(dev) - len); + fifo8_push_all(&dev->cmdfifo, buf, len); + esp_set_tc(dev, esp_get_tc(dev) - len); + } dev->ti_size = 0; if (esp_get_tc(dev) == 0) { /* Command has been received */ @@ -775,20 +802,22 @@ esp_do_dma(esp_t *dev) switch (dev->rregs[ESP_CMD]) { case (CMD_TI | CMD_DMA): - if (dev->mca) { - dma_set_drq(dev->DmaChannel, 1); - while (dev->dma_86c01.pos < len) { - int val = dma_channel_read(dev->DmaChannel); - esp_log("ESP SCSI DMA write for 53C9x: pos = %i, val = %02x\n", dev->dma_86c01.pos, val & 0xff); - sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos] = val & 0xff; - dev->dma_86c01.pos++; - } - dma_set_drq(dev->DmaChannel, 0); - dev->dma_86c01.pos = 0; - } else - esp_pci_dma_memory_rw(dev, sd->sc->temp_buffer + dev->buffer_pos, len, WRITE_TO_DEVICE); + if (len) { + if (dev->mca) { + dma_set_drq(dev->DmaChannel, 1); + while (dev->dma_86c01.pos < len) { + int val = dma_channel_read(dev->DmaChannel); + esp_log("ESP SCSI DMA write for 53C9x: pos = %i, val = %02x\n", dev->dma_86c01.pos, val & 0xff); + sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos] = val & 0xff; + dev->dma_86c01.pos++; + } + dma_set_drq(dev->DmaChannel, 0); + dev->dma_86c01.pos = 0; + } else + esp_pci_dma_memory_rw(dev, sd->sc->temp_buffer + dev->buffer_pos, len, WRITE_TO_DEVICE); - esp_set_tc(dev, esp_get_tc(dev) - len); + esp_set_tc(dev, esp_get_tc(dev) - len); + } dev->buffer_pos += len; dev->xfer_counter -= len; dev->ti_size += len; @@ -834,18 +863,19 @@ esp_do_dma(esp_t *dev) switch (dev->rregs[ESP_CMD]) { case (CMD_TI | CMD_DMA): - if (dev->mca) { - dma_set_drq(dev->DmaChannel, 1); - while (dev->dma_86c01.pos < len) { - dma_channel_write(dev->DmaChannel, sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos]); - esp_log("ESP SCSI DMA read for 53C9x: pos = %i, val = %02x\n", dev->dma_86c01.pos, sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos]); - dev->dma_86c01.pos++; - } - dev->dma_86c01.pos = 0; - dma_set_drq(dev->DmaChannel, 0); - } else - esp_pci_dma_memory_rw(dev, sd->sc->temp_buffer + dev->buffer_pos, len, READ_FROM_DEVICE); - + if (len) { + if (dev->mca) { + dma_set_drq(dev->DmaChannel, 1); + while (dev->dma_86c01.pos < len) { + dma_channel_write(dev->DmaChannel, sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos]); + esp_log("ESP SCSI DMA read for 53C9x: pos = %i, val = %02x\n", dev->dma_86c01.pos, sd->sc->temp_buffer[dev->buffer_pos + dev->dma_86c01.pos]); + dev->dma_86c01.pos++; + } + dev->dma_86c01.pos = 0; + dma_set_drq(dev->DmaChannel, 0); + } else + esp_pci_dma_memory_rw(dev, sd->sc->temp_buffer + dev->buffer_pos, len, READ_FROM_DEVICE); + } dev->buffer_pos += len; dev->xfer_counter -= len; dev->ti_size -= len; @@ -886,6 +916,7 @@ esp_do_dma(esp_t *dev) if (len) { buf[0] = dev->status; + /* Length already non-zero */ if (dev->mca) { dma_set_drq(dev->DmaChannel, 1); while (dev->dma_86c01.pos < len) { @@ -925,6 +956,7 @@ esp_do_dma(esp_t *dev) if (len) { buf[0] = 0; + /* Length already non-zero */ if (dev->mca) { dma_set_drq(dev->DmaChannel, 1); while (dev->dma_86c01.pos < len) { @@ -1323,6 +1355,37 @@ esp_callback(void *priv) } } +static int +esp_cmd_is_valid(esp_t *dev, uint8_t cmd) +{ + uint8_t cmd_group = (cmd & CMD_GRP_MASK) >> 4; + + /* Always allow misc commands */ + if (cmd_group == CMD_GRP_MISC) + return 1; + + switch (dev->asc_mode) { + case ESP_ASC_MODE_DIS: + /* Disconnected mode: only allow disconnected commands */ + if (cmd_group == CMD_GRP_DISC) + return 1; + + break; + + case ESP_ASC_MODE_INI: + /* Initiator mode: allow initiator commands */ + if (cmd_group == CMD_GRP_INIT) + return 1; + + break; + + default: + break; + } + + return 0; +} + static uint32_t esp_reg_read(esp_t *dev, uint32_t saddr) { @@ -1385,6 +1448,11 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) break; case ESP_CMD: dev->rregs[ESP_CMD] = val; + if (!esp_cmd_is_valid(dev, dev->rregs[saddr])) { + dev->rregs[ESP_RSTAT] |= INTR_IL; + esp_raise_irq(dev); + break; + } if (val & CMD_DMA) { dev->dma = 1; @@ -1446,6 +1514,7 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) handle_satn_stop(dev); break; case CMD_MSGACC: + dev->asc_mode = ESP_ASC_MODE_DIS; dev->rregs[ESP_RINTR] |= INTR_DC; dev->rregs[ESP_RSEQ] = 0; dev->rregs[ESP_RFLAGS] = 0; diff --git a/src/unix/unix.c b/src/unix/unix.c index f3580cd19..5a69424b4 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -948,6 +948,11 @@ void (*f_rl_callback_handler_remove)(void) = NULL; # define LIBEDIT_LIBRARY "libedit.so" #endif +void ui_sb_update_icon_wp(int tag, int state) +{ + /* No-op */ +} + uint32_t timer_onesec(uint32_t interval, UNUSED(void *param)) { diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 06db8dcba..e6d918e53 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -85,6 +85,7 @@ paradise_in(uint16_t addr, void *priv) { paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; + uint8_t max_sr = (paradise->type >= WD90C30) ? 0x15 : 0x12; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -94,7 +95,7 @@ paradise_in(uint16_t addr, void *priv) if (svga->seqaddr > 7) { if (paradise->type < WD90C11 || svga->seqregs[6] != 0x48) return 0xff; - if (svga->seqaddr > 0x12) + if (svga->seqaddr > max_sr) return 0xff; return svga->seqregs[svga->seqaddr & 0x1f]; } @@ -342,12 +343,12 @@ paradise_remap(paradise_t *paradise) paradise->write_bank[3] = paradise->write_bank[2] + 0x8000; } else if ((svga->gdcreg[6] & 0x0c) == 0x04) { paradise->read_bank[0] = svga->gdcreg[0x0a] << 12; - paradise->read_bank[1] = svga->gdcreg[9] << 12; + paradise->read_bank[1] = (svga->gdcreg[9] << 12) + 0x8000; paradise->read_bank[2] = paradise->read_bank[0]; paradise->read_bank[3] = paradise->read_bank[1]; paradise->write_bank[0] = svga->gdcreg[0x0a] << 12; - paradise->write_bank[1] = svga->gdcreg[9] << 12; + paradise->write_bank[1] = (svga->gdcreg[9] << 12) + 0x8000; paradise->write_bank[2] = paradise->write_bank[0]; paradise->write_bank[3] = paradise->write_bank[1]; } else { @@ -505,11 +506,11 @@ paradise_recalctimings(svga_t *svga) if ((svga->gdcreg[6] & 1) || (svga->attrregs[0x10] & 1)) { if ((svga->bpp >= 8) && !svga->lowres) { svga->render = svga_render_8bpp_highres; - if (paradise->type != WD90C11) + if (paradise->type < WD90C11) svga->vram_display_mask = (svga->crtc[0x2f] & 0x02) ? 0x3ffff : paradise->vram_mask; } } - if (paradise->type == WD90C11) switch (svga->crtc[0x2f] & 0x60) { + if (paradise->type >= WD90C11) switch (svga->crtc[0x2f] & 0x60) { case 0x60: case 0x40: svga->vram_display_mask = 0x3ffff; break; @@ -581,12 +582,11 @@ paradise_decode_addr(paradise_t *paradise, uint32_t addr, int write) break; } - if (memory_map_mode <= 1) { - if (write) - addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; - else - addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; - } + if (write) + addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; + else + addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; + return addr; } @@ -669,7 +669,7 @@ paradise_read(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - addr = paradise_decode_addr(paradise, addr, 1); + addr = paradise_decode_addr(paradise, addr, 0); if (addr == 0xffffffff) return 0xff; @@ -704,7 +704,7 @@ paradise_readw(uint32_t addr, void *priv) uint32_t prev_addr; uint32_t prev_addr2; - addr = paradise_decode_addr(paradise, addr, 1); + addr = paradise_decode_addr(paradise, addr, 0); if (addr == 0xffffffff) return 0xffff; diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index 5a9251dad..91a2ce500 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -898,20 +898,6 @@ xga_ext_inb(uint16_t addr, void *priv) return ret; } -#define READ(addr, dat) \ - dat = xga->vram[(addr) & (xga->vram_mask)]; - -#define WRITE(addr, dat) \ - xga->vram[((addr)) & (xga->vram_mask)] = dat; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; - -#define READW(addr, dat) \ - dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; - -#define WRITEW(addr, dat) \ - *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; - #define ROP(mix, d, s) \ { \ switch ((mix) ? (xga->accel.frgd_mix & 0x1f) : (xga->accel.bkgd_mix & 0x1f)) { \ @@ -984,434 +970,256 @@ xga_ext_inb(uint16_t addr, void *priv) } \ } +static uint32_t +xga_transform_addr(uint32_t addr, uint8_t mode) +{ + uint32_t ret = addr; + + if ((mode & 0x0f) == 0x0c) + ret ^= 1; + + return ret; +} + +static uint16_t +xga_transform_val(uint16_t val, uint8_t mode, int bits) +{ + uint16_t ret = 0x0000; + + switch (mode & 0x0f) { + default: + ret = val; + break; + case 0x08: /* 1 bpp */ + for (int i = 0; i < bits; i++) + ret |= ((val >> i) & 0x01) << (i ^ 7); + break; + case 0x09: /* 2 bpp */ + for (int i = 0; i < bits; i += 2) + ret |= ((val >> i) & 0x03) << (i ^ 6); + break; + case 0x0a: /* 4 bpp */ + for (int i = 0; i < bits; i += 4) + ret |= ((val >> i) & 0x0f) << (i ^ 4); + break; + case 0x0c: /* 16 bpp */ + if (bits == 16) for (int i = 0; i < (bits >> 3); i++) + ret |= ((val >> (i << 3)) & 0xff) << ((i << 3) ^ 8); + else + ret = val; + break; + } + + return ret & ((1 << bits) - 1); +} + +static uint8_t +xga_map_readb(svga_t *svga, uint32_t addr, int map) +{ + xga_t *xga = (xga_t *) svga->xga; + uint8_t ret; + + if ((addr >= xga->linear_base) && (addr <= (xga->linear_base + 0xfffff))) + ret = xga->vram[addr & xga->vram_mask]; + else + ret = xga_transform_val(mem_readb_phys(xga_transform_addr(addr, xga->accel.px_map_format[map])), + xga->accel.px_map_format[map], 8); + return ret; +} + +static uint16_t +xga_map_readw(svga_t *svga, uint32_t addr, int map) +{ + xga_t *xga = (xga_t *) svga->xga; + uint16_t ret; + + if ((addr >= xga->linear_base) && (addr <= (xga->linear_base + 0xfffff))) + ret = *(uint16_t *) &xga->vram[addr & xga->vram_mask]; + else + ret = xga_transform_val(mem_readw_phys(addr), xga->accel.px_map_format[map], 16); + + return ret; +} + static void -xga_set_pixel_map_endianess(xga_t *xga, int srcmap, int dstmap) +xga_map_writeb(svga_t *svga, uint32_t addr, int map, uint8_t val) { - if (xga->access_mode & 0x08) { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) - xga->src_reverse_order = 1; + xga_t *xga = (xga_t *) svga->xga; - xga->dst_reverse_order = 1; - } else { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) { - if (xga->accel.px_map_format[srcmap] & 0x08) { - xga->src_reverse_order = 1; - xga->dst_reverse_order = 1; - } - } - if (xga->accel.px_map_format[dstmap] & 0x08) { - xga->src_reverse_order = 1; - xga->dst_reverse_order = 1; - } - } - xga_log("1bpp setendianness: dstmap=%02x, srcmap=%02x, mode=%02x, dstreverse=%d, srcreverse=%d.\n", xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode, xga->dst_reverse_order, xga->src_reverse_order); -} - -static uint32_t -xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int srcmap, int dstmap, uint32_t base, int width) -{ - xga_t *xga = (xga_t *) svga->xga; - uint32_t addr = base; - int bits; - uint8_t byte; - uint8_t px; - int skip = 0; - int pos = (y * (width + 1)) + (x % (width + 1)); - - if (xga->access_mode & 0x08) { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) - xga->src_reverse_order = 1; - - xga->dst_reverse_order = 1; - } else { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) { - if (xga->accel.px_map_format[srcmap] & 0x08) { - switch (xga->accel.px_map_format[srcmap] & 0x07) { - case 0x00: /*1-bit*/ - xga->src_reverse_order = 1; - break; - default: - break; - } - } - } - if (xga->accel.px_map_format[dstmap] & 0x08) - xga->dst_reverse_order = 1; - } - - addr += (pos / 8); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); + if ((addr >= xga->linear_base) && (addr <= (xga->linear_base + 0xfffff))) { + xga->vram[addr & xga->vram_mask] = val; + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; } else - byte = mem_readb_phys(addr); - - bits = pos & 7; - - if (xga->src_reverse_order || xga->dst_reverse_order) - bits ^= 7; - - if (!(xga->access_mode & 0x08) && !(xga->accel.px_map_format[xga->accel.pat_src] & 0x08)) - bits ^= 7; - - px = (byte >> bits) & 0x01; - - if ((width + 1) & 7) { - xga_log("CMD=%08x, 1bpp patread: dstmap=%02x, srcmap=%02x, mode=%02x, dstreverse=%d, srcreverse=%d, addr=%06x, pos=%d, width=%d, x=%d, y=%d, byte=%02x, bits=%d, pix=%x.\n", xga->accel.command, xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode, xga->dst_reverse_order, xga->src_reverse_order, addr, pos, width + 1, x, y, byte, bits, px); - } - - return px; + mem_writeb_phys(xga_transform_addr(addr, xga->accel.px_map_format[map]), + xga_transform_val(val, xga->accel.px_map_format[map], 8)); } -static uint32_t -xga_accel_read_area_map_pixel(svga_t *svga, int x, int y, int srcmap, int dstmap, uint32_t base, int width) +static void +xga_map_writew(svga_t *svga, uint32_t addr, int map, uint16_t val) { - xga_t *xga = (xga_t *) svga->xga; - uint32_t addr = base; - int bits; - uint8_t byte; - uint8_t px; - int skip = 0; - int pos = (y * (width + 1)) + (x % (width + 1)); + xga_t *xga = (xga_t *) svga->xga; - if (xga->access_mode & 0x08) { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) - xga->src_reverse_order = 1; - - xga->dst_reverse_order = 1; - } else { - if ((((xga->accel.command >> 28) & 3) == 2) || (((xga->accel.command >> 30) & 3) == 2)) { - if (xga->accel.px_map_format[srcmap] & 0x08) { - switch (xga->accel.px_map_format[srcmap] & 0x07) { - case 0x00: /*1-bit*/ - xga->src_reverse_order = 1; - break; - default: - break; - } - } - } - if (xga->accel.px_map_format[dstmap] & 0x08) { - switch (xga->accel.px_map_format[dstmap] & 0x07) { - case 0x00: /*1-bit*/ - xga->dst_reverse_order = 1; - break; - default: - break; - } - } - } - - addr += (pos / 8); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); + if ((addr >= xga->linear_base) && (addr <= (xga->linear_base + 0xfffff))) { + *(uint16_t *) &xga->vram[addr & xga->vram_mask] = val; + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; } else - byte = mem_readb_phys(addr); + mem_writew_phys(addr, xga_transform_val(val, xga->accel.px_map_format[map], 16)); +} - xga_log("1bpp arearead: dstmap=%02x, srcmap=%02x, mode=%02x.\n", xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode); +static int +xga_calc_pos(int x, int y, int width) +{ + int ret = (y * (width + 1)) + (x % (width + 1)); - bits = pos & 7; - - if (xga->src_reverse_order || xga->dst_reverse_order) - bits ^= 7; - - px = (byte >> bits) & 0x01; - return px; + return ret; } static uint32_t -xga_accel_source_read_map_pixel(svga_t *svga, int x, int y, int srcmap, int dstmap, uint32_t base, int width) +xga_add_to_addr(xga_t *xga, uint32_t addr, int pos, int map) { - xga_t *xga = (xga_t *) svga->xga; - uint32_t addr = base; - int bits; - uint32_t byte; - uint8_t mask; - uint8_t px; - int skip = 0; - int pos; + int pos_div[8] = { 8, 4, 2, 1, 1, 1, 1, 1 }; + int pos_mul[8] = { 1, 1, 1, 1, 2, 1, 1, 1 }; + int div_val = pos_div[xga->accel.px_map_format[map] & 0x07]; + int mul_val = pos_mul[xga->accel.px_map_format[map] & 0x07]; + uint32_t ret = addr + ((pos / div_val) * mul_val); - switch (xga->accel.px_map_format[srcmap] & 0x07) { - case 0: /*1-bit*/ - pos = (y * (width + 1)) + (x % (width + 1)); - addr += (pos / 8); + return ret; +} - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; +#define READ_MAP(base, pos, map) xga_map_readb(svga, xga_add_to_addr(xga, base, pos, map), map) +#define READ_MAPW(base, pos, map) xga_map_readw(svga, xga_add_to_addr(xga, base, pos, map), map) +#define WRITE_MAP(base, pos, map, val) xga_map_writeb(svga, xga_add_to_addr(xga, base, pos, map), map, val) +#define WRITE_MAPW(base, pos, map, val) xga_map_writew(svga, xga_add_to_addr(xga, base, pos, map), map, val) - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); +#define DO_READ_MAP(map) READ_MAP(base, pos, map) - xga_log("1bpp srcread: dstmap=%02x, srcmap=%02x, mode=%02x.\n", xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode); +#define PIXEL_MASK(bits) (0x07 / bits) +#define ALL_SET(bits) ((1 << bits) - 1) - bits = pos & 7; +#define MASK(map, bits) ((pos & PIXEL_MASK(bits)) * bits) +#define MASKED_READ(map, bits) (DO_READ_MAP(map) >> MASK(map, bits)) & ALL_SET(bits) - if (xga->src_reverse_order) - bits ^= 7; +static uint32_t +xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y) +{ + xga_t *xga = (xga_t *) svga->xga; + int map = 0; + uint32_t ret = 0x000000ff; - px = (byte >> bits) & 0x01; - xga_log("1bpp srcread: OPMODEBIG=%02x, SRC Map=%02x, DST Map=%02x, AccessMode=%02x, SRCPIX=%02x, DSTPIX=%02x, srcwidth=%d, pos=%d, bits=%d, px=%x, x=%d, y=%d, skip=%d.\n", - xga->op_mode & 0x08, (xga->accel.px_map_format[srcmap] & 0x0f), (xga->accel.px_map_format[dstmap] & 0x0f), xga->access_mode & 0x0f, srcmap, dstmap, width, pos, bits, px, x, y, skip); - return px; - case 2: /*4-bit*/ - addr += (y * ((width + 1) >> 1)); - addr += ((x % (width + 1)) >> 1); + switch ((xga->accel.command >> 12) & 0x0f) { + default: + case 8: + map = 0; + break; + case 1 ... 3: + map = (xga->accel.command >> 12) & 0x0f; + break; + case 9: + map = (xga->accel.command >> 20) & 0x0f; + if (map > 0x03) + map = 0; + break; + } - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; + if (map != 0) { + int width = xga->accel.px_map_width[map]; + int pos = xga_calc_pos(x, y, width); + uint32_t base = xga->accel.px_map_base[map]; - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); + ret = MASKED_READ(map, 1); + } - if ((xga->accel.px_map_format[srcmap] & 0x08) && (xga->access_mode & 0x08)) - mask = ((1 - (x & 1)) << 2); - else { - mask = ((x & 1) << 2); - mask ^= 0x04; - } + return ret; +} - byte = (byte >> mask) & 0x0f; - xga_log("4bpp read: OPMODEBIG=%02x, SRC Map=%02x, DST Map=%02x, AccessMode=%02x, SRCPIX=%02x, DSTPIX=%02x, wordpix=%04x, x=%d, y=%d, skip=%d, mask=%02x.\n", xga->op_mode & 0x08, (xga->accel.px_map_format[xga->accel.src_map] & 0x0f), (xga->accel.px_map_format[xga->accel.dst_map] & 0x0f), xga->access_mode & 0x0f, xga->accel.src_map, xga->accel.dst_map, byte, x, y, skip, mask); - return byte; - case 3: /*8-bit*/ - addr += (y * (width + 1)); - addr += (x % (width + 1)); +static uint32_t +xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map) +{ + xga_t *xga = (xga_t *) svga->xga; + int width = xga->accel.px_map_width[map]; + int pos = xga_calc_pos(x, y, width); + uint32_t base = xga->accel.px_map_base[map]; + uint32_t ret = 0x00000000; - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; + switch (xga->accel.px_map_format[map] & 0x07) { + case 0: /* 1 bpp */ + ret = MASKED_READ(map, 1); + break; - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); + case 1: /* 2 bpp */ + ret = MASKED_READ(map, 2); + break; - return byte; - case 4: /*16-bit*/ - addr += (y * ((width + 1) << 1)); - addr += ((x % (width + 1)) << 1); + case 2: /* 4 bpp */ + ret = MASKED_READ(map, 4); + break; - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; + case 3: /* 8 bpp */ + ret = READ_MAP(base, pos, map); + break; - if (!skip) { - READW(addr, byte); - } else { - byte = mem_readw_phys(addr); - if ((xga->access_mode & 0x07) == 0x04) - byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); - else if (xga->access_mode & 0x08) - byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); - } - return byte; + case 4: /* 16 bpp */ + ret = READ_MAPW(base, pos, map); + break; default: break; } - return 0; -} -static uint32_t -xga_accel_destination_read_map_pixel(svga_t *svga, int x, int y, int srcmap, int dstmap, uint32_t base, int width) -{ - xga_t *xga = (xga_t *) svga->xga; - uint32_t addr = base; - int bits; - uint32_t byte; - uint8_t mask; - uint8_t px; - int skip = 0; - int pos; - - switch (xga->accel.px_map_format[dstmap] & 0x07) { - case 0: /*1-bit*/ - pos = (y * (width + 1)) + (x % (width + 1)); - addr += (pos / 8); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); - - xga_log("1bpp dstread: dstmap=%02x, srcmap=%02x, mode=%02x.\n", xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode); - - bits = pos & 7; - - if (xga->dst_reverse_order) - bits ^= 7; - - px = (byte >> bits) & 0x01; - xga_log("1bpp dstread: OPMODEBIG=%02x, SRC Map=%02x, DST Map=%02x, AccessMode=%02x, SRCPIX=%02x, DSTPIX=%02x, dstwidth=%d, pos=%d, bits=%d, px=%x, x=%d, y=%d, skip=%d.\n", - xga->op_mode & 0x08, (xga->accel.px_map_format[srcmap] & 0x0f), (xga->accel.px_map_format[dstmap] & 0x0f), xga->access_mode & 0x0f, srcmap, dstmap, width, pos, bits, px, x, y, skip); - return px; - case 2: /*4-bit*/ - addr += (y * ((width + 1) >> 1)); - addr += ((x % (width + 1)) >> 1); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); - - if ((xga->accel.px_map_format[dstmap] & 0x08) && (xga->access_mode & 0x08)) - mask = ((1 - (x & 1)) << 2); - else { - mask = ((x & 1) << 2); - mask ^= 0x04; - } - - byte = (byte >> mask) & 0x0f; - xga_log("4bpp read: OPMODEBIG=%02x, SRC Map=%02x, DST Map=%02x, AccessMode=%02x, SRCPIX=%02x, DSTPIX=%02x, wordpix=%04x, x=%d, y=%d, skip=%d, mask=%02x.\n", xga->op_mode & 0x08, (xga->accel.px_map_format[xga->accel.src_map] & 0x0f), (xga->accel.px_map_format[xga->accel.dst_map] & 0x0f), xga->access_mode & 0x0f, xga->accel.src_map, xga->accel.dst_map, byte, x, y, skip, mask); - return byte; - case 3: /*8-bit*/ - addr += (y * (width + 1)); - addr += (x % (width + 1)); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); - - return byte; - case 4: /*16-bit*/ - addr += (y * ((width + 1) << 1)); - addr += ((x % (width + 1)) << 1); - - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READW(addr, byte); - } else { - byte = mem_readw_phys(addr); - if ((xga->access_mode & 0x07) == 0x04) - byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); - else if (xga->access_mode & 0x08) - byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); - } - return byte; - - default: - break; - } - return 0; + return ret; } static void -xga_accel_write_map_pixel(svga_t *svga, int x, int y, int srcmap, int dstmap, uint32_t base, uint32_t pixel, int width) +xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t pixel) { xga_t *xga = (xga_t *) svga->xga; - uint32_t addr = base; uint8_t byte; uint8_t mask; - int skip = 0; - int pos; + int bit; + int width = xga->accel.px_map_width[map]; + int pos = xga_calc_pos(x, y, width); + uint32_t base = xga->accel.px_map_base[map]; - switch (xga->accel.px_map_format[dstmap] & 0x07) { - case 0: /*1-bit*/ - pos = (y * (width + 1)) + (x % (width + 1)); - addr += (pos / 8); + switch (xga->accel.px_map_format[map] & 0x07) { + case 0: /* 1 bpp */ + byte = READ_MAP(base, pos, map); + bit = pos & 7; - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); - - xga_log("1bpp dstwrite: dstmap=%02x, srcmap=%02x, mode=%02x.\n", xga->accel.px_map_format[dstmap], xga->accel.px_map_format[srcmap], xga->access_mode); - - pos &= 7; - - if (xga->dst_reverse_order) - pos ^= 7; - - pixel <<= pos; - mask = 1 << pos; + pixel <<= bit; + mask = 1 << bit; byte = (byte & ~mask) | (pixel & mask); - if (!skip) { - WRITE(addr, byte); - } - mem_writeb_phys(addr, byte); + WRITE_MAP(base, pos, map, byte); break; - case 2: /*4-bit*/ - addr += (y * ((width + 1) >> 1)); - addr += ((x % (width + 1)) >> 1); - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; + case 1: /* 2 bpp */ + byte = READ_MAP(base, pos, map); + mask = ((pos & 3) << 1); - if (!skip) { - READ(addr, byte); - } else - byte = mem_readb_phys(addr); + pixel <<= mask; + mask = 0x03 << mask; - if ((xga->accel.px_map_format[dstmap] & 0x08) && (xga->access_mode & 0x08)) - mask = ((1 - (x & 1)) << 2); - else { - mask = ((x & 1) << 2); - mask ^= 0x04; - } - xga_log("4bpp Write: AccessMode=%02x.\n", xga->access_mode & 0x08); + byte = (byte & ~mask) | (pixel & mask); + WRITE_MAP(base, pos, map, byte); + break; + + case 2: /* 4 bpp */ + byte = READ_MAP(base, pos, map); + mask = ((pos & 1) << 2); pixel <<= mask; mask = 0x0f << mask; byte = (byte & ~mask) | (pixel & mask); - if (!skip) { - WRITE(addr, byte); - } - mem_writeb_phys(addr, byte); + WRITE_MAP(base, pos, map, byte); break; - case 3: /*8-bit*/ - addr += (y * (width + 1)); - addr += (x % (width + 1)); - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - WRITE(addr, pixel & 0xff); - } - mem_writeb_phys(addr, pixel & 0xff); + case 3: /* 8bpp */ + WRITE_MAP(base, pos, map, pixel); break; - case 4: /*16-bit*/ - addr += (y * ((width + 1) << 1)); - addr += ((x % (width + 1)) << 1); - if ((addr < xga->linear_base) || (addr > (xga->linear_base + 0xfffff))) - skip = 1; - - if (!skip) { - WRITEW(addr, pixel); - } else { - if ((xga->access_mode & 0x07) == 0x04) - pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); - else if (xga->access_mode & 0x08) - pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); - } - mem_writew_phys(addr, pixel); + case 4: /* 16bpp */ + WRITE_MAPW(base, pos, map, pixel); break; default: @@ -1428,8 +1236,6 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) uint32_t old_dest_dat; 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; int16_t dx; @@ -1485,11 +1291,13 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) if (xga->accel.pat_src == 8) { while (y >= 0) { - xga_set_pixel_map_endianess(xga, xga->accel.src_map, xga->accel.dst_map); 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_source_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + 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) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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; @@ -1497,19 +1305,22 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); if ((xga->accel.command & 0x30) == 0) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } else if (((xga->accel.command & 0x30) == 0x10) && x) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } else if (((xga->accel.command & 0x30) == 0x20) && y) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + 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) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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; @@ -1517,13 +1328,13 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) dest_dat = (dest_dat & plane_mask) | (old_dest_dat & ~plane_mask); if ((xga->accel.command & 0x30) == 0) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } else if (((xga->accel.command & 0x30) == 0x10) && x) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } else if (((xga->accel.command & 0x30) == 0x20) && y) { if (ssv & 0x10) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } @@ -1552,8 +1363,6 @@ xga_line_draw_write(svga_t *svga) uint32_t old_dest_dat = 0x00000000; 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 = xga->accel.blt_width; int x = 0; int draw_pixel = 0; @@ -1579,7 +1388,6 @@ xga_line_draw_write(svga_t *svga) if (xga->accel.pat_src == 8) { if ((xga->accel.command & 0x30) == 0x30) { while (y >= 0) { - xga_set_pixel_map_endianess(xga, xga->accel.src_map, xga->accel.dst_map); draw_pixel = 0; if (xga->accel.octant & 0x01) { /*Y Major*/ @@ -1617,26 +1425,30 @@ xga_line_draw_write(svga_t *svga) xga_log("Draw Boundary: DX=%d, DY=%d, wrt_pix=%d, ymajor=%d, bottomtotop=%x, len=%d, err=%d, frgdmix=%02x.\n", dx, dy, draw_pixel, xga->accel.octant & 0x01, xga->accel.octant & 0x02, y, xga->accel.bres_err_term, xga->accel.frgd_mix & 0x1f); 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)) && draw_pixel) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, cx, cy, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, cx, cy, xga->accel.src_map) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } else { if (draw_pixel) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, cx, cy, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, cx, cy, xga->accel.src_map) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } @@ -1681,38 +1493,43 @@ xga_line_draw_write(svga_t *svga) } } else { while (y >= 0) { - xga_set_pixel_map_endianess(xga, xga->accel.src_map, xga->accel.dst_map); 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_source_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + 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) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); if ((xga->accel.command & 0x30) == 0) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); else if (((xga->accel.command & 0x30) == 0x10) && x) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); else if (((xga->accel.command & 0x30) == 0x20) && y) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, xga->accel.dst_map, srcbase, xga->accel.px_map_width[xga->accel.src_map]) : xga->accel.frgd_color; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map]); + 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) : + xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); if ((xga->accel.command & 0x30) == 0) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); else if (((xga->accel.command & 0x30) == 0x10) && x) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); else if (((xga->accel.command & 0x30) == 0x20) && y) - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map]); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } @@ -1767,9 +1584,6 @@ xga_bitblt(svga_t *svga) uint32_t old_dest_dat; uint32_t color_cmp = xga->accel.color_cmp; uint32_t plane_mask = xga->accel.plane_mask; - uint32_t patbase; - 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; uint32_t dstwidth = xga->accel.px_map_width[xga->accel.dst_map]; uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; @@ -1836,27 +1650,30 @@ xga_bitblt(svga_t *svga) srcwidth, srcheight, dstwidth, dstheight, xga->accel.sx, xga->accel.sy); while (xga->accel.y >= 0) { - xga_set_pixel_map_endianess(xga, xga->accel.src_map, xga->accel.dst_map); 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_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } else { if ((dx >= 0) && (dx <= dstwidth) && (dy >= 0) && (dy <= dstheight)) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } @@ -1895,7 +1712,6 @@ xga_bitblt(svga_t *svga) } } } else if (xga->accel.pat_src >= 1) { - patbase = xga->accel.px_map_base[xga->accel.pat_src]; patwidth = xga->accel.px_map_width[xga->accel.pat_src]; patheight = xga->accel.px_map_height[xga->accel.pat_src]; @@ -1938,7 +1754,7 @@ xga_bitblt(svga_t *svga) if (((xga->accel.command >> 24) & 0x0f) == 0x0a) { if ((xga->accel.bkgd_mix & 0x1f) == 0x05) { while (xga->accel.y >= 0) { - mix = xga_accel_read_area_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.src_map, xga->accel.dst_map, patbase, patwidth); + mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py); if (mix) xga->accel.filling ^= 1; @@ -1946,26 +1762,30 @@ xga_bitblt(svga_t *svga) 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)) && xga->accel.filling) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); xga_log("XGA Area Fill1: Dest=%02x, Src=%02x, OldD=%02x.\n", dest_dat, src_dat, old_dest_dat); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } else { if ((dx >= 0) && (dx <= dstwidth) && (dy >= 0) && (dy <= dstheight) && xga->accel.filling) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); xga_log("XGA Area Fill2: Dest=%02x, Src=%02x, OldD=%02x.\n", dest_dat, src_dat, old_dest_dat); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } @@ -2002,36 +1822,44 @@ xga_bitblt(svga_t *svga) } } else { while (xga->accel.y >= 0) { - mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.src_map, xga->accel.dst_map, patbase, patwidth); + mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py); 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))) { if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : bkgdcol; + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + bkgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } else { if ((dx >= 0) && (dx <= dstwidth) && (dy >= 0) && (dy <= dstheight)) { if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : frgdcol; + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + frgdcol; else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_source_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, xga->accel.dst_map, srcbase, srcwidth) : bkgdcol; + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? + xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map) : + bkgdcol; - dest_dat = xga_accel_destination_read_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dstwidth); + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map); 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); - xga_accel_write_map_pixel(svga, dx, dy, xga->accel.src_map, xga->accel.dst_map, dstbase, dest_dat, dstwidth); + xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dest_dat); } } } @@ -3046,13 +2874,20 @@ xga_write_banked(uint32_t addr, uint8_t val, void *priv) svga_t *svga = (svga_t *) priv; xga_t *xga = (xga_t *) svga->xga; - if (xga->access_mode & 0x08) { - if ((xga->access_mode & 0x07) == 0x04) - addr ^= 1; - } + xga->changedvram[(xga_transform_addr(addr, xga->access_mode) & xga->vram_mask) >> 12] = + svga->monitor->mon_changeframecount; + xga->vram[xga_transform_addr(addr, xga->access_mode) & xga->vram_mask] = + xga_transform_val(val, xga->access_mode, 8); +} - xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; - xga->vram[addr & xga->vram_mask] = val; +static void +xga_writew_banked(uint32_t addr, uint16_t val, void *priv) +{ + svga_t *svga = (svga_t *) priv; + xga_t *xga = (xga_t *) svga->xga; + + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; + *(uint16_t *) &(xga->vram[addr & xga->vram_mask]) = xga_transform_val(val, xga->access_mode, 16); } static void @@ -3088,8 +2923,7 @@ xga_writew(uint32_t addr, uint16_t val, void *priv) cycles -= svga->monitor->mon_video_timing_write_w; - xga_write_banked(addr, val & 0xff, svga); - xga_write_banked(addr + 1, val >> 8, svga); + xga_writew_banked(addr, val, svga); } static void @@ -3107,10 +2941,8 @@ xga_writel(uint32_t addr, uint32_t val, void *priv) cycles -= svga->monitor->mon_video_timing_write_l; - xga_write_banked(addr, val & 0xff, svga); - xga_write_banked(addr + 1, val >> 8, svga); - xga_write_banked(addr + 2, val >> 16, svga); - xga_write_banked(addr + 3, val >> 24, svga); + xga_writew_banked(addr, val & 0xffff, svga); + xga_writew_banked(addr + 2, val >> 16, svga); } uint8_t @@ -3160,12 +2992,21 @@ xga_read_banked(uint32_t addr, void *priv) xga_t *xga = (xga_t *) svga->xga; uint8_t ret = 0xff; - if (xga->access_mode & 0x08) { - if ((xga->access_mode & 0x07) == 0x04) - addr ^= 1; - } + ret = xga_transform_val(xga->vram[xga_transform_addr(addr, xga->access_mode) & xga->vram_mask], + xga->access_mode, 8); - ret = xga->vram[addr & xga->vram_mask]; + return ret; +} + +static uint16_t +xga_readw_banked(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + xga_t *xga = (xga_t *) svga->xga; + uint16_t ret = 0xffff; + + ret = xga_transform_val(*(uint16_t *) &(xga->vram[addr & xga->vram_mask]), + xga->access_mode, 16); return ret; } @@ -3208,8 +3049,7 @@ xga_readw(uint32_t addr, void *priv) cycles -= svga->monitor->mon_video_timing_read_w; - ret = xga_read_banked(addr, svga); - ret |= (xga_read_banked(addr + 1, svga) << 8); + ret = xga_readw_banked(addr, svga); return ret; } @@ -3230,10 +3070,8 @@ xga_readl(uint32_t addr, void *priv) cycles -= svga->monitor->mon_video_timing_read_l; - ret = xga_read_banked(addr, svga); - ret |= (xga_read_banked(addr + 1, svga) << 8); - ret |= (xga_read_banked(addr + 2, svga) << 16); - ret |= (xga_read_banked(addr + 3, svga) << 24); + ret = xga_readw_banked(addr, svga); + ret |= (xga_readw_banked(addr + 2, svga) << 16); return ret; } @@ -3258,23 +3096,35 @@ xga_write_linear(uint32_t addr, uint8_t val, void *priv) cycles -= svga->monitor->mon_video_timing_write_b; - xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; - xga->vram[addr & xga->vram_mask] = val; + xga->changedvram[(xga_transform_addr(addr, xga->access_mode) & xga->vram_mask) >> 12] = + svga->monitor->mon_changeframecount; + xga->vram[xga_transform_addr(addr, xga->access_mode) & xga->vram_mask] = + xga_transform_val(val, xga->access_mode, 8); } static void xga_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) priv; - const xga_t *xga = (xga_t *) svga->xga; + svga_t *svga = (svga_t *) priv; + xga_t *xga = (xga_t *) svga->xga; + xga_log("WriteLL XGA=%d, addr=%08x, val=%02x.\n", xga->on, addr, val); if (!xga->on) { svga_writew_linear(addr, val, svga); return; } - xga_write_linear(addr, val, priv); - xga_write_linear(addr + 1, val >> 8, priv); + addr &= xga->vram_mask; + + if (addr >= xga->vram_size) { + xga_log("Write Linear Over!.\n"); + return; + } + + cycles -= svga->monitor->mon_video_timing_write_b; + + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; + *(uint16_t *) &(xga->vram[addr & xga->vram_mask]) = xga_transform_val(val, xga->access_mode, 16); } static void @@ -3288,10 +3138,8 @@ xga_writel_linear(uint32_t addr, uint32_t val, void *priv) return; } - xga_write_linear(addr, val, priv); - xga_write_linear(addr + 1, val >> 8, priv); - xga_write_linear(addr + 2, val >> 16, priv); - xga_write_linear(addr + 3, val >> 24, priv); + xga_writew_linear(addr, val, priv); + xga_writew_linear(addr + 2, val >> 16, priv); } static uint8_t @@ -3301,19 +3149,17 @@ xga_read_linear(uint32_t addr, void *priv) const xga_t *xga = (xga_t *) svga->xga; uint8_t ret = 0xff; - if (!xga->on) - return svga_read_linear(addr, svga); + if (xga->on) { + addr &= xga->vram_mask; - addr &= xga->vram_mask; + if (addr < xga->vram_size) { + cycles -= svga->monitor->mon_video_timing_read_b; - if (addr >= xga->vram_size) { - xga_log("Read Linear Over ADDR=%x!.\n", addr); - return ret; - } - - cycles -= svga->monitor->mon_video_timing_read_b; - - ret = xga->vram[addr & xga->vram_mask]; + ret = xga_transform_val(xga->vram[xga_transform_addr(addr, xga->access_mode) & xga->vram_mask], + xga->access_mode, 8); + } + } else + ret = svga_read_linear(addr, svga); return ret; } @@ -3323,13 +3169,19 @@ xga_readw_linear(uint32_t addr, void *priv) { svga_t *svga = (svga_t *) priv; const xga_t *xga = (xga_t *) svga->xga; - uint16_t ret; + uint16_t ret = 0xffff; - if (!xga->on) - return svga_readw_linear(addr, svga); + if (xga->on) { + addr &= xga->vram_mask; - ret = xga_read_linear(addr, svga); - ret |= (xga_read_linear(addr + 1, svga) << 8); + if (addr < xga->vram_size) { + cycles -= svga->monitor->mon_video_timing_read_b; + + ret = xga_transform_val(*(uint16_t *) &(xga->vram[addr & xga->vram_mask]), + xga->access_mode, 16); + } + } else + ret = svga_readw_linear(addr, svga); return ret; } @@ -3344,10 +3196,8 @@ xga_readl_linear(uint32_t addr, void *priv) if (!xga->on) return svga_readl_linear(addr, svga); - ret = xga_read_linear(addr, svga); - ret |= (xga_read_linear(addr + 1, svga) << 8); - ret |= (xga_read_linear(addr + 2, svga) << 16); - ret |= (xga_read_linear(addr + 3, svga) << 24); + ret = xga_readw_linear(addr, svga); + ret |= (xga_readw_linear(addr + 2, svga) << 16); return ret; } @@ -3557,6 +3407,8 @@ xga_mca_write(int port, uint8_t val, void *priv) 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); + if (!xga->base_addr_1mb) + xga->pos_regs[4] |= 1; /*If 1MB VRAM aperture is disabled on MCA, enable the 4MB VRAM aperture instead.*/ io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga);