Re: A85: TI-H: asm


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

Re: A85: TI-H: asm




>ok...i am trying my best to learn how to program in assembly using
>zshell...right now i am a little stuck though...will someone please
explain to
>me how and why these routines (from the zshell school) actually work (word
for
>word).
>


It's actually pretty simple.


>PLOTTING PIXELS
>
>Here are four routines for putting a pixel, removing a pixel, changing a
>pixel, and checking to see if a pixel is lit.
>
>     PutPixel: ; Puts a pixel at B,C
>      ROM_CALL(FIND_PIXEL)	
>      ld de,$FC00
>      add hl,de
>      or (hl)
>      ld (hl),a
>      ret

This first command finds the video location of the pixel.  But it isnt the
complete location, just the number of bytes from the start (FC00).  So you
add them together to get the absolute ram address.  Also, a is loaded with
the number of the bit^2 (you square the bit #).  This is better than the
actual bit number, because you cannot do set a, (hl).  So to get around
that, you have to first OR a (which is for example 00010000) with the
address in hl (which is the actual pixels like 11111111 is all on, and
00000000 is all off) so this, no matter what, lights the pixel.  Like ORing
0000 with 0100 yields 0100, and 1111 with 0100 yields 1111.  Then, because
the result is stored in the accumulator (the a register), you have to load
the a register into the address at hl!



>
>     RemovePixel: ; Removes a pixel at B,C
>      ROM_CALL(FIND_PIXEL)
>      ld de,$FC00
>      add hl,de
>      cpl
>      and (hl)
>      ld (hl),a
>      ret
>


This time, the a register is complemented (which means that if a was
00010000, it now becomes 11101111), and then is AND with the video location
at hl (which means that if a was 11101111 and the video at hl was 10111111,
the result would be 10101111, because for a pixel to be lit with the AND
command, both must be lit).  Then, because the result is stored in a, you
load a into the video address (hl).




>     ChangePixel: ; Changes the pixel at B,C
>      ROM_CALL(FIND_PIXEL)
>      ld de,$FC00
>      add hl,de
>      xor (hl)
>      ld (hl),a
>      ret


(Here is the XOR table)
------------------------
|  a  	|  hl  |Result|
------------------------
|  0	|  0	|  0	|
|  0	|  1	|  1	|
|  1	|  0	|  1	|
|  1	|  1	|  0	|
----------------------

This XORs a with (hl) (if a is 00010000 and (hl) is 11111111 the result is
11101111, and if (hl) is 00000000, the result is 00010000).  Then, becuase
the result is stored in the accumulator, a is loaded into (hl).



>     TestPixel: ; Tests the pixel at B,C. If the Z flag is set, no pixel,
else
>a pixel is lit
>      ROM_CALL(FIND_PIXEL)
>      ld de,$FC00
>      add hl,de
>      and (hl)
>      ret
>


Now the accumulator is ANDed with (hl) (which means that if a is 00010000
and (hl) is 11111111, the result is 00010000 with the zero flag not set,
but if a is 00010000 and (hl) is 00000000, the result is 00000000 which
sets the zero flag!

Need anymore help?  Just ask!
------------------
felix@megsinet.net


References: