You are not logged in.
I'm messing around with the pokecrystal pokedex trying to add in the ability to switch colors, similarly to how the options menu allows you change the borders. I've been able to implement a screen that has the options, but every attempt at giving setting the options to do something crashes the game.
In engine\pokedex\pokedex.asm I've got:
.MenuAction_Red ld hl, wPokedexColor ; loads ram byte into hl bit 0, [hl] ; checks if its already red jr z, .setRed ; get out if its already red res 0, [hl] ; reset bit set 1, [hl] ; set hl to red .setRed ret .MenuAction_Blue ld hl, wPokedexColor ; loads ram byte into hl bit 1, [hl] ; checks if its already blue jr nz, .setBlue ; get out if its already blue ld a, [hl] ; loads hl (ram byte) into a xor a ; clears a ld [hl], a ; pass cleared a back to hl set 1, [hl] ; set hl to blue .setBlue ret
wPokedColor is the ram byte I created to hold the selected color byte. Also this is only two of the options, specifically the two versions of code i tried.
then in enigine\gfx\cgb_layouts.asm I've got:
_CGB_Pokedex: ld de, wBGPals1 ld a, [wPokedexColor] call GetandDrawPokedexColor call GetPredefPal call LoadHLPaletteIntoDE ; dex interface palette ld a, [wCurPartySpecies] cp $ff jr nz, .is_pokemon ld hl, .PokedexQuestionMarkPalette call LoadHLPaletteIntoDE ; green question mark palette jr .got_palette
This is just what colors the main the pokedex screen, but instead of it just a with a predefpal, I wanted it to load a with wPokedexColor and then run another function to determine which of those bits is set to determine the loaded color.
; holds wPokedexColor in a, while h grabs the palette, ; then passes it to a before returning, h is used to check the bit GetandDrawPokedexColor: ld l, $0 ld h, PREDEFPAL_POKEDEX ; gives h the first palette and a ; check if only the first bit is set jr nz, .set ; jp if its not zero .loop inc h inc l and a jr z, .loop .set ld a, h ret
as the comments say, my attempt was to load l with 0 and h with the first palette (original pokedex color) then compare it to a, then if it was set to red, it just passes h to a and returns to _CGB_Pokedex with that, if not if loops through incrementing h and l till the check yields not 0 and leaves.
I should mention that this is also my first attempt at writing some custom code for pokecrystal, so I'm sure there's much better ways of attempting this.
Last edited by NobodySociety (2020-01-09 16:43:58)
What's going on in the loop of GetandDrawPokedexColor? You are checking a again without having updated it, and there is no way to jump back to .loop.
Whoops. I typoed that line. I'll update the op. The logic on a was it would remain what was in wPokedexColor until the loop found the set bit, updating h (with the palette) along the way.
Ok so turns out I was super overthinking it.
I added this to constants\wram_constants.asm
const_def const DEXCOLOR_RED const DEXCOLOR_BLUE const DEXCOLOR_PURPLE const DEXCOLOR_BROWN const DEXCOLOR_GREEN const DEXCOLOR_PINK const DEXCOLOR_YELLOW
I modified the menu actions in engine\pokedex\pokedex.asm
UPDATE: Figured out how to force it to update on the spot.
.MenuAction_Red ld b, DEXCOLOR_RED jr .ChangeColor .MenuAction_Blue ld b, DEXCOLOR_BLUE jr .ChangeColor .MenuAction_Purple ld b, DEXCOLOR_PURPLE jr .ChangeColor .MenuAction_Brown ld b, DEXCOLOR_BROWN jr .ChangeColor .MenuAction_Green ld b, DEXCOLOR_GREEN jr .ChangeColor .MenuAction_Pink ld b, DEXCOLOR_PINK jr .ChangeColor .MenuAction_Yellow ld b, DEXCOLOR_YELLOW .ChangeColor: ld a, [wCurPokedexColor] cp b jr z, .skip_changing_color ; Skip if new mode is same as current. ld a, b ld [wCurPokedexColor], a .skip_changing_color call Pokedex_BlackOutBG ld a, DEXSTATE_COLOR_OPTION ld [wJumptableIndex], a ret
This sets wPokedexColor to the proper bit.
Then in engine\gfx\cgb_layouts.asm i changed _CGB_Pokedex to
_CGB_Pokedex: ld de, wBGPals1 ld a, [wCurPokedexColor] cp DEXCOLOR_BLUE jr nz, .Purple ld a, PREDEFPAL_RB_CYANMON jr .setColor .Purple cp DEXCOLOR_PURPLE jr nz, .Brown ld a, PREDEFPAL_RB_PURPLEMON jr .setColor .Brown cp DEXCOLOR_BROWN jr nz, .Green ld a, PREDEFPAL_RB_BROWNMON jr .setColor .Green cp DEXCOLOR_GREEN jr nz, .Pink ld a, PREDEFPAL_RB_GREENMON jr .setColor .Pink cp DEXCOLOR_PINK jr nz, .Yellow ld a, PREDEFPAL_RB_PINKMON jr .setColor .Yellow cp DEXCOLOR_YELLOW jr nz, .Red ld a, PREDEFPAL_RB_YELLOWMON jr .setColor .Red ld a, PREDEFPAL_POKEDEX .setColor call GetPredefPal call LoadHLPaletteIntoDE ; dex interface palette ld a, [wCurPartySpecies] cp $ff jr nz, .is_pokemon ld hl, .PokedexQuestionMarkPalette call LoadHLPaletteIntoDE ; green question mark palette jr .got_palette
There is still some stuff to hammer out, like I'm sure there's a way to optimize this but I'm not quite sure how to go about doing that.
UPDATE 2: Figured out the color reset issue, changed the location of the ram byte. Now it all works as expected.
Last edited by NobodySociety (2020-01-12 00:01:56)