📄 vgacard.java
字号:
/* JPC: A x86 PC Hardware Emulator for a pure Java Virtual Machine Release Version 2.0 A project from the Physics Dept, The University of Oxford Copyright (C) 2007 Isis Innovation Limited This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Details (including contact information) can be found at: www.physics.ox.ac.uk/jpc*/package org.jpc.emulator.pci.peripheral;import org.jpc.emulator.pci.*;import org.jpc.emulator.motherboard.*;import org.jpc.emulator.memory.*;import org.jpc.emulator.memory.codeblock.*;import org.jpc.emulator.processor.Processor;import org.jpc.support.*;import org.jpc.emulator.*;import java.util.*;import java.io.*;public class VGACard extends AbstractPCIDevice implements IOPortCapable, HardwareComponent{ //VGA_RAM_SIZE must be a power of two private static final int VGA_RAM_SIZE = 4096 * 1024; private static final int INIT_VGA_RAM_SIZE = 64 * 1024; private static final int PAGE_SHIFT = 12; private final int[] expand4 = new int[256]; private final int[] expand2 = new int[256]; private final int[] expand4to8 = new int[16]; private static final int MOR_COLOR_EMULATION = 0x01; private static final int ST01_V_RETRACE = 0x08; private static final int ST01_DISP_ENABLE = 0x01; private static final int VBE_DISPI_MAX_XRES = 1024; private static final int VBE_DISPI_MAX_YRES = 768; private static final int VBE_DISPI_INDEX_ID = 0x0; private static final int VBE_DISPI_INDEX_XRES = 0x1; private static final int VBE_DISPI_INDEX_YRES = 0x2; private static final int VBE_DISPI_INDEX_BPP = 0x3; private static final int VBE_DISPI_INDEX_ENABLE = 0x4; private static final int VBE_DISPI_INDEX_BANK = 0x5; private static final int VBE_DISPI_INDEX_VIRT_WIDTH = 0x6; private static final int VBE_DISPI_INDEX_VIRT_HEIGHT = 0x7; private static final int VBE_DISPI_INDEX_X_OFFSET = 0x8; private static final int VBE_DISPI_INDEX_Y_OFFSET = 0x9; private static final int VBE_DISPI_INDEX_NB = 0xa; private static final int VBE_DISPI_ID0 = 0xB0C0; private static final int VBE_DISPI_ID1 = 0xB0C1; private static final int VBE_DISPI_ID2 = 0xB0C2; private static final int VBE_DISPI_DISABLED = 0x00; private static final int VBE_DISPI_ENABLED = 0x01; private static final int VBE_DISPI_LFB_ENABLED = 0x40; private static final int VBE_DISPI_NOCLEARMEM = 0x80; private static final int VBE_DISPI_LFB_PHYSICAL_ADDRESS = 0xE0000000; private static final int GMODE_TEXT = 0; private static final int GMODE_GRAPH = 1; private static final int GMODE_BLANK = 2; private static final int CH_ATTR_SIZE = (160 * 100); private static final int VGA_MAX_HEIGHT = 1024; private static final int GR_INDEX_SETRESET = 0x00; private static final int GR_INDEX_ENABLE_SETRESET = 0x01; private static final int GR_INDEX_COLOR_COMPARE = 0x02; private static final int GR_INDEX_DATA_ROTATE = 0x03; private static final int GR_INDEX_READ_MAP_SELECT = 0x04; private static final int GR_INDEX_GRAPHICS_MODE = 0x05; private static final int GR_INDEX_MISC = 0x06; private static final int GR_INDEX_COLOR_DONT_CARE = 0x07; private static final int GR_INDEX_BITMASK = 0x08; private static final int SR_INDEX_RESET = 0x00; private static final int SR_INDEX_CLOCKING_MODE = 0x01; private static final int SR_INDEX_MAP_MASK = 0x02; private static final int SR_INDEX_CHAR_MAP_SELECT = 0x03; private static final int SR_INDEX_SEQ_MEMORY_MODE = 0x04; private static final int AR_INDEX_PALLETE_MIN = 0x00; private static final int AR_INDEX_PALLETE_MAX = 0x0F; private static final int AR_INDEX_ATTR_MODE_CONTROL = 0x10; private static final int AR_INDEX_OVERSCAN_COLOR = 0x11; private static final int AR_INDEX_COLOR_PLANE_ENABLE = 0x12; private static final int AR_INDEX_HORIZ_PIXEL_PANNING = 0x13; private static final int AR_INDEX_COLOR_SELECT = 0x14; private static final int CR_INDEX_HORZ_DISPLAY_END = 0x01; private static final int CR_INDEX_VERT_TOTAL = 0x06; private static final int CR_INDEX_OVERFLOW = 0x07; private static final int CR_INDEX_MAX_SCANLINE = 0x09; private static final int CR_INDEX_CURSOR_START = 0x0a; private static final int CR_INDEX_CURSOR_END = 0x0b; private static final int CR_INDEX_START_ADDR_HIGH = 0x0c; private static final int CR_INDEX_START_ADDR_LOW = 0x0d; private static final int CR_INDEX_CURSOR_LOC_HIGH = 0x0e; private static final int CR_INDEX_CURSOR_LOC_LOW = 0x0f; private static final int CR_INDEX_VERT_RETRACE_END = 0x11; private static final int CR_INDEX_VERT_DISPLAY_END = 0x12; private static final int CR_INDEX_OFFSET = 0x13; private static final int CR_INDEX_CRTC_MODE_CONTROL = 0x17; private static final int CR_INDEX_LINE_COMPARE = 0x18; private static final int[] sequencerRegisterMask = new int[]{ 0x03, //~0xfc, 0x3d, //~0xc2, 0x0f, //~0xf0, 0x3f, //~0xc0, 0x0e, //~0xf1, 0x00, //~0xff, 0x00, //~0xff, 0xff //~0x00 }; private static final int[] graphicsRegisterMask = new int[]{ 0x0f, //~0xf0 0x0f, //~0xf0 0x0f, //~0xf0 0x1f, //~0xe0 0x03, //~0xfc 0x7b, //~0x84 0x0f, //~0xf0 0x0f, //~0xf0 0xff, //~0x00 0x00, //~0xff 0x00, //~0xff 0x00, //~0xff 0x00, //~0xff 0x00, //~0xff 0x00, //~0xff 0x00 //~0xff }; private static final int[] mask16 = new int[]{ 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff }; private static final int[] dmask16 = new int[]{ 0x00000000, 0xff000000, 0x00ff0000, 0xffff0000, 0x0000ff00, 0xff00ff00, 0x00ffff00, 0xffffff00, 0x000000ff, 0xff0000ff, 0x00ff00ff, 0xffff00ff, 0x0000ffff, 0xff00ffff, 0x00ffffff, 0xffffffff }; private static final int[] dmask4 = new int[]{ 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff }; private static final int[] cursorGlyph = new int[]{ 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; private GraphicsUpdater VGA_DRAW_LINE2; private GraphicsUpdater VGA_DRAW_LINE2D2; private GraphicsUpdater VGA_DRAW_LINE4; private GraphicsUpdater VGA_DRAW_LINE4D2; private GraphicsUpdater VGA_DRAW_LINE8D2; private GraphicsUpdater VGA_DRAW_LINE8; private GraphicsUpdater VGA_DRAW_LINE15; private GraphicsUpdater VGA_DRAW_LINE16; private GraphicsUpdater VGA_DRAW_LINE24; private GraphicsUpdater VGA_DRAW_LINE32; private int latch; private int sequencerRegisterIndex, graphicsRegisterIndex, attributeRegisterIndex, crtRegisterIndex; private int[] sequencerRegister, graphicsRegister, attributeRegister, crtRegister; //private int[] invalidatedYTable; private boolean attributeRegisterFlipFlop; private int miscellaneousOutputRegister; private int featureControlRegister; private int st00, st01; // status 0 and 1 private int dacReadIndex, dacWriteIndex, dacSubIndex, dacState; private int shiftControl, doubleScan; private int[] dacCache; private int[] palette; private int bankOffset; private int vbeIndex; private int[] vbeRegs; private int vbeStartAddress; private int vbeLineOffset; private int vbeBankMask; private int[] fontOffset; private int graphicMode; private int lineOffset; private int lineCompare; private int startAddress; private int planeUpdated; private int lastCW, lastCH; private int lastWidth, lastHeight; private int lastScreenWidth, lastScreenHeight; private int cursorStart, cursorEnd; private int cursorOffset; private final int[] lastPalette; private int[] lastChar; private boolean ioportRegistered; private boolean pciRegistered; private boolean memoryRegistered; private boolean updatingScreen; private VGARAMIORegion ioRegion; private VGALowMemoryRegion lowIORegion; public VGACard() { ioportRegistered = false; memoryRegistered = false; pciRegistered = false; setupArrays(); setupGraphicsModes(); assignDevFN(-1); setIRQIndex(16); putConfigByte(0x00, (byte)0x34); // dummy VGA (same as Bochs ID) putConfigByte(0x01, (byte)0x12); putConfigByte(0x02, (byte)0x11); putConfigByte(0x03, (byte)0x11); putConfigByte(0x0a, (byte)0x00); // VGA Controller putConfigByte(0x0b, (byte)0x03); putConfigByte(0x0e, (byte)0x00); // header_type sequencerRegister = new int[256]; graphicsRegister = new int[256]; attributeRegister = new int[256]; crtRegister = new int[256]; //invalidatedYTable = new int[VGA_MAX_HEIGHT / 32]; dacCache = new int[3]; palette = new int[768]; ioRegion = new VGARAMIORegion(); lowIORegion = new VGALowMemoryRegion(); vbeRegs = new int[VBE_DISPI_INDEX_NB]; fontOffset = new int[2]; lastPalette = new int[256]; lastChar = new int[CH_ATTR_SIZE]; this.internalReset(); bankOffset = 0; vbeRegs[VBE_DISPI_INDEX_ID] = VBE_DISPI_ID0; vbeBankMask = ((VGA_RAM_SIZE >>> 16) - 1); } public void dumpState(DataOutput output) throws IOException { super.dumpState(output); output.writeInt(expand4.length); for (int i = 0; i< expand4.length; i++) output.writeInt(expand4[i]); output.writeInt(expand2.length); for (int i = 0; i< expand2.length; i++) output.writeInt(expand2[i]); output.writeInt(expand4to8.length); for (int i = 0; i< expand4to8.length; i++) output.writeInt(expand4to8[i]); output.writeInt(latch); output.writeInt(sequencerRegisterIndex); output.writeInt(graphicsRegisterIndex); output.writeInt(attributeRegisterIndex); output.writeInt(crtRegisterIndex); output.writeInt(sequencerRegister.length); for (int i = 0; i< sequencerRegister.length; i++) output.writeInt(sequencerRegister[i]); output.writeInt(graphicsRegister.length); for (int i = 0; i< graphicsRegister.length; i++) output.writeInt(graphicsRegister[i]); output.writeInt(attributeRegister.length); for (int i = 0; i< attributeRegister.length; i++) output.writeInt(attributeRegister[i]); output.writeInt(crtRegister.length); for (int i = 0; i< crtRegister.length; i++) output.writeInt(crtRegister[i]); output.writeBoolean(attributeRegisterFlipFlop); output.writeInt(miscellaneousOutputRegister); output.writeInt(featureControlRegister); output.writeInt(st00); output.writeInt(st01); output.writeInt(dacReadIndex); output.writeInt(dacWriteIndex); output.writeInt(dacSubIndex); output.writeInt(dacState); output.writeInt(shiftControl); output.writeInt(doubleScan); output.writeInt(dacCache.length); for (int i = 0; i< dacCache.length; i++) output.writeInt(dacCache[i]); output.writeInt(palette.length); for (int i = 0; i< palette.length; i++) output.writeInt(palette[i]); output.writeInt(bankOffset); output.writeInt(vbeIndex); output.writeInt(vbeRegs.length); for (int i = 0; i< vbeRegs.length; i++) output.writeInt(vbeRegs[i]); output.writeInt(vbeStartAddress); output.writeInt(vbeLineOffset); output.writeInt(vbeBankMask); output.writeInt(fontOffset.length); for (int i = 0; i< fontOffset.length; i++) output.writeInt(fontOffset[i]); output.writeInt(graphicMode); output.writeInt(lineOffset); output.writeInt(lineCompare); output.writeInt(startAddress); output.writeInt(planeUpdated); output.writeInt(lastCW); output.writeInt(lastCH); output.writeInt(lastWidth); output.writeInt(lastHeight); output.writeInt(lastScreenWidth); output.writeInt(lastScreenHeight); output.writeInt(cursorStart); output.writeInt(cursorEnd); output.writeInt(cursorOffset); output.writeInt(lastPalette.length); for (int i = 0; i< lastPalette.length; i++) output.writeInt(lastPalette[i]); output.writeInt(lastChar.length); for (int i = 0; i< lastChar.length; i++) output.writeInt(lastChar[i]); output.writeBoolean(updatingScreen); //dump ioregion ioRegion.dumpState(output); //dump graphics updaters VGA_DRAW_LINE2.dumpState(output); VGA_DRAW_LINE2D2.dumpState(output); VGA_DRAW_LINE4.dumpState(output); VGA_DRAW_LINE4D2.dumpState(output); VGA_DRAW_LINE8D2.dumpState(output); VGA_DRAW_LINE8.dumpState(output); VGA_DRAW_LINE15.dumpState(output); VGA_DRAW_LINE16.dumpState(output); VGA_DRAW_LINE24.dumpState(output); VGA_DRAW_LINE32.dumpState(output); } public void loadState(DataInput input) throws IOException { super.loadState(input); ioportRegistered =false; pciRegistered = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -