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
#62
Ok, now I have time to check this out.

Looks interesting.

BTW, my code with less writes was No Bueno.

1) I was doing using exact value conditionals with a changing number.

2) I also found it is necessary to write all ten pins or there are bugs when the pins are swept away and reset. with the code activated and #1 fixed.

Updated with > < conditionals, and the values of the conditionals to adjust for pin placement lag.

Seems to work pretty good.

The way you are proposing is more what I had in mind.

Besides, this could open up doors to other modes of gameplay. Random pins????.......
Reply
#63
(12-24-2021, 08:13 PM)Hackwiz Wrote: Besides, this could open up doors to other modes of gameplay. Random pins????.......

That would be neat. Random pins (considering we're just differentiating between 1's and 0's) would be easy to implement a function for. Could use what's called the Time Base, or write your own RNG.
Reply
#64
Winner winner chicken dinner!
Works fine in Dolphin.

06001500 00000064
01010101 01010101
01010000 00010001
01010001 00000001
00010100 00010000
00010001 00000001
00000001 00010100
00000001 00000000
00010001 00000100
00000100 01000000
00010001 00000000
00000000 00000100
01000101 01000000
01000001 00000000
C0000000 00000010
3C608071 A0038D40
70001000 3C608000
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
E0000000 80008000

Will check it out on the Wii.
Nice piece of work.
Now to dissect what you did.

Very cool indeed.

Had to add another pin configuration for 10x10=100
Only had nine configs.
Reply
#65
Mine does have 10 configs, the source clearly shows that. And on the compiled code there's 12 1/2 words of null. 12 1/2 words converted to bytes is 100.

Either way, I'm surprised it works. My usual rough draft sources always have some blunder present somewhere. I have a tendency of making silly mistakes Tongue

For making random pins, a simple way would be using the Time Base. Since we need ten pin configs and the pin value as a byte can only be 0x00 or 0x01, we can use a stream of 10 bits for the random pin sequence. We'll use the least significant (far right) 10 bits of the time base. It's random 'enough' to get the job done.

Here's the code and source where you update the pin config based on the typical button activator like the last source.

C0000000 0000000D
3C608071 A0038D40
7000XXXX 3C608000 #XXXX = button activator
40820010 38000000
980303FF 4E800020
880303FF 2C000001
4D820020 38000001
980303FF 7C0C42E6
700003FF 3C608126
606396B9 38A0000A
7CA903A6 5400083C
5400F87E 540507FE
9CA3057C 4200FFF4
4E800020 00000000

Source:
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)

#Grab Timebase Lower 32bits
mftbl r0

#Leave only the right side 10 bits for the pin config
andi. r0, r0, 0x03FF

#Setup Loop 1st time store address for stbu
lis r3, 0x8126 #(0x81269C35 minus 0x57C = 0x812696B9)
ori r3, r3, 0x96B9

#Set loop amount
li r5, 10
mtctr r5

#Shift the Time Base over to the left by 1 (for prep with shifting in loop iterations)
slwi r0, r0, 1

#The loop

#Shift what's in r0 by 1 bit to the right
shift_and_store_loop:
srwi r0, r0, 1

#Leave only bit 31 leftover
clrlwi r5, r0, 31

#Store the pin config bit as a byte; update the storing address by 0x57C every time
stbu r5, 0x057C (r3)
bdnz+ shift_and_store_loop

#End C0
#blr #Uncomment if NOT compiling with pyiiasmh, adjust compiled code accordingly
Reply
#66
You are correct. Your code does account for ten configurations. However, I found a duplicate configuration after you posted your code and removed it. the reason I noticed is because one of the configurations was "no pins set" lol. So I added a 1-2-3-7-10 split for the tenth config.
Reply
#67
So here is what I found checking out your code. Not the random pin one. The one you posted just before it.
Works great on the Wii also.
One of the things I was after, was having the pin configurations set all the pins, even on your second roll, so you could
practice the chosen split, over and over, even if you knock a pin or two over on the first roll.
Your code will indeed change the split configs, but on the second roll any pins knocked down on the first roll,
stay down.
Basically, it works like the standard game with the ability to change pin configs.

This is good, because:

1) It does behave like the standard game until your code is activated with (-) button.
and continues to act like a standard game. This makes for a great default setting.
2) Using your code with my insanely long conditionals with writes for all the pin configs, gives me exactly what I was looking for.

- "Standard" gameplay mode until you Press (-) to enter "Splits Only" mode and cycle through pin configs.
- Press 1 to exit Splits Only mode and continue in standard mode.

Behold:

