dev_dec21030.cc Source File

Back to the index.

dev_dec21030.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2009 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * COMMENT: DEC 21030 "TGA" graphics card
29  *
30  * Resolutions that seem to be possible: 640x480, 1024x768, 1280x1024.
31  * 8 bits, perhaps others? (24 bit?)
32  *
33  * NetBSD should say something like this:
34  *
35  * tga0 at pci0 dev 12 function 0: TGA2 pass 2, board type T8-02
36  * tga0: 1280 x 1024, 8bpp, Bt485 RAMDAC
37  *
38  * See netbsd/src/sys/dev/pci/tga.c for more info.
39  * tga_rop_vtov() for video-to-video copy (scrolling and fast
40  * erasing)
41  *
42  * TODO: This device is far from complete.
43  * The RAMDAC is non-existant.
44  *
45  * TODO: all fb device writes with direct writes to the framebuffer
46  * memory, and update the x1,y1,x2,y2 coordinates instead.
47  * That will give better performance.
48  */
49 
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 
54 #include "device.h"
55 #include "devices.h"
56 #include "machine.h"
57 #include "memory.h"
58 #include "misc.h"
59 
60 #include "thirdparty/tgareg.h"
61 
62 
63 #define MAX_XSIZE 2048
64 
65 #if 1
68 #else
69 int dec21030_default_xsize = 1024;
70 int dec21030_default_ysize = 768;
71 #endif
72 
73 
74 /* TODO: Ugly hack: this causes the framebuffer to be in memory */
75 #define FRAMEBUFFER_PADDR 0x4000000000ULL
76 #define FRAMEBUFFER_BASE 0x201000
77 
78 
79 struct dec21030_data {
81  uint32_t pixel_mask;
82  uint32_t copy_source;
83  uint32_t color;
84  struct vfb_data *vfb_data;
85 };
86 
87 
88 DEVICE_ACCESS(dec21030)
89 {
90  struct dec21030_data *d = (struct dec21030_data *) extra;
91  uint64_t idata, odata = 0;
92  int reg, r, white = 255, black = 0;
93  size_t i, newlen;
94  unsigned char buf2[MAX_XSIZE];
95 
96  /* Read/write to the framebuffer: */
97  if (relative_addr >= FRAMEBUFFER_BASE) {
98  /* TODO: Perhaps this isn't graphics mode (GMOR),
99  but GOPR (operation) specific: */
100 
101  switch (d->graphics_mode) {
102  case 1: /* Bitmap write: */
103  /* Copy from data into buf2: */
104  for (i=0; i<len; i++) {
105  buf2[i*8 + 0] = data[i]&1? white : black;
106  buf2[i*8 + 1] = data[i]&2? white : black;
107  buf2[i*8 + 2] = data[i]&4? white : black;
108  buf2[i*8 + 3] = data[i]&8? white : black;
109  buf2[i*8 + 4] = data[i]&16? white : black;
110  buf2[i*8 + 5] = data[i]&32? white : black;
111  buf2[i*8 + 6] = data[i]&64? white : black;
112  buf2[i*8 + 7] = data[i]&128? white : black;
113  }
114 
115  newlen = 0;
116  for (i=0; i<32; i++)
117  if (d->pixel_mask & (1 << i))
118  newlen ++;
119 
120  if (newlen > len * 8)
121  newlen = len * 8;
122 
123  r = dev_fb_access(cpu, mem, relative_addr -
124  FRAMEBUFFER_BASE, buf2, newlen, writeflag,
125  d->vfb_data);
126  break;
127  case 0x2d: /* Block fill: */
128  /* data is nr of pixels to fill minus one */
129  newlen = memory_readmax64(cpu, data, len) + 1;
130  /* debug("YO addr=0x%08x, newlen=%i\n", relative_addr,
131  newlen); */
132  if (newlen > MAX_XSIZE)
133  newlen = MAX_XSIZE;
134  memset(buf2, d->color, newlen);
135  r = dev_fb_access(cpu, mem, relative_addr -
136  FRAMEBUFFER_BASE, buf2, newlen, MEM_WRITE,
137  d->vfb_data);
138  break;
139  default:
140  r = dev_fb_access(cpu, mem, relative_addr -
141  FRAMEBUFFER_BASE, data, len, writeflag,
142  d->vfb_data);
143  }
144  return r;
145  }
146 
147  idata = memory_readmax64(cpu, data, len);
148 
149  /* Read from/write to the dec21030's registers: */
150  reg = ((relative_addr - TGA_MEM_CREGS) & (TGA_CREGS_ALIAS - 1))
151  / sizeof(uint32_t);
152  switch (reg) {
153 
154  /* Color? (there are 8 of these, 2 used in 8-bit mode,
155  8 in 24-bit mode) */
156  case TGA_REG_GBCR0:
157  if (writeflag == MEM_WRITE)
158  d->color = idata;
159  else
160  odata = d->color;
161  break;
162 
163  /* Board revision */
164 /* case TGA_MEM_CREGS + sizeof(uint32_t) * TGA_REG_GREV: */
165  case TGA_REG_GREV:
166  /* 01,02,03,04 (rev0) and 20,21,22 (rev1) are allowed */
167  odata = 0x04;
168  break;
169 
170  /* Graphics Mode: */
171  case TGA_REG_GMOR:
172  if (writeflag == MEM_WRITE)
173  d->graphics_mode = idata;
174  else
175  odata = d->graphics_mode;
176  break;
177 
178  /* Pixel mask: */
179  case TGA_REG_GPXR_S: /* "one-shot" */
180  case TGA_REG_GPXR_P: /* persistant */
181  if (writeflag == MEM_WRITE)
182  d->pixel_mask = idata;
183  else
184  odata = d->pixel_mask;
185  break;
186 
187  /* Horizonsal size: */
188  case TGA_REG_VHCR:
189  odata = dec21030_default_xsize / 4; /* lowest 9 bits */
190  break;
191 
192  /* Vertical size: */
193  case TGA_REG_VVCR:
194  odata = dec21030_default_ysize; /* lowest 11 bits */
195  break;
196 
197  /* Block copy source: */
198  case TGA_REG_GCSR:
199  d->copy_source = idata;
200  debug("[ dec21030: block copy source = 0x%08x ]\n", idata);
201  break;
202 
203  /* Block copy destination: */
204  case TGA_REG_GCDR:
205  debug("[ dec21030: block copy destination = 0x%08x ]\n", idata);
206  newlen = 64;
207  /* Both source and destination are raw framebuffer addresses,
208  offset by 0x1000. */
209  dev_fb_access(cpu, mem, d->copy_source - 0x1000,
210  buf2, newlen, MEM_READ, d->vfb_data);
211  dev_fb_access(cpu, mem, idata - 0x1000,
212  buf2, newlen, MEM_WRITE, d->vfb_data);
213  break;
214 
215  default:
216  if (writeflag == MEM_WRITE)
217  debug("[ dec21030: unimplemented write to address"
218  " 0x%x (=reg 0x%x), data=0x%02x ]\n",
219  (int)relative_addr, reg, (int)idata);
220  else
221  debug("[ dec21030: unimplemented read from address"
222  " 0x%x (=reg 0x%x) ]\n", (int)relative_addr, reg);
223  }
224 
225  if (writeflag == MEM_READ)
226  memory_writemax64(cpu, data, len, odata);
227 
228  return 1;
229 }
230 
231 
232 DEVINIT(dec21030)
233 {
234  struct dec21030_data *d;
235 
236  CHECK_ALLOCATION(d = (struct dec21030_data *) malloc(sizeof(struct dec21030_data)));
237  memset(d, 0, sizeof(struct dec21030_data));
238 
240  devinit->addr, 128*1048576, dev_dec21030_access, d,
241  DM_DEFAULT, NULL);
242 
243  /*
244  * TODO: I have no idea about how/where this framebuffer should
245  * be in relation to the pci device
246  */
251 
252  return 1;
253 }
254 
dec21030_data::color
uint32_t color
Definition: dev_dec21030.cc:83
data
u_short data
Definition: siireg.h:79
TGA_REG_GCDR
#define TGA_REG_GCDR
Definition: tgareg.h:145
VFB_GENERIC
#define VFB_GENERIC
Definition: devices.h:190
debug
#define debug
Definition: dev_adb.cc:57
MAX_XSIZE
#define MAX_XSIZE
Definition: dev_dec21030.cc:63
dec21030_data
Definition: dev_dec21030.cc:79
devinit::addr
uint64_t addr
Definition: device.h:46
memory_device_register
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
MEM_READ
#define MEM_READ
Definition: memory.h:116
dec21030_data::graphics_mode
int graphics_mode
Definition: dev_dec21030.cc:80
TGA_REG_GPXR_S
#define TGA_REG_GPXR_S
Definition: tgareg.h:74
TGA_REG_GMOR
#define TGA_REG_GMOR
Definition: tgareg.h:75
DM_DEFAULT
#define DM_DEFAULT
Definition: memory.h:130
devinit::machine
struct machine * machine
Definition: device.h:41
dec21030_data::copy_source
uint32_t copy_source
Definition: dev_dec21030.cc:82
device.h
MEM_WRITE
#define MEM_WRITE
Definition: memory.h:117
TGA_REG_VHCR
#define TGA_REG_VHCR
Definition: tgareg.h:90
dec21030_data::vfb_data
struct vfb_data * vfb_data
Definition: dev_dec21030.cc:84
FRAMEBUFFER_BASE
#define FRAMEBUFFER_BASE
Definition: dev_dec21030.cc:76
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
machine.h
devinit::name
char * name
Definition: device.h:43
TGA_REG_GBCR0
#define TGA_REG_GBCR0
Definition: tgareg.h:135
TGA_REG_GPXR_P
#define TGA_REG_GPXR_P
Definition: tgareg.h:88
dec21030_default_ysize
int dec21030_default_ysize
Definition: dev_dec21030.cc:67
devinit
Definition: device.h:40
dev_fb_access
int dev_fb_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, unsigned char *data, size_t len, int writeflag, void *)
TGA_REG_VVCR
#define TGA_REG_VVCR
Definition: tgareg.h:91
machine::memory
struct memory * memory
Definition: machine.h:126
reg
#define reg(x)
Definition: tmp_alpha_tail.cc:53
DEVINIT
DEVINIT(dec21030)
Definition: dev_dec21030.cc:232
TGA_REG_GREV
#define TGA_REG_GREV
Definition: tgareg.h:86
tgareg.h
TGA_CREGS_ALIAS
#define TGA_CREGS_ALIAS
Definition: tgareg.h:49
DEVICE_ACCESS
DEVICE_ACCESS(dec21030)
Definition: dev_dec21030.cc:88
TGA_MEM_CREGS
#define TGA_MEM_CREGS
Definition: tgareg.h:47
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
devices.h
cpu
Definition: cpu.h:326
TGA_REG_GCSR
#define TGA_REG_GCSR
Definition: tgareg.h:144
vfb_data
Definition: devices.h:198
FRAMEBUFFER_PADDR
#define FRAMEBUFFER_PADDR
Definition: dev_dec21030.cc:75
dec21030_default_xsize
int dec21030_default_xsize
Definition: dev_dec21030.cc:66
memory.h
dec21030_data::pixel_mask
uint32_t pixel_mask
Definition: dev_dec21030.cc:81
dev_fb_init
struct vfb_data * dev_fb_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, int xsize, int ysize, int bit_depth, const char *name)
Definition: dev_fb.cc:834
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17