| |
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 |
|
| |
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. |
| |
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 :) |
| |
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 |
| |
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
|
| |
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 |
| |
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
|
| |
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 |
| |
Fungus
Registered: Sep 2002 Posts: 686 |
lda tiletable,x
sta whereever
ora #$40
sta whereever
eor #$c0
sta whereever
ora #$40
sta whereever
etc...
|
| |
cbmeeks
Registered: Oct 2005 Posts: 78 |
Quote: <Post censored by CSDb staff>
lol.
Well, I'm the new kid in town so I will take Oswald's help with great appreciation. :-)
METROID
http://www.metroidclassic.com |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: lol.
Well, I'm the new kid in town so I will take Oswald's help with great appreciation. :-)
METROID
http://www.metroidclassic.com
Just for the record: "Oswald is NOT crappy coder"... |
| |
null Account closed
Registered: Jun 2006 Posts: 645 |
During daytime, Oswald is just a simple 6510 programmer.. but on CSDb, he transforms into...:
:_D :_D :_D
------------------------------------
Knoeki/DigitalSoundsSystem/GheyMaidInc/SwappersWithAttitude
http://hardwarehacks.untergrund.net/zomgwtfbbq/index.php |
| |
Richard
Registered: Dec 2001 Posts: 621 |
Lol, that picture still makes me laugh :)
|
| |
Conrad
Registered: Nov 2006 Posts: 849 |
|
| |
Richard
Registered: Dec 2001 Posts: 621 |
Nice one ;) |