0 Members and 3 Guests are viewing this topic.
ld hl,plotSScreen ld bc,768Loop: ld (hl),0 inc hl dec bc;test if bc=0 ld a,b or c jr nz,Loop ret
;alter the above code, saving 2300 t-states ld hl,plotSScreen ld bc,300h ;300h = 768. So C=0, B=3 ld a,cLoop: 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,cLoop: 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
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
ld hl,plotSScreen ld (hl),0 ld de,plotSScreen+1 ld bc,767 ldir ret;13 bytes, 16152 t-states
EmptyBuffer: LD BC,768 LD A,0 LD HL, plotsscreenBufferLoop: LD (HL),A INC HL DEC BC CP C JR NZ, BufferLoop CP B JR NZ, BufferLoop B_CALL _GrBufCpy ret
clearGbuf: ld b,64 ;7t - clear 64 rows ld (saveSP),sp ;20t - save the SP with SMC ld hl,0 ;10t - we're going to push hl, so it will push two 0's wherever the stack is pointing (the gbuf) ld sp,plotSScreen+767 :10t - remember, the stack works backwards, so start at the end of gbufclearLoop: push hl ;11t - 2 each push clears 2 bytes push hl ;11t - 4 push hl ;11t - 6 push hl ;11t - 8 push hl ;11t - 10 push hl ;11t - 12 erase one row djnz clearLoop ;13/8t - repeat 63 timessaveSP = $+1 ld sp,$0000 ;10t - restore sp (the $0000 will get overwritten with SMC) ret