Re: A82: How do the good programmers do it?


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

Re: A82: How do the good programmers do it?



ilya winham <ilyamojo@geocities.com> writes:
>
>So if I wanted to store 1 into (3,4) I would:
>  ld A,1
>  ld (Matrixone + 12 + 4 ),A  (<--you can use +'s like this?? doesn't 
>seem right?)

Okay...well, so we don't confuse each other, let's agree on something.
Here's your matrix:


	COL	     0,1,2,3	ROW
Matrixone:	.db 0,0,0,0	-0
		.db 0,0,0,0	-1
		.db 0,0,0,0	-2
		.db 0,0,0,0	-3

Hopefully that is aligned correctly for you. So your matrix location
(3,4) would actually be (2,3). Understand? It's easier to think of it
this way, trust me. Your code:
	 ld (Matrixone + 12 + 4 ),A
would access location (3,?). 'Cause 12 is 3 * 4  (ROW is 3) and 4...well,
you're off the matrix. Heh. Simply calling Matrixone is accessing (0,0)
so the column is either 0,1,2, or 3. Got it? 
	Z80 Programming Law: 0 is 1
Heh. ;) Yes, you can use +'s like that. 


>So If I wanted to read (3,4) I would:
>
>  ld A, (Matrixone + 12 +3 )

Okay, according to the diagram above, your code would access (3,3), not
(3,4). Understand?

>> Logic:
>>         ld (Matrixone + [ROW*4] + [COL] ), A
>>         or A
>>         jr z, Label
>
>I don't understand what this logic stuff does.  I need something to 
>see if the number is a 0,1,2,3 etc..

Just use the compare command and then make a conditional jump. Example:
(this checks if matrix location (2,1) is 4.

	ld A, (Matrixone + (1*4) + 0)
	cp 4
	jr z, Label

You don't need the multiplication or the 0 in there, but so you know the
thinking behind accessing the location, I put them in. The compare
command (CP) takes the number you specify (in this case, 4) and subtracts
it from the A register. The flags are updated and you make a conditional
jump. If the result of the subtraction is negative, the carry flag is
set. You can then use 2 conditional jumps for an if statement that checks
to see if the value is within a particular range. Still confused? Keep
asking.
	
		-Scoobie


Follow-Ups: References: