0 Members and 1 Guest are viewing this topic.
ld de,6 ; byte counter for lines, each 6 bytes next line ld ix,($89EA) ; get the location of file ld iy,$988A ; get location to write ld b, 156 ; counter initloop: ld a,(ix+0) ; get element of file ld hl,0 ; reset hl ld c,b ; backup b for second loop ld b,8 ; initialize second loopdouble: rrca ; get a bit of a in carry rr l ; shift that in l rr h ; shift also h sra l ; doublicate bit and shift once more rr h djnz -9 ; repeat "double" for each bit ld (iy+0),l ; write first half ld (iy+1),h ; second half ld (iy+12),l ; next line ld (iy+13),h dec e ; count one down (each 6 bytes there has to be a line skipped) jrnz 9 ; execute only if counter 0, otherwise jump to else ld de,12 add iy,de ; add 12 to skip next line ld e,6 ; reset counterelse: ld b,c ; get backup of main counter djnz -43 ; jump back to loop to repeat if counter finished
set textInverse,(IY+textFlags)
di ; mess with IY all you want ld IY,flags ei
I don't think you meant to do djnz -9. The assembler will try to send control to address $FFF7, and since djnz has only a 256-byte relative jump range, that can basically be anywhere in a 256-byte block surrounding the routine depending on where the routine is located.I think you meant to do djnz double. Same thing with the jr nz stuff. The assembler calculates the appropriate offset for you.
ld hl,($89EA) ; get the location of file ld ix,$988A ; get location to write ld bc, 26*256+6 ; row counter in B (26), column counter in C (6)outerloop: push bcinnerloop: ld e,(hl) ; get element of file ld b,8 ; initialize second loopdouble: rrc e ; get a bit of e in carry rr d ; shift that in d rra ; shift also a sra d ; duplicate bit and shift once more rra djnz double ; repeat "double" for each bit ld (ix+0),d ; write first half ld (ix+1),a ; second half ld (ix+12),d ; next line ld (ix+13),a inc hl ; next file byte inc ix ; next column inc ix ; next column dec c ; count one down (each 6 bytes there has to be a line skipped) jr nz,innerloop ld c,12 ;B is already 0, so BC=12 add ix,bc ; add 12 to skip next line pop bc ; restore row counter and column counter djnz outerloop
Btw, you don't need to subtract two extra bytes when you are jumping backwards, you just need to add the size of the instruction when jumping forward. At least not when assembling on a computer. I think if you were writing hex code, you'd be right (for relative jumps, at least), as a hex value of $00 would jump to the next instruction. However, the assembler starts at the start of the instruction (that is, at the first byte of the instruction), so jr $ would cause an infinite loop. Jr $-9 would jump to the instruction nine bytes before (in your case, the address held by the label double).EDIT: DeepThought: For djnz/jr, would a value like -9 really trip it up? I think you might end up jumping to the wrong place because the calculator calculates relative jumps differently from the assembler. Wouldn't the assembler just load $F7 (even if it gets interpreted as $FFF7, the assembler might truncate it down to $F7) after the djnz/jr byte (i don't know what the hex codes are), essentially jumping to $-7 (2 bytes after double, aka the 2nd byte of the "rr l"?
EDIT: DeepThought: For djnz/jr, would a value like -9 really trip it up? I think you might end up jumping to the wrong place because the calculator calculates relative jumps differently from the assembler. Wouldn't the assembler just load $F7 (even if it gets interpreted as $FFF7, the assembler might truncate it down to $F7) after the djnz/jr byte (i don't know what the hex codes are), essentially jumping to $-7 (2 bytes after double, aka the 2nd byte of the "rr l"?
Example: jr $1 would skip one byte. jr $-5 would jump to byte 3 before "jr". jr $-2 would make it stuck in an endless loop.
.org $9D95-2.db $BB,$6D ld HL, $+2
.org $9D95-2.db $BB,$6D ld HL, $2