Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > [gamedev] Reading level data problem
2005-10-03 18:43
BastetFurry

Registered: Jul 2005
Posts: 88
[gamedev] Reading level data problem

Hi Folks!

I try to code something in asm, and as i like them its going to be a simple RPG.
But now i have a little problem, how to read the map data?
I have this, hardcoded for now, testdungeon in my programm:
party: ;X first and then Y
!byte $01,$02

dungeon1: ;16x16 grid of map data
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$01,$01,$01,$00,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$01,$00,$01,$00,$01,$00,$01,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$01,$00,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$01,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

As i am used to do high level programming, i cant figure out how to get something from there with the party coordinates.
I hope somebody can give at least a hint how to get an address out of x and y.

2005-10-03 18:59
Oswald

Registered: Apr 2002
Posts: 5027
hi, just do this:

mul16

.word 0
.word 16
.word 32
.
.
.
.word 16*16

lda y
asl
tay
lda mul16,y
sta $fe
lda mul16+1,y
sta $ff

; read map data here:

ldy x
lda ($fe),y


(it is possible to do this faster, but for a general routine this is the way)
2005-10-03 19:27
JackAsser

Registered: Jun 2002
Posts: 1990
Don't forget to add base address of the map...

Basically address to read from = leveldata+x+y*16. And as Oswald mentioned y*16 can be looked up from a mul16 table easily.

But then you might wanna consider this: Imagine you already know what address you are on, say in the middle (16*8+8), then if you move left you simply decrease it, if you move right you increase it, if you move up you subtract 16 and if you move down you add 16, instead of always recalculating it everytime.
2005-10-03 21:05
Ben
Account closed

Registered: Feb 2003
Posts: 163
Hmm.. I would do this the simple way:

lda y
asl
asl
asl
asl
clc
adc x
tax
lda table,x
2005-10-03 21:05
BastetFurry

Registered: Jul 2005
Posts: 88
Thanks both of you, it works like a charm ^.^
I could even adapt it to draw chars to the screen for me.
2005-10-03 21:06
BastetFurry

Registered: Jul 2005
Posts: 88
Quote: Hmm.. I would do this the simple way:

lda y
asl
asl
asl
asl
clc
adc x
tax
lda table,x


If you could please explain that to me?
I understanded the first one, but that is a bit cryptic for me :-/
2005-10-03 21:06
Ben
Account closed

Registered: Feb 2003
Posts: 163
Quote: Thanks both of you, it works like a charm ^.^
I could even adapt it to draw chars to the screen for me.


I see we cross-posted.. Just ignore me then ;)
2005-10-03 21:10
Ben
Account closed

Registered: Feb 2003
Posts: 163
Quote: If you could please explain that to me?
I understanded the first one, but that is a bit cryptic for me :-/


lda y
asl
asl
asl
asl

would yield y*16 in the accumulator

clc
adc x

would yield y*16+x in the accumulator
and now use this as offset in your table :)

tax
lda table,x


This works as 16*16 = 256 obviously :)
If you start using larger tables you would indeed need to resort to Oswald's method or some other variations of my snippet ;)

2005-10-03 22:55
BastetFurry

Registered: Jul 2005
Posts: 88
This is it so far, i think not bad for the first real (somewhat) usefull ASM. (The other things where testing and "basic research" ;) )

http://fileanchor.com/4547-d

You are in the center und move around with Joy2.

Ill try to catch some sleep now, any suggestions are welcome.
(Dont disassemble or you will be shocked by my horrible code. I think i will better never attend a 4k ;) )
2005-10-07 17:05
Honesty

Registered: Jan 2003
Posts: 117
Nah... For coding counts in the end thaT it worx and do what it should do how i look like is equal to my opinion...

There are many ways leading to rome...

2005-10-08 12:15
Ben
Account closed

Registered: Feb 2003
Posts: 163
Quote: Nah... For coding counts in the end thaT it worx and do what it should do how i look like is equal to my opinion...

There are many ways leading to rome...



If the operational specifications of 'doing' also includes executing in the minimum number of cycles then these 5 cycles being won (under equal conditions) do make a difference clearly..
 
... 19 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
t0m3000/HF^BOOM!^IBX
csabanw
Flexman
Bacchus/FairLight
Airwolf/F4CG
chancer
Knut Clausen/SHAPE/F..
Jetboy/Elysium
pby/HF/Acrise
Guests online: 117
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 Layers  (9.7)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Performers  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.4)
2 Magic  (9.4)
3 hedning  (9.2)
4 Elwix  (9.1)
5 A Life in Hell  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.21 sec.