Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $f21 = Y rotation max
- $f26 = Y rotation decel (same as X)
- $f28 = Y rotation accel (X is nearly twice as fast and probably better to use for overall feel)
- $01b8(a0) = current Y speed
- $f22 = X rotation max
- $f26 = X rotation decel
- $f29 = X rotation accel
- $01bc(v0) = current X speed
- $f20 = movement max (regular and strafing)
- $f25 = movement decel
- $f27 = movement accel
- $01b4(v0) = current movement speed
- $01b0(v0) = current strafe speed
- ; Code snippet for converting analog values to digital bitmasks based on current mapping
- ; a2 = base pointer for live gamepad status
- ; s0 = base pointer for effective button mask status
- ; $9dbc(gp) = move foreward
- ; $9dbe(gp) = move backward
- ; $9dc2(gp) = turn left
- ; $9dc0(gp) = turn right
- ; $9dca(gp) = look down
- ; $9dc8(gp) = look up
- ; $9dc6(gp) = strafe left
- ; $9dc4(gp) = strafe right
- ; Start modifying at 001b55f4
- lhu v0, $0008(s0) ; Copy last frames calculated mask
- sh zero, $0008(s0)
- sh v0, $000a(s0)
- addu s1, zero, zero
- lbu v0, $0004(a2) ; v0 = right X axis value
- lhu v1, $9dc2(gp) ; v1 = Button mapping for "turn left"
- sltiu at, v0, $007F
- bnel at, zero, right_x_done
- or s1, s1, v1
- lhu v1, $9dc0(gp) ; v1 = Button mapping for "turn right"
- addi v0, v0, $ff81 ; subtract 0x7F
- bnel v0, zero, right_x_done
- or s1, s1, v1
- right_x_done:
- lbu v0, $0005(a2) ; v0 = right Y axis value
- lhu v1, $9dca(gp) ; v1 = Button mapping for "look down"
- sltiu at, v0, $007F
- bnel at, zero, right_y_done
- or s1, s1, v1
- lhu v1, $9dc8(gp) ; v1 = Button mapping for "look up"
- addi v0, v0, $ff81 ; subtract 0x7F
- bnel v0, zero, right_y_done
- or s1, s1, v1
- right_y_done:
- lbu v0, $0006(a2) ; v0 = left X axis value
- lhu v1, $9dc6(gp) ; v1 = Button mapping for "strafe left"
- sltiu at, v0, $007F
- bnel at, zero, left_x_done
- or s1, s1, v1
- lhu v1, $9dc4(gp) ; v1 = Button mapping for "strafe right"
- addi v0, v0, $ff81 ; subtract 0x7F
- bnel v0, zero, left_x_done
- or s1, s1, v1
- left_x_done:
- lbu v0, $0007(a2) ; v0 = left Y axis value
- lhu v1, $9dbc(gp) ; v1 = Button mapping for "move forward"
- sltiu at, v0, $007F
- bnel at, zero, left_y_done
- or s1, s1, v1
- lhu v1, $9dbe(gp) ; v1 = Button mapping for "move backward"
- addi v0, v0, $ff81 ; subtract 0x7F
- bnel v0, zero, left_y_done
- or s1, s1, v1
- left_y_done:
- ; At this point s1 has the calculated mask for this frame
- lhu v0, $000a(s0) ; v0 = calculated buttons pressed last frame
- lhu v1, $0000(s0) ; v1 = current real button mask
- sh s1, $0008(s0) ; s1 = calculated presses this frame
- nor v0, zero, v0 ; v0 now contains all calculated buttons not pressed last frame
- lhu a0, $0002(s0) ; a0 = real new buttons pressed this frame
- and v0, s1, v0 ; v0 = new calculated buttons pressed this frame
- or v1, v1, s1 ; v1 = effective button mask
- or a0, a0, v0 ; a0 = effective new button mask
- sh v1, $0000(s0)
- beq zero, zero, $001b5760
- sh a0, $0002(s0)
- ; Modify jump at 001b55ec to go here
- skip_effective_processing:
- sh zero, $0008(s0)
- beq zero, zero, $001b5760
- sh zero, $000a(s0)
- ; ----------------------------------------------------------------------
- ; Code snippet for transforming axis input into player axis speed values
- lui at, $0041
- addiu at, at, $3DB8
- lw v0, $0004(at)
- addiu at, zero, $00FF
- beq v0, at, <skip>
- lui at, $3C01 ; load literal float value of 1/127
- addiu at, at, $0204
- mtc1 at, $f1 ; Move 1/127 to coprocessor register f1
- lui v1, $01E0 ; Load upper bytes of memory address from next instruction
- lbu v0, $DC05(v1) ; right stick x axis byte loaded to v0 (0 to 255) from 1E0DC06
- addiu at, zero, $00ff
- beql v0, at, <adjust>
- addi v0, v0, $FFFF
- adjust:
- addiu v1, zero, $007f ; load constant 127 to v1 (li v1, 0x7F)
- sub v0, v0, v1 ; subtract 127 to adjust joystick value range from (0 to 255) to (-127 to 128)
- add v1, v0, zero ; save a copy for later
- mtc1 v0, $f0 ; Send joystick values to coprocessor to allow float operations
- cvt.s.w $f0, $f0 ; convert joystick values from integer to float
- mul.s $f0, $f0, $f1 ; scale joystick range from( -127 to 127 ) to ( -1.0 to 1.0 )
- mul.s $f0, $f0, <axis max register> ; calculate target speed
- addiu v0, s7, $3F80
- lwc1 $f1, <current speed>(v0) ; Read current speed
- ; A this point $f0 contains target speed, $f1 contains current speed, v1 has integer axis value (PS2 has no concept of a signed 0, so deceleration towards 0
- ; from a negative speed is a special case), v0 is pointer to player status struct that contains their current rotational and movement speeds. The game stores
- ; all needed acceleration and max speed values in FPU registers for input processing, and these take into account status effects and other modifiers already.
- abs.s $f2, $f0
- c.eq.s $f2, $f0
- nop
- bc1t positive_target
- abs.s $f2, $f1
- negative_target:
- c.eq.s $f2, $f1
- nop
- bc1tl negative_target_and_positive_current
- sub.s $f1, $f1, <axis accel register>
- negative_target_and_negative_current
- c.lt.s $f0, $f1
- neg.s $f3, <axis accel register>
- bc1fl decel1
- add.s $f1, $f1, <axis decel register>
- add.s $f1, $f1, $f3
- negative_target_and_positive_current:
- c.lt.s $f1, $f0
- beq zero, zero, <overshoot>
- swc1 $f1, <current speed>(v0)
- decel1:
- c.lt.s $f0, $f1
- beq zero, zero, <overshoot>
- swc1 $f1, <current speed>(v0)
- positive_target:
- beq v1, zero, decel_toward_neutral
- mov.s $f3, <axis decel register>
- mov.s $f3, <axis accel register>
- decel_toward_neutral:
- c.eq.s $f2, $f1
- nop
- bc1fl positive_target_and_negative_current
- add.s $f1, $f1, $f3
- positive_target_and_positive_current
- c.lt.s $f1, $f0
- mov.s $f3, <axis accel register>
- bc1fl decel2
- sub.s $f1, $f1, <axis decel register>
- add.s $f1, $f1, $f3
- positive_target_and_negative_current
- c.lt.s $f0, $f1
- beq zero, zero, <overshoot>
- swc1 $f1, <current speed>(v0)
- decel2:
- c.lt.s $f1, $f0
- beq zero, zero, <overshoot>
- swc1 $f1, <current speed>(v0)
- overshoot:
- bc1tl overshot
- swcl $f0, <current speed>(v0)
- overshot:
- skip:
Advertisement
Add Comment
Please, Sign In to add comment