]> git.sesse.net Git - pistorm/blob - platforms/amiga/rtg/rtg.h
More RTG acceleration, fix everything
[pistorm] / platforms / amiga / rtg / rtg.h
1 #define PIGFX_RTG_BASE 0x70000000
2 #define PIGFX_RTG_SIZE 0x02000000
3
4 #define PIGFX_REG_SIZE 0x00010000
5
6 #define CARD_OFFSET 0
7
8 #include "rtg_driver_amiga/rtg_enums.h"
9
10 void rtg_write(uint32_t address, uint32_t value, uint8_t mode);
11 unsigned int rtg_read(uint32_t address, uint8_t mode);
12 void rtg_set_clut_entry(uint8_t index, uint32_t xrgb);
13 void rtg_init_display();
14 void rtg_shutdown_display();
15
16 void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format, uint8_t mask);
17 void rtg_blitrect(uint16_t x, uint16_t y, uint16_t dx, uint16_t dy, uint16_t w, uint16_t h, uint16_t pitch, uint16_t format, uint8_t mask);
18 void rtg_blitrect_nomask_complete(uint16_t sx, uint16_t sy, uint16_t dx, uint16_t dy, uint16_t w, uint16_t h, uint16_t srcpitch, uint16_t dstpitch, uint32_t src_addr, uint32_t dst_addr, uint16_t format, uint8_t minterm);
19 void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t t_pitch, uint16_t format, uint16_t offset_x, uint8_t mask, uint8_t draw_mode);
20 void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint16_t offset_x, uint16_t offset_y, uint8_t mask, uint8_t draw_mode, uint8_t loop_rows);
21
22 #define PATTERN_LOOPX \
23     tmpl_x ^= 0x01; \
24     cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; \
25
26 #define PATTERN_LOOPY \
27         sptr += 2 ; \
28         if ((ys + offset_y + 1) % loop_rows == 0) \
29                 sptr = sptr_base; \
30         tmpl_x = (offset_x / 8) % 2; \
31         cur_bit = base_bit; \
32         dptr += pitch;
33
34 #define TEMPLATE_LOOPX \
35     tmpl_x++; \
36     cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; \
37
38 #define TEMPLATE_LOOPY \
39     sptr += t_pitch; \
40     dptr += pitch; \
41     tmpl_x = offset_x / 8; \
42     cur_bit = base_bit;
43
44 #define SET_RTG_PIXELS(a, b, c, d) \
45     switch (c) { \
46         case RTGFMT_8BIT: \
47             if (cur_byte & 0x80) a[b + 0] = d[c]; \
48             if (cur_byte & 0x40) a[b + 1] = d[c]; \
49             if (cur_byte & 0x20) a[b + 2] = d[c]; \
50             if (cur_byte & 0x10) a[b + 3] = d[c]; \
51             if (cur_byte & 0x08) a[b + 4] = d[c]; \
52             if (cur_byte & 0x04) a[b + 5] = d[c]; \
53             if (cur_byte & 0x02) a[b + 6] = d[c]; \
54             if (cur_byte & 0x01) a[b + 7] = d[c]; \
55             break; \
56         case RTGFMT_RBG565: \
57             if (cur_byte & 0x80) ((uint16_t *)a)[b + 0] = d[c]; \
58             if (cur_byte & 0x40) ((uint16_t *)a)[b + 1] = d[c]; \
59             if (cur_byte & 0x20) ((uint16_t *)a)[b + 2] = d[c]; \
60             if (cur_byte & 0x10) ((uint16_t *)a)[b + 3] = d[c]; \
61             if (cur_byte & 0x08) ((uint16_t *)a)[b + 4] = d[c]; \
62             if (cur_byte & 0x04) ((uint16_t *)a)[b + 5] = d[c]; \
63             if (cur_byte & 0x02) ((uint16_t *)a)[b + 6] = d[c]; \
64             if (cur_byte & 0x01) ((uint16_t *)a)[b + 7] = d[c]; \
65             break; \
66         case RTGFMT_RGB32: \
67             if (cur_byte & 0x80) ((uint32_t *)a)[b + 0] = d[c]; \
68             if (cur_byte & 0x40) ((uint32_t *)a)[b + 1] = d[c]; \
69             if (cur_byte & 0x20) ((uint32_t *)a)[b + 2] = d[c]; \
70             if (cur_byte & 0x10) ((uint32_t *)a)[b + 3] = d[c]; \
71             if (cur_byte & 0x08) ((uint32_t *)a)[b + 4] = d[c]; \
72             if (cur_byte & 0x04) ((uint32_t *)a)[b + 5] = d[c]; \
73             if (cur_byte & 0x02) ((uint32_t *)a)[b + 6] = d[c]; \
74             if (cur_byte & 0x01) ((uint32_t *)a)[b + 7] = d[c]; \
75             break; \
76     }
77
78 #define SET_RTG_PIXELS_COND(a, b, c, d, e) \
79     switch (c) { \
80         case RTGFMT_8BIT: \
81             a[b + 0] = (cur_byte & 0x80) ? d[c] : e[c]; \
82             a[b + 1] = (cur_byte & 0x40) ? d[c] : e[c]; \
83             a[b + 2] = (cur_byte & 0x20) ? d[c] : e[c]; \
84             a[b + 3] = (cur_byte & 0x10) ? d[c] : e[c]; \
85             a[b + 4] = (cur_byte & 0x08) ? d[c] : e[c]; \
86             a[b + 5] = (cur_byte & 0x04) ? d[c] : e[c]; \
87             a[b + 6] = (cur_byte & 0x02) ? d[c] : e[c]; \
88             a[b + 7] = (cur_byte & 0x01) ? d[c] : e[c]; \
89             break; \
90         case RTGFMT_RBG565: \
91             ((uint16_t *)a)[b + 0] = (cur_byte & 0x80) ? d[c] : e[c]; \
92             ((uint16_t *)a)[b + 1] = (cur_byte & 0x40) ? d[c] : e[c]; \
93             ((uint16_t *)a)[b + 2] = (cur_byte & 0x20) ? d[c] : e[c]; \
94             ((uint16_t *)a)[b + 3] = (cur_byte & 0x10) ? d[c] : e[c]; \
95             ((uint16_t *)a)[b + 4] = (cur_byte & 0x08) ? d[c] : e[c]; \
96             ((uint16_t *)a)[b + 5] = (cur_byte & 0x04) ? d[c] : e[c]; \
97             ((uint16_t *)a)[b + 6] = (cur_byte & 0x02) ? d[c] : e[c]; \
98             ((uint16_t *)a)[b + 7] = (cur_byte & 0x01) ? d[c] : e[c]; \
99             break; \
100         case RTGFMT_RGB32: \
101             ((uint32_t *)a)[b + 0] = (cur_byte & 0x80) ? d[c] : e[c]; \
102             ((uint32_t *)a)[b + 1] = (cur_byte & 0x40) ? d[c] : e[c]; \
103             ((uint32_t *)a)[b + 2] = (cur_byte & 0x20) ? d[c] : e[c]; \
104             ((uint32_t *)a)[b + 3] = (cur_byte & 0x10) ? d[c] : e[c]; \
105             ((uint32_t *)a)[b + 4] = (cur_byte & 0x08) ? d[c] : e[c]; \
106             ((uint32_t *)a)[b + 5] = (cur_byte & 0x04) ? d[c] : e[c]; \
107             ((uint32_t *)a)[b + 6] = (cur_byte & 0x02) ? d[c] : e[c]; \
108             ((uint32_t *)a)[b + 7] = (cur_byte & 0x01) ? d[c] : e[c]; \
109             break; \
110     }
111
112 #define INVERT_RTG_PIXELS(a, b, c) \
113     switch (c) { \
114         case RTGFMT_8BIT: \
115             if (cur_byte & 0x80) a[b + 0] = ~a[b + 0]; \
116             if (cur_byte & 0x40) a[b + 1] = ~a[b + 1]; \
117             if (cur_byte & 0x20) a[b + 2] = ~a[b + 2]; \
118             if (cur_byte & 0x10) a[b + 3] = ~a[b + 3]; \
119             if (cur_byte & 0x08) a[b + 4] = ~a[b + 4]; \
120             if (cur_byte & 0x04) a[b + 5] = ~a[b + 5]; \
121             if (cur_byte & 0x02) a[b + 6] = ~a[b + 6]; \
122             if (cur_byte & 0x01) a[b + 7] = ~a[b + 7]; \
123             break; \
124         case RTGFMT_RBG565: \
125             if (cur_byte & 0x80) ((uint16_t *)a)[b + 0] = ~((uint16_t *)a)[b + 0]; \
126             if (cur_byte & 0x40) ((uint16_t *)a)[b + 1] = ~((uint16_t *)a)[b + 1]; \
127             if (cur_byte & 0x20) ((uint16_t *)a)[b + 2] = ~((uint16_t *)a)[b + 2]; \
128             if (cur_byte & 0x10) ((uint16_t *)a)[b + 3] = ~((uint16_t *)a)[b + 3]; \
129             if (cur_byte & 0x08) ((uint16_t *)a)[b + 4] = ~((uint16_t *)a)[b + 4]; \
130             if (cur_byte & 0x04) ((uint16_t *)a)[b + 5] = ~((uint16_t *)a)[b + 5]; \
131             if (cur_byte & 0x02) ((uint16_t *)a)[b + 6] = ~((uint16_t *)a)[b + 6]; \
132             if (cur_byte & 0x01) ((uint16_t *)a)[b + 7] = ~((uint16_t *)a)[b + 7]; \
133             break; \
134         case RTGFMT_RGB32: \
135             if (cur_byte & 0x80) ((uint32_t *)a)[b + 0] = ~((uint32_t *)a)[b + 0]; \
136             if (cur_byte & 0x40) ((uint32_t *)a)[b + 1] = ~((uint32_t *)a)[b + 1]; \
137             if (cur_byte & 0x20) ((uint32_t *)a)[b + 2] = ~((uint32_t *)a)[b + 2]; \
138             if (cur_byte & 0x10) ((uint32_t *)a)[b + 3] = ~((uint32_t *)a)[b + 3]; \
139             if (cur_byte & 0x08) ((uint32_t *)a)[b + 4] = ~((uint32_t *)a)[b + 4]; \
140             if (cur_byte & 0x04) ((uint32_t *)a)[b + 5] = ~((uint32_t *)a)[b + 5]; \
141             if (cur_byte & 0x02) ((uint32_t *)a)[b + 6] = ~((uint32_t *)a)[b + 6]; \
142             if (cur_byte & 0x01) ((uint32_t *)a)[b + 7] = ~((uint32_t *)a)[b + 7]; \
143             break; \
144     }
145
146 #define SET_RTG_PIXEL(a, b, c, d) \
147     switch (c) { \
148         case RTGFMT_8BIT: \
149             a[b] = d[c]; \
150             break; \
151         case RTGFMT_RBG565: \
152             ((uint16_t *)a)[b] = d[c]; \
153             break; \
154         case RTGFMT_RGB32: \
155             ((uint32_t *)a)[b] = d[c]; \
156             break; \
157     }
158
159 #define INVERT_RTG_PIXEL(a, b, c) \
160     switch (c) { \
161         case RTGFMT_8BIT: \
162             a[b] = ~a[c]; \
163             break; \
164         case RTGFMT_RBG565: \
165             ((uint16_t *)a)[b] = ~((uint16_t *)a)[b]; \
166             break; \
167         case RTGFMT_RGB32: \
168             ((uint32_t *)a)[b] = ~((uint32_t *)a)[b]; \
169             break; \
170     }