annotate jag_video.c @ 1093:4987fddd42a0

Initial stab at jaguar disassemler
author Michael Pavone <pavone@retrodev.com>
date Sun, 30 Oct 2016 19:42:48 -0700
parents a68274a25e2f
children faa3a4617f62
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) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
65 uint8_t c = cry >> 12;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
66 uint8_t r = cry >> 8 & 0xF;
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];
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
71 red = red * 255 / y;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
72 blue = blue * 255 / y;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
73 green = green * 255 / y;
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
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
190 void op_run(jag_video *context)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
191 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
192 while (context->op.cycles < context->cycles)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
193 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
194 switch (context->op.state)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
195 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
196 case OBJ_IDLE:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
197 case OBJ_GPU_WAIT:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
198 context->op.cycles = context->cycles;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
199 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
200 case OBJ_FETCH_DESC1: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
201 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
202 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
203 address += 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
204
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
205 context->regs[VID_OBJ0] = val >> 48;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
206 context->regs[VID_OBJ1] = val >> 32;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
207 context->regs[VID_OBJ2] = val >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
208 context->regs[VID_OBJ3] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
209 context->op.type = val & 7;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
210 context->op.has_prefetch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
211 uint16_t ypos = val >> 3 & 0x7FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
212 switch (context->op.type)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
213 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
214 case OBJ_BITMAP:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
215 case OBJ_SCALED: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
216 uint16_t height = val >> 14 & 0x7FF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
217 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
218 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
219 context->op.state = OBJ_FETCH_DESC2;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
220 context->op.obj_start = address - 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
221 context->op.ypos = ypos;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
222 context->op.height = height;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
223 context->op.link = link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
224 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
225 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
226 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
227 //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
228 address = link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
229 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
230 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
231 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
232 case OBJ_GPU:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
233 context->op.state = OBJ_GPU_WAIT;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
234 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
235 case OBJ_BRANCH: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
236 uint8_t branch;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
237 switch(val >> 14 & 7)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
238 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
239 case 0:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
240 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
241 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
242 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
243 branch = ypos > context->regs[VID_VCOUNT];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
244 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
245 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
246 branch = ypos < context->regs[VID_VCOUNT];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
247 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
248 case 3:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
249 branch = context->regs[VID_OBJFLAG] & 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
250 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
251 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
252 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
253 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
254 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
255 branch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
256 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
257 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
258 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
259 if (branch) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
260 address &= 0xC00007;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
261 address |= val >> 21 & 0x3FFFF8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
262 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
263 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
264 case OBJ_STOP:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
265 //TODO: trigger interrupt
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
266 context->op.state = OBJ_IDLE;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
267 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
268 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
269 context->regs[VID_OBJLIST1] = address;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
270 context->regs[VID_OBJLIST2] = address >> 16;
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 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
273 case OBJ_FETCH_DESC2: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
274 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
275 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
276 address += 8;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
277
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
278 context->op.xpos = val & 0xFFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
279 if (context->op.xpos & 0x800) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
280 context->op.xpos |= 0xF000;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
281 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
282 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
283 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
284 if (context->op.bpp == 32) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
285 context->op.bpp = 24;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
286 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
287 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
288 if (context->op.bpp < 8) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
289 context->op.pal_offset = val >> 37;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
290 if (context->op.bpp == 4) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
291 context->op.pal_offset &= 0xF0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
292 } else if(context->op.bpp == 2) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
293 context->op.pal_offset &= 0xFC;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
294 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
295 context->op.pal_offset &= 0xFE;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
296 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
297 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
298 context->op.pal_offset = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
299 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
300 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
301 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
302 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
303 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
304 //TODO: do something with RELEASE flag
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
305 context->op.leftclip = val >> 49;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
306 if (context->op.type == OBJ_SCALED) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
307 context->op.state = OBJ_FETCH_DESC3;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
308 switch (context->op.bpp)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
309 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
310 case 1:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
311 context->op.leftclip &= 0x3F;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
312
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
313 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
314 //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
315 case 2:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
316 context->op.leftclip &= 0x3E;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
317 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
318 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
319 context->op.leftclip &= 0x3C;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
320 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
321 case 8:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
322 context->op.leftclip &= 0x38;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
323 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
324 case 16:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
325 context->op.leftclip &= 0x30;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
326 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
327 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
328 context->op.leftclip = 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
329 break;
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 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
332 context->op.state = OBJ_PROCESS;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
333 address = context->op.link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
334 switch (context->op.bpp)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
335 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
336 case 1:
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 2:
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 //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
343 case 4:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
344 context->op.leftclip &= 0x38;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
345 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
346 case 8:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
347 context->op.leftclip &= 0x30;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
348 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
349 case 16:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
350 context->op.leftclip &= 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
351 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
352 default:
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
353 context->op.leftclip = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
354 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
355 }
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 if (context->op.xpos < 0) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
358 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
359 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
360 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
361 if (clip >= context->op.line_phrases) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
362 context->op.line_phrases = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
363 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
364 context->op.line_phrases -= clip;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
365 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
366 if (context->op.leftclip >= 64) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
367 context->op.line_phrases--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
368 context->op.leftclip -= 64;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
369 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
370
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
371 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
372 } else if (context->op.bpp < 32){
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
373 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
374 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
375 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
376 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
377 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
378 //ignore objects that are completely offscreen
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
379 //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
380 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
381 address = context->op.link;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
382 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
383 context->regs[VID_OBJLIST1] = address;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
384 context->regs[VID_OBJLIST2] = address >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
385 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
386 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
387 case OBJ_FETCH_DESC3: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
388 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
389 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
390
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
391 context->op.state = OBJ_PROCESS;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
392 context->op.hscale = val & 0xFF;;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
393 context->op.hremainder = val & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
394 context->op.vscale = val >> 8 & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
395 context->op.remainder = val >> 16 & 0xFF;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
396
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
397 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
398 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
399 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
400 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
401 case OBJ_PROCESS: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
402 uint32_t proc_cycles = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
403 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
404 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
405 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
406 context->op.has_prefetch = 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
407 context->op.line_phrases--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
408 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
409 if (!proc_cycles) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
410 //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
411 proc_cycles = 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
412 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
413 while (proc_cycles)
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
414 {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
415 if (context->op.type == OBJ_SCALED && context->op.hscale) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
416 while (context->op.hremainder <= 0 && context->op.im_bits) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
417 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
418 context->op.hremainder += context->op.hscale;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
419 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
420 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
421 if (context->op.im_bits) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
422 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
423 val &= (1 << context->op.bpp) - 1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
424 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
425 if (context->op.bpp < 16) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
426 val = context->clut[val + context->op.pal_offset];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
427 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
428 if (context->op.bpp == 32) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
429 context->write_line_buffer[context->op.lb_offset++] = val >> 16;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
430 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
431 context->write_line_buffer[context->op.lb_offset++] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
432 if (context->op.type == OBJ_SCALED) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
433 context->op.hremainder -= 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
434 }
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 && 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
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;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
439 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
440 val = context->clut[val + context->op.pal_offset];
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
441 context->write_line_buffer[context->op.lb_offset++] = val;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
442 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
443 context->op_cycles++;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
444 proc_cycles--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
445 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
446 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
447 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
448 context->op.has_prefetch = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
449 //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
450 //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
451 //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
452 //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
453 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
454 context->op.leftclip = 0;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
455 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
456 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
457 context->op.state = OBJ_HEIGHT_WB;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
458 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
459 break;
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 case OBJ_HEIGHT_WB: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
462 if (context->op.type == OBJ_BITMAP) {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
463 context->op.height--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
464 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
465 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
466 } else {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
467 context->op.remainder -= 0x20;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
468 context->op.state = OBJ_REMAINDER_WB;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
469 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
470 context->op.height--;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
471 context->op.remainder += context->op.vscale;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
472 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
473 }
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 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
476 | ((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
477 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
478 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
479 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
480 case OBJ_REMAINDER_WB: {
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
481 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
482 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
483 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
484 break;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
485 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
486 }
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 }
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
489
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
490 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
491 {
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
492 if (context->regs[VID_VMODE] & BIT_TBGEN) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
493 while (context->cycles < target_cycle)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
494 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
495 //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
496 if (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
497 (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
498 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
499 || 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
500 )
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
501 && 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
502 && 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
503 ) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
504 //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
505 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
506 context->write_line_buffer = context->line_buffer_b;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
507 copy_linebuffer(context, context->line_buffer_a);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
508 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
509 context->write_line_buffer = context->line_buffer_a;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
510 copy_linebuffer(context, context->line_buffer_b);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
511 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
512 //clear new write line buffer with background color
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
513 for (int i = 0; i < LINEBUFFER_WORDS; i++)
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
514 {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
515 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
516 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
517
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
518 //kick off object processor
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
519 context->op.state = OBJ_FETCH_DESC1;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
520 } 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
521 //stob object processor
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
522 context->op.state = OBJ_IDLE;
1089
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
1090
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
525 context->cycles++;
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
526 op_run(context);
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
527
a68274a25e2f Initial stab at implementing the Jaguar object processor
Michael Pavone <pavone@retrodev.com>
parents: 1089
diff changeset
528 //advance counters
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
529 if (
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
530 !context->output
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_BEGIN]
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
532 && 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
533 ) {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
534 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
535 } 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
536 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
537 + 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
538 render_framebuffer_updated(FRAMEBUFFER_ODD, width);
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
539 context->output = NULL;
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
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
542 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
543 //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
544 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
545 //increment half-line counter
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
546 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
547 context->regs[VID_VCOUNT] = 0;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
548 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
549 context->regs[VID_VCOUNT]++;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
550 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
551 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
552 context->regs[VID_HCOUNT]++;
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
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
555 }
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
556 } else {
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
557 context->cycles = target_cycle;
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
558 }
1087
6433d4d05934 Added placeholder code for video output hardware/object processor
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
559 }
1088
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
560
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
561 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
562 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
563 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
564 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
565
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
566 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
567 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
568 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
569 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
570 context->regs[reg] = value;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
571 if (reg == VID_VMODE) {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
572 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
573 context->pclock_counter = 0;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
574 if (value & 0x10) {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
575 context->mode = VMODE_VARIABLE;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
576 } else {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
577 context->mode = value >> 1 & 3;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
578 }
1089
87597a048d38 Initial implementation of video output hardware
Michael Pavone <pavone@retrodev.com>
parents: 1088
diff changeset
579 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
580 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
581 switch (reg)
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
582 {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
583 case VID_OBJLIST1:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
584 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
585 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
586 case VID_OBJLIST2:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
587 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
588 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
589 case VID_HPERIOD:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
590 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
591 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
592 case VID_HBLANK_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
593 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
594 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
595 case VID_HBLANK_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
596 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
597 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
598 case VID_HSYNC:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
599 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
600 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
601 case VID_HDISP_BEGIN1:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
602 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
603 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
604 case VID_HDISP_BEGIN2:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
605 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
606 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
607 case VID_HDISP_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
608 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
609 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
610 case VID_VPERIOD:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
611 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
612 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
613 case VID_VBLANK_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
614 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
615 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
616 case VID_VBLANK_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
617 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
618 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
619 case VID_VSYNC:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
620 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
621 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
622 case VID_VDISP_BEGIN:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
623 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
624 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
625 case VID_VDISP_END:
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
626 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
627 break;
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
628 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
629 } else {
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
630 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
631 }
c0a026e974f4 Basic handling of video/object processor register writes
Michael Pavone <pavone@retrodev.com>
parents: 1087
diff changeset
632 }