Line 20... |
Line 20... |
#include <stdio.h>
|
#include <stdio.h>
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "fb.h"
|
#include "fb.h"
|
|
|
static unsigned char buffer[FB_SIZEY * FB_SIZEX];
|
|
static unsigned long pal[256];
|
static unsigned long pal[256];
|
static int fb_pic;
|
static int fb_ctrl = 0;
|
static int fb_cycles;
|
static int fb_pic = 0;
|
|
static int fb_cycles = 0;
|
/* Variable to screen buffer. */
|
static unsigned long fb_addr = 0;
|
struct dev_memarea *buf_area;
|
|
static unsigned long fb_addr;
|
|
|
|
/* Write a register */
|
|
void fb_buf_write8 (unsigned long addr, unsigned long value)
|
|
{
|
|
int a = addr - fb_addr;
|
|
if (a < 0 || a >= FB_SIZEY * FB_SIZEX) {
|
|
fprintf (stderr, "Write out of screen buffer (0x%08x)!\n", addr);
|
|
cont_run = 0;
|
|
} else buffer[a] = value;
|
|
}
|
|
|
|
/* Read a register */
|
|
unsigned long fb_buf_read8 (unsigned long addr)
|
|
{
|
|
int a = (addr - fb_addr);
|
|
if (a < 0 || a >= FB_SIZEY * FB_SIZEX) {
|
|
fprintf (stderr, "Read out of screen buffer (0x%08x)!\n", addr);
|
|
cont_run = 0;
|
|
return 0;
|
|
} else return buffer[a];
|
|
}
|
|
|
|
static void change_buf_addr (unsigned long addr)
|
static void change_buf_addr (unsigned long addr)
|
{
|
{
|
unsigned long size_mask = bit_mask (FB_SIZEX * FB_SIZEY);
|
|
unsigned long addr_mask = ~size_mask;
|
|
buf_area->addr_mask = addr_mask;
|
|
buf_area->addr_compare = addr & addr_mask;
|
|
fb_addr = addr;
|
fb_addr = addr;
|
}
|
}
|
|
|
/* Write a register */
|
/* Write a register */
|
void fb_write32 (unsigned long addr, unsigned long value)
|
void fb_write32 (unsigned long addr, unsigned long value)
|
{
|
{
|
int a = (addr - config.fb.baseaddr);
|
int a = (addr - config.fb.baseaddr);
|
switch (a) {
|
switch (a) {
|
case FB_CTRL: break;
|
case FB_CTRL: fb_ctrl = value; break;
|
case FB_BUFADDR: change_buf_addr (value); break;
|
case FB_BUFADDR: change_buf_addr (value); break;
|
default:
|
default:
|
a -= FB_PAL;
|
a -= FB_PAL;
|
a /= 4;
|
a /= 4;
|
if (a < 0 || a >= 256) {
|
if (a < 0 || a >= 256) {
|
Line 82... |
Line 54... |
/* Read a register */
|
/* Read a register */
|
unsigned long fb_read32 (unsigned long addr)
|
unsigned long fb_read32 (unsigned long addr)
|
{
|
{
|
int a = (addr - config.fb.baseaddr);
|
int a = (addr - config.fb.baseaddr);
|
switch (a) {
|
switch (a) {
|
case FB_CTRL: return 0; break;
|
case FB_CTRL: return fb_ctrl; break;
|
case FB_BUFADDR: return fb_addr; break;
|
case FB_BUFADDR: return fb_addr; break;
|
default:
|
default:
|
a -= FB_PAL;
|
a -= FB_PAL;
|
a /= 4;
|
a /= 4;
|
if (a < 0 || a >= 256) {
|
if (a < 0 || a >= 256) {
|
Line 161... |
Line 133... |
for (y = sy - 1; y >= 0; y--) {
|
for (y = sy - 1; y >= 0; y--) {
|
int align = (4 - sx) % 4;
|
int align = (4 - sx) % 4;
|
int zero = CNV32(0);
|
int zero = CNV32(0);
|
while (align < 0) align += 4;
|
while (align < 0) align += 4;
|
for (x = 0; x < sx; x++)
|
for (x = 0; x < sx; x++)
|
fputc (buffer[y * sx + x], fo);
|
fputc (evalsim_mem8 (fb_addr + y * sx + x), fo);
|
if (align && !fwrite (&zero, align, 1, fo)) return 1;
|
if (align && !fwrite (&zero, align, 1, fo)) return 1;
|
}
|
}
|
|
|
if (config.sim.verbose) printf ("DONE\n");
|
if (config.sim.verbose) printf ("DONE\n");
|
fclose (fo);
|
fclose (fo);
|
Line 178... |
Line 150... |
int i;
|
int i;
|
|
|
if (config.fb.enabled) {
|
if (config.fb.enabled) {
|
fb_pic = 0;
|
fb_pic = 0;
|
fb_cycles = 0;
|
fb_cycles = 0;
|
|
fb_addr = 0;
|
|
fb_ctrl = 0;
|
|
|
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
pal[i] = (i << 16) | (i << 8) | (i << 0);
|
pal[i] = (i << 16) | (i << 8) | (i << 0);
|
|
|
register_memoryarea(config.fb.bufaddr, FB_SIZEX * FB_SIZEY, 1, fb_buf_read8, fb_buf_write8);
|
|
buf_area = cur_area;
|
|
|
|
if (config.fb.baseaddr)
|
if (config.fb.baseaddr)
|
register_memoryarea(config.fb.baseaddr, FB_PAL + 256*4, 4, fb_read32, fb_write32);
|
register_memoryarea(config.fb.baseaddr, FB_PAL + 256*4, 4, fb_read32, fb_write32);
|
}
|
}
|
}
|
}
|
|
|
/* Handles one VGA clock */
|
/* Handles one VGA clock */
|
void fb_clock ()
|
void fb_clock ()
|
{
|
{
|
/* dump the image? */
|
/* dump the image? */
|
if (fb_cycles++ >= config.fb.refresh_rate) {
|
if (fb_ctrl && fb_cycles++ >= config.fb.refresh_rate) {
|
char temp[STR_SIZE];
|
char temp[STR_SIZE];
|
sprintf (temp, "%s%04i.bmp", &config.fb.filename[0], fb_pic);
|
sprintf (temp, "%s%04i.bmp", &config.fb.filename[0], fb_pic);
|
fb_dump_image (temp);
|
fb_dump_image (temp);
|
fb_cycles = 0;
|
fb_cycles = 0;
|
fb_pic++;
|
fb_pic++;
|