nesdev.com https://forums.nesdev.com/ 

C/++ for the SNES https://forums.nesdev.com/viewtopic.php?f=12&t=12023 
Page 4 of 4 
Author:  psycopathicteen [ Wed Nov 26, 2014 10:32 am ] 
Post subject:  Re: C/++ for the SNES 
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 
Author:  tepples [ Wed Nov 26, 2014 11:06 am ] 
Post subject:  Re: C/++ for the SNES 
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.) 
Author:  Sik [ Wed Nov 26, 2014 11:23 am ] 
Post subject:  Re: C/++ for the SNES 
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. 
Author:  psycopathicteen [ Wed Nov 26, 2014 5:03 pm ] 
Post subject:  Re: C/++ for the SNES 
Those are pretty much the kinds of "hardcore optimizations" that games like Space Megaforce use. 
Page 4 of 4  All times are UTC  7 hours 
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ 