Compare commits

...
Sign in to create a new pull request.

6 commits

Author SHA1 Message Date
hugova
fe21bdea3b fix off by one issue of line_up_inv.s 2025-07-26 19:55:25 +02:00
hugova
8eb5ff855b fix most of by one errors of linedraw. 2025-07-26 19:42:57 +02:00
hugova
185f37dccc make use of new clear_screen macro. 2025-07-26 15:55:57 +02:00
hugova
0f9db52148 write a specific memset only for clearing screen, so we can make it faster! 2025-07-26 15:54:47 +02:00
hugova
ef22e5a2ff use faster memset algoritm. 2025-07-26 14:50:23 +02:00
hugova
7f136b9ed2 fix up the build / compile stuff 2025-07-26 14:48:46 +02:00
16 changed files with 193 additions and 355 deletions

View file

@ -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, #>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, #>Screen_RAM
Mov_16 length, length + 1, #<$03E8, #>$03E8
LDA #%11110000
jsr memset
JSR memset
;; Disable maskeble interups (not all)
SEI

View file

@ -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

View file

@ -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

View file

@ -21,12 +21,8 @@ loop:
; DEY
; BNE delay_point
;;clear screen
VIC_bank = $4000
Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00
jsr memset
JSR clear_screen
;;move circle
INC $AD

View file

@ -30,12 +30,7 @@ loop:
LDA $AD
STA radius
;; clean the screen
VIC_bank = $4000
Mov_16 A_start, A_start + 1, #<VIC_bank, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00
jsr memset
JSR clear_screen
;; draw the circle
JSR circle

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -8,6 +8,8 @@
X_pos_ = $0E
Y_end_ = $0F
X_end_ = $0C
full_angle_test:
LDA #$d2
STA X_pos_
LDA #$62
@ -34,23 +36,45 @@
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, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00
jsr memset
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_
@ -68,15 +92,10 @@ 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, #>VIC_bank
Mov_16 length, length + 1, #<$1f40, #>$1f40
LDA #$00
jsr memset
jsr clear_screen
long_line_test_b:
LDA #$00
LDA #$01
STA X_pos_
LDA #$00
STA Y_pos_
@ -99,15 +118,10 @@ 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, #>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
LDA #$01
STA X_end_
LDA #$00
STA Y_end_

View file

@ -50,6 +50,7 @@ end_selfmod:
;LDY #$01
INY
LDX dx
INX
for_x:
LDA byte_to_paint
ORA (btp_mem_pos), Y

View file

@ -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
@ -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

View file

@ -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, #>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 #<length_
JSR big_set
STX big_set + low_length_3
RTS
.endproc

118
wip-hugo/routines/memory/memset.s Executable file → Normal file
View file

@ -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
STA RTS_pointer ; cy = 3
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

View file

@ -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
STA RTS_pointer
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

View file

@ -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 &>/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 &>/dev/null &

View file

@ -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:
@ -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"