Re: A82: Clearing part of GraphMem


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

Re: A82: Clearing part of GraphMem




> 
> ClearGraph:
>  ld b,64          ;do this 64 times 
>  ld hl,GRAPH_MEM  ;Copy from GRAPH_MEM
> loop:
>  push bc          ;save bc
>  ld (hl),0        ;Clear the bytes
>  ld h,d           ;Save to GRAPH_MEM
>  ld l,e           ;Save to GRAPH_MEM
>  ld bc,8          ;Copy first 8 pixels of line
>  ldir             ;do it
>  pop bc           ;restore bc
>  ld de,12         ;load 12 to de
>  add hl,de        ;add 12 to hl
>  djnz loop        ;repeat loop if not b=0 
>  ret              ;return
> 
The most obvious problem with this code is "ld h,d and ld l,e". The
following occurs on the first iteration of the loop, as a result:
-1st byte of GRAPH_MEM is set to 0
-hl=de
-ldir basically does nothing as hl and de point to the same location
-de=12
-hl=hl+12

Then it loops back:
-(hl)=0 (hl points to some unknown location, determined by the initial
value of de)
-hl=de=12
-ldir does nothing useful

This continues with the same,_useless_ location pointed to by hl getting
set to zero many times.

Assuming this is meant to be "ld d,h \ ld e,l", then , yes, your code will
work. But there is no point in ldir-ing 8 times. Infact, there is no point
in ldir-ing at all. You see, each pixel on the graphics screen is
represented by one _bit_ in GRAPH_MEM. Your code writes zero to the first
_byte_ in GRAPH_MEM (on the current line) and then proceeds to write (hl)
to (de) when they are exactly the same. There is no point in even using
de; apart from the "ld (hl),0", that block of code does essentially
nothing. Eliminating it also means not having to save bc, which gets rid
of 2 commands. After this "pruning", you're essentially left with the code
Adamman proposed (which _does_ work), except that his version will run a
tad faster because it only executes "ld de,12" once, instead of 64 times.
Also, unless you're call-ing that function, the "ret" command will most
likely take your calc somewhere it doesn't want to be..

Jwaz


References: