[TI ASM] Drawing maps

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Guest

[TI ASM] Drawing maps

Post by Guest »

:arrow: I have a question about drawing maps:

I want to draw a map which should consist of 24 16x16 sprites; 1 for a black and 0 for a white sprite. (of course i will use other sprites)

Code: Select all

Map:
 .db 1,1,1,1,1,1
 .db 1,0,0,0,0,1
 .db 1,0,0,0,0,1
 .db 1,1,1,1,1,1
How to do that?
How to put that on the screen?
It should take a number of the Mapcode and then it should draw a sprite on the graph...
Thx,
NanoWar
Duck
Sir Posts-A-Lot
Posts: 231
Joined: Sat 18 Dec, 2004 3:38 am

Post by Duck »

Drawing a complete tilemap is done by two nested for-loops.
In case of a tilemap that does not get bigger then the screen:
screenX: calculated X location of sprite
screenY: calculated Y location of sprite
spriteLocation: calculated tile position in memory
map: your tilemap position
This is a _very_ basic idea of how a simple tilemap drawer could be written:

Code: Select all

for (Y=0 to mapheight-1)
  for (X=0 to mapwidth-1)
    current_tile_value = value_at(map + mapwidth*Y + X)
    spriteLocation = current_tilemap_location + 8*current_tile_value
    screenX = 8*X
    screenY = 8*Y
    drawSprite(screenX, screenY, spriteLocation)
  next X
next Y
I'm not going into details here, after reading "ASM in 28 days" you're definatly able to write the ASM code yourself.
Good luck!
User avatar
NanoWar
Extreme Poster
Posts: 365
Joined: Fri 17 Dec, 2004 6:39 pm
Location: #$&"%§!
Contact:

Post by NanoWar »

Hmm... :? Yes it works... Thx...
NanoWar
Revolution Software
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

well i have used java before and i totally understand that, but i cant get a for statement to be used. ie it says that unreconized etc.

could someone post a site which will explain map rotines or post some sample code?
thanks
in z80 im tring to do it in
koolmansam375
Extreme Poster
Posts: 479
Joined: Fri 17 Dec, 2004 11:09 pm
Contact:

Post by koolmansam375 »

kalan_vod wrote:well i have used java before and i totally understand that, but i cant get a for statement to be used. ie it says that unreconized etc.

could someone post a site which will explain map rotines or post some sample code?
thanks
in z80 im tring to do it in
are you trying to use an exact copy of what Duck posted? Thats not z80 or java, its VB

in z80 there is no "for" statement but you create the same effect with "djnz loop" where b is set to however many times you want it to loop
Image

Pongwars shall live!

blog is down atm. :-(
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

ok thats what i thought that there is no for in z80, could you show me an ex.?
koolmansam375
Extreme Poster
Posts: 479
Joined: Fri 17 Dec, 2004 11:09 pm
Contact:

Post by koolmansam375 »

here. a djnz loop

Code: Select all

    ld b,100
loop:
    djnz loop
is eqiuvalent to

Code: Select all

    ld b,100
loop:
    dec b
    jr nz,loop
which in C/++ is this for loop

Code: Select all

for (int b=100;b>0;b--);
[/code]
Image

Pongwars shall live!

blog is down atm. :-(
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Dwedit made pretty good one that sould work in a lot of situations.
http://joepnet.com/hosted/maxcoderz/php ... light=#901
Though, it's not good to learn from, it's pretty complicated. It took me few minutes to figure what it was doing, quite ingenius though.


That whole thread contains some examples mapping.
Though you should really try to code it yourself for the expierence. What duck posted, Even if you don't know VB, should give you idea of what to do.
Image
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

well i had this

Code: Select all

start:
	ld a,(a_pos)
	inc a
        ld l,a
	ld a,(b_pos)
        inc a
	ld b,8
	ld ix,ground
	call ionPutSprite
	call ionFastCopy
	jr start
just to see if i was doing it right and it as you could probally tell it would just display on and off
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Well, yeah aside from blinking endlessly that seems fine. :D

Though I would name a_pos and b_pos something better. that way you don't get confused with the x and y.
Image
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

it was just to test :P, but whats a good way to increase by like

inc a 8 times or is there a better way?
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Uhhh... have you read this?
http://dragon-fire.org/Asmin28/lesson/toc.html

To increase by 8 would be add a,8.
Image
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

Dwedit is a damn genius, he has made so many great things. I would like to see a calcwbsine interview on him.

Also it is a good idea to get a decent grasp of z80 asm and the calcs general structure (memory, how the lcd is accessed etc) before diving into such things as tilemaps and sprite routines. It honestly makes it a whole lot easier.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
DarkAuron
Maxcoderz Staff
Posts: 1349
Joined: Sat 18 Dec, 2004 6:53 pm

Post by DarkAuron »

Might be easier if you learn how to move a sprite the screen first, then you'd learn how to connect the visual aspect with the code.
[Gridwars Score] - E: 1860037 M: 716641 H: 261194
koolmansam375
Extreme Poster
Posts: 479
Joined: Fri 17 Dec, 2004 11:09 pm
Contact:

Post by koolmansam375 »

heres my attemp at a tilemapper. it doesnt work in the flash debugger and i think im not handling the stack correctly :/

d is the ycor and e is the xcor

Code: Select all

drawmap:
        ld   hl,tilemapdata      ;pointer to map data
        push hl
        ld   de,0       ;the top left of the screen
        ld   b,7                   ;7 tiles per row
        push bc
xloop:
	push bc
	ld a,(hl)
	add a,a
	add a,a
	add a,a  ;x8
	push de
	ld d,0
	ld e,a
	ld ix,sprites
	add ix,de
	ld l,d
	ld a,e
	ld b,8
	push de
	push hl
	call ionPutSprite
	pop hl             ;restore map position
	inc hl             ;increase the map pointer
	pop de
	inc e
	pop bc
	djnz xloop         ;display next column if it needs to


	inc d
	ld e,0
	pop bc
	pop hl
	push de
	ld de,19
	add hl,de
	pop de
	djnz xloop
	
	call ionFastCopy   ;display the results
Image

Pongwars shall live!

blog is down atm. :-(
Post Reply