Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2017-02-01 23:18:16

KeiTaRo
Member
Registered: 2015-12-05
Post 28/31
Website

[pokered] "new" trainer class picture oddities

Hello!

I've attempted to replace the unused "PROF.OAK" trainer class with a female swimmer. I've changed the parties, graphics, and everything else I would need to change correctly to the best of my knowledge (including changing the picture pointer in both main.asm and its reference in trainer_pic_money_pointers and e.asm as well) ... the trainer works perfectly in every way except for the fact that it's picture is showing up as that of a Youngster...I double checked that my pointers are correct and that there aren't any other stray references (for what it's worth, I created a new picture pointer all together in main.asm because replacing the one used by Oak would have changed him in the intro, as well. The new picture is in a different bank because it told me I was out of room in the existing bank of trainer images. Not sure if this is relevant.) ... I'm not entirely sure why this sort of weirdness would be happening, as my other trainers still seem to work correctly. I'm sure this is probably something REALLY obvious, but I'm unable to track down what it is. Any advice is appreciated!

Offline

#2 2017-02-03 02:43:58

Danny-E 33
Administrator
Registered: 2012-06-09
Post 1,018/1,021

Re: [pokered] "new" trainer class picture oddities

I can't say for sure, but I bet this is the problem...

You know how the currently loaded rom bank is loaded into ram at address $4000-7fff?
The trainer pics are originally in bank $13 and they are the very first thing in the bank. This means the pointer to YoungsterPic (the first pic) is $4000 (pointing to the beginning of the ram bank).
You put the female swimmer's pic in a different bank. And I bet you put it as the very first thing in that bank.
However, the game doesn't store information regarding which bank to find each individual trainer pic. All trainer pics are assumed to be in the same bank.
Since the female swimmer's pic is the first thing in its bank, the pointer to that pic is $4000. The game looks in bank $13 like usual, and ends up loading the Youngster's pic.

Your two solutions to this are:
Make room in bank $13 to put the female swimmer's pic in the same bank as the others.
Or modify the code that references TrainerPics to load a specific bank into ram based on trainer ID.


Red Hack: Pokémon Prototype

Total number of registered users: 7000+
Total number of active users: ~12

Offline

#3 2017-02-03 04:19:25

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 3,453/3,456

Re: [pokered] "new" trainer class picture oddities

I can also try to help you out with an example of how to let the game find trainer pics in any bank, and various other trainer data updates you may or may not be interested in.

Offline

#4 2017-02-03 19:48:04

KeiTaRo
Member
Registered: 2015-12-05
Post 29/31
Website

Re: [pokered] "new" trainer class picture oddities

Oh!! I did in fact put it as the first thing in that bank (I truthfully just tacked it on directly at the beginning of Bank 14 since it was right there and it fit) ... you may be on to something, I will have to see if I can make room and fit it in to 13 and see if that helps.

Additionally, Mateo, I would in fact be very interested in all of this! I believe, so far, the only changes I've made to trainers has been separating them from using Pokemon IDs, so I'm open to whatever other updates you may have.

UPDATE EDIT: Danny was right on the nose with that conclusion. I moved the following things out of Bank 13 to the end of Bank 12:

INCLUDE "data/mapHeaders/battlecenterm.asm"
INCLUDE "scripts/battlecenterm.asm"
INCLUDE "data/mapObjects/battlecenterm.asm"
BattleCenterMBlocks: INCBIN "maps/battlecenterm.blk"

INCLUDE "data/mapHeaders/tradecenterm.asm"
INCLUDE "scripts/tradecenterm.asm"
INCLUDE "data/mapObjects/tradecenterm.asm"
TradeCenterMBlocks: INCBIN "maps/tradecenterm.blk"

INCLUDE "engine/give_pokemon.asm"

INCLUDE "engine/predefs.asm"

...which allowed me to free up a whole lot of space in Bank 13 that I otherwise didn't have, and I assumed moving these would have no bad side effects. I then moved my pointers out of Bank 14 and in to the end of the pointer tables in Bank 13 and voila! it works! So, yay to that, at least. Would never have thought that would have been the case, since at least in the case of Pokemon, I've been able to load images from all sorts of different banks.

Last edited by KeiTaRo (2017-02-04 00:45:54)

Offline

#5 2017-02-04 21:30:42

Wild
New member
From: The Land Down Under
Registered: 2016-12-30
Post 7/9

Re: [pokered] "new" trainer class picture oddities

I myself was interested in making provision for Trainer images to be stored in any bank and attempted to modify LoadTrainerPic in Core.asm to read the Trainer Class, then search through a list that matches ID with the bank that the picture is stored in.

_LoadTrainerPic:
; wd033-wd034 contain pointer to pic
    ld a, [wTrainerPicPointer]
    ld e, a
    ld a, [wTrainerPicPointer + 1]
    ld d, a ; de contains pointer to trainer pic
    ld a, [wLinkState]
    and a
    ld a, [wTrainerClass] ; new code to find bank for trainer pics
    ld hl,TrainerImageBanksTable
    ld c,a
    ld b,0
    add hl, bc
    ld a, [hli]
    jr z, .loadSprite
    ld a, Bank(RedPicFront)
.loadSprite
    call UncompressSpriteFromDE
    ld de, vFrontPic
    ld a, $77
    ld c, a
    jp LoadUncompressedSpriteData
TrainerImageBanksTable:
    db BANK(YoungsterPic)  ; $01
    db BANK(BugCatcherPic) ; $02
    db BANK(LassPic)      ; $03
    db BANK(SailorPic)     ; $04
    db BANK(JrTrainerMPic) ; $05
    db BANK(JrTrainerFPic) ; $06
    db BANK(PokemaniacPic) ; $07
    db BANK(SuperNerdPic)  ; $08
    db BANK(HikerPic)      ; $09
    db BANK(BikerPic)      ; $0A
    db BANK(BurglarPic)    ; $0B
    db BANK(EngineerPic)   ; $0C
    db BANK(FisherPic)        ; $0E
    db BANK(SwimmerPic)       ; $0F
    db BANK(CueBallPic)      ; $10
    db BANK(GamblerPic)       ; $11
    db BANK(BeautyPic)        ; $12
    db BANK(PsychicPic)    ; $13
    db BANK(RockerPic)        ; $14
    db BANK(JugglerPic)       ; $15
    db BANK(TamerPic)         ; $16
    db BANK(BirdKeeperPic)   ; $17
    db BANK(BlackbeltPic)     ; $18
    db BANK(Rival1Pic)         ; $19
    db BANK(ScientistPic)     ; $1A
    db BANK(GiovanniPic)      ; $1B
    db BANK(RocketPic)        ; $1C
    db BANK(CooltrainerMPic) ; $1D
    db BANK(CooltrainerFPic) ; $1E
    db BANK(BrunoPic)         ; $1F
    db BANK(BrockPic)         ; $20
    db BANK(MistyPic)         ; $21
    db BANK(LtSurgePic)      ; $22
    db BANK(ErikaPic)         ; $23
    db BANK(KogaPic)          ; $24
    db BANK(BlainePic)        ; $25
    db BANK(SabrinaPic)       ; $26
    db BANK(GentlemanPic)     ; $27
    db BANK(Rival2Pic)         ; $28
    db BANK(Rival3Pic)         ; $29
    db BANK(LoreleiPic)       ; $2A
    db BANK(ChannelerPic)    ; $2B
    db BANK(AgathaPic)        ; $2C
    db BANK(LancePic)         ; $2D
    db BANK(FirebreatherPic)  ; $2E
    db BANK(BoarderPic)        ; $2F

The code works somewhat, but not consistently. I can move a chunk of images from bank 13 and put them into another bank and some show fine and others are either a garbled mess or crash the game. It also happens that sprites begin to become confused, with for example a Sailor shown instead of a Lass. I have gone over this quite a few times now and am quite stumped as to me the code looks sound!

Any help or advice on this would be greatly appreciated! It's a small thing but it's really bugging me. I'd also like to get to grips with using lists correctly, and this seemed like it would be an easy introduction...

Last edited by Wild (2017-02-04 21:47:19)

Offline

#6 2017-02-05 03:25:53

Mateo
Member
From: The Sims 4
Registered: 2009-11-25
Post 3,455/3,456

Re: [pokered] "new" trainer class picture oddities

As far as the actual "trainer pics can be anywhere" part of it, I did this: https://github.com/TheFakeMateo/RedPlus … b6c925b0e4

That also added the code for another custom trainer type, that would let you define another Sprite number and AI number for that trainer. So like if you wanted to make a trainer with one class name that looked like another, and had the AI of a third one, you could if you wanted to. And obviously some of those pointer entries are for classes/sprites that don't exist in vanilla Pokered, so keep that in mind.

That will work, but I cleaned up more after that, and a lot of other trainer changes came later. You can take a look at my engine/battle/read_trainer.asm to see how it reads a bunch of stuff, and at data/trainer_parties.asm to see how trainers look using my current format. Some of the other tables it references are pretty easy to find if you poke around in the data/ folder, too. Hopefully some of that helps you guys get started.

Offline

#7 2017-02-07 03:00:25

Danny-E 33
Administrator
Registered: 2012-06-09
Post 1,019/1,021

Re: [pokered] "new" trainer class picture oddities

Wild wrote:

The code works somewhat, but not consistently. I can move a chunk of images from bank 13 and put them into another bank and some show fine and others are either a garbled mess or crash the game. It also happens that sprites begin to become confused, with for example a Sailor shown instead of a Lass. I have gone over this quite a few times now and am quite stumped as to me the code looks sound!

You have to decrement the trainer ID by 1 when accessing the bank ID table, cause trainer IDs start at 01, but the first entry of the table is entry 00.

ld a, [wTrainerClass] ; new code to find bank for trainer pics
ld hl,TrainerImageBanksTable
dec a     ;  <--- add this line
ld c,a
ld b,0
add hl, bc
ld a, [hli]

Without decrementing by 1, you load the bank of the next trainer (which may or may not be the same bank that you want).


Red Hack: Pokémon Prototype

Total number of registered users: 7000+
Total number of active users: ~12

Offline

#8 2017-02-17 04:11:40

KeiTaRo
Member
Registered: 2015-12-05
Post 30/31
Website

Re: [pokered] "new" trainer class picture oddities

Argh. I tried to add Wild's new code, while also including Danny's fix, and I now have nothing but garbled images :( is there a step that wasn't included in that code that I'm missing? it compiles perfectly fine, it just doesn't show up correctly. I thought the code seemed pretty straight-forward...

Offline

#9 2017-02-17 16:27:14

Danny-E 33
Administrator
Registered: 2012-06-09
Post 1,021/1,021

Re: [pokered] "new" trainer class picture oddities

Well I can't say yet what I think the problem is.
What I suggest is using bgb's debugger to find the problem.

Open bgb and start your game. Then right-click in the middle of the game window and select Other->Debugger.
Then in the debugger window, click Debug->breakpoints. In the breakpoint window, put "_LoadTrainerPic" in the "PC =" box and click "Add".
Then play your game until you enter a battle and a trainer pic gets loaded. If the breakpoint was set up correctly, bgb should freeze at the beginning of that asm routine.
At that point, you can use F7 to step forward and only execute one asm instruction at a time. This allows you to observe the code flow (which calls and jumps are taken) and to observe the values in the registers between instructions. This way, you can identify the moment things start behaving differently from what you planned on or expected to happen.

Hopefully the problem is within _LoadTrainerPic but if you debug the whole routine and don't find the problem, it's certainly possible that the problem lies somewhere else.
Learning to use the debugger is definitely the most successful way to solve these kinds of problems. It's tricky to get comfortable with the debugger at first, but it is completely worth it.


Just a side note, when you put "_LoadTrainerPic" into the "PC =" box in the breakpoint window, that will only work if you have the "*.sym" file (that was generated by rgblink during assembly of the rom) in the same directory as the rom that is loaded in bgb.


Red Hack: Pokémon Prototype

Total number of registered users: 7000+
Total number of active users: ~12

Offline

#10 2017-02-18 22:06:24

Wild
New member
From: The Land Down Under
Registered: 2016-12-30
Post 8/9

Re: [pokered] "new" trainer class picture oddities

Thanks for your constructive comments guys.

Mateo, your updated trainer format is very interesting, I'll definitely be looking into adding more variation into the battle system in the near future, so I'm sure this will be very useful.

Danny, indeed, the problem was that I was reading one entry too high in the list, thanks for pointing that out. However, by decrementing a, it did not work properly for some reason. I therefore resorted to adding a padding byte to the start of the list and leaving a as it was:

TrainerImageBanksTable:
    db $00 ; PADDING
    db BANK(YoungsterPic)  ; $01
    db BANK(BugCatcherPic) ; $02
    db BANK(LassPic)      ; $03

KeiTaRo, does doing this solve your issue? If not, did you ensure that the TrainerImageBanksTable was added to the end of core.asm, or is being compiled separately into the same bank?

On a side note, could anyone recommend some reading that would go into more detail on the programming language that Pokered uses, z80 processor instructions if I remember correctly? Thanks!

Offline

Board footer

Powered by FluxBB