;alter the above code, saving 2300 t-states
ld hl,plotSScreen
ld bc,300h ;300h = 768. So C=0, B=3
ld a,c
Loop:
ld (hl),a ;1 byte, 7 cycles, compared to 'ld (hl),0' which is 2 bytes, 10 cycles
inc hl
dec bc
;test if bc=0
ld a,b
or c
jr nz,Loop
ret
;alter the above code to replace everything after 'inc hl'
;saves 7675 t-states, so 9975 t-states saved in all so far. Also a few bytes smaller.
ld hl,plotSScreen
ld bc,300h ;300h = 768. So C=0, B=3
ld a,c
Loop:
ld (hl),a
cpi ;not using it for its inteaded use. Still, increments HL, decrements BC, checks if BC is 0
jp pe,Loop
ret
;25378 t-states, 14 bytes
Here is a different approach:
ld hl,plotSScreen
ld bc,3 ;768 = 300h, but here we load 3 into C, 0 in B
sub a ;set A=0, more optimised than 'ld a,0'
Loop:
ld (hl),a
inc hl
djnz Loop
dec c
jr nz,Loop
ret
;15 bytes, 19789 t-states