Re: Line drawing algorithm
Posted: Wed Dec 18, 2024 2:31 am
Hello,
I know my search for a quick Linde drawing code is a bit boring for some people. Nevertheless, I would like to share my latest optimization with you.
In the routine for creating the jumps in the main routine, I was able to get a small speed advantage by adjusting the BCS jump. It depends on whether the main direction of the line runs in X or Y. The routine then either jumps straight to the Y set point instruction or the X direction is recalculated.
The initialization routine starts at $2153 and the main line drawing routine at $0010.
Approximately 23-24,000 pixels per second are now drawn on a screen of 144x192 points.
The pixels per second are determined by the largest delta x or delta y and are counted per run.
(I used $59 for the counter, but i see, that it is possible to use $1B.)
The total is then displayed every second and then set to zero.
Hit Enter/Return to clear the screen.
If we have a screen with 128x192 points, up to 26,000 pixels per second are possible.
If you dont like to put the core line drawing routine to the ZP, you can modify the attached one easily.
On a 144x192 pixel screen, you have up to 22,000 pixels the second in a routine without the heavy ZP usage.
Are further optimizations possible in this small routine?
Best regards
Sven
The Zero page code:
I know my search for a quick Linde drawing code is a bit boring for some people. Nevertheless, I would like to share my latest optimization with you.
In the routine for creating the jumps in the main routine, I was able to get a small speed advantage by adjusting the BCS jump. It depends on whether the main direction of the line runs in X or Y. The routine then either jumps straight to the Y set point instruction or the X direction is recalculated.
The initialization routine starts at $2153 and the main line drawing routine at $0010.
Approximately 23-24,000 pixels per second are now drawn on a screen of 144x192 points.
The pixels per second are determined by the largest delta x or delta y and are counted per run.
(I used $59 for the counter, but i see, that it is possible to use $1B.)
The total is then displayed every second and then set to zero.
Hit Enter/Return to clear the screen.
If we have a screen with 128x192 points, up to 26,000 pixels per second are possible.
If you dont like to put the core line drawing routine to the ZP, you can modify the attached one easily.
On a 144x192 pixel screen, you have up to 22,000 pixels the second in a routine without the heavy ZP usage.
Are further optimizations possible in this small routine?
Best regards
Sven
Code: Select all
draw_line:
SEC ;
LDX #$E8 ; INX
LDA X2 ; X2
SBC X1 ; X1
; X2 - X1
BCS X3C0F ;
;
LDX #$CA ; DEX
EOR #$FF ;
ADC #$01 ;
X3C0F:
STX $10 ; INX or DEX
STX $1C ;
STA $13 ;
SEC ;
LDY #$C8 ; INY
LDA Y2 ; Y1
SBC Y1 ; Y0
BCS X3C22 ;
;
LDY #$88 ; DEY
EOR #$FF ;
ADC #$01 ;
X3C22:
STY $06 ; INY or DEY
STA $04 ;
LDX X1 ;
LDY Y1 ;
LDA $13 ;
CMP $04 ;
BCS X3C52 ;
;
STA $15 ;
LDA $06 ;
STA $10 ;
LDA $04 ;
STA $59 ; count pixels can deleted
STA $1B ; count pixels can used
LSR A ;
STA $13 ;
LDA #$C0 ; CPY
STA $35 ;
LDA Y2 ;
STA $36 ;
lda #$13 ; change jump in BCS
sta $19 ;
LDA lowb,X ; load first low byte
JMP $0026 ;
;
X3C52:
STA $59 ; count pixels can deleted
STA $1B ; count pixels can used
LSR A ;
STA $13 ;
LDA $04 ;
STA $15 ;
LDA $06 ;
STA $1C ;
LDA #$E0 ; CPX
STA $35 ;
LDA X2 ;
STA $36 ;
lda #$05 ; change jump in BCS
sta $19 ;
LDA lowb,X ; load first low byte
JMP $0026
Code: Select all
X3C74:
DEY
SEC
LDA #$00
X3C78:
SBC #$0A
STA $13
BCS X3C81
X3C7C:
ADC #$33
X3C7E:
DEX
X3C7F:
STA $13
X3C81:
LDA lowb,X
cmp Pixel_Low
beq nextstep
STA Pixel_low
LDA highb,X
STA Pixel_High
nextstep:
LDA $0000,Y
ORA xTable,X
STA (Pixel_low),Y
X3C92:
CPY #$1B
BNE X3C74
;RTS
jmp endline