Undefinied3's SMW Blog: Potency Routine

Welcome!


Welcome!

Yes, a new blog! Here I'll keep you informed about SMW related things. I'll post videos, images, information, tools, sprites, ASM codes, etc. I hope you enjoy it.

Friday, February 18, 2011

Potency Routine

Yep, nobody had ever done it, so I did it :D It's a quite simples routine, since the SMW's multiplication registers do everything.. If you're interessed, here is the routine:



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Potency routine ($02-$03 will hand the result)
;$00 must be the Base and $01 the Exponent
;Note: the result it's a 16 bits value.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Potency:
DEC $01 ;\Fix the
DEC $01 ;/Exponent
LDA $00 ;\$02 will be
STA $02 ;/the "second" base
LDX $01 ;Set up Loop
.LoopForIToExponentDo
LDA $00 ;\The "real" base
STA $4202 ;/Set at the multiply register A
LDA $02 ;\The "second" base
STA $4203 ;/Set at the multiply register B
NOP #8 ;Waste cycles. We need time to the multiplication works
LDA $4216 ;\Hand the result
STA $02 ;/Store first digit
LDA $4217 ;\Hand the result
STA $03 ;/Store second digit
DEX ;Decremet exponent/Loop
BPL .LoopForIToExponentDo ;If the loop doesn't end, return
RTS ;Finally, end...



If you dont understand, do this:


LDA #$Base
STA $00
LDA #$Exponent
STA $01
JSR Potency
REP #$30
LDA $02
*Random Code*
SEP #$30


Or even this:


LDA #$Base
STA $00
LDA #$Exponent
STA $01
JSR Potency
LDA $02
*Random Code*
LDA $03
*Another Random Code*



I don't know why you should use this, but well... Do whatever you want, but just keep in mind that this routine doesn't work correctly with the Hex2Dec one, cause it has only 3 digits, and can't be higher than 255, and since my routine gives a 16 bits result, you would need to edit somethings in the Hex2Dec routine to works correctly.

No comments:

Post a Comment