mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-26 18:29:54 +00:00
Optimized line buffer and rendering sequence slightly
This commit is contained in:
parent
6da9a8f9f8
commit
aa66273149
@ -14,7 +14,7 @@
|
||||
#undef DEBUG
|
||||
|
||||
// The line buffer
|
||||
char* const LINE_BUFFER = 0x4000;
|
||||
char* const LINE_BUFFER = 0x2000;
|
||||
// The two charsets used as screen buffers
|
||||
char* const CANVAS1 = 0x3000;
|
||||
char* const CANVAS2 = 0x3800;
|
||||
@ -38,8 +38,6 @@ char align(0x100) SINTAB[0x140] = kickasm {{
|
||||
}};
|
||||
char* COSTAB = SINTAB+0x40;
|
||||
|
||||
void plot(char* canvas, char x, char y);
|
||||
|
||||
void main() {
|
||||
// Clear the console
|
||||
memset(CONSOLE, ' ', 40*25);
|
||||
@ -66,7 +64,7 @@ void main() {
|
||||
// Set text color
|
||||
textcolor(WHITE);
|
||||
|
||||
char p0_idx = 0x88;
|
||||
char p0_idx = 0xf0;
|
||||
char p1_idx = p0_idx+15;
|
||||
char p2_idx = p0_idx+170;
|
||||
|
||||
@ -91,16 +89,16 @@ void main() {
|
||||
p0_idx++;
|
||||
p1_idx++;
|
||||
p2_idx++;
|
||||
// Fill canvas
|
||||
eorfill(LINE_BUFFER, canvas);
|
||||
// Wait until the canvas on screen has been switched before starting work on the next frame
|
||||
VICII->BORDER_COLOR = RED;
|
||||
while(canvas_show_flag) {}
|
||||
VICII->BORDER_COLOR = BLACK;
|
||||
// Swap canvas to show on screen (using XOR)
|
||||
canvas_show_memory ^= toD018(SCREEN,CANVAS1)^toD018(SCREEN,CANVAS2);
|
||||
// Fill canvas
|
||||
eorfill(LINE_BUFFER, canvas);
|
||||
// swap canvas being rendered to (using XOR)
|
||||
canvas ^= (CANVAS1^CANVAS2);
|
||||
// Swap canvas to show on screen (using XOR)
|
||||
canvas_show_memory ^= toD018(SCREEN,CANVAS1)^toD018(SCREEN,CANVAS2);
|
||||
// Set flag used to signal when the canvas has been shown
|
||||
canvas_show_flag = 1;
|
||||
// Read and display cycles
|
||||
@ -175,7 +173,7 @@ void line(char* canvas, char x1, char y1, char x2, char y2) {
|
||||
// X is the driver - plot every X using bresenham
|
||||
char e = dx/2;
|
||||
do {
|
||||
plot(canvas, x, y);
|
||||
plot(x, y);
|
||||
x += sx;
|
||||
e += dy;
|
||||
if(dx < e) {
|
||||
@ -183,32 +181,32 @@ void line(char* canvas, char x1, char y1, char x2, char y2) {
|
||||
e -= dx;
|
||||
}
|
||||
} while (x != x2);
|
||||
plot(canvas, x, y);
|
||||
plot(x, y);
|
||||
} else {
|
||||
// Y is the driver - only plot one plot per X
|
||||
char e = dy/2;
|
||||
plot(canvas, x, y);
|
||||
plot(x, y);
|
||||
do {
|
||||
y += sy;
|
||||
e += dx;
|
||||
if(dy<e) {
|
||||
x += sx;
|
||||
e -= dy;
|
||||
plot(canvas, x, y);
|
||||
plot(x, y);
|
||||
}
|
||||
} while (y != y2);
|
||||
}
|
||||
}
|
||||
|
||||
// Column offsets
|
||||
unsigned int plot_column[16] = { 0, 1*128, 2*128, 3*128, 4*128, 5*128, 6*128, 7*128, 8*128, 9*128, 10*128, 11*128, 12*128, 13*128, 14*128, 15*128 };
|
||||
char* plot_column[16] = { LINE_BUFFER+0, LINE_BUFFER+1*128, LINE_BUFFER+2*128, LINE_BUFFER+3*128, LINE_BUFFER+4*128, LINE_BUFFER+5*128, LINE_BUFFER+6*128, LINE_BUFFER+7*128, LINE_BUFFER+8*128, LINE_BUFFER+9*128, LINE_BUFFER+10*128, LINE_BUFFER+11*128, LINE_BUFFER+12*128, LINE_BUFFER+13*128, LINE_BUFFER+14*128, LINE_BUFFER+15*128 };
|
||||
// The bits used for plotting a pixel
|
||||
char plot_bit[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
|
||||
// Plot a single point on the canvas
|
||||
void plot(char* canvas, char x, char y) {
|
||||
inline void plot(char x, char y) {
|
||||
// Find the canvas column
|
||||
char* column = canvas + plot_column[x/8];
|
||||
char* column = plot_column[x/8];
|
||||
// Plot the bit
|
||||
column[y] |= plot_bit[x&7];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user