RE: LZ: Question with programming
[Prev][Next][Index][Thread]
RE: LZ: Question with programming
On Tue, 10 Dec 1996 21:44:39 -0500,
Ryan Myers wrote...
>I am thinking of using a matrix-style level system for a new game...
>
>This is the code I figured would do the job; could anyone inform if this
>would work, as I just broke my link yesterday by popping off the cable,
and
>I don't have time lately between school and work to make a new one yet.
>
>My thanks in advance.
>
>-----------------------------BEGIN
>SNIPPET------------------------------------
>
>The Matrix would be like this:
>
>Matrix1:
> .db 6, 6, 6, 6, 6, 6
> .db 6, 6, 6, 6, 6, 6
> ...
> .db 6, 6, 6, 6, 6, 6
>
>For a total of 12 rows of 6 wide, containing values 0, 1, 2, 3, 4, 5, or
6.
>
>This would be the code to retrieve a value at row x, column y - assuming
>that
>the first value in the matrix is row 0 col 0 and the last row 11 col 5.
>Row
>is given in B and Column in A.
>
>GetValue:
> mul b, 6
> add a, b
> ld hl, a
> add hl, Matrix1
> ld a, (hl)
> ret
>
There is no multiplication instruction in assembly language. Your
instruction mul b, 6 is invalid and will not work. To do any
multiplication you must use a routine which shifts the multiplier to the
right, tests the carry bit. If the carry bit is set, you add the
multiplicand to your result (at this point, zero) then shift the
multiplicand one to the left. Then you repeat until you are done with your
eight bits.
Also, there is no ld hl, a command in Z80 assembly. a is an eight bit
register, while hl is a sixteen bit register, and you cannot load an eight
bit register into a sixteen bit register. The closest you could come is to
load a into l (make sure h is zero), then add that to Matrix1, then add the
program offset, THEN you would have the address of the byte you wanted to
load from.
Sorry to say it doesn't work, but...well, it doesn't!
When you write programs, you may wish to check forsome commands in a Z80
istruction set to be sure they exist.
Michael Wyman - SeaHorse Software
wyma0012@gold.tc.umn.edu
Follow-Ups: