forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
framebufferboards.cpp
504 lines (450 loc) · 10.7 KB
/
framebufferboards.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
* UAE - The Un*x Amiga Emulator
*
* Misc frame buffer boards
*
* - Harlequin
*
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "debug.h"
#include "memory.h"
#include "custom.h"
#include "picasso96.h"
#include "gfxboard.h"
#include "statusline.h"
#include "rommgr.h"
#include "framebufferboards.h"
#include "xwin.h"
typedef uae_u32(REGPARAM3 *fb_get_func)(struct fb_struct *, uaecptr) REGPARAM;
typedef void (REGPARAM3 *fb_put_func)(struct fb_struct *, uaecptr, uae_u32) REGPARAM;
extern addrbank generic_fb_bank;
struct fb_struct
{
int devnum;
int monitor_id;
uae_u32 configured;
uae_u32 io_start, io_end;
uae_u8 data[16];
bool enabled;
bool modechanged;
bool visible;
int width, height;
bool lace;
RGBFTYPE rgbtype;
int fb_offset;
int fb_offset_limit;
int fb_vram_mask;
int fb_vram_size;
bool fb_modified;
uae_u8 *fb;
uae_u8 *surface;
bool isalpha;
bool ntsc;
bool genlock;
int model;
int irq;
fb_get_func lget, wget, bget;
fb_put_func lput, wput, bput;
};
static struct fb_struct *fb_data[MAX_RTG_BOARDS];
static int fb_boards;
static struct fb_struct *fb_last;
static bool fb_get_surface(struct fb_struct *data)
{
struct amigadisplay *ad = &adisplays[data->monitor_id];
bool gotsurf = false;
if (ad->picasso_on) {
if (data->surface == NULL) {
data->surface = gfx_lock_picasso(data->monitor_id, false, false);
gotsurf = true;
}
if (data->surface && gotsurf) {
if (softstatusline())
picasso_statusline(data->monitor_id, data->surface);
}
}
return data->surface != NULL;
}
static void fb_free_surface(struct fb_struct *data)
{
if (!data->surface)
return;
gfx_unlock_picasso(data->monitor_id, true);
data->surface = NULL;
}
static void harlequin_offset(struct fb_struct *data)
{
int offset = data->data[0] & 0x3f;
data->fb_offset = offset * 65536;
}
static void harlequin_setmode(struct fb_struct *data)
{
int mode = data->data[1] & 3;
switch (mode)
{
case 0:
case 3:
data->width = 910;
break;
case 1:
data->width = 832;
break;
case 2:
data->width = 740;
break;
}
data->lace = (data->data[1] & 8) != 0;
data->height = data->ntsc ? 486 : 576;
}
static void REGPARAM2 harlequin_wput(struct fb_struct *data, uaecptr addr, uae_u32 w)
{
addr &= 0x1ffff;
if (addr == 0) {
uae_u8 old0 = data->data[0];
uae_u8 old1 = data->data[1];
data->data[0] = (uae_u8)(w >> 8);
data->data[1] = (uae_u8)(w >> 0);
data->data[0] &= ~0x80;
data->data[0] |= data->genlock ? 0x00 : 0x80;
if ((data->data[0] & 0x40) != (old0 & 0x40))
data->fb_modified = true;
if (data->data[1] != old1)
data->fb_modified = true;
harlequin_offset(data);
harlequin_setmode(data);
} else if (addr >= 0x10000) {
if (data->fb_offset >= data->fb_offset_limit)
return;
addr -= 0x10000;
if (!data->isalpha) {
if ((addr & 3) == 2)
w &= 0xff00;
if ((addr & 3) == 3)
w &= 0x00ff;
}
data->fb[data->fb_offset + addr + 0] = (uae_u8)(w >> 8);
data->fb[data->fb_offset + addr + 1] = (uae_u8)(w >> 0);
data->fb_modified = true;
}
}
static void REGPARAM2 harlequin_bput(struct fb_struct *data, uaecptr addr, uae_u32 b)
{
addr &= 0x1ffff;
if (addr == 2) {
data->data[2] = b;
data->irq = 0;
} else if (addr >= 0x20 && addr < 0x30) {
write_log(_T("RAMDAC WRITE %0x = %02x\n"), addr, (uae_u8)b);
} else if (addr >= 0x10000) {
if (data->fb_offset >= data->fb_offset_limit)
return;
addr -= 0x10000;
if (!data->isalpha && (addr & 3) == 3)
b = 0;
data->fb[data->fb_offset + addr] = (uae_u8)b;
data->fb_modified = true;
}
}
static uae_u32 REGPARAM2 harlequin_wget(struct fb_struct *data, uaecptr addr)
{
uae_u16 v = 0;
addr &= 0x1ffff;
if (addr == 0) {
v = (data->data[0] << 8) | (data->data[1] << 0);
} else if (addr >= 0x10000) {
if (data->fb_offset >= data->fb_offset_limit)
return 0;
addr -= 0x10000;
v = data->fb[data->fb_offset + addr + 0] << 8;
v |= data->fb[data->fb_offset + addr + 1] << 0;
}
return v;
}
static uae_u32 REGPARAM2 harlequin_bget(struct fb_struct *data, uaecptr addr)
{
uae_u8 v = 0;
addr &= 0x1ffff;
if (addr == 0 || addr == 1 || addr == 2) {
v = data->data[addr];
} else if (addr >= 0x20 && addr < 0x30) {
write_log(_T("RAMDAC READ %0x\n"), addr);
} else if (addr >= 0x10000) {
if (data->fb_offset >= data->fb_offset_limit)
return 0;
addr -= 0x10000;
v = data->fb[data->fb_offset + addr];
}
return 0;
}
static bool harlequin_init(struct autoconfig_info *aci)
{
uae_u8 model = 100;
int vram = 0x200000;
bool isac = true;
bool ntsc = false;
aci->label = _T("Harlequin");
struct boardromconfig *brc = get_device_rom(aci->prefs, ROMTYPE_HARLEQUIN, gfxboard_get_devnum(aci->prefs, aci->devnum), NULL);
if (brc) {
model = (brc->roms[0].device_settings & 3) + 100;
ntsc = (model & 1) != 0;
}
aci->autoconfig_bytes[1] = model;
if (!aci->doinit) {
return true;
}
struct fb_struct *data = xcalloc(struct fb_struct, 1);
data->devnum = aci->devnum;
fb_data[data->devnum] = data;
data->bget = harlequin_bget;
data->wget = harlequin_wget;
data->bput = harlequin_bput;
data->wput = harlequin_wput;
if (brc) {
switch((brc->roms[0].device_settings >> 2) & 3)
{
case 0: // 1.5M
vram = 0x200000;
isac = false;
break;
case 1: // 2M
vram = 0x200000;
isac = true;
break;
case 2: // 3M
vram = 0x400000;
isac = false;
break;
case 3: // 4M
vram = 0x400000;
isac = true;
break;
}
data->genlock = ((brc->roms[0].device_settings >> 4) & 1) != 0;
}
data->model = model;
data->ntsc = ntsc;
data->isalpha = isac;
data->fb_vram_size = vram;
data->fb_vram_mask = data->fb_vram_size - 1;
data->fb_offset_limit = vram;
data->fb = xcalloc(uae_u8, data->fb_vram_size);
data->rgbtype = RGBFB_R8G8B8A8;
harlequin_setmode(data);
aci->addrbank = &generic_fb_bank;
aci->userdata = data;
fb_boards++;
return true;
}
static void harlequin_free(void *userdata)
{
struct fb_struct *data = (struct fb_struct*)userdata;
fb_free_surface(data);
xfree(data->fb);
data->fb = NULL;
fb_data[data->devnum] = NULL;
xfree(data);
}
static void fb_irq(struct fb_struct *data)
{
if (!data->irq)
return;
if (data->irq == 2)
INTREQ_0(0x8000 | 0x0008);
else if (data->irq == 6)
INTREQ_0(0x8000 | 0x2000);
}
static void harlequin_reset(void *userdata)
{
struct fb_struct *data = (struct fb_struct*)userdata;
fb_boards = 0;
fb_last = NULL;
}
static void harlequin_hsync(void *userdata)
{
struct fb_struct *data = (struct fb_struct*)userdata;
fb_irq(data);
}
static void harlequin_convert(struct fb_struct *data)
{
struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[data->monitor_id];
bool r = (data->data[1] & 0x80) != 0;
bool g = (data->data[1] & 0x40) != 0;
bool b = (data->data[1] & 0x20) != 0;
int buf = (data->data[0] & 0x40) ? 1 : 0;
int offset = 0, laceoffset = 0;
int laceoffsetv = (data->width * data->height / 2) * 4;
if (buf && data->fb_vram_size > 0x200000)
offset += data->fb_vram_size / 2;
int sy = 0;
int w = vidinfo->width < data->width ? vidinfo->width : data->width;
int h = vidinfo->height < data->height ? vidinfo->height : data->height;
for (int y = 0; y < h; y++) {
uae_u8 *s = data->fb + offset + laceoffset + sy * data->width * 4;
if (r && g && b) {
fb_copyrow(data->monitor_id, s, data->surface, 0, 0, data->width, 4, y);
} else {
uae_u8 tmp[1000 * 4];
uae_u8 *d = tmp;
for (int x = 0; x < w * 4; x += 4) {
d[x + 0] = r ? s[x + 0] : 0;
d[x + 1] = g ? s[x + 1] : 0;
d[x + 2] = b ? s[x + 2] : 0;
d[x + 3] = 0;
}
fb_copyrow(data->monitor_id, d, data->surface, 0, 0, data->width, 4, y);
}
if (data->lace) {
laceoffset = laceoffset ? 0 : laceoffsetv;
if (!laceoffset)
sy++;
} else {
sy++;
}
}
}
static bool harlequin_vsync(void *userdata, struct gfxboard_mode *mode)
{
struct fb_struct *data = (struct fb_struct*)userdata;
bool rendered = false;
if (data->model >= 102) {
data->data[2] |= 0x80;
if (data->data[2] & 0x40) {
data->irq = 2;
fb_irq(data);
}
}
if (data->visible) {
mode->width = data->width;
mode->height = data->height;
mode->mode = data->rgbtype;
if (fb_get_surface(data)) {
if (data->fb_modified || data->modechanged || mode->redraw_required) {
data->fb_modified = false;
data->modechanged = false;
harlequin_convert(data);
}
fb_free_surface(data);
rendered = true;
}
}
return rendered;
}
static bool harlequin_toggle(void *userdata, int mode)
{
struct fb_struct *data = (struct fb_struct*)userdata;
if (!data->configured)
return false;
if (!mode) {
if (!data->enabled)
return false;
data->enabled = false;
data->modechanged = false;
data->visible = false;
return true;
} else {
if (data->enabled)
return false;
data->enabled = true;
data->modechanged = true;
data->visible = true;
return true;
}
return false;
}
static void harlequin_configured(void *userdata, uae_u32 address)
{
struct fb_struct *data = (struct fb_struct*)userdata;
data->configured = address;
data->io_start = address;
data->io_end = data->io_start + 0x20000;
}
static struct fb_struct *getfbboard(uaecptr addr)
{
if (fb_boards == 1)
return fb_data[0];
if (fb_last && addr >= fb_last->io_start && addr <fb_last->io_end)
return fb_last;
for (int i = 0; i < MAX_RTG_BOARDS; i++) {
struct fb_struct *fb = fb_data[i];
if (!fb)
continue;
if (!fb->configured)
continue;
if (addr >= fb->io_start && addr < fb->io_end) {
fb_last = fb;
return fb;
}
}
return NULL;
}
static void REGPARAM2 fb_lput(uaecptr addr, uae_u32 w)
{
struct fb_struct *data = getfbboard(addr);
if (data) {
data->wput(data, addr + 0, w >> 16);
data->wput(data, addr + 2, w & 65535);
}
}
static void REGPARAM2 fb_wput(uaecptr addr, uae_u32 w)
{
struct fb_struct *data = getfbboard(addr);
if (data) {
data->wput(data, addr, w);
}
}
static void REGPARAM2 fb_bput(uaecptr addr, uae_u32 w)
{
struct fb_struct *data = getfbboard(addr);
if (data) {
data->bput(data, addr, w);
}
}
static uae_u32 REGPARAM2 fb_bget(uaecptr addr)
{
uae_u32 v = 0;
struct fb_struct *data = getfbboard(addr);
if (data) {
v = data->bget(data, addr);
}
return v;
}
static uae_u32 REGPARAM2 fb_wget(uaecptr addr)
{
uae_u32 v = 0;
struct fb_struct *data = getfbboard(addr);
if (data) {
v = data->wget(data, addr);
}
return v;
}
static uae_u32 REGPARAM2 fb_lget(uaecptr addr)
{
uae_u32 v = 0;
struct fb_struct *data = getfbboard(addr);
if (data) {
v = data->wget(data, addr) << 16;
v |= data->wget(data, addr + 2);
}
return v;
}
static addrbank generic_fb_bank
{
fb_lget, fb_wget, fb_bget,
fb_lput, fb_wput, fb_bput,
default_xlate, default_check, NULL, NULL, _T("FRAMEBUFFER BOARD"),
fb_lget, fb_wget,
ABFLAG_IO, S_READ, S_WRITE
};
struct gfxboard_func harlequin_func
{
harlequin_init,
harlequin_free,
harlequin_reset,
harlequin_hsync,
harlequin_vsync,
harlequin_toggle,
harlequin_configured
};