1 |
/* |
2 |
* Copyright (C) 2004-2006 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 |
* $Id: dev_bt431.c,v 1.11 2006/01/01 13:17:16 debug Exp $ |
29 |
* |
30 |
* Brooktree 431, used by TURBOchannel graphics cards. |
31 |
* |
32 |
* TODO. |
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 |
#include "bt431reg.h" |
44 |
|
45 |
|
46 |
struct bt431_data { |
47 |
uint32_t bt431_reg[DEV_BT431_NREGS]; |
48 |
|
49 |
unsigned char cur_addr_hi; |
50 |
unsigned char cur_addr_lo; |
51 |
|
52 |
int planes; |
53 |
int cursor_on; |
54 |
int cursor_x; |
55 |
int cursor_y; |
56 |
int cursor_xsize; |
57 |
int cursor_ysize; |
58 |
|
59 |
struct vfb_data *vfb_data; |
60 |
}; |
61 |
|
62 |
|
63 |
/* |
64 |
* dev_bt431_access(): |
65 |
*/ |
66 |
DEVICE_ACCESS(bt431) |
67 |
{ |
68 |
struct bt431_data *d = (struct bt431_data *) extra; |
69 |
uint64_t idata = 0, odata = 0; |
70 |
int btaddr; |
71 |
#if 0 |
72 |
int on, new_cursor_x, new_cursor_y; |
73 |
#endif |
74 |
|
75 |
if (writeflag == MEM_WRITE) |
76 |
idata = memory_readmax64(cpu, data, len); |
77 |
|
78 |
btaddr = ((d->cur_addr_hi << 8) + d->cur_addr_lo) % DEV_BT431_NREGS; |
79 |
|
80 |
/* TODO */ |
81 |
|
82 |
/* Read from/write to the bt431: */ |
83 |
switch (relative_addr) { |
84 |
case 0x00: /* Low byte of address: */ |
85 |
if (writeflag == MEM_WRITE) { |
86 |
debug("[ bt431: write to Low Address Byte, " |
87 |
"0x%02x ]\n", (int)idata); |
88 |
d->cur_addr_lo = idata; |
89 |
} else { |
90 |
odata = d->cur_addr_lo; |
91 |
debug("[ bt431: read from Low Address Byte: " |
92 |
"0x%0x ]\n", (int)odata); |
93 |
} |
94 |
break; |
95 |
case 0x04: /* High byte of address: */ |
96 |
if (writeflag == MEM_WRITE) { |
97 |
debug("[ bt431: write to High Address Byte, " |
98 |
"0x%02x ]\n", (int)idata); |
99 |
d->cur_addr_hi = idata; |
100 |
} else { |
101 |
odata = d->cur_addr_hi; |
102 |
debug("[ bt431: read from High Address Byte: " |
103 |
"0x%0x ]\n", (int)odata); |
104 |
} |
105 |
break; |
106 |
case 0x08: /* Register access: */ |
107 |
if (writeflag == MEM_WRITE) { |
108 |
debug("[ bt431: write to BT431 register 0x%04x, " |
109 |
"value 0x%02x ]\n", btaddr, (int)idata); |
110 |
d->bt431_reg[btaddr] = idata; |
111 |
|
112 |
#if 0 |
113 |
/* Write to cursor bitmap: */ |
114 |
if (btaddr >= 0x400) |
115 |
bt431_sync_xysize(d); |
116 |
#endif |
117 |
} else { |
118 |
odata = d->bt431_reg[btaddr]; |
119 |
debug("[ bt431: read from BT431 register 0x%04x, " |
120 |
"value 0x%02x ]\n", btaddr, (int)odata); |
121 |
} |
122 |
|
123 |
/* Go to next register: */ |
124 |
d->cur_addr_lo ++; |
125 |
if (d->cur_addr_lo == 0) |
126 |
d->cur_addr_hi ++; |
127 |
break; |
128 |
default: |
129 |
if (writeflag == MEM_WRITE) { |
130 |
debug("[ bt431: unimplemented write to address " |
131 |
"0x%x, data=0x%02x ]\n", (int)relative_addr, |
132 |
(int)idata); |
133 |
} else { |
134 |
debug("[ bt431: unimplemented read from address " |
135 |
"0x%x ]\n", (int)relative_addr); |
136 |
} |
137 |
} |
138 |
|
139 |
#if 0 |
140 |
|
141 |
TODO: This is from bt459! |
142 |
|
143 |
/* NetBSD uses 370,37 as magic values. */ |
144 |
new_cursor_x = (d->bt431_reg[BT431_REG_CXLO] & 255) + |
145 |
((d->bt431_reg[BT431_REG_CXHI] & 255) << 8) - 370; |
146 |
new_cursor_y = (d->bt431_reg[BT431_REG_CYLO] & 255) + |
147 |
((d->bt431_reg[BT431_REG_CYHI] & 255) << 8) - 37; |
148 |
|
149 |
/* TODO: what do the bits in the CCR do? */ |
150 |
on = d->bt431_reg[BT431_REG_CCR] ? 1 : 0; |
151 |
|
152 |
on = 1; |
153 |
|
154 |
if (new_cursor_x != d->cursor_x || new_cursor_y != d->cursor_y || |
155 |
on != d->cursor_on) { |
156 |
int ysize_mul = 1; |
157 |
|
158 |
d->cursor_x = new_cursor_x; |
159 |
d->cursor_y = new_cursor_y; |
160 |
d->cursor_on = on; |
161 |
|
162 |
/* |
163 |
* Ugly hack for Ultrix: |
164 |
* |
165 |
* Ultrix and NetBSD assume that the cursor works differently. |
166 |
* Ultrix uses the 370,38 coordinates, but draws the cursor |
167 |
* upwards. NetBSD draws it downwards. Ultrix also makes the |
168 |
* cursor smaller (?). |
169 |
* |
170 |
* TODO: This actually depends on which ultrix kernel you use. |
171 |
* Clearly, the BT459 emulation is not implemented well |
172 |
* enough yet. |
173 |
* |
174 |
* TODO: Find out why? Is it because of special BT459 |
175 |
* commands? |
176 |
* |
177 |
* TODO: Is the above text even valid anymore? :-) |
178 |
*/ |
179 |
if (!(d->bt431_reg[BT431_REG_CCR] & 1)) { |
180 |
/* ysize_mul = 4; */ |
181 |
d->cursor_y += 5 - (d->cursor_ysize * ysize_mul); |
182 |
} |
183 |
|
184 |
debug("[ bt431: cursor = %03i,%03i ]\n", d->cursor_x, |
185 |
d->cursor_y); |
186 |
dev_fb_setcursor(d->vfb_data, d->cursor_x, d->cursor_y, on, |
187 |
d->cursor_xsize, d->cursor_ysize * ysize_mul); |
188 |
} |
189 |
#endif |
190 |
|
191 |
if (writeflag == MEM_READ) |
192 |
memory_writemax64(cpu, data, len, odata); |
193 |
|
194 |
return 1; |
195 |
} |
196 |
|
197 |
|
198 |
/* |
199 |
* dev_bt431_init(): |
200 |
*/ |
201 |
void dev_bt431_init(struct memory *mem, uint64_t baseaddr, |
202 |
struct vfb_data *vfb_data, int planes) |
203 |
{ |
204 |
struct bt431_data *d = malloc(sizeof(struct bt431_data)); |
205 |
if (d == NULL) { |
206 |
fprintf(stderr, "out of memory\n"); |
207 |
exit(1); |
208 |
} |
209 |
memset(d, 0, sizeof(struct bt431_data)); |
210 |
d->vfb_data = vfb_data; |
211 |
d->planes = planes; |
212 |
d->cursor_x = -1; |
213 |
d->cursor_y = -1; |
214 |
d->cursor_xsize = d->cursor_ysize = 8; /* anything */ |
215 |
|
216 |
memory_device_register(mem, "bt431", baseaddr, DEV_BT431_LENGTH, |
217 |
dev_bt431_access, (void *)d, DM_DEFAULT, NULL); |
218 |
} |
219 |
|