From 7f136b9ed22310ee13ecc73395ef3c0a321dfbf5 Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 14:48:46 +0200 Subject: [PATCH 1/6] fix up the build / compile stuff --- wip-hugo/build.sh | 2 +- wip-hugo/run.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wip-hugo/build.sh b/wip-hugo/build.sh index 6f2a82d..a91a9aa 100755 --- a/wip-hugo/build.sh +++ b/wip-hugo/build.sh @@ -3,4 +3,4 @@ cl65 -o build/file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg -l build/program.lst source.s -Ln build/program.lbl \ #VICE do not like - -sed -i 's/-/m/g' program.lbl +sed -i 's/-/m/g' build/program.lbl diff --git a/wip-hugo/run.sh b/wip-hugo/run.sh index 725a15f..f60ad5d 100755 --- a/wip-hugo/run.sh +++ b/wip-hugo/run.sh @@ -2,4 +2,4 @@ killall x64sc ./build.sh \ -&& nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 -moncommands program.lbl build/file.prg /dev/null & +&& nohup flatpak run net.sf.VICE -windowypos 0 -windowxpos 960 -windowwidth 945 -windowheight 720 -moncommands build/program.lbl build/file.prg /dev/null & From ef22e5a2fff1cd2a96fb2cf880570fb2a1a517b1 Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 14:50:23 +0200 Subject: [PATCH 2/6] use faster memset algoritm. --- wip-hugo/routines/memory/memset.s | 118 ++++++++++++++++++++---------- wip-hugo/source.s | 3 +- 2 files changed, 80 insertions(+), 41 deletions(-) mode change 100755 => 100644 wip-hugo/routines/memory/memset.s diff --git a/wip-hugo/routines/memory/memset.s b/wip-hugo/routines/memory/memset.s old mode 100755 new mode 100644 index 55700e9..37371ad --- a/wip-hugo/routines/memory/memset.s +++ b/wip-hugo/routines/memory/memset.s @@ -1,40 +1,78 @@ -;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- - -;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length' -;; Modifies A, X and A_start -.proc memset - .include "mem.inc" - -;; big_set sets the memory in $ff chunks. -;; skipp if length >= $ff -LDX length +1 -BNE big_set -JMP small_set - -big_set: ;sets $ff of memory - ;; Y value do not matter, will go through all anyway! - .repeat $ff - STA (A_start), Y - DEY - .endrepeat - STA (A_start), Y ; dont forget Y =0 -big_set_end: - ;;set all hole $ff memory chunks! - INC A_start + 1 - DEX ;; length +1 -- - BEQ small_set - JMP big_set - - - -;;sets the rest of the memory -;; note that this can use code above (smc) or the same method. may implement later. -small_set: - LDY length -small_set_loop: - STA (A_start), Y - DEY - BNE small_set_loop - STA (A_start), Y - RTS -.endproc +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length' +;; Modifies A, X and A_start +.proc memset + .include "mem.inc" + +;; big_set sets the memory in $ff chunks. +;; skipp if length >= $ff +LDX length +1 +BNE big_set +JMP small_set + +big_set: ;sets $ff of memory + ;; Y value do not matter, will go through all anyway! + .repeat $ff + STA (A_start), Y + DEY + .endrepeat + STA (A_start), Y ; dont forget Y =0 +big_set_end: + ;;set all hole $ff memory chunks! + INC A_start + 1 + DEX ;; length +1 -- + BEQ small_set + JMP big_set + +;; Note that cpu cykels total: cy_tot = 66 to 69 +;; But we skipp a BNE (cy = 2*) * [length (mod 255)] +;; The BNE case has an avrige of 2*255/2 = 255 so this is faster (on avrige.) + +small_set: + STA data_to_write ; cy = 3 + LDA length ; cy = 3 + STA length_copy ; cy = 3 + + ;; calculate rts-position + LDX #$00 ; cy = 2 + STX length + 1 ; cy = 3 + ;; 3 bytes = STA DEY NOP = seting 1 byte of memory. + ;; So we need to calculate: length*3 + Mult_16 A, length + 1 ; cy = 7 + ; A= length + ADC length_copy ; cy = 3 + TAY + LDA length + 1 ; cy = 3 + ADC #$00 ; cy = 2 + STA length + 1 ; cy = 3 + + ;; Now RTS_pointer + Y = length*3 + big_set_label + LDA #big_set ; cy = 2 + ADC length + 1 ; cy = 3 + STA RTS_pointer + 1 ; cy = 3 + + ;; read data we will change to RTS + STY Y_copy ; cy = 3 + LDA (RTS_pointer), Y ; cy = 5* + TAX ; cy = 2 + + ;; set RTS in big_set + LDA #$60 ; cy = 2 + STA (RTS_pointer), Y ; cy = 5* + + ;; JSR to modified big_set + LDY length_copy ; cy = 3 + DEY ; because we want to count to Y=0 :) + LDA data_to_write ; cy = 3 + JSR big_set ; cy = 6 + + ;; revert changes + LDY Y_copy ; cy = 3 + TXA ; cy = 2 + STA (RTS_pointer), Y ; cy = 5* + + RTS +.endproc diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 9c0bfd3..59c0c30 100644 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -33,7 +33,8 @@ JMP exit .include "routines/pixel/pixel_draw.s" .include "routines/pixel/pixel_calc.s" .include "routines/text/char_draw.s" -.include "routines/memory/memset_alt.s" +.include "routines/memory/memset.s" +;.include "routines/memory/clear_screen.s" .include "routines/memory/memcpy.s" .include "routines/arithmatic/mult.s" .include "routines/arithmatic/div.s" From 0f9db52148021e84917526e9373f5c38e3895f87 Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 15:54:47 +0200 Subject: [PATCH 3/6] write a specific memset only for clearing screen, so we can make it faster! --- wip-hugo/routines/memory/clear_screen.s | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 wip-hugo/routines/memory/clear_screen.s diff --git a/wip-hugo/routines/memory/clear_screen.s b/wip-hugo/routines/memory/clear_screen.s new file mode 100644 index 0000000..e55edb8 --- /dev/null +++ b/wip-hugo/routines/memory/clear_screen.s @@ -0,0 +1,39 @@ +;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- + +;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length' +;; Modifies A, X and A_start +.proc clear_screen + .include "mem.inc" + VIC_bank = $4000 + length_ = $1f40 + low_length_3 = $C0 + $03 ;; we need one more. + Mov_16 A_start, A_start + 1, #VIC_bank + LDA #$00 + ;; big_set sets the memory in $ff chunks. + ;; skipp if length >= $ff + LDX #>length_ + BNE big_set + JMP small_set +big_set: ;sets $ff of memory + ;; Y value do not matter, will go through all anyway! + .repeat $ff + STA (A_start), Y + DEY + .endrepeat + STA (A_start), Y ; dont forget Y =0 +big_set_end: + ;;set all hole $ff memory chunks! + INC A_start + 1 + DEX ;; length +1 -- + BEQ small_set + JMP big_set + +small_set: + LDX big_set + low_length_3 + LDY #$60 + STY big_set + low_length_3 + LDY # Date: Sat, 26 Jul 2025 15:55:57 +0200 Subject: [PATCH 4/6] make use of new clear_screen macro. --- wip-hugo/STARTUP.s | 9 +- wip-hugo/program.lbl | 168 ------------------ .../routines/circle/circle_test_position.s | 8 +- wip-hugo/routines/circle/circle_test_size.s | 7 +- wip-hugo/routines/line/line_test_extensive.s | 23 +-- wip-hugo/routines/memory/memset_alt.s | 75 -------- wip-hugo/source.s | 22 +-- 7 files changed, 20 insertions(+), 292 deletions(-) delete mode 100644 wip-hugo/program.lbl delete mode 100644 wip-hugo/routines/memory/memset_alt.s diff --git a/wip-hugo/STARTUP.s b/wip-hugo/STARTUP.s index 0852267..bc9ebc8 100755 --- a/wip-hugo/STARTUP.s +++ b/wip-hugo/STARTUP.s @@ -58,17 +58,14 @@ ORA Screen_RAM_settings STA Screen_RAM_settings - ;; Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset + ;; clear the screen + JSR clear_screen ;; Sets the screen color to black and white Mov_16 A_start, A_start + 1, #Screen_RAM Mov_16 length, length + 1, #<$03E8, #>$03E8 LDA #%11110000 - jsr memset + JSR memset ;; Disable maskeble interups (not all) SEI diff --git a/wip-hugo/program.lbl b/wip-hugo/program.lbl deleted file mode 100644 index 2cec8a4..0000000 --- a/wip-hugo/program.lbl +++ /dev/null @@ -1,168 +0,0 @@ -al 001444 .__BSS_LOAD__ -al 001444 .__BSS_RUN__ -al 000000 .__BSS_SIZE__ -al 000001 .__EXEHDR__ -al 000001 .__LOADADDR__ -al 000000 .__ZP_FILEOFFS__ -al 000002 .__ZP_LAST__ -al 0000FE .__ZP_SIZE__ -al 000002 .__ZP_START__ -al 001404 .big_y_offset -al 0013CE .binary_factor -al 0013C3 .log -al 0013BA .inverse_factor_value -al 0013B9 .for_i_end -al 0013B1 .R_pos -al 0013B5 .R_neg -al 0013A4 .for_i -al 00139A .div -al 001399 .endloop -al 00138C .loop -al 00138E .start -al 001387 .mult -al 001377 .change_length -al 001380 .y_overflow -al 001370 .loop -al 00136E .memcpy -al 00132F .big_set_end -al 001337 .small_set -al 001030 .big_set -al 001029 .memset -al 000FFF .move_data -al 000FD6 .calculate_screen_position -al 000FBC .calculate_petski_position -al 000FBC .char_draw -al 000FB3 .calc_byte_to_paint -al 000F95 .pixel_calc -al 000F90 .draw -al 000F88 .calc_byte_to_paint -al 000F6A .pixel_draw -al 000F68 .draw_lower_triangle -al 000F5C .draw_upper_triangle -al 000F45 .BC_overflow -al 000F5C .BC_overflow_end -al 000F28 .AB_overflow -al 000F3C .AB_overflow_end -al 000F1F .triangle -al 000F1E .end -al 000EF9 .qbb_y_overflow -al 000F15 .qbb_y_end -al 000EF3 .qbb_y -al 000ED9 .qdb_overflow -al 000EF3 .qdb_y_end -al 000ED5 .qdb_y -al 000EBB .qca_x_overflow -al 000ED5 .qca_x_end -al 000EB7 .qca_x -al 000E9D .qaa_x_overflow -al 000EB7 .qaa_x_end -al 000E99 .qaa_x -al 000E95 .change_x -al 000F15 .endif -al 000E95 .if -al 000E6C .qcb_x_overflow -al 000E87 .qcb_x_end -al 000E68 .qcb_x -al 000E4E .qdb_x_overflow -al 000E68 .qdb_x_end -al 000E4A .qdb_x -al 000E2E .qda_y_overflow -al 000E4A .qda_y_end -al 000E28 .qda_y -al 000E0E .qaa_y_underflow -al 000E28 .qaa_y_end -al 000E0A .qaa_y -al 000E08 .change_Y -al 000E00 .draw_qab -al 000DF8 .draw_qbb -al 000DF2 .draw_qdb -al 000DEA .draw_qcb -al 000DE4 .draw_qca -al 000DDC .draw_qda -al 000DD6 .draw_qba -al 000DCE .draw_qaa -al 000DCE .draw_pixels -al 000DCE .while_x_bigger_then_y -al 000DB4 .draw_right_px_in_circle -al 000D93 .draw_lower_px_in_circle -al 000D75 .draw_left_px_in_circle -al 000D57 .draw_upper_px_in_circle -al 000D4B .circle -al 000D2A .move_8px_left -al 000D26 .increment_pixel_x -al 000D1C .LOCALmMACRO_SYMBOLm002F -al 000D4A .end -al 000CFD .move_8px_up -al 000D0B .decrement_y_pos_end -al 000CFA .decrement_y_pos -al 000CF4 .for_y -al 000CDF .end_selfmod -al 000D1C .case_1 -al 000D3B .case_2 -al 000CCB .selfmod -al 000C90 .decrement_y_pos_end -al 000C7F .move_8px_up -al 000C7C .decrement_y_pos -al 000C72 .LOCALmMACRO_SYMBOLm0021 -al 000C9F .end -al 000C53 .move_8px_left -al 000C61 .increment_pixel_x_end -al 000C4F .increment_pixel_x -al 000C49 .for_x -al 000C35 .end_selfmod -al 000C72 .case_1 -al 000C90 .case_2 -al 000C21 .selfmod -al 000BD4 .move_8px_left -al 000BD0 .increment_pixel_x -al 000BC6 .LOCALmMACRO_SYMBOLm0017 -al 000BF5 .end -al 000BA7 .move_8px_down -al 000BB5 .increment_y_pos_end -al 000BA4 .increment_y_pos -al 000B9E .for_y -al 000B7D .end_selfmod -al 000BC6 .case_1 -al 000BE6 .case_2 -al 000B69 .selfmod -al 000B2E .decrement_y_pos_end -al 000B1D .move_8px_up -al 000B1A .decrement_y_pos -al 000B10 .LOCALmMACRO_SYMBOLm0009 -al 000B3D .end -al 000AF1 .move_8px_right -al 000AFF .decrement_pixel_x_end -al 000AED .decrement_pixel_x -al 000AE7 .for_x -al 000AC7 .end_selfmod -al 000B10 .case_1 -al 000B2E .case_2 -al 000AB3 .selfmod -al 000A88 .line_down -al 000B3E .line_down_inv -al 000A80 .steep_ -al 000A84 .shallow_ -al 000BF6 .line_up -al 000CA0 .line_up_inv -al 000A6E .steep -al 000A72 .shallow -al 000A68 .up -al 000A78 .down -al 000A5F .dx_no_underflow -al 000A54 .line -al 000A51 .exit -al 000A21 .end_test_y -al 000A15 .test_y -al 000A0B .end_test_x -al 0009FF .test_x -al 0009D0 .@loop -al 0009BE .long_line_test_b -al 0009A9 .clear_screen_ -al 000992 .@loop -al 000980 .long_line_test_a -al 00096B .clear_screen -al 000954 .@loop -al 0008FE .loop -al 0008C5 .loop -al 000897 .NMI_routine_end -al 000896 .NMI_routine diff --git a/wip-hugo/routines/circle/circle_test_position.s b/wip-hugo/routines/circle/circle_test_position.s index 1c3ea74..ffa296f 100644 --- a/wip-hugo/routines/circle/circle_test_position.s +++ b/wip-hugo/routines/circle/circle_test_position.s @@ -21,12 +21,8 @@ loop: ; DEY ; BNE delay_point - ;;clear screen - VIC_bank = $4000 - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset + + JSR clear_screen ;;move circle INC $AD diff --git a/wip-hugo/routines/circle/circle_test_size.s b/wip-hugo/routines/circle/circle_test_size.s index 02f901b..1c9093a 100644 --- a/wip-hugo/routines/circle/circle_test_size.s +++ b/wip-hugo/routines/circle/circle_test_size.s @@ -30,12 +30,7 @@ loop: LDA $AD STA radius - ;; clean the screen - VIC_bank = $4000 - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset + JSR clear_screen ;; draw the circle JSR circle diff --git a/wip-hugo/routines/line/line_test_extensive.s b/wip-hugo/routines/line/line_test_extensive.s index 4f79005..f24537c 100644 --- a/wip-hugo/routines/line/line_test_extensive.s +++ b/wip-hugo/routines/line/line_test_extensive.s @@ -34,14 +34,7 @@ CMP #$ff bne @loop -clear_screen: - ;;Lets clear bitmap - VIC_bank = $4000 - ;;Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset +jsr clear_screen long_line_test_a: LDA #$00 @@ -68,12 +61,7 @@ long_line_test_a: CMP #$ff BNE @loop -clear_screen_: - ;;Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset + jsr clear_screen long_line_test_b: LDA #$00 @@ -99,12 +87,7 @@ long_line_test_b: CMP #$ff BNE @loop -clear_screen__: - ;;Paint the bitmap black. More bitmap: https://www.c64-wiki.com/wiki/53272, https://www.c64-wiki.com/wiki/Screen_RAM#Moving_of_screen_RAM - Mov_16 A_start, A_start + 1, #VIC_bank - Mov_16 length, length + 1, #<$1f40, #>$1f40 - LDA #$00 - jsr memset +jsr clear_screen long_line_test_b_pos_end_swapped: LDA #$00 diff --git a/wip-hugo/routines/memory/memset_alt.s b/wip-hugo/routines/memory/memset_alt.s deleted file mode 100644 index b2c50b9..0000000 --- a/wip-hugo/routines/memory/memset_alt.s +++ /dev/null @@ -1,75 +0,0 @@ -;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- - -;; Sets memory in 'A'-registry to all addresses from 'A_start' until 'A_start' + 'length' -;; Modifies A, X and A_start -.proc memset - .include "mem.inc" - -;; big_set sets the memory in $ff chunks. -;; skipp if length >= $ff -LDX length +1 -BNE big_set -JMP small_set - -big_set: ;sets $ff of memory - ;; Y value do not matter, will go through all anyway! - .repeat $ff - STA (A_start), Y - DEY - .endrepeat - STA (A_start), Y ; dont forget Y =0 -big_set_end: - ;;set all hole $ff memory chunks! - INC A_start + 1 - DEX ;; length +1 -- - BEQ small_set - JMP big_set - - -small_set: - STA data_to_write - LDA length - STA length_copy - - ;; calculate rts-position - LDX #$00 - STX length + 1 - ;; 3 bytes = STA DEY NOP = seting 1 byte of memory. - ;; So we need to calculate: length*3 - Mult_16 A, length + 1 - ; A= length - ADC length_copy - TAY - LDA length + 1 - ADC #$00 - STA length + 1 - - ;; Now RTS_pointer + Y = length*3 + big_set_label - LDA #big_set - ADC length + 1 - STA RTS_pointer + 1 - - ;; read data we will change to RTS - STY Y_copy - LDA (RTS_pointer), Y - TAX - - ;; set RTS in big_set - LDA #$60 - STA (RTS_pointer), Y - - ;; JSR to modified big_set - LDY length_copy - DEY ; because we want to count to Y=0 :) - LDA data_to_write - JSR big_set - - ;; revert changes - LDY Y_copy - TXA - STA (RTS_pointer), Y - - RTS -.endproc diff --git a/wip-hugo/source.s b/wip-hugo/source.s index 59c0c30..33379cf 100644 --- a/wip-hugo/source.s +++ b/wip-hugo/source.s @@ -11,17 +11,17 @@ .include "STARTUP.s" ;.include "dubbel_buffer/raster_irqs.s" -;.include "routines/arithmatic/mult_test.s" -;.include "routines/arithmatic/div_test.s" -;.include "routines/circle/circle_test.s" -;.include "routines/circle/circle_test_size.s" -;.include "routines/circle/circle_test_position.s" -;.include "routines/line/line_test.s" +.include "routines/arithmatic/mult_test.s" +.include "routines/arithmatic/div_test.s" +.include "routines/circle/circle_test.s" +.include "routines/circle/circle_test_size.s" +.include "routines/circle/circle_test_position.s" +.include "routines/line/line_test.s" .include "routines/line/line_test_extensive.s" -;.include "routines/text/char_draw_test.s" -;.include "routines/pixel/pixel_test.s" -;.include "routines/memory/memcpy_test.s" -;.include "routines/memory/memset_test.s" +.include "routines/text/char_draw_test.s" +.include "routines/pixel/pixel_test.s" +.include "routines/memory/memcpy_test.s" +.include "routines/memory/memset_test.s" ;.include "routines/triangle/triangle_test.s" exit: @@ -34,7 +34,7 @@ JMP exit .include "routines/pixel/pixel_calc.s" .include "routines/text/char_draw.s" .include "routines/memory/memset.s" -;.include "routines/memory/clear_screen.s" +.include "routines/memory/clear_screen.s" .include "routines/memory/memcpy.s" .include "routines/arithmatic/mult.s" .include "routines/arithmatic/div.s" From 8eb5ff855b2e00dcfac19d354a7b1e8c26a5395a Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 19:42:57 +0200 Subject: [PATCH 5/6] fix most of by one errors of linedraw. --- wip-hugo/routines/line/line.s | 29 +++++++-------- wip-hugo/routines/line/line_down.s | 1 + wip-hugo/routines/line/line_down_inv.s | 1 + wip-hugo/routines/line/line_test_extensive.s | 39 ++++++++++++++++++-- wip-hugo/routines/line/line_up.s | 1 + wip-hugo/routines/line/line_up_inv.s | 1 + 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/wip-hugo/routines/line/line.s b/wip-hugo/routines/line/line.s index 9768771..89a50de 100644 --- a/wip-hugo/routines/line/line.s +++ b/wip-hugo/routines/line/line.s @@ -5,26 +5,24 @@ .include "line.inc" ;; Fix line that is too long - LDA Y_pos - CMP #$C8 ;;y_max = $C8 - BCC do_not_fix_y_pos - LDA #$C8 + LDA #$C8 ;y_max = $C8 + CMP Y_pos + BCS do_not_fix_y_pos STA Y_pos do_not_fix_y_pos: - LDA Y_end - CMP #$C8 ;;y_max = $C8 - BCC do_not_fix_y_end LDA #$C8 + CMP Y_pos ;y_max = $C8 + BCS do_not_fix_y_end STA Y_end do_not_fix_y_end: - ;;dx SEC LDA X_end SBC X_pos BCS dx_no_underflow;; X_end >= X_pos EOR #$ff ; Fix bit underflow + ADC #$01 STA dx ;; line_* expect X_pos < X_end and now its not the case. ;; Lets move them around @@ -36,28 +34,27 @@ do_not_fix_y_end: LDY Y_end STX Y_end STY Y_pos - - dx_no_underflow: STA dx + SEC - LDA Y_pos - SBC Y_end - STA dy - BCC down ;normal Y_pos < Y_end + LDA Y_end + SBC Y_pos + BCS down ;normal Y_pos < Y_end up:; Y_pos > Y_end + EOR #$ff ; Fix bit underflow + ADC #$01 STA dy + CMP dx BCC shallow; dy < dx steep: jsr line_up_inv RTS shallow: ;dy =< dx - lda dx jsr line_up RTS down: - EOR #$ff ; Fix bit underflow STA dy CMP dx BCC shallow_; dy < dx diff --git a/wip-hugo/routines/line/line_down.s b/wip-hugo/routines/line/line_down.s index b81a095..6641a0a 100644 --- a/wip-hugo/routines/line/line_down.s +++ b/wip-hugo/routines/line/line_down.s @@ -67,6 +67,7 @@ end_selfmod: STA byte_to_paint ;; X = X_end - X_pos LDX dx + INX ; okay if it overflow to $00 because it will go back to $ff in loop. Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00,! ;; Y has always a offset of at least 1 = C + $0000 INY for_x: diff --git a/wip-hugo/routines/line/line_down_inv.s b/wip-hugo/routines/line/line_down_inv.s index 465ffdf..4446379 100644 --- a/wip-hugo/routines/line/line_down_inv.s +++ b/wip-hugo/routines/line/line_down_inv.s @@ -55,6 +55,7 @@ end_selfmod: INY Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00, ! LDX dy + INX CLC for_y: ; C =0 LDA byte_to_paint diff --git a/wip-hugo/routines/line/line_test_extensive.s b/wip-hugo/routines/line/line_test_extensive.s index f24537c..8438af5 100644 --- a/wip-hugo/routines/line/line_test_extensive.s +++ b/wip-hugo/routines/line/line_test_extensive.s @@ -8,6 +8,8 @@ X_pos_ = $0E Y_end_ = $0F X_end_ = $0C + +full_angle_test: LDA #$d2 STA X_pos_ LDA #$62 @@ -36,14 +38,43 @@ jsr clear_screen +full_angle_test_pos_end_swapped: +LDA #$d2 +STA X_end_ +LDA #$62 +STA Y_end_ +LDA #$ff +STA X_pos_ +LDA #$0 +STA Y_pos_ + +;; Full angle test +@loop: +LDA Y_end_ +STA Y_end +LDA X_end_ +STA X_end +LDA X_pos_ +STA X_pos +LDA Y_pos_ +STA Y_pos + +jsr line +INC Y_pos_ +LDA Y_pos_ +CMP #$ff +bne @loop + +jsr clear_screen + long_line_test_a: - LDA #$00 + LDA #$01 STA X_pos_ LDA #$60 STA Y_pos_ LDA #$ff STA X_end_ - LDA #$0 + LDA #$00 STA Y_end_ @loop: LDA Y_pos_ @@ -64,7 +95,7 @@ long_line_test_a: jsr clear_screen long_line_test_b: - LDA #$00 + LDA #$01 STA X_pos_ LDA #$00 STA Y_pos_ @@ -90,7 +121,7 @@ long_line_test_b: jsr clear_screen long_line_test_b_pos_end_swapped: - LDA #$00 + LDA #$01 STA X_end_ LDA #$00 STA Y_end_ diff --git a/wip-hugo/routines/line/line_up.s b/wip-hugo/routines/line/line_up.s index 0edae87..24f1ae1 100644 --- a/wip-hugo/routines/line/line_up.s +++ b/wip-hugo/routines/line/line_up.s @@ -50,6 +50,7 @@ end_selfmod: ;LDY #$01 INY LDX dx + INX for_x: LDA byte_to_paint ORA (btp_mem_pos), Y diff --git a/wip-hugo/routines/line/line_up_inv.s b/wip-hugo/routines/line/line_up_inv.s index 5ad7940..a99b39b 100644 --- a/wip-hugo/routines/line/line_up_inv.s +++ b/wip-hugo/routines/line/line_up_inv.s @@ -52,6 +52,7 @@ end_selfmod: Sub_16 btp_mem_pos, btp_mem_pos + 1, #$00, #$00,! CLC LDX dy + INX for_y: LDA byte_to_paint ORA (btp_mem_pos), Y From fe21bdea3bc722d271d0821a7baea8fa548db138 Mon Sep 17 00:00:00 2001 From: hugova Date: Sat, 26 Jul 2025 19:55:25 +0200 Subject: [PATCH 6/6] fix off by one issue of line_up_inv.s --- wip-hugo/routines/line/line_up_inv.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wip-hugo/routines/line/line_up_inv.s b/wip-hugo/routines/line/line_up_inv.s index a99b39b..44719e8 100644 --- a/wip-hugo/routines/line/line_up_inv.s +++ b/wip-hugo/routines/line/line_up_inv.s @@ -34,7 +34,7 @@ STA D + 1 ;; because C flag is wrong value we let dy_2 be 1 to small - Sub_16 dy_2, dy_2 +1, #$01,#$00 + Sub_16 dx_2, dx_2 +1, #$01,#$00 selfmod: LDA dx_2