OpenCores
no use no use 1/1 no use no use
[or1ksim #23] Cleanup VGA peripheral
by Unknown on Feb 4, 2005
Not available!
Hi, Changelog says it all. ChangeLog: * Cleanup VGA peripheral useing the new callbacks. nog. -------------- next part -------------- --- peripheral/vga.c 2005-02-04 12:18:46.000000000 +0100 +++ ../or1ksim-ac/peripheral/vga.c 2005-02-04 15:41:08.000000000 +0100 @@ -34,7 +34,7 @@ #include "sched.h" /* When this counter reaches config.vgas[].refresh_rate, a screenshot is taken and outputted */ -static struct { +struct vga_state { int pics; unsigned long ctrl, stat, htim, vtim; int vbindex; @@ -42,45 +42,35 @@ unsigned hlen, vlen; int pindex; unsigned long palette[2][256]; -} vga[MAX_VGAS]; + oraddr_t baseaddr; + int refresh_rate; + int irq; + char *filename; +}; /* Write a register */ void vga_write32(oraddr_t addr, uint32_t value, void *dat) { - int i, found = -1; + struct vga_state *vga = dat; - /* Find which controller this is */ - for (i = 0; i = config.vgas.baseaddr) && (addr baseaddr; switch (addr) { - case VGA_CTRL: vga[found].ctrl = value; break; - case VGA_STAT: vga[found].stat = value; break; - case VGA_HTIM: vga[found].htim = value; break; - case VGA_VTIM: vga[found].vtim = value; break; - case VGA_HVLEN: vga[found].hlen = (value >> 16) + 2; vga[found].hlen = (value & 0xffff) + 2; break; - case VGA_VBARA: vga[found].vbar[0] = value; break; - case VGA_VBARB: vga[found].vbar[1] = value; break; + case VGA_CTRL: vga->ctrl = value; break; + case VGA_STAT: vga->stat = value; break; + case VGA_HTIM: vga->htim = value; break; + case VGA_VTIM: vga->vtim = value; break; + case VGA_HVLEN: vga->hlen = (value >> 16) + 2; vga->hlen = (value & 0xffff) + 2; break; + case VGA_VBARA: vga->vbar[0] = value; break; + case VGA_VBARB: vga->vbar[1] = value; break; default: if (addr >= VGA_CLUTA && addr palette[0][addr - VGA_CLUTA] = value & 0x00ffffff; } else if (addr >= VGA_CLUTB) { - vga[found].palette[1][addr - VGA_CLUTB] = value & 0x00ffffff; + vga->palette[1][addr - VGA_CLUTB] = value & 0x00ffffff; } else { - fprintf( stderr, "vga_write32( 0x%"PRIxADDR", 0x%08"PRIx32" ): Out of range\n", addr + config.vgas[found].baseaddr, value); + fprintf( stderr, "vga_write32( 0x%"PRIxADDR", 0x%08"PRIx32" ): Out of range\n", addr + vga->baseaddr, value); runtime.sim.cont_run = 0; return; } @@ -91,37 +81,23 @@ /* Read a register */ uint32_t vga_read32(oraddr_t addr, void *dat) { - int i, found = -1; - - /* Find which controller this is */ - for (i = 0; i = config.vgas.baseaddr) && (addr baseaddr; switch (addr) { - case VGA_CTRL: return vga[found].ctrl; - case VGA_STAT: return vga[found].stat; - case VGA_HTIM: return vga[found].htim; - case VGA_VTIM: return vga[found].vtim; - case VGA_HVLEN: return ((vga[found].hlen - 2) ctrl; + case VGA_STAT: return vga->stat; + case VGA_HTIM: return vga->htim; + case VGA_VTIM: return vga->vtim; + case VGA_HVLEN: return ((vga->hlen - 2) vlen - 2); + case VGA_VBARA: return vga->vbar[0]; + case VGA_VBARB: return vga->vbar[1]; default: if (addr >= VGA_CLUTA && addr palette[0][addr - VGA_CLUTA]; } else if (addr >= VGA_CLUTB) { - return vga[found].palette[1][addr - VGA_CLUTB]; + return vga->palette[1][addr - VGA_CLUTB]; } else { fprintf( stderr, "vga_read32( 0x%"PRIxADDR" ): Out of range\n", addr); runtime.sim.cont_run = 0; @@ -136,7 +112,7 @@ #ifdef __BIG_ENDIAN__ #warning Image dump not supported on big endian machines -static int vga_dump_image (char *filename, int v) +static int vga_dump_image (char *filename, struct vga_start *vga) { return 1; } @@ -164,20 +140,20 @@ /* Dumps a bmp file, based on current image */ -static int vga_dump_image (char *filename, int v) +static int vga_dump_image (char *filename, struct vga_state *vga) { - int sx = vga[v].hlen; - int sy = vga[v].vlen; + int sx = vga->hlen; + int sy = vga->vlen; int i, x, y; - int pc = vga[v].ctrl & VGA_CTRL_PC; - int rbpp = vga[v].ctrl & VGA_CTRL_CD; + int pc = vga->ctrl & VGA_CTRL_PC; + int rbpp = vga->ctrl & VGA_CTRL_CD; int bpp = rbpp >> 8; BMP_HEADER bh; INFOHEADER ih; FILE *fo; - if (!sx || !sy) return; + if (!sx || !sy) return 1; /* 16bpp and 32 bpp will be converted to 24bpp */ if (bpp == 1 || bpp == 3) bpp = 2; @@ -202,7 +178,7 @@ if (pc) { /* Write palette? */ for (i = 0; i palette[vga->pindex]; val = (d >> 0) & 0xff; /* Blue */ val |= (d >> 8) & 0xff; /* Green */ val |= (d >> 16) & 0xff; /* Red */ @@ -215,7 +191,7 @@ int align = 4 - ((bpp + 1) * sx) % 4; int zero = 0; for (x = 0; x vbar[vga->vbindex] + (y * sx + x) * (bpp + 1)); if (!fwrite (&pixel, sizeof (pixel), 1, fo)) return 1; } if (!fwrite (&zero, align, 1, fo)) return 1; @@ -226,92 +202,96 @@ } #endif /* !__BIG_ENDIAN__ */ -void vga_job (int param) +void vga_job (void *dat) { + struct vga_state *vga = dat; /* dump the image? */ char temp[STR_SIZE]; - sprintf (temp, "%s%04i.bmp", config.vgas[param].filename, vga[param].pics++); - vga_dump_image (temp, param); + sprintf (temp, "%s%04i.bmp", vga->filename, vga->pics++); + vga_dump_image (temp, vga); - SCHED_ADD(vga_job, param, runtime.sim.cycles + config.vgas[param].refresh_rate); + SCHED_ADD(vga_job, dat, runtime.sim.cycles + vga->refresh_rate); } /* Reset all VGAs */ -void vga_reset () +void vga_reset (void *dat) { - int i, j; - for (i = 0; i = 0 && val.int_val palette[0] = vga->palette[1] = 0; + + vga->ctrl = vga->stat = vga->htim = vga->vtim = 0; + vga->hlen = vga->vlen = 0; + vga->vbar[0] = vga->vbar[1] = 0; + + /* Init screen dumping machine */ + vga->pics = 0; + + vga->pindex = 0; + vga->vbindex = 0; + + SCHED_ADD(vga_job, dat, runtime.sim.cycles + vga->refresh_rate); } +/*----------------------------------------------------[ VGA Configuration ]---*/ void vga_baseaddr(union param_val val, void *dat) { - if (current_device >= 0 && current_device baseaddr = val.addr_val; } void vga_irq(union param_val val, void *dat) { - if (current_device >= 0 && current_device irq = val.int_val; } void vga_refresh_rate(union param_val val, void *dat) { - if (current_device >= 0 && current_device refresh_rate = val.int_val; } void vga_filename(union param_val val, void *dat) { - if (current_device >= 0 && current_device filename = strdup (val.str_val))); +} + +void *vga_sec_start(void) +{ + struct vga_state *new = malloc(sizeof(struct vga_state)); + + if(!new) { + fprintf(stderr, "Peripheral VGA: Run out of memory\n"); + exit(-1); + } + + new->baseaddr = 0; + + return new; +} + +void vga_sec_end(void *dat) +{ + struct vga_state *vga = dat; + + if (vga->baseaddr) + register_memoryarea(vga->baseaddr, VGA_ADDR_SPACE, 4, 0, vga_read32, vga_write32, dat); + + reg_sim_reset(vga_reset, dat); } void reg_vga_sec(void) { - struct config_section *sec = reg_config_sec("vga", NULL, NULL); + struct config_section *sec = reg_config_sec("vga", vga_sec_start, vga_sec_end); - reg_config_param(sec, "nvgas", paramt_int, vga_nvgas); - reg_config_param(sec, "device", paramt_int, change_device); reg_config_param(sec, "baseaddr", paramt_addr, vga_baseaddr); reg_config_param(sec, "irq", paramt_int, vga_irq); reg_config_param(sec, "refresh_rate", paramt_int, vga_refresh_rate); reg_config_param(sec, "filename", paramt_str, vga_filename); - reg_config_param(sec, "enddevice", paramt_none, end_device); } --- peripheral/vga.h 2002-04-10 09:10:30.000000000 +0200 +++ ../or1ksim-ac/peripheral/vga.h 2005-02-04 15:34:53.000000000 +0100 @@ -47,7 +47,4 @@ /* Vert. Timing Register */ /* Horiz. and Vert. Length Register */ -/* Reset all VGAs */ -void vga_reset (); - #endif /* _VGA_H_ */ --- sim-config.c 2005-02-04 15:48:19.000000000 +0100 +++ ../or1ksim-ac/sim-config.c 2005-02-04 15:39:29.000000000 +0100 @@ -127,9 +129,6 @@ /* DMAs */ config.ndmas = 0; - /* VGAs */ - config.nvgas = 0; - /* Frame buffer */ config.fb.enabled = 0; --- sim-config.h 2005-02-04 15:48:19.000000000 +0100 +++ ../or1ksim-ac/sim-config.h 2005-02-04 15:50:46.000000000 +0100 @@ -28,7 +28,6 @@ #define MAX_ETHERNETS 4 /* Max. number of Ethernet MACs */ #define MAX_GPIOS 4 /* Max. number of GPIO modules */ #define MAX_MEMORIES 16 /* Max. number of memory devices attached */ -#define MAX_VGAS 4 /* Max. number of VGAs */ #define MAX_ATAS 4 /* Max. number of ATAS */ #define MAX_SBUF_LEN 256 /* Max. length of store buffer */ @@ -71,14 +70,6 @@ unsigned long base_vapi_id; /* First VAPI ID. GPIO uses 8 consecutive IDs */ } gpios[MAX_GPIOS]; - int nvgas; - struct { - unsigned long baseaddr; /* Base address */ - int irq; /* IRQ of this device */ - int refresh_rate; /* Number of clocks per refresh */ - char filename[STR_SIZE]; /* Base file name; suffix of ####.bmp is added */ - } vgas[MAX_VGAS]; - struct { int enabled; /* Whether frame buffer is enabled */ unsigned long baseaddr; /* Base address of frame buffer register */ --- sim.cfg 2005-02-04 15:48:19.000000000 +0100 +++ ../or1ksim-ac/sim.cfg 2005-02-04 15:40:01.000000000 +0100 @@ -761,10 +761,6 @@ This section configures the VGA/LCD controller - nvgas = - number of VGA devices connected - - instance specific: baseaddr = address of first VGA register @@ -779,14 +775,10 @@ */ section vga - nvgas = 1 - - device 0 - baseaddr = 0x97100000 - irq = 8 - refresh_rate = 100000 - filename = "primary" - enddevice + baseaddr = 0x97100000 + irq = 8 + refresh_rate = 100000 + filename = "primary" end --- toplevel.c 2005-02-04 15:55:48.000000000 +0100 +++ ../or1ksim-ac/toplevel.c 2005-02-04 15:54:32.000000000 +0100 @@ -48,7 +48,6 @@ #include "spr_defs.h" #include "sprs.h" #include "dma.h" -#include "vga.h" #include "fb.h" #include "ps2kbd.h" #include "vapi.h" @@ -174,7 +173,6 @@ dma_reset(); eth_reset(); gpio_reset(); - vga_reset (); fb_reset (); kbd_reset (); tick_reset();
no use no use 1/1 no use no use
© copyright 1999-2026 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.