forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawing.cpp
5316 lines (4759 loc) · 160 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-2008 Toni Wilen
*/
/* There are a couple of concepts of "coordinates" in this file.
- DIW coordinates
- DDF coordinates (essentially cycles, resolution lower than lores by a factor of 2)
- Pixel coordinates
* in the Amiga's resolution as determined by BPLCON0 ("Amiga coordinates")
* in the window resolution as determined by the preferences ("window coordinates").
* in the window resolution, and with the origin being the topmost left corner of
the window ("native coordinates")
One note about window coordinates. The visible area depends on the width of the
window, and the centering code. The first visible horizontal window coordinate is
often _not_ 0, but the value of VISIBLE_LEFT_BORDER instead.
One important thing to remember: DIW coordinates are in the lowest possible
resolution.
To prevent extremely bad things (think pixels cut in half by window borders) from
happening, all ports should restrict window widths to be multiples of 16 pixels. */
#define SPRITE_DEBUG_HIDE 0
#define BG_COLOR_DEBUG 0
#define EXTBORDER_BLANK 0
#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"
#include "cd32_fmv.h"
#include "specialmonitors.h"
#include "devices.h"
#include "gfxboard.h"
//#define XLINECHECK
struct amigadisplay adisplays[MAX_AMIGADISPLAYS];
typedef enum
{
CMODE_NORMAL,
CMODE_DUALPF,
CMODE_EXTRAHB,
CMODE_EXTRAHB_ECS_KILLEHB,
CMODE_HAM
} CMODE_T;
extern int sprite_buffer_res;
static int lores_factor;
int lores_shift, shres_shift;
static void pfield_set_linetoscr(void);
int debug_bpl_mask = 0xff, debug_bpl_mask_one;
static struct decision *dp_for_drawing;
static struct draw_info *dip_for_drawing;
static void lores_set(int lores)
{
int old = lores_shift;
lores_shift = lores;
if (lores_shift != old || shres_shift != RES_MAX - lores) {
shres_shift = RES_MAX - lores;
pfield_set_linetoscr();
}
}
static void lores_reset (void)
{
lores_factor = currprefs.gfx_resolution ? 2 : 1;
lores_set(currprefs.gfx_resolution);
if (doublescan > 0) {
int ls = lores_shift;
if (ls < 2) {
ls++;
}
lores_factor = 2;
lores_set(ls);
}
sprite_buffer_res = currprefs.gfx_resolution;
if (doublescan > 0 && sprite_buffer_res < RES_SUPERHIRES)
sprite_buffer_res++;
}
/* mirror of chipset_mask */
bool ecs_agnus;
bool ecs_denise;
bool aga_mode;
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];
static uae_u32 clxtab[256];
/* Video buffer description structure. Filled in by the graphics system
* dependent code. */
/* OCS/ECS color lookup table. */
xcolnr xcolors[4096];
struct spritepixelsbuf {
bool attach;
uae_u8 stdata;
uae_u16 stfmdata;
uae_u16 data;
};
static struct spritepixelsbuf spritepixels_buffer[MAX_PIXELS_PER_LINE];
static struct spritepixelsbuf *spritepixels;
static int sprite_first_x, sprite_last_x;
#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;
struct color_entry colors_for_drawing;
xcolnr fullblack;
static struct color_entry direct_colors_for_drawing;
static xcolnr *p_acolors;
static xcolnr *p_xcolors;
/* The size of these arrays is pretty arbitrary; it was chosen to be "more
than enough". The coordinates used for indexing into these arrays are
almost, but not quite, Amiga coordinates (there's a constant offset). */
static union {
uae_u64 apixels_q[MAX_PIXELS_PER_LINE * 2 / sizeof(uae_u64)];
uae_u32 apixels_l[MAX_PIXELS_PER_LINE * 2 / sizeof(uae_u32)];
uae_u8 apixels[MAX_PIXELS_PER_LINE * 2];
} pixdata;
static uae_u8 *refresh_indicator_buffer;
static uae_u8 *refresh_indicator_changed, *refresh_indicator_changed_prev;
static int refresh_indicator_height;
#ifdef OS_WITHOUT_MEMORY_MANAGEMENT
uae_u16 *spixels;
#else
uae_u16 spixels[2 * MAX_SPR_PIXELS];
#endif
struct sprite_stb spixstate;
static uae_u32 ham_linebuf[MAX_PIXELS_PER_LINE * 2];
static uae_u8 all_ones[MAX_PIXELS_PER_LINE];
static uae_u8 all_zeros[MAX_PIXELS_PER_LINE];
uae_u8 *xlinebuffer, *xlinebuffer_genlock;
static int *amiga2aspect_line_map, *native2amiga_line_map;
static int native2amiga_line_map_height;
static uae_u8 **row_map;
static uae_u8 *row_map_genlock_buffer;
static uae_u8 row_tmp[MAX_PIXELS_PER_LINE * 32 / 8];
static int max_drawn_amiga_line;
uae_u8 **row_map_genlock;
uae_u8 *row_map_color_burst_buffer;
/* line_draw_funcs: pfield_do_linetoscr, pfield_do_fill_line, decode_ham */
typedef void (*line_draw_func)(int, int, int);
#define LINE_UNDECIDED 1
#define LINE_DECIDED 2
#define LINE_DECIDED_DOUBLE 3
#define LINE_AS_PREVIOUS 4
#define LINE_BLACK 5
#define LINE_REMEMBERED_AS_BLACK 6
#define LINE_DONE 7
#define LINE_DONE_AS_PREVIOUS 8
#define LINE_REMEMBERED_AS_PREVIOUS 9
#define LINESTATE_SIZE ((MAXVPOS + MAXVPOS_WRAPLINES) * 2 + 1)
static uae_u8 linestate[LINESTATE_SIZE];
uae_u8 line_data[(MAXVPOS + MAXVPOS_WRAPLINES) * 2][MAX_PLANES * MAX_WORDS_PER_LINE * 2];
/* 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;
/* same for blank */
static int vblank_top_start, vblank_bottom_stop;
static int hblank_left_start, hblank_right_stop;
static int hblank_left_start_hard, hblank_right_stop_hard;
static bool exthblank, extborder, exthblanken, exthblankon;
static bool ehb_enable;
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;
/* 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, bplehb, bplham, bpldualpf, bpldualpfpri;
static int bpldualpf2of, bplplanecnt, bplmaxplanecnt, ecsshres;
static int bplbypass, bplcolorburst, bplcolorburst_field;
static int bplres;
static int plf1pri, plf2pri, bplxor, bplxorsp, bpland, bpldelay_sh;
static uae_u32 plf_sprite_mask;
static int sbasecol[2] = { 16, 16 };
static int hposblank;
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;
static int hsync_shift_hack;
static bool sprite_smaller_than_64, sprite_smaller_than_64_inuse;
static bool full_blank;
static uae_u8 vb_state;
uae_sem_t gui_sem;
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;
}
#ifdef XLINECHECK
static void xlinecheck (unsigned int start, unsigned int end)
{
unsigned int xstart = (unsigned int)xlinebuffer + start * vidinfo->drawbuffer.pixbytes;
unsigned int xend = (unsigned int)xlinebuffer + end * vidinfo->drawbuffer.pixbytes;
unsigned int end1 = (unsigned int)vidinfo->drawbuffer.bufmem + vidinfo->drawbuffer.rowbytes * vidinfo->drawbuffer.height;
int min = linetoscr_x_adjust_bytes / vidinfo->drawbuffer.pixbytes;
int ok = 1;
if (xstart >= vidinfo->drawbuffer.emergmem && xstart < vidinfo->drawbuffer.emergmem + 4096 * vidinfo->drawbuffer.pixbytes &&
xend >= vidinfo->drawbuffer.emergmem && xend < vidinfo->drawbuffer.emergmem + 4096 * vidinfo->drawbuffer.pixbytes)
return;
if (xstart < (unsigned int)vidinfo->drawbuffer.bufmem || xend < (unsigned int)vidinfo->drawbuffer.bufmem)
ok = 0;
if (xend > end1 || xstart >= end1)
ok = 0;
xstart -= (unsigned int)vidinfo->drawbuffer.bufmem;
xend -= (unsigned int)vidinfo->drawbuffer.bufmem;
if ((xstart % vidinfo->drawbuffer.rowbytes) >= vidinfo->drawbuffer.width * vidinfo->drawbuffer.pixbytes)
ok = 0;
if ((xend % vidinfo->drawbuffer.rowbytes) >= vidinfo->drawbuffer.width * vidinfo->drawbuffer.pixbytes)
ok = 0;
if (xstart >= xend)
ok = 0;
if (xend - xstart > vidinfo->drawbuffer.width * vidinfo->drawbuffer.pixbytes)
ok = 0;
if (!ok) {
write_log (_T("*** %d-%d (%dx%dx%d %d) %p\n"),
start - min, end - min, vidinfo->drawbuffer.width, vidinfo->drawbuffer.height,
vidinfo->drawbuffer.pixbytes, vidinfo->drawbuffer.rowbytes,
xlinebuffer);
}
}
#else
#define xlinecheck(start, end)
#endif
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 reset_decision_table (void)
{
for (int i = 0; i < sizeof linestate / sizeof *linestate; i++) {
linestate[i] = LINE_UNDECIDED;
}
}
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)
{
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;
}
STATIC_INLINE int res_shift_from_window (int x)
{
if (res_shift >= 0)
return x >> res_shift;
return x << -res_shift;
}
STATIC_INLINE int res_shift_from_amiga (int x)
{
if (res_shift >= 0)
return x >> res_shift;
return x << -res_shift;
}
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 first_planes_vpos, last_planes_vpos;
extern int diwfirstword_total, diwlastword_total;
extern int ddffirstword_total, ddflastword_total;
extern bool vertical_changed, horizontal_changed;
extern int firstword_bplcon1;
extern int 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 + (DISPLAY_LEFT_SHIFT << currprefs.gfx_resolution);
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;
}
static void expand_vb_state(void)
{
full_blank = vb_state == VB_PRGVB || (vb_state >= VB_XBLANK && vb_state < VB_XBORDER) || (vb_state == VB_XBORDER);
}
static void extblankcheck(void)
{
exthblankon = dp_for_drawing && (dp_for_drawing->bplcon3 & 1) && (dp_for_drawing->bplcon0 & 1);
if (exthblanken && exthblankon) {
exthblank = true;
}
if (exthblanken && !exthblankon) {
exthblank = false;
}
}
static void reset_hblanking_limits(void)
{
hblank_left_start = visible_left_start;
hblank_right_stop = visible_right_stop;
if (hblank_left_start < visible_left_border) {
hblank_left_start = visible_left_border;
}
if (hblank_right_stop > visible_right_border) {
hblank_right_stop = visible_right_border;
}
}
static void get_vblanking_limits(int *vbstrtp, int *vbstopp, bool overscanonly)
{
int vbstrt = vblank_firstline_hw;
if (!ecs_denise) {
vbstrt--;
}
int vbstop = maxvpos + lof_display;
if (!ecs_denise && !ecs_agnus) {
vbstop++;
} else if (ecs_agnus && !ecs_denise) {
// hide hblank bug by faking vblank start 1 line earlier
if (currprefs.gfx_overscanmode < OVERSCANMODE_BROADCAST) {
vbstrt++;
vbstop--;
}
}
if (currprefs.gfx_overscanmode < OVERSCANMODE_OVERSCAN && !overscanonly) {
int mult = (OVERSCANMODE_OVERSCAN - currprefs.gfx_overscanmode) * 5;
vbstrt += mult;
vbstop -= mult;
}
vbstrt <<= currprefs.gfx_vresolution;
vbstop <<= currprefs.gfx_vresolution;
if (vblank_top_start < vbstrt) {
vblank_top_start = vbstrt;
}
if (vblank_bottom_stop > vbstop) {
vblank_bottom_stop = vbstop;
}
*vbstrtp = vbstrt;
*vbstopp = vbstop;
}
// this handles hardwired vblank
// vb_state in do_color_changes() handles programmed vblank
static void set_vblanking_limits(void)
{
vblank_top_start = visible_top_start;
vblank_bottom_stop = visible_bottom_stop;
if (vblank_top_start < visible_top_start) {
vblank_top_start = visible_top_start;
}
if (vblank_bottom_stop > visible_bottom_stop) {
vblank_bottom_stop = visible_bottom_stop;
}
if (currprefs.gfx_overscanmode == OVERSCANMODE_ULTRA) {
return;
}
bool hardwired = true;
if (ecs_agnus) {
hardwired = (new_beamcon0 & BEAMCON0_VARVBEN) == 0;
// ECS Denise with exhblank: always use thisline_decision.vb blanking method
if (ecs_denise && !aga_mode && exthblank) {
hardwired = false;
}
}
if (hardwired) {
int vbstrt, vbstop;
get_vblanking_limits(&vbstrt, &vbstop, false);
if (vblank_top_start < vbstrt) {
vblank_top_start = vbstrt;
}
if (vblank_bottom_stop > vbstop) {
vblank_bottom_stop = vbstop;
}
}
}
int get_vertical_visible_height(bool useoldsize)
{
struct vidbuf_description *vidinfo = &adisplays[0].gfxvidinfo;
int h = vidinfo->drawbuffer.inheight;
int vbstrt, vbstop;
if (programmedmode <= 1) {
h = maxvpos_display + maxvpos_display_vsync - minfirstline;
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 (currprefs.gfx_overscanmode < OVERSCANMODE_ULTRA) {
bool hardwired = true;
if (ecs_agnus) {
hardwired = (new_beamcon0 & BEAMCON0_VARVBEN) == 0;
}
if (hardwired) {
get_vblanking_limits(&vbstrt, &vbstop, true);
int hh = vbstop - vbstrt;
if (h > hh) {
h = hh;
}
}
}
return h;
}
static void set_hblanking_limits(void)
{
if (currprefs.gfx_overscanmode == OVERSCANMODE_ULTRA) {
hblank_left_start_hard = visible_left_start;
hblank_right_stop_hard = visible_right_stop;
return;
}
hblank_left_start_hard = hblank_left_start;
hblank_right_stop_hard = hblank_right_stop;
// horizontal blanking
bool hardwired = !dp_for_drawing || !ce_is_extblankset(colors_for_drawing.extra);
bool doblank = false;
int hbstrt = ((maxhpos + 8) << CCK_SHRES_SHIFT) - 3;
int hbstop = (47 << CCK_SHRES_SHIFT) - 7;
if (currprefs.gfx_overscanmode < OVERSCANMODE_OVERSCAN) {
int mult = (OVERSCANMODE_OVERSCAN - currprefs.gfx_overscanmode) * 4;
hbstrt -= mult << CCK_SHRES_SHIFT;
hbstop += mult << CCK_SHRES_SHIFT;
if (currprefs.gfx_overscanmode == 0) {
hbstrt += 2 << CCK_SHRES_SHIFT;
hbstop -= 2 << CCK_SHRES_SHIFT;
}
}
// programmed mode with hardwired hblanking
if (hblank_left_start_hard < coord_hw_to_window_x_shres(hbstop)) {
hblank_left_start_hard = coord_hw_to_window_x_shres(hbstop);
}
if (hblank_right_stop_hard > coord_hw_to_window_x_shres(hbstrt)) {
hblank_right_stop_hard = coord_hw_to_window_x_shres(hbstrt);
}
if (hardwired) {
doblank = true;
} else if (currprefs.gfx_overscanmode <= OVERSCANMODE_OVERSCAN) {
doblank = true;
} else if (currprefs.gfx_overscanmode == OVERSCANMODE_BROADCAST) {
hbstrt = (239 << CCK_SHRES_SHIFT) - 3;
doblank = true;
}
if (doblank && programmedmode != 1) {
// programmed mode with programmed hblanking
// reposition to sync
// use hardwired hblank emulation as overscan blanking.
if ((new_beamcon0 & bemcon0_hsync_mask) && !hardwired) {
extern uae_u16 hsstrt;
hbstrt += (hsstrt - 18) << CCK_SHRES_SHIFT;
hbstop += (hsstrt - 18) << CCK_SHRES_SHIFT;
}
if (currprefs.chipset_hr) {
hbstrt &= ~(3 >> currprefs.gfx_resolution);
hbstop &= ~(3 >> currprefs.gfx_resolution);
} else {
hbstrt &= ~3;
hbstop &= ~3;
}
if (hblank_left_start < coord_hw_to_window_x_shres(hbstop)) {
hblank_left_start = coord_hw_to_window_x_shres(hbstop);
}
if (hblank_right_stop > coord_hw_to_window_x_shres(hbstrt)) {
hblank_right_stop = coord_hw_to_window_x_shres(hbstrt);
}
}
}
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;
/* program may have set last visible line as last possible line (CD32 boot screen) */
if (last_planes_vpos < maxvpos)
last_planes_vpos++;
if (plflastline_total < maxvpos)
plflastline_total++;
}
if (plflastline_total < 4)
plflastline_total = last_planes_vpos;
ddffirstword_total = coord_hw_to_window_x_lores(ddffirstword_total * 2 + DIW_DDF_OFFSET);
ddflastword_total = coord_hw_to_window_x_lores(ddflastword_total * 2 + DIW_DDF_OFFSET);
if (doublescan <= 0 && !programmedmode) {
int min = coord_diw_lores_to_window_x(92);
int max = coord_diw_lores_to_window_x(460);
if (diwfirstword_total < min)
diwfirstword_total = min;
if (diwlastword_total > max)
diwlastword_total = max;
if (ddffirstword_total < min)
ddffirstword_total = min;
if (ddflastword_total > max)
ddflastword_total = max;
if (0 && !aga_mode) {
if (ddffirstword_total > diwfirstword_total)
diwfirstword_total = ddffirstword_total;
if (ddflastword_total < diwlastword_total)
diwlastword_total = ddflastword_total;
}
}
w = diwlastword_total - diwfirstword_total;
dx = diwfirstword_total - visible_left_border;
y2 = plflastline_total;
if (y2 > last_planes_vpos)
y2 = last_planes_vpos;
y1 = plffirstline_total;
if (first_planes_vpos > y1)
y1 = first_planes_vpos;
if (minfirstline > y1)
y1 = minfirstline;
dbl2 = dbl1 = currprefs.gfx_vresolution;
if (doublescan > 0 && interlace_seen <= 0) {
dbl1--;
dbl2--;
}
h = y2 - y1;
dy = y1 - minfirstline;
if (first_planes_vpos == 0) {
// 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 && first_planes_vpos) {
int th = (maxvpos - minfirstline) * 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 (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;
}
}
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 / 3)
return ret;
if (dy > vidinfo->outbuffer->inheight / 3)
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 MinV: %d MaxV: %d Min: %d\n"),
plffirstline_total, plflastline_total,
first_planes_vpos, last_planes_vpos, 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;
if (y2 > last_planes_vpos)
y2 = last_planes_vpos;
y1 = plffirstline_total;
if (first_planes_vpos > y1)
y1 = first_planes_vpos;
if (minfirstline > y1)
y1 = minfirstline;
h = y2 - y1;
dy = y1 - minfirstline;
if (*pw > 0)
w = *pw;
w = xshift (w, res_shift);