Coding Questions and other Quandaries
#61
Here's a better version of what I wrote up. I haven't tested this at all.

Uses C0 instead of C2.
Pin Config table (10 available configs) done as a Gecko String Write at 0x80001500.
Button Status byte still at 0x800003FF, and Pin Config tracker byte still at 0x800003FE

Here's the code, I left all the pin config blank (00's). Each pin config allows to edit the config of all 10 pins aka bytes. 10 x 10 = 100 total pins (bytes) to configure
06001500 00000064
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000
00000000 00000000 #Final word of null is NOT part of the pin config
C0000000 00000010
3C608071 A0038D40
7000XXXX 3C608000 #XXXX = button activator
40820010 38000000
980303FF 4E800020
880303FF 2C000001
4D820020 38000001
980303FF 88A303FE
38A50001 2805000A
41A00008 38A00000
98A303FE 1CA5000A
3D208126 612996B9
60631500 7C632A14
3863FFFF 3800000A
7C0903A6 8C030001
9C09057C 4200FFF8
4E800020 00000000

Sources:

06 Write ~
Code:
#Pin Config Table at EVA (06 Gecko String Write at 0x80001500)
#Config 1
.llong 0x0000000000000000
.short 0x0000
#Config 2
.llong 0x0000000000000000
.short 0x0000
#Config 3
.llong 0x0000000000000000
.short 0x0000
#Config 4
.llong 0x0000000000000000
.short 0x0000
#Config 5
.llong 0x0000000000000000
.short 0x0000
#Config 6
.llong 0x0000000000000000
.short 0x0000
#Config 7
.llong 0x0000000000000000
.short 0x0000
#Config 8
.llong 0x0000000000000000
.short 0x0000
#Config 9
.llong 0x0000000000000000
.short 0x0000
#Config 10
.llong 0x0000000000000000
.short 0x0000

And C0~
Code:
#Get button(s) pressed, check against desired activator
lis r3, 0x8071
lhz r0, 0xFFFF8D40 (r3)
andi. r0, r0, 0xXXXX #Your desired button(s)
lis r3, 0x8000 #Before taking the branch, set r3 to its new value, upper 16 bits of EVA
bne- button_has_been_pressed

#Nothing Pressed, Reset Button Status
li r0, 0
stb r0, 0x3FF (r3)
blr #End C0

#Button Pressed, Adjust Button Status
#0 = Not Pressed
#1 = Pressed
button_has_been_pressed:
lbz r0, 0x3FF (r3)
cmpwi r0, 1
beqlr- #End C0
li r0, 1
stb r0, 0x3FF (r3)

#Update Pin Config tracker
lbz r5, 0x03FE (r3)
addi r5, r5, 1

#Check if it exceeded max config allowed (10 configs allowed in this source currently - 0, 1, 2 .. .. 9)
cmplwi r5, 10 #Check if we went beyond 9
blt+ store_tracker
li r5, 0 #Reset tracker byte
store_tracker:
stb r5, 0x03FE (r3)

#Multiple Pin config tracker byte by 0xA (10)
#0 x A = 0
#1 x A = A (10) #First button press uses this button config because of earlier "addi r5, r5, 1"
#2 x A = 14 (20)
#etc etc
mulli r5, r5, 0xA

#Use it as a indexed offset to load correct pin config from pin config table located at 0x80001500
#But first set the initial loop store address (0x81269C35 minus 0x57C = 0x812696B9)
#Each pin config byte address is equally separated by 0x57C
lis r9, 0x8126
ori r9, r9, 0x96B9

#Set first load address
ori r3, r3, 0x1500 #Starting point 0x80001500
add r3, r3, r5 #Points to correct pin config in the EVA based on the index number recently calculated
subi r3, r3, 1

#Set loop amount (10 for 10 pins)
li r0, 10
mtctr r0

#Update the pin config!
pin_write_loop:
lbzu r0, 0x1 (r3)
stbu r0, 0x57C (r9)
bdnz+ pin_write_loop

#The End
#blr #Uncomment if not compiling with pyiiasmh, adjust compiled code accordingly

If you are going to test this, step thru it first.

Thread on C0 codetypes (includes how to debug/step them) - https://mariokartwii.com/showthread.php?tid=1156
Reply


Messages In This Thread
RE: Coding Questions and other Quandaries - by Vega - 12-23-2021, 02:46 PM

Forum Jump:


Users browsing this thread: 36 Guest(s)