OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_34/] [or1ksim/] [peripheral/] [fb.c] - Blame information for rev 766

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 645 markom
/* fb.c -- Simple frame buffer
2
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdio.h>
21
#include "sim-config.h"
22
#include "abstract.h"
23
#include "fb.h"
24
 
25
static unsigned long pal[256];
26 648 markom
static int fb_ctrl = 0;
27
static int fb_pic = 0;
28
static int fb_cycles = 0;
29
static unsigned long fb_addr = 0;
30 645 markom
 
31 647 markom
static void change_buf_addr (unsigned long addr)
32
{
33
  fb_addr = addr;
34
}
35
 
36
/* Write a register */
37
void fb_write32 (unsigned long addr, unsigned long value)
38
{
39
  int a = (addr - config.fb.baseaddr);
40
  switch (a) {
41 648 markom
    case FB_CTRL:    fb_ctrl = value; break;
42 647 markom
    case FB_BUFADDR: change_buf_addr (value); break;
43
    default:
44
      a -= FB_PAL;
45
      a /= 4;
46
      if (a < 0 || a >= 256) {
47
        fprintf (stderr, "Write out of palette buffer (0x%08x)!\n", addr);
48
        cont_run = 0;
49
      } else pal[a] = value;
50
      break;
51
  }
52
}
53
 
54 645 markom
/* Read a register */
55 647 markom
unsigned long fb_read32 (unsigned long addr)
56 645 markom
{
57 647 markom
  int a = (addr - config.fb.baseaddr);
58
  switch (a) {
59 648 markom
    case FB_CTRL:    return fb_ctrl; break;
60 647 markom
    case FB_BUFADDR: return fb_addr; break;
61
    default:
62
      a -= FB_PAL;
63
      a /= 4;
64
      if (a < 0 || a >= 256) {
65
        fprintf (stderr, "Read out of palette buffer (0x%08x)!\n", addr);
66
        cont_run = 0;
67
        return 0;
68
      } else return pal[a];
69
  }
70 645 markom
}
71
 
72
/* define these also for big endian */
73
#define CNV16(x) (x)
74
#define CNV32(x) (x)
75
 
76
/* Dumps a bmp file, based on current image */
77
static int fb_dump_image (char *filename)
78
{
79
  int sx = FB_SIZEX;
80
  int sy = FB_SIZEY;
81
  int i, x, y;
82
  FILE *fo;
83
 
84
  unsigned short int u16;
85
  unsigned long int u32;
86
 
87
  if (config.sim.verbose) printf ("Creating %s...", filename);
88
  fo = fopen (filename, "wb+");
89
  u16 = CNV16(19778); /* BM */
90
  if (!fwrite (&u16, 2, 1, fo)) return 1;
91
  u32 = CNV32(14 + 40 + sx * sy + 1024); /* size */
92
  if (!fwrite (&u32, 4, 1, fo)) return 1;
93
  u32 = CNV32(0); /* reserved */
94
  if (!fwrite (&u32, 4, 1, fo)) return 1;
95
  u32 = 14 + 40 + 1024; /* offset */
96
  if (!fwrite (&u32, 4, 1, fo)) return 1;
97
 
98
  u32 = CNV32(40); /* header size */
99
  if (!fwrite (&u32, 4, 1, fo)) return 1;
100
  u32 = CNV32(sx); /* width */
101
  if (!fwrite (&u32, 4, 1, fo)) return 1;
102
  u32 = CNV32(sy); /* height */
103
  if (!fwrite (&u32, 4, 1, fo)) return 1;
104
  u16 = CNV16(1);  /* planes */
105
  if (!fwrite (&u16, 2, 1, fo)) return 1;
106
  u16 = CNV16(8);  /* bits */
107
  if (!fwrite (&u16, 2, 1, fo)) return 1;
108
  u32 = CNV32(0);  /* compression */
109
  if (!fwrite (&u32, 4, 1, fo)) return 1;
110
  u32 = CNV32(x * y); /* image size */
111
  if (!fwrite (&u32, 4, 1, fo)) return 1;
112
  u32 = CNV32(0);  /* x resolution */
113
  if (!fwrite (&u32, 4, 1, fo)) return 1;
114
  u32 = CNV32(0);  /* y resolution */
115
  if (!fwrite (&u32, 4, 1, fo)) return 1;
116
  u32 = CNV32(0);  /* ncolours = 0; should be generated */
117
  if (!fwrite (&u32, 4, 1, fo)) return 1;
118
  u32 = CNV32(0);  /* important colours; all are important */
119
  if (!fwrite (&u32, 4, 1, fo)) return 1;
120
 
121
  for (i = 0; i < 256; i++) {
122
    unsigned long val, d;
123
    d = pal[i];
124 766 simons
#if 1
125
    val = ((d >> 0) & 0x1f) << 3;   /* Blue */
126
    val |= ((d >> 5) & 0x3f) << 10;  /* Green */
127
    val |= ((d >> 11) & 0x1f) << 19; /* Red */
128
#else 
129 645 markom
    val = CNV32(pal[i]);
130 766 simons
#endif
131 645 markom
    if (!fwrite (&val, 4, 1, fo)) return 1;
132
  }
133
 
134
  if (config.sim.verbose) printf ("(%i,%i)", sx, sy);
135
  /* Data is stored upside down */
136
  for (y = sy - 1; y >= 0; y--) {
137
    int align = (4 - sx) % 4;
138
    int zero = CNV32(0);
139
    while (align < 0) align += 4;
140
    for (x = 0; x < sx; x++)
141 648 markom
      fputc (evalsim_mem8 (fb_addr + y * sx + x), fo);
142 645 markom
    if (align && !fwrite (&zero, align, 1, fo)) return 1;
143
  }
144
 
145
  if (config.sim.verbose) printf ("DONE\n");
146
  fclose (fo);
147
  return 0;
148
}
149
 
150
/* Reset all VGAs */
151
void fb_reset ()
152
{
153
  int i;
154 647 markom
 
155 645 markom
  if (config.fb.enabled) {
156
    fb_pic = 0;
157
    fb_cycles = 0;
158 648 markom
    fb_addr = 0;
159
    fb_ctrl = 0;
160 645 markom
 
161
    for (i = 0; i < 256; i++)
162
      pal[i] = (i << 16) | (i << 8) | (i << 0);
163 647 markom
 
164 648 markom
 
165
 
166 647 markom
    if (config.fb.baseaddr)
167
      register_memoryarea(config.fb.baseaddr, FB_PAL + 256*4, 4, fb_read32, fb_write32);
168 645 markom
  }
169
}
170
 
171
/* Handles one VGA clock */
172
void fb_clock ()
173
{
174
  /* dump the image? */
175 648 markom
  if (fb_ctrl && fb_cycles++ >= config.fb.refresh_rate) {
176 645 markom
    char temp[STR_SIZE];
177
    sprintf (temp, "%s%04i.bmp", &config.fb.filename[0], fb_pic);
178
    fb_dump_image (temp);
179
    fb_cycles = 0;
180
    fb_pic++;
181
  }
182
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.