From 1c9fa962d3fbb53f00c9183d244b87a87d3f6c1e Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sat, 3 Apr 2021 00:20:47 +0200 Subject: [PATCH] Fixed slope calculation. Added fragment. --- .../mos6502-common/vdum1=vwum2_plus_vwum3.asm | 12 ++++++++++++ src/test/kc/examples/mega65/linedrawing.c | 14 ++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vdum1=vwum2_plus_vwum3.asm diff --git a/src/main/fragment/mos6502-common/vdum1=vwum2_plus_vwum3.asm b/src/main/fragment/mos6502-common/vdum1=vwum2_plus_vwum3.asm new file mode 100644 index 000000000..d2724f951 --- /dev/null +++ b/src/main/fragment/mos6502-common/vdum1=vwum2_plus_vwum3.asm @@ -0,0 +1,12 @@ +clc +lda {m2} +adc {m3} +sta {m1} +lda {m2}+1 +adc {m3}+1 +sta {m1}+1 +lda #0 +sta {m1}+3 +adc #0 +sta {m1}+2 + diff --git a/src/test/kc/examples/mega65/linedrawing.c b/src/test/kc/examples/mega65/linedrawing.c index 8eafde9f4..05288143d 100644 --- a/src/test/kc/examples/mega65/linedrawing.c +++ b/src/test/kc/examples/mega65/linedrawing.c @@ -90,13 +90,16 @@ void main() { graphics_mode(); - draw_line(0, 100, 319, 0, 1); + //draw_line(150, 0, 160, 40, 5); + //draw_line(160, 0, 160, 40, 6); + //draw_line(170, 0, 160, 40, 7); /* 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); @@ -107,7 +110,6 @@ void main() { draw_line(0, y1, 319, 100, 6); draw_line(0, 100, 319, y1, 6); } - */ for(;;) ; @@ -207,12 +209,12 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) { 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; + unsigned int slope_init = 32768; 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); + unsigned long addr = GRAPHICS + (unsigned int)(x1/8) * 64 * 25 + (unsigned int)(y1*8) + (unsigned char)(x1&7); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = BYTE0(addr); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = BYTE1(addr); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = BYTE2(addr); @@ -266,12 +268,12 @@ void draw_line(int x1, int y1, int x2, int y2, unsigned char colour) { line_dma_command[LINE_DMA_COMMAND_SLOPE_OFFSET + 2] = HIBYTE(slope); // Put slope init into DMA options - unsigned int slope_init = slope/2; + unsigned int slope_init = 32768; 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); + unsigned long addr = GRAPHICS + (unsigned int)(x1/8) * 64 * 25 + (unsigned int)(y1*8) + (unsigned char)(x1&7); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 0] = BYTE0(addr); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 1] = BYTE1(addr); line_dma_command[LINE_DMA_COMMAND_DEST_OFFSET + 2] = BYTE2(addr);