From 3de1834b3596f0787478572b7079ef897ba46b4d Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 2 Apr 2021 11:49:28 +0200 Subject: [PATCH] Added slope initialization and a few fragments. --- .../vwsm1=_deref_pwsc1_plus_1.asm | 7 ++++ .../vwum1=_deref_pwuc1_ror_1.asm | 6 +++ src/test/kc/examples/mega65/linedrawing.c | 42 +++++++++++++++---- 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vwsm1=_deref_pwsc1_plus_1.asm create mode 100644 src/main/fragment/mos6502-common/vwum1=_deref_pwuc1_ror_1.asm diff --git a/src/main/fragment/mos6502-common/vwsm1=_deref_pwsc1_plus_1.asm b/src/main/fragment/mos6502-common/vwsm1=_deref_pwsc1_plus_1.asm new file mode 100644 index 000000000..dde900783 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwsm1=_deref_pwsc1_plus_1.asm @@ -0,0 +1,7 @@ +clc +lda {c1} +adc #1 +sta {m1} +lda {c1}+1 +adc #0 +sta {m1}+1 \ No newline at end of file diff --git a/src/main/fragment/mos6502-common/vwum1=_deref_pwuc1_ror_1.asm b/src/main/fragment/mos6502-common/vwum1=_deref_pwuc1_ror_1.asm new file mode 100644 index 000000000..4c0eabe7d --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=_deref_pwuc1_ror_1.asm @@ -0,0 +1,6 @@ +lda {c1}+1 +lsr +sta {m1}+1 +lda {c1} +ror +sta {m1} diff --git a/src/test/kc/examples/mega65/linedrawing.c b/src/test/kc/examples/mega65/linedrawing.c index 5299bb515..8eafde9f4 100644 --- a/src/test/kc/examples/mega65/linedrawing.c +++ b/src/test/kc/examples/mega65/linedrawing.c @@ -44,6 +44,8 @@ char line_dma_command[] = { DMA_OPTION_LINE_XSTEP_HI, (25*64 - 8) >> 8, // Line X step bytes 64x25 DMA_OPTION_LINE_SLOPE_LO, 0, // Line Slope DMA_OPTION_LINE_SLOPE_HI, 0, // Line Slope + DMA_OPTION_LINE_SLOPE_INIT_LO, 0, // Line slope init + DMA_OPTION_LINE_SLOPE_INIT_HI, 0, // Line slope init DMA_OPTION_LINE_MODE, 0, // Line Mode DMA_OPTION_FORMAT_F018A, // F018A list format DMA_OPTION_END, // end of options @@ -58,14 +60,16 @@ char line_dma_command[] = { // Offset of the DMA line SLOPE const char LINE_DMA_COMMAND_SLOPE_OFFSET = 5; +// Offset of the DMA line SLOPE init +const char LINE_DMA_COMMAND_SLOPE_INIT_OFFSET = 9; // Offset of the DMA line MODE -const char LINE_DMA_COMMAND_MODE_OFFSET = 9; +const char LINE_DMA_COMMAND_MODE_OFFSET = 13; // Offset of the DMA count -const char LINE_DMA_COMMAND_COUNT_OFFSET = 13; +const char LINE_DMA_COMMAND_COUNT_OFFSET = 17; // Offset of the DMA source -const char LINE_DMA_COMMAND_SRC_OFFSET = 15; +const char LINE_DMA_COMMAND_SRC_OFFSET = 19; // Offset of the DMA destination -const char LINE_DMA_COMMAND_DEST_OFFSET = 18; +const char LINE_DMA_COMMAND_DEST_OFFSET = 22; void main() { @@ -85,11 +89,26 @@ void main() { VICIV->CONTROLC |= VICIV_VFAST; graphics_mode(); - draw_line(160, 100, 0, 199, 1); + + draw_line(0, 100, 319, 0, 1); + + /* + draw_line(160, 100, 0, 199, 1); draw_line(160, 100, 319, 199, 2); draw_line( 0, 0, 160, 100, 3); draw_line(160, 100, 319, 0, 4); + for(int x1=0;x1<320;x1+=10) { + draw_line(x1, 0, 160, 199, 5); + draw_line(160, 0, x1, 199, 5); + } + + for(int y1=0;y1<200;y1+=10) { + draw_line(0, y1, 319, 100, 6); + draw_line(0, 100, 319, y1, 6); + } + */ + for(;;) ; } @@ -182,11 +201,15 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) { // Slope is the most significant bytes of the fractional part // of the division result - int slope = *MATH_DIVOUT_FRAC_INT1; + unsigned int slope = (unsigned int)*MATH_DIVOUT_FRAC_INT1; // Put slope into DMA options line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = LOBYTE(slope); line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = HIBYTE(slope); + // Put slope init into DMA options + unsigned int slope_init = slope/2; + line_dma_command[LINE_DMA_COMMAND_SLOPE_INIT_OFFSET] = LOBYTE(slope_init); + line_dma_command[LINE_DMA_COMMAND_SLOPE_INIT_OFFSET + 2] = HIBYTE(slope_init); // Load DMA dest address with the address of the first pixel unsigned long addr = GRAPHICS + (x1/8) * 64 * 25 + (y1*8) + (x1&7); @@ -236,12 +259,17 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) { VICIV->BORDER_COLOR = 0; // Slope is the most significant bytes of the fractional part of the division result - int slope = *MATH_DIVOUT_FRAC_INT1; + unsigned int slope = (unsigned int)*MATH_DIVOUT_FRAC_INT1; // Put slope into DMA options line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET] = LOBYTE(slope); line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = HIBYTE(slope); + // Put slope init into DMA options + unsigned int slope_init = slope/2; + line_dma_command[LINE_DMA_COMMAND_SLOPE_INIT_OFFSET] = LOBYTE(slope_init); + line_dma_command[LINE_DMA_COMMAND_SLOPE_INIT_OFFSET + 2] = HIBYTE(slope_init); + // Load DMA dest address with the address of the first pixel unsigned long addr = GRAPHICS + (x1/8) * 64 * 25 + (y1*8) + (x1&7); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = BYTE0(addr);