Optimal shifting for set pixel?
Hi,
I'm optimizing my set pixel code. For speed. But without using partitioned memory (i.e. a table on 256 byte boundary) I have optimal memory address position code and am now trying to optimize the shifting part.
Here's what I came up with so far.
Is there a more optimal approach to creating a mask for shifting then this?
T.
I'm optimizing my set pixel code. For speed. But without using partitioned memory (i.e. a table on 256 byte boundary) I have optimal memory address position code and am now trying to optimize the shifting part.
Here's what I came up with so far.
ld a,#x ; symbolic. a is x (0->255) and #7 ; remainder of division by 8 (0->7) inc a ; avoid special condition without shift / i.e. jr z ld b,a ; our shift counter xor a ; a=0 scf ; our shift bit loop: rra ; to a djnz loop ; until apropriate position
Is there a more optimal approach to creating a mask for shifting then this?
T.
Post edited by tstih on
Comments
Have a SET 0,(HL) instruction, and modify the last byte from C6 to be (C6 | (x&7)<<3), then execute that.
(disclaimer: haven't tried it)
Also, this could work:
ld (jump+1), a \ ld a, 1 \ jump: jr 0 \ rla \ rla \ rla \ rla \ rla \ rla \ rla
ld de,table and 7 add a,e ld e,a ld a,(de) ld (setn+1),a setn set 0,(hl) ret table defb #c6,#ce,#d6,#de,#e6,#ed,#d6,#deEdit: looking previous code, tablevalues might be incorrect
Edit2:
As mentioned above C6 and further are correct values.
When table at #nn00:
ld d,tablehighbyte and 7 ld e,a ld a,(de) ld (setn+1),a setn set 0,(hl) ret table defb #c6,#ce,#d6,#de,#e6,#ed,#d6,#deLike this?
- IONIAN-GAMES.com -
AND #7;
LD H, table/256; # locate table in such manner that L=0
LD L,A;
LD A,(HL);
table defb #80,#40,#20,#10,#08,#04,#02,#01;
It's untested, but you should get the idea.
easy way is fill 256 bytes with the same sequence, so code looks like:
If it weren't a passed value, we could do:
LD A,(bw+X);
bw:db #80,#40,#20,#10,#08,#04,#02,#01 ;32 times
routine by Busy:
;DE=Y.X PLOT PUSH HL,BC:LD H,HIGH PLOTTBL,L,D,B,(HL):INC H LD A,(HL),L,E:INC H:OR (HL) INC H:LD C,A,A,(BC) OR (HL):LD (BC),A POP BC,HL:RETof course, routine ain't optimized.to use plot some data must be prepared(1024 bytes):
PLOTTBL EQU #A000 call FORMER FORMER LD DE,#4000,BC,#8000,L,E FLP1 LD H,high PLOTTBL LD (HL),D:INC H:LD (HL),E:INC H LD (HL),C:INC H:LD (HL),B RRC B LD A,C:ADC A,0:LD C,A FBR1 INC D:LD A,D:AND 7 JR NZ,FNXT:LD A,E:ADD A,32 LD E,A:JR C,FNXT LD A,D:SUB 8:LD D,A FNXT INC L:JR NZ,FLP1 LD HL,PLOTTBL+#C0,BC,#3F LD DE,HL:INC E LD (HL),0:LDIR RET