?? vga.c
字號:
return; s->vbe_regs[VBE_DISPI_INDEX_VIRT_WIDTH] = w; s->vbe_regs[VBE_DISPI_INDEX_VIRT_HEIGHT] = h; s->vbe_line_offset = line_offset; } break; case VBE_DISPI_INDEX_X_OFFSET: case VBE_DISPI_INDEX_Y_OFFSET: { int x; s->vbe_regs[s->vbe_index] = val; s->vbe_start_addr = s->vbe_line_offset * s->vbe_regs[VBE_DISPI_INDEX_Y_OFFSET]; x = s->vbe_regs[VBE_DISPI_INDEX_X_OFFSET]; if (s->vbe_regs[VBE_DISPI_INDEX_BPP] == 4) s->vbe_start_addr += x >> 1; else s->vbe_start_addr += x * ((s->vbe_regs[VBE_DISPI_INDEX_BPP] + 7) >> 3); s->vbe_start_addr >>= 2; } break; default: break; } }}#endif/* called for accesses between 0xa0000 and 0xc0000 */uint32_t vga_mem_readb(void *opaque, target_phys_addr_t addr){ VGAState *s = opaque; int memory_map_mode, plane; uint32_t ret; /* convert to VGA memory offset */ memory_map_mode = (s->gr[6] >> 2) & 3; addr &= 0x1ffff; switch(memory_map_mode) { case 0: break; case 1: if (addr >= 0x10000) return 0xff; addr += s->bank_offset; break; case 2: addr -= 0x10000; if (addr >= 0x8000) return 0xff; break; default: case 3: addr -= 0x18000; if (addr >= 0x8000) return 0xff; break; } if (s->sr[4] & 0x08) { /* chain 4 mode : simplest access */ ret = s->vram_ptr[addr]; } else if (s->gr[5] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane = (s->gr[4] & 2) | (addr & 1); ret = s->vram_ptr[((addr & ~1) << 1) | plane]; } else { /* standard VGA latched access */ s->latch = ((uint32_t *)s->vram_ptr)[addr]; if (!(s->gr[5] & 0x08)) { /* read mode 0 */ plane = s->gr[4]; ret = GET_PLANE(s->latch, plane); } else { /* read mode 1 */ ret = (s->latch ^ mask16[s->gr[2]]) & mask16[s->gr[7]]; ret |= ret >> 16; ret |= ret >> 8; ret = (~ret) & 0xff; } } return ret;}static uint32_t vga_mem_readw(void *opaque, target_phys_addr_t addr){ uint32_t v;#ifdef TARGET_WORDS_BIGENDIAN v = vga_mem_readb(opaque, addr) << 8; v |= vga_mem_readb(opaque, addr + 1);#else v = vga_mem_readb(opaque, addr); v |= vga_mem_readb(opaque, addr + 1) << 8;#endif return v;}static uint32_t vga_mem_readl(void *opaque, target_phys_addr_t addr){ uint32_t v;#ifdef TARGET_WORDS_BIGENDIAN v = vga_mem_readb(opaque, addr) << 24; v |= vga_mem_readb(opaque, addr + 1) << 16; v |= vga_mem_readb(opaque, addr + 2) << 8; v |= vga_mem_readb(opaque, addr + 3);#else v = vga_mem_readb(opaque, addr); v |= vga_mem_readb(opaque, addr + 1) << 8; v |= vga_mem_readb(opaque, addr + 2) << 16; v |= vga_mem_readb(opaque, addr + 3) << 24;#endif return v;}/* called for accesses between 0xa0000 and 0xc0000 */void vga_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val){ VGAState *s = opaque; int memory_map_mode, plane, write_mode, b, func_select, mask; uint32_t write_mask, bit_mask, set_mask;#ifdef DEBUG_VGA_MEM printf("vga: [0x%x] = 0x%02x\n", addr, val);#endif /* convert to VGA memory offset */ memory_map_mode = (s->gr[6] >> 2) & 3; addr &= 0x1ffff; switch(memory_map_mode) { case 0: break; case 1: if (addr >= 0x10000) return; addr += s->bank_offset; break; case 2: addr -= 0x10000; if (addr >= 0x8000) return; break; default: case 3: addr -= 0x18000; if (addr >= 0x8000) return; break; } if (s->sr[4] & 0x08) { /* chain 4 mode : simplest access */ plane = addr & 3; mask = (1 << plane); if (s->sr[2] & mask) { s->vram_ptr[addr] = val;#ifdef DEBUG_VGA_MEM printf("vga: chain4: [0x%x]\n", addr);#endif s->plane_updated |= mask; /* only used to detect font change */ cpu_physical_memory_set_dirty(s->vram_offset + addr); } } else if (s->gr[5] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane = (s->gr[4] & 2) | (addr & 1); mask = (1 << plane); if (s->sr[2] & mask) { addr = ((addr & ~1) << 1) | plane; s->vram_ptr[addr] = val;#ifdef DEBUG_VGA_MEM printf("vga: odd/even: [0x%x]\n", addr);#endif s->plane_updated |= mask; /* only used to detect font change */ cpu_physical_memory_set_dirty(s->vram_offset + addr); } } else { /* standard VGA latched access */ write_mode = s->gr[5] & 3; switch(write_mode) { default: case 0: /* rotate */ b = s->gr[3] & 7; val = ((val >> b) | (val << (8 - b))) & 0xff; val |= val << 8; val |= val << 16; /* apply set/reset mask */ set_mask = mask16[s->gr[1]]; val = (val & ~set_mask) | (mask16[s->gr[0]] & set_mask); bit_mask = s->gr[8]; break; case 1: val = s->latch; goto do_write; case 2: val = mask16[val & 0x0f]; bit_mask = s->gr[8]; break; case 3: /* rotate */ b = s->gr[3] & 7; val = (val >> b) | (val << (8 - b)); bit_mask = s->gr[8] & val; val = mask16[s->gr[0]]; break; } /* apply logical operation */ func_select = s->gr[3] >> 3; switch(func_select) { case 0: default: /* nothing to do */ break; case 1: /* and */ val &= s->latch; break; case 2: /* or */ val |= s->latch; break; case 3: /* xor */ val ^= s->latch; break; } /* apply bit mask */ bit_mask |= bit_mask << 8; bit_mask |= bit_mask << 16; val = (val & bit_mask) | (s->latch & ~bit_mask); do_write: /* mask data according to sr[2] */ mask = s->sr[2]; s->plane_updated |= mask; /* only used to detect font change */ write_mask = mask16[mask]; ((uint32_t *)s->vram_ptr)[addr] = (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | (val & write_mask);#ifdef DEBUG_VGA_MEM printf("vga: latch: [0x%x] mask=0x%08x val=0x%08x\n", addr * 4, write_mask, val);#endif cpu_physical_memory_set_dirty(s->vram_offset + (addr << 2)); }}static void vga_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val){#ifdef TARGET_WORDS_BIGENDIAN vga_mem_writeb(opaque, addr, (val >> 8) & 0xff); vga_mem_writeb(opaque, addr + 1, val & 0xff);#else vga_mem_writeb(opaque, addr, val & 0xff); vga_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);#endif}static void vga_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val){#ifdef TARGET_WORDS_BIGENDIAN vga_mem_writeb(opaque, addr, (val >> 24) & 0xff); vga_mem_writeb(opaque, addr + 1, (val >> 16) & 0xff); vga_mem_writeb(opaque, addr + 2, (val >> 8) & 0xff); vga_mem_writeb(opaque, addr + 3, val & 0xff);#else vga_mem_writeb(opaque, addr, val & 0xff); vga_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff); vga_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff); vga_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff);#endif}typedef void vga_draw_glyph8_func(uint8_t *d, int linesize, const uint8_t *font_ptr, int h, uint32_t fgcol, uint32_t bgcol);typedef void vga_draw_glyph9_func(uint8_t *d, int linesize, const uint8_t *font_ptr, int h, uint32_t fgcol, uint32_t bgcol, int dup9);typedef void vga_draw_line_func(VGAState *s1, uint8_t *d, const uint8_t *s, int width);#define DEPTH 8#include "vga_template.h"#define DEPTH 15#include "vga_template.h"#define BGR_FORMAT#define DEPTH 15#include "vga_template.h"#define DEPTH 16#include "vga_template.h"#define BGR_FORMAT#define DEPTH 16#include "vga_template.h"#define DEPTH 32#include "vga_template.h"#define BGR_FORMAT#define DEPTH 32#include "vga_template.h"static unsigned int rgb_to_pixel8_dup(unsigned int r, unsigned int g, unsigned b){ unsigned int col; col = rgb_to_pixel8(r, g, b); col |= col << 8; col |= col << 16; return col;}static unsigned int rgb_to_pixel15_dup(unsigned int r, unsigned int g, unsigned b){ unsigned int col; col = rgb_to_pixel15(r, g, b); col |= col << 16; return col;}static unsigned int rgb_to_pixel15bgr_dup(unsigned int r, unsigned int g, unsigned int b){ unsigned int col; col = rgb_to_pixel15bgr(r, g, b); col |= col << 16; return col;}static unsigned int rgb_to_pixel16_dup(unsigned int r, unsigned int g, unsigned b){ unsigned int col; col = rgb_to_pixel16(r, g, b); col |= col << 16; return col;}static unsigned int rgb_to_pixel16bgr_dup(unsigned int r, unsigned int g, unsigned int b){ unsigned int col; col = rgb_to_pixel16bgr(r, g, b); col |= col << 16; return col;}static unsigned int rgb_to_pixel32_dup(unsigned int r, unsigned int g, unsigned b){ unsigned int col; col = rgb_to_pixel32(r, g, b); return col;}static unsigned int rgb_to_pixel32bgr_dup(unsigned int r, unsigned int g, unsigned b){ unsigned int col; col = rgb_to_pixel32bgr(r, g, b); return col;}/* return true if the palette was modified */static int update_palette16(VGAState *s){ int full_update, i; uint32_t v, col, *palette; full_update = 0; palette = s->last_palette; for(i = 0; i < 16; i++) { v = s->ar[i]; if (s->ar[0x10] & 0x80) v = ((s->ar[0x14] & 0xf) << 4) | (v & 0xf); else v = ((s->ar[0x14] & 0xc) << 4) | (v & 0x3f); v = v * 3; col = s->rgb_to_pixel(c6_to_8(s->palette[v]), c6_to_8(s->palette[v + 1]), c6_to_8(s->palette[v + 2])); if (col != palette[i]) { full_update = 1; palette[i] = col; } } return full_update;}/* return true if the palette was modified */static int update_palette256(VGAState *s){ int full_update, i; uint32_t v, col, *palette; full_update = 0; palette = s->last_palette; v = 0; for(i = 0; i < 256; i++) { if (s->dac_8bit) { col = s->rgb_to_pixel(s->palette[v], s->palette[v + 1], s->palette[v + 2]); } else { col = s->rgb_to_pixel(c6_to_8(s->palette[v]), c6_to_8(s->palette[v + 1]), c6_to_8(s->palette[v + 2])); } if (col != palette[i]) { full_update = 1; palette[i] = col; } v += 3; } return full_update;}static void vga_get_offsets(VGAState *s, uint32_t *pline_offset, uint32_t *pstart_addr, uint32_t *pline_compare){ uint32_t start_addr, line_offset, line_compare;#ifdef CONFIG_BOCHS_VBE if (s->vbe_regs[VBE_DISPI_INDEX_ENABLE] & VBE_DISPI_ENABLED) { line_offset = s->vbe_line_offset; start_addr = s->vbe_start_addr; line_compare = 65535; } else#endif { /* compute line_offset in bytes */ line_offset = s->cr[0x13]; line_offset <<= 3; /* starting address */ start_addr = s->cr[0x0d] | (s->cr[0x0c] << 8); /* line compare */ line_compare = s->cr[0x18] | ((s->cr[0x07] & 0x10) << 4) | ((s->cr[0x09] & 0x40) << 3); } *pline_offset = line_offset; *pstart_addr = start_addr; *pline_compare = line_compare;}/* update start_addr and line_offset. Return TRUE if modified */static int update_basic_params(VGAState *s){ int full_update; uint32_t start_addr, line_offset, line_compare; full_update = 0; s->get_offsets(s, &line_offset, &start_addr, &line_compare); if (line_offset != s->line_offset || start_addr != s->start_addr || line_compare != s->line_compare) { s->line_offset = line_offset; s->start_addr = start_addr; s->line_compare = line_compare; full_update = 1; } return full_update;}#define NB_DEPTHS 7static inline int get_depth_index(DisplayState *s){ switch(s->depth) { default: case 8: return 0; case 15: if (s->bgr) return 5; else return 1; case 16: if (s->bgr) return 6; else return 2; case 32: if (s->bgr) return 4; else return 3; }}static vga_draw_glyph8_func *vga_draw_glyph8_table[NB_DEPTHS] = { vga_draw_glyph8_8, vga_draw_glyph8_16, vga_draw_glyph8_16, vga_draw_glyph8_32, vga_draw_glyph8_32, vga_draw_glyph8_16, vga_draw_glyph8_16,};static vga_draw_glyph8_func *vga_draw_glyph16_table[NB_DEPTHS] = { vga_draw_glyph16_8, vga_draw_glyph16_16, vga_draw_glyph16_16, vga_draw_glyph16_32, vga_draw_glyph16_32, vga_draw_glyph16_16, vga_draw_glyph16_16,};static vga_draw_glyph9_func *vga_draw_glyph9_table[NB_DEPTHS] = { vga_draw_glyph9_8, vga_draw_glyph9_16, vga_draw_glyph9_16, vga_draw_glyph9_32, vga_draw_glyph9_32, vga_draw_glyph9_16, vga_draw_glyph9_16,};static const uint8_t cursor_glyph[32 * 4] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -