[A83] Re: Tilemap/Displaying Pics/ Scrolling Screen


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

[A83] Re: Tilemap/Displaying Pics/ Scrolling Screen




>From: "Nick Palladino" <nickps1@hotmail.com>
>
>Okay, I new to assembly and need some help. I&#8217;ve seen some
>tutorials on tilemaps and stuff but they didn&#8217;t help. I want
>to know how to
>  1. Make and display a picture in assembly.
>  2. Make a tilemap to scroll.
>Can some one please send me some example code that includes
>a real scrolling tilemap that actually works. Thank You.
>
>P.S could the reply to this be in extensive detail so I don&#8217;t
>have to bug anyone else on how to do tilemaps.

Extensive detail? Here we go....

--------------------------------------------------
Chapter I Displaying your own pictures in assembly
--------------------------------------------------
________________
* example code *
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
.org progStart

	ld	hl,picture	; get the picture
	ld	de,8E29h	; is scrnBuf
	ld	bc,768		; is number bytes we have
	ldir			;   to copy (12*64)
	call	fastCopy	; copy scrnBuf to screen
	bcall(_getKey)		; wait for a key so we can
	ret			;   watch our picture
picture:
	.db $AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
	.db $55,$55,$55,$55,$55,$55,$55,$55,$55,$55,$55,$55
; ..64 lines in total..
	.db $AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
	.db $55,$55,$55,$55,$55,$55,$55,$55,$55,$55,$55,$55
.end
_______________
* explanation *
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Each pixel on the screen is represented by one bit. Set a bit and the pixel 
flashes on. Reset a bit and it goes out. So, to display a picture we first 
create a bit representation of that picture, copy that data to scrnBuf (or 
grphBuf or plotsscreen, whatever you call it) and then run a fastCopy 
routine which just copies the data in the scrnBuf to the screen. So, more in 
detail, in our case $AA (which is %10101010) would be pixel on, pixel off, 
pixel on, pixel off, pixel on, pixel off, pixel on, pixel off. If you 
replace $AA by $FF (is %11111111) you get a full line, and if you replace 
$AA by ... you get ... etc.

--------------------------------------------------
Chapter II Displaying a tilemap
--------------------------------------------------

(I wrote the tilemap routine myself. You may use it of course)
________________
* example code *
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
.org progStart

	ld	hl,tilemap	; HL -> tilemap
	ld	de,tiles	; DE -> tiles
	call	drawTileMap	; draw the tilemap in scrnBuf
	call	fastCopy	; copy scrnBuf to screen
	bcall(_getKey)		; wait for a key so we can
	ret			;   watch our picture

drawTileMap:
	push	hl
	pop	ix
	ld	hl,8E29h
	ld	bc,8*256+12
drawTileMapLoop:
	push	bc
	ld	b,c
drawLineLoop:
	push	bc
	push	de
	push	hl
	ld	h,0
	ld	l,(ix)
	inc	ix
	add	hl,hl
	add	hl,hl
	add	hl,hl
	add	hl,de
	ex	de,hl
	pop	hl
	ld	b,8
drawTileLoop:
	ld	a,(de)
	ld	(hl),a
	inc	de
	ld	a,b
	ld	b,0
	add	hl,bc
	ld	b,a
	djnz	drawTileLoop
	ld	de,-(8*12)+1
	add	hl,de
	pop	de
	pop	bc
	djnz	drawLineLoop
	ld	c,7*12
	add	hl,bc
	pop	bc
	djnz	drawTileMapLoop
	ret

tilemap:
	.db	0,1,0,2,0,1,0,2,0,1,0,2
	.db	1,0,2,0,1,0,2,0,1,0,2,0
	.db	0,1,0,2,0,1,0,2,0,1,0,2
	.db	1,0,2,0,1,0,2,0,1,0,2,0
	.db	0,1,0,2,0,1,0,2,0,1,0,2
	.db	1,0,2,0,1,0,2,0,1,0,2,0
	.db	0,1,0,2,0,1,0,2,0,1,0,2
	.db	1,0,2,0,1,0,2,0,1,0,2,0
tiles:
	.db	0,0,0,0,0,0,0,0

	.db	00000000b
	.db	00011100b
	.db	00111110b
	.db	01101011b
	.db	01111111b
	.db	01011101b
	.db	00100010b
	.db	00011100b

	.db	00000000b
	.db	00011100b
	.db	00111110b
	.db	01101011b
	.db	01111111b
	.db	01100011b
	.db	00111110b
	.db	00011100b

.end
_______________
* explanation *
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
The tilemap routine uses HL and DE as input. HL must point to the tilemap 
itself and DE to the tiles you want to use. Then the tilemap routine scans 
the whole tilemap. For each byte it draws that tile, but keep in mind that 
it starts with 0. So 2 means it takes the 3th tile and so on. And so it 
fills the whole screen. This tilemap routine draws 8*8 tiles, so the tilemap 
itself must be 12*8 to fit on a 96*64 screen.

===================================================================

I know you're desparate to know scrolling and smooth scrolling, but if you 
already understand this I think you should be capable of understanding a 
tutorial about that.

Hope this helps you a lot already,

	Tijl Cosemans

_________________________________________________________________
Download MSN Explorer gratis van http://explorer.msn.nl/intl.asp