1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-29 18:49:42 +00:00

Fixed line drawing - and fixed a fragment with an error.

This commit is contained in:
jespergravgaard 2021-04-04 10:59:29 +02:00
parent ab71bff269
commit ba2fdf58c5
2 changed files with 6 additions and 10 deletions

View File

@ -2,8 +2,6 @@ clc
lda {m2} lda {m2}
adc #1 adc #1
sta {m1} sta {m1}
bcc !+
lda {m2}+1 lda {m2}+1
adc #0 adc #0
sta {m1}+1 sta {m1}+1
!:

View File

@ -1,7 +1,7 @@
// Test hardware line drawing // Test hardware line drawing
// Based on https://github.com/MEGA65/mega65-tools/blob/master/src/tests/test_290.c // Based on https://github.com/MEGA65/mega65-tools/blob/master/src/tests/test_290.c
#pragma target(mega65) #pragma target(mega65_remote)
#include <mega65.h> #include <mega65.h>
#include <mega65-dma.h> #include <mega65-dma.h>
#include <6502.h> #include <6502.h>
@ -79,9 +79,8 @@ void main() {
} }
// Performs division on two 16 bit unsigned ints // Performs division on two 16 bit unsigned ints
// Returns the fractional part top 16 bit of the result // Returns the 16 bit fractional part of the result
// Uses the MEGA65 hardware math unit // Uses the MEGA65 hardware math unit
unsigned int m65_div16u_frac(unsigned int dividend, unsigned int divisor) { unsigned int m65_div16u_frac(unsigned int dividend, unsigned int divisor) {
// Use hardware divider to get the slope // Use hardware divider to get the slope
@ -89,7 +88,7 @@ unsigned int m65_div16u_frac(unsigned int dividend, unsigned int divisor) {
*MATH_MULTINB_INT0 = (signed int)divisor; *MATH_MULTINB_INT0 = (signed int)divisor;
*MATH_MULTINA_INT1 = 0; *MATH_MULTINA_INT1 = 0;
*MATH_MULTINB_INT1 = 0; *MATH_MULTINB_INT1 = 0;
// Wait 16 cycles // Wait 16 cycles (only neeeded for some values)
asm { asm {
lda MATH_DIVOUT_FRAC_INT1 @nooptimize lda MATH_DIVOUT_FRAC_INT1 @nooptimize
lda MATH_DIVOUT_FRAC_INT1 @nooptimize lda MATH_DIVOUT_FRAC_INT1 @nooptimize
@ -194,7 +193,7 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) {
unsigned int count = (unsigned int)dy; unsigned int count = (unsigned int)dy;
char is_slope_negative = ((x2 - x1) < 0) ? 1 : 0; char is_slope_negative = ((x2 - x1) < 0) ? 1 : 0;
char is_direction_y = 1; char is_direction_y = 1;
line_dma_execute(addr, slope, count, colour, is_slope_negative, is_direction_y); line_dma_execute(addr, slope, count, colour, is_direction_y, is_slope_negative);
} else { } else {
// X is major axis // X is major axis
if (x2 < x1) { if (x2 < x1) {
@ -207,11 +206,10 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) {
unsigned int count = (unsigned int)dx; unsigned int count = (unsigned int)dx;
char is_slope_negative = ((y2 - y1) < 0) ? 1 : 0; char is_slope_negative = ((y2 - y1) < 0) ? 1 : 0;
char is_direction_y = 0; char is_direction_y = 0;
line_dma_execute(addr, slope, count, colour, is_slope_negative, is_direction_y); line_dma_execute(addr, slope, count, colour, is_direction_y, is_slope_negative);
} }
} }
// Address of the screen // Address of the screen
unsigned char * const SCREEN = 0xc000; unsigned char * const SCREEN = 0xc000;
// // Absolute address of the graphics // // Absolute address of the graphics