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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_1_0/] [or1ksim/] [peripheral/] [fb.c] - Blame information for rev 846

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 805 markom
#include "sched.h"
25 645 markom
 
26 799 simons
#define FB_WRAP (512*1024)
27
 
28 645 markom
static unsigned long pal[256];
29 648 markom
static int fb_ctrl = 0;
30
static int fb_pic = 0;
31 845 markom
static int fb_in_refresh = 1;
32
static int fb_refresh_count = 0;
33 648 markom
static unsigned long fb_addr = 0;
34 645 markom
 
35 647 markom
static void change_buf_addr (unsigned long addr)
36
{
37
  fb_addr = addr;
38
}
39
 
40
/* Write a register */
41
void fb_write32 (unsigned long addr, unsigned long value)
42
{
43
  int a = (addr - config.fb.baseaddr);
44
  switch (a) {
45 846 markom
    case FB_CTRL:    fb_ctrl = value; break;
46 647 markom
    case FB_BUFADDR: change_buf_addr (value); break;
47
    default:
48
      a -= FB_PAL;
49
      a /= 4;
50
      if (a < 0 || a >= 256) {
51
        fprintf (stderr, "Write out of palette buffer (0x%08x)!\n", addr);
52
        cont_run = 0;
53
      } else pal[a] = value;
54
      break;
55
  }
56
}
57
 
58 645 markom
/* Read a register */
59 647 markom
unsigned long fb_read32 (unsigned long addr)
60 645 markom
{
61 647 markom
  int a = (addr - config.fb.baseaddr);
62
  switch (a) {
63 845 markom
    case FB_CTRL:
64 846 markom
      return fb_ctrl & ~0xff000000| (fb_in_refresh ? 0x80000000 : 0) | ((unsigned long)(fb_refresh_count & 0x7f) << 24);
65 845 markom
      break;
66 647 markom
    case FB_BUFADDR: return fb_addr; break;
67
    default:
68
      a -= FB_PAL;
69
      a /= 4;
70
      if (a < 0 || a >= 256) {
71
        fprintf (stderr, "Read out of palette buffer (0x%08x)!\n", addr);
72
        cont_run = 0;
73
        return 0;
74
      } else return pal[a];
75
  }
76 645 markom
}
77
 
78
/* define these also for big endian */
79
#define CNV16(x) (x)
80
#define CNV32(x) (x)
81
 
