forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genblitter.cpp
194 lines (180 loc) · 6.92 KB
/
genblitter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* UAE - The Un*x Amiga Emulator
*
* Optimized blitter minterm function generator
*
* Copyright 1995,1996 Bernd Schmidt
* Copyright 1996 Alessandro Bissacco
*/
#include "sysconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "genblitter.h"
/* Here is the minterm table used in blitter function generation */
static unsigned char blttbl[]= {
0x00, 0x0a, 0x2a, 0x30, 0x3a, 0x3c, 0x4a, 0x6a, 0x8a, 0x8c, 0x9a, 0xa8,
0xaa, 0xb1, 0xca, 0xcc, 0xd8, 0xe2, 0xea, 0xf0, 0xfa, 0xfc
};
static void generate_include(void)
{
int minterm;
printf("STATIC_INLINE uae_u32 blit_func(uae_u32 srca, uae_u32 srcb, uae_u32 srcc, uae_u8 mt)\n{\nswitch(mt){\n");
for (minterm = 0; minterm < 256; minterm++) {
printf("case 0x%x:\n", minterm);
printf("\treturn %s;\n", blitops[minterm].s);
}
printf("}\n");
printf("return 0;\n"); /* No, sir, it doesn't! */
printf("}\n");
}
static void generate_func(void)
{
unsigned int i;
printf("#include \"sysconfig.h\"\n");
printf("#include \"sysdeps.h\"\n");
printf("#include \"options.h\"\n");
printf("#include \"custom.h\"\n");
printf("#include \"memory.h\"\n");
printf("#include \"blitter.h\"\n");
printf("#include \"blitfunc.h\"\n\n");
for (i = 0; i < sizeof(blttbl); i++) {
int active = blitops[blttbl[i]].used;
int a_is_on = active & 1, b_is_on = active & 2, c_is_on = active & 4;
printf("void blitdofast_%x (uaecptr pta, uaecptr ptb, uaecptr ptc, uaecptr ptd, struct bltinfo *b)\n",blttbl[i]);
printf("{\n");
printf("int i,j;\n");
printf("uae_u32 totald = 0;\n");
if (b_is_on) printf("uae_u32 srcb = b->bltbhold;\n");
if (c_is_on) printf("uae_u32 srcc = b->bltcdat;\n");
printf("uae_u16 ashift = bltcon0 >> 12;\n");
printf("uae_u16 bshift = bltcon1 >> 12;\n");
printf("uae_u32 dstd=0;\n");
printf("uaecptr dstp = 0;\n");
printf("for (j = 0; j < b->vblitsize; j++) {\n");
printf("\tfor (i = 0; i < b->hblitsize; i++) {\n");
if (a_is_on) {
printf("\t\tuae_u32 bltadat, srca;\n");
}
if (c_is_on) printf("\t\tif (ptc) { srcc = chipmem_wget_indirect(ptc); ptc += 2; }\n");
if (b_is_on) printf("\t\tif (ptb) {\n\t\t\tuae_u32 bltbdat = b->bltbdat = chipmem_wget_indirect(ptb); ptb += 2;\n");
if (b_is_on) printf("\t\t\tsrcb = (((uae_u32)b->bltbold << 16) | bltbdat) >> bshift;\n");
if (b_is_on) printf("\t\t\tb->bltbold = bltbdat;\n\t\t}\n");
if (a_is_on) printf("\t\tif (pta) { bltadat = b->bltadat = chipmem_wget_indirect(pta); pta += 2; } else { bltadat = b->bltadat; }\n");
if (a_is_on) printf("\t\tbltadat &= blit_masktable[i];\n");
if (a_is_on) printf("\t\tsrca = (((uae_u32)b->bltaold << 16) | bltadat) >> ashift;\n");
if (a_is_on) printf("\t\tb->bltaold = bltadat;\n");
printf("\t\tif (dstp) chipmem_wput_indirect(dstp, dstd);\n");
printf("\t\tdstd = (%s) & 0xFFFF;\n", blitops[blttbl[i]].s);
printf("\t\ttotald |= dstd;\n");
printf("\t\tif (ptd) { dstp = ptd; ptd += 2; }\n");
printf("\t}\n");
if (a_is_on) printf("\tif (pta) pta += b->bltamod;\n");
if (b_is_on) printf("\tif (ptb) ptb += b->bltbmod;\n");
if (c_is_on) printf("\tif (ptc) ptc += b->bltcmod;\n");
printf("\tif (ptd) ptd += b->bltdmod;\n");
printf("}\n");
if (b_is_on) printf("b->bltbhold = srcb;\n");
if (c_is_on) printf("b->bltcdat = srcc;\n");
printf("\t\tif (dstp) chipmem_wput_indirect(dstp, dstd);\n");
printf("if (totald != 0) b->blitzero = 0;\n");
printf("}\n");
printf("void blitdofast_desc_%x (uaecptr pta, uaecptr ptb, uaecptr ptc, uaecptr ptd, struct bltinfo *b)\n",blttbl[i]);
printf("{\n");
printf("uae_u32 totald = 0;\n");
printf("int i,j;\n");
if (b_is_on) printf("uae_u32 srcb = b->bltbhold;\n");
if (c_is_on) printf("uae_u32 srcc = b->bltcdat;\n");
printf("uae_u16 ashift = 16 - (bltcon0 >> 12);\n");
printf("uae_u16 bshift = 16 - (bltcon1 >> 12);\n");
printf("uae_u32 dstd = 0;\n");
printf("uaecptr dstp = 0;\n");
printf("for (j = 0; j < b->vblitsize; j++) {\n");
printf("\tfor (i = 0; i < b->hblitsize; i++) {\n");
if (a_is_on) {
printf("\t\tuae_u32 bltadat, srca;\n");
}
if (c_is_on) printf("\t\tif (ptc) { srcc = chipmem_wget_indirect(ptc); ptc -= 2; }\n");
if (b_is_on) printf("\t\tif (ptb) {\n\t\t\tuae_u32 bltbdat = b->bltbdat = chipmem_wget_indirect(ptb); ptb -= 2;\n");
if (b_is_on) printf("\t\t\tsrcb = ((bltbdat << 16) | b->bltbold) >> bshift;\n");
if (b_is_on) printf("\t\t\tb->bltbold = bltbdat;\n\t\t}\n");
if (a_is_on) printf("\t\tif (pta) { bltadat = b->bltadat = chipmem_wget_indirect(pta); pta -= 2; } else { bltadat = b->bltadat; }\n");
if (a_is_on) printf("\t\tbltadat &= blit_masktable[i];\n");
if (a_is_on) printf("\t\tsrca = (((uae_u32)bltadat << 16) | b->bltaold) >> ashift;\n");
if (a_is_on) printf("\t\tb->bltaold = bltadat;\n");
printf("\t\tif (dstp) chipmem_wput_indirect(dstp, dstd);\n");
printf("\t\tdstd = (%s) & 0xFFFF;\n", blitops[blttbl[i]].s);
printf("\t\ttotald |= dstd;\n");
printf("\t\tif (ptd) { dstp = ptd; ptd -= 2; }\n");
printf("\t}\n");
if (a_is_on) printf("\tif (pta) pta -= b->bltamod;\n");
if (b_is_on) printf("\tif (ptb) ptb -= b->bltbmod;\n");
if (c_is_on) printf("\tif (ptc) ptc -= b->bltcmod;\n");
printf("\tif (ptd) ptd -= b->bltdmod;\n");
printf("}\n");
if (b_is_on) printf("b->bltbhold = srcb;\n");
if (c_is_on) printf("b->bltcdat = srcc;\n");
printf("\t\tif (dstp) chipmem_wput_indirect(dstp, dstd);\n");
printf("if (totald != 0) b->blitzero = 0;\n");
printf("}\n");
}
}
static void generate_table(void)
{
unsigned int index = 0;
unsigned int i;
printf("#include \"sysconfig.h\"\n");
printf("#include \"sysdeps.h\"\n");
printf("#include \"options.h\"\n");
printf("#include \"custom.h\"\n");
printf("#include \"memory.h\"\n");
printf("#include \"blitter.h\"\n");
printf("#include \"blitfunc.h\"\n\n");
printf("blitter_func * const blitfunc_dofast[256] = {\n");
for (i = 0; i < 256; i++) {
if (index < sizeof(blttbl) && i == blttbl[index]) {
printf("blitdofast_%x",i);
index++;
}
else printf("0");
if (i < 255) printf(", ");
if ((i & 7) == 7) printf("\n");
}
printf("};\n\n");
index = 0;
printf("blitter_func * const blitfunc_dofast_desc[256] = {\n");
for (i = 0; i < 256; i++) {
if (index < sizeof(blttbl) && i == blttbl[index]) {
printf("blitdofast_desc_%x",i);
index++;
}
else printf("0");
if (i < 255) printf(", ");
if ((i & 7) == 7) printf("\n");
}
printf("};\n");
}
static void generate_header(void)
{
unsigned int i;
for (i = 0; i < sizeof(blttbl); i++) {
printf("extern blitter_func blitdofast_%x;\n",blttbl[i]);
printf("extern blitter_func blitdofast_desc_%x;\n",blttbl[i]);
}
}
int main(int argc, char **argv)
{
char mode = 'i';
if (argc == 2) mode = *argv[1];
switch (mode) {
case 'i': generate_include();
break;
case 'f': generate_func();
break;
case 't': generate_table();
break;
case 'h': generate_header();
break;
default: abort();
}
return 0;
}