Re: LZ-Adv: Clearing up some TI-82 confusion.


[Prev][Next][Index][Thread]

Re: LZ-Adv: Clearing up some TI-82 confusion.



[SNIP]


>GetScreenAddr:
> ld bc,0
> ld hl,0
> ld a,(YCoord)
> ld l,a
> add hl,hl
> add hl,hl
> add hl,hl
> add hl,hl
> add hl,hl
> add hl,hl
> add hl,hl
> ld a,(XCoord)
> ld c,a
> add hl,bc
> ld bc,VIDEO_MEM
> add hl,bc
> ret
>
>Oh boy, actual CODE!  Basically, it converts an X and a Y coordinate
>pointing to part of a pseudo-16x8 array into their screen equivalent. 
See
>all those "add hl,hl" things?  (Keep in mind that this is pre-beta and I
may
>turn this into a repeating loop.)  Basically, it takes the Y coordinate
(a
>value from 0 to 7) and multiplies it by 128, then adds the X coordinate
(a
>value from 0 to 15).  128 is equal to 16*8; in other words, 16 bytes per
row
>* 8 rows per picture (my pictures are 1 byte by one byte).  Numbers like
128
>are very nice, you see, because they can be represented by a power of 2
and
>therefore a number of SLAs (or in this case, add hl,hl because you can't
SLA
>a 16-bit double register).  With 12 bytes per row rather than a nice
smooth
>16, however, the TI-82 would not be able to chug my lovely code (12*8 =
96 =
>a number between 2^6 and 2^7).  I might end up having to HARDCODE the
>information!  Horrors!  Hardcoding is NOT my friend.  Tight little
>algorithms are my friends.  Those and the talking ponies.




Try this on the TI-82.


ADD HL,HL  ;
ADD HL,HL  ;
ADD HL,HL  ;
ADD HL,HL  ;
ADD HL,HL  ; 32 x HL -> HL


LD  HL,DE  ; 32 x HL -> DE


ADD HL,HL  ; 64 x HL -> HL
ADD HL,DE  ; (32 x HL) + (64 x HL) -> HL


Because 32 x HL + 64 x HL = 96 HL.


Also, this is only one byte more than your 7 ADD HL,HLs in the TI-85
version!


Jason "Thursday" Wenger
jwenger@juno.com
Illegitimi no carborundum


References: