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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_66/] [or1ksim/] [peripheral/] [fb.c] - Blame information for rev 805

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

powered by: WebSVN 2.1.0

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