It is currently Sun Nov 19, 2017 1:00 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject: Re: C/++ for the SNES
PostPosted: Wed Nov 26, 2014 10:32 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2359
Most programmers write code like this when transitioning from 68k to 65xx:

Code:

lda $00      ;; add $01 to $00
clc
adc $01
sta $00

lda $00      ;; add $02 to $00
clc
adc $02
sta $00

lda $1000    ;; move $1000 to the $03 so it can run faster
sta $03

lda $03      ;; add $00 to $03
clc
adc $00
sta $03

lda $03
sta $1000    ;; move $03 back to $1000


Top
 Profile  
 
 Post subject: Re: C/++ for the SNES
PostPosted: Wed Nov 26, 2014 11:06 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19229
Location: NE Indiana, USA (NTSC)
To teach a smug 68000 weenie how to make a 6502 scream, you might have to show him a few peephole optimizations one at a time.

Remove loads after stores:
Code:
lda $00
clc
adc $01
sta $00      ;; remove lda $00 after store
clc
adc $02
sta $00
lda $1000    ;; move $1000 to the $03 so it can run faster
sta $03      ;; remove lda $03 after store
clc
adc $00
sta $03
sta $1000


Remove stores whose value is provably unused:
Code:
lda $00
clc
adc $01
clc          ;; remove unused sta $00
adc $02
sta $00
lda $1000
clc
adc $00
sta $03
sta $1000


Addition of this type is commutative:
Code:
lda $00
clc
adc $01
clc
adc $02
sta $00
lda $00      ;; group accesses to same address
clc
adc $1000
sta $03
sta $1000


Which allows removing another load after store:
Code:
lda $00
clc
adc $01
clc
adc $02
sta $00      ;; remove lda $00 after store
clc
adc $1000
sta $03
sta $1000


Thus this section of code is provably equivalent yet small enough for repeating unused store analysis with $00 and $03 in the rest of the snippet. If it turns out they're not needed, you end up with perfectly idiomatic 6502 assembly:
Code:
lda $00
clc
adc $01
clc
adc $02      ;; remove unused sta $00
clc
adc $1000    ;; remove unused sta $03
sta $1000


You already know all this, but the process illustrated in this example might help someone else adapt to the 6502. Each step might produce its own "Oh!" moment.

(And now this is used as an example on wiki.superfamicom.org.)


Top
 Profile  
 
 Post subject: Re: C/++ for the SNES
PostPosted: Wed Nov 26, 2014 11:23 am 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
If you want to make a 68000 programmer suffer, go with Z80 instead. Not too few registers to result in a mentality change, but not enough registers to be comfortable. Enjoy watching how heavily that stack gets hammered.


Top
 Profile  
 
 Post subject: Re: C/++ for the SNES
PostPosted: Wed Nov 26, 2014 5:03 pm 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2359
Those are pretty much the kinds of "hardcore optimizations" that games like Space Megaforce use.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group