-
Notifications
You must be signed in to change notification settings - Fork 91
/
drawing.cpp
5992 lines (5400 loc) · 151 KB
/
drawing.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
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 Un*x Amiga Emulator
*
* Screen drawing functions
*
* Copyright 1995-2000 Bernd Schmidt
* Copyright 1995 Alessandro Bissacco
* Copyright 2000-2024 Toni Wilen
*
* Complete rewrite 2024
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include <assert.h>
#include "options.h"
#include "threaddep/thread.h"
#include "uae.h"
#include "memory.h"
#include "custom.h"
#include "newcpu.h"
#include "xwin.h"
#include "autoconf.h"
#include "gui.h"
#include "picasso96.h"
#include "drawing.h"
#include "savestate.h"
#include "statusline.h"
#include "inputdevice.h"
#include "debug.h"
#ifdef CD32
#include "cd32_fmv.h"
#endif
#include "specialmonitors.h"
#include "devices.h"
#include "gfxboard.h"
#define AUTOSCALE_SPRITES 1
#define LOL_SHIFT_COLORS 0
struct amigadisplay adisplays[MAX_AMIGADISPLAYS];
typedef enum
{
CMODE_NORMAL,
CMODE_DUALPF,
CMODE_EXTRAHB,
CMODE_HAM,
CMODE_EXTRAHB_ECS_KILLEHB
} CMODE_T;
static void select_lts(void);
extern int sprite_buffer_res;
static int lores_factor;
int lores_shift, shres_shift;
static uae_u32 ham_lastcolor;
int debug_bpl_mask = 0xff, debug_bpl_mask_one;
/* mirror of chipset_mask */
bool ecs_agnus;
bool ecs_denise, ecs_denise_only;
bool aga_mode;
bool agnusa1000;
bool denisea1000_noehb;
bool denisea1000;
bool direct_rgb;
/* The shift factor to apply when converting between Amiga coordinates and window
coordinates. Zero if the resolution is the same, positive if window coordinates
have a higher resolution (i.e. we're stretching the image), negative if window
coordinates have a lower resolution (i.e. we're shrinking the image). */
static int res_shift;
static int linedbl, linedbld;
int interlace_seen;
int detected_screen_resolution;
#define AUTO_LORES_FRAMES 10
static int can_use_lores = 0, frame_res, frame_res_lace;
static int resolution_count[RES_MAX + 1], lines_count;
static int center_reset;
static bool init_genlock_data;
bool need_genlock_data;
/* Lookup tables for dual playfields. The dblpf_*1 versions are for the case
that playfield 1 has the priority, dbplpf_*2 are used if playfield 2 has
priority. If we need an array for non-dual playfield mode, it has no number. */
/* The dbplpf_ms? arrays contain a shift value. plf_spritemask is initialized
to contain two 16 bit words, with the appropriate mask if pf1 is in the
foreground being at bit offset 0, the one used if pf2 is in front being at
offset 16. */
static int dblpf_ms1[256], dblpf_ms2[256], dblpf_ms[256];
static int dblpf_ind1[256], dblpf_ind2[256];
static int dblpf_2nd1[256], dblpf_2nd2[256];
static const int dblpfofs[] = { 0, 2, 4, 8, 16, 32, 64, 128 };
static int sprite_offs[256];
/* Video buffer description structure. Filled in by the graphics system
* dependent code. */
/* OCS/ECS color lookup table. */
xcolnr xcolors[4096];
#ifdef AGA
/* AGA mode color lookup tables */
unsigned int xredcolors[256], xgreencolors[256], xbluecolors[256];
static int dblpf_ind1_aga[256], dblpf_ind2_aga[256];
#else
static uae_u8 spriteagadpfpixels[1];
static int dblpf_ind1_aga[1], dblpf_ind2_aga[1];
#endif
int xredcolor_s, xredcolor_b, xredcolor_m;
int xgreencolor_s, xgreencolor_b, xgreencolor_m;
int xbluecolor_s, xbluecolor_b, xbluecolor_m;
xcolnr fullblack;
static struct color_entry direct_colors_for_drawing_bypass;
static xcolnr *p_acolors;
static xcolnr *p_xcolors;
static uae_u8 *refresh_indicator_buffer;
static uae_u8 *refresh_indicator_changed, *refresh_indicator_changed_prev;
static int refresh_indicator_height;
uae_u8 *xlinebuffer, *xlinebuffer2;
uae_u16 *xlinebuffer_genlock;
static int *amiga2aspect_line_map, *native2amiga_line_map;
static int native2amiga_line_map_height;
static uae_u8 **row_map;
static uae_u16 *row_map_genlock_buffer;
static uae_u8 row_tmp8[MAX_PIXELS_PER_LINE * 32 / 8];
static uae_u16 row_tmp16[MAX_PIXELS_PER_LINE * 32 / 8];
static int max_drawn_amiga_line;
uae_u16 **row_map_genlock;
uae_u8 *row_map_color_burst_buffer;
/* Centering variables. */
static int min_diwstart, max_diwstop;
/* The visible window: VISIBLE_LEFT_BORDER contains the left border of the visible
area, VISIBLE_RIGHT_BORDER the right border. These are in window coordinates. */
int visible_left_border, visible_right_border;
/* Pixels outside of visible_start and visible_stop are always black */
static int visible_left_start, visible_right_stop;
static int visible_top_start, visible_bottom_stop;
bool exthblanken;
static int exthblank;
static bool syncdebug;
static int linetoscr_x_adjust_pixbytes, linetoscr_x_adjust_pixels;
static int thisframe_y_adjust;
static int thisframe_y_adjust_real, min_ypos_for_screen;
static int max_ypos_thisframe1;
int thisframe_first_drawn_line, thisframe_last_drawn_line;
static int drawing_blank_start, drawing_blank_end;
/* A frame counter that forces a redraw after at least one skipped frame in
interlace mode. */
static int last_redraw_point;
#define MAX_STOP 30000
static int first_drawn_line, last_drawn_line;
/* These are generated by the drawing code from the line_decisions array for
each line that needs to be drawn. These are basically extracted out of
bit fields in the hardware registers. */
static int bplmode, bplmode_new;
static bool bplehb_eke, bplham, bplehb, bpldualpf, bpldualpfpri;
static uae_u8 bplehb_mask;
static int bpldualpf2of, bplplanecnt, bplmaxplanecnt, ecsshres;
static int bplbypass, bplcolorburst, bplcolorburst_field;
static int bplres;
static int plf1pri, plf2pri, bpland;
static uae_u32 plf_sprite_mask;
static int sbasecol[2], sbasecol2[2];
static bool ecs_genlock_features_active;
static uae_u8 ecs_genlock_features_mask;
static bool ecs_genlock_features_colorkey;
static bool aga_genlock_features_zdclken;
uae_sem_t gui_sem;
static int rga_denise_fast_read, rga_denise_fast_write;
#define DENISE_RGA_SLOT_FAST_TOTAL 1024
static struct denise_rga rga_denise_fast[DENISE_RGA_SLOT_FAST_TOTAL];
typedef void (*LINETOSRC_FUNC)(void);
static LINETOSRC_FUNC lts;
static bool lts_changed, lts_request;
static int denise_hcounter, denise_hcounter_next, denise_hcounter_new, denise_hcounter_prev;
static uae_u32 bplxdat[MAX_PLANES], bplxdat2[MAX_PLANES], bplxdat3[MAX_PLANES];
static uae_u64 bplxdat_64[MAX_PLANES], bplxdat2_64[MAX_PLANES], bplxdat3_64[MAX_PLANES];
static uae_u16 bplcon0_denise, bplcon1_denise, bplcon2_denise, bplcon3_denise, bplcon4_denise;
static uae_u8 bplcon4_denise_xor_val, bplcon4_denise_sbase, bplcon4_denise_xor_val2;
static int bplcon1_shift[2], bplcon1_shift_full[2], bplcon1_shift_full_masked[2], bplshiftcnt[2];
static int bplcon1_shift_mask, bplcon1_shift_mask_full;
static int denise_res, denise_res_size;
static uae_u16 denise_diwstrt, denise_diwstop;
static int denise_hstrt, denise_hstop, denise_diwhigh, denise_diwhigh2;
static int denise_brdstrt, denise_brdstop;
static int denise_brdstrt_lores, denise_brdstop_lores;
static bool denise_brdstrt_unalign, denise_brdstop_unalign;
static int denise_hstrt_lores, denise_hstop_lores;
static bool denise_hstrt_unalign, denise_hstop_unalign, denise_phbstrt_unalign, denise_phbstop_unalign;
static int denise_hbstrt_lores, denise_hbstop_lores;
static int denise_strlong_lores, denise_strlong_hd;
static bool denise_strlong_unalign, strlong_emulation;
static int denise_phbstrt, denise_phbstop, denise_phbstrt_lores, denise_phbstop_lores;
static int linear_denise_vbstrt, linear_denise_vbstop;
static int linear_denise_hbstrt, linear_denise_hbstop;
static int denise_visible_lines;
static uae_u16 hbstrt_denise_reg, hbstop_denise_reg;
static uae_u16 fmode_denise, denise_bplfmode, denise_sprfmode;
static bool denise_sprfmode64, denise_bplfmode64;
static int bpldat_fmode;
static int fetchmode_size_denise, fetchmode_mask_denise;
static int delayed_vblank_ecs;
static bool denise_hdiw, denise_hblank, denise_phblank, denise_vblank, denise_pvblank;
static bool denise_blank_active, denise_blank_active2, denise_hblank_active, denise_vblank_active;
static bool debug_special_csync, debug_special_hvsync;
static bool exthblankon_ecs, exthblankon_ecsonly, exthblankon_aga;
static bool denise_csync, denise_vsync, denise_hsync, denise_blank_enabled;
static bool denise_csync_blanken, denise_csync_blanken2;
static bool diwhigh_written;
struct color_entry denise_colors;
static bool bpl1dat_trigger, bpl1dat_copy;
static uae_u32 bordercolor, bordercolor_ecs_shres;
static int sprites_hidden, sprites_hidden2, sprite_hidden_mask;
static bool bordersprite, borderblank, bordertrans;
static bool bpldat_copy[2];
static int denise_planes, denise_max_planes;
static bool denise_odd_even, denise_max_odd_even;
static int pix_prev;
static int last_bpl_pix;
static int previous_strobe, previous_strobe_flag;
static bool denise_strlong, agnus_lol, extblank;
static int lol;
static int denise_lol_shift_prev, denise_lol_shifted_prev;
static int decode_specials, decode_specials_debug;
static int *dpf_lookup, *dpf_lookup_no;
static int denise_sprres, denise_spr_add, denise_spr_shiftsize;
static int denise_xposmask, denise_xposmask_lores, denise_xposmask_mask_lores;
static uae_u16 clxcon, clxcon2;
static int clxcon_bpl_enable_o, clxcon_bpl_match_o;
static int clxcon_bpl_enable, clxcon_bpl_match;
static uae_u16 clxcon_bpl_enable_55, clxcon_bpl_enable_aa;
static uae_u16 clxcon_bpl_match_55, clxcon_bpl_match_aa;
static int aga_delayed_color_idx;
static uae_u16 aga_delayed_color_val, aga_delayed_color_con2, aga_delayed_color_con3;
static int aga_unalign0, aga_unalign1, bpl1dat_unalign, reswitch_unalign;
static uae_u8 loaded_pix, loaded_pixs[4];
static int hresolution, hresolution_add;
static bool denise_sprite_blank_active;
static int delayed_sprite_vblank_ecs;
static bool denise_burst;
static int *debug_dma_dhpos_odd;
static struct dma_rec *debug_dma_ptr;
static int denise_cycle_half;
static int denise_vblank_extra, denise_vblank_extra_vbstrt, denise_vblank_extra_vbstop;
static uae_u32 dtbuf[2][4];
static uae_u16 dtgbuf[2][4];
struct denise_spr
{
int num;
uae_u16 pos, ctl;
uae_u32 dataa, datab;
uae_u64 dataa64, datab64;
int xpos, xpos_lores;
int armed, armeds;
uae_u32 dataas, databs;
uae_u64 dataas64, databs64;
bool attached;
bool shiftercopydone;
int fmode;
int shift;
int pix;
};
static struct denise_spr dspr[MAX_SPRITES];
static struct denise_spr *dprspt[MAX_SPRITES + 1], *dprspts[MAX_SPRITES + 1];
static int denise_spr_nr_armed, denise_spr_nr_armeds;
static uae_u16 bplcoltable[256];
static uae_u16 sprcoltable[256];
static uae_u16 sprbplcoltable[256];
static uae_u8 sprcolmask;
static int denise_spr_nearestcnt;
static int denise_y_start, denise_y_end;
static int denise_pixtotal, denise_linecnt, denise_startpos, denise_cck, denise_total;
static uae_u32 *buf1, *buf2, *buf_d;
static uae_u16 *gbuf;
static uae_u8 pixx0, pixx1, pixx2, pixx3;
static uae_u32 debug_buf[256 * 2 * 4], debug_bufx[256 * 2 * 4];
static uae_u32 *hbstrt_ptr1, *hbstrt_ptr2;
static uae_u32 *hbstop_ptr1, *hbstop_ptr2;
void set_inhibit_frame(int monid, int bit)
{
struct amigadisplay *ad = &adisplays[monid];
ad->inhibit_frame |= 1 << bit;
}
void clear_inhibit_frame(int monid, int bit)
{
struct amigadisplay *ad = &adisplays[monid];
ad->inhibit_frame &= ~(1 << bit);
}
void toggle_inhibit_frame(int monid, int bit)
{
struct amigadisplay *ad = &adisplays[monid];
ad->inhibit_frame ^= 1 << bit;
}
static void clearbuffer(struct vidbuffer *dst)
{
if (!dst->bufmem_allocated)
return;
uae_u8 *p = dst->bufmem_allocated;
for (int y = 0; y < dst->height_allocated; y++) {
memset (p, 0, dst->width_allocated * dst->pixbytes);
p += dst->rowbytes;
}
}
static void count_frame(int monid)
{
struct amigadisplay *ad = &adisplays[monid];
ad->framecnt++;
if (ad->framecnt >= currprefs.gfx_framerate || currprefs.monitoremu == MONITOREMU_A2024)
ad->framecnt = 0;
if (ad->inhibit_frame)
ad->framecnt = 1;
}
STATIC_INLINE int xshift (int x, int shift)
{
if (shift < 0)
return x >> (-shift);
else
return x << shift;
}
int coord_native_to_amiga_x (int x)
{
return 0;
/*
x += visible_left_border;
x = xshift (x, 1 - lores_shift);
return x + 2 * DISPLAY_LEFT_SHIFT - 2 * DIW_DDF_OFFSET;
*/
}
int coord_native_to_amiga_y (int y)
{
if (!native2amiga_line_map || y < 0 || y >= native2amiga_line_map_height)
return -1;
return native2amiga_line_map[y] + thisframe_y_adjust - minfirstline;
}
void notice_screen_contents_lost(int monid)
{
struct amigadisplay *ad = &adisplays[monid];
ad->picasso_redraw_necessary = 1;
ad->frame_redraw_necessary = 2;
}
bool isnativevidbuf(int monid)
{
struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo;
if (vidinfo->outbuffer == NULL)
return false;
if (vidinfo->outbuffer == &vidinfo->drawbuffer)
return true;
return vidinfo->outbuffer->nativepositioning;
}
extern int plffirstline_total, plflastline_total;
extern int diwfirstword_total, diwlastword_total;
extern int ddffirstword_total, ddflastword_total;
extern bool vertical_changed, horizontal_changed;
extern int firstword_bplcon1;
extern bool lof_display;
#define MIN_DISPLAY_W 256
#define MIN_DISPLAY_H 192
#define MAX_DISPLAY_W 362
#define MAX_DISPLAY_H 283
static int gclow, gcloh, gclox, gcloy, gclorealh;
static int stored_left_start, stored_top_start, stored_width, stored_height;
void get_custom_topedge (int *xp, int *yp, bool max)
{
if (isnativevidbuf(0) && !max) {
int x, y;
x = visible_left_border;
y = minfirstline << currprefs.gfx_vresolution;
#if 0
int dbl1, dbl2;
dbl2 = dbl1 = currprefs.gfx_vresolution;
if (doublescan > 0 && interlace_seen <= 0) {
dbl1--;
dbl2--;
}
x = -(visible_left_border + (DISPLAY_LEFT_SHIFT << currprefs.gfx_resolution));
y = -minfirstline << currprefs.gfx_vresolution;
y = xshift (y, dbl2);
#endif
*xp = x;
*yp = y;
} else {
*xp = 0;
*yp = 0;
}
}
static void reset_custom_limits(void)
{
gclow = gcloh = gclox = gcloy = 0;
gclorealh = -1;
center_reset = 1;
}
int get_vertical_visible_height(bool useoldsize)
{
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
int h = vidinfo->drawbuffer.inheight;
if (programmedmode <= 1) {
h = maxvsize_display;
if (useoldsize) {
// 288/576 or 243/486
if (h == 288 || h == 243) {
h--;
}
}
h <<= currprefs.gfx_vresolution;
}
if (interlace_seen && currprefs.gfx_vresolution > 0) {
h -= 1 << (currprefs.gfx_vresolution - 1);
}
if (!syncdebug) {
bool hardwired = true;
if (ecs_agnus) {
hardwired = (new_beamcon0 & BEAMCON0_VARVBEN) == 0;
}
if (hardwired) {
int hh = denise_visible_lines << currprefs.gfx_vresolution;
if (h > hh) {
h = hh;
}
}
}
return h;
}
void get_custom_raw_limits(int *pw, int *ph, int *pdx, int *pdy)
{
if (stored_width > 0) {
*pw = stored_width;
*ph = stored_height;
*pdx = stored_left_start;
*pdy = stored_top_start;
} else {
int x = visible_left_border;
if (x < visible_left_start)
x = visible_left_start;
*pdx = x;
int x2 = visible_right_border;
if (x2 > visible_right_stop)
x2 = visible_right_stop;
*pw = x2 - x;
int y = min_ypos_for_screen;
if (y < visible_top_start)
y = visible_top_start;
*pdy = y;
int y2 = max_ypos_thisframe1;
if (y2 > visible_bottom_stop)
y2 = visible_bottom_stop;
*ph = y2 - y;
}
}
void check_custom_limits(void)
{
struct amigadisplay *ad = &adisplays[0];
struct gfx_filterdata *fd = &currprefs.gf[ad->gf_index];
int vls = visible_left_start;
int vrs = visible_right_stop;
int vts = visible_top_start;
int vbs = visible_bottom_stop;
int left = fd->gfx_filter_left_border < 0 ? 0 : fd->gfx_filter_left_border >> (RES_MAX - currprefs.gfx_resolution);
int right = fd->gfx_filter_right_border < 0 ? 0 : fd->gfx_filter_right_border >> (RES_MAX - currprefs.gfx_resolution);
int top = fd->gfx_filter_top_border < 0 ? 0 : fd->gfx_filter_top_border;
int bottom = fd->gfx_filter_bottom_border < 0 ? 0 : fd->gfx_filter_bottom_border;
// backwards compatibility, old 0x38 start is gone.
if (left > 0) {
left += (0x38 * 4) >> (RES_MAX - currprefs.gfx_resolution);
right += (0x38 * 4) >> (RES_MAX - currprefs.gfx_resolution);
}
if (left > visible_left_start)
visible_left_start = left;
if (right > left && right < visible_right_stop)
visible_right_stop = right;
if (top > visible_top_start)
visible_top_start = top;
if (bottom > top && bottom < visible_bottom_stop)
visible_bottom_stop = bottom;
}
void set_custom_limits (int w, int h, int dx, int dy, bool blank)
{
struct amigadisplay *ad = &adisplays[0];
struct gfx_filterdata *fd = &currprefs.gf[ad->gf_index];
int vls = visible_left_start;
int vrs = visible_right_stop;
int vts = visible_top_start;
int vbs = visible_bottom_stop;
if (fd->gfx_filter_left_border == 0) {
w = 0;
dx = 0;
}
if (fd->gfx_filter_top_border == 0) {
h = 0;
dy = 0;
}
if (specialmonitor_uses_control_lines() || !blank) {
w = -1;
h = -1;
}
if (w <= 0 || dx < 0) {
visible_left_start = 0;
visible_right_stop = MAX_STOP;
} else {
visible_left_start = visible_left_border + dx;
visible_right_stop = visible_left_start + w;
}
if (h <= 0 || dy < 0) {
visible_top_start = 0;
visible_bottom_stop = MAX_STOP;
} else {
visible_top_start = min_ypos_for_screen + dy;
visible_bottom_stop = visible_top_start + h;
}
if ((w >= 0 && h >= 0) &&
(vls != visible_left_start || vrs != visible_right_stop ||
vts != visible_top_start || vbs != visible_bottom_stop))
notice_screen_contents_lost(0);
check_custom_limits();
}
void store_custom_limits (int w, int h, int x, int y)
{
stored_left_start = x;
stored_top_start = y;
stored_width = w;
stored_height = h;
#if 0
write_log (_T("%dx%d %dx%d %dx%d %dx%d %d\n"), x, y, w, h,
currprefs.gfx_xcenter_pos,
currprefs.gfx_ycenter_pos,
currprefs.gfx_xcenter_size,
currprefs.gfx_ycenter_size,
currprefs.gfx_filter_autoscale);
#endif
}
int get_custom_limits (int *pw, int *ph, int *pdx, int *pdy, int *prealh)
{
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
int w, h, dx, dy, y1, y2, dbl1, dbl2;
int ret = 0;
if (!pw || !ph || !pdx || !pdy) {
reset_custom_limits ();
return 0;
}
if (!isnativevidbuf(0)) {
*pw = vidinfo->outbuffer->outwidth;
*ph = vidinfo->outbuffer->outheight;
*pdx = 0;
*pdy = 0;
*prealh = -1;
return 1;
}
*pw = gclow;
*ph = gcloh;
*pdx = gclox;
*pdy = gcloy;
*prealh = gclorealh;
if (gclow > 0 && gcloh > 0)
ret = -1;
if (interlace_seen) {
static int interlace_count;
// interlace = only use long frames
if (lof_display && (interlace_count & 1) == 0)
interlace_count++;
if (!lof_display && (interlace_count & 1) != 0)
interlace_count++;
if (interlace_count < 3)
return ret;
if (!lof_display)
return ret;
interlace_count = 0;
}
int diwfirst, diwlast;
diwfirst = diwfirstword_total << 2;
diwlast = diwlastword_total << 2;
int ddffirst = ddffirstword_total << (RES_MAX + 1);
int ddflast = ddflastword_total << (RES_MAX + 1);
if (doublescan <= 0 && !programmedmode) {
int min = 92 << RES_MAX;
int max = 460 << RES_MAX;
if (diwfirst < min)
diwfirst = min;
if (diwlast > max)
diwlast = max;
if (ddffirstword_total < 30000) {
if (ddffirst < min)
ddffirst = min;
if (ddflast > max)
ddflast = max;
if (0 && !aga_mode) {
if (ddffirst > diwfirst)
diwfirst = ddffirst;
if (ddflast < diwlast)
diwlast = ddflast;
}
}
}
w = diwlast - diwfirst;
dx = diwfirst - (hdisplay_left_border << (RES_MAX + 1));
w >>= (RES_MAX - currprefs.gfx_resolution);
dx >>= (RES_MAX - currprefs.gfx_resolution);
y2 = plflastline_total;
y1 = plffirstline_total;
if (minfirstline_linear > y1)
y1 = minfirstline_linear;
dbl2 = dbl1 = currprefs.gfx_vresolution;
if (doublescan > 0 && interlace_seen <= 0) {
dbl1--;
dbl2--;
}
h = y2 - y1 + 1;
dy = y1 - minfirstline_linear;
if (plffirstline_total >= 30000) {
// no planes enabled during frame
if (ret < 0)
return 1;
h = currprefs.ntscmode ? 200 : 240;
w = 320 << currprefs.gfx_resolution;
dy = 36 / 2;
dx = 58;
}
if (dx < 0)
dx = 0;
*prealh = -1;
if (programmedmode != 1 && plffirstline_total < 30000) {
int th = (current_linear_vpos - minfirstline_linear) * 95 / 100;
if (th > h) {
th = xshift (th, dbl1);
*prealh = th;
}
}
dy = xshift (dy, dbl2);
h = xshift (h, dbl1);
if (w == 0 || h == 0)
return 0;
#if 0
if (doublescan <= 0 && programmedmode != 1) {
if ((w >> currprefs.gfx_resolution) < MIN_DISPLAY_W) {
dx += (w - (MIN_DISPLAY_W << currprefs.gfx_resolution)) / 2;
w = MIN_DISPLAY_W << currprefs.gfx_resolution;
}
if ((h >> dbl1) < MIN_DISPLAY_H) {
dy += (h - (MIN_DISPLAY_H << dbl1)) / 2;
h = MIN_DISPLAY_H << dbl1;
}
if ((w >> currprefs.gfx_resolution) > MAX_DISPLAY_W) {
dx += (w - (MAX_DISPLAY_W << currprefs.gfx_resolution)) / 2;
w = MAX_DISPLAY_W << currprefs.gfx_resolution;
}
if ((h >> dbl1) > MAX_DISPLAY_H) {
dy += (h - (MAX_DISPLAY_H << dbl1)) / 2;
h = MAX_DISPLAY_H << dbl1;
}
}
#endif
if (gclow == w && gcloh == h && gclox == dx && gcloy == dy)
return ret;
if (w <= 0 || h <= 0 || dx < 0 || dy < 0)
return ret;
if (doublescan <= 0 && programmedmode != 1) {
if (dx > vidinfo->outbuffer->inwidth / 2)
return ret;
if (dy > vidinfo->outbuffer->inheight / 2)
return ret;
}
gclow = w;
gcloh = h;
gclox = dx;
gcloy = dy;
gclorealh = *prealh;
*pw = w;
*ph = h;
*pdx = dx;
*pdy = dy;
#if 1
write_log (_T("Display Size: %dx%d Offset: %dx%d\n"), w, h, dx, dy);
write_log (_T("First: %d Last: %d Min: %d\n"),
plffirstline_total, plflastline_total,
minfirstline);
#endif
center_reset = 1;
return 1;
}
void get_custom_mouse_limits (int *pw, int *ph, int *pdx, int *pdy, int dbl)
{
int delay1, delay2;
int w, h, dx, dy, dbl1, dbl2, y1, y2;
w = diwlastword_total - diwfirstword_total;
dx = diwfirstword_total - visible_left_border;
y2 = plflastline_total;
y1 = plffirstline_total;
if (minfirstline > y1)
y1 = minfirstline;
h = y2 - y1;
dy = y1 - minfirstline;
if (*pw > 0)
w = *pw;
w = xshift (w, res_shift);
if (*ph > 0)
h = *ph;
delay1 = (firstword_bplcon1 & 0x0f) | ((firstword_bplcon1 & 0x0c00) >> 6);
delay2 = ((firstword_bplcon1 >> 4) & 0x0f) | (((firstword_bplcon1 >> 4) & 0x0c00) >> 6);
// if (delay1 == delay2)
// dx += delay1;
dx = xshift (dx, res_shift);
dbl2 = dbl1 = currprefs.gfx_vresolution;
if ((doublescan > 0 || interlace_seen > 0) && !dbl) {
dbl1--;
dbl2--;
}
if (interlace_seen > 0)
dbl2++;
if (interlace_seen <= 0 && dbl)
dbl2--;
h = xshift (h, dbl1);
dy = xshift (dy, dbl2);
if (w < 1)
w = 1;
if (h < 1)
h = 1;
if (dx < 0)
dx = 0;
if (dy < 0)
dy = 0;
*pw = w; *ph = h;
*pdx = dx; *pdy = dy;
}
static bool get_genlock_very_rare_and_complex_case(uae_u8 v)
{
if (ecs_genlock_features_colorkey) {
if (currprefs.genlock_effects) {
if (v < 64 && (currprefs.ecs_genlock_features_colorkey_mask[0] & (1LL << v))) {
return false;
}
if (v >= 64 && v < 128 && (currprefs.ecs_genlock_features_colorkey_mask[1] & (1LL << (v - 64)))) {
return false;
}
if (v >= 128 && v < 192 && (currprefs.ecs_genlock_features_colorkey_mask[2] & (1LL << (v - 128)))) {
return false;
}
if (v >= 192 && v < 256 && (currprefs.ecs_genlock_features_colorkey_mask[3] & (1LL << (v - 192)))) {
return false;
}
} else {
// color key match?
if (denise_colors.color_regs_genlock[v]) {
return false;
}
}
}
// plane mask match?
if (currprefs.genlock_effects) {
if (v & currprefs.ecs_genlock_features_plane_mask)
return false;
} else {
if (v & ecs_genlock_features_mask)
return false;
}
return true;
}
// false = transparent
STATIC_INLINE bool get_genlock_transparency(uae_u8 v)
{
if (!ecs_genlock_features_active) {
if (v == 0)
return false;
return true;
} else {
return get_genlock_very_rare_and_complex_case(v);
}
}
STATIC_INLINE bool get_genlock_transparency_border(void)
{
if (!ecs_genlock_features_active) {
return false;
} else {
// border color with BRDNTRAN bit set = not transparent
if (bplcon3_denise & 0x0010)
return true;
return get_genlock_very_rare_and_complex_case(0);
}
}
static void gen_pfield_tables(void)
{
for (int i = 0; i < 256; i++) {
int plane1 = ((i >> 0) & 1) | ((i >> 1) & 2) | ((i >> 2) & 4) | ((i >> 3) & 8);
int plane2 = ((i >> 1) & 1) | ((i >> 2) & 2) | ((i >> 3) & 4) | ((i >> 4) & 8);
dblpf_2nd1[i] = plane1 == 0 && plane2 != 0;
dblpf_2nd2[i] = plane2 != 0;
#ifdef AGA
dblpf_ind1_aga[i] = plane1 == 0 ? plane2 : plane1;
dblpf_ind2_aga[i] = plane2 == 0 ? plane1 : plane2;
#endif
dblpf_ms1[i] = plane1 == 0 ? (plane2 == 0 ? 16 : 8) : 0;
dblpf_ms2[i] = plane2 == 0 ? (plane1 == 0 ? 16 : 0) : 8;
dblpf_ms[i] = i == 0 ? 16 : 8;
if (plane2 > 0)
plane2 += 8;
// use OCS/ECS unused plane bits 6 and 7 for
// dualplayfield BPLCON2 invalid value emulation.
int plane1x = (i & 0x40) ? 0 : plane1;
int plane2x = (i & 0x80) ? 0 : plane2;
dblpf_ind1[i] = plane1 == 0 ? plane2x : plane1x;
dblpf_ind2[i] = plane2 == 0 ? plane1x : plane2x;
sprite_offs[i] = (i & 15) ? 0 : 2;
}
}
void init_row_map(void)
{
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
static uae_u8 *oldbufmem;
static int oldheight, oldpitch;
static bool oldgenlock, oldburst;
int i, j;
if (vidinfo->drawbuffer.height_allocated > max_uae_height) {
write_log (_T("Resolution too high, aborting\n"));
abort ();
}
if (!row_map) {
row_map = xmalloc(uae_u8*, max_uae_height + 1);
row_map_genlock = xmalloc(uae_u16*, max_uae_height + 1);
}
if (oldbufmem && oldbufmem == vidinfo->drawbuffer.bufmem &&
oldheight == vidinfo->drawbuffer.height_allocated &&
oldpitch == vidinfo->drawbuffer.rowbytes &&
oldgenlock == init_genlock_data &&
oldburst == (row_map_color_burst_buffer ? 1 : 0))
return;
xfree(row_map_genlock_buffer);
row_map_genlock_buffer = NULL;
if (init_genlock_data) {
row_map_genlock_buffer = xcalloc(uae_u16, vidinfo->drawbuffer.width_allocated * (vidinfo->drawbuffer.height_allocated + 2));
}
xfree(row_map_color_burst_buffer);
row_map_color_burst_buffer = NULL;
if (currprefs.cs_color_burst) {
row_map_color_burst_buffer = xcalloc(uae_u8, vidinfo->drawbuffer.height_allocated + 2);
}
j = oldheight == 0 ? max_uae_height : oldheight;
for (i = vidinfo->drawbuffer.height_allocated; i < max_uae_height + 1 && i < j + 1; i++) {
row_map[i] = row_tmp8;
row_map_genlock[i] = row_tmp16;
}
for (i = 0, j = 0; i < vidinfo->drawbuffer.height_allocated; i++, j += vidinfo->drawbuffer.rowbytes) {
row_map[i] = vidinfo->drawbuffer.bufmem + j;
if (init_genlock_data) {
row_map_genlock[i] = row_map_genlock_buffer + vidinfo->drawbuffer.width_allocated * (i + 1);
} else {
row_map_genlock[i] = NULL;
}
}
oldbufmem = vidinfo->drawbuffer.bufmem;
oldheight = vidinfo->drawbuffer.height_allocated;
oldpitch = vidinfo->drawbuffer.rowbytes;
oldgenlock = init_genlock_data;
oldburst = row_map_color_burst_buffer ? 1 : 0;
}
static void init_aspect_maps(void)
{
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
int i, maxl, h;
linedbld = linedbl = currprefs.gfx_vresolution;
if (doublescan > 0 && interlace_seen <= 0) {
linedbl = 0;
linedbld = 1;
}
maxl = (MAXVPOS + 1) << linedbld;
min_ypos_for_screen = minfirstline << linedbl;
max_drawn_amiga_line = -1;
vidinfo->xchange = 1 << (RES_MAX - currprefs.gfx_resolution);
vidinfo->ychange = linedbl ? 1 : 2;
visible_left_start = 0;
visible_right_stop = MAX_STOP;
visible_top_start = 0;
visible_bottom_stop = MAX_STOP;
h = vidinfo->drawbuffer.height_allocated;
if (h == 0)
/* Do nothing if the gfx driver hasn't initialized the screen yet */
return;
if (native2amiga_line_map)
xfree (native2amiga_line_map);
if (amiga2aspect_line_map)
xfree (amiga2aspect_line_map);
/* At least for this array the +1 is necessary. */
native2amiga_line_map_height = h;
amiga2aspect_line_map = xmalloc (int, (MAXVPOS + 1) * 2 + 1);
native2amiga_line_map = xmalloc (int, native2amiga_line_map_height);
for (i = 0; i < maxl; i++) {