Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2019-07-21 16:04:40

Polipolictosaurus
New member
Registered: 2019-07-16
Post 1/1

Curiosity about running and surfing speed (Crystal)

Hi everyone, sorry to bother...
I'm very basic regarding assembly but i didn't have lot of problems so far, I've managed to get everything works fine but i don't understand a thing:
I made a "Running Surf speed", basically replicating what i did for the running shoes, i just did the same thing like the running shoes (Checking the player state and the b button press) like this:

In the .TrySurf Routine in (engine/overworld/player_movement.asm)

call .SurfRunCheck
jr z, .fast

ld a, STEP_WALK
call .DoStep
scf
ret

.SurfRunCheck:
ld a, [wPlayerState]
cp PLAYER_SURF
ret nz
ldh a, [hJoypadDown]
and B_BUTTON
cp B_BUTTON
ret

My question is: what does the jr z, and the ret nz do? also other lines, as far as i understood the code goes like:
-Call my SurfRunCheck routine
-Load in a the player state
-Compare it with PLAYER_SURF status
- ret nz (My only guess would be: return if the compare not equals zero? so further more meaning that a positive cp return zero?)
- load in a joypad pressed buttons
- mask out whatever is not b button (Not sure about this one)
- after masking out compare if the player is pressing b_button only
- return (don't know what does it return? i'm guessing here too that it returns the cp results so 1 - 0)

THEN return to the trySurf routine and goes:

-jr z, .fast (I don't know what it does here, i've just copied it from the running shoes tutorial because i knew it had to be there, but i'm guessing it just says to run the .fast routine if the cp for b button was positive, but if it is like this by my guessing ad assumptions could it be replaced with:
--
call .SurfRunCheck
cp 0
je .fast
-- ??)
...
Tried searching for the jr function online and it is a jump to register function, so it jumps to z? does it mean that my SurfRunCheck routin is loaded into the z register?
I mean the code works with no problem seems (I didn't test much of it but seems ok) it's just a curiosity of mine because i don't want to do things without understanding what i'm doing..

Last edited by Polipolictosaurus (2019-07-21 16:05:07)

Offline

#2 2019-08-03 20:46:32

Miksy91
Member
Registered: 2010-10-16
Post 2,347/2,347

Re: Curiosity about running and surfing speed (Crystal)

.DoStep takes the type of movement as a parameter in register a. In original routine, STEP_WALK is loaded into register a before .DoStep is called in order to make the player (riding a pokemon) taking a step into the direction faced. And what you want to do is to make it so that if B button is pressed down, player takes a fast step into that direction right? To accomplish this, you can for example change .TrySurf to end in the following way:

...
ld a, [wWalkingIntoLand]
and a
jr nz, .ExitWater

call .checkIfButtonBIsPressed
jp z, .fast
jp .walk

and implement .checkIfButtonBIsPressed as follows:

ldh a, [hJoypadDown]
and B_BUTTON
cp B_BUTTON
ret

This changes the value of z flag so that if B button is pressed down, z flag is set, and otherwise its unset. Now after the call command to this sub routine, "jp z, .fast" is executed which makes it so that execution of code continues at .fast if z flag is set (= B button was pressed down). Otherwise "jp .walk" is executed which continues execution at .walk. Moreover, .fast and .walk load STEP_BIKE and STEP_WALK respectively in register a, and call .DoStep afterwards. Therefore this works (and makes sense with what I pointed out in my first sentence above).

Offline

Board footer

Powered by FluxBB