A85: The hands down way to do Matrixes


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

A85: The hands down way to do Matrixes



Here it is, first, you have to decide which of two ways you want to do your
matrixes:

1) The changes you do to them will not matter after you exit the program
or
2) The changes are saved

--------- #1 ----------

okay, have your matrix down here, at the end of your program.

.db 43,2,4,1,3,5,...
.db (so on)

and define three constants:

XSIZE		=	25		; or whatever
YSIZE		=	25		; or whatever
TOTSIZE	= 	XSIZE * YSIZE ; total # of bytes in matrix

Now, before you do anything you have got to do this:

-- usgard --
	ld	hl, &matrix  
	ld	de, TEXT_MEM2
	ld	bc, TOTSIZE
	ldir
-- zshell --
	ld	hl, matrix
	ld	de, (PROGRAM_ADDR)
	add	hl, de
	ld	de, TEXT_MEM2
	ld	bc, TOTSIZE
	ldir

Alrighty, now your matrix will be in TEXT_MEM2.  Now, you may ask, how do
we get a piece?  To load the value of a piece, do this:

	ld	h, YSIZE
	ld	l, (ypos)	; where (ypos) is where you stored the y position
				; of which piece to get
	call	MUL_HL		; this will work for usgard, otherwise you have
				; to get a compatable multiplication routine that
				; multiples H by L and stores into HL, look on
				; ticalc.org.
	ld	a, (xpos)
	ld	d, 0
	ld	e, a
	
	add	hl, de

	ld	de, TEXT_MEM2

	add	hl, de

	ld	a, (hl)

A now has the piece value of that.  To STORE, do this:

	push	af
	ld	h, YSIZE
	ld	l, (ypos)	; where (ypos) is where you stored the y position
				; of which piece to get
	call	MUL_HL		; this will work for usgard, otherwise you have
				; to get a compatable multiplication routine that
				; multiples H by L and stores into HL, look on
				; ticalc.org.
	ld	a, (xpos)
	ld	d, 0
	ld	e, a
	
	add	hl, de

	ld	de, TEXT_MEM2

	add	hl, de

	pop	af

	ld	(hl), a

There you go.  If you use this method and not number 2, you should look
into using Huffman compression on your data to make it smaller.

---- #2 ----

Do exactly the same as above, except at the end of your program, do this:

-- usgard --
	ld	de, &matrix  
	ld	hl, TEXT_MEM2
	ld	bc, TOTSIZE
	ldir
-- zshell --
	ld	hl, matrix
	ld	de, (PROGRAM_ADDR)
	add	hl, de
	ld	de, TEXT_MEM2
	ex	hl, de
	ld	bc, TOTSIZE
	ldir

That's it.  Be sure you make ZShell / USGARD recalculate the checksum if
you use the 2nd method.  Also, there may be a couple ways to optimize this
better if you use usgard.

---
Evil Jim
Viva La Mexico
<eviljim@writeme.com>
http://members.tripod.com/~eviljim/
I want to die in my sleep like my Grandfather, not screaming in pain like
the passengers in my car...