|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Screen drawing functions
5: *
1.1.1.8 root 6: * Copyright 1995-2000 Bernd Schmidt
1.1 root 7: * Copyright 1995 Alessandro Bissacco
1.1.1.13 root 8: * Copyright 2000,2001 Toni Wilen
1.1 root 9: */
10:
1.1.1.8 root 11: /* There are a couple of concepts of "coordinates" in this file.
12: - DIW coordinates
13: - DDF coordinates (essentially cycles, resolution lower than lores by a factor of 2)
14: - Pixel coordinates
15: * in the Amiga's resolution as determined by BPLCON0 ("Amiga coordinates")
16: * in the window resolution as determined by the preferences ("window coordinates").
17: * in the window resolution, and with the origin being the topmost left corner of
18: the window ("native coordinates")
19: One note about window coordinates. The visible area depends on the width of the
20: window, and the centering code. The first visible horizontal window coordinate is
21: often _not_ 0, but the value of VISIBLE_LEFT_BORDER instead.
22:
23: One important thing to remember: DIW coordinates are in the lowest possible
24: resolution.
25:
26: To prevent extremely bad things (think pixels cut in half by window borders) from
27: happening, all ports should restrict window widths to be multiples of 16 pixels. */
28:
1.1 root 29: #include "sysconfig.h"
30: #include "sysdeps.h"
31:
32: #include <ctype.h>
33: #include <assert.h>
34:
35: #include "config.h"
36: #include "options.h"
1.1.1.14! root 37: #include "threaddep/thread.h"
1.1 root 38: #include "uae.h"
39: #include "memory.h"
40: #include "custom.h"
41: #include "newcpu.h"
42: #include "xwin.h"
43: #include "autoconf.h"
44: #include "gui.h"
45: #include "picasso96.h"
46: #include "drawing.h"
1.1.1.13 root 47: #include "savestate.h"
1.1 root 48:
1.1.1.12 root 49: int lores_factor, lores_shift;
1.1 root 50:
1.1.1.8 root 51: /* The shift factor to apply when converting between Amiga coordinates and window
52: coordinates. Zero if the resolution is the same, positive if window coordinates
53: have a higher resolution (i.e. we're stretching the image), negative if window
54: coordinates have a lower resolution (i.e. we're shrinking the image). */
55: static int res_shift;
56:
1.1 root 57: static int interlace_seen = 0;
58:
1.1.1.11 root 59: /* Lookup tables for dual playfields. The dblpf_*1 versions are for the case
60: that playfield 1 has the priority, dbplpf_*2 are used if playfield 2 has
61: priority. If we need an array for non-dual playfield mode, it has no number. */
62: /* The dbplpf_ms? arrays contain a shift value. plf_spritemask is initialized
63: to contain two 16 bit words, with the appropriate mask if pf1 is in the
64: foreground being at bit offset 0, the one used if pf2 is in front being at
65: offset 16. */
1.1.1.12 root 66:
1.1.1.11 root 67: static int dblpf_ms1[256], dblpf_ms2[256], dblpf_ms[256];
68: static int dblpf_ind1[256], dblpf_ind2[256];
1.1.1.12 root 69:
70: static int dblpf_2nd1[256], dblpf_2nd2[256];
71: static int dblpf_ind1_aga[256], dblpf_ind2_aga[256];
72:
1.1 root 73: static int dblpfofs[] = { 0, 2, 4, 8, 16, 32, 64, 128 };
74:
1.1.1.11 root 75: static int sprite_offs[256];
76:
1.1 root 77: static uae_u32 clxtab[256];
78:
79: /* Video buffer description structure. Filled in by the graphics system
80: * dependent code. */
81:
82: struct vidbuf_description gfxvidinfo;
83:
1.1.1.9 root 84: /* OCS/ECS color lookup table. */
1.1 root 85: xcolnr xcolors[4096];
1.1.1.9 root 86: /* AGA mode color lookup tables */
87: unsigned int xredcolors[256], xgreencolors[256], xbluecolors[256];
1.1 root 88:
89: struct color_entry colors_for_drawing;
90:
1.1.1.8 root 91: /* The size of these arrays is pretty arbitrary; it was chosen to be "more
92: than enough". The coordinates used for indexing into these arrays are
93: almost, but not quite, Amiga coordinates (there's a constant offset). */
1.1 root 94: union {
95: /* Let's try to align this thing. */
96: double uupzuq;
97: long int cruxmedo;
1.1.1.13 root 98: uae_u8 apixels[MAX_PIXELS_PER_LINE * 2];
99: uae_u16 apixels_w[MAX_PIXELS_PER_LINE * 2 / 2];
100: uae_u32 apixels_l[MAX_PIXELS_PER_LINE * 2 / 4];
1.1 root 101: } pixdata;
102:
1.1.1.11 root 103: uae_u16 spixels[2 * MAX_SPR_PIXELS];
104: /* Eight bits for every pixel. */
105: union sps_union spixstate;
106:
1.1.1.13 root 107: static uae_u32 ham_linebuf[MAX_PIXELS_PER_LINE * 2];
108: static uae_u8 spriteagadpfpixels[MAX_PIXELS_PER_LINE * 2]; /* AGA dualplayfield sprite */
1.1 root 109:
110: char *xlinebuffer;
111:
112: static int *amiga2aspect_line_map, *native2amiga_line_map;
113: static char *row_map[2049];
114: static int max_drawn_amiga_line;
115:
1.1.1.9 root 116: /* line_draw_funcs: pfield_do_linetoscr, pfield_do_fill_line, decode_ham */
1.1 root 117: typedef void (*line_draw_func)(int, int);
118:
119: #define LINE_UNDECIDED 1
120: #define LINE_DECIDED 2
121: #define LINE_DECIDED_DOUBLE 3
122: #define LINE_AS_PREVIOUS 4
1.1.1.2 root 123: #define LINE_BLACK 5
124: #define LINE_REMEMBERED_AS_BLACK 6
1.1 root 125: #define LINE_DONE 7
126: #define LINE_DONE_AS_PREVIOUS 8
127: #define LINE_REMEMBERED_AS_PREVIOUS 9
128:
129: static char *line_drawn;
1.1.1.5 root 130: static char linestate[(MAXVPOS + 1)*2 + 1];
1.1 root 131:
1.1.1.5 root 132: uae_u8 line_data[(MAXVPOS + 1) * 2][MAX_PLANES * MAX_WORDS_PER_LINE * 2];
1.1 root 133:
1.1.1.8 root 134: /* Centering variables. */
135: static int min_diwstart, max_diwstop, prev_x_adjust;
136: /* The visible window: VISIBLE_LEFT_BORDER contains the left border of the visible
137: area, VISIBLE_RIGHT_BORDER the right border. These are in window coordinates. */
138: static int visible_left_border, visible_right_border;
1.1 root 139: static int linetoscr_x_adjust_bytes;
140: static int thisframe_y_adjust, prev_y_adjust;
141: static int thisframe_y_adjust_real, max_ypos_thisframe, min_ypos_for_screen;
142: static int extra_y_adjust;
143: int thisframe_first_drawn_line, thisframe_last_drawn_line;
144:
1.1.1.8 root 145: /* A frame counter that forces a redraw after at least one skipped frame in
146: interlace mode. */
1.1 root 147: static int last_redraw_point;
148:
149: static int first_drawn_line, last_drawn_line;
150: static int first_block_line, last_block_line;
151:
152: /* These are generated by the drawing code from the line_decisions array for
1.1.1.8 root 153: each line that needs to be drawn. These are basically extracted out of
154: bit fields in the hardware registers. */
1.1.1.13 root 155: static int bplehb, bplham, bpldualpf, bpldualpfpri, bpldualpf2of, bplplanecnt, bplres;
1.1.1.11 root 156: static uae_u32 plf_sprite_mask;
1.1.1.12 root 157: static int sbasecol[2];
1.1 root 158:
159: int picasso_requested_on;
160: int picasso_on;
161:
162: uae_sem_t gui_sem;
163: int inhibit_frame;
164:
165: int framecnt = 0;
166: static int frame_redraw_necessary;
167: static int picasso_redraw_necessary;
168:
1.1.1.6 root 169: STATIC_INLINE void count_frame (void)
1.1 root 170: {
171: framecnt++;
1.1.1.5 root 172: if (framecnt >= currprefs.gfx_framerate)
1.1 root 173: framecnt = 0;
174: }
175:
176: int coord_native_to_amiga_x (int x)
177: {
1.1.1.8 root 178: x += visible_left_border;
1.1 root 179: x <<= (1 - lores_shift);
1.1.1.11 root 180: return x + 2*DISPLAY_LEFT_SHIFT - 2*DIW_DDF_OFFSET;
1.1 root 181: }
182:
183: int coord_native_to_amiga_y (int y)
184: {
185: return native2amiga_line_map[y] + thisframe_y_adjust - minfirstline;
186: }
187:
1.1.1.8 root 188: STATIC_INLINE int res_shift_from_window (int x)
189: {
190: if (res_shift >= 0)
191: return x >> res_shift;
192: return x << -res_shift;
193: }
194:
195: STATIC_INLINE int res_shift_from_amiga (int x)
196: {
197: if (res_shift >= 0)
198: return x >> res_shift;
199: return x << -res_shift;
200: }
201:
1.1 root 202: void notice_screen_contents_lost (void)
203: {
204: picasso_redraw_necessary = 1;
205: frame_redraw_necessary = 2;
206: }
207:
208: static struct decision *dp_for_drawing;
209: static struct draw_info *dip_for_drawing;
210:
1.1.1.8 root 211: /* Record DIW of the current line for use by centering code. */
1.1 root 212: void record_diw_line (int first, int last)
213: {
214: if (last > max_diwstop)
215: max_diwstop = last;
216: if (first < min_diwstart)
217: min_diwstart = first;
218: }
219:
220: /*
221: * Screen update macros/functions
222: */
223:
1.1.1.8 root 224: /* The important positions in the line: where do we start drawing the left border,
225: where do we start drawing the playfield, where do we start drawing the right border.
226: All of these are forced into the visible window (VISIBLE_LEFT_BORDER .. VISIBLE_RIGHT_BORDER).
227: PLAYFIELD_START and PLAYFIELD_END are in window coordinates. */
228: static int playfield_start, playfield_end;
229:
230: static int pixels_offset;
231: static int src_pixel;
232: /* How many pixels in window coordinates which are to the left of the left border. */
233: static int unpainted;
1.1 root 234:
1.1.1.8 root 235: /* Initialize the variables necessary for drawing a line.
236: * This involves setting up start/stop positions and display window
237: * borders. */
238: static void pfield_init_linetoscr (void)
1.1 root 239: {
1.1.1.8 root 240: /* First, get data fetch start/stop in DIW coordinates. */
1.1.1.11 root 241: int ddf_left = dp_for_drawing->plfleft * 2 + DIW_DDF_OFFSET;
242: int ddf_right = dp_for_drawing->plfright * 2 + DIW_DDF_OFFSET;
1.1.1.8 root 243: /* Compute datafetch start/stop in pixels; native display coordinates. */
1.1.1.11 root 244: int native_ddf_left = coord_hw_to_window_x (ddf_left);
245: int native_ddf_right = coord_hw_to_window_x (ddf_right);
1.1.1.8 root 246:
247: int linetoscr_diw_start = dp_for_drawing->diwfirstword;
248: int linetoscr_diw_end = dp_for_drawing->diwlastword;
249:
250: if (dip_for_drawing->nr_sprites == 0) {
251: if (linetoscr_diw_start < native_ddf_left)
252: linetoscr_diw_start = native_ddf_left;
253: if (linetoscr_diw_end > native_ddf_right)
254: linetoscr_diw_end = native_ddf_right;
1.1 root 255: }
256:
1.1.1.8 root 257: /* Perverse cases happen. */
258: if (linetoscr_diw_end < linetoscr_diw_start)
259: linetoscr_diw_end = linetoscr_diw_start;
1.1 root 260:
1.1.1.8 root 261: playfield_start = linetoscr_diw_start;
262: playfield_end = linetoscr_diw_end;
1.1 root 263:
1.1.1.8 root 264: if (playfield_start < visible_left_border)
265: playfield_start = visible_left_border;
266: if (playfield_start > visible_right_border)
267: playfield_start = visible_right_border;
268: if (playfield_end < visible_left_border)
269: playfield_end = visible_left_border;
270: if (playfield_end > visible_right_border)
271: playfield_end = visible_right_border;
272:
273: /* Now, compute some offsets. */
274:
275: res_shift = lores_shift - bplres;
1.1.1.11 root 276: ddf_left -= DISPLAY_LEFT_SHIFT;
277: ddf_left <<= bplres;
1.1.1.12 root 278: pixels_offset = MAX_PIXELS_PER_LINE - ddf_left;
1.1.1.11 root 279:
1.1.1.8 root 280: unpainted = visible_left_border < playfield_start ? 0 : visible_left_border - playfield_start;
1.1.1.12 root 281: src_pixel = MAX_PIXELS_PER_LINE + res_shift_from_window (playfield_start - native_ddf_left + unpainted);
1.1 root 282:
1.1.1.8 root 283: if (dip_for_drawing->nr_sprites == 0)
1.1 root 284: return;
1.1.1.8 root 285: /* Must clear parts of apixels. */
286: if (linetoscr_diw_start < native_ddf_left) {
287: int size = res_shift_from_window (native_ddf_left - linetoscr_diw_start);
288: linetoscr_diw_start = native_ddf_left;
1.1.1.12 root 289: memset (pixdata.apixels + MAX_PIXELS_PER_LINE - size, 0, size);
1.1.1.8 root 290: }
291: if (linetoscr_diw_end > native_ddf_right) {
292: int pos = res_shift_from_window (native_ddf_right - native_ddf_left);
293: int size = res_shift_from_window (linetoscr_diw_end - native_ddf_right);
294: linetoscr_diw_start = native_ddf_left;
1.1.1.12 root 295: memset (pixdata.apixels + MAX_PIXELS_PER_LINE + pos, 0, size);
1.1 root 296: }
297: }
1.1.1.2 root 298:
1.1.1.8 root 299: /* If C++ compilers didn't suck, we'd use templates. */
300:
301: #define TYPE uae_u8
302: #define LNAME linetoscr_8
303: #define SRC_INC 1
304: #define HDOUBLE 0
1.1.1.9 root 305: #define AGA 0
1.1.1.8 root 306: #include "linetoscr.c"
1.1.1.9 root 307: #define LNAME linetoscr_8_stretch1
1.1.1.8 root 308: #define SRC_INC 1
309: #define HDOUBLE 1
1.1.1.9 root 310: #define AGA 0
1.1.1.8 root 311: #include "linetoscr.c"
1.1.1.9 root 312: #define LNAME linetoscr_8_shrink1
1.1.1.8 root 313: #define SRC_INC 2
314: #define HDOUBLE 0
1.1.1.9 root 315: #define AGA 0
316: #include "linetoscr.c"
317:
318: #define LNAME linetoscr_8_aga
319: #define SRC_INC 1
320: #define HDOUBLE 0
321: #define AGA 1
322: #include "linetoscr.c"
323: #define LNAME linetoscr_8_stretch1_aga
324: #define SRC_INC 1
325: #define HDOUBLE 1
326: #define AGA 1
327: #include "linetoscr.c"
328: #define LNAME linetoscr_8_shrink1_aga
329: #define SRC_INC 2
330: #define HDOUBLE 0
331: #define AGA 1
1.1.1.8 root 332: #include "linetoscr.c"
333:
334: #undef TYPE
1.1.1.9 root 335:
1.1.1.8 root 336: #define TYPE uae_u16
337: #define LNAME linetoscr_16
338: #define SRC_INC 1
339: #define HDOUBLE 0
1.1.1.9 root 340: #define AGA 0
1.1.1.8 root 341: #include "linetoscr.c"
1.1.1.9 root 342: #define LNAME linetoscr_16_stretch1
1.1.1.8 root 343: #define SRC_INC 1
344: #define HDOUBLE 1
1.1.1.9 root 345: #define AGA 0
1.1.1.8 root 346: #include "linetoscr.c"
1.1.1.9 root 347: #define LNAME linetoscr_16_shrink1
1.1.1.8 root 348: #define SRC_INC 2
349: #define HDOUBLE 0
1.1.1.9 root 350: #define AGA 0
351: #include "linetoscr.c"
352:
353: #define LNAME linetoscr_16_aga
354: #define SRC_INC 1
355: #define HDOUBLE 0
356: #define AGA 1
357: #include "linetoscr.c"
358: #define LNAME linetoscr_16_stretch1_aga
359: #define SRC_INC 1
360: #define HDOUBLE 1
361: #define AGA 1
362: #include "linetoscr.c"
363: #define LNAME linetoscr_16_shrink1_aga
364: #define SRC_INC 2
365: #define HDOUBLE 0
366: #define AGA 1
1.1.1.8 root 367: #include "linetoscr.c"
368:
369: #undef TYPE
1.1.1.9 root 370:
1.1.1.8 root 371: #define TYPE uae_u32
372: #define LNAME linetoscr_32
373: #define SRC_INC 1
374: #define HDOUBLE 0
1.1.1.9 root 375: #define AGA 0
1.1.1.8 root 376: #include "linetoscr.c"
1.1.1.9 root 377: #define LNAME linetoscr_32_stretch1
1.1.1.8 root 378: #define SRC_INC 1
379: #define HDOUBLE 1
1.1.1.9 root 380: #define AGA 0
1.1.1.8 root 381: #include "linetoscr.c"
1.1.1.9 root 382: #define LNAME linetoscr_32_shrink1
1.1.1.8 root 383: #define SRC_INC 2
384: #define HDOUBLE 0
1.1.1.9 root 385: #define AGA 0
386: #include "linetoscr.c"
387:
388: #define LNAME linetoscr_32_aga
389: #define SRC_INC 1
390: #define HDOUBLE 0
391: #define AGA 1
392: #include "linetoscr.c"
393: #define LNAME linetoscr_32_stretch1_aga
394: #define SRC_INC 1
395: #define HDOUBLE 1
396: #define AGA 1
397: #include "linetoscr.c"
398: #define LNAME linetoscr_32_shrink1_aga
399: #define SRC_INC 2
400: #define HDOUBLE 0
401: #define AGA 1
1.1.1.8 root 402: #include "linetoscr.c"
1.1 root 403:
1.1.1.9 root 404: #undef TYPE
405:
1.1.1.8 root 406: static void fill_line_8 (char *buf, int start, int stop)
1.1 root 407: {
1.1.1.8 root 408: uae_u8 *b = (uae_u8 *)buf;
1.1 root 409: int i;
1.1.1.8 root 410: xcolnr col = colors_for_drawing.acolors[0];
411: for (i = start; i < stop; i++)
412: b[i] = col;
1.1 root 413: }
1.1.1.8 root 414: static void fill_line_16 (char *buf, int start, int stop)
1.1 root 415: {
1.1.1.8 root 416: uae_u16 *b = (uae_u16 *)buf;
1.1 root 417: int i;
1.1.1.8 root 418: xcolnr col = colors_for_drawing.acolors[0];
419: for (i = start; i < stop; i++)
420: b[i] = col;
1.1 root 421: }
1.1.1.8 root 422: static void fill_line_32 (char *buf, int start, int stop)
1.1 root 423: {
1.1.1.8 root 424: uae_u32 *b = (uae_u32 *)buf;
1.1 root 425: int i;
1.1.1.8 root 426: xcolnr col = colors_for_drawing.acolors[0];
427: for (i = start; i < stop; i++)
428: b[i] = col;
1.1.1.2 root 429: }
430:
1.1.1.6 root 431: STATIC_INLINE void fill_line (void)
1.1 root 432: {
433: int shift;
434: int nints, nrem;
435: int *start;
436: xcolnr val;
437:
438: shift = 0;
439: if (gfxvidinfo.pixbytes == 2)
440: shift = 1;
441: if (gfxvidinfo.pixbytes == 4)
442: shift = 2;
443:
444: nints = gfxvidinfo.width >> (2-shift);
445: nrem = nints & 7;
446: nints &= ~7;
1.1.1.8 root 447: start = (int *)(((char *)xlinebuffer) + (visible_left_border << shift));
1.1 root 448: val = colors_for_drawing.acolors[0];
1.1.1.9 root 449: if (gfxvidinfo.pixbytes == 2)
450: val |= val << 16;
1.1 root 451: for (; nints > 0; nints -= 8, start += 8) {
452: *start = val;
453: *(start+1) = val;
454: *(start+2) = val;
455: *(start+3) = val;
456: *(start+4) = val;
457: *(start+5) = val;
458: *(start+6) = val;
459: *(start+7) = val;
460: }
461:
462: switch (nrem) {
463: case 7:
464: *start++ = val;
465: case 6:
466: *start++ = val;
467: case 5:
468: *start++ = val;
469: case 4:
470: *start++ = val;
471: case 3:
472: *start++ = val;
473: case 2:
474: *start++ = val;
475: case 1:
476: *start = val;
477: }
478: }
479:
1.1.1.8 root 480: static int linetoscr_double_offset;
1.1 root 481:
1.1.1.8 root 482: static void pfield_do_linetoscr (int start, int stop)
483: {
1.1.1.9 root 484: if (currprefs.chipset_mask & CSMASK_AGA) {
485: if (res_shift == 0)
486: switch (gfxvidinfo.pixbytes) {
487: case 1: src_pixel = linetoscr_8_aga (src_pixel, start, stop); break;
488: case 2: src_pixel = linetoscr_16_aga (src_pixel, start, stop); break;
489: case 4: src_pixel = linetoscr_32_aga (src_pixel, start, stop); break;
490: }
491: else if (res_shift == 1)
492: switch (gfxvidinfo.pixbytes) {
493: case 1: src_pixel = linetoscr_8_stretch1_aga (src_pixel, start, stop); break;
494: case 2: src_pixel = linetoscr_16_stretch1_aga (src_pixel, start, stop); break;
495: case 4: src_pixel = linetoscr_32_stretch1_aga (src_pixel, start, stop); break;
496: }
497: else if (res_shift == -1)
498: switch (gfxvidinfo.pixbytes) {
499: case 1: src_pixel = linetoscr_8_shrink1_aga (src_pixel, start, stop); break;
500: case 2: src_pixel = linetoscr_16_shrink1_aga (src_pixel, start, stop); break;
501: case 4: src_pixel = linetoscr_32_shrink1_aga (src_pixel, start, stop); break;
502: }
503: else
504: abort ();
505: } else {
506: if (res_shift == 0)
507: switch (gfxvidinfo.pixbytes) {
508: case 1: src_pixel = linetoscr_8 (src_pixel, start, stop); break;
509: case 2: src_pixel = linetoscr_16 (src_pixel, start, stop); break;
510: case 4: src_pixel = linetoscr_32 (src_pixel, start, stop); break;
511: }
512: else if (res_shift == 1)
513: switch (gfxvidinfo.pixbytes) {
514: case 1: src_pixel = linetoscr_8_stretch1 (src_pixel, start, stop); break;
515: case 2: src_pixel = linetoscr_16_stretch1 (src_pixel, start, stop); break;
516: case 4: src_pixel = linetoscr_32_stretch1 (src_pixel, start, stop); break;
517: }
518: else if (res_shift == -1)
519: switch (gfxvidinfo.pixbytes) {
520: case 1: src_pixel = linetoscr_8_shrink1 (src_pixel, start, stop); break;
521: case 2: src_pixel = linetoscr_16_shrink1 (src_pixel, start, stop); break;
522: case 4: src_pixel = linetoscr_32_shrink1 (src_pixel, start, stop); break;
523: }
524: else
525: abort ();
526: }
1.1 root 527: }
528:
1.1.1.8 root 529: static void pfield_do_fill_line (int start, int stop)
1.1 root 530: {
1.1.1.8 root 531: switch (gfxvidinfo.pixbytes) {
532: case 1: fill_line_8 (xlinebuffer, start, stop); break;
533: case 2: fill_line_16 (xlinebuffer, start, stop); break;
534: case 4: fill_line_32 (xlinebuffer, start, stop); break;
1.1 root 535: }
536: }
537:
1.1.1.8 root 538: static void pfield_do_linetoscr_full (int double_line)
1.1 root 539: {
540: char *oldxlb = (char *)xlinebuffer;
1.1.1.8 root 541: int old_src_pixel = src_pixel;
542:
543: pfield_do_linetoscr (playfield_start, playfield_end);
1.1 root 544: xlinebuffer = oldxlb + linetoscr_double_offset;
1.1.1.8 root 545: src_pixel = old_src_pixel;
546: pfield_do_linetoscr (playfield_start, playfield_end);
1.1 root 547: }
1.1.1.8 root 548:
549: static void dummy_worker (int start, int stop)
1.1 root 550: {
551: }
552:
1.1.1.8 root 553: static unsigned int ham_lastcolor;
1.1.1.2 root 554:
1.1.1.8 root 555: static int ham_decode_pixel;
1.1 root 556:
1.1.1.8 root 557: /* Decode HAM in the invisible portion of the display (left of VISIBLE_LEFT_BORDER),
558: but don't draw anything in. This is done to prepare HAM_LASTCOLOR for later,
1.1.1.9 root 559: when decode_ham runs. */
1.1.1.8 root 560: static void init_ham_decoding (void)
1.1 root 561: {
1.1.1.8 root 562: int unpainted_amiga = res_shift_from_window (unpainted);
563: ham_decode_pixel = src_pixel;
1.1.1.9 root 564: ham_lastcolor = color_reg_get (&colors_for_drawing, 0);
565:
566: if (currprefs.chipset_mask & CSMASK_AGA) {
567: if (bplplanecnt == 8) { /* AGA mode HAM8 */
568: while (unpainted_amiga-- > 0) {
569: int pv = pixdata.apixels[ham_decode_pixel++];
570: switch (pv & 0x3) {
571: case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break;
572: case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break;
573: case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break;
574: case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break;
575: }
576: }
577: } else if(bplplanecnt == 6) { /* AGA mode HAM6 */
578: while (unpainted_amiga-- > 0) {
579: int pv = pixdata.apixels[ham_decode_pixel++];
580: switch (pv & 0x30) {
581: case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break;
582: case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break;
583: case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break;
584: case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break;
585: }
586: }
587: }
588: } else {
589: if (bplplanecnt == 6) { /* OCS/ECS mode HAM6 */
590: while (unpainted_amiga-- > 0) {
591: int pv = pixdata.apixels[ham_decode_pixel++];
592: switch (pv & 0x30) {
593: case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break;
594: case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break;
595: case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break;
596: case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break;
597: }
598: }
1.1 root 599: }
600: }
601: }
602:
1.1.1.9 root 603: static void decode_ham (int pix, int stoppos)
1.1 root 604: {
1.1.1.8 root 605: int todraw_amiga = res_shift_from_window (stoppos - pix);
1.1.1.13 root 606: if (!bplham)
1.1.1.8 root 607: abort ();
1.1 root 608:
1.1.1.9 root 609: if (currprefs.chipset_mask & CSMASK_AGA) {
610: if (bplplanecnt == 8) { /* AGA mode HAM8 */
611: while (todraw_amiga-- > 0) {
612: int pv = pixdata.apixels[ham_decode_pixel];
613: switch (pv & 0x3) {
614: case 0x0: ham_lastcolor = colors_for_drawing.color_regs_aga[pv >> 2]; break;
615: case 0x1: ham_lastcolor &= 0xFFFF03; ham_lastcolor |= (pv & 0xFC); break;
616: case 0x2: ham_lastcolor &= 0x03FFFF; ham_lastcolor |= (pv & 0xFC) << 16; break;
617: case 0x3: ham_lastcolor &= 0xFF03FF; ham_lastcolor |= (pv & 0xFC) << 8; break;
618: }
619: ham_linebuf[ham_decode_pixel++] = ham_lastcolor;
620: }
621: } else if(bplplanecnt == 6) { /* AGA mode HAM6 */
622: while (todraw_amiga-- > 0) {
623: int pv = pixdata.apixels[ham_decode_pixel];
624: switch (pv & 0x30) {
625: case 0x00: ham_lastcolor = colors_for_drawing.color_regs_aga[pv]; break;
626: case 0x10: ham_lastcolor &= 0xFFFF00; ham_lastcolor |= (pv & 0xF) << 4; break;
627: case 0x20: ham_lastcolor &= 0x00FFFF; ham_lastcolor |= (pv & 0xF) << 20; break;
628: case 0x30: ham_lastcolor &= 0xFF00FF; ham_lastcolor |= (pv & 0xF) << 12; break;
629: }
630: ham_linebuf[ham_decode_pixel++] = ham_lastcolor;
631: }
632: }
633: } else {
634: if (bplplanecnt == 6) { /* OCS/ECS mode HAM6 */
635: while (todraw_amiga-- > 0) {
636: int pv = pixdata.apixels[ham_decode_pixel];
637: switch (pv & 0x30) {
638: case 0x00: ham_lastcolor = colors_for_drawing.color_regs_ecs[pv]; break;
639: case 0x10: ham_lastcolor &= 0xFF0; ham_lastcolor |= (pv & 0xF); break;
640: case 0x20: ham_lastcolor &= 0x0FF; ham_lastcolor |= (pv & 0xF) << 8; break;
641: case 0x30: ham_lastcolor &= 0xF0F; ham_lastcolor |= (pv & 0xF) << 4; break;
642: }
643: ham_linebuf[ham_decode_pixel++] = ham_lastcolor;
644: }
1.1 root 645: }
646: }
647: }
648:
1.1.1.2 root 649: static void gen_pfield_tables (void)
1.1 root 650: {
651: int i;
652:
653: /* For now, the AGA stuff is broken in the dual playfield case. We encode
654: * sprites in dpf mode by ORing the pixel value with 0x80. To make dual
655: * playfield rendering easy, the lookup tables contain are made linear for
656: * values >= 128. That only works for OCS/ECS, though. */
657:
658: for (i = 0; i < 256; i++) {
659: int plane1 = (i & 1) | ((i >> 1) & 2) | ((i >> 2) & 4) | ((i >> 3) & 8);
660: int plane2 = ((i >> 1) & 1) | ((i >> 2) & 2) | ((i >> 3) & 4) | ((i >> 4) & 8);
1.1.1.11 root 661:
1.1.1.12 root 662: dblpf_2nd1[i] = plane1 == 0 ? (plane2 == 0 ? 0 : 2) : 1;
663: dblpf_2nd2[i] = plane2 == 0 ? (plane1 == 0 ? 0 : 1) : 2;
664: dblpf_ind1_aga[i] = plane1 == 0 ? plane2 : plane1;
665: dblpf_ind2_aga[i] = plane2 == 0 ? plane1 : plane2;
666:
1.1.1.11 root 667: dblpf_ms1[i] = plane1 == 0 ? (plane2 == 0 ? 16 : 8) : 0;
668: dblpf_ms2[i] = plane2 == 0 ? (plane1 == 0 ? 16 : 0) : 8;
669: dblpf_ms[i] = i == 0 ? 16 : 8;
1.1 root 670: if (plane2 > 0)
671: plane2 += 8;
672: dblpf_ind1[i] = i >= 128 ? i & 0x7F : (plane1 == 0 ? plane2 : plane1);
673: dblpf_ind2[i] = i >= 128 ? i & 0x7F : (plane2 == 0 ? plane1 : plane2);
674:
1.1.1.11 root 675: sprite_offs[i] = (i & 15) ? 0 : 2;
1.1 root 676:
677: clxtab[i] = ((((i & 3) && (i & 12)) << 9)
678: | (((i & 3) && (i & 48)) << 10)
679: | (((i & 3) && (i & 192)) << 11)
680: | (((i & 12) && (i & 48)) << 12)
681: | (((i & 12) && (i & 192)) << 13)
682: | (((i & 48) && (i & 192)) << 14));
683: }
684: }
685:
1.1.1.11 root 686: /* When looking at this function and the ones that inline it, bear in mind
687: what an optimizing compiler will do with this code. All callers of this
688: function only pass in constant arguments (except for E). This means
689: that many of the if statements will go away completely after inlining. */
1.1.1.13 root 690: STATIC_INLINE void draw_sprites_1 (struct sprite_entry *e, int ham, int dualpf,
691: int doubling, int skip, int has_attach, int aga)
1.1.1.11 root 692: {
693: int *shift_lookup = dualpf ? (bpldualpfpri ? dblpf_ms2 : dblpf_ms1) : dblpf_ms;
694: uae_u16 *buf = spixels + e->first_pixel;
695: uae_u8 *stbuf = spixstate.bytes + e->first_pixel;
1.1.1.13 root 696: int pos, window_pos;
697: uae_u8 xor_val = (uae_u8)(dp_for_drawing->bplcon4 >> 8);
1.1.1.11 root 698:
699: buf -= e->pos;
700: stbuf -= e->pos;
701:
1.1.1.13 root 702: window_pos = e->pos + ((DIW_DDF_OFFSET - DISPLAY_LEFT_SHIFT) << (aga ? 1 : 0));
703: if (skip)
704: window_pos >>= 1;
705: else if (doubling)
706: window_pos <<= 1;
707: window_pos += pixels_offset;
708: for (pos = e->pos; pos < e->max; pos += 1 << skip) {
1.1.1.11 root 709: int maskshift, plfmask;
710: unsigned int v = buf[pos];
711:
712: /* The value in the shift lookup table is _half_ the shift count we
713: need. This is because we can't shift 32 bits at once (undefined
714: behaviour in C). */
1.1.1.13 root 715: maskshift = shift_lookup[pixdata.apixels[window_pos]];
1.1.1.11 root 716: plfmask = (plf_sprite_mask >> maskshift) >> maskshift;
717: v &= ~plfmask;
718: if (v != 0) {
1.1.1.13 root 719: unsigned int vlo, vhi, col;
1.1.1.11 root 720: unsigned int v1 = v & 255;
721: /* OFFS determines the sprite pair with the highest priority that has
722: any bits set. E.g. if we have 0xFF00 in the buffer, we have sprite
723: pairs 01 and 23 cleared, and pairs 45 and 67 set, so OFFS will
724: have a value of 4.
725: 2 * OFFS is the bit number in V of the sprite pair, and it also
726: happens to be the color offset for that pair. */
727: int offs;
728: if (v1 == 0)
729: offs = 4 + sprite_offs[v >> 8];
730: else
731: offs = sprite_offs[v1];
732:
733: /* Shift highest priority sprite pair down to bit zero. */
734: v >>= offs * 2;
735: v &= 15;
736:
737: if (has_attach && (stbuf[pos] & (1 << offs))) {
738: col = v;
1.1.1.13 root 739: if (aga)
740: col += sbasecol[1];
741: else
742: col += 16;
1.1.1.11 root 743: } else {
744: /* This sequence computes the correct color value. We have to select
745: either the lower-numbered or the higher-numbered sprite in the pair.
746: We have to select the high one if the low one has all bits zero.
747: If the lower-numbered sprite has any bits nonzero, (VLO - 1) is in
748: the range of 0..2, and with the mask and shift, VHI will be zero.
749: If the lower-numbered sprite is zero, (VLO - 1) is a mask of
750: 0xFFFFFFFF, and we select the bits of the higher numbered sprite
751: in VHI.
752: This is _probably_ more efficient than doing it with branches. */
753: vlo = v & 3;
754: vhi = (v & (vlo - 1)) >> 2;
1.1.1.13 root 755: col = (vlo | vhi);
756: if (aga) {
757: if (vhi > 0)
758: col += sbasecol[1];
759: else
760: col += sbasecol[0];
761: } else {
762: col += 16;
763: }
1.1.1.11 root 764: col += (offs * 2);
765: }
1.1.1.13 root 766: if (dualpf) {
767: if (aga) {
768: spriteagadpfpixels[window_pos] = col;
769: if (doubling)
770: spriteagadpfpixels[window_pos + 1] = col;
771: } else {
772: col += 128;
773: if (doubling)
774: pixdata.apixels_w[window_pos >> 1] = col | (col << 8);
775: else
776: pixdata.apixels[window_pos] = col;
1.1 root 777: }
1.1.1.13 root 778: } else if (ham) {
779: col = color_reg_get (&colors_for_drawing, col);
780: if (aga)
781: col ^= xor_val;
782: ham_linebuf[window_pos] = col;
783: if (doubling)
784: ham_linebuf[window_pos + 1] = col;
1.1 root 785: } else {
1.1.1.13 root 786: if (aga)
787: col ^= xor_val;
788: if (doubling)
789: pixdata.apixels_w[window_pos >> 1] = col | (col << 8);
1.1.1.11 root 790: else
1.1.1.13 root 791: pixdata.apixels[window_pos] = col;
1.1 root 792: }
793: }
1.1.1.13 root 794: window_pos += 1 << doubling;
1.1 root 795: }
796: }
1.1.1.11 root 797:
798: /* See comments above. Do not touch if you don't know what's going on.
799: * (We do _not_ want the following to be inlined themselves). */
1.1.1.13 root 800: /* lores bitplane, lores sprites */
801: static void draw_sprites_normal_sp_lo_nat (struct sprite_entry *e) { draw_sprites_1 (e, 0, 0, 0, 0, 0, 0); }
802: static void draw_sprites_normal_dp_lo_nat (struct sprite_entry *e) { draw_sprites_1 (e, 0, 1, 0, 0, 0, 0); }
803: static void draw_sprites_ham_sp_lo_nat (struct sprite_entry *e) { draw_sprites_1 (e, 1, 0, 0, 0, 0, 0); }
804: static void draw_sprites_normal_sp_lo_at (struct sprite_entry *e) { draw_sprites_1 (e, 0, 0, 0, 0, 1, 0); }
805: static void draw_sprites_normal_dp_lo_at (struct sprite_entry *e) { draw_sprites_1 (e, 0, 1, 0, 0, 1, 0); }
806: static void draw_sprites_ham_sp_lo_at (struct sprite_entry *e) { draw_sprites_1 (e, 1, 0, 0, 0, 1, 0); }
807: /* hires bitplane, lores sprites */
808: static void draw_sprites_normal_sp_hi_nat (struct sprite_entry *e) { draw_sprites_1 (e, 0, 0, 1, 0, 0, 0); }
809: static void draw_sprites_normal_dp_hi_nat (struct sprite_entry *e) { draw_sprites_1 (e, 0, 1, 1, 0, 0, 0); }
810: static void draw_sprites_ham_sp_hi_nat (struct sprite_entry *e) { draw_sprites_1 (e, 1, 0, 1, 0, 0, 0); }
811: static void draw_sprites_normal_sp_hi_at (struct sprite_entry *e) { draw_sprites_1 (e, 0, 0, 1, 0, 1, 0); }
812: static void draw_sprites_normal_dp_hi_at (struct sprite_entry *e) { draw_sprites_1 (e, 0, 1, 1, 0, 1, 0); }
813: static void draw_sprites_ham_sp_hi_at (struct sprite_entry *e) { draw_sprites_1 (e, 1, 0, 1, 0, 1, 0); }
814:
815: /* not very optimized */
816: STATIC_INLINE void draw_sprites_aga (struct sprite_entry *e)
817: {
818: int diff = RES_HIRES - bplres;
819: if (diff > 0)
820: draw_sprites_1 (e, bplham, bpldualpf, 0, diff, e->has_attached, 1);
821: else
822: draw_sprites_1 (e, bplham, bpldualpf, -diff, 0, e->has_attached, 1);
823: }
824:
1.1.1.11 root 825:
1.1.1.13 root 826: STATIC_INLINE void draw_sprites_ecs (struct sprite_entry *e)
1.1.1.11 root 827: {
828: if (e->has_attached)
829: if (bplres == 1)
830: if (bplham)
831: draw_sprites_ham_sp_hi_at (e);
832: else
833: if (bpldualpf)
834: draw_sprites_normal_dp_hi_at (e);
835: else
836: draw_sprites_normal_sp_hi_at (e);
837: else
838: if (bplham)
839: draw_sprites_ham_sp_lo_at (e);
840: else
841: if (bpldualpf)
842: draw_sprites_normal_dp_lo_at (e);
843: else
844: draw_sprites_normal_sp_lo_at (e);
845: else
846: if (bplres == 1)
847: if (bplham)
848: draw_sprites_ham_sp_hi_nat (e);
849: else
850: if (bpldualpf)
851: draw_sprites_normal_dp_hi_nat (e);
852: else
853: draw_sprites_normal_sp_hi_nat (e);
854: else
855: if (bplham)
856: draw_sprites_ham_sp_lo_nat (e);
857: else
858: if (bpldualpf)
859: draw_sprites_normal_dp_lo_nat (e);
860: else
861: draw_sprites_normal_sp_lo_nat (e);
1.1 root 862: }
863:
1.1.1.13 root 864:
1.1.1.8 root 865: #define MERGE(a,b,mask,shift) do {\
866: uae_u32 tmp = mask & (a ^ (b >> shift)); \
867: a ^= tmp; \
868: b ^= (tmp << shift); \
869: } while (0)
870:
1.1.1.11 root 871: #define GETLONG(P) (*(uae_u32 *)P)
872:
873: /* We use the compiler's inlining ability to ensure that PLANES is in effect a compile time
874: constant. That will cause some unnecessary code to be optimized away.
1.1.1.8 root 875: Don't touch this if you don't know what you are doing. */
1.1.1.11 root 876: STATIC_INLINE void pfield_doline_1 (uae_u32 *pixels, int wordcount, int planes)
1.1.1.8 root 877: {
878: while (wordcount-- > 0) {
879: uae_u32 b0, b1, b2, b3, b4, b5, b6, b7;
880:
881: b0 = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0, b7 = 0;
882: switch (planes) {
1.1.1.11 root 883: case 8: b0 = GETLONG ((uae_u32 *)real_bplpt[7]); real_bplpt[7] += 4;
884: case 7: b1 = GETLONG ((uae_u32 *)real_bplpt[6]); real_bplpt[6] += 4;
885: case 6: b2 = GETLONG ((uae_u32 *)real_bplpt[5]); real_bplpt[5] += 4;
886: case 5: b3 = GETLONG ((uae_u32 *)real_bplpt[4]); real_bplpt[4] += 4;
887: case 4: b4 = GETLONG ((uae_u32 *)real_bplpt[3]); real_bplpt[3] += 4;
888: case 3: b5 = GETLONG ((uae_u32 *)real_bplpt[2]); real_bplpt[2] += 4;
889: case 2: b6 = GETLONG ((uae_u32 *)real_bplpt[1]); real_bplpt[1] += 4;
890: case 1: b7 = GETLONG ((uae_u32 *)real_bplpt[0]); real_bplpt[0] += 4;
1.1.1.8 root 891: }
892:
893: MERGE (b0, b1, 0x55555555, 1);
894: MERGE (b2, b3, 0x55555555, 1);
895: MERGE (b4, b5, 0x55555555, 1);
896: MERGE (b6, b7, 0x55555555, 1);
897:
898: MERGE (b0, b2, 0x33333333, 2);
899: MERGE (b1, b3, 0x33333333, 2);
900: MERGE (b4, b6, 0x33333333, 2);
901: MERGE (b5, b7, 0x33333333, 2);
902:
903: MERGE (b0, b4, 0x0f0f0f0f, 4);
904: MERGE (b1, b5, 0x0f0f0f0f, 4);
905: MERGE (b2, b6, 0x0f0f0f0f, 4);
906: MERGE (b3, b7, 0x0f0f0f0f, 4);
907:
908: MERGE (b0, b1, 0x00ff00ff, 8);
909: MERGE (b2, b3, 0x00ff00ff, 8);
910: MERGE (b4, b5, 0x00ff00ff, 8);
911: MERGE (b6, b7, 0x00ff00ff, 8);
912:
913: MERGE (b0, b2, 0x0000ffff, 16);
914: do_put_mem_long (pixels, b0);
915: do_put_mem_long (pixels + 4, b2);
916: MERGE (b1, b3, 0x0000ffff, 16);
917: do_put_mem_long (pixels + 2, b1);
918: do_put_mem_long (pixels + 6, b3);
919: MERGE (b4, b6, 0x0000ffff, 16);
920: do_put_mem_long (pixels + 1, b4);
921: do_put_mem_long (pixels + 5, b6);
922: MERGE (b5, b7, 0x0000ffff, 16);
923: do_put_mem_long (pixels + 3, b5);
924: do_put_mem_long (pixels + 7, b7);
925: pixels += 8;
926: }
927: }
928:
929: /* See above for comments on inlining. These functions should _not_
930: be inlined themselves. */
1.1.1.11 root 931: static void pfield_doline_n1 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 1); }
932: static void pfield_doline_n2 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 2); }
933: static void pfield_doline_n3 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 3); }
934: static void pfield_doline_n4 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 4); }
935: static void pfield_doline_n5 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 5); }
936: static void pfield_doline_n6 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 6); }
937: static void pfield_doline_n7 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 7); }
938: static void pfield_doline_n8 (uae_u32 *data, int count) { pfield_doline_1 (data, count, 8); }
1.1.1.8 root 939:
940: static void pfield_doline (int lineno)
941: {
1.1.1.11 root 942: int wordcount = dp_for_drawing->plflinelen;
1.1.1.12 root 943: uae_u32 *data = pixdata.apixels_l + MAX_PIXELS_PER_LINE/4;
1.1 root 944:
945: #ifdef SMART_UPDATE
1.1.1.8 root 946: #define DATA_POINTER(n) (line_data[lineno] + (n)*MAX_WORDS_PER_LINE*2)
947: real_bplpt[0] = DATA_POINTER (0);
948: real_bplpt[1] = DATA_POINTER (1);
949: real_bplpt[2] = DATA_POINTER (2);
950: real_bplpt[3] = DATA_POINTER (3);
951: real_bplpt[4] = DATA_POINTER (4);
952: real_bplpt[5] = DATA_POINTER (5);
953: real_bplpt[6] = DATA_POINTER (6);
954: real_bplpt[7] = DATA_POINTER (7);
955: #endif
956:
1.1.1.11 root 957: switch (bplplanecnt) {
958: default: break;
959: case 0: memset (data, 0, wordcount * 32); break;
960: case 1: pfield_doline_n1 (data, wordcount); break;
961: case 2: pfield_doline_n2 (data, wordcount); break;
962: case 3: pfield_doline_n3 (data, wordcount); break;
963: case 4: pfield_doline_n4 (data, wordcount); break;
964: case 5: pfield_doline_n5 (data, wordcount); break;
965: case 6: pfield_doline_n6 (data, wordcount); break;
966: case 7: pfield_doline_n7 (data, wordcount); break;
967: case 8: pfield_doline_n8 (data, wordcount); break;
1.1 root 968: }
969: }
970:
971: void init_row_map (void)
972: {
973: int i;
974: if (gfxvidinfo.height > 2048) {
975: write_log ("Resolution too high, aborting\n");
976: abort ();
977: }
978: for (i = 0; i < gfxvidinfo.height + 1; i++)
979: row_map[i] = gfxvidinfo.bufmem + gfxvidinfo.rowbytes * i;
980: }
981:
982: static void init_aspect_maps (void)
983: {
984: int i, maxl;
985: double native_lines_per_amiga_line;
986:
987: if (native2amiga_line_map)
988: free (native2amiga_line_map);
989: if (amiga2aspect_line_map)
990: free (amiga2aspect_line_map);
991:
992: /* At least for this array the +1 is necessary. */
1.1.1.5 root 993: amiga2aspect_line_map = (int *)malloc (sizeof (int) * (MAXVPOS + 1)*2 + 1);
1.1 root 994: native2amiga_line_map = (int *)malloc (sizeof (int) * gfxvidinfo.height);
995:
996: if (currprefs.gfx_correct_aspect)
997: native_lines_per_amiga_line = ((double)gfxvidinfo.height
998: * (currprefs.gfx_lores ? 320 : 640)
999: / (currprefs.gfx_linedbl ? 512 : 256)
1000: / gfxvidinfo.width);
1001: else
1002: native_lines_per_amiga_line = 1;
1003:
1.1.1.5 root 1004: maxl = (MAXVPOS + 1) * (currprefs.gfx_linedbl ? 2 : 1);
1.1 root 1005: min_ypos_for_screen = minfirstline << (currprefs.gfx_linedbl ? 1 : 0);
1006: max_drawn_amiga_line = -1;
1007: for (i = 0; i < maxl; i++) {
1.1.1.9 root 1008: int v = (int) ((i - min_ypos_for_screen) * native_lines_per_amiga_line);
1.1 root 1009: if (v >= gfxvidinfo.height && max_drawn_amiga_line == -1)
1010: max_drawn_amiga_line = i - min_ypos_for_screen;
1011: if (i < min_ypos_for_screen || v >= gfxvidinfo.height)
1012: v = -1;
1013: amiga2aspect_line_map[i] = v;
1014: }
1015: if (currprefs.gfx_linedbl)
1016: max_drawn_amiga_line >>= 1;
1017:
1018: if (currprefs.gfx_ycenter && !(currprefs.gfx_correct_aspect)) {
1.1.1.5 root 1019: /* @@@ verify maxvpos vs. MAXVPOS */
1.1 root 1020: extra_y_adjust = (gfxvidinfo.height - (maxvpos << (currprefs.gfx_linedbl ? 1 : 0))) >> 1;
1021: if (extra_y_adjust < 0)
1022: extra_y_adjust = 0;
1023: }
1024:
1025: for (i = 0; i < gfxvidinfo.height; i++)
1026: native2amiga_line_map[i] = -1;
1027:
1028: if (native_lines_per_amiga_line < 1) {
1029: /* Must omit drawing some lines. */
1030: for (i = maxl - 1; i > min_ypos_for_screen; i--) {
1031: if (amiga2aspect_line_map[i] == amiga2aspect_line_map[i-1]) {
1032: if (currprefs.gfx_linedbl && (i & 1) == 0 && amiga2aspect_line_map[i+1] != -1) {
1033: /* If only the first line of a line pair would be omitted,
1034: * omit the second one instead to avoid problems with line
1035: * doubling. */
1036: amiga2aspect_line_map[i] = amiga2aspect_line_map[i+1];
1037: amiga2aspect_line_map[i+1] = -1;
1038: } else
1039: amiga2aspect_line_map[i] = -1;
1040: }
1041: }
1042: }
1043:
1044: for (i = maxl-1; i >= min_ypos_for_screen; i--) {
1045: int j;
1046: if (amiga2aspect_line_map[i] == -1)
1047: continue;
1048: for (j = amiga2aspect_line_map[i]; j < gfxvidinfo.height && native2amiga_line_map[j] == -1; j++)
1049: native2amiga_line_map[j] = i >> (currprefs.gfx_linedbl ? 1 : 0);
1050: }
1051: }
1052:
1053: /*
1054: * A raster line has been built in the graphics buffer. Tell the graphics code
1055: * to do anything necessary to display it.
1056: */
1057: static void do_flush_line_1 (int lineno)
1058: {
1059: if (lineno < first_drawn_line)
1060: first_drawn_line = lineno;
1061: if (lineno > last_drawn_line)
1062: last_drawn_line = lineno;
1063:
1064: if (gfxvidinfo.maxblocklines == 0)
1.1.1.11 root 1065: flush_line (lineno);
1.1 root 1066: else {
1067: if ((last_block_line+1) != lineno) {
1068: if (first_block_line != -2)
1069: flush_block (first_block_line, last_block_line);
1070: first_block_line = lineno;
1071: }
1072: last_block_line = lineno;
1073: if (last_block_line - first_block_line >= gfxvidinfo.maxblocklines) {
1074: flush_block (first_block_line, last_block_line);
1075: first_block_line = last_block_line = -2;
1076: }
1077: }
1078: }
1079:
1.1.1.6 root 1080: STATIC_INLINE void do_flush_line (int lineno)
1.1 root 1081: {
1082: do_flush_line_1 (lineno);
1083: }
1084:
1085: /*
1086: * One drawing frame has been finished. Tell the graphics code about it.
1087: * Note that the actual flush_screen() call is a no-op for all reasonable
1088: * systems.
1089: */
1090:
1.1.1.6 root 1091: STATIC_INLINE void do_flush_screen (int start, int stop)
1.1 root 1092: {
1.1.1.6 root 1093: /* TODO: this flush operation is executed outside locked state!
1094: Should be corrected.
1095: (sjo 26.9.99) */
1096:
1.1 root 1097: if (gfxvidinfo.maxblocklines != 0 && first_block_line != -2) {
1098: flush_block (first_block_line, last_block_line);
1099: }
1100: if (start <= stop)
1101: flush_screen (start, stop);
1102: }
1103:
1104: static int drawing_color_matches;
1105: static enum { color_match_acolors, color_match_full } color_match_type;
1106:
1.1.1.8 root 1107: /* Set up colors_for_drawing to the state at the beginning of the currently drawn
1108: line. Try to avoid copying color tables around whenever possible. */
1.1 root 1109: static void adjust_drawing_colors (int ctable, int bplham)
1110: {
1111: if (drawing_color_matches != ctable) {
1112: if (bplham) {
1.1.1.9 root 1113: color_reg_cpy (&colors_for_drawing, curr_color_tables + ctable);
1.1 root 1114: color_match_type = color_match_full;
1115: } else {
1116: memcpy (colors_for_drawing.acolors, curr_color_tables[ctable].acolors,
1.1.1.9 root 1117: sizeof colors_for_drawing.acolors);
1.1 root 1118: color_match_type = color_match_acolors;
1119: }
1120: drawing_color_matches = ctable;
1121: } else if (bplham && color_match_type != color_match_full) {
1.1.1.9 root 1122: color_reg_cpy (&colors_for_drawing, &curr_color_tables[ctable]);
1.1 root 1123: color_match_type = color_match_full;
1124: }
1125: }
1126:
1.1.1.8 root 1127: STATIC_INLINE void do_color_changes (line_draw_func worker_border, line_draw_func worker_pfield)
1.1 root 1128: {
1.1.1.8 root 1129: int i;
1130: int lastpos = visible_left_border;
1.1.1.9 root 1131:
1.1.1.8 root 1132: for (i = dip_for_drawing->first_color_change; i <= dip_for_drawing->last_color_change; i++) {
1133: int regno = curr_color_changes[i].regno;
1134: unsigned int value = curr_color_changes[i].value;
1135: int nextpos, nextpos_in_range;
1.1 root 1136: if (i == dip_for_drawing->last_color_change)
1137: nextpos = max_diwlastword;
1138: else
1.1.1.11 root 1139: nextpos = coord_hw_to_window_x (curr_color_changes[i].linepos * 2);
1.1.1.8 root 1140:
1141: nextpos_in_range = nextpos;
1142: if (nextpos > visible_right_border)
1143: nextpos_in_range = visible_right_border;
1144:
1145: if (nextpos_in_range > lastpos) {
1146: if (lastpos < playfield_start) {
1147: int t = nextpos_in_range <= playfield_start ? nextpos_in_range : playfield_start;
1148: (*worker_border) (lastpos, t);
1149: lastpos = t;
1150: }
1151: }
1152: if (nextpos_in_range > lastpos) {
1153: if (lastpos >= playfield_start && lastpos < playfield_end) {
1154: int t = nextpos_in_range <= playfield_end ? nextpos_in_range : playfield_end;
1155: (*worker_pfield) (lastpos, t);
1156: lastpos = t;
1157: }
1158: }
1159: if (nextpos_in_range > lastpos) {
1160: if (lastpos >= playfield_end)
1161: (*worker_border) (lastpos, nextpos_in_range);
1162: lastpos = nextpos_in_range;
1163: }
1.1 root 1164: if (i != dip_for_drawing->last_color_change) {
1.1.1.9 root 1165: color_reg_set (&colors_for_drawing, regno, value);
1166: colors_for_drawing.acolors[regno] = getxcolor (value);
1.1 root 1167: }
1.1.1.8 root 1168: if (lastpos >= visible_right_border)
1.1.1.11 root 1169: break;
1170: }
1.1 root 1171: }
1172:
1173: /* We only save hardware registers during the hardware frame. Now, when
1174: * drawing the frame, we expand the data into a slightly more useful
1175: * form. */
1176: static void pfield_expand_dp_bplcon (void)
1177: {
1.1.1.11 root 1178: int plf1pri, plf2pri;
1179: bplres = dp_for_drawing->bplres;
1180: bplplanecnt = dp_for_drawing->nr_planes;
1.1.1.13 root 1181: bplham = ((dp_for_drawing->bplcon0 & 0x800) == 0x800
1182: && (bplplanecnt == 6
1183: || ((currprefs.chipset_mask & CSMASK_AGA) != 0 && bplplanecnt == 8)));
1.1.1.9 root 1184: if (currprefs.chipset_mask & CSMASK_AGA) {
1185: /* The KILLEHB bit exists in ECS, but is apparently meant for Genlock
1186: * stuff, and it's set by some demos (e.g. Andromeda Seven Seas) */
1187: bplehb = ((dp_for_drawing->bplcon0 & 0xFCC0) == 0x6000 && !(dp_for_drawing->bplcon2 & 0x200));
1188: } else {
1189: bplehb = (dp_for_drawing->bplcon0 & 0xFC00) == 0x6000;
1190: }
1.1.1.11 root 1191: plf1pri = dp_for_drawing->bplcon2 & 7;
1192: plf2pri = (dp_for_drawing->bplcon2 >> 3) & 7;
1193: plf_sprite_mask = 0xFFFF0000 << (4 * plf2pri);
1194: plf_sprite_mask |= (0xFFFF << (4 * plf1pri)) & 0xFFFF;
1.1 root 1195: bpldualpf = (dp_for_drawing->bplcon0 & 0x400) == 0x400;
1196: bpldualpfpri = (dp_for_drawing->bplcon2 & 0x40) == 0x40;
1.1.1.12 root 1197: bpldualpf2of = (dp_for_drawing->bplcon3 >> 10) & 7;
1198: sbasecol[0] = ((dp_for_drawing->bplcon4 >> 4) & 15) << 4;
1199: sbasecol[1] = ((dp_for_drawing->bplcon4 >> 0) & 15) << 4;
1.1 root 1200: }
1201:
1202: enum double_how {
1203: dh_buf,
1204: dh_line,
1205: dh_emerg
1206: };
1207:
1.1.1.6 root 1208: STATIC_INLINE void pfield_draw_line (int lineno, int gfx_ypos, int follow_ypos)
1.1 root 1209: {
1.1.1.8 root 1210: static int warned = 0;
1.1 root 1211: int border = 0;
1212: int do_double = 0;
1213: enum double_how dh;
1214:
1.1.1.2 root 1215: dp_for_drawing = line_decisions + lineno;
1216: dip_for_drawing = curr_drawinfo + lineno;
1.1 root 1217: switch (linestate[lineno]) {
1.1.1.8 root 1218: case LINE_REMEMBERED_AS_PREVIOUS:
1219: if (!warned)
1220: write_log ("Shouldn't get here... this is a bug.\n"), warned++;
1.1 root 1221: return;
1222:
1.1.1.8 root 1223: case LINE_BLACK:
1.1.1.2 root 1224: linestate[lineno] = LINE_REMEMBERED_AS_BLACK;
1225: border = 2;
1.1 root 1226: break;
1227:
1.1.1.8 root 1228: case LINE_REMEMBERED_AS_BLACK:
1.1.1.2 root 1229: return;
1230:
1.1.1.8 root 1231: case LINE_AS_PREVIOUS:
1.1.1.2 root 1232: dp_for_drawing--;
1233: dip_for_drawing--;
1.1.1.11 root 1234: if (dp_for_drawing->plfleft == -1)
1.1.1.2 root 1235: border = 1;
1236: linestate[lineno] = LINE_DONE_AS_PREVIOUS;
1.1 root 1237: break;
1238:
1.1.1.8 root 1239: case LINE_DONE_AS_PREVIOUS:
1.1 root 1240: /* fall through */
1.1.1.8 root 1241: case LINE_DONE:
1.1 root 1242: return;
1243:
1.1.1.8 root 1244: case LINE_DECIDED_DOUBLE:
1.1 root 1245: if (follow_ypos != -1) {
1246: do_double = 1;
1247: linetoscr_double_offset = gfxvidinfo.rowbytes * (follow_ypos - gfx_ypos);
1.1.1.2 root 1248: linestate[lineno + 1] = LINE_DONE_AS_PREVIOUS;
1.1 root 1249: }
1250:
1251: /* fall through */
1.1.1.8 root 1252: default:
1.1.1.11 root 1253: if (dp_for_drawing->plfleft == -1)
1.1 root 1254: border = 1;
1255: linestate[lineno] = LINE_DONE;
1.1.1.2 root 1256: break;
1.1 root 1257: }
1258:
1259: dh = dh_line;
1260: xlinebuffer = gfxvidinfo.linemem;
1.1.1.10 root 1261: if (xlinebuffer == 0 && do_double
1262: && (border == 0 || (border != 1 && dip_for_drawing->nr_color_changes > 0)))
1.1 root 1263: xlinebuffer = gfxvidinfo.emergmem, dh = dh_emerg;
1264: if (xlinebuffer == 0)
1265: xlinebuffer = row_map[gfx_ypos], dh = dh_buf;
1266: xlinebuffer -= linetoscr_x_adjust_bytes;
1267:
1.1.1.11 root 1268: if (border == 0) {
1.1 root 1269: pfield_expand_dp_bplcon ();
1270:
1.1.1.13 root 1271: if (bplres == RES_LORES && ! currprefs.gfx_lores)
1.1 root 1272: currprefs.gfx_lores = 2;
1.1.1.8 root 1273:
1.1.1.13 root 1274: pfield_init_linetoscr ();
1.1.1.11 root 1275: pfield_doline (lineno);
1.1 root 1276:
1277: adjust_drawing_colors (dp_for_drawing->ctable, bplham || bplehb);
1278:
1.1.1.9 root 1279: /* The problem is that we must call decode_ham() BEFORE we do the
1.1.1.8 root 1280: sprites. */
1281: if (! border && bplham) {
1282: init_ham_decoding ();
1.1 root 1283: if (dip_for_drawing->nr_color_changes == 0) {
1284: /* The easy case: need to do HAM decoding only once for the
1285: * full line. */
1.1.1.9 root 1286: decode_ham (visible_left_border, visible_right_border);
1.1 root 1287: } else /* Argh. */ {
1.1.1.9 root 1288: do_color_changes (dummy_worker, decode_ham);
1.1 root 1289: adjust_drawing_colors (dp_for_drawing->ctable, bplham || bplehb);
1290: }
1291: }
1292:
1.1.1.11 root 1293: {
1294: int i;
1.1.1.13 root 1295: for (i = 0; i < dip_for_drawing->nr_sprites; i++) {
1296: if (currprefs.chipset_mask & CSMASK_AGA)
1297: draw_sprites_aga (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i);
1298: else
1299: draw_sprites_ecs (curr_sprite_entries + dip_for_drawing->first_sprite_entry + i);
1300: }
1.1.1.11 root 1301: }
1.1 root 1302:
1.1.1.8 root 1303: do_color_changes (pfield_do_fill_line, pfield_do_linetoscr);
1304: if (dh == dh_emerg)
1.1.1.14! root 1305: memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1 root 1306:
1.1.1.8 root 1307: do_flush_line (gfx_ypos);
1308: if (do_double) {
1309: if (dh == dh_emerg)
1.1.1.14! root 1310: memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1.1.8 root 1311: else if (dh == dh_buf)
1.1.1.14! root 1312: memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1.1.8 root 1313: do_flush_line (follow_ypos);
1.1 root 1314: }
1315: if (currprefs.gfx_lores == 2)
1316: currprefs.gfx_lores = 0;
1.1.1.2 root 1317: } else if (border == 1) {
1.1 root 1318: adjust_drawing_colors (dp_for_drawing->ctable, 0);
1319:
1320: if (dip_for_drawing->nr_color_changes == 0) {
1321: fill_line ();
1322: do_flush_line (gfx_ypos);
1323: #if 0
1324: if (dh == dh_emerg)
1325: abort ();
1326: #endif
1327: if (do_double) {
1328: if (dh == dh_buf) {
1329: xlinebuffer = row_map[follow_ypos] - linetoscr_x_adjust_bytes;
1330: fill_line ();
1331: }
1332: /* If dh == dh_line, do_flush_line will re-use the rendered line
1333: * from linemem. */
1334: do_flush_line (follow_ypos);
1335: }
1336: return;
1337: }
1338:
1.1.1.8 root 1339: playfield_start = visible_right_border;
1340: playfield_end = visible_right_border;
1341:
1342: do_color_changes (pfield_do_fill_line, pfield_do_fill_line);
1.1 root 1343:
1344: if (dh == dh_emerg)
1.1.1.14! root 1345: memcpy (row_map[gfx_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1 root 1346:
1347: do_flush_line (gfx_ypos);
1348: if (do_double) {
1349: if (dh == dh_emerg)
1.1.1.14! root 1350: memcpy (row_map[follow_ypos], xlinebuffer + linetoscr_x_adjust_bytes, gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1 root 1351: else if (dh == dh_buf)
1.1.1.14! root 1352: memcpy (row_map[follow_ypos], row_map[gfx_ypos], gfxvidinfo.pixbytes * gfxvidinfo.width);
1.1 root 1353: /* If dh == dh_line, do_flush_line will re-use the rendered line
1354: * from linemem. */
1355: do_flush_line (follow_ypos);
1356: }
1.1.1.2 root 1357: } else {
1358: xcolnr tmp = colors_for_drawing.acolors[0];
1.1.1.9 root 1359: colors_for_drawing.acolors[0] = getxcolor (0);
1.1.1.2 root 1360: fill_line ();
1361: do_flush_line (gfx_ypos);
1362: colors_for_drawing.acolors[0] = tmp;
1.1 root 1363: }
1364: }
1365:
1366: static void center_image (void)
1367: {
1.1.1.8 root 1368: prev_x_adjust = visible_left_border;
1.1 root 1369: prev_y_adjust = thisframe_y_adjust;
1370:
1371: if (currprefs.gfx_xcenter) {
1372: if (max_diwstop - min_diwstart < gfxvidinfo.width && currprefs.gfx_xcenter == 2)
1373: /* Try to center. */
1.1.1.8 root 1374: visible_left_border = ((max_diwstop - min_diwstart - gfxvidinfo.width) / 2 + min_diwstart) & ~1;
1.1 root 1375: else
1.1.1.8 root 1376: visible_left_border = max_diwstop - gfxvidinfo.width;
1.1 root 1377:
1378: /* Would the old value be good enough? If so, leave it as it is if we want to
1379: * be clever. */
1380: if (currprefs.gfx_xcenter == 2) {
1.1.1.8 root 1381: if (visible_left_border < prev_x_adjust && prev_x_adjust < min_diwstart)
1382: visible_left_border = prev_x_adjust;
1.1 root 1383: }
1384: } else
1.1.1.8 root 1385: visible_left_border = max_diwlastword - gfxvidinfo.width;
1386: if (visible_left_border < 0)
1387: visible_left_border = 0;
1388:
1389: linetoscr_x_adjust_bytes = visible_left_border * gfxvidinfo.pixbytes;
1390:
1391: visible_right_border = visible_left_border + gfxvidinfo.width;
1392: if (visible_right_border > max_diwlastword)
1393: visible_right_border = max_diwlastword;
1.1 root 1394:
1395: thisframe_y_adjust = minfirstline;
1396: if (currprefs.gfx_ycenter && thisframe_first_drawn_line != -1) {
1397: if (thisframe_last_drawn_line - thisframe_first_drawn_line < max_drawn_amiga_line && currprefs.gfx_ycenter == 2)
1398: thisframe_y_adjust = (thisframe_last_drawn_line - thisframe_first_drawn_line - max_drawn_amiga_line) / 2 + thisframe_first_drawn_line;
1399: else
1400: thisframe_y_adjust = thisframe_first_drawn_line;
1401: /* Would the old value be good enough? If so, leave it as it is if we want to
1402: * be clever. */
1403: if (currprefs.gfx_ycenter == 2) {
1404: if (thisframe_y_adjust != prev_y_adjust
1405: && prev_y_adjust <= thisframe_first_drawn_line
1406: && prev_y_adjust + max_drawn_amiga_line > thisframe_last_drawn_line)
1407: thisframe_y_adjust = prev_y_adjust;
1408: }
1409: /* Make sure the value makes sense */
1410: if (thisframe_y_adjust + max_drawn_amiga_line > maxvpos)
1411: thisframe_y_adjust = maxvpos - max_drawn_amiga_line;
1412: if (thisframe_y_adjust < minfirstline)
1413: thisframe_y_adjust = minfirstline;
1414: }
1415: thisframe_y_adjust_real = thisframe_y_adjust << (currprefs.gfx_linedbl ? 1 : 0);
1416: max_ypos_thisframe = (maxvpos - thisframe_y_adjust) << (currprefs.gfx_linedbl ? 1 : 0);
1417:
1418: /* @@@ interlace_seen used to be (bplcon0 & 4), but this is probably
1419: * better. */
1.1.1.8 root 1420: if (prev_x_adjust != visible_left_border || prev_y_adjust != thisframe_y_adjust)
1.1 root 1421: frame_redraw_necessary |= interlace_seen && currprefs.gfx_linedbl ? 2 : 1;
1422:
1423: max_diwstop = 0;
1424: min_diwstart = 10000;
1425: }
1426:
1427: static void init_drawing_frame (void)
1428: {
1429: int i, maxline;
1430:
1431: init_hardware_for_drawing_frame ();
1432:
1433: if (thisframe_first_drawn_line == -1)
1434: thisframe_first_drawn_line = minfirstline;
1435: if (thisframe_first_drawn_line > thisframe_last_drawn_line)
1436: thisframe_last_drawn_line = thisframe_first_drawn_line;
1437:
1438: maxline = currprefs.gfx_linedbl ? (maxvpos+1) * 2 + 1 : (maxvpos+1) + 1;
1439: #ifdef SMART_UPDATE
1.1.1.2 root 1440: for (i = 0; i < maxline; i++) {
1441: switch (linestate[i]) {
1442: case LINE_DONE_AS_PREVIOUS:
1443: linestate[i] = LINE_REMEMBERED_AS_PREVIOUS;
1444: break;
1445: case LINE_REMEMBERED_AS_BLACK:
1446: break;
1447: default:
1448: linestate[i] = LINE_UNDECIDED;
1449: break;
1450: }
1451: }
1.1 root 1452: #else
1453: memset (linestate, LINE_UNDECIDED, maxline);
1454: #endif
1455: last_drawn_line = 0;
1456: first_drawn_line = 32767;
1457:
1458: first_block_line = last_block_line = -2;
1459: if (currprefs.test_drawing_speed)
1460: frame_redraw_necessary = 1;
1461: else if (frame_redraw_necessary)
1462: frame_redraw_necessary--;
1463:
1464: center_image ();
1465:
1466: thisframe_first_drawn_line = -1;
1467: thisframe_last_drawn_line = -1;
1468:
1469: drawing_color_matches = -1;
1470: }
1471:
1.1.1.14! root 1472: /*
! 1473: * Some code to put status information on the screen.
! 1474: */
! 1475:
! 1476: #define TD_PADX 10
! 1477: #define TD_PADY 2
! 1478: #define TD_WIDTH 32
! 1479: #define TD_LED_WIDTH 24
! 1480: #define TD_LED_HEIGHT 4
! 1481:
! 1482: #define TD_RIGHT 1
! 1483: #define TD_BOTTOM 2
! 1484:
! 1485: static int td_pos = (TD_RIGHT|TD_BOTTOM);
! 1486:
! 1487: #define TD_NUM_WIDTH 7
! 1488: #define TD_NUM_HEIGHT 7
! 1489:
! 1490: #define TD_TOTAL_HEIGHT (TD_PADY * 2 + TD_NUM_HEIGHT)
! 1491:
! 1492: static char *numbers = { /* ugly */
! 1493: "------ ------ ------ ------ ------ ------ ------ ------ ------ ------ "
! 1494: "-xxxxx ---xx- -xxxxx -xxxxx -x---x -xxxxx -xxxxx -xxxxx -xxxxx -xxxxx "
! 1495: "-x---x ----x- -----x -----x -x---x -x---- -x---- -----x -x---x -x---x "
! 1496: "-x---x ----x- -xxxxx -xxxxx -xxxxx -xxxxx -xxxxx ----x- -xxxxx -xxxxx "
! 1497: "-x---x ----x- -x---- -----x -----x -----x -x---x ---x-- -x---x -----x "
! 1498: "-xxxxx ----x- -xxxxx -xxxxx -----x -xxxxx -xxxxx ---x-- -xxxxx -xxxxx "
! 1499: "------ ------ ------ ------ ------ ------ ------ ------ ------ ------ "
! 1500: };
! 1501:
! 1502: STATIC_INLINE void putpixel (int x, xcolnr c8)
! 1503: {
! 1504: switch(gfxvidinfo.pixbytes)
! 1505: {
! 1506: case 1:
! 1507: xlinebuffer[x] = (uae_u8)c8;
! 1508: break;
! 1509: case 2:
! 1510: {
! 1511: uae_u16 *p = (uae_u16 *)xlinebuffer + x;
! 1512: *p = c8;
! 1513: break;
! 1514: }
! 1515: case 3:
! 1516: /* no 24 bit yet */
! 1517: break;
! 1518: case 4:
! 1519: {
! 1520: uae_u32 *p = (uae_u32 *)xlinebuffer + x;
! 1521: *p = c8;
! 1522: break;
! 1523: }
! 1524: }
! 1525: }
! 1526:
! 1527: static void write_tdnumber (int x, int y, int num)
! 1528: {
! 1529: int j;
! 1530: uae_u8 *numptr;
! 1531:
! 1532: numptr = numbers + num * TD_NUM_WIDTH + 10 * TD_NUM_WIDTH * y;
! 1533: for (j = 0; j < TD_NUM_WIDTH; j++) {
! 1534: putpixel (x + j, *numptr == 'x' ? xcolors[0xfff] : xcolors[0x000]);
! 1535: numptr++;
! 1536: }
! 1537: }
! 1538:
! 1539: static void draw_status_line (int line)
! 1540: {
! 1541: int x, y, i, j, led, on;
! 1542: int on_rgb, off_rgb, c;
! 1543: uae_u8 *buf;
! 1544:
! 1545: if (td_pos & TD_RIGHT)
! 1546: x = gfxvidinfo.width - TD_PADX - 5*TD_WIDTH;
! 1547: else
! 1548: x = TD_PADX;
! 1549:
! 1550: y = line - (gfxvidinfo.height - TD_TOTAL_HEIGHT);
! 1551: xlinebuffer = gfxvidinfo.linemem;
! 1552: if (xlinebuffer == 0)
! 1553: xlinebuffer = row_map[line];
! 1554:
! 1555: memset (xlinebuffer, 0, gfxvidinfo.width * gfxvidinfo.pixbytes);
! 1556:
! 1557: for (led = 0; led < 5; led++) {
! 1558: int track;
! 1559: if (led > 0) {
! 1560: track = gui_data.drive_track[led-1];
! 1561: on = gui_data.drive_motor[led-1];
! 1562: on_rgb = 0x0f0;
! 1563: off_rgb = 0x040;
! 1564: } else {
! 1565: track = -1;
! 1566: on = gui_data.powerled;
! 1567: on_rgb = 0xf00;
! 1568: off_rgb = 0x400;
! 1569: }
! 1570: c = xcolors[on ? on_rgb : off_rgb];
! 1571:
! 1572: for (j = 0; j < TD_LED_WIDTH; j++)
! 1573: putpixel (x + j, c);
! 1574:
! 1575: if (y >= TD_PADY && y - TD_PADY < TD_NUM_HEIGHT) {
! 1576: if (track >= 0) {
! 1577: int offs = (TD_WIDTH - 2 * TD_NUM_WIDTH) / 2;
! 1578: write_tdnumber (x + offs, y - TD_PADY, track / 10);
! 1579: write_tdnumber (x + offs + TD_NUM_WIDTH, y - TD_PADY, track % 10);
! 1580: }
! 1581: }
! 1582: x += TD_WIDTH;
! 1583: }
! 1584: }
! 1585:
1.1 root 1586: void finish_drawing_frame (void)
1587: {
1588: int i;
1589:
1590: #ifndef SMART_UPDATE
1591: /* @@@ This isn't exactly right yet. FIXME */
1592: if (!interlace_seen) {
1593: do_flush_screen (first_drawn_line, last_drawn_line);
1594: return;
1595: }
1596: #endif
1597: if (! lockscr ()) {
1598: notice_screen_contents_lost ();
1599: return;
1600: }
1601: for (i = 0; i < max_ypos_thisframe; i++) {
1602: int where;
1.1.1.14! root 1603: int i1 = i + min_ypos_for_screen;
1.1 root 1604: int line = i + thisframe_y_adjust_real;
1605:
1606: if (linestate[line] == LINE_UNDECIDED)
1607: break;
1608:
1.1.1.14! root 1609: where = amiga2aspect_line_map[i1];
! 1610: if (where >= gfxvidinfo.height - TD_TOTAL_HEIGHT)
1.1 root 1611: break;
1612: if (where == -1)
1613: continue;
1614:
1.1.1.14! root 1615: pfield_draw_line (line, where, amiga2aspect_line_map[i1 + 1]);
1.1 root 1616: }
1.1.1.14! root 1617: for (i = 0; i < TD_TOTAL_HEIGHT; i++) {
! 1618: int line = gfxvidinfo.height - TD_TOTAL_HEIGHT + i;
! 1619: draw_status_line (line);
! 1620: do_flush_line (line);
! 1621: }
! 1622:
1.1 root 1623: unlockscr ();
1624: do_flush_screen (first_drawn_line, last_drawn_line);
1625: }
1626:
1627: void hardware_line_completed (int lineno)
1628: {
1629: #ifndef SMART_UPDATE
1630: {
1631: int i, where;
1632: /* l is the line that has been finished for drawing. */
1633: i = lineno - thisframe_y_adjust_real;
1634: if (i >= 0 && i < max_ypos_thisframe) {
1635: where = amiga2aspect_line_map[i+min_ypos_for_screen];
1636: if (where < gfxvidinfo.height && where != -1)
1637: pfield_draw_line (lineno, where, amiga2aspect_line_map[i+min_ypos_for_screen+1]);
1638: }
1639: }
1640: #endif
1641: }
1642:
1.1.1.6 root 1643: STATIC_INLINE void check_picasso (void)
1.1 root 1644: {
1645: #ifdef PICASSO96
1646: if (picasso_on && picasso_redraw_necessary)
1647: picasso_refresh ();
1648: picasso_redraw_necessary = 0;
1649:
1650: if (picasso_requested_on == picasso_on)
1651: return;
1652:
1653: picasso_on = picasso_requested_on;
1654:
1655: if (!picasso_on)
1.1.1.3 root 1656: clear_inhibit_frame (IHF_PICASSO);
1.1 root 1657: else
1.1.1.3 root 1658: set_inhibit_frame (IHF_PICASSO);
1.1 root 1659:
1660: gfx_set_picasso_state (picasso_on);
1661: picasso_enablescreen (picasso_requested_on);
1662:
1663: notice_screen_contents_lost ();
1664: notice_new_xcolors ();
1665: #endif
1666: }
1667:
1668: void vsync_handle_redraw (int long_frame, int lof_changed)
1669: {
1670: last_redraw_point++;
1671: if (lof_changed || ! interlace_seen || last_redraw_point >= 2 || long_frame) {
1672: last_redraw_point = 0;
1673: interlace_seen = 0;
1674:
1675: if (framecnt == 0)
1676: finish_drawing_frame ();
1677:
1678: /* At this point, we have finished both the hardware and the
1679: * drawing frame. Essentially, we are outside of all loops and
1680: * can do some things which would cause confusion if they were
1681: * done at other times.
1682: */
1683:
1.1.1.13 root 1684: if (savestate_state == STATE_DOSAVE) {
1685: custom_prepare_savestate ();
1686: savestate_state = STATE_SAVE;
1687: save_state (savestate_filename, "Description!");
1688: savestate_state = 0;
1689: } else if (savestate_state == STATE_DORESTORE) {
1690: savestate_state = STATE_RESTORE;
1691: uae_reset ();
1692: restore_state (savestate_filename);
1693: #if 0
1694: activate_debugger ();
1695: #endif
1696: }
1697:
1.1 root 1698: if (quit_program < 0) {
1699: quit_program = -quit_program;
1.1.1.3 root 1700: set_inhibit_frame (IHF_QUIT_PROGRAM);
1.1.1.11 root 1701: set_special (SPCFLAG_BRK);
1.1 root 1702: filesys_prepare_reset ();
1703: return;
1704: }
1705:
1706: count_frame ();
1707: check_picasso ();
1708:
1.1.1.2 root 1709: check_prefs_changed_audio ();
1.1 root 1710: check_prefs_changed_custom ();
1711: check_prefs_changed_cpu ();
1712: if (check_prefs_changed_gfx ()) {
1713: init_row_map ();
1714: init_aspect_maps ();
1715: notice_screen_contents_lost ();
1716: notice_new_xcolors ();
1717: }
1718:
1719: if (inhibit_frame != 0)
1720: framecnt = 1;
1721:
1722: if (framecnt == 0)
1723: init_drawing_frame ();
1724: }
1725: }
1726:
1.1.1.2 root 1727: void hsync_record_line_state (int lineno, enum nln_how how, int changed)
1.1 root 1728: {
1.1.1.2 root 1729: char *state;
1.1 root 1730: if (framecnt != 0)
1731: return;
1.1.1.2 root 1732:
1733: state = linestate + lineno;
1734: changed += frame_redraw_necessary;
1735:
1.1 root 1736: switch (how) {
1737: case nln_normal:
1.1.1.2 root 1738: *state = changed ? LINE_DECIDED : LINE_DONE;
1.1 root 1739: break;
1740: case nln_doubled:
1.1.1.2 root 1741: *state = changed ? LINE_DECIDED_DOUBLE : LINE_DONE;
1742: changed += state[1] != LINE_REMEMBERED_AS_PREVIOUS;
1743: state[1] = changed ? LINE_AS_PREVIOUS : LINE_DONE_AS_PREVIOUS;
1744: break;
1745: case nln_nblack:
1746: *state = changed ? LINE_DECIDED : LINE_DONE;
1747: if (state[1] != LINE_REMEMBERED_AS_BLACK)
1748: state[1] = LINE_BLACK;
1.1 root 1749: break;
1750: case nln_lower:
1.1.1.2 root 1751: if (state[-1] == LINE_UNDECIDED)
1752: state[-1] = LINE_BLACK;
1753: *state = changed ? LINE_DECIDED : LINE_DONE;
1.1 root 1754: break;
1755: case nln_upper:
1.1.1.2 root 1756: *state = changed ? LINE_DECIDED : LINE_DONE;
1757: if (state[1] == LINE_UNDECIDED
1758: || state[1] == LINE_REMEMBERED_AS_PREVIOUS
1759: || state[1] == LINE_AS_PREVIOUS)
1760: state[1] = LINE_BLACK;
1.1 root 1761: break;
1762: }
1763: }
1764:
1765: void notice_interlace_seen (void)
1766: {
1767: interlace_seen = 1;
1768: }
1769:
1770: void reset_drawing (void)
1771: {
1772: int i;
1773:
1774: inhibit_frame = 0;
1775: uae_sem_init (&gui_sem, 0, 1);
1776:
1777: #ifdef PICASSO96
1778: InitPicasso96 ();
1779: picasso_on = 0;
1780: picasso_requested_on = 0;
1781: gfx_set_picasso_state (0);
1782: #endif
1783: max_diwstop = 0;
1784:
1785: lores_factor = currprefs.gfx_lores ? 1 : 2;
1786: lores_shift = currprefs.gfx_lores ? 0 : 1;
1787:
1788: /*memset(blitcount, 0, sizeof(blitcount)); blitter debug */
1789: for (i = 0; i < sizeof linestate / sizeof *linestate; i++)
1790: linestate[i] = LINE_UNDECIDED;
1791:
1792: xlinebuffer = gfxvidinfo.bufmem;
1793:
1794: init_aspect_maps ();
1795:
1796: if (line_drawn == 0)
1797: line_drawn = (char *)malloc (gfxvidinfo.height);
1798:
1799: init_row_map();
1800:
1801: last_redraw_point = 0;
1802:
1.1.1.11 root 1803: memset (spixels, 0, sizeof spixels);
1804: memset (&spixstate, 0, sizeof spixstate);
1805:
1.1 root 1806: init_drawing_frame ();
1807: }
1808:
1809: void drawing_init ()
1810: {
1811: native2amiga_line_map = 0;
1812: amiga2aspect_line_map = 0;
1813: line_drawn = 0;
1814:
1815: gen_pfield_tables();
1816: }
1817:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.