dev_bt455.cc Source File

Back to the index.

dev_bt455.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: Brooktree BT455, used by TURBOchannel graphics cards
29  *
30  * TODO: This is hardcoded to only use 16 grayscales, using only the
31  * green component of the palette. Perhaps some other graphics card uses
32  * the BT455 as well; if so then this device must be re-hacked.
33  */
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 
39 #include "devices.h"
40 #include "memory.h"
41 #include "misc.h"
42 
43 
44 
45 struct bt455_data {
46  unsigned char addr_cmap;
47  unsigned char addr_cmap_data;
48  unsigned char addr_clr;
49  unsigned char addr_ovly;
50 
52 
53  struct vfb_data *vfb_data;
54  unsigned char *rgb_palette; /* ptr to 256 * 3 (r,g,b) */
55 };
56 
57 
59 {
60  struct bt455_data *d = (struct bt455_data *) extra;
61  uint64_t idata = 0, odata = 0;
62  int i, modified;
63 
64  if (writeflag == MEM_WRITE)
65  idata = memory_readmax64(cpu, data, len);
66 
67  /* Read from/write to the bt455: */
68  switch (relative_addr) {
69  case 0x00: /* addr_cmap */
70  if (writeflag == MEM_WRITE) {
71  debug("[ bt455: write to addr_cmap, 0x%02x ]\n", idata);
72  d->addr_cmap = idata;
73  d->cur_rgb_offset = (d->addr_cmap & 0xf) * 3;
74  } else {
75  odata = d->addr_cmap;
76  debug("[ bt455: read from addr_cmap: 0x%0x ]\n", odata);
77  }
78  break;
79  case 0x04: /* addr_cmap_data */
80  if (writeflag == MEM_WRITE) {
81  debug("[ bt455: write to addr_cmap_data, 0x%02x ]\n",
82  (int)idata);
83  d->addr_cmap_data = idata;
84 
85  modified = 0;
86 
87  /* Only write on updates to the Green value: */
88  if ((d->cur_rgb_offset % 3) == 1) {
89  /* Update 16 copies: */
90  for (i=0; i<16; i++) {
91  int addr = (d->cur_rgb_offset + 16*i)
92  % 0x300;
93  int newvalue = idata * 0x11;
94 
95  if (d->rgb_palette[(addr / 3) * 3 + 0]
96  != newvalue ||
97  d->rgb_palette[(addr / 3) * 3 + 1]
98  != newvalue ||
99  d->rgb_palette[(addr / 3) * 3 + 2]
100  != newvalue)
101  modified = 1;
102 
103  d->rgb_palette[(addr / 3) * 3 + 0] =
104  d->rgb_palette[(addr / 3) * 3 + 1] =
105  d->rgb_palette[(addr / 3) * 3 + 2] =
106  newvalue;
107  }
108  }
109 
110  if (modified) {
111  d->vfb_data->update_x1 = 0;
112  d->vfb_data->update_x2 = d->vfb_data->xsize - 1;
113  d->vfb_data->update_y1 = 0;
114  d->vfb_data->update_y2 = d->vfb_data->ysize - 1;
115  }
116 
117  /* Advance to next palette byte: */
118  d->cur_rgb_offset ++;
119  } else {
120  odata = d->addr_cmap_data;
121  debug("[ bt455: read from addr_cmap_data: 0x%0x ]\n",
122  (int)odata);
123  }
124  break;
125  case 0x08: /* addr_clr */
126  if (writeflag == MEM_WRITE) {
127  debug("[ bt455: write to addr_clr, value 0x%02x ]\n",
128  (int)idata);
129  d->addr_clr = idata;
130  } else {
131  odata = d->addr_clr;
132  debug("[ bt455: read from addr_clr: value 0x%02x ]\n",
133  (int)odata);
134  }
135  break;
136  case 0x0c: /* addr_ovly */
137  if (writeflag == MEM_WRITE) {
138  debug("[ bt455: write to addr_ovly, value 0x%02x ]\n",
139  (int)idata);
140  d->addr_ovly = idata;
141  } else {
142  odata = d->addr_ovly;
143  debug("[ bt455: read from addr_ovly: value 0x%02x ]\n",
144  (int)odata);
145  }
146  break;
147  default:
148  if (writeflag == MEM_WRITE) {
149  debug("[ bt455: unimplemented write to address 0x%x,"
150  " data=0x%02x ]\n", (int)relative_addr, (int)idata);
151  } else {
152  debug("[ bt455: unimplemented read from address "
153  "0x%x ]\n", (int)relative_addr);
154  }
155  }
156 
157  if (writeflag == MEM_READ)
158  memory_writemax64(cpu, data, len, odata);
159 
160  return 1;
161 }
162 
163 
164 /*
165  * dev_bt455_init():
166  */
167 void dev_bt455_init(struct memory *mem, uint64_t baseaddr,
168  struct vfb_data *vfb_data)
169 {
170  struct bt455_data *d;
171 
172  CHECK_ALLOCATION(d = (struct bt455_data *) malloc(sizeof(struct bt455_data)));
173  memset(d, 0, sizeof(struct bt455_data));
174 
175  d->vfb_data = vfb_data;
177 
178  memory_device_register(mem, "bt455", baseaddr, DEV_BT455_LENGTH,
179  dev_bt455_access, (void *)d, DM_DEFAULT, NULL);
180 }
181 
data
u_short data
Definition: siireg.h:79
vfb_data::rgb_palette
unsigned char rgb_palette[256 *3]
Definition: devices.h:223
memory
Definition: memory.h:75
bt455_data::addr_clr
unsigned char addr_clr
Definition: dev_bt455.cc:48
debug
#define debug
Definition: dev_adb.cc:57
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
vfb_data::update_x2
int update_x2
Definition: devices.h:220
MEM_READ
#define MEM_READ
Definition: memory.h:116
vfb_data::xsize
int xsize
Definition: devices.h:204
DM_DEFAULT
#define DM_DEFAULT
Definition: memory.h:130
vfb_data::update_y1
int update_y1
Definition: devices.h:220
addr
uint32_t addr
Definition: tmp_arm_multi.cc:52
MEM_WRITE
#define MEM_WRITE
Definition: memory.h:117
DEV_BT455_LENGTH
#define DEV_BT455_LENGTH
Definition: devices.h:136
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
dev_bt455_access
int dev_bt455_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, unsigned char *data, size_t len, int writeflag, void *)
bt455_data::addr_ovly
unsigned char addr_ovly
Definition: dev_bt455.cc:49
bt455_data
Definition: dev_bt455.cc:45
bt455_data::addr_cmap_data
unsigned char addr_cmap_data
Definition: dev_bt455.cc:47
vfb_data::update_x1
int update_x1
Definition: devices.h:220
bt455_data::rgb_palette
unsigned char * rgb_palette
Definition: dev_bt455.cc:54
vfb_data::ysize
int ysize
Definition: devices.h:205
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
DEVICE_ACCESS
DEVICE_ACCESS(bt455)
Definition: dev_bt455.cc:58
devices.h
cpu
Definition: cpu.h:326
dev_bt455_init
void dev_bt455_init(struct memory *mem, uint64_t baseaddr, struct vfb_data *vfb_data)
Definition: dev_bt455.cc:167
vfb_data
Definition: devices.h:198
bt455_data::vfb_data
struct vfb_data * vfb_data
Definition: dev_bt455.cc:53
bt455_data::addr_cmap
unsigned char addr_cmap
Definition: dev_bt455.cc:46
memory.h
bt455_data::cur_rgb_offset
int cur_rgb_offset
Definition: dev_bt455.cc:51
vfb_data::update_y2
int update_y2
Definition: devices.h:220
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18