-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicasso96.c
executable file
·3039 lines (2694 loc) · 92 KB
/
picasso96.c
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* UAE - The U*nix Amiga Emulator
*
* Picasso96 Support Module
*
* Copyright 1997-2001 Brian King <[email protected], [email protected]>
* Copyright 2000-2001 Bernd Roesch
* Copyright 2003-2005 Richard Drummond
*
* Theory of operation:
* On the Amiga side, a Picasso card consists mainly of a memory area that
* contains the frame buffer. On the UAE side, we allocate a block of memory
* that will hold the frame buffer. This block is in normal memory, it is
* never directly on the graphics card. All graphics operations, which are
* mainly reads and writes into this block and a few basic operations like
* filling a rectangle, operate on this block of memory.
* Since the memory is not on the graphics card, some work must be done to
* synchronize the display with the data in the Picasso frame buffer. There
* are various ways to do this. One possibility is to allocate a second
* buffer of the same size, and perform all write operations twice. Since
* we never read from the second buffer, it can actually be placed in video
* memory. The X11 driver could be made to use the Picasso frame buffer as
* the data buffer of an XImage, which could then be XPutImage()d from time
* to time. Another possibility is to translate all Picasso accesses into
* Xlib (or GDI, or whatever your graphics system is) calls. This possibility
* is a bit tricky, since there is a risk of generating very many single pixel
* accesses which may be rather slow.
*
* TODO:
* - we want to add a manual switch to override SetSwitch for hardware banging
* programs started from a Picasso workbench.
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "uae.h"
#include "memory.h"
#include "custom.h"
#include "newcpu.h"
#include "xwin.h"
#include "picasso96.h"
#ifdef JIT
int have_done_picasso = 0; /* For the JIT compiler */
# ifdef PICASSO96
static int picasso_is_special = PIC_WRITE; /* ditto */
static int picasso_is_special_read = PIC_READ; /* ditto */
# endif
#endif
#ifdef PICASSO96
static int p96syncrate;
int p96hsync_counter;
int p96hack_vpos, p96hack_vpos2, p96refresh_active;
#define P96TRACING_ENABLED 0
#if P96TRACING_ENABLED
#define P96TRACE(x) do { write_log x; } while(0)
#else
#define P96TRACE(x) do { ; } while(0)
#endif
static uae_u32 gfxmem_lget (uaecptr) REGPARAM;
static uae_u32 gfxmem_wget (uaecptr) REGPARAM;
static uae_u32 gfxmem_bget (uaecptr) REGPARAM;
static void gfxmem_lput (uaecptr, uae_u32) REGPARAM;
static void gfxmem_wput (uaecptr, uae_u32) REGPARAM;
static void gfxmem_bput (uaecptr, uae_u32) REGPARAM;
static int gfxmem_check (uaecptr addr, uae_u32 size) REGPARAM;
static uae_u8 *gfxmem_xlate (uaecptr addr) REGPARAM;
static uae_u8 all_ones_bitmap, all_zeros_bitmap;
struct picasso96_state_struct picasso96_state;
struct picasso_vidbuf_description picasso_vidinfo;
/* These are the maximum resolutions. They are filled in by
* GetSupportedResolutions() */
/* have to fill this in, otherwise problems occur
* @@@ ??? what problems?
*/
struct ScreenResolution planar = { 320, 240 };
struct ScreenResolution chunky = { 640, 480 };
struct ScreenResolution hicolour = { 640, 480 };
struct ScreenResolution truecolour = { 640, 480 };
struct ScreenResolution alphacolour = { 640, 480 };
uae_u16 picasso96_pixel_format = RGBFF_CHUNKY;
struct PicassoResolution DisplayModes[MAX_PICASSO_MODES];
static int mode_count = 0;
static int set_gc_called = 0;
static int set_panning_called = 0;
/* Address of the screen in the Amiga frame buffer at the time of the last
SetPanning call. */
//static uaecptr oldscr;
static uae_u32 p2ctab[256][2];
/*
* Picasso96 seems to have a bug which screws the palette emulation in
* ARGB32 modes. We work around this by using a BGRA32 framebuffer instead,
* and byte-swapping each pixel when output to the real screen
*/
static int need_argb32_hack = 0;
/* This stuff should probably be moved elsewhere */
#if (defined __powerpc__ || defined __ppc__ || defined __POWERPC__ \
|| defined __PPC__) && defined __GNUC__
STATIC_INLINE void memcpy_bswap32 (void *dst, void *src, int n)
{
int words = n / 4;
if (words > 1) {
uae_u32 tmp;
asm volatile (
"addi %2, %2, -1 \n\
mtctr %2 \n\
lwz %3, 0(%1) \n\
1: stwbrx %3, 0, %0 \n\
addi %0, %0, 4 \n\
lwzu %3, 4(%1) \n\
bdnz 1b \n\
stwbrx %3, 0, %0"
: "+r" (dst), "+r" (src), "+r" (words), "=r" (tmp)
:
: "ctr", "memory");
} else {
uae_u32 tmp;
asm volatile (
"lwz %2, 0(%1) \n\
stwbrx %2, 0, %0"
: "+r" (dst), "+r" (src), "=r" (tmp)
:
: "memory");
}
}
#else
STATIC_INLINE void memcpy_bswap32 (void *dst, void *src, int n)
{
int i = n / 4;
uae_u32 *dstp = (uae_u32 *)dst;
uae_u32 *srcp = (uae_u32 *)src;
for ( ; i; i--)
*dstp++ = bswap_32 (*srcp++);
}
#endif
/*
* Debugging dumps
*/
static void DumpModeInfoStructure (uaecptr amigamodeinfoptr)
{
write_log ("ModeInfo Structure Dump:\n");
write_log (" Node.ln_Succ = 0x%x\n", get_long (amigamodeinfoptr));
write_log (" Node.ln_Pred = 0x%x\n", get_long (amigamodeinfoptr + 4));
write_log (" Node.ln_Type = 0x%x\n", get_byte (amigamodeinfoptr + 8));
write_log (" Node.ln_Pri = %d\n", get_byte (amigamodeinfoptr + 9));
/*write_log (" Node.ln_Name = %s\n", uaememptr->Node.ln_Name); */
write_log (" OpenCount = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_OpenCount));
write_log (" Active = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Active));
write_log (" Width = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Width));
write_log (" Height = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_Height));
write_log (" Depth = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Depth));
write_log (" Flags = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_Flags));
write_log (" HorTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorTotal));
write_log (" HorBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorBlankSize));
write_log (" HorSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncStart));
write_log (" HorSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSize));
write_log (" HorSyncSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorSyncSkew));
write_log (" HorEnableSkew = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_HorEnableSkew));
write_log (" VerTotal = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerTotal));
write_log (" VerBlankSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerBlankSize));
write_log (" VerSyncStart = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncStart));
write_log (" VerSyncSize = %d\n", get_word (amigamodeinfoptr + PSSO_ModeInfo_VerSyncSize));
write_log (" Clock = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_first_union));
write_log (" ClockDivide = %d\n", get_byte (amigamodeinfoptr + PSSO_ModeInfo_second_union));
write_log (" PixelClock = %d\n", get_long (amigamodeinfoptr + PSSO_ModeInfo_PixelClock));
}
static void DumpLibResolutionStructure (uaecptr amigalibresptr)
{
int i;
uaecptr amigamodeinfoptr;
struct LibResolution *uaememptr = (struct LibResolution *)
get_mem_bank (amigalibresptr).xlateaddr (amigalibresptr);
return;
write_log ("LibResolution Structure Dump:\n");
if (get_long (amigalibresptr + PSSO_LibResolution_DisplayID) == 0xFFFFFFFF) {
write_log (" Finished With LibResolutions...\n");
} else {
write_log (" Name = %s\n", uaememptr->P96ID);
write_log (" DisplayID = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_DisplayID));
write_log (" Width = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Width));
write_log (" Height = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Height));
write_log (" Flags = %d\n", get_word (amigalibresptr + PSSO_LibResolution_Flags));
for (i = 0; i < MAXMODES; i++) {
amigamodeinfoptr = get_long (amigalibresptr + PSSO_LibResolution_Modes + i * 4);
write_log (" ModeInfo[%d] = 0x%x\n", i, amigamodeinfoptr);
if (amigamodeinfoptr)
DumpModeInfoStructure (amigamodeinfoptr);
}
write_log (" BoardInfo = 0x%x\n", get_long (amigalibresptr + PSSO_LibResolution_BoardInfo));
}
}
static char binary_byte[9];
static char *BuildBinaryString (uae_u8 value)
{
int i;
for (i = 0; i < 8; i++) {
binary_byte[i] = (value & (1 << (7 - i))) ? '#' : '.';
}
binary_byte[8] = '\0';
return binary_byte;
}
static void DumpPattern (struct Pattern *patt)
{
/*
uae_u8 *mem;
int row, col;
for (row = 0; row < (1 << patt->Size); row++) {
mem = patt->Memory + row * 2;
for (col = 0; col < 2; col++) {
write_log ("%s", BuildBinaryString (*mem++));
}
write_log ("\n");
}
*/
}
static void DumpTemplate (struct Template *tmp, uae_u16 w, uae_u16 h)
{
/*
uae_u8 *mem = tmp->Memory;
int row, col, width;
width = (w + 7) >> 3;
write_log ("xoffset = %d, bpr = %d\n", tmp->XOffset, tmp->BytesPerRow);
for (row = 0; row < h; row++) {
mem = tmp->Memory + row * tmp->BytesPerRow;
for (col = 0; col < width; col++) {
write_log ("%s", BuildBinaryString (*mem++));
}
write_log ("\n");
}
*/
}
int picasso_nr_resolutions (void)
{
return mode_count;
}
static void ShowSupportedResolutions (void)
{
int i;
return;
for (i = 0; i < mode_count; i++)
write_log ("%s\n", DisplayModes[i].name);
}
STATIC_INLINE uae_u8 GetBytesPerPixel (uae_u32 RGBfmt)
{
switch (RGBfmt) {
case RGBFB_CLUT:
return 1;
case RGBFB_A8R8G8B8:
case RGBFB_A8B8G8R8:
case RGBFB_R8G8B8A8:
case RGBFB_B8G8R8A8:
return 4;
case RGBFB_B8G8R8:
case RGBFB_R8G8B8:
return 3;
case RGBFB_R5G5B5:
case RGBFB_R5G6B5:
case RGBFB_R5G6B5PC:
case RGBFB_R5G5B5PC:
case RGBFB_B5G6R5PC:
case RGBFB_B5G5R5PC:
return 2;
default:
P96TRACE (("P96: ERROR - GetBytesPerPixel() was unsuccessful with 0x%x?!\n", RGBfmt));
return 0;
}
}
/*
* Amiga <-> native structure conversion functions
*/
static int CopyRenderInfoStructureA2U (uaecptr amigamemptr,
struct RenderInfo *ri)
{
uaecptr memp = get_long (amigamemptr + PSSO_RenderInfo_Memory);
if (valid_address (memp, PSSO_RenderInfo_sizeof)) {
ri->AMemory = memp;
ri->Memory = get_real_address (memp);
ri->BytesPerRow = get_word (amigamemptr + PSSO_RenderInfo_BytesPerRow);
ri->RGBFormat = get_long (amigamemptr + PSSO_RenderInfo_RGBFormat);
return 1;
}
write_log ("P96: ERROR - Invalid RenderInfo memory area.\n");
return 0;
}
static int CopyPatternStructureA2U (uaecptr amigamemptr,
struct Pattern *pattern)
{
uaecptr memp = get_long (amigamemptr + PSSO_Pattern_Memory);
if (valid_address (memp, PSSO_Pattern_sizeof)) {
pattern->Memory = get_real_address (memp);
pattern->XOffset = get_word (amigamemptr + PSSO_Pattern_XOffset);
pattern->YOffset = get_word (amigamemptr + PSSO_Pattern_YOffset);
pattern->FgPen = get_long (amigamemptr + PSSO_Pattern_FgPen);
pattern->BgPen = get_long (amigamemptr + PSSO_Pattern_BgPen);
pattern->Size = get_byte (amigamemptr + PSSO_Pattern_Size);
pattern->DrawMode = get_byte (amigamemptr + PSSO_Pattern_DrawMode);
return 1;
}
write_log ("P96: ERROR - Invalid Pattern memory area.\n");
return 0;
}
static void CopyColorIndexMappingA2U (uaecptr amigamemptr,
struct ColorIndexMapping *cim)
{
int i;
cim->ColorMask = get_long (amigamemptr);
for (i = 0; i < 256; i++, amigamemptr += 4)
cim->Colors[i] = get_long (amigamemptr + 4);
}
static int CopyBitMapStructureA2U (uaecptr amigamemptr, struct BitMap *bm)
{
int i;
bm->BytesPerRow = get_word (amigamemptr + PSSO_BitMap_BytesPerRow);
bm->Rows = get_word (amigamemptr + PSSO_BitMap_Rows);
bm->Flags = get_byte (amigamemptr + PSSO_BitMap_Flags);
bm->Depth = get_byte (amigamemptr + PSSO_BitMap_Depth);
if (bm->Depth > 8) {
write_log ("P96: WARNING - Can't handle %d-bit deep bitmap\n",
bm->Depth);
return 0;
}
for (i = 0; i < bm->Depth; i++) {
uaecptr plane = get_long (amigamemptr + PSSO_BitMap_Planes + i * 4);
switch (plane) {
case 0:
bm->Planes[i] = &all_zeros_bitmap;
break;
case 0xFFFFFFFF:
bm->Planes[i] = &all_ones_bitmap;
break;
default:
if (valid_address (plane, bm->BytesPerRow * bm->Rows))
bm->Planes[i] = get_real_address (plane);
else
return 0;
break;
}
}
return 1;
}
static int CopyTemplateStructureA2U (uaecptr amigamemptr,
struct Template *tmpl)
{
uaecptr memp = get_long (amigamemptr + PSSO_Template_Memory);
if (valid_address (memp, 1 /* FIXME */ )) {
tmpl->Memory = get_real_address (memp);
tmpl->BytesPerRow = get_word (amigamemptr + PSSO_Template_BytesPerRow);
tmpl->XOffset = get_byte (amigamemptr + PSSO_Template_XOffset);
tmpl->DrawMode = get_byte (amigamemptr + PSSO_Template_DrawMode);
tmpl->FgPen = get_long (amigamemptr + PSSO_Template_FgPen);
tmpl->BgPen = get_long (amigamemptr + PSSO_Template_BgPen);
return 1;
}
write_log ("P96: ERROR - Invalid Template memory area.\n");
return 0;
}
static void CopyLibResolutionStructureU2A (struct LibResolution *libres,
uaecptr amigamemptr)
{
uae_u8 *uaememptr = 0;
int i;
/* I know that amigamemptr is inside my gfxmem chunk, so I can just
* do the xlate() */
uaememptr = gfxmem_xlate (amigamemptr);
/* zero out our LibResolution structure */
memset (uaememptr, 0, PSSO_LibResolution_sizeof);
strcpy ((char*)uaememptr + PSSO_LibResolution_P96ID, libres->P96ID);
put_long (amigamemptr + PSSO_LibResolution_DisplayID, libres->DisplayID);
put_word (amigamemptr + PSSO_LibResolution_Width, libres->Width);
put_word (amigamemptr + PSSO_LibResolution_Height, libres->Height);
put_word (amigamemptr + PSSO_LibResolution_Flags, libres->Flags);
for (i = 0; i < MAXMODES; i++)
put_long (amigamemptr + PSSO_LibResolution_Modes + i * 4, libres->Modes[i]);
#if 0
put_long (amigamemptr, libres->Node.ln_Succ);
put_long (amigamemptr + 4, libres->Node.ln_Pred);
put_byte (amigamemptr + 8, libres->Node.ln_Type);
put_byte (amigamemptr + 9, libres->Node.ln_Pri);
#endif
put_long (amigamemptr + 10, amigamemptr + PSSO_LibResolution_P96ID);
put_long (amigamemptr + PSSO_LibResolution_BoardInfo, libres->BoardInfo);
}
/* l is Amiga address of list, in correct endian format for UAE
* n is Amiga address of node, in correct endian format for UAE */
static void AmigaListAddTail (uaecptr l, uaecptr n)
{
put_long (n + 0, l + 4); // n->ln_Succ = (struct Node *)&l->lh_Tail;
put_long (n + 4, get_long (l + 8)); // n->ln_Pred = l->lh_TailPred;
put_long (get_long (l + 8) + 0, n); // l->lh_TailPred->ln_Succ = n;
put_long (l + 8, n); // l->lh_TailPred = n;
}
/*
* Functions to perform an action on the real screen
*/
/*
* Fill a rectangle on the screen. src points to the start of a line of the
* filled rectangle in the frame buffer; it can be used as a memcpy source if
* there is no OS specific function to fill the rectangle.
*/
static void do_fillrect (uae_u8 *src, int x, int y, int width, int height,
uae_u32 pen, int Bpp, RGBFTYPE rgbtype)
{
uae_u8 *dst;
P96TRACE (("P96: do_fillrect (src:%08x x:%d y:%d w:%d h%d pen:%08x)\n",
src, x, y, width, height, pen));
/* Try OS specific fillrect function here; and return if successful. Make
* sure we adjust for the pen values if we're doing 8-bit
* display-emulation on a 16-bit or higher screen. */
if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
# ifndef WORDS_BIGENDIAN
if (Bpp > 1)
if (!(Bpp == 4 && need_argb32_hack))
pen = bswap_32 (pen);
# else
if (Bpp == 4 && need_argb32_hack)
pen = bswap_32 (pen);
# endif
if (DX_Fill (x, y, width, height, pen, rgbtype))
return;
} else {
if (DX_Fill (x, y, width, height, picasso_vidinfo.clut[src[0]], rgbtype))
return;
}
P96TRACE (("P96: WARNING - do_fillrect() using fall-back routine!\n"));
DX_Invalidate (y, y + height - 1);
if (!picasso_vidinfo.extra_mem)
return;
width *= picasso96_state.BytesPerPixel;
dst = gfx_lock_picasso ();
if (!dst)
goto out;
dst += y * picasso_vidinfo.rowbytes + x * picasso_vidinfo.pixbytes;
if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
if (Bpp == 1) {
while (height-- > 0) {
memset (dst, pen, width);
dst += picasso_vidinfo.rowbytes;
}
} else {
if (Bpp == 4 && need_argb32_hack) {
while (height-- > 0) {
memcpy_bswap32 (dst, src, width);
dst += picasso_vidinfo.rowbytes;
}
} else {
while (height-- > 0) {
memcpy (dst, src, width);
dst += picasso_vidinfo.rowbytes;
}
}
}
} else {
int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
abort ();
while (height-- > 0) {
int i;
switch (psiz) {
case 2:
for (i = 0; i < width; i++)
*((uae_u16 *) dst + i) = picasso_vidinfo.clut[src[i]];
break;
case 4:
for (i = 0; i < width; i++)
*((uae_u32 *) dst + i) = picasso_vidinfo.clut[src[i]];
break;
default:
abort ();
}
dst += picasso_vidinfo.rowbytes;
}
}
out:
gfx_unlock_picasso ();
}
/*
* This routine modifies the real screen buffer after a blit has been
* performed in the save area. If can_do_blit is nonzero, the blit can
* be performed within the real screen buffer; otherwise, this routine
* must do it by hand using the data in the save area, pointed to by
* srcp.
*/
static void do_blit (struct RenderInfo *ri, int Bpp, int srcx, int srcy,
int dstx, int dsty, int width, int height,
BLIT_OPCODE opcode, int can_do_blit)
{
int xoff = picasso96_state.XOffset;
int yoff = picasso96_state.YOffset;
uae_u8 *srcp, *dstp;
/* Clipping. */
dstx -= xoff;
dsty -= yoff;
if (srcy < yoff || srcx < xoff
|| srcx - xoff + width > picasso96_state.Width
|| srcy - yoff + height > picasso96_state.Height)
{
can_do_blit = 0;
}
if (dstx < 0) {
srcx -= dstx;
width += dstx;
dstx = 0;
}
if (dsty < 0) {
srcy -= dsty;
height += dsty;
dsty = 0;
}
if (dstx + width > picasso96_state.Width)
width = picasso96_state.Width - dstx;
if (dsty + height > picasso96_state.Height)
height = picasso96_state.Height - dsty;
if (width <= 0 || height <= 0)
return;
/* If this RenderInfo points at something else than the currently visible
* screen, we must ignore the blit. */
if (can_do_blit) {
/*
* Call OS blitting function that can do it in video memory.
* Should return if it was successful
*/
if (DX_Blit (srcx, srcy, dstx, dsty, width, height, opcode))
return;
}
/* If no OS blit available, we do a copy from the P96 framebuffer in Amiga
memory to the host's frame buffer. */
DX_Invalidate (dsty, dsty + height - 1);
if (!picasso_vidinfo.extra_mem)
return;
dstp = gfx_lock_picasso ();
if (dstp == 0)
goto out;
/* Since the blit has already been performed in the framebuffer, we only need
* to blit the updated area to the screen. Therefore we use the destination
* coordinates for the source rectangle in the framebuffer - not the source
* coordinates.
*/
srcp = ri->Memory + (dstx + xoff) * Bpp + (dsty + yoff) * ri->BytesPerRow;
dstp += dsty * picasso_vidinfo.rowbytes + dstx * picasso_vidinfo.pixbytes;
P96TRACE (("P96: do_blit with srcp 0x%x, dstp 0x%x, dst_rowbytes %d, srcx"
" %d, srcy %d, dstx %d, dsty %d, w %d, h %d, dst_pixbytes %d\n",
srcp, dstp, picasso_vidinfo.rowbytes, srcx, srcy, dstx, dsty,
width,height, picasso_vidinfo.pixbytes));
P96TRACE (("P96: gfxmem is at 0x%x\n", gfxmemory));
if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
width *= Bpp;
if (Bpp == 4 && need_argb32_hack) {
while (height-- > 0) {
memcpy_bswap32 (dstp, srcp, width);
srcp += ri->BytesPerRow;
dstp += picasso_vidinfo.rowbytes;
}
} else {
while (height-- > 0) {
memcpy (dstp, srcp, width);
srcp += ri->BytesPerRow;
dstp += picasso_vidinfo.rowbytes;
}
}
} else {
int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat);
if (picasso96_state.RGBFormat != RGBFB_CHUNKY)
abort ();
while (height-- > 0) {
int i;
switch (psiz) {
case 2:
for (i = 0; i < width; i++)
*((uae_u16 *) dstp + i) = picasso_vidinfo.clut[srcp[i]];
break;
case 4:
for (i = 0; i < width; i++)
*((uae_u32 *) dstp + i) = picasso_vidinfo.clut[srcp[i]];
break;
default:
abort ();
}
srcp += ri->BytesPerRow;
dstp += picasso_vidinfo.rowbytes;
}
}
out:
gfx_unlock_picasso ();
}
/*
* Invert a rectangle on the screen.
*/
static void do_invertrect (struct RenderInfo *ri, int Bpp, int x, int y,
int width, int height)
{
#if 0
/* Clipping. */
x -= picasso96_state.XOffset;
y -= picasso96_state.YOffset;
if (x < 0) {
width += x;
x = 0;
}
if (y < 0) {
height += y;
y = 0;
}
if (x + width > picasso96_state.Width)
width = picasso96_state.Width - x;
if (y + height > picasso96_state.Height)
height = picasso96_state.Height - y;
if (width <= 0 || height <= 0)
return;
#endif
/* TODO: Try OS specific invertrect function here; and return if successful. */
do_blit (ri, Bpp, x, y, x, y, width, height, BLIT_SRC, 0);
}
/*
* Successive writes to the P96 framebuffer frequently occur in the same line. We
* optimize for this case by not flushing each write immediately to the screen.
* Instead, we delay until data is written to a different framebuffer line.
* Then we flush the line containing the previous data written.
*/
/* When successive writes to the framebuffer occur on the same line, we need to
* remember these details about that line. Note: these are address in Amiga
* memory space.
*/
static uaecptr currline_start; /* start address of the line in the framebuffer */
static uaecptr currline_end; /* end address of the line in the framebuffer plus one */
static uaecptr currline_min; /* address of the left-most byte modified */
static uaecptr currline_max; /* address of the right-most byte modfied plus one */
static int currline_y; /* row number of this line */
/*
* Write line from the framebuffer to the screen
*
* scrp = Pointer to first byte in the source line to write
* line_no = Number of line to write (relative to visible screen).
* first_byte = Offset in bytes from start of line to first byte to write.
* byte_count = Number of bytes to write from source line.
*/
STATIC_INLINE void write_currline (uae_u8 *srcp, int line_no, int first_byte, int byte_count)
{
uae_u8 *dstp;
if ((dstp = gfx_lock_picasso ()) != 0) {
int Bpp = GetBytesPerPixel (picasso_vidinfo.rgbformat);
if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) {
dstp += line_no * picasso_vidinfo.rowbytes + first_byte;
if (need_argb32_hack && Bpp == 4)
memcpy_bswap32 (dstp, srcp, byte_count);
else
memcpy (dstp, srcp, byte_count);
} else {
dstp += line_no * picasso_vidinfo.rowbytes + first_byte * Bpp;
switch (Bpp) {
case 2: {
int i;
uae_u16 *dstp16 = (uae_u16*) dstp;
for (i = 0; i < byte_count; i++)
*dstp16++ = picasso_vidinfo.clut[srcp[i]];
break;
}
case 4: {
int i;
for (i = 0; i < byte_count; i++)
*((uae_u32 *) dstp + i) = picasso_vidinfo.clut[srcp[i]];
break;
}
}
}
gfx_unlock_picasso ();
}
}
static void flush_currline (void)
{
int line_no = currline_y - picasso96_state.YOffset;
/* We only need to flush this line to the screen if the line
* is acutally visible on screen */
if (line_no >= 0 && line_no < picasso96_state.Height) {
/* Tell the graphics system that this line needs to be
* redrawn */
DX_Invalidate (line_no, line_no);
/* If our graphics system uses a separate buffer, then
* that must be updated too */
if (picasso_vidinfo.extra_mem) {
uae_u8 fb_bpp = picasso96_state.BytesPerPixel;
int byte_count = (currline_max - currline_min);
int first_byte = currline_min - currline_start
- (picasso96_state.XOffset * fb_bpp);
uae_u8 *srcp = (currline_min - gfxmem_start) + gfxmemory;
if (first_byte < 0) {
byte_count += first_byte;
srcp += first_byte;
first_byte = 0;
}
if ((first_byte + byte_count) > (picasso96_state.Width * fb_bpp))
byte_count = picasso96_state.Width * fb_bpp - first_byte;
if (byte_count > 0)
write_currline (srcp, line_no, first_byte, byte_count);
}
}
currline_start = 0xFFFFFFFF;
}
STATIC_INLINE void wgfx_flushline (void)
{
if (currline_start == 0xFFFFFFFF || !picasso_on)
return;
flush_currline ();
}
STATIC_INLINE int renderinfo_is_current_screen (struct RenderInfo *ri)
{
if (!picasso_on)
return 0;
if (ri->Memory != gfxmemory + (picasso96_state.Address - gfxmem_start))
return 0;
return 1;
}
/* Clear our screen, since we've got a new Picasso screen-mode, and refresh
* with the proper contents. This is called on several occasions:
* 1. Amiga-->Picasso transition, via SetSwitch()
* 2. Picasso-->Picasso transition, via SetPanning().
* 3. whenever the graphics code notifies us that the screen contents have
* been lost.
*/
extern unsigned int new_beamcon0;
void picasso_refresh (int call_setpalette)
{
struct RenderInfo ri;
if (!picasso_on)
return;
{ // for higher P96 mousedraw rate
extern uae_u16 vtotal;
if (p96hack_vpos2) {
vtotal = p96hack_vpos2;
new_beamcon0 |= 0x80;
p96refresh_active=1;
} else new_beamcon0 |= 0x20;
}
#ifdef JIT
have_done_picasso=1;
#endif
/* Make sure that the first time we show a Picasso video mode, we don't
* blit any crap. We can do this by checking if we have an Address yet. */
if (picasso96_state.Address) {
unsigned int width, height;
/* blit the stuff from our static frame-buffer to the gfx-card */
ri.Memory = gfxmemory + (picasso96_state.Address - gfxmem_start);
ri.BytesPerRow = picasso96_state.BytesPerRow;
ri.RGBFormat = picasso96_state.RGBFormat;
if (set_panning_called) {
width = picasso96_state.VirtualWidth;
height = picasso96_state.VirtualHeight;
} else {
width = picasso96_state.Width;
height = picasso96_state.Height;
}
do_blit (&ri, picasso96_state.BytesPerPixel, 0, 0, 0, 0, width,
height, BLIT_SRC, 0);
} else
write_log ("P96: ERROR - picasso_refresh() can't refresh!\n");
}
/*
* Functions to perform an action on the frame-buffer
*/
STATIC_INLINE void do_blitrect_frame_buffer (struct RenderInfo *ri,
struct RenderInfo *dstri,
unsigned long srcx, unsigned long srcy,
unsigned long dstx, unsigned long dsty,
unsigned long width, unsigned long height,
uae_u8 mask, BLIT_OPCODE opcode)
{
uae_u8 *src, *dst, *tmp, *tmp2, *tmp3;
uae_u8 Bpp = GetBytesPerPixel (ri->RGBFormat);
unsigned long total_width = width * Bpp;
unsigned long linewidth = (total_width + 15) & ~15;
unsigned long lines;
/* int can_do_visible_blit = 0; */
src = ri->Memory + srcx*Bpp + srcy*ri->BytesPerRow;
dst = dstri->Memory + dstx*Bpp + dsty*dstri->BytesPerRow;
if (mask != 0xFF && Bpp > 1) {
P96TRACE (("P96: WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp));
}
if (mask == 0xFF || Bpp > 1) {
if( opcode == BLIT_SRC ) {
/* handle normal case efficiently */
if (ri->Memory == dstri->Memory && dsty == srcy) {
unsigned long i;
for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
memmove (dst, src, total_width);
} else if (dsty < srcy) {
unsigned long i;
for (i = 0; i < height; i++, src += ri->BytesPerRow, dst += dstri->BytesPerRow)
memcpy (dst, src, total_width);
} else {
unsigned long i;
src += (height-1) * ri->BytesPerRow;
dst += (height-1) * dstri->BytesPerRow;
for (i = 0; i < height; i++, src -= ri->BytesPerRow, dst -= dstri->BytesPerRow)
memcpy (dst, src, total_width);
}
return;
} else {
uae_u8 *src2 = src;
uae_u8 *dst2 = dst;
uae_u32 *src2_32 = (uae_u32*)src;
uae_u32 *dst2_32 = (uae_u32*)dst;
unsigned int y;
for (y = 0; y < height; y++) {
uae_u32 *bound = (uae_u32 *)(src + total_width - 4);
//copy now the longs
for (src2_32 = (uae_u32*)src, dst2_32 = (uae_u32*)dst; src2_32 < bound; src2_32++, dst2_32++ ) {
switch ((uae_u8) opcode) {
case BLIT_FALSE:
*dst2_32 = 0;
break;
case BLIT_NOR:
*dst2_32 = ~(*src2_32 | *dst2_32);
break;
case BLIT_ONLYDST:
*dst2_32 = *dst2_32 & ~(*src2_32);
break;
case BLIT_NOTSRC:
*dst2_32 = ~(*src2_32);
break;
case BLIT_ONLYSRC:
*dst2_32 = *src2_32 & ~(*dst2_32);
break;
case BLIT_NOTDST:
*dst2_32 = ~(*dst2_32);
break;
case BLIT_EOR:
*dst2_32 = *src2_32 ^ *dst2_32;
break;
case BLIT_NAND:
*dst2_32 = ~(*src2_32 & *dst2_32);
break;
case BLIT_AND:
*dst2_32 = *src2_32 & *dst2_32;
break;
case BLIT_NEOR:
*dst2_32 = ~(*src2_32 ^ *dst2_32);
break;
case BLIT_DST:
write_log ("P96: ERROR - do_blitrect_frame_buffer shouldn't get BLIT_DST!\n");
break;
case BLIT_NOTONLYSRC:
*dst2_32 = ~(*src2_32) | *dst2_32;
break;
case BLIT_SRC:
write_log ("P96: ERROR - do_blitrect_frame_buffer shouldn't get BLIT_SRC!\n");
break;
case BLIT_NOTONLYDST:
*dst2_32 = ~(*dst2_32) | *src2_32;
break;
case BLIT_OR:
*dst2_32 = *src2_32 | *dst2_32;
break;
case BLIT_TRUE:
*dst2_32 = 0xFFFFFFFF;
break;
case 30: {
/* code for swap source with dest in byte */
uae_u32 temp;
temp = *src2_32;
*src2_32 = *dst2_32;
*dst2_32 = temp;
break;
}
case BLIT_LAST:
write_log( "P96: ERROR - do_blitrect_frame_buffer shouldn't get BLIT_LAST!\n");
break;
} /* switch opcode */
} // for end
//now copy the rest few bytes
for (src2 = (uae_u8*)src2_32, dst2 = (uae_u8*)dst2_32; src2 < src + total_width; src2++, dst2++ ) {
switch ((uae_u8)opcode) {
case BLIT_FALSE:
*dst2 = 0;
break;
case BLIT_NOR:
*dst2 = ~(*src2 | *dst2);
break;
case BLIT_ONLYDST:
*dst2 = *dst2 & ~(*src2);
break;
case BLIT_NOTSRC:
*dst2 = ~(*src2);
break;
case BLIT_ONLYSRC:
*dst2 = *src2 & ~(*dst2);
break;
case BLIT_NOTDST: