’Cause all games were better on the GBC

You are not logged in.

  • Index
  • → Generation I
  • → Getting an unexplainable error when making rom (cygwin64)

#1 2018-12-28 00:27:08

New member
Registered: 2018-12-28
Post 1/5

Getting an unexplainable error when making rom (cygwin64)

I am working on some code that randomizes pokemon per-encounter instead of hard coding the slots like the universal randomizer. So far I have it working to the point where I DO get random encounters, at the correct levels for the area, but I still get glitch pokemon. I set it to re-randomize when it gets a number larger than 0xBE to avoid getting trainers and such, and I can specifically get it to not choose 0x00 with the following

cp $0
jr z, .GenRandomSpecies

obviously, I have the entire function labeled .GenRandomSpecies

Now, if I add under that

cp $1F
jr z, .GenRandomSpecies
with 1F being the next invalid ID, it works fine. As soon as I add any others, the next being $20 though, I get the following

error: engine/battle/wild_encounters.asm(line_number) : Value must be 8-bit
make: ***[Makefile:52: pokered.gbc] Error 1

the line_number seems to sometimes be the line of the last jr instruction and sometimes it seems completely random like in the case of having just $0, $1F, and $20 it says line 23 which is normally just fine. (not to mention, untouched) or just another random line. I'm attempting to do this for 39 values, but I can't even get past 3. What could cause this?

Last edited by Mallos31 (2018-12-28 00:46:50)


#2 2018-12-30 16:05:22

Registered: 2016-05-09
Post 871/894

Re: Getting an unexplainable error when making rom (cygwin64)

The jr instruction is an optimized short jump. It stores the jump distance in a single 8-bit byte, instead of a whole two-byte destination. Thus it can only go backwards or forwards ±127 bytes in ROM. If the destination label is farther than that, you have to use jp.

Pokémon Polished Crystal (GitHub) — version 2.2.0 released
Pokémon Red★ and Blue★: Space World Edition (GitHub) — updated August 19!
Polished Map: pokecrystal+pokered map, tileset, and palette editor — version 4.1.0 released!


#3 2018-12-30 23:21:14

New member
Registered: 2018-12-28
Post 2/5

Re: Getting an unexplainable error when making rom (cygwin64)

Fantastic! I'll give it a shot! Thank you very much.

EDIT: Gave it a shot, and it works perfectly! Now's where I take what I've learned and try to hijack trainer roster data and randomize that. Thanks again!

Last edited by Mallos31 (2018-12-30 23:35:31)


#4 2019-01-05 20:53:58

Danny-E 33
Registered: 2012-06-09
Post 1,120/1,134

Re: Getting an unexplainable error when making rom (cygwin64)

Instead of comparing to all the invalid index values, I would generate a random value from 1 to 151, and then use the routine PokedexToIndex to get the valid index number for the chosen Pokemon

    call Random
    cp NUM_POKEMON + 1
    jr nc, .GenRandomSpecies ; too big, invalid
    and a
    jr z, .GenRandomSpecies  ; zero, invalid
    ld [wd11e], a
    callab PokedexToIndex
    ld a, [wd11e]
    ret                      ; return valid index in a

That being said, it's still impressive and valuable to have been able to figure out how to get it to work the way you did


  • Index
  • → Generation I
  • → Getting an unexplainable error when making rom (cygwin64)

Board footer

Powered by FluxBB