1/1

|
[or1ksim #24] Cleanup FB peripheral
by Unknown on Feb 4, 2005 |
Not available! | ||
|
Hi,
Changelog says it all.
ChangeLog:
* Cleanup FB peripheral, useing the new callbacks.
nog.
-------------- next part --------------
--- peripheral/fb.c 2005-02-04 15:55:35.000000000 +0100
+++ ../or1ksim-ac/peripheral/fb.c 2005-02-04 16:24:07.000000000 +0100
@@ -18,6 +18,7 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include
+#include
#include "config.h"
@@ -34,31 +35,42 @@
#define FB_WRAP (512*1024)
-static unsigned long pal[256];
-static int fb_ctrl = 0;
-static int fb_pic = 0;
-static int fb_in_refresh = 1;
-static int fb_refresh_count = 0;
-static oraddr_t fb_addr = 0;
-static oraddr_t cam_addr = 0;
-static int camerax = 0, cameray = 0, camera_pos = 0;
+struct fb_state {
+ unsigned long pal[256];
+ int ctrl;
+ int pic;
+ int in_refresh;
+ int refresh_count;
+ oraddr_t addr;
+ oraddr_t cam_addr;
+ int camerax;
+ int cameray;
+ int camera_pos;
+ oraddr_t baseaddr;
+ int refresh;
+ int refresh_rate;
+ char *filename;
+};
-static void change_buf_addr (oraddr_t addr)
+static void change_buf_addr (struct fb_state *fb, oraddr_t addr)
{
- fb_addr = addr;
+ fb->addr = addr;
}
/* Write a register */
void fb_write32 (oraddr_t addr, uint32_t value, void *dat)
{
- int a = (addr - config.fb.baseaddr);
+ struct fb_state *fb = dat;
+
+ oraddr_t a = (addr - fb->baseaddr);
+
switch (a) {
- case FB_CTRL: fb_ctrl = value; break;
- case FB_BUFADDR: change_buf_addr (value); break;
- case FB_CAMBUFADDR: cam_addr = value; break;
- case FB_CAMPOSADDR: camera_pos = value;
- camerax = value % FB_SIZEX;
- cameray = value / FB_SIZEX;
+ case FB_CTRL: fb->ctrl = value; break;
+ case FB_BUFADDR: change_buf_addr (fb, value); break;
+ case FB_CAMBUFADDR: fb->cam_addr = value; break;
+ case FB_CAMPOSADDR: fb->camera_pos = value;
+ fb->camerax = value % FB_SIZEX;
+ fb->cameray = value / FB_SIZEX;
break;
default:
a -= FB_PAL;
@@ -66,7 +78,7 @@
if (a = 256) {
fprintf (stderr, "Write out of palette buffer (0x%"PRIxADDR")!\n", addr);
runtime.sim.cont_run = 0;
- } else pal[a] = value;
+ } else fb->pal[a] = value;
break;
}
}
@@ -74,14 +86,17 @@
/* Read a register */
oraddr_t fb_read32 (oraddr_t addr, void *dat)
{
- int a = (addr - config.fb.baseaddr);
+ struct fb_state *fb = dat;
+
+ oraddr_t a = (addr - fb->baseaddr);
+
switch (a) {
case FB_CTRL:
- return fb_ctrl & ~0xff000000| (fb_in_refresh ? 0x80000000 : 0) | ((unsigned long)(fb_refresh_count & 0x7f) ctrl & ~0xff000000| (fb->in_refresh ? 0x80000000 : 0) | ((unsigned long)(fb->refresh_count & 0x7f) addr; break;
+ case FB_CAMBUFADDR: return fb->cam_addr; break;
+ case FB_CAMPOSADDR: return fb->camera_pos; break;
default:
a -= FB_PAL;
a /= 4;
@@ -89,7 +104,7 @@
fprintf (stderr, "Read out of palette buffer (0x%"PRIxADDR")!\n", addr);
runtime.sim.cont_run = 0;
return 0;
- } else return pal[a];
+ } else return fb->pal[a];
}
}
@@ -109,7 +124,7 @@
#endif
/* Dumps a bmp file, based on current image */
-static int fb_dump_image8 (char *filename)
+static int fb_dump_image8 (struct fb_state *fb, char *filename)
{
int sx = FB_SIZEX;
int sy = FB_SIZEY;
@@ -155,7 +170,7 @@
for (i = 0; i pal;
#if 1
val = ((d >> 0) & 0x1f) > 5) & 0x3f) addr & ~(FB_WRAP - 1)) | ((fb->addr + y * sx + x) & (FB_WRAP - 1));
fputc (evalsim_mem8 (add), fo);
}
if (align && !fwrite (&zero, align, 1, fo)) return 1;
@@ -186,7 +201,7 @@
}
/* Dumps a bmp file, based on current image */
-static int fb_dump_image24 (char *filename)
+static int fb_dump_image24 (struct fb_state *fb, char *filename)
{
int sx = FB_SIZEX;
int sy = FB_SIZEY;
@@ -235,15 +250,15 @@
for (y = sy - 1; y >= 0; y--) {
unsigned char line[FB_SIZEX][3];
for (x = 0; x = cameray && x >= camerax && y = fb->cameray && x >= fb->camerax && y cameray + CAM_SIZEY && x camerax + CAM_SIZEX) {
+ int add = (fb->cam_addr + (x - fb->camerax + (y - fb->cameray) * CAM_SIZEX) * 2) ^ 2;
unsigned short d = evalsim_mem16 (add);
line[x][0] = ((d >> 0) & 0x1f) > 5) & 0x3f) > 11) & 0x1f) addr & ~(FB_WRAP - 1)) | ((fb->addr + y * sx + x) & (FB_WRAP - 1));
+ unsigned short d = fb->pal[evalsim_mem8 (add)];
line[x][0] = ((d >> 0) & 0x1f) > 5) & 0x3f) > 11) & 0x1f) refresh) {
/* dump the image? */
- if (fb_ctrl & 1) {
+ if (fb->ctrl & 1) {
char temp[STR_SIZE];
- sprintf (temp, "%s%04i.bmp", &config.fb.filename[0], fb_pic);
- if (fb_ctrl & 2) fb_dump_image24 (temp);
- else fb_dump_image8 (temp);
- fb_pic++;
+ sprintf (temp, "%s%04i.bmp", fb->filename, fb->pic);
+ if (fb->ctrl & 2) fb_dump_image24 (fb, temp);
+ else fb_dump_image8 (fb, temp);
+ fb->pic++;
}
- SCHED_ADD(fb_job, 0, runtime.sim.cycles + config.fb.refresh_rate - config.fb.refresh_rate / REFRESH_DIVIDER);
- fb_in_refresh = 0;
+ SCHED_ADD(fb_job, dat, runtime.sim.cycles + fb->refresh_rate - fb->refresh_rate / REFRESH_DIVIDER);
+ fb->in_refresh = 0;
+ fb->refresh = 0;
} else {
- fb_refresh_count++;
- SCHED_ADD(fb_job, 1, runtime.sim.cycles + config.fb.refresh_rate / REFRESH_DIVIDER);
-
+ fb->refresh_count++;
+ fb->refresh = 1;
+ SCHED_ADD(fb_job, dat, runtime.sim.cycles + fb->refresh_rate / REFRESH_DIVIDER);
}
}
/* Reset all VGAs */
-void fb_reset ()
+void fb_reset (void *dat)
{
+ struct fb_state *fb = dat;
int i;
- if (config.fb.enabled) {
- fb_pic = 0;
- fb_addr = 0;
- fb_ctrl = 0;
-
- for (i = 0; i pic = 0;
+ fb->addr = 0;
+ fb->ctrl = 0;
-/*-----------------------------------------------------[ FB configuration ]---*/
-void fb_enabled(union param_val val, void *dat)
-{
- config.fb.enabled = val.int_val;
+ for (i = 0; i pal = (i refresh_rate);
+ fb->refresh = 0;
}
+/*-----------------------------------------------------[ FB configuration ]---*/
void fb_baseaddr(union param_val val, void *dat)
{
- config.fb.baseaddr = val.addr_val;
+ struct fb_state *fb = dat;
+ fb->baseaddr = val.addr_val;
}
void fb_refresh_rate(union param_val val, void *dat)
{
- config.fb.refresh_rate = val.int_val;
+ struct fb_state *fb = dat;
+ fb->refresh_rate = val.int_val;
}
void fb_filename(union param_val val, void *dat)
{
- strcpy(config.fb.filename, val.str_val);
+ struct fb_state *fb = dat;
+ if(!(fb->filename = strdup(val.str_val))) {
+ fprintf(stderr, "Peripheral FB: Run out of memory\n");
+ exit(-1);
+ }
+}
+
+void *fb_sec_start(void)
+{
+ struct fb_state *new = malloc(sizeof(struct fb_state));
+
+ if(!new) {
+ fprintf(stderr, "Peripheral FB: Run out of memory\n");
+ exit(-1);
+ }
+
+ new->baseaddr = 0;
+ new->ctrl = 0;
+ new->pic = 0;
+ new->in_refresh = 1;
+ new->refresh_count = 0;
+ new->addr = 0;
+ new->cam_addr = 0;
+ new->camerax = 0;
+ new->cameray = 0;
+ new->camera_pos = 0;
+
+ return new;
+}
+
+void fb_sec_end(void *dat)
+{
+ struct fb_state *fb = dat;
+
+ if (fb->baseaddr)
+ register_memoryarea(fb->baseaddr, FB_PAL + 256*4, 4, 0, fb_read32, fb_write32, dat);
+
+ reg_sim_reset(fb_reset, dat);
}
void reg_fb_sec(void)
{
- struct config_section *sec = reg_config_sec("fb", NULL, NULL);
+ struct config_section *sec = reg_config_sec("fb", fb_sec_start, fb_sec_end);
- reg_config_param(sec, "enabled", paramt_int, fb_enabled);
reg_config_param(sec, "baseaddr", paramt_addr, fb_baseaddr);
reg_config_param(sec, "refresh_rate", paramt_int, fb_refresh_rate);
reg_config_param(sec, "filename", paramt_str, fb_filename);
--- peripheral/fb.h 2002-05-22 09:15:41.000000000 +0200
+++ ../or1ksim-ac/peripheral/fb.h 2005-02-04 15:59:16.000000000 +0100
@@ -37,7 +37,4 @@
#define FB_CAMPOSADDR 0x000c
#define FB_PAL 0x0400
-/* Reset all frame buffers */
-void fb_reset ();
-
#endif /* _VGA_H_ */
--- toplevel.c 2005-02-04 16:25:08.000000000 +0100
+++ ../or1ksim-ac/toplevel.c 2005-02-04 16:21:36.000000000 +0100
@@ -48,7 +48,6 @@
#include "spr_defs.h"
#include "sprs.h"
#include "dma.h"
-#include "fb.h"
#include "ps2kbd.h"
#include "vapi.h"
#include "gdbcomm.h"
@@ -173,7 +172,6 @@
dma_reset();
eth_reset();
gpio_reset();
- fb_reset ();
kbd_reset ();
tick_reset();
pm_reset();
--- sim-config.h 2005-02-04 16:25:08.000000000 +0100
+++ ../or1ksim-ac/sim-config.h 2005-02-04 16:22:01.000000000 +0100
@@ -71,13 +71,6 @@
} gpios[MAX_GPIOS];
struct {
- int enabled; /* Whether frame buffer is enabled */
- unsigned long baseaddr; /* Base address of frame buffer register */
- int refresh_rate; /* Number of clocks per refresh */
- char filename[STR_SIZE]; /* Base file name; suffix of ####.bmp is added */
- } fb;
-
- struct {
int enabled; /* Is keyboard enabled? */
unsigned long baseaddr; /* Base address of frame buffer register */
int irq; /* Irq number of this device */
--- sim-config.c 2005-02-04 16:25:08.000000000 +0100
+++ ../or1ksim-ac/sim-config.c 2005-02-04 16:21:48.000000000 +0100
@@ -127,9 +129,6 @@
/* DMAs */
config.ndmas = 0;
- /* Frame buffer */
- config.fb.enabled = 0;
-
/* CPU */
config.cpu.superscalar = 0;
config.sim.history = 0;
--- sim.cfg 2005-02-04 16:25:08.000000000 +0100
+++ ../or1ksim-ac/sim.cfg 2005-02-04 16:28:23.000000000 +0100
@@ -803,9 +803,6 @@
This section configures the frame buffer
- enabled = 0/1
- whether frame buffer is enabled
-
baseaddr =
base address of frame buffer
@@ -820,7 +817,6 @@
*/
section fb
- enabled = 1
baseaddr = 0x97000000
refresh_rate = 1000000
filename = "primary"
|
|||
1/1

