annotate jag_video.c @ 1470:1e3e0205640f

Add support for writeable ROM and an entry for Game no Kanzume Otokuyou using that support as it expects the cart area to be writable
author Michael Pavone <pavone@retrodev.com>
date Sat, 14 Oct 2017 05:03:38 -0700
parents 653558f6fa7a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdint.h>
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdlib.h>
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
3 #include <stdio.h>
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "jag_video.h"
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
5 #include "jaguar.h"
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
6 #include "render.h"
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
8 enum {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
9 VMODE_CRY,
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
10 VMODE_RGB24,
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
11 VMODE_DIRECT16,
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
12 VMODE_RGB16,
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
13 VMODE_VARIABLE
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
14 };
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
15
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
16 #define BIT_TBGEN 1
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
17
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
18 char *vmode_names[] = {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
19 "CRY",
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
20 "RGB24",
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
21 "RGB16",
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
22 "DIRECT16",
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
23 "VARIABLE"
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
24 };
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
25
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
26 static uint8_t cry_red[9][16] = {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
27 {0, 34, 68, 102, 135, 169, 203, 237, 255, 255, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
28 {0, 34, 68, 102, 135, 169, 203, 230, 247, 255, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
29 {0, 34, 68, 102, 135, 170, 183, 197, 214, 235, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
30 {0, 34, 68, 102, 130, 141, 153, 164, 181, 204, 227, 249, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
31 {0, 34, 68, 95, 104, 113, 122, 131, 148, 173, 198, 223, 248, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
32 {0, 34, 64, 71, 78, 85, 91, 98, 115, 143, 170, 197, 224, 252, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
33 {0, 34, 43, 47, 52, 56, 61, 65, 82, 112, 141, 171, 200, 230, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
34 {0, 19, 21, 23, 26, 28, 30, 32, 49, 81, 113, 145, 177, 208, 240, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
35 {0, 0, 0, 0, 0, 0, 0, 0, 17, 51, 85, 119, 153, 187, 221, 255}
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
36 };
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
37
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
38 static uint8_t cry_green[16][8] = {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
39 {0, 0, 0, 0, 0, 0, 0, 0},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
40 {17, 19, 21, 23, 26, 28, 30, 32},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
41 {34, 38, 43, 47, 52, 56, 61, 65},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
42 {51, 57, 64, 71, 78, 85, 91, 98},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
43 {68, 77, 86, 95, 104, 113, 122, 131},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
44 {85, 96, 107, 119, 130, 141, 153, 164},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
45 {102, 115, 129, 142, 156, 170, 183, 197},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
46 {119, 134, 150, 166, 182, 198, 214, 230},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
47 {136, 154, 172, 190, 208, 226, 244, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
48 {153, 173, 193, 214, 234, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
49 {170, 192, 215, 238, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
50 {187, 211, 236, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
51 {204, 231, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
52 {221, 250, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
53 {238, 255, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
54 {255, 255, 255, 255, 255, 255, 255, 255},
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
55 };
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
56
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
57 static uint32_t table_cry[0x10000];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
58 static uint32_t table_rgb[0x10000];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
59 static uint32_t table_variable[0x10000];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
60
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
61 static uint32_t cry_to_rgb(uint16_t cry)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
62 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
63 uint32_t y = cry & 0xFF;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
64 if (y) {
1099
9c62edafcf74 Fix CRY color mapping
Michael Pavone <pavone@retrodev.com>
parents: 1098
diff changeset
65 uint8_t c = cry >> 8 & 0xF;
9c62edafcf74 Fix CRY color mapping
Michael Pavone <pavone@retrodev.com>
parents: 1098
diff changeset
66 uint8_t r = cry >> 12;
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
67
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
68 uint32_t red = cry_red[c < 7 ? 0 : c - 7][r];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
69 uint32_t green = cry_green[c][r < 8 ? r : 15 - r];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
70 uint32_t blue = cry_red[c < 7 ? 0 : c - 7][15-r];
1099
9c62edafcf74 Fix CRY color mapping
Michael Pavone <pavone@retrodev.com>
parents: 1098
diff changeset
71 red = red * y / 255;
9c62edafcf74 Fix CRY color mapping
Michael Pavone <pavone@retrodev.com>
parents: 1098
diff changeset
72 blue = blue * y / 255;
9c62edafcf74 Fix CRY color mapping
Michael Pavone <pavone@retrodev.com>
parents: 1098
diff changeset
73 green = green * y / 255;
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
74 return render_map_color(red, green, blue);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
75 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
76 return render_map_color(0, 0, 0);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
77 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
78 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
79
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
80 static uint32_t rgb16_to_rgb(uint16_t rgb)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
81 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
82 return render_map_color(
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
83 rgb >> 8 & 0xF8,
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
84 rgb << 2 & 0xFC,
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
85 rgb >> 4 & 0xF8
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
86 );
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
87 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
88
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 jag_video *jag_video_init(void)
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
91 static uint8_t table_init_done = 0;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
92 if (!table_init_done) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
93 for (int i = 0; i < 0x10000; i++)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
94 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
95 table_cry[i] = cry_to_rgb(i);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
96 table_rgb[i] = rgb16_to_rgb(i);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
97 table_variable[i] = i & 1 ? rgb16_to_rgb(i & 0xFFFE) : cry_to_rgb(i);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
98 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
99 table_init_done = 1;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
100 }
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 return calloc(1, sizeof(jag_video));
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
104 static void copy_16(uint32_t *dst, uint32_t len, uint16_t *linebuffer, uint32_t *table)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
105 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
106 for (; len; len--, dst++, linebuffer++)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
107 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
108 *dst = table[*linebuffer];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
109 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
110 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
111
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
112 static void copy_linebuffer(jag_video *context, uint16_t *linebuffer)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
113 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
114 if (!context->output) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
115 return;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
116 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
117 uint32_t *dst = context->output;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
118 uint32_t len;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
119 if (context->regs[VID_HCOUNT] == context->regs[VID_HDISP_BEGIN1]) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
120 if (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
121 context->regs[VID_HDISP_BEGIN2] == context->regs[VID_HDISP_BEGIN1]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
122 || context->regs[VID_HDISP_BEGIN2] > (context->regs[VID_HPERIOD] | 0x400)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
123 ) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
124 //only one line buffer per line, so copy the previous line in its entirety
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
125 len = context->regs[VID_HDISP_END] - 0x400 + context->regs[VID_HPERIOD] - context->regs[VID_HDISP_BEGIN1] + 2;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
126 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
127 //copy the second half of the previous line
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
128 if (context->regs[VID_HDISP_BEGIN2] & 0x400) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
129 //BEGIN2 is after the HCOUNT jump
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
130 dst += context->regs[VID_HPERIOD] - context->regs[VID_HDISP_BEGIN1]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
131 + context->regs[VID_HDISP_BEGIN2] - 0x400 + 1;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
132 len = context->regs[VID_HDISP_END] - context->regs[VID_HDISP_BEGIN2] + 1;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
133 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
134 //BEGIN2 is before the HCOUNT jump
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
135 dst += context->regs[VID_HDISP_BEGIN2] - context->regs[VID_HDISP_BEGIN1];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
136 len = context->regs[VID_HDISP_END] + context->regs[VID_HPERIOD] - context->regs[VID_HDISP_BEGIN2] + 2;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
137 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
138 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
139 context->output += context->output_pitch / sizeof(uint32_t);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
140 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
141 //copy the first half of the current line
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
142 if (context->regs[VID_HDISP_BEGIN2] & 0x400) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
143 //BEGIN2 is after the HCOUNT jump
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
144 len = context->regs[VID_HDISP_BEGIN2] - 0x400 + context->regs[VID_HPERIOD] - context->regs[VID_HDISP_BEGIN1] + 1;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
145 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
146 //BEGIN2 is before the HCOUNT jump
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
147 len = context->regs[VID_HDISP_BEGIN2] - context->regs[VID_HDISP_BEGIN1];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
148 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
149 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
150 len /= context->pclock_div;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
151 switch (context->mode)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
152 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
153 case VMODE_CRY:
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
154 copy_16(dst, len, linebuffer, table_cry);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
155 break;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
156 case VMODE_RGB24:
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
157 //TODO: Implement me
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
158 break;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
159 case VMODE_DIRECT16:
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
160 //TODO: Implement this once I better understand what would happen on hardware with composite output
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
161 break;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
162 case VMODE_RGB16:
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
163 copy_16(dst, len, linebuffer, table_rgb);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
164 break;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
165 case VMODE_VARIABLE:
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
166 copy_16(dst, len, linebuffer, table_variable);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
167 break;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
168 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
169 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
170
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
171 enum {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
172 OBJ_IDLE,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
173 OBJ_FETCH_DESC1,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
174 OBJ_FETCH_DESC2,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
175 OBJ_FETCH_DESC3,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
176 OBJ_PROCESS,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
177 OBJ_HEIGHT_WB,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
178 OBJ_REMAINDER_WB,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
179 OBJ_GPU_WAIT
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
180 };
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
181
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
182 enum {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
183 OBJ_BITMAP,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
184 OBJ_SCALED,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
185 OBJ_GPU,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
186 OBJ_BRANCH,
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
187 OBJ_STOP
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
188 };
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
189
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
190 uint32_t jag_cycles_to_halfline(jag_video *context, uint32_t target)
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
191 {
1100
653558f6fa7a Fix Jaguar video interrupt cycle calculation
Michael Pavone <pavone@retrodev.com>
parents: 1099
diff changeset
192 uint32_t cycles = context->regs[VID_HPERIOD] - (context->regs[VID_HCOUNT] & 0x3FF);
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
193 uint32_t num_lines;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
194 if (context->regs[VID_VCOUNT] < target) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
195 num_lines = target - 1 - context->regs[VID_VCOUNT];
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
196 } else {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
197 num_lines = target + context->regs[VID_VPERIOD] - context->regs[VID_VCOUNT];
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
198 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
199 cycles += num_lines * context->regs[VID_HPERIOD];
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
200 return cycles;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
201 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
202
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
203 uint32_t jag_next_vid_interrupt(jag_video *context)
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
204 {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
205 if (context->regs[VID_VINT] > context->regs[VID_VPERIOD]) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
206 return 0xFFFFFFF;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
207 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
208 return context->cycles + jag_cycles_to_halfline(context, context->regs[VID_VINT]);
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
209 }
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
210
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
211 void op_run(jag_video *context)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
212 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
213 while (context->op.cycles < context->cycles)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
214 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
215 switch (context->op.state)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
216 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
217 case OBJ_IDLE:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
218 case OBJ_GPU_WAIT:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
219 context->op.cycles = context->cycles;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
220 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
221 case OBJ_FETCH_DESC1: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
222 uint32_t address = context->regs[VID_OBJLIST1] | context->regs[VID_OBJLIST2] << 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
223 uint64_t val = jag_read_phrase(context->system, address, &context->op.cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
224 address += 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
225
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
226 context->regs[VID_OBJ0] = val >> 48;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
227 context->regs[VID_OBJ1] = val >> 32;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
228 context->regs[VID_OBJ2] = val >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
229 context->regs[VID_OBJ3] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
230 context->op.type = val & 7;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
231 context->op.has_prefetch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
232 uint16_t ypos = val >> 3 & 0x7FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
233 switch (context->op.type)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
234 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
235 case OBJ_BITMAP:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
236 case OBJ_SCALED: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
237 uint16_t height = val >> 14 & 0x7FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
238 uint32_t link = (address & 0xC00007) | (val >> 21 & 0x3FFFF8);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
239 if ((ypos == 0x7FF || context->regs[VID_VCOUNT] >= ypos) && height) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
240 context->op.state = OBJ_FETCH_DESC2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
241 context->op.obj_start = address - 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
242 context->op.ypos = ypos;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
243 context->op.height = height;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
244 context->op.link = link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
245 context->op.data_address = val >> 40 & 0xFFFFF8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
246 context->op.cur_address = context->op.data_address;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
247 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
248 //object is not visible on this line, advance to next object
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
249 address = link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
250 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
251 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
252 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
253 case OBJ_GPU:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
254 context->op.state = OBJ_GPU_WAIT;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
255 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
256 case OBJ_BRANCH: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
257 uint8_t branch;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
258 switch(val >> 14 & 7)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
259 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
260 case 0:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
261 branch = ypos == context->regs[VID_VCOUNT] || ypos == 0x7FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
262 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
263 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
264 branch = ypos > context->regs[VID_VCOUNT];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
265 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
266 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
267 branch = ypos < context->regs[VID_VCOUNT];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
268 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
269 case 3:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
270 branch = context->regs[VID_OBJFLAG] & 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
271 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
272 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
273 branch = (context->regs[VID_HCOUNT] & 0x400) != 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
274 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
275 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
276 branch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
277 fprintf(stderr, "Invalid branch CC type %d in object at %X\n", (int)(val >> 14 & 7), address-8);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
278 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
279 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
280 if (branch) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
281 address &= 0xC00007;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
282 address |= val >> 21 & 0x3FFFF8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
283 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
284 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
285 case OBJ_STOP:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
286 //TODO: trigger interrupt
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
287 context->op.state = OBJ_IDLE;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
288 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
289 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
290 context->regs[VID_OBJLIST1] = address;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
291 context->regs[VID_OBJLIST2] = address >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
292 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
293 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
294 case OBJ_FETCH_DESC2: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
295 uint32_t address = context->regs[VID_OBJLIST1] | context->regs[VID_OBJLIST2] << 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
296 uint64_t val = jag_read_phrase(context->system, address, &context->op.cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
297 address += 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
298
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
299 context->op.xpos = val & 0xFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
300 if (context->op.xpos & 0x800) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
301 context->op.xpos |= 0xF000;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
302 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
303 context->op.increment = (val >> 15 & 0x7) * 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
304 context->op.bpp = 1 << (val >> 12 & 7);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
305 if (context->op.bpp == 32) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
306 context->op.bpp = 24;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
307 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
308 context->op.line_pitch = (val >> 18 & 0x3FF) * 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
309 if (context->op.bpp < 8) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
310 context->op.pal_offset = val >> 37;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
311 if (context->op.bpp == 4) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
312 context->op.pal_offset &= 0xF0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
313 } else if(context->op.bpp == 2) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
314 context->op.pal_offset &= 0xFC;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
315 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
316 context->op.pal_offset &= 0xFE;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
317 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
318 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
319 context->op.pal_offset = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
320 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
321 context->op.line_phrases = val >> 28 & 0x3FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
322 context->op.hflip = (val & (1UL << 45)) != 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
323 context->op.addpixels = (val & (1UL << 46)) != 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
324 context->op.transparent = (val & (1UL << 47)) != 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
325 //TODO: do something with RELEASE flag
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
326 context->op.leftclip = val >> 49;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
327 if (context->op.type == OBJ_SCALED) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
328 context->op.state = OBJ_FETCH_DESC3;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
329 switch (context->op.bpp)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
330 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
331 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
332 context->op.leftclip &= 0x3F;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
333
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
334 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
335 //documentation isn't clear exactly how this works for higher bpp values
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
336 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
337 context->op.leftclip &= 0x3E;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
338 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
339 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
340 context->op.leftclip &= 0x3C;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
341 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
342 case 8:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
343 context->op.leftclip &= 0x38;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
344 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
345 case 16:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
346 context->op.leftclip &= 0x30;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
347 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
348 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
349 context->op.leftclip = 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
350 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
351 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
352 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
353 context->op.state = OBJ_PROCESS;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
354 address = context->op.link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
355 switch (context->op.bpp)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
356 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
357 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
358 context->op.leftclip &= 0x3E;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
359 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
360 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
361 context->op.leftclip &= 0x3C;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
362 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
363 //values for 4bpp and up are sort of a guess
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
364 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
365 context->op.leftclip &= 0x38;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
366 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
367 case 8:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
368 context->op.leftclip &= 0x30;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
369 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
370 case 16:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
371 context->op.leftclip &= 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
372 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
373 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
374 context->op.leftclip = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
375 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
376 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
377 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
378 if (context->op.xpos < 0) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
379 int16_t pixels_per_phrase = 64 / context->op.bpp;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
380 int16_t clip = -context->op.xpos / pixels_per_phrase;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
381 int16_t rem = -context->op.xpos % pixels_per_phrase;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
382 if (clip >= context->op.line_phrases) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
383 context->op.line_phrases = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
384 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
385 context->op.line_phrases -= clip;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
386 context->op.leftclip += rem * context->op.bpp;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
387 if (context->op.leftclip >= 64) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
388 context->op.line_phrases--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
389 context->op.leftclip -= 64;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
390 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
391
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
392 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
393 } else if (context->op.bpp < 32){
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
394 context->op.lb_offset = context->op.xpos;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
395 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
396 context->op.lb_offset = context->op.xpos * 2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
397 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
398 if (context->op.lb_offset >= LINEBUFFER_WORDS || !context->op.line_phrases) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
399 //ignore objects that are completely offscreen
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
400 //not sure if that's how the hardware does it, but it would make sense
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
401 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
402 address = context->op.link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
403 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
404 context->regs[VID_OBJLIST1] = address;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
405 context->regs[VID_OBJLIST2] = address >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
406 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
407 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
408 case OBJ_FETCH_DESC3: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
409 uint32_t address = context->regs[VID_OBJLIST1] | context->regs[VID_OBJLIST2] << 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
410 uint64_t val = jag_read_phrase(context->system, address, &context->op.cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
411
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
412 context->op.state = OBJ_PROCESS;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
413 context->op.hscale = val & 0xFF;;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
414 context->op.hremainder = val & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
415 context->op.vscale = val >> 8 & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
416 context->op.remainder = val >> 16 & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
417
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
418 context->regs[VID_OBJLIST1] = context->op.link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
419 context->regs[VID_OBJLIST2] = context->op.link >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
420 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
421 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
422 case OBJ_PROCESS: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
423 uint32_t proc_cycles = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
424 if (!context->op.has_prefetch && context->op.line_phrases) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
425 context->op.prefetch = jag_read_phrase(context->system, context->op.cur_address, &proc_cycles);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
426 context->op.cur_address += context->op.increment;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
427 context->op.has_prefetch = 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
428 context->op.line_phrases--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
429 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
430 if (!proc_cycles) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
431 //run at least one cycle of writes even if we didn't spend any time reading
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
432 proc_cycles = 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
433 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
434 while (proc_cycles)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
435 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
436 if (context->op.im_bits) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
437 uint32_t val = context->op.im_data >> (context->op.im_bits - context->op.bpp);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
438 val &= (1 << context->op.bpp) - 1;
1098
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
439 if (val || !context->op.transparent)
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
440 {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
441 if (context->op.bpp < 16) {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
442 val = context->clut[val + context->op.pal_offset];
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
443 }
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
444 if (context->op.bpp == 32) {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
445 context->write_line_buffer[context->op.lb_offset++] = val >> 16;
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
446 }
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
447 context->write_line_buffer[context->op.lb_offset++] = val;
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
448 } else {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
449 context->op.lb_offset += context->op.bpp == 32 ? 2 : 1;
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
450 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
451 if (context->op.type == OBJ_SCALED) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
452 context->op.hremainder -= 0x20;
1098
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
453 while (context->op.hremainder <= 0 && context->op.im_bits) {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
454 context->op.im_bits -= context->op.bpp;
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
455 context->op.hremainder += context->op.hscale;
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
456 }
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
457 } else {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
458 context->op.im_bits -= context->op.bpp;
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
459 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
460 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
461 if (context->op.im_bits && context->op.bpp < 32 && context->op.type == OBJ_BITMAP && context->op.lb_offset < LINEBUFFER_WORDS) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
462 uint32_t val = context->op.im_data >> (context->op.im_bits - context->op.bpp);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
463 val &= (1 << context->op.bpp) - 1;
1098
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
464 if (val || !context->op.transparent)
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
465 {
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
466 val = context->clut[val + context->op.pal_offset];
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
467 context->write_line_buffer[context->op.lb_offset] = val;
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
468 }
4a726e339d6f Fix implementation of scaled objects. Implement transparency flag
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
469 context->op.lb_offset++;
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
470 context->op.im_bits -= context->op.bpp;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
471 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
472 context->op_cycles++;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
473 proc_cycles--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
474 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
475 if (!context->op.im_bits && context->op.has_prefetch) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
476 context->op.im_data = context->op.prefetch;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
477 context->op.has_prefetch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
478 //docs say this is supposed to be a value in pixels
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
479 //but given the "significant" bits part I'm guessing
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
480 //this is actually how many bits are pre-shifted off
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
481 //the first phrase read in a line
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
482 context->op.im_bits = 64 - context->op.leftclip;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
483 context->op.leftclip = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
484 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
485 if (context->op.lb_offset == LINEBUFFER_WORDS || (!context->op.im_bits && !context->op.line_phrases)) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
486 context->op.state = OBJ_HEIGHT_WB;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
487 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
488 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
489 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
490 case OBJ_HEIGHT_WB: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
491 if (context->op.type == OBJ_BITMAP) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
492 context->op.height--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
493 context->op.data_address += context->op.line_pitch;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
494 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
495 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
496 context->op.remainder -= 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
497 context->op.state = OBJ_REMAINDER_WB;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
498 while (context->op.height && context->op.remainder <= 0) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
499 context->op.height--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
500 context->op.remainder += context->op.vscale;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
501 context->op.data_address += context->op.line_pitch;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
502 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
503 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
504 uint64_t val = context->op.type | context->op.ypos << 3 | context->op.height << 14
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
505 | ((uint64_t)context->op.link & 0x3FFFF8) << 21 | ((uint64_t)context->op.data_address) << 40;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
506 context->op.cycles += jag_write_phrase(context->system, context->op.obj_start, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
507 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
508 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
509 case OBJ_REMAINDER_WB: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
510 uint64_t val = context->op.hscale | context->op.vscale << 8 | context->op.remainder << 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
511 context->op.cycles += jag_write_phrase(context->system, context->op.obj_start+16, val);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
512 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
513 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
514 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
515 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
516 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
517 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
518
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
519 void jag_video_run(jag_video *context, uint32_t target_cycle)
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
520 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
521 if (context->regs[VID_VMODE] & BIT_TBGEN) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
522 while (context->cycles < target_cycle)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
523 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
524 //TODO: Optimize this to not actually increment one step at a time
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
525 if (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
526 (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
527 context->regs[VID_HCOUNT] == context->regs[VID_HDISP_BEGIN1]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
528 || context->regs[VID_HCOUNT] == context->regs[VID_HDISP_BEGIN2]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
529 )
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
530 && context->regs[VID_VCOUNT] >= context->regs[VID_VDISP_BEGIN]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
531 && context->regs[VID_VCOUNT] < context->regs[VID_VDISP_END]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
532 ) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
533 //swap linebuffers, render linebuffer to framebuffer and kick off object processor
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
534 if (context->write_line_buffer == context->line_buffer_a) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
535 context->write_line_buffer = context->line_buffer_b;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
536 copy_linebuffer(context, context->line_buffer_a);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
537 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
538 context->write_line_buffer = context->line_buffer_a;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
539 copy_linebuffer(context, context->line_buffer_b);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
540 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
541 //clear new write line buffer with background color
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
542 for (int i = 0; i < LINEBUFFER_WORDS; i++)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
543 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
544 context->write_line_buffer[i] = context->regs[VID_BGCOLOR];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
545 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
546
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
547 //kick off object processor
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
548 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
549 } else if (context->regs[VID_HCOUNT] == context->regs[VID_HDISP_END]) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
550 //stob object processor
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
551 context->op.state = OBJ_IDLE;
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
552 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
553
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
554 context->cycles++;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
555 op_run(context);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
556
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
557 //advance counters
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
558 if (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
559 !context->output
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
560 && context->regs[VID_VCOUNT] == context->regs[VID_VDISP_BEGIN]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
561 && context->regs[VID_HCOUNT] == context->regs[VID_HDISP_BEGIN1]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
562 ) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
563 context->output = render_get_framebuffer(FRAMEBUFFER_ODD, &context->output_pitch);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
564 } else if (context->output && context->regs[VID_VCOUNT] >= context->regs[VID_VDISP_END]) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
565 int width = (context->regs[VID_HPERIOD] - context->regs[VID_HDISP_BEGIN1]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
566 + context->regs[VID_HDISP_END] - 1024 + 2) / context->pclock_div;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
567 render_framebuffer_updated(FRAMEBUFFER_ODD, width);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
568 context->output = NULL;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
569 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
570
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
571 if ((context->regs[VID_HCOUNT] & 0x3FF) == context->regs[VID_HPERIOD]) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
572 //reset bottom 10 bits to zero, flip the 11th bit which represents which half of the line we're on
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
573 context->regs[VID_HCOUNT] = (context->regs[VID_HCOUNT] & 0x400) ^ 0x400;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
574 //increment half-line counter
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
575 if (context->regs[VID_VCOUNT] == context->regs[VID_VPERIOD]) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
576 context->regs[VID_VCOUNT] = 0;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
577 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
578 context->regs[VID_VCOUNT]++;
1097
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
579 if (context->regs[VID_VCOUNT] == context->regs[VID_VINT]) {
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
580 context->cpu_int_pending |= BIT_CPU_VID_INT_ENABLED;
faa3a4617f62 Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents: 1090
diff changeset
581 }
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
582 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
583 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
584 context->regs[VID_HCOUNT]++;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
585 }
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
586
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
587 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
588 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
589 context->cycles = target_cycle;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
590 }
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
591 }
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
592
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
593 static uint8_t is_reg_writeable(uint32_t address)
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
594 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
595 return address < VID_HLPEN || address >= VID_OBJLIST1;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
596 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
597
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
598 void jag_video_reg_write(jag_video *context, uint32_t address, uint16_t value)
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
599 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
600 uint32_t reg = (address >> 1 & 0x7F) - 2;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
601 if (reg < JAG_VIDEO_REGS && is_reg_writeable(reg)) {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
602 context->regs[reg] = value;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
603 if (reg == VID_VMODE) {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
604 context->pclock_div = (value >> 9 & 7) + 1;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
605 context->pclock_counter = 0;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
606 if (value & 0x10) {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
607 context->mode = VMODE_VARIABLE;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
608 } else {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
609 context->mode = value >> 1 & 3;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
610 }
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
611 printf("Mode %s, pixel clock divider: %d, time base generation: %s\n", vmode_names[context->mode], context->pclock_div, value & BIT_TBGEN ? "enabled" : "disabled");
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
612 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
613 switch (reg)
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
614 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
615 case VID_OBJLIST1:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
616 printf("Object List Pointer 1: %X\n", value);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
617 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
618 case VID_OBJLIST2:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
619 printf("Object List Pointer 2: %X\n", value);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
620 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
621 case VID_HPERIOD:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
622 printf("Horizontal period: %d\n", value & 0x3FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
623 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
624 case VID_HBLANK_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
625 printf("horizontal blanking begin: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
626 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
627 case VID_HBLANK_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
628 printf("horizontal blanking end: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
629 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
630 case VID_HSYNC:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
631 printf("horizontal sync start: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
632 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
633 case VID_HDISP_BEGIN1:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
634 printf("horizontal display begin 1: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
635 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
636 case VID_HDISP_BEGIN2:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
637 printf("horizontal display begin 2: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
638 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
639 case VID_HDISP_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
640 printf("horizontal display end: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
641 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
642 case VID_VPERIOD:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
643 printf("Vertical period: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
644 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
645 case VID_VBLANK_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
646 printf("vertical blanking begin: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
647 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
648 case VID_VBLANK_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
649 printf("vertical blanking end: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
650 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
651 case VID_VSYNC:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
652 printf("vertical sync start: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
653 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
654 case VID_VDISP_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
655 printf("vertical display begin: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
656 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
657 case VID_VDISP_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
658 printf("vertical display end: %d\n", value & 0x7FF);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
659 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
660 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
661 } else {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
662 fprintf(stderr, "Write to invalid video/object processor register %X:%X\n", address, value);
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
663 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
664 }