A85: Matrices


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

A85: Matrices



Question, someone made this routine for me and it doesn't seem to work
correctly.  What is going on?

	ld b,0
	ld c,1
	CALL_(GetGamePiece)
	ld b,36                      ;Coordinates for sprite
	ld c,4
	CALL_(CheckPiece)            ;Didn't include it but its there
				     ;It starts getting the wrong piece
				     ;what is happening?


GetGamePiece:
	ld hl,GameBoard
	ld de,(PROGRAM_ADDR)
	add hl,de               ;hl has addr of game board
	ld a,0                  ;count for byte offset in map
	push af
	ld a,c
	cp 0                    ;if c is 0, don't do RowLoop
	pop af
	jr z,AddCol             ;just add in the column
	ld d,10                 ;the number of rows on the game board
RowLoop:
	add a,d                 ;add one more row to add to offset
	push af
	ld c,a
	dec a                   ;one less row
	cp 0
	pop af
	jr nz,RowLoop
AddCol:
	add a,b                 ;add the column number
	ld e,a                  ;\put offset in 16 bit 
	ld d,0                  ;/ register
	add hl,de               ;hl has addr of piece in map
	ld a,(hl)               ;a has the piece (0,1,2,3)
	ret
GameBoard:
	.db 00,01,00,01,00,01,00,01
	.db 01,00,01,00,01,00,01,00
	.db 00,01,00,01,00,01,00,01
	.db 03,00,03,00,03,00,03,00
	.db 00,03,00,03,00,03,00,03
	.db 02,00,02,00,02,00,02,00
	.db 00,02,00,02,00,02,00,02
	.db 02,00,02,00,02,00,02,00

Thanks
John


References: