-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudocode.py
2386 lines (2292 loc) · 84 KB
/
pseudocode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Documentation on r13: "Reserved under 64-bit environment; not restored across system calls."
Seems to be used as a constant data segment pointer in Melee: r13 = 0x804db6a0
**Table of contents pointer rtoc = r2**
Historically (from IBM documentation) the set of pointers to a fragment's indirectly accessed data was referred to as the Table of Contents and its base register was called the Table of Contents Register (RTOC).
To access imported data or indirect global data, the build-time offset of the global data item is added to the value in GPR2. The result is the address of a pointer that points to the desired data.
To access imported routines, the offset of the routine is added to the value in GPR2, as in the data version, but the result points not directly to the routine, but to a transition vector.
Table of Contents pointer TOC = rtoc = r2 = 0x804df9e0 (for Melee, vanilla and slippi, never changes)
0x804DBcD4 = R2-0x3D0C: 0.5f (float)
0x804D8254 = R2-0x778C: 0.0f (float)
0x804D8330 = R2-0x76B0: 0.0f (float)
0x804d8334 = R2-0x76AC: 1.0f (float)
R2-0x6B64: 1.0f (float) not tested if constant
R2-0x6890: 0.0f (float)
R2-0x7C30: 0.0f (float)
R2-0x7C2C: -pi/2 (float), hex=0xbfc90fdb
r2-0x7C28: pi (float), hex=0x40490fdb
r2-0x7C24: 0.0f (float)
R2-0x7C20: pi/2 (float), hex=0x3fc90fdb
# Static Variables
R13-0x514C: ftCommonData* p_stc_ftcommon
R13-0x5194: GXColor* p_stc_shieldcolors
R13-0x6C98: int debugLevel?=0 # Probably always zero, meaning that debug tests are disabled. For example this disables a "position has NaN component" at the end of PlayerThink_Physics
# documented in community spreadsheed
struct PlayerEntityStruct:
CharData* pCharData # offset = 0x2C
struct CharData:
# members partially documented in the community spreadsheet, see 'Char Data Offsets' tab, under 'START Player Character Data'
################################################################################################
# Standard Math and Vector functions
################################################################################################
fn atan2@0x80022c30(y@f1, x@f2) -> angle@f1
@Notes:
Mathematical definition:
atan2(y,x) is the oriented angle in the range (-pi, pi]
from the vector (1,0) to (x,y), or equivalently a=atan(y,x) is uniquely defined by the property
(x,y)=(cos(a), sin(a)).
Actual behaviour:
Using the single precision (->bad approximation!) constants
pi/2: hex = 0x3fc90fdb, or 0x3ff921fb60000000 when represented as a double,
pi : hex = 0x40490fdb, or 0x400921fb60000000 when represented as a double,
the result is always in the range [-pi, pi]. The result is:
x > 0: atan(y/x)
x < 0, y > 0: atan(y/x) + pi
x < 0, y < 0: atan(y/x) - pi
x < 0, y == +0: +pi
x < 0, y == -0: -pi
x == 0, y > 0: pi/2
x == 0, y < 0: -pi/2
x == 0, y == 0, signbit(x)!=signbit(y): pi/2
x == 0, y == 0, signbit(x)==signbit(y): signbit set ? -pi/2 : pi/2
All divisions, additions and subtractions above are done with single precision.
Note how the result depends on the sign bit of y if x < 0 and y == 0.
@Reimplementation:
bool sign_x = signbit(x)
bool sign_y = signbit(y)
if sign_x == sign_y:
if sign_x != 0: # x, y <= 0
return (x == 0) ? -pi/2 : atan(y/x)-pi
else:
return (x != 0) ? atan(y/x) : pi/2
else:
if x < 0: return atan(y/x) + pi
if x != 0: return atan(y/x)
return pi/2
@PseudoAssembly:
# save lr, r1 on the stack
float y@sp0x8 = y@f1
float x@sp0xC = x@f2
int raw_y@r0 = raw_cast(int) y@sp0x08
int raw_x@r3 = raw_cast(int) x@sp0x0C
bool sign_y@r4 = [email protected] # highest significant bit
bool sign_x@r0 = [email protected] # highest significant bit
#80022c54
if sign_x@r0 == sign_y@r4:
#80022c5c
if sign_x@r0 != 0:
x@f1 = x@sp0xC
#80022c6c
if x@f1 == 0: # 0 == *(float*)(r2-0x7C30)
return -pi/2 # the hex value for -pi/2 is 0xbfc90fdb, stored at r2-0x7C2C
y@f0 = y@sp0x8
return atan@0x80022E68(f1 = y@f0 / x@f1) - pi # the hex value for pi is 0x40490fdb, stored at r2-0x7C28
x@f1 = x@sp0xC
#80022c98:
if x@f1 != 0 # 0 == *(float*)(r2-0x7C24)
y@f0 = y@sp0x8
return atan@0x80022E68(f1 = y@f0 / x@f1)
return pi/2 # the hex value for pi/2 is 0x3fc90fdb, stored at r2-0x7C20
else: #80022cbc
x@f1 = x@sp0xC
#80022cc0
if x@f1 < 0: # 0 == *(float*)(r2-0x7C24)
return atan(f1 = y@sp0x8 / x@f1) + pi # the hex value for pi is 0x40490fdb, stored at r2-0x7C28
if x@f1 != 0: # 0 == *(float*)(r2-0x7C24)
return atan(f1 = y@sp0x8 / x@f1)
return pi_half with sign of sign_y@r4 # hex value of pi_half: (16329 << 16) + 4049 = 0x3fc90fdb
#80022d0c: restore stack and return
@Assembly:
80022c30: mflr r0
80022c34: stw r0, 0x0004 (sp)
80022c38: stwu sp, -0x0010 (sp)
80022c3c: stfs f1, 0x0008 (sp)
80022c40: stfs f2, 0x000C (sp)
80022c44: lwz r0, 0x0008 (sp)
80022c48: lwz r3, 0x000C (sp)
80022c4c: rlwinm r4, r0, 0, 0, 0 (80000000)
80022c50: rlwinm r0, r3, 0, 0, 0 (80000000)
80022c54: cmpw r0, r4
80022c58: bne- ->0x80022CBC
80022c5c: cmpwi r0, 0
80022c60: beq- ->0x80022C94
80022c64: lfs f0, -0x7C30 (rtoc)
80022c68: lfs f1, 0x000C (sp)
80022c6c: fcmpu cr0,f0,f1
80022c70: bne- ->0x80022C7C
80022c74: lfs f1, -0x7C2C (rtoc)
80022c78: b ->0x80022D0C
80022c7c: lfs f0, 0x0008 (sp)
80022c80: fdivs f1,f0,f1
80022c84: bl ->0x80022E68
80022c88: lfs f0, -0x7C28 (rtoc)
80022c8c: fsubs f1,f1,f0
80022c90: b ->0x80022D0C
80022c94: lfs f1, 0x000C (sp)
80022c98: lfs f0, -0x7C24 (rtoc)
80022c9c: fcmpu cr0,f1,f0
80022ca0: beq- ->0x80022CB4
80022ca4: lfs f0, 0x0008 (sp)
80022ca8: fdivs f1,f0,f1
80022cac: bl ->0x80022E68
80022cb0: b ->0x80022D0C
80022cb4: lfs f1, -0x7C20 (rtoc)
80022cb8: b ->0x80022D0C
80022cbc: lfs f1, 0x000C (sp)
80022cc0: lfs f0, -0x7C24 (rtoc)
80022cc4: fcmpo cr0,f1,f0
80022cc8: bge- ->0x80022CE4
80022ccc: lfs f0, 0x0008 (sp)
80022cd0: fdivs f1,f0,f1
80022cd4: bl ->0x80022E68
80022cd8: lfs f0, -0x7C28 (rtoc)
80022cdc: fadds f1,f0,f1
80022ce0: b ->0x80022D0C
80022ce4: fcmpu cr0,f1,f0
80022ce8: beq- ->0x80022CFC
80022cec: lfs f0, 0x0008 (sp)
80022cf0: fdivs f1,f0,f1
80022cf4: bl ->0x80022E68
80022cf8: b ->0x80022D0C
80022cfc: addis r3, r4, 16329
80022d00: addi r0, r3, 4059
80022d04: stw r0, 0x0008 (sp)
80022d08: lfs f1, 0x0008 (sp)
80022d0c: lwz r0, 0x0014 (sp)
80022d10: addi sp, sp, 16
80022d14: mtlr r0
80022d18: blr
fn sin@0x803263d4(float angle@f1) -> result@f1
@Bug:
For the angle 3.14159=atan2(0,-1), the result is
sin( 3.14159) = -8.74228e-08 (0xbe7777a5c0000000). This wrong, the result should be positive because 0 < 3.14159 < Pi.
sin(-3.14159) = +8.74228e-08 (0x3e7777a5c0000000). Also wrong, the result should be negative because -Pi < -3.14159 < 0.
However for a slightly more accurate value of pi, the result is very accurate again.
sin(3.141592, hex=0x400921f9f01b866e) = 2.7736e-06
TODO: This makes me suspicious that a special case is used for the angle 3.13159=atan2(0,-1).
fn cos@0x80326240(float angle@f1) -> result@f1
@ExampleValues:
cos(+-3.14159) = -1.0, where 3.14159=atan2(0,-1). The exact result is closer to -0.9999999999964793, but this is correctly
rounded for single precision.
How these numerical errors affect vector normalization:
Sometimes vectors are normalized in a silly way:
When normalizing a 2D-vector v, a=atan2(v.y, v.x) is computed, then vec2(cos(a), sin(a)) is used as
the normalized vector, instead of just computing v/v.length().
When normalizing (-1,0) that way, we get a=atan2(0,-1)=3.14159, and then the result is vec2(-1, -8.74228e-08).
Similarly when normalizing (-1,-0), the result is vec2(-1, 8.74228e-08). TODO: research how exactly that is related
to the (extended) invisible ceiling glitch.
fn PSVECAdd@0x80342D54 (Vec3* pA@r3, Vec3* pB@r4, Vec3* pResult@r5): *pResult = *pA + *pB
fn PSVECSubtract@0x80342d78(Vec3* pA@r3, Vec3* pB@r4, Vec3* pResult@r5): *pResult = *pA - *pB
################################################################################################
# Animation state change functions?
################################################################################################
fn AS_Walk_Prefunction@0x800c9528(float argFloat@f1, PlayerEntityStruct* pPlayerEntityStruct@r3) -> ?:
@Notes:
This function is called every time the walk speed transitions between slow/middle/fast,
but not while the speed stays in one of those 3 states.
@Params:
Example parameters for Peach:
f1 = 0.0
Example parameters for Falcon:
f1 = 10.0
@PseudoAssembly:
# save r29, ..., r31, f31 on the stackframe
argFloat@f31 = argFloat@f1
pPlayerEntityStruct@r29 = pPlayerEntityStruct@r3
CharData* pCharData@r31 = [email protected]@0x2C
float Multiplier@f8 = 1.0 # assuming TOC.float@-0x6B64 = 1.0 is const
if [email protected]@0x2223 & 0b01:
# for peach this would be: r3 = 0x80c6d170 -> f8 = 0.7 (surrounded by many other float values)
# on another dolphin instance r3 had another value, but still points to the same value 0.7
# surrounded by those other values
void* pData = r13-0x5184 # TODO: is this a struct, or just a pointer to a float? Is that float constant?
Multiplier@f8 = *cast(float*)(pData+0) # always=0.7?
if [email protected](float)@0x38 != 1.0 # assuming TOC.float@-0x6B64 = 1.0 is const
Multiplier@f8 = AdjustSomething_DuetoModelScale_NotEqualOne@0x800CF594(f1 = Multiplier@f8, f2 = [email protected](float)@0x38, f3 = *(r13.float*@-0x517C)) # f3=1 for Peach
if [email protected]@0x197C != 0:
Multiplier@f8 *= @r13.float@-0x5180
# call AS_Walk: copy params to f1..f7, r4, r5
f1 = argFloat@f31 # restore the f1 parameter, because f1 was used in between
f2 = [email protected]@0x2DC # 70 for Peach, 54 for Falcon
f3 = [email protected]@0x2E0 # 40 for Peach, 40 for Falcon
f4 = [email protected]@0x2E4 # 30 for Peach, 25 for Falcon
f5 = [email protected]@0x011C # 0.187 for Peach (SlowWalkMax)
f6 = [email protected]@0x0120 # 0.47 for Peach (MidWalkPoint)
f7 = [email protected]@0x0124 # 0.76 for Peach (FastWalkMin)
r3 = pPlayerEntityStruct@r29 # restore the r3 parameter, because r3 was used in between
r4 = 15
r5 = 0
Call(0x800DFCA4="AS_Walk ...")
@Assembly:
#800c9528: mflr r0
r0 = lr
#800c952c: stw r0, 0x0004 (sp)
*(r1 + 0x0004) = r0
#800c9530: stwu sp, -0x0030 (sp)
*(r1 + -0x0030) = r1
r1 += -0x0030
#800c9534: stfd f31, 0x0028 (sp)
*(double*)(r1 + 0x0028) = f31
#800c9538: fmr f31, f1
f31 = f1
#800c953c: stw r31, 0x0024 (sp)
*(r1 + 0x0024) = r31
#800c9540: stw r30, 0x0020 (sp)
*(r1 + 0x0020) = r30
#800c9544: stw r29, 0x001C (sp)
*(r1 + 0x001C) = r29
#800c9548: mr r29, r3
r29 = r3
#800c954c: lwz r31, 0x002C (r3)
r31 = *(r3 + 0x002C)
#800c9550: lfs f8, -0x6B64 (rtoc)
f8 = *(float*)(r2 + -0x6B64)
#800c9554: lbz r0, 0x2223 (r31)
r0 = *(byte*)(r31 + 0x2223)
#800c9558: addi r30, r31, 732
r30 = r31 + 732
#800c955c: rlwinm. r0, r0, 0, 31, 31 (00000001)
r0 = r0 & 0b10000000000000000000000000000000
@CR0 = compare_signed(r0, 0)
#800c9560: beq- ->0x800C956C
if CR[0] reflects 'eq': goto ->0x800C956C
#800c9564: lwz r3, -0x5184 (r13)
r3 = *(r13 + -0x5184)
#800c9568: lfs f8, 0 (r3)
f8 = *(float*)(r3 + 0)
#800c956c: lfs f0, -0x6B64 (rtoc)
f0 = *(float*)(r2 + -0x6B64)
#800c9570: lfs f2, 0x0038 (r31)
f2 = *(float*)(r31 + 0x0038)
#800c9574: fcmpu cr0,f0,f2
cr0 = compare_floats(f0, f2) # a<b: 0b1000, a>b: 0b0100, a==b: 0b0010, unordered(NaN): 0b0001
@FPCC = cr0
if one operand is SNaN: @VXSNAN = 1
#800c9578: beq- ->0x800C9590
if CR[0] reflects 'eq': goto ->0x800C9590
#800c957c: lwz r3, -0x517C (r13)
r3 = *(r13 + -0x517C)
#800c9580: fmr f1, f8
f1 = f8
#800c9584: lfs f3, 0x000C (r3)
f3 = *(float*)(r3 + 0x000C)
#800c9588: bl ->0x800CF594
LR = __next_instruction_address
goto ->0x800CF594
#800c958c: fmr f8, f1
f8 = f1
#800c9590: lwz r0, 0x197C (r31)
r0 = *(r31 + 0x197C)
#800c9594: cmplwi r0, 0
CR0 = compare_unsigned(r0, 0) # a<b: 0b1000, a>b: 0b0100, a==b: 0b0010; last bit is set to the summary overflow bit from @XER
#800c9598: beq- ->0x800C95A8
if CR[0] reflects 'eq': goto ->0x800C95A8
#800c959c: lwz r3, -0x5180 (r13)
r3 = *(r13 + -0x5180)
#800c95a0: lfs f0, 0 (r3)
f0 = *(float*)(r3 + 0)
#800c95a4: fmuls f8,f8,f0
f8 = f8 * f0 (as singles)
#800c95a8: fmr f1, f31
f1 = f31
#800c95ac: lfs f2, 0 (r30)
f2 = *(float*)(r30 + 0)
#800c95b0: lfs f3, 0x0004 (r30)
f3 = *(float*)(r30 + 0x0004)
#800c95b4: mr r3, r29
r3 = r29
#800c95b8: lfs f4, 0x0008 (r30)
f4 = *(float*)(r30 + 0x0008)
#800c95bc: lfs f5, 0x011C (r31)
f5 = *(float*)(r31 + 0x011C)
#800c95c0: li r4, 15
r4 = 0 + 15
#800c95c4: lfs f6, 0x0120 (r31)
f6 = *(float*)(r31 + 0x0120)
#800c95c8: li r5, 0
r5 = 0 + 0
#800c95cc: lfs f7, 0x0124 (r31)
f7 = *(float*)(r31 + 0x0124)
#800c95d0: bl ->0x800DFCA4
LR = __next_instruction_address
goto ->0x800DFCA4
#800c95d4: lwz r0, 0x0034 (sp)
r0 = *(r1 + 0x0034)
#800c95d8: lfd f31, 0x0028 (sp)
f31 = *(double*)(r1 + 0x0028)
#800c95dc: lwz r31, 0x0024 (sp)
r31 = *(r1 + 0x0024)
#800c95e0: lwz r30, 0x0020 (sp)
r30 = *(r1 + 0x0020)
#800c95e4: lwz r29, 0x001C (sp)
r29 = *(r1 + 0x001C)
#800c95e8: addi sp, sp, 48
sp = r1 + 48
#800c95ec: mtlr r0
lr = r0
#800c95f0: blr
goto LR
fn AS_Walk(PlayerEntityStruct* pPlayerEntityStruct@r3,
int unkIntParam1?@r4, # always = 15 when called from AS_Walk_Prefunction
int unkIntParam2?@r5, # always = 0 when called from AS_Walk_Prefunction
float unkFloatParam@f1, # same param as in AS_Walk_Prefunction
float SlowWalkAnimLength@f2, float WalkAnimLength@f3, float FastWalkAnimLength@f4,
float SlowWalkSpeed@f5, WalkSpeed@f6, float FastWalkSpeed@f7,
float Multiplier?@f8) -> ?
@Notes:
This function is called every time the walk speed transitions between slow/middle/fast,
but not while the speed stays in one of those 3 states.
@PseudoAssembly:
# save r29, ..., r31, f26, ..., f31 on the stackframe
# duplicate some registers so we can overwrite and later restore them
f31 = FastWalkSpeed@f7
f30 = WalkSpeed@f6
f29 = SlowWalkSpeed@f5
f28 = FastWalkAnimLength@f4
f27 = WalkAnimLength@f3
f26 = SlowWalkAnimLength@f2
r30 = unkIntParam1@r4
r29 = pPlayerEntityStruct@r3
pCharData@r31 = [email protected]@0x2C
[email protected]@0x2360 = Multiplier@f8
pCharData@r3 = [email protected]@0x2C # unnecessary memory read, could just do r3=r31
float absGroundVel@f2 = [email protected]@0xEC
if absGroundVel@f2 < 0: # 0.0f@(r2-0x6890)
absGroundVel@f2 = -absGroundVel@f2
f3 = [email protected]@0x2360 # TODO: undocumented member
float walkMaxVel@f4 = [email protected]@0x0118
global ftCommonData* p_stc_ftcommon@r4 = p_stc_ftcommon@(r13-0x514C)
if absGroundVel@f2 == [email protected]@0x2C * f3 * walkMaxVel@f4:
r0 = 2
else:
r0 = (absGroundVel@f2 >= [email protected]@0x28 * f3 * walkMaxVel@f4) ? 1 : 0
ActionStateChange@0x800693AC(r3 = r29, r4 = r30 + r0, r6 = 0, f1=unkFloatParam@f1, f2 = TOC.float@-0x688C, f3 = 0 /*=TOC.float@-0x6890*/) # possibly more float parameters are used.
AS_AnimationFrameUpdate&More@0x8006EBA4(r3 = r29)
# TODO: look what the following character data fields are. Just a copy of other fields?
[email protected]?@0x2340 = [email protected]@0xEC
[email protected]?@0x2344 = unkIntParam1@r30
[email protected]?@0x2348 = SlowWalkAnimLength@f26
[email protected]?@0x234C = WalkAnimLength@f27
[email protected]?@0x2350 = FastWalkAnimLength@f28
[email protected]?@0x2354 = SlowWalkSpeed@f29
[email protected]?@0x2358 = WalkSpeed@f30
[email protected]?@0x235C = FastWalkSpeed@f31
# unwind stackframe and return
@Assembly:
#800dfca4: mflr r0
r0 = lr
#800dfca8: stw r0, 0x0004 (sp)
*(r1 + 0x0004) = r0
#800dfcac: stwu sp, -0x0098 (sp)
*(r1 + -0x0098) = r1
r1 += -0x0098
#800dfcb0: stfd f31, 0x0090 (sp)
*(double*)(r1 + 0x0090) = f31
#800dfcb4: fmr f31, f7
f31 = f7
#800dfcb8: stfd f30, 0x0088 (sp)
*(double*)(r1 + 0x0088) = f30
#800dfcbc: fmr f30, f6
f30 = f6
#800dfcc0: stfd f29, 0x0080 (sp)
*(double*)(r1 + 0x0080) = f29
#800dfcc4: fmr f29, f5
f29 = f5
#800dfcc8: stfd f28, 0x0078 (sp)
*(double*)(r1 + 0x0078) = f28
#800dfccc: fmr f28, f4
f28 = f4
#800dfcd0: stfd f27, 0x0070 (sp)
*(double*)(r1 + 0x0070) = f27
#800dfcd4: fmr f27, f3
f27 = f3
#800dfcd8: stfd f26, 0x0068 (sp)
*(double*)(r1 + 0x0068) = f26
#800dfcdc: fmr f26, f2
f26 = f2
#800dfce0: stw r31, 0x0064 (sp)
*(r1 + 0x0064) = r31
#800dfce4: stw r30, 0x0060 (sp)
*(r1 + 0x0060) = r30
#800dfce8: mr r30, r4
r30 = r4
#800dfcec: stw r29, 0x005C (sp)
*(r1 + 0x005C) = r29
#800dfcf0: mr r29, r3
r29 = r3
#800dfcf4: lwz r31, 0x002C (r3)
r31 = *(r3 + 0x002C)
#800dfcf8: stfs f8, 0x2360 (r31)
*(float*)(r31 + 0x2360) = f8
#800dfcfc: lwz r3, 0x002C (r3)
r3 = *(r3 + 0x002C)
#800dfd00: lfs f0, -0x6890 (rtoc)
f0 = *(float*)(r2 + -0x6890)
#800dfd04: lfs f2, 0x00EC (r3)
f2 = *(float*)(r3 + 0x00EC)
#800dfd08: fcmpo cr0,f2,f0
cr0 = compare_floats(f2, f0) # a<b: 0b1000, a>b: 0b0100, a==b: 0b0010, unordered(NaN): 0b0001
@FPCC = cr0
if one operand is SNaN: { @VXSNAN = 1; if @VE == 0: @VXVC = 1; }
elif one operand is QNaN: @VXVC = 1
#800dfd0c: bge- ->0x800DFD14
if CR[0] reflects 'ge': goto ->0x800DFD14
#800dfd10: fneg f2,f2
f2 = -f2 # sign bit is flipped, even for NaN values
#800dfd14: lwz r4, -0x514C (r13)
r4 = *(r13 + -0x514C)
#800dfd18: lfs f4, 0x0118 (r3)
f4 = *(float*)(r3 + 0x0118)
#800dfd1c: lfs f0, 0x002C (r4)
f0 = *(float*)(r4 + 0x002C)
#800dfd20: lfs f3, 0x2360 (r3)
f3 = *(float*)(r3 + 0x2360)
#800dfd24: fmuls f0,f0,f4
f0 = f0 * f4 (as singles)
#800dfd28: fmuls f0,f3,f0
f0 = f3 * f0 (as singles)
#800dfd2c: fcmpo cr0,f2,f0
cr0 = compare_floats(f2, f0) # a<b: 0b1000, a>b: 0b0100, a==b: 0b0010, unordered(NaN): 0b0001
@FPCC = cr0
if one operand is SNaN: { @VXSNAN = 1; if @VE == 0: @VXVC = 1; }
elif one operand is QNaN: @VXVC = 1
#800dfd30: cror 2, 1, 2
CR.bits[2] = CR.bits[1] or CR.bits[2]
#800dfd34: bne- ->0x800DFD40
if CR[0] reflects 'ne': goto ->0x800DFD40
#800dfd38: li r0, 2
r0 = 0 + 2
#800dfd3c: b ->0x800DFD64
goto ->0x800DFD64
#800dfd40: lfs f0, 0x0028 (r4)
f0 = *(float*)(r4 + 0x0028)
#800dfd44: fmuls f0,f0,f4
f0 = f0 * f4 (as singles)
#800dfd48: fmuls f0,f3,f0
f0 = f3 * f0 (as singles)
#800dfd4c: fcmpo cr0,f2,f0
cr0 = compare_floats(f2, f0) # a<b: 0b1000, a>b: 0b0100, a==b: 0b0010, unordered(NaN): 0b0001
@FPCC = cr0
if one operand is SNaN: { @VXSNAN = 1; if @VE == 0: @VXVC = 1; }
elif one operand is QNaN: @VXVC = 1
#800dfd50: cror 2, 1, 2
CR.bits[2] = CR.bits[1] or CR.bits[2]
#800dfd54: bne- ->0x800DFD60
if CR[0] reflects 'ne': goto ->0x800DFD60
#800dfd58: li r0, 1
r0 = 0 + 1
#800dfd5c: b ->0x800DFD64
goto ->0x800DFD64
#800dfd60: li r0, 0
r0 = 0 + 0
#800dfd64: lfs f2, -0x688C (rtoc)
f2 = *(float*)(r2 + -0x688C)
#800dfd68: add r4, r30, r0
r4 = r30 + r0
#800dfd6c: lfs f3, -0x6890 (rtoc)
f3 = *(float*)(r2 + -0x6890)
#800dfd70: mr r3, r29
r3 = r29
#800dfd74: li r6, 0
r6 = 0 + 0
#800dfd78: bl ->0x800693AC
LR = __next_instruction_address
goto ->0x800693AC
#800dfd7c: mr r3, r29
r3 = r29
#800dfd80: bl ->0x8006EBA4
LR = __next_instruction_address
goto ->0x8006EBA4
#800dfd84: lfs f0, 0x00EC (r31)
f0 = *(float*)(r31 + 0x00EC)
#800dfd88: stfs f0, 0x2340 (r31)
*(float*)(r31 + 0x2340) = f0
#800dfd8c: stw r30, 0x2344 (r31)
*(r31 + 0x2344) = r30
#800dfd90: stfs f26, 0x2348 (r31)
*(float*)(r31 + 0x2348) = f26
#800dfd94: stfs f27, 0x234C (r31)
*(float*)(r31 + 0x234C) = f27
#800dfd98: stfs f28, 0x2350 (r31)
*(float*)(r31 + 0x2350) = f28
#800dfd9c: stfs f29, 0x2354 (r31)
*(float*)(r31 + 0x2354) = f29
#800dfda0: stfs f30, 0x2358 (r31)
*(float*)(r31 + 0x2358) = f30
#800dfda4: stfs f31, 0x235C (r31)
*(float*)(r31 + 0x235C) = f31
#800dfda8: lwz r0, 0x009C (sp)
r0 = *(r1 + 0x009C)
#800dfdac: lfd f31, 0x0090 (sp)
f31 = *(double*)(r1 + 0x0090)
#800dfdb0: lfd f30, 0x0088 (sp)
f30 = *(double*)(r1 + 0x0088)
#800dfdb4: lfd f29, 0x0080 (sp)
f29 = *(double*)(r1 + 0x0080)
#800dfdb8: lfd f28, 0x0078 (sp)
f28 = *(double*)(r1 + 0x0078)
#800dfdbc: lfd f27, 0x0070 (sp)
f27 = *(double*)(r1 + 0x0070)
#800dfdc0: lfd f26, 0x0068 (sp)
f26 = *(double*)(r1 + 0x0068)
#800dfdc4: lwz r31, 0x0064 (sp)
r31 = *(r1 + 0x0064)
#800dfdc8: lwz r30, 0x0060 (sp)
r30 = *(r1 + 0x0060)
#800dfdcc: lwz r29, 0x005C (sp)
r29 = *(r1 + 0x005C)
#800dfdd0: addi sp, sp, 152
sp = r1 + 152
#800dfdd4: mtlr r0
lr = r0
#800dfdd8: blr
goto LR
fn AS_WalkAnimChange(f1=,f2=SlowWalkAnimLength,f3=WalkAnimLength,f4=FastWalkAnimLength,f5=SlowWalkSpeed,f6=WalkSpeed,f7=FastWalkSpeed,f8=Multiplier?)->void?
@Callstack:
AS_WalkAnimChange
AS_WalkAnimChangePrefunction
AS_WalkAnimChangePrefunction
Interrupt_Walk
Interrupt_AS_Wait
PlayerThink_Interrupt
GObjProc
updateFunction
Scene_ProcessMinor
Scene_ProcessMajor
Scene_Main
main
@Assembly
800dfca4: mflr r0
800dfca8: stw r0, 0x0004 (sp)
800dfcac: stwu sp, -0x0098 (sp)
800dfcb0: stfd f31, 0x0090 (sp)
800dfcb4: fmr f31, f7
800dfcb8: stfd f30, 0x0088 (sp)
800dfcbc: fmr f30, f6
800dfcc0: stfd f29, 0x0080 (sp)
800dfcc4: fmr f29, f5
800dfcc8: stfd f28, 0x0078 (sp)
800dfccc: fmr f28, f4
800dfcd0: stfd f27, 0x0070 (sp)
800dfcd4: fmr f27, f3
800dfcd8: stfd f26, 0x0068 (sp)
800dfcdc: fmr f26, f2
800dfce0: stw r31, 0x0064 (sp)
800dfce4: stw r30, 0x0060 (sp)
800dfce8: mr r30, r4
800dfcec: stw r29, 0x005C (sp)
800dfcf0: mr r29, r3
800dfcf4: lwz r31, 0x002C (r3)
800dfcf8: stfs f8, 0x2360 (r31)
800dfcfc: lwz r3, 0x002C (r3)
800dfd00: lfs f0, -0x6890 (rtoc)
800dfd04: lfs f2, 0x00EC (r3)
800dfd08: fcmpo cr0,f2,f0
800dfd0c: bge- ->0x800DFD14
800dfd10: fneg f2,f2
800dfd14: lwz r4, -0x514C (r13)
800dfd18: lfs f4, 0x0118 (r3)
800dfd1c: lfs f0, 0x002C (r4)
800dfd20: lfs f3, 0x2360 (r3)
800dfd24: fmuls f0,f0,f4
800dfd28: fmuls f0,f3,f0
800dfd2c: fcmpo cr0,f2,f0
800dfd30: cror 2, 1, 2
800dfd34: bne- ->0x800DFD40
800dfd38: li r0, 2
800dfd3c: b ->0x800DFD64
800dfd40: lfs f0, 0x0028 (r4)
800dfd44: fmuls f0,f0,f4
800dfd48: fmuls f0,f3,f0
800dfd4c: fcmpo cr0,f2,f0
800dfd50: cror 2, 1, 2
800dfd54: bne- ->0x800DFD60
800dfd58: li r0, 1
800dfd5c: b ->0x800DFD64
800dfd60: li r0, 0
800dfd64: lfs f2, -0x688C (rtoc)
800dfd68: add r4, r30, r0
800dfd6c: lfs f3, -0x6890 (rtoc)
800dfd70: mr r3, r29
800dfd74: li r6, 0
800dfd78: bl ->0x800693AC
800dfd7c: mr r3, r29
800dfd80: bl ->0x8006EBA4 AS_AnimationFrameUpdate&More
800dfd84: lfs f0, 0x00EC (r31)
800dfd88: stfs f0, 0x2340 (r31)
800dfd8c: stw r30, 0x2344 (r31)
800dfd90: stfs f26, 0x2348 (r31)
800dfd94: stfs f27, 0x234C (r31)
800dfd98: stfs f28, 0x2350 (r31)
800dfd9c: stfs f29, 0x2354 (r31)
800dfda0: stfs f30, 0x2358 (r31)
800dfda4: stfs f31, 0x235C (r31)
800dfda8: lwz r0, 0x009C (sp)
800dfdac: lfd f31, 0x0090 (sp)
800dfdb0: lfd f30, 0x0088 (sp)
800dfdb4: lfd f29, 0x0080 (sp)
800dfdb8: lfd f28, 0x0078 (sp)
800dfdbc: lfd f27, 0x0070 (sp)
800dfdc0: lfd f26, 0x0068 (sp)
800dfdc4: lwz r31, 0x0064 (sp)
800dfdc8: lwz r30, 0x0060 (sp)
800dfdcc: lwz r29, 0x005C (sp)
800dfdd0: addi sp, sp, 152
800dfdd4: mtlr r0
800dfdd8: blr
################################################################################################
# Player Physics functions
################################################################################################
fn PlayerThink_Physics@0x8006b82c(PlayerEntityStruct* pPlayerEntityStruct@r3)->void
@PseudoAssembly:
# save r26..r31, f30, f31 on the stackframe
# stackframe for local variables has size 0x68. Stack variable storage is notated as varName@sp0x32 to refer to the variable at sp+0x32=r1+0x32.
# duplicate registers
pPlayerEntityStruct@r28 = pPlayerEntityStruct@r3
CharData* pCharData@r3 = [email protected]@0x2C
pCharData@r31 = pCharData@r3
if [email protected]@0x221F & 0b10000: # 'sleep' bit according to m-Ex figher.h, should this be called not_sleeping instead?
return
# all wind hazards like wispy are accumulated into this vector at the end of the following then-block, and set to 0 in the else-block.
# => The bit tested in the if-condition might test if the player is active or not (not active when dead/respawning/on the angel platform)
Vec3 windOffset@sp0x4C
#8006b85c
if [email protected](byte)@0x2219 & 0b100 == 0: # 'freeze' bit according to m-Ex fighter.h
#8006b868
if [email protected](int)@0x2064 != 0:
[email protected](int)@0x2064 -= 1
# I was not able to trigger the following counter. Even with a memory breakpoint,
# this value was only read by HSD_DObjAnimAll at 8035e07c. Here's what I tested:
# smash attack charge timer
# grab timer
# shield break tumble timer
# hitlag/hitstun timer
# ledge grab timer
# L-cancel window
# tech window
# Barrel timer
# Peach float timer
# Item regrab cooldown after throwing with A or c-stick
# TODO: TEST VARIOUS ITEM TIMERS (tested until home run bat so far)
# The value is also written to every time the UnclePunch conversion training resets, but
# that's probably just UnclePunch code.
if [email protected]@0x2108 != 0: # TODO: undocumented character data
[email protected]@0x2108 -= 1
FtChkDevice_DecrementImmunity@0x800C0A98(r3 = pPlayerEntityStruct@r28)
# I think this calls the main physics function for states like walk/jump/attack
#8006b85c
FUNC_PTR AS_Physics_Func@r12 = [email protected]@0x21A4
if AS_Physics_Func@r12 != 0:
AS_Physics_Func@r12(r3 = pPlayerEntityStruct@r28)
#8006B8B0 Update knockback, and (when transitioning to the ground?) also the velocity:
# when airborne:
# - reduce knockback magnitude by knockbackDecay
# - unless some (debugging?) flag is set, then reduces knockback velocity x and y individually by the x and y components of pCharData.vec2@0x2D4.
# - always set ground_kb_vel = 0
# when grounded:
# - when ground_kb_vel==0, set it to knockbackVel.x (this might have some unintended implications)
# - reduce ground_kb_vel magnitude slightly
# - Then set knockbackVel = groundVel.x * surfaceTangent.
float* p_kb_vel@r30 = &[email protected]@0x8C
float kb_vel_x@f2 = [email protected]@0x8C.x
if [email protected] != vec2(0): # 0.0f@f1 = 0.0f@toc-0x778C; (0.0f@f1 != kb_vel_x@f2) || (0.0f@f1 != [email protected]@0x4):
#8006B8D0
if [email protected](int)@0xE0 == 1: # 0=grounded, 1=airborne.
float kb_vel_x@f31 = [email protected]@0x0
float kb_vel_y@f30 = [email protected]@0x4
if [email protected]@0x2228 & 0b10_0000: # I was not able to trigger this case in normal gameplay yet. spreadsheet comment: facing angle? hi-pitch, lo-pitch, noCliffCatch
[email protected] = reduceMagnitude@0x8007CD6C([email protected], getVec0x2D4_X_assertPlayerIndex@0x8007CDA4(r3 = pCharData@r31))
[email protected] = reduceMagnitude@0x8007CD6C([email protected], getVec0x2D4_Y_assertPlayerIndex@0x8007cdf8(r3 = pCharData@r31))
else: #@0x8006b924
# Conceptually the next code block does this:
# float kb_vel_len@f4 = sqrt(kb_vel_x@f31 * kb_vel_x@f31 + kb_vel_y@f30 * kb_vel_y@f30)
# But the following code is an explicit square root implementation (Probably because
# the compiler inlined the square root). To compute the square root of S, first a rough
# approximation x of 1/sqrt(S) is computed using the assembly instruction frsqrte, which has
# a relative error less than 1/32. Next Newton's method is used to find the root of the equation
# f(x) := 1/x^2 - S = 0.
# Newton's method to solve for f(x)=0 uses the iteration x_{n+1} = x_n - f(x)/f'(x).
# This leads to the iteration formula:
# x_{n+1} = x_n * (3 - S * x_n^2)/2, n=0,1,2,...
# This formula is iterated three times, then x is a very good approximation of
# 1/sqrt(S). Therefore x*S is a very good approximation of sqrt(S).
float S = kb_vel_x@f31 * kb_vel_x@f31 + kb_vel_y@f30 * kb_vel_y@f30
float x
if S > 0:
float x = approx_rsqrt(S) # rough approximation of 1/sqrt(S)
loop 3 times:
# The constants are stored at TOC.double@-0x7758=3 and TOC.double@-0x7760=0.5
x *= 0.5 * (3 - S * x*x)
x *= S # now x is a very good approximation of the square root of S
else:
x = 0
float kb_vel_len@f4 = x
# decrement knockback velocity magnitude
float kb_vel_decrement = p_stc_ftcommon@(r13-0x514c).kb_frameDecay@0x204 # = 0.051 constant?
if kb_vel_len@f4 < kb_vel_decrement:
*p_kb_vel@r30 = vec2(0) # = vec2(0.0f@toc-0x778C, 0.0f@toc-0x778C)
else:
# What we want to achieve is this:
# *p_kb_vel *= (kb_vel_len - kb_vel_decrement)/kb_vel_len
# But this is implemented very inefficiently like this:
float kb_angle = atan2@0x80022C30(kb_vel_y, kb_vel_x)
vec2 normalized_kb_vel = vec2(cos@8006b9b8(kb_angle), sin@8006b9d4(kb_angle)) # kb_vel / kb_vel_len would be better still
*p_kb_vel@r30 -= kb_vel_decrement * normalized_kb_vel
[email protected]_kb_vel@0xF0 = 0 # = 0.0f@toc-0x778C
else: #8006b9f8
# This is probably triggered when transitioning from the air to the ground, for example with ASDI down after getting hit.
if [email protected]_kb_vel@0xF0 == 0:
[email protected]_kb_vel@0xF0 = kb_vel_x@f2
float effectiveFriction = [email protected]@0x128 * Stage_GetGroundFrictionMultiplier@0x80084A40(r3 = pCharData@r31) * p_stc_ftcommon@(r13-0x514c).float?@0x200 # ground multiplier usually 1. last factor was 1 when I looked
reduceGroundKnockbackVel@0x8007CCA0(r3 = pCharData@r31, f1 = effectiveFriction)
# set knockback velocity to ground_kb_vel * surfaceTangent
Vec2* pNormal@r29 = &[email protected]@0x844 # surface normal points out of the surface.
*(p_kb_vel@r30) = [email protected]_kb_vel@0xF0 * Vec2([email protected]@0x4, [email protected]@0x0)
#8006BA5C Now handle the attacker's shield knockback in a similar way
Vec3* pAtkShieldKB@r29 = &[email protected]@0x98
float atkShieldKB_X@f2 = [email protected]@0x98.x
if [email protected]@0x98.xy != vec2(0,0):
if [email protected](int)@0xE0 == 1: # = vec2(0.0f@toc-0x778C, 0.0f@toc-0x778C)
#8006ba88
vec2 atkShieldKB = [email protected]@0x98.xy
# The following square root was inlined to a large Newton approximation of this
# inverse square root just as a few lines above. I'll just write the result here:
float atkShieldKB_len@f4 = sqrt(atkShieldKB.x * atkShieldKB.x + atkShieldKB.y * atkShieldKB.y)
float len_decrement = p_stc_ftcommon@(r13-0x514c).shield_kb_frameDecay@0x3E8 # TODO: document this
if atkShieldKB_len@f4 < len_decrement:
[email protected]@0x0 = 0
# BUG IN THE MELEE CODE THAT CAUSES THE INVISIBLE CEILING GLITCH
# The next line should be 'pAtkShieldKB.y = 0', but instead it is:
[email protected]@0x4 = 0
else:
# again, the better implementation would be:
# *pAtkShieldKB *= (atkShieldKB_len - len_decrement)/atkShieldKB_len
float atkShieldKBAngle = atan2(atkShieldKB.y, atkShieldKB.x)
*(pAtkShieldKB@r29) -= len_decrement * Vec2(cos(atkShieldKBAngle), sin(atkShieldKBAngle))
[email protected]_shield_kb_vel@0xF4 = 0 # 0 = TOC.float@-0x778C
else: #8006bb64
if [email protected]_shield_kb_vel@0xF4 == 0:
[email protected]_shield_kb_vel@0xF4 = atkShieldKB_X@f2
float effectiveFriction = [email protected]@0x128 * Stage_GetGroundFrictionMultiplier@0x80084A40(r3 = pCharData@r31) * p_stc_ftcommon@(r13-0x514c).float?@0x03EC # This last constant variable differs from the one for the knockback friction above
reduceGroundShieldKnockbackVel@0x8007CE4C(r3 = pCharData@r31, f1 = effectiveFriction)
Vec2* pNormal@r27 = &[email protected]@0x844
*(pAtkShieldKB@r29) = [email protected]_shield_kb_vel@0xF4 * Vec2([email protected]@0x4, [email protected]@0x0)
#8006BBC8 update horizontalSelfVel
[email protected]@0xE4 = 0
[email protected]@0xE8 = 0
#PSVECAdd@0x80342D54(r3=&[email protected]@0x80, r4=&[email protected]@0x74, r5=&[email protected]@0x80)
[email protected]@0x80.xyz += [email protected]@0x74.xyz
[email protected]@0x74 = Vec3(0)
# copy selfVel into a stack storage variable
Vec3 selfVel@sp0x40 = [email protected]@0x80
# TODO: these double_lower_32bit variables are probably integer counters that get decremented each frame.
# The double value construction then is only used as an interpoltion tool between selfVel and some UnkVel2.
uint double_lower_32bits_1@r0 = [email protected]_lower_32bits_1@0x1948
if double_lower_32bits_1@r0 != 0:
# bit construction of two doubles on the stack. The flags count as mantissa bits. Withouth these flags,
# the bytes 0x4330_0000_0000_0000, interpreted as a double, give the decimal value 4_503_599_627_370_496, and a bit higher with mantissa bits.
uint[2] doubleA@sp0x58 = [0x43300000, double_lower_32bits_1@r0 ^ (1 << 31)] # highest bit is flipped
uint[2] doubleB@sp0x60 = [0x43300000, [email protected]_lower_32bits_2@0x194C ^ (1 << 31)] # highest bit is flipped
double A@f0 = raw_cast(double)doubleA@sp0x58
double B@f1 = raw_cast(double)doubleB@sp0x60
float C@f2 = [email protected]@-0x7790 - (B - [email protected]@-0x7780) / (A - [email protected]@-0x7780)
[email protected] = C@f2 * ([email protected]@0x80.xy - [email protected]@0xA4.xy) + [email protected]@0xA4.xy
if [email protected]_lower_32bits_2@0x194C == 0:
[email protected]_lower_32bits_1@0x1948 = 0
# add some horizontal+depth offset to the position? Why is there no vertical component?
[email protected]@0xB0.x += [email protected]@0xF8
[email protected]@0xB0.z += [email protected]@0xFC
if (double_lower_32bits_1@r0 & 0b10) && !([email protected]@0x2222 & 0b01):
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xD4, r4 = &selfVel@sp0x40, r5 = r3)
[email protected]@0xD4.xyz += [email protected]
bool bit@r0 = [email protected](ubyte)@0x2210.bits[5] # bits[0] being the least significant bit
[email protected](ubyte)@0x2210.bits[5] = 0
if bit@r0 || (CALL(0x80070FD0)(r3 = pCharData@r31); r3 != 0) || ([email protected]@0x594 & 1):
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xB0, r4 = [email protected]@0xD4, r5 = r3)
[email protected]?@0xD4 = vec3(0) # = 0.0f@toc-0x778C) TODO: we set this velocity to 0 after applying it -> Is this SDI or ASDI?
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xB0, r4 = pAtkShieldKB@r29, r5 = r3)
[email protected]@0xB0.xyz += [email protected]
else:
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xB0, r4 = &[email protected]@0xB0, r5 = r3)
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xB0, r4 = pAtkShieldKB@r29, r5 = r3)
[email protected]@0xB0.xy += [email protected]
# accumulate wind hazards into the windOffset vector
Stage_CheckForWindHazards@0x8007B924(r3 = pPlayerEntityStruct@r28, /*result vec3*/r4 = &windOffset@sp0x4C)
else: # 0x8006bde8
Vec3 windOffset@sp0x4C = Vec(0) # the 0.0f constant below is from f0 = [email protected]@-0x778C
DataOffset_ComboCount_TopNAttackerModify@0x80076528(r3 = pPlayerEntityStruct@r28)
#8006be00 void (*EveryHitlag_x21D0)(GOBJ *fighter)
FuncPtr hitlagFn@r12 = [email protected]_x21D0@0x21D0
if hitlagFn@r12 != 0:
hitlagFn@r12(r3 = pPlayerEntityStruct@r28)
#8006be18
if [email protected](int)@0xE0 == 0:
Vec3 difference@sp0x24
# I think this function always returns r3=1, but it contains two __assert functions. But I guess these just stop or reset the game.
# result is written to where r5 points to, which is 'difference' in this case
bool res@r3 = Collision_GetPositionDifference@0x800567C0(/*GroundID*/r3 = [email protected]?@0x83C/*groundID field not documented*/, /*Vec3*/r4 = &[email protected]@0xB0, r5 = &difference@sp0x24)
if res@r3:
#PSVECAdd@0x80342D54(r3 = &[email protected]@0xB0, &difference@sp0x24, r5 = r3)
[email protected]@0xB0 += difference@sp0x24
#8006be4c
[email protected]@0xB0.xyz += [email protected]
#8006be80 TODO: do the bitflag tests here tell us if the player is dead?
Player_CheckForDeath@0x800D3158(r3 = pPlayerEntityStruct@r28)
if [email protected]@0x2225.bits[7]: # bit[0] = least significant
# if position.y crossed (0.25*stage.blastBottom+0.75*stage.cameraBottom) + stage.crowdReactStart from below...
if [email protected]@0xC0 <= StageInfo_CrowdGaspHeight?@0x80224BC4() &&
[email protected]@0xB0.y > StageInfo_CrowdGaspHeight?@0x80224BC4():
[email protected]@0x2225.bits[7] = 0 # bit[0] = least significant bit
else:
if ([email protected]@0x222A.bits[6] == 0) && ([email protected]@0x2228.bits[2] == 0):
# if position.y crossed 0.5*(stage.blastBottom+stage.cameraBottom) + stage.crowdReactStart from above...
if [email protected]@0xC0 >= StageInfo_OffscreenBottomLoad@0x80224B98() &&
[email protected]@0xB0.y < StageInfo_OffscreenBottomLoad@0x80224B98():
# plays this sound you always hear when you get close to the bottom blast zone
SFX_PlayCharacterSFX@0x80088148(r3 = r31, r4 = 96, r5 = 127, r6 = 64)
[email protected]@0x2225.bits[7] = 1 # bits[0] = least significant bit
#8006bf28
if [email protected](float)@0x18A4 != 0 # 0.0f@toc-0x778C
if [email protected]@0x221C & 0b10:
# not sure when we reach this point, but often around the end of knockback, sometimes completely unrelated
if !PositionXBetweenLedgesMinDelta@0x80322258(f1 = [email protected]@0xB0.x):
[email protected](float)@0x18A4 = 0 # = 0.0f@toc-0x778C
Hurtbox_SetAllNotUpdated@0x8007AF28(r3 = pPlayerEntityStruct@r28)
#8006bf64
if debugLevel(int)?@(r13-0x6C98) <= 3: # This value is zero and I think it always will be. Probably some debug level indicator, because only a NaN test follows next.
return
#8006bf70: The remaining code does this and then returns, but the isNaN tests are inlined by the compiler.
# I think setting f1 and f2 here has no effect. But maybe the registers are dumped by the OSReport or __assert.
f1 = [email protected]@0xB0.x
f2 = [email protected]@0xB0.y
OSReport@0x803456A8(r3 = 0x803C0000 + 1452, CR.bits[6] = 1) # bit[0] = leftmost bit
__assert@0x80388220(r3 = 0x803C0000 + 1404, r4 = 2517, r5 = r13 - 31888)
# Close to ASM version of the above block:
# Determine the FloatType of [email protected]@0xB0.x, write result to r0.
# This was probably inlined by the compiler.
enum FloatType { NaN=1, Infinite=2, Zero=3, Normal=4, Subnormal=5 }
#8006bf70
uint exponentMask@r0 = 0b01111111100000000000000000000000 # = 0x7F800000
uint rawPosX@r4 = [email protected]@0xB0.x
uint exponentBits@r3 = rawPosX@r4 & 0b01111111100000000000000000000000
#8006bf84
if exponentBits@r3 != exponentMask@r0:
# not all exponent bits set -> a number
#8006bf8c
if 0 == exponentBits@r3 < exponentMask@r0: # we already know that '<' is true from the '!=', why test this?
# no exponent bits set -> subnormal number or zero., including zero when also no fractional bits are set.
#8006bfb4
r0 = (rawPosX@r4 & 0b00000000011111111111111111111111) ? FloatType.Subnormal : FloatType.Zero
else:
#8006bfcc
r0 = FloatType.Normal # some but not all exponent bits are set -> normal number
else:
# all exponent bits set
r0 = (rawPosX@r4 & 0b00000000011111111111111111111111) ? FloatType.NaN : FloatType.Infinite
#8006bfd0
FloatType posXFloatType@r0 = r0
if posXFloatType@r0 != FloatType.NaN:
# determine float type of [email protected]@0xB0.y, result in r0
f0 = [email protected]@0xB0.y
r0 = 0x7F800000
*(float*)(r1 + 0x0014) = f0
r4 = *(int32)(r1 + 0x0014)
r3 = r4 & 0b01111111100000000000000000000000
if r3 != r0:
if r3 >= r0 || r0 != 0:
r0 = 4
else:
r0 = (r4 & 0b00000000011111111111111111111111) ? 5 : 3
else:
r0 = (r4 & 0b00000000011111111111111111111111) ? 1 : 2
FloatType posYFloatType@r0 = r0
if posYFloatType@r0 != FloatType.NaN:
# determine float type of [email protected]@0xB0.z, result in r0
f0 = [email protected]@0xB0.z
r0 = 0x7F800000
*(float*)(r1 + 0x0010) = f0
r4 = *(int32)(r1 + 0x0010)
r3 = r4 & 0b01111111100000000000000000000000
if r3 != r0:
if r3 <= r0 != 0:
r0 = (r4 & 0b00000000011111111111111111111111) ? 5 : 3
else:
r0 = 4
else:
r0 = (r4 & 0b00000000011111111111111111111111) ? 1 : 2
FloatType posZFloatType@r0 = r0
if posZFloatType@r0 != FloatType.NaN:
return
# Setting f1,f2 has no effect, but it's actually in the ASM code.
# These also can not be return values, because an assertion error is being generated next.
f1 = [email protected]@0xB0.x
f2 = [email protected]@0xB0.y
OSReport@0x803456A8(r3 = 0x803C0000 + 1452, CR.bits[6] = 1) # bit[0] = leftmost bit
__assert@0x80388220(r3 = 0x803C0000 + 1404, r4 = 2517, r5 = r13 - 31888)
# unwind stackframe and return
@Assembly:
8006b82c: mflr r0
8006b830: stw r0, 0x0004 (sp)
8006b834: stwu sp, -0x0090 (sp)
8006b838: stfd f31, 0x0088 (sp)
8006b83c: stfd f30, 0x0080 (sp)
8006b840: stmw r26, 0x0068 (sp)
8006b844: mr r28, r3
8006b848: lwz r3, 0x002C (r3)
8006b84c: lbz r0, 0x221F (r3)
8006b850: addi r31, r3, 0
8006b854: rlwinm. r0, r0, 28, 31, 31 (00000010)
8006b858: bne- ->0x8006C0D4
8006b85c: lbz r0, 0x2219 (r31)
8006b860: rlwinm. r0, r0, 30, 31, 31 (00000004)
8006b864: bne- ->0x8006BDE8