0 Members and 1 Guest are viewing this topic.
dec a jr nz, AWasnt1
ld b, a djnz AWasnt1
ld a, (hl) dec a jr nz, not1 ... jr finalnot1: dec a jr nz, not2 ... jr finalnot2: dec a jr nz, not3 ... jr finalnot3: dec a jr nz, not4 ... jr finalnot4: ...final:
ld b, (hl) djnz not1 ...not1: djnz not2 ...not2: djnz not3 ...not3: djnz not4 ...not4: djnz not5 ...not5:final:
;######################################;plot a byte;a = byte;b = inverse 1 = yes, 0 = no;de = xyplotAByte: ld c, d ld d, 0 ld h, d ld l, e add hl, de add hl, de add hl, hl add hl, hl srl c srl c srl c ld e, c add hl, de ld de, plotSScreen add hl, de djnz inversing or (hl) ld (hl), a retinversing: cpl and (hl) ld (hl), a ret
pop hl ld ix, op1+1 ld bc, 8*256+6 ld d, 8 xor aunpackNameLoop: rr (hl) rra djnz notNextUnpackByte inc hl ld b, 8notNextUnpackByte: dec c jr nz, unpackNameLoop ld c, 6 rra rra ld (ix), a inc ix xor a dec d jr nz, unpackNameLoop
Why not replace it with this, which is both faster and smaller (you don't need the jumps if you can leave b at 0):Code: [Select] ld b, (hl) djnz not1 ...not1: djnz not2 ...not2: djnz not3 ...not3: djnz not4 ...not4: djnz not5 ...not5:final:
DJNZ * decrements B. If B is not 0, it pretends to be a jr. If B is 0, the code continues. This is mostly used for loops because it uses only 2 bytes, so * is usually negative. Because of this, people seem to forget that you can jump forward with this. :P
I think the best DJNZ is to ONLY use DJNZ I was reading about Single Instruction Set Computers and learned that using only DJNZ you can produce a turring complete language!