[Maintenance] Define VRAM access macros for arbitrary bit counts

Templates would have been nicer, but as soon as you add just one
non-immediate parameter, Turbo C++ generates a useless store to a new
local variable, ruining the generated code.

Part of P0069, funded by [Anonymous] and Yanga.
This commit is contained in:
nmlgc 2020-01-12 20:34:42 +01:00
parent e0d0dcd51d
commit b5cef6eb69
5 changed files with 29 additions and 21 deletions

25
ReC98.h
View File

@ -103,12 +103,33 @@ extern planar8_t *VRAM_PLANE_G;
extern planar8_t *VRAM_PLANE_R;
extern planar8_t *VRAM_PLANE_E;
#define VRAM_OFFSET(x, y) ((x) >> 3) + (y << 6) + (y << 4)
#define VRAM_CHUNK(plane, offset, bit_count) \
*(planar##bit_count##_t *)(VRAM_PLANE_##plane + offset)
#define VRAM_SNAP(dst, plane, offset, bit_count) \
dst = VRAM_CHUNK(plane, offset, bit_count);
#define VRAM_SNAP_4(dst, offset, bit_count) \
VRAM_SNAP(dst.B, B, offset, bit_count); \
VRAM_SNAP(dst.R, R, offset, bit_count); \
VRAM_SNAP(dst.G, G, offset, bit_count); \
VRAM_SNAP(dst.E, E, offset, bit_count);
#define VRAM_PUT(plane, offset, src, bit_count) \
VRAM_CHUNK(plane, offset, bit_count) = src;
#define VRAM_PUT_4(offset, src, bit_count) \
VRAM_PUT(B, offset, src.B, bit_count); \
VRAM_PUT(R, offset, src.R, bit_count); \
VRAM_PUT(G, offset, src.G, bit_count); \
VRAM_PUT(E, offset, src.E, bit_count);
#define PLANE_DWORD_BLIT(dst, src) \
for(p = 0; p < PLANE_SIZE; p += (int)sizeof(planar32_t)) { \
*(planar32_t*)((dst) + p) = *(planar32_t*)((src) + p); \
}
#define VRAM_OFFSET(x, y) ((x) >> 3) + (y << 6) + (y << 4)
void pascal vram_planes_set(void);
// -----------------

View File

@ -32,10 +32,7 @@ void graph_slow_2xscale_rect_1_to_0(int x0, int y0, int x1, int y1, int w1, int
for(col16 = 0; col16 < w1 / 16; col16++) {
int scale_p;
graph_accesspage_func(1);
px16.B = *(planar16_t*)(VRAM_PLANE_B + p1);
px16.R = *(planar16_t*)(VRAM_PLANE_R + p1);
px16.G = *(planar16_t*)(VRAM_PLANE_G + p1);
px16.E = *(planar16_t*)(VRAM_PLANE_E + p1);
VRAM_SNAP_4(px16, p1, 16);
px16_nonzero = px16.B | px16.R | px16.G | px16.E;
for(scale_p = 0; scale_p < ROW_SIZE * 2; scale_p += ROW_SIZE) {
planar32_t dst32;

View File

@ -33,8 +33,8 @@ void egc_copy_rect_1_to_0(int x, int y, int w, int h)
egc_start_copy();
for(row = 0; row < h; row++) {
for(col = x_floor, p = row_p; col < x_end; p += 2, col += 16) {
graph_accesspage_func(1); bits = *(planar16_t*)(VRAM_PLANE_B + p);
graph_accesspage_func(0); *(planar16_t*)(VRAM_PLANE_B + p) = bits;
graph_accesspage_func(1); VRAM_SNAP(bits, B, p, 16);
graph_accesspage_func(0); VRAM_PUT(B, p, bits, 16);
}
row_p += 640 / 8;
}

View File

@ -33,16 +33,8 @@ void pascal graph_copy_rect_1_to_0(int x, int y, int w, int h)
for(col = 0, p = row_p; col < (w >> 4); col++, p += 2) {
if(row_p >= 0) {
vram_planar_16_pixels_t p16;
graph_accesspage(1);
p16.B = *(planar16_t*)(VRAM_PLANE_B + p);
p16.R = *(planar16_t*)(VRAM_PLANE_R + p);
p16.G = *(planar16_t*)(VRAM_PLANE_G + p);
p16.E = *(planar16_t*)(VRAM_PLANE_E + p);
graph_accesspage(0);
*(planar16_t*)(VRAM_PLANE_B + p) = p16.B;
*(planar16_t*)(VRAM_PLANE_R + p) = p16.R;
*(planar16_t*)(VRAM_PLANE_G + p) = p16.G;
*(planar16_t*)(VRAM_PLANE_E + p) = p16.E;
graph_accesspage(1); VRAM_SNAP_4(p16, p, 16);
graph_accesspage(0); VRAM_PUT_4(p, p16, 16);
}
}
row_p += ROW_SIZE;

View File

@ -69,9 +69,7 @@ void darken_pic_at(int x, int y)
grcg_setcolor(GC_RMW, 0);
for(row = 0; row < 144; row++, row_p += 640 / 8) {
for(col = 0; col < 192 / 8; col += 2) {
*(planar16_t*)(VRAM_PLANE_B + row_p + col) =
row & 1 ? 0xAAAA : 0x5555
;
VRAM_PUT(B, row_p + col, (row & 1 ? 0xAAAA : 0x5555), 16);
}
}
grcg_off();