dev_pmagja.cc Source File

Back to the index.

dev_pmagja.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: TURBOchannel PMAG-JA graphics card
29  *
30  * TODO
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "devices.h"
38 #include "machine.h"
39 #include "memory.h"
40 #include "misc.h"
41 
42 
43 #define XSIZE 1280
44 #define YSIZE 1024
45 
46 #define PMAGJA_FIRSTOFFSET 0x40030
47 
48 /* #define JA_DEBUG */
49 
50 struct pmagja_data {
51  struct interrupt irq;
52  struct memory *fb_mem;
53  struct vfb_data *vfb_data;
54 
55  unsigned char pixeldata[XSIZE * YSIZE];
56 
57  int current_r;
58  int current_g;
59  int current_b;
60 
62 };
63 
64 
66 {
67  struct pmagja_data *d = (struct pmagja_data *) extra;
68  uint64_t idata = 0, odata = 0;
69  size_t i, res = 1;
70 
71  if (writeflag == MEM_WRITE)
72  idata = memory_readmax64(cpu, data, len);
73 
74  relative_addr += PMAGJA_FIRSTOFFSET;
75 
76 #ifdef JA_DEBUG
77 {
78 size_t i;
79 for (i=0; i<len; i++)
80  if (data[i] != 0 && data[i] != 1 && data[i]!=0xff)
81  if (writeflag)
82  fatal("[ pmagja: write to addr 0x%08llx: 0x%08llx ]\n",
83  (long long)relative_addr, (long long)idata);
84 }
85 #endif
86 
87  switch (relative_addr) {
88  case 0x0800c4: /* pip offset */
89  if (writeflag==MEM_READ) {
90  odata = d->pip_offset;
91  debug("[ pmagja: read from pip offset: 0x%08llx ]\n",
92  (long long)odata);
93  } else {
94  d->pip_offset = idata;
95  debug("[ px: write to pip offset: 0x%08llx ]\n",
96  (long long)idata);
97  }
98  break;
99  default:
100  if (relative_addr >= 0x200000) {
101  /* 8-bit access: */
102  for (i=0; i<len; i++) {
103  int ofs = relative_addr - 0x200000 + i;
104  int x, y;
105  unsigned char newdata[3];
106  y = ofs / XSIZE;
107  x = ofs - y*XSIZE;
108 
109  if (writeflag) {
110  d->pixeldata[x + y*XSIZE] = data[i];
111  newdata[0] = d->vfb_data->rgb_palette[
112  data[i] * 3 + 0];
113  newdata[1] = d->vfb_data->rgb_palette[
114  data[i] * 3 + 1];
115  newdata[2] = d->vfb_data->rgb_palette[
116  data[i] * 3 + 2];
117  dev_fb_access(cpu, d->fb_mem, (x +
118  y * XSIZE) * 3, newdata, 3,
119  writeflag, d->vfb_data);
120  } else {
121  data[i] = d->pixeldata[x + y*XSIZE];
122  }
123  }
124  /* Return success. */
125  return 1;
126  } else if (relative_addr >= 0x100000 &&
127  relative_addr < 0x200000) {
128  /* 24-bit access: */
129 #if 0
130 {
131  if (writeflag)
132  if (idata != 0)
133  fatal("[ pmagja: write to addr 0x%08llx: 0x%08llx ]\n",
134  (long long)relative_addr, (long long)idata);
135 }
136 #endif
137  int x, y, ofs;
138 
139  ofs = (relative_addr - 0x100000) * 2;
140  y = ofs / XSIZE;
141  x = ofs - y * XSIZE;
142 
143 #if 0
144  if (writeflag == MEM_WRITE) {
145  int ix;
146  for (ix=0; ix<len*2; ix++) {
147  unsigned char data[3];
148  int ctype;
149 
150  data[0] = data[1] = data[2] = 0;
151  ctype = (idata >> (ix*4)) & 0xf;
152  if (ctype == 0)
153  data[0] = 255;
154  if (ctype == 3)
155  data[1] = 255;
156  if (ctype == 0xf)
157  data[2] = 255;
158 
159  res = dev_fb_access(cpu, d->fb_mem,
160  ofs * 3, data, 3, MEM_WRITE,
161  d->vfb_data);
162  ofs ++;
163  }
164  }
165 #endif
166  return 1;
167  } else {
168  /* Unknown: */
169  if (writeflag==MEM_READ) {
170  fatal("[ pmagja: read from addr 0x%x: "
171  "0x%llx ]\n", (int)relative_addr,
172  (long long)odata);
173  } else {
174  fatal("[ pmagja: write to addr 0x%x: "
175  "0x%llx ]\n", (int)relative_addr,
176  (long long)idata);
177  }
178  }
179  }
180 
181  if (writeflag == MEM_READ)
182  memory_writemax64(cpu, data, len, odata);
183 
184 #ifdef JA_DEBUG
185 /*
186  if (!writeflag)
187  fatal("[ pmagja: read from addr 0x%08llx: 0x%08llx ]\n",
188  (long long)relative_addr, (long long)odata);
189 */
190 #endif
191 
192  return res;
193 }
194 
195 
196 void dev_pmagja_init(struct machine *machine, struct memory *mem,
197  uint64_t baseaddr, const char *irq_path)
198 {
199  struct pmagja_data *d;
200 
201  CHECK_ALLOCATION(d = (struct pmagja_data *) malloc(sizeof(struct pmagja_data)));
202  memset(d, 0, sizeof(struct pmagja_data));
203 
204  INTERRUPT_CONNECT(irq_path, d->irq);
205 
206  d->fb_mem = memory_new(XSIZE * YSIZE * 3, machine->arch);
207  if (d->fb_mem == NULL) {
208  fprintf(stderr, "dev_pmagja_init(): out of memory (1)\n");
209  exit(1);
210  }
212  XSIZE, YSIZE, XSIZE, YSIZE, 24, "PMAG-JA");
213  if (d->vfb_data == NULL) {
214  fprintf(stderr, "dev_pmagja_init(): out of memory (2)\n");
215  exit(2);
216  }
217 
218  /* TODO: not bt459, but a bt463: */
219  dev_bt459_init(machine, mem, baseaddr + 0x40000, 0, d->vfb_data, 8,
220  irq_path, 0); /* palette (TODO: type) */
221  dev_bt431_init(mem, baseaddr + 0x40010, d->vfb_data, 8); /* cursor */
222 
223  memory_device_register(mem, "pmagja", baseaddr + PMAGJA_FIRSTOFFSET,
225  DM_DEFAULT, NULL);
226 }
227 
data
u_short data
Definition: siireg.h:79
INTERRUPT_CONNECT
#define INTERRUPT_CONNECT(name, istruct)
Definition: interrupt.h:77
pmagja_data::current_g
int current_g
Definition: dev_pmagja.cc:58
VFB_GENERIC
#define VFB_GENERIC
Definition: devices.h:190
dev_pmagja_access
int dev_pmagja_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, unsigned char *data, size_t len, int writeflag, void *)
vfb_data::rgb_palette
unsigned char rgb_palette[256 *3]
Definition: devices.h:223
pmagja_data::pip_offset
int pip_offset
Definition: dev_pmagja.cc:61
memory
Definition: memory.h:75
debug
#define debug
Definition: dev_adb.cc:57
XSIZE
#define XSIZE
Definition: dev_pmagja.cc:43
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
pmagja_data::pixeldata
unsigned char pixeldata[XSIZE *YSIZE]
Definition: dev_pmagja.cc:55
MEM_READ
#define MEM_READ
Definition: memory.h:116
DM_DEFAULT
#define DM_DEFAULT
Definition: memory.h:130
DEV_PMAGJA_LENGTH
#define DEV_PMAGJA_LENGTH
Definition: devices.h:331
MEM_WRITE
#define MEM_WRITE
Definition: memory.h:117
dev_bt459_init
void dev_bt459_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, uint64_t baseaddr_irq, struct vfb_data *vfb_data, int planes, const char *irq_path, int type)
Definition: dev_bt459.cc:522
pmagja_data::current_b
int current_b
Definition: dev_pmagja.cc:59
fatal
void fatal(const char *fmt,...)
Definition: main.cc:152
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
machine.h
machine
Definition: machine.h:97
pmagja_data
Definition: dev_pmagja.cc:50
DEVICE_ACCESS
DEVICE_ACCESS(pmagja)
Definition: dev_pmagja.cc:65
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 *)
YSIZE
#define YSIZE
Definition: dev_pmagja.cc:44
pmagja_data::vfb_data
struct vfb_data * vfb_data
Definition: dev_pmagja.cc:53
pmagja_data::irq
struct interrupt irq
Definition: dev_pmagja.cc:51
pmagja_data::current_r
int current_r
Definition: dev_pmagja.cc:57
dev_pmagja_init
void dev_pmagja_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, const char *irq_path)
Definition: dev_pmagja.cc:196
interrupt
Definition: interrupt.h:36
pmagja_data::fb_mem
struct memory * fb_mem
Definition: dev_pmagja.cc:52
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
dev_bt431_init
void dev_bt431_init(struct memory *mem, uint64_t baseaddr, struct vfb_data *vfb_data, int planes)
Definition: dev_bt431.cc:196
memory_new
struct memory * memory_new(uint64_t physical_max, int arch)
Definition: memory.cc:146
vfb_data
Definition: devices.h:198
machine::arch
int arch
Definition: machine.h:110
memory.h
PMAGJA_FIRSTOFFSET
#define PMAGJA_FIRSTOFFSET
Definition: dev_pmagja.cc:46
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 Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18