82
/* Dumps a bmp file, based on current image */
83
static int fb_dump_image (char *filename)
84
{
85
  int sx = FB_SIZEX;
86
  int sy = FB_SIZEY;
87
  int i, x, y;
88
  FILE *fo;
89
 
90
  unsigned short int u16;
91
  unsigned long int u32;
92
 
93
  if (config.sim.verbose) printf ("Creating %s...", filename);
94
  fo = fopen (filename, "wb+");
95
  u16 = CNV16(19778); /* BM */
96
  if (!fwrite (&u16, 2, 1, fo)) return 1;
97
  u32 = CNV32(14 + 40 + sx * sy + 1024); /* size */
98
  if (!fwrite (&u32, 4, 1, fo)) return 1;
99
  u32 = CNV32(0); /* reserved */
100
  if (!fwrite (&u32, 4, 1, fo)) return 1;
101
  u32 = 14 + 40 + 1024; /* offset */
102
  if (!fwrite (&u32, 4, 1, fo)) return 1;
103
 
104
  u32 = CNV32(40); /* header size */
105
  if (!fwrite (&u32, 4, 1, fo)) return 1;
106
  u32 = CNV32(sx); /* width */
107
  if (!fwrite (&u32, 4, 1, fo)) return 1;
108
  u32 = CNV32(sy); /* height */
109
  if (!fwrite (&u32, 4, 1, fo)) return 1;
110
  u16 = CNV16(1);  /* planes */
111
  if (!fwrite (&u16, 2, 1, fo)) return 1;
112
  u16 = CNV16(8);  /* bits */
113
  if (!fwrite (&u16, 2, 1, fo)) return 1;
114
  u32 = CNV32(0);  /* compression */
115
  if (!fwrite (&u32, 4, 1, fo)) return 1;
116
  u32 = CNV32(x * y); /* image size */
117
  if (!fwrite (&u32, 4, 1, fo)) return 1;
118
  u32 = CNV32(0);  /* x resolution */
119
  if (!fwrite (&u32, 4, 1, fo)) return 1;
120
  u32 = CNV32(0);  /* y resolution */
121
  if (!fwrite (&u32, 4, 1, fo)) return 1;
122
  u32 = CNV32(0);  /* ncolours = 0; should be generated */
123
  if (!fwrite (&u32, 4, 1, fo)) return 1;
124
  u32 = CNV32(0);  /* important colours; all are important */
125
  if (!fwrite (&u32, 4, 1, fo)) return 1;
126
 
127
  for (i = 0; i < 256; i++) {
128
    unsigned long val, d;
129
    d = pal[i];
130 766 simons
#if 1
131
    val = ((d >> 0) & 0x1f) << 3;   /* Blue */
132
    val |= ((d >> 5) & 0x3f) << 10;  /* Green */
133
    val |= ((d >> 11) & 0x1f) << 19; /* Red */
134
#else 
135 645 markom
    val = CNV32(pal[i]);
136 766 simons
#endif
137 645 markom
    if (!fwrite (&val, 4, 1, fo)) return 1;
138
  }
139
 
140
  if (config.sim.verbose) printf ("(%i,%i)", sx, sy);
141
  /* Data is stored upside down */
142
  for (y = sy - 1; y >= 0; y--) {
143
    int align = (4 - sx) % 4;
144
    int zero = CNV32(0);
145 799 simons
    int add;
146 645 markom
    while (align < 0) align += 4;
147 799 simons
    for (x = 0; x < sx; x++) {
148
      add = (fb_addr & ~(FB_WRAP - 1)) | ((fb_addr + y * sx + x) & (FB_WRAP - 1));
149
      fputc (evalsim_mem8 (add), fo);
150
    }
151 645 markom
    if (align && !fwrite (&zero, align, 1, fo)) return 1;
152
  }
153
 
154
  if (config.sim.verbose) printf ("DONE\n");
155
  fclose (fo);
156
  return 0;
157
}
158
 
159 805 markom
void fb_job (int param)
160
{
161 845 markom
  if (param) {
162
    /* dump the image? */
163
    if (fb_ctrl) {
164
      char temp[STR_SIZE];
165
      sprintf (temp, "%s%04i.bmp", &config.fb.filename[0], fb_pic);
166
      fb_dump_image (temp);
167
      fb_pic++;
168
    }
169
    SCHED_ADD(fb_job, 0, cycles + config.fb.refresh_rate - config.fb.refresh_rate / REFRESH_DIVIDER);
170
    fb_in_refresh = 0;
171
  } else {
172
    fb_refresh_count++;
173
    SCHED_ADD(fb_job, 1, cycles + config.fb.refresh_rate / REFRESH_DIVIDER);
174
 
175 805 markom
  }
176
}
177
 
178 645 markom
/* Reset all VGAs */
179
void fb_reset ()
180
{
181
  int i;
182 647 markom
 
183 645 markom
  if (config.fb.enabled) {
184
    fb_pic = 0;
185 648 markom
    fb_addr = 0;
186
    fb_ctrl = 0;
187 645 markom
 
188
    for (i = 0; i < 256; i++)
189
      pal[i] = (i << 16) | (i << 8) | (i << 0);
190 647 markom
 
191
    if (config.fb.baseaddr)
192
      register_memoryarea(config.fb.baseaddr, FB_PAL + 256*4, 4, fb_read32, fb_write32);
193 805 markom
    SCHED_ADD(fb_job, 0, cycles + config.fb.refresh_rate);
194 645 markom
  }
195
}

powered by: WebSVN 2.1.0

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