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 > Make this faster??
2007-09-26 17:00
cbmeeks

Registered: Oct 2005
Posts: 78
Make this faster??

I'm at work doing some paper coding (using a pen and paper) and was wondering if this snippet could be made faster.

What it does is grab the left side of a 2x2 char tile and blit it on the screen.

IE:

AB
CD

This would grab "AC" because my data is laid out like: "ACBD"


LDA #1     // tile number
ROL        // multiply by 4 to get the starting addr
TAX
LDA (TILES),X
STA SCREEN
INX         // get the next char
LDA (TILES),X
STA SCREEN + 40



Thanks for any tips!
cbmeeks

METROID
http://www.metroidclassic.com
2007-09-26 17:04
doynax
Account closed

Registered: Oct 2004
Posts: 212
Quote: I'm at work doing some paper coding (using a pen and paper) and was wondering if this snippet could be made faster.

What it does is grab the left side of a 2x2 char tile and blit it on the screen.

IE:

AB
CD

This would grab "AC" because my data is laid out like: "ACBD"


LDA #1     // tile number
ROL        // multiply by 4 to get the starting addr
TAX
LDA (TILES),X
STA SCREEN
INX         // get the next char
LDA (TILES),X
STA SCREEN + 40



Thanks for any tips!
cbmeeks

METROID
http://www.metroidclassic.com


Why not simply store each of the for sub-tiles in a separate (byte-indexed) array?
For the most part you should prefer SoA (structure of arrays) layouts on the 6502.
2007-09-26 17:05
cadaver

Registered: Feb 2002
Posts: 1160
Drawing new stuff on edges of screen rarely needs to be super-optimized, because the screen-copy (shifting the screen data one char to whatever direction) still takes much much more time.

If you plan to scroll by always redrawing the whole screenful of blocks, it'll be too slow.

Of course you still need a redraw routine for the case when the game starts or the player teleports, but that doesn't need to be mega-optimal then, as doesn't happen every frame :)
2007-09-26 17:08
cbmeeks

Registered: Oct 2005
Posts: 78
Right now I am playing with data layout.

It is broken down like this:

World Map contains ROOMS.
Rooms contain tiles.
Tiles contain chars.

So the world map would be like:

R1R1R1R2
R2 R3

...

R1 would contain tiles:
01 02 01 01 03 ....

And each tile would contain chars:
01 -> AB
CD

etc..

As I am scrolling left, I will need to blit a new column containing the left side of the tile (AB).

I also want to optimize this for scrolling UP/DOWN by storing the tiles in ABCD.

Hope that makes sense. I am trying for the smallest number of cycles possible.

Unless I am just missing the big picture??

Thanks

METROID
http://www.metroidclassic.com
2007-09-26 17:08
Oswald

Registered: Apr 2002
Posts: 5094
- rol does only multiply with 2
- use 2 asl instead as rol will put the c bit into the least significant bit
- what cadaver and doynax said
2007-09-26 17:11
cbmeeks

Registered: Oct 2005
Posts: 78
Quote: - rol does only multiply with 2
- use 2 asl instead as rol will put the c bit into the least significant bit
- what cadaver and doynax said


Dur...oh yeah. lol

as far as not optimizing a single column, I guess that is a good point. I know the screen copy is going to be 99.9999% of the CPU hog when scrolling. That is why I was trying to have a great routine for drawing the tiles. Remember the tiles will be mixed and I will only ever be drawing a half-tile at any time.

METROID
http://www.metroidclassic.com
2007-09-26 17:15
Oswald

Registered: Apr 2002
Posts: 5094
optimizing your tile array layout will give you:

one tile:

tiletable1|tiletable2
----------+----------
tiletable3|tiletable4

code:

ldx tilenumber
lda tiletable1,x
sta wherever
lda tiletable2,x
sta wherever
lda tiletable3,x
sta wherever
lda tiletable4,x
sta wherever

some extremely good tutorials on game coding (go to rants):

http://cadaver.homeftp.net/

edit:

only one column from the tile at a time naturally:

ldx tilenumber
lda tiletable1,x
sta wherever
lda tiletable3,x
sta wherever
2007-09-26 17:29
cbmeeks

Registered: Oct 2005
Posts: 78
Quote: optimizing your tile array layout will give you:

one tile:

tiletable1|tiletable2
----------+----------
tiletable3|tiletable4

code:

ldx tilenumber
lda tiletable1,x
sta wherever
lda tiletable2,x
sta wherever
lda tiletable3,x
sta wherever
lda tiletable4,x
sta wherever

some extremely good tutorials on game coding (go to rants):

http://cadaver.homeftp.net/

edit:

only one column from the tile at a time naturally:

ldx tilenumber
lda tiletable1,x
sta wherever
lda tiletable3,x
sta wherever


Arg!! You see, that's why I asked. That is a simple, obvious idea but my feeble mind didn't think of it. Kinda like the Pet Rock. lol

Thanks!

I will draft something up in that fashion.


METROID
http://www.metroidclassic.com
 
... 7 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - 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
E$G/HF ⭐ 7
MaD ][/Starship
Guests online: 111
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Antitrack  (9.8)
3 OTD  (9.8)
4 Fungus  (9.8)
5 S!R  (9.8)

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