06001500 00000064
01010101 01010101
01010000 00010001
01010001 00000001
00010100 00010000
00010001 00000001
00000001 00010100
00000001 00000000
00010001 00000100
00000100 01000000
00010001 00000000
00000000 00000100
01000101 01000000
01000001 00000000
c0000000 00000010
3c608071 a0038d40
70001000 3c608000
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
280003fe 00000000
01269c35 00000001
0126a1b1 00000001
0126a72d 00000001
0126aca9 00000001
0126b225 00000001
0126b7a1 00000001
0126bd1d 00000001
0126c299 00000001
0126c815 00000001
0126cd91 00000001
e0000000 80000000
280003fe 00000100
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000001
0126b225 00000000
0126b7a1 00000001
0126bd1d 00000001
0126c299 00000001
0126c815 00000000
0126cd91 00000001
e0000000 80000000
280003fe 00000200
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000001
0126b225 00000000
0126b7a1 00000001
0126bd1d 00000001
0126c299 00000000
0126c815 00000000
0126cd91 00000001
e0000000 80000000
280003fe 00000300
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000001
0126b225 00000000
0126b7a1 00000001
0126bd1d 00000000
0126c299 00000000
0126c815 00000000
0126cd91 00000001
e0000000 80000000
280003fe 00000400
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000001
0126b225 00000000
0126b7a1 00000001
0126bd1d 00000001
0126c299 00000000
0126c815 00000000
0126cd91 00000000
e0000000 80000000
280003fe 00000500
01269c35 00000000
0126a1b1 00000001
0126a72d 00000000
0126aca9 00000000
0126b225 00000000
0126b7a1 00000000
0126bd1d 00000000
0126c299 00000001
0126c815 00000000
0126cd91 00000001
e0000000 80000000
280003fe 00000600
01269c35 00000000
0126a1b1 00000000
0126a72d 00000001
0126aca9 00000000
0126b225 00000000
0126b7a1 00000000
0126bd1d 00000001
0126c299 00000000
0126c815 00000001
0126cd91 00000000
e0000000 80000000
280003fe 00000700
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000001
0126b225 00000000
0126b7a1 00000001
0126bd1d 00000000
0126c299 00000000
0126c815 00000000
0126cd91 00000000
e0000000 80000000
280003fe 00000800
01269c35 00000000
0126a1b1 00000000
0126a72d 00000000
0126aca9 00000000
0126b225 00000000
0126b7a1 00000000
0126bd1d 00000001
0126c299 00000000
0126c815 00000001
0126cd91 00000000
e0000000 80000000
280003fe 00000900
01269c35 00000001
0126a1b1 00000001
0126a72d 00000001
0126aca9 00000000
0126b225 00000000
0126b7a1 00000000
0126bd1d 00000001
0126c299 00000000
0126c815 00000000
0126cd91 00000001
e0000000 00000000
28708d40 00000200
020003fe 00001000
e0000000 80008000

Works great on the Wii Smile Smile Smile
Reply
#68
That's because the ASM only writes the pin config once while the RAM writes keep writing the specified pin config every frame (every time the Code Handler is executed). You can modify the ASM to include writing a certain pin config every frame too like the RAM writes.

Let me know how the random pin config ASM works. Tongue
Reply
#69
(12-26-2021, 03:06 AM)Vega Wrote: That's because the ASM only writes the pin config once while the RAM writes keep writing the specified pin config every frame (every time the Code Handler is executed). You can modify the ASM to include writing a certain pin config every frame too like the RAM writes.

Let me know how the random pin config ASM works. Tongue

Will do!!!!
Reply
#70
I went in and revisited the nightmare of setting bp's on pin status.
Was quickly reminded that it brings the game to its knees (2 fps), and can cause Dolphin to crash/shut down.
So I enlisted the help of the wife, in throwing the ball, so I could pause it, and just before hitting the pins, set the bp.

Two instructions break when going through all pin sequences eg. Initial pin setting, replay sequences, setting pins after the first roll and the top of the next frame:

804DC914 stb r4, 0x26D (r3)
and
804DCB2C stb r0, 0x26D (r30)

Struck paydirt when I changed:

804DC914 stb r4, 0x26D (r3)
to
804DC914 lbz r4, 0x26D (r3)


Set up a couple button activators to alternate the new and original asm,
and BOOM we have a code that exceeded my expectations Smile

Press (-) to cycle through splits configs. Game remains in "Standard Mode."
Press (1) to lock the current pins standing, so they always appear with every roll. "Splits Training Mode."
Press (2) to unlock pins and resume "Standard Mode" play.

06001500 00000064
01010101 01010101
01010000 00010001
01010001 00000001
00010100 00010000
00010001 00000001
00000001 00010100
00000001 00000000
00010001 00000100
00000100 01000000
00010001 00000000
00000000 00000100
01000101 01000000
01000001 00000000
C0000000 00000010
3C608071 A0038D40
70001000 3C608000
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
28708D40 00000100
C24DC914 00000001
9883026D 00000000
020003FE 00001000
E0000000 00000000
28708D40 00000200
C24DC914 00000001
8883026D 00000000
E0000000 80008000

Good job Vega!

Now on to the random pin code.......
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)