psycopathicteen wrote:
Did SNES carts typically have more data in them than PCE carts?
Off topic, but does writing slow code really save time? What if code becomes so sloppy that it slows down development, and the only way to clean it up is by optimizing it?
Pretty much, in most cases LOADS of time. Lets take a really simple example.
Given I have 7 sprites and I want to set their x,y and image ptr. Let imaging that it makes a square box, like a dialog or something. The dumb way of doing this would be something like
Code:
lda #136
sta $d000
lda #120
sta $d001
lda #160
sta $d002
lda #120
sta $d003
lda #136
sta $d004
lda #141
sta $d005
lda #160
sta $d006
lda #141
sta $d007
lda #80
sta 2040
lda #81
sta 2041
lda #82
sta 2042
lda #83
sta 2043
Which is code you can write straight off the top of your head, you don't really need to think about it. However it is really bad code. To which I now have to sit and think about a couple of options. 1 all of the addresses are in a line, so I could just use ,x but that eats more CPU time, do I need this code to be clock fast, am I in a VBlank for example... Maybe since there are shared values it would be not to much room to just unroll the loop with the values... well lets have a stab at the ,x method. looking at the code there is a two groups, the D0XX and the 204X so let make a couple of loops, first lets make sure that X doesn't hold an important value I want to preserve, or find a better place where I don't care about X before I trash it
Code:
ldx #7
- lda SpriteXYs,x
sta $d000,x
dex
bpl -
ldx #3
- lda SpritePtrs,x
sta 2040,x
dex
bpl-
SpriteXYs .byte 136,120,160,120,136,141,160,141
SpriteData .byte 80,81,82,83
Much nicer, less to type, but I had to scroll through the code to find a place to park the data, but still, two loop is a bit odd right, I mean it could be 3x4 so lets fix the code
Code:
ldx #3
- lda SpriteXYs,x
sta $d000,x
lda SpriteXYs+4,x
sta $d004,x
lda SpriteData,x
sta 2040,x
dex
bpl -
SpriteXYs .byte 136,120,160,120,136,141,160,141
SpriteData .byte 80,81,82,83
well if I don't need Y, I can get rid of the SpriteData, nah for 4 its not worth it, maybe if I was setting all 8 it would be..
This is all well and good but we are in a production house and we use macros because they are awesome and setting a sprite is something we do
a lot so we have a
Code:
setSprite .macro
lda #\2
sta $d000+(\1*2)
lda #\3
sta $d001+(\1*2)
lda #\4
sta 2040+\1
.endm
so the first code becomes
Code:
#setSprite(0,136,120,80)
#setSprite(1,160,120,81)
#setSprite(2,136,141,82)
#setSprite(3,160,141,83)
which was a lot faster to type than anything above. And it also doesn't have a giant wall of code for you to scroll past and go hmmm that is a lot of code, I should fix it...
Now lets imagine for a second that the artists decided to put a small flourish in the bottom right corner of the dialogue box, but the flourish goes above the sprites top pixel, but as there was room left below the normal line they put the flourish all one sprite as it was easier for them to visualise it, so now the bottom right sprite needs to be moved up 4 pixels so everything lines back up again. Go through the examples above and make the modification you need to make in your head and then tell me which one was the fastest for you to understand, see and modify what needed to be done?
Now imagine you moved the DB address on the 65816 and then when something else fired it didn't handle having the DB pointer moved on it, and it randomly crashed, and the lead programmer had to spend 2 days and $1000 in wages trying to hunt down the bug and fix it, for 20 clocks
but if you used the slower long absolute it wouldn't have happened.