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