Re: A86: Need Help! Level Maps!


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

Re: A86: Need Help! Level Maps!



I've attached a really bad example of a tilemap program that I wrote my
first week while learning asm (it is really bad!).  But it does display a
map to the screen, nonetheless.

At 07:36 PM 8/5/98 PDT, you wrote:
>
>Anyone help me. I need a Map reader to read a 8x16 Level Map. Depending 
>on if each bit of the map is on or off I need it to display either a 
>grass sprite or a Block sprite. These are 8x8 sprites. BIOSERRORS helped 
>me but he didn't give me an example of how to use the map reader to 
>display sprites. Anyone who helps me will get MAJOR credit for the game. 
>Your Name WILL be on the Title Screen. Please help! All I need is the 
>level reader that puts sprites to the screen. I have one by BIOSERRORS 
>that I can use to see If a block's in front of you. PLEASE HELP!
>
>InFuZeD at Zone TI - "Making Basic Programming Worth While"
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>
; 
; MAP v1.0 by David Phillips <electrum@tfs.net>
; program started: 04/29/98
; last update    : 04/30/98
;

#include "ti86asm.inc"
#include "asm86.h"

.org _asm_exec_ram


MainLoop:
	call _clrLCD				; clear the display screen
	call BUSY_OFF				; turn off the busy indicator (we're not a BASIC program ;-)
	

DrawMap:
	ld bc,$0800					; there are 8 lines up and down -- loop for all Y lines
	ld hl,Map					; hl points to our map
CopyY:
	push bc						; save bc, the Y counter, so we can draw the X lines
	ld c,b						; C is the Y line we are on
	ld b,16						; now we draw all of the X lines -- 16 of them
CopyX:	
	push bc						; save bc, the X coutner, because we need it to hold where we want the sprite to go
	push hl						; save the pointer to our map
	ld d,b						; D saves B so we can swap B and C for our X & Y coords
	ld a,8						; we are drawing bottom to top, but the map is read top to bottom
	sub c						; subtract from number of lines up & down to get the top to bottom number
	ld b,a						; since sub stores the result in A, load it into B -- we just swapped it with C
	ld a,16						; just like above, drawing right to left, but map is left to right
	sub d						; we use D, where we saved B, since we already swapped C into it
	ld c,a						; store the result into C -- we just swapped B and C
	push bc						; save bc, because we'll trash our new location by using B for looping
	ld b,(hl)					; load in the sprite we want to draw from the map
	inc b						; increase B by one, since the map starts at 0, and we need it to start at 1
	ld de,8						; load in the size of sprites (8 x 8 bits), so 8 bytes
	ld hl,Sprite0-8				; a sprite of 0 will be added once even though it's correct, so back up by one sprite
MapLoop:
	add hl,de					; add the size of a sprite to get the current right one
	djnz MapLoop				; loop until we are at the correct sprite
	pop bc						; restore the location to draw at
	ld d,h						; copy hl, the sprite pointer, to de
	ld e,l						; de is the pointer to the sprite
	call GridPutSprite			; call the sprite routine
	pop hl						; restore the pointer to the map -- sprite drawing trashed it
	inc hl						; move to the next map square

	pop bc						; restore the X loop counter
	djnz CopyX					; draw all of the sprites for this row
	pop bc						; restore the Y loop counter
	djnz CopyY					; draw all of the columns of X rows
	

	call Pause					; let them see it
	call _clrLCD				; clear the screen before exit
	ret							; return to TI-OS or a shell


;-------------------------------------------------------------------------
; Input:
; C = X	 [0,15]				Note:  it's in a 16 x 8 grid
; B = Y	 [0,8]
; DE = pointer to sprite 
;-------------------------------------------------------------------------
GridPutSprite:
	push de					; save pointer to sprite
	ld hl,$fb80				; point to video mem - 128 bytes (grid size)
	inc b					; add one to the Y coord
	ld de,$80				; number of bytes per line in grid
YCoord:
	add hl,de				; add one more line to it
	djnz YCoord				; move to the right line determined by Y
	add hl,bc				; add the offset of the sprite to video mem
	pop de					; we need the pointer for the sprite back
	ld b,8					; our sprites are 8 lines high, do 8 lines
CopySprite:
	push bc					; save the offset of video memory
	ld a,(de)				; load in the next byte of the sprite
	ld (hl),a				; copy it to video memory
	inc de					; move to next byte of the sprite
	ld bc,16				; we need to move to next display line
	add hl,bc				; actually move down one physical line
	pop bc					; we need the offset in video memory again
	djnz CopySprite			; copy all 8 lines
	ret						; we're all done
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
Pause:
	call GET_KEY			; wait for a key to be pressed
	cp K_EXIT				; is it exit?
	jr z,pausequit			; then jump to exit the program
	cp K_ENTER				; was it enter?
	jr nz,Pause				; if it wasn't, jump to wait for another
	ret						; return, since it had to be
pausequit:
	pop hl					; since we were CALLed and not RETing, we
	       					; have to pop the call address off the stack
							; or the next RET will return to that address
	call _clrLCD			; clear the screen before exit
	ret						; return to TI-OS or a shell
;-------------------------------------------------------------------------



Map:
    .db $2,$2,$1,$3,$3,$3,$2,$3,$0,$2,$1,$3,$0,$0,$1,$3
    .db $1,$3,$1,$2,$2,$2,$3,$3,$3,$2,$3,$1,$2,$0,$0,$1
    .db $2,$2,$3,$3,$2,$1,$1,$0,$0,$0,$1,$3,$3,$2,$1,$3
    .db $2,$2,$1,$0,$0,$3,$2,$2,$2,$3,$1,$1,$3,$3,$3,$2
    .db $2,$3,$0,$1,$1,$2,$2,$2,$2,$0,$2,$2,$0,$1,$1,$2
    .db $3,$2,$1,$0,$0,$3,$3,$1,$0,$1,$0,$1,$1,$0,$3,$1
    .db $2,$3,$0,$1,$2,$3,$2,$1,$2,$3,$2,$1,$2,$2,$3,$0
    .db $1,$2,$1,$2,$0,$2,$0,$1,$0,$2,$2,$1,$1,$2,$3,$3

Sprite0:
	.db %00000000
	.db %00010000
	.db %00000001
	.db %00100000
	.db %00001000
	.db %00100000
	.db %00000001
	.db %01000000

Sprite1:
	.db %00000000
	.db %00010000
	.db %00101000
	.db %00100100
	.db %01000010
	.db %01000010
	.db %01111110
	.db %00000000

Sprite2:
	.db %00000000
	.db %00111100
	.db %01111110
	.db %00111100
	.db %00011000
	.db %00011000
	.db %00011000
	.db %00000000

Sprite3:
	.db %01000001
	.db %10101010
	.db %00010100
	.db %00000000
	.db %10100010
	.db %01010101
	.db %00001000
	.db %01000001


.end


--
David Phillips
mailto:electrum@tfs.net
ICQ: 13811951
AOL/AIM: electrum32

References: