Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2016-12-03 23:27:47

Aria Hearts
New member
Registered: 2016-12-03
Post 1/9

Replacing Backsprites in Pokered

In some hacks I've noticed that there are zoomed out, 66 dimension sprites and curious on how to do that, I looked through the forum and found Danny-E 33's larger backsprite routine and using his three routines, it was a success! The images are now zoomed out but scrambled up, but when using a 66 dimension backsprite, it works fine, so that part is okay.

However, when I tried to replace the backsprites all at once, I get this error.

rgbasm -D _BLUE -h -o main_blue.o main.asm
C:\usr\local\bin\rgbasm.exe: Section 'Pics 1' is too big (old size 15971 + 537 > 16384)
make: *** [Makefile:41: main_blue.o] Error 1

It seems that some of the sprites from "Pics 1" in main.asm are too big, and I'm wondering how I can re-point it without making the game too heavy. I've checked the individual Pokemon asm files, and some do say "55" instead of "66" But I think that's more of a front sprite problem right?

I would greatly appreciate your help!

Offline

#2 2016-12-04 00:27:57

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

Re: Replacing Backsprites in Pokered

As you have noticed, when you modify the routines so that back pics are not zoomed in, 4x4 back pics no longer work correctly. You must use 6x6 pics.
Also, your assumption is correct that when a mon's base stats say "55" instead of "66" that is only referring to the front pic for that mon. The back pic is still 6x6 no matter what.

Since the Pics 1 section is too big, you have to move a handful of pics out of that bank and in to an empty bank.
Unfortunately, the routine that accesses back pics was not written well enough to allow you to simply move the pics.
You have to make modifications to 'UncompressMonSprite::' in home.asm such that the routine correctly accesses the new banks.

Here is the original routine:

; uncompresses the front or back sprite of the specified mon
; assumes the corresponding mon header is already loaded
; hl contains offset to sprite pointer ($b for front or $d for back)
UncompressMonSprite::
    ld bc,wMonHeader
    add hl,bc
    ld a,[hli]
    ld [wSpriteInputPtr],a    ; fetch sprite input pointer
    ld a,[hl]
    ld [wSpriteInputPtr+1],a
; define (by index number) the bank that a pokemon's image is in
; index = Mew, bank 1
; index = Kabutops fossil, bank $B
; index < $1F, bank 9
; $1F ≤ index < $4A, bank $A
; $4A ≤ index < $74, bank $B
; $74 ≤ index < $99, bank $C
; $99 ≤ index,       bank $D
    ld a,[wcf91] ; XXX name for this ram location
    ld b,a
    cp MEW
    ld a,BANK(MewPicFront)
    jr z,.GotBank
    ld a,b
    cp FOSSIL_KABUTOPS
    ld a,BANK(FossilKabutopsPic)
    jr z,.GotBank
    ld a,b
    cp TANGELA + 1
    ld a,BANK(TangelaPicFront)
    jr c,.GotBank
    ld a,b
    cp MOLTRES + 1
    ld a,BANK(MoltresPicFront)
    jr c,.GotBank
    ld a,b
    cp BEEDRILL + 2
    ld a,BANK(BeedrillPicFront)
    jr c,.GotBank
    ld a,b
    cp STARMIE + 1
    ld a,BANK(StarmiePicFront)
    jr c,.GotBank
    ld a,BANK(VictreebelPicFront)
.GotBank
    jp UncompressSpriteData

Try changing it to this:

; uncompresses the front or back sprite of the specified mon
; assumes the corresponding mon header is already loaded
; hl contains offset to sprite pointer ($b for front or $d for back)
UncompressMonSprite::
    ld bc,wMonHeader
    add hl,bc
    ld a,[hli]
    ld [wSpriteInputPtr],a    ; fetch sprite input pointer
    ld a,[hl]
    ld [wSpriteInputPtr+1],a
    ld a,[wcf91] ; XXX name for this ram location
    cp FOSSIL_KABUTOPS
    jr z,.RecallBank
    cp FOSSIL_AERODACTYL
    jr z,.RecallBank
    cp MON_GHOST
    jr z,.RecallBank
    ld a,[wMonHPicBank]
    jr .GotBank
.RecallBank
    ld a,BANK(FossilKabutopsPic)
.GotBank
    jp UncompressSpriteData

An important note about this new routine is that a mon's front pic must be in the same bank as its back pic.
Also, FossilKabutopsPic, FossilAerodactylPic, and GhostPic must all be in the same bank as each other, but it doesn't matter which one.

Then open wram.asm and find these lines:

wMonHLearnset:: ; d0cc
; bit field
    flag_array 50 + 5
    ds 1

And replace those lines with this:

wMonHLearnset:: ; d0cc
; bit field
    flag_array 50 + 5

wMonHPicBank:: ; d0d3
    ds 1

The last change you have to make is edit all files in the data/baseStats/ folder so that the last line is replaced with the mon's pic bank number. For example, the last line of data/baseStats/abra.asm is:

db 0 ; padding

And you need to replace it with this:

db BANK(AbraPicFront)

Every file in that folder has the exact same last line, except the last line of data/baseStats/mew.asm is:

db %11111111 ; usually spacing

But you should replace that line with mew's pic bank in the same way as the others.


Red Hack: Pokémon Prototype

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

Offline

#3 2016-12-30 03:40:58

Aria Hearts
New member
Registered: 2016-12-03
Post 2/9

Re: Replacing Backsprites in Pokered

Thank you for replying so fast! I really appreciate it.

I'm sorry I haven't been as active on the forums, finals and prep week came up when I was editing the lines of code. I have finally gotten around to making all the changes in the routine, however, it still gives me an error.

I went to into wram.asm and home.asm and quadruple checked that I changed everything precisely, all the lines in the files of the base stat folder are changed from:

db 0 ; padding

to:

db BANK(AbraPicFront)



This is the error I got when I tried "make blue" again:

$ make blue
rgbasm -D _BLUE -h -o main_blue.o main.asm
C:\usr\local\bin\rgbasm.exe: Section 'Pics 1' is too big (old size 15971 + 537 > 16384)
make: *** [Makefile:41: main_blue.o] Error 1

I have finished custom sprites that I will be using that only has the grey, light grey, white, and black palette that Red uses, I used the eyedropper tool from the old files to make sure it's the same "color". At the moment, however, I am currently using Mateo's Red ++ (151 Kanto) back sprites as a temporary resource.

Offline

#4 2016-12-30 19:49:35

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

Re: Replacing Backsprites in Pokered

Danny-E 33 wrote:

Since the Pics 1 section is too big, you have to move a handful of pics out of that bank and in to an empty bank.

...

An important note about this new routine is that a mon's front pic must be in the same bank as its back pic.
Also, FossilKabutopsPic, FossilAerodactylPic, and GhostPic must all be in the same bank as each other, but it doesn't matter which one.

I'm not sure you've done this step. All the instructions from my post are just a bunch of setup that allows for you to move pics out of there original banks successfully.
You still have to find `SECTION "Pics 1"` in main.asm and move some mon pics from there to a new bank.

To do this, I recommend defining PICS_6 at the top of main, below PICS_5:

PICS_6 EQU $2D

The at the bottom of main, add:

SECTION "Pics 6",ROMX,BANK[PICS_6]

Then paste the mon pics here that you removed from PICS_1.


Red Hack: Pokémon Prototype

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

Offline

#5 2016-12-30 22:05:58

Aria Hearts
New member
Registered: 2016-12-03
Post 3/9

Re: Replacing Backsprites in Pokered

Oh, yes! Thank you, the starter sprites and backsprites worked out perfectly.

Starters%20work_zpsm1rsucfs.png

Some of the graphics, however, did get a bit jumbled up, such as the Nidorino in the intro page.

Nidorino_zps8nlatinc.png

and the Player's back sprite:

Shey%20Jumbled_zpsvvxom0ok.png

The titlescreen worked out wonderfully as well:

Title1_zpscglgxmir.png

However, when I let it go idle for a bit, the next Pokemon doesn't load and after a while the game crashes.

Title2_zpsi0gtmon8.png

I was wondering what may be the cause of this.

Offline

#6 2016-12-30 23:07:38

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

Re: Replacing Backsprites in Pokered

I don't immediately know the problem. I would start by double checking Nidorino's base stats file, and double checking that both his front and back pic are in the same bank in main.asm.
You can do the same with the mons that aren't working on the title screen.

As for the player back pic, if you refer to the original thread, you will see that the player back pic is handled separately from mon back pics, so a few different routines need to be modified.


Red Hack: Pokémon Prototype

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

Offline

#7 2016-12-31 06:59:25

Aria Hearts
New member
Registered: 2016-12-03
Post 4/9

Re: Replacing Backsprites in Pokered

Oh yeah, there is a separate routine in the core.asm folder I have to check up on right? I've looked through both the original thread and the pastebin url from the Backsprite Routine Thread and noticed a few patterns. Using the patterns, I'm guessing that the address "6CD5" is in the function "LoadPlayerBackPic", "7BC8" is "LoadBackSpriteUnzoomed", "16EA" was "InterlaceMergeSpriteBuffers", and "9310 is vBackPic". I'm kinda stuck on what changing the 5 bytes at "LoadPlayerBackPic"/"6CA3" means, however.

I'm guessing this line:

ld 7BC8
00
00

means something like:

call LoadBackSpriteUnzoomed

"ld" loads the address at 7BC8 and since that is similar to the function LoadBackSpriteUnzoomed, I think "ld" means it can "call" it. I'm not sure too sure what the 00's mean though.

Do these have to do with how the tiles are arranged?

OAM%20Tiles_zps2osvsoh7.jpg

As for the Pokemon sprites, I checked every file in the baseStats folder and made sure it has db BANK(NamePicFront) I did "comment" out the "db 0 ; padding" instead of deleting it using a semicolon though. But I don't think that's what's causing it since all the files that worked in Pics 1 use the same routine.

Nidorino%20pic%20insert_zpsnc5gxhlc.jpg

I've also checked the Nidorino files and the front and back are all in the same group. I'm using a bit of Mateo's organization from Red++ as a reference to see what they did.

FrontBack_zpsjoklrmgx.jpg

I also found out that Clefairy is in there too. Luckily, I recently did a Fairy, Steel, and Dark type test and put Clefairy, Magnemite, and (Dark) Rattata in the wild before importing the pictures in. The type test worked and I decided to leave the three in the wild because I haven't figured out the terrain for the route yet. Fortunately, this is a good place to start testing out what the cause of this bug is.  Clefairy is in Pics 2, Magnemite is in Pics 4, and Rattata is in Pics 1.

I walked in the grass and found a Clefairy, which is in the group Pics 2, this is where the Nidorino was from. The battle screen was black for a few seconds longer than usual, the game lagged a bit, then it shows the glitched up sprite. I can still control the menu.

Clefairy%20Glitch_zpsdrrvioyt.png

Next I ran into a Rattata, which is from Pics 1. This one seems to run smoothly. The Pics 1 group imports Bulbasaur to Pikachu, which is why Beedrill doesn't look jumbled up.

Rattata%20okay_zps70t9agck.png

The next Pokemon I've encountered was a Magnemite, which is further down the list at Pics 4. This one glitched the most, it was doing its cry extremely slowly and distorted and I couldn't control the game anymore, I had to reset.

Magnemite%20Glitch_zps3tbirqeq.png

This also happens in the opening title screen too. The Pokemon in the opening screen that are from Pics 1, such as Beedrill, are also shown exactly like the PNG files, however, as we go down further to Pics 4, the game starts to slow down, the sprites in other groups jumble up, and then the game crashes after letting it go idle for a while.

I think this issue might have to do something with the main.asm, however, I'm not too sure where to start.

I have to thank you again for helping me so much Danny, I really appreciate it! I can't stress that enough. I'm new to the whole ASM thing so I'm experimenting a lot and I really appreciate all the help I can get.

Offline

#8 2016-12-31 08:27:58

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

Re: Replacing Backsprites in Pokered

Ah. the "ld 7BC8" seems to be an awful typo on my part. In my defense, this was over 4 years ago and I was very new at assembly and I was hex editing my hack, not using the disassembly yet.

What I was doing was documenting the bytes I was typing in to the hex editor.
The assembly instructions I was referring to were:

call $7bc8
nop
nop

And the byte values I meant to type in that post were:

CD C8 7B
00
00

The opcode for the `call` instruction is $cd and the address, $7bc8, is written in little endian in the rom.
I messed that up bad. My apologies. Of course, I typed it correctly into the hex editor, so I never noticed the error in the forum post.

$00 is the opcode for `nop`. This was necessary back then because I was hex editing and I couldn't easily shift large sections of an asm routine, so I padded with 00's when I "shrunk" part of a routine. You don't have to do this in the disassembly.

Your other problem regarding mon pics.. If every mon in Pics 1 is working and no mon from any other pic bank is working, then I suspect something is wrong with UncompressMonSprite in home.asm. Are you sure you modified it correctly?


Red Hack: Pokémon Prototype

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

Offline

#9 2017-01-01 00:24:52

Aria Hearts
New member
Registered: 2016-12-03
Post 5/9

Re: Replacing Backsprites in Pokered

I'm sorry, I'm still a bit lost at the moment. I have replaced "$7bc8" as the function "LoadBackSpriteUnzoomed" like it is on the pastebin. I took a look at the board and the pastebin again to investigate what I'm doing and my sprite is still jumbled up. I also tried putting the "nop"s in too, just in case. So I written every step down to document the steps I need to take.

ASM                               Hex


LoadPlayerBackPic                 ;F: 6CA3
    ld a, 0C                      ;ld a,[BattleType]
...
.next                             ;call 36EB
    ld a, Bank(RedPicBack)        ;ld a, 03 "Loads RedPicBack onto the accumulator"
    call UncompressSpriteFromDE   ;"This wasn't omitted out in the Pastebin"
    ;predef ScaleSpriteByTwo?     ;(omitted) cd 6D 3F     
    call LoadBackSpriteUnzoomed   ;cd C8 7B
    ;nop                          ;00  "Not needed for assembly"
    ;nop                          ;00
    ld hl, wOAMBuffer             ;ld hl, C300 "Not sure what OAMBuffer quite does"
    xor a                         ;xor a "ld a, 0"
    ld [hOAMTile], a              ;ld (FF00+8B), a
    ld b, $7                      ;ld b, 07 "Loads $7 onto b"
    ld e, $a0                     ;ld e, A0 "Loads $a0 onto e"
.loop
    ld c, 03                      ;ld c, 03
    ld d, 38                      ;ld d, 38
.innerLoop
    ld [hl], d                    ;ld [hl], d
    inc hl                        ;ld hl
    ld [hl],e                     ;ld [hl],e   "put the values 38 and A0 at 0xC300 and 0x C301, respectively"
    ld a, $8                      ;ld a, 08
    add d                         ;add d
    ld d,a                        ;ld d,a
    inc hl                        ;inc hl
    ld, a, [hOAMTile]             ;ld a, (FF00+8B)
    ldi [hl], a                   ;ldi [hl], a
    inc a                         ;inc a
    ld, [hOAMTile], a             ;ld (FF00+8B), a
    inc hl                        ;inc hl
    dec c                         ;dec c
    jr nz, .innerloop             ;jr nz, 6CB6

LoadBackSpriteUnzoomed:           ;F: 7BC8
    ld a, $66                     ;ld, a 66
    ld de, vBackPic               ;ld de, 9310
    push de                       ;push de
    jp LoadUncompressedBackSprite ;jp (address most likely 1848)

This is how the routines look like:

LoadPlayerBackPic:

Routine1_zpsacop3lj5.jpg

LoadBackSpriteUnzoomed:

Routine2_zpswqpau2yj.jpg

LoadUncompressedBackSprite:

Routine3_zpsahsvpmdw.jpg

I also got rid of "call UncompressSpriteFromDE" to see what would happen and got this:

NoUncompressSpriteDE_zpscrypnbyl.png

I also designated which byte I want the pics to be in on the top of the main.asm.
All%20the%20pics_zpsmefqvho0.jpg

RedPicBack and OldManPic is in "Pics 7".

Pics%207_zpsora1vjta.jpg


I was wondering if this might the game is glitching out. I'm not sure where to start to fix this issue.

As for the UncompressMonSprite, I semicoloned the things I needed to delete, and when I deleted the semicoloned text, it has the same effect.

Here's how the UncompressMonSprite function looks like:
UncompressMonSprite%20Part1_zpsiavmwhfj.jpg
UncompressMonSprite%20Part2_zpspk0wegnu.jpg

Offline

#10 2017-01-01 20:33:09

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

Re: Replacing Backsprites in Pokered

What is the size of the player back pic you are using?

As for Clefairy, Magnemite, etc., I would put a break point in bgb on UncompressMonSprite and see what bank number is returned at the end.

If you want, you can send me a zip of your repo and I can take a look at it.


Red Hack: Pokémon Prototype

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

Offline

#11 2017-01-03 05:41:20

Aria Hearts
New member
Registered: 2016-12-03
Post 6/9

Re: Replacing Backsprites in Pokered

Oh! It was the wrong dimension for the RedPicBack sprite. I used the front picture's dimensions for the backpic without realizing it wasn't 48x48. I thought it looked a little big. Here's how it looks like now! Thank you so much! This really means a lot.

It%20Works_zpsgibkausa.png?t=1483333523

As for the Clefairy and Magnemite situation, I'm not sure how to put a break point in bgb. I have the program, but I'm not quite sure how to use it. Do you have a tutorial about to do this or can you show me what needs to be done?

I'll email you the repo. I'm Heartsaria@gmail.com. And you're 33Dannye right?

Offline

#12 2017-01-03 06:53:07

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

Re: Replacing Backsprites in Pokered

I found it.

In data/baseStats/arbok.asm you didn't comment out the 00 padding byte, so the calculation of base stats addresses were off by one for all mon after Arbok.

db 0 ; padding
db BANK(ArbokPicFront)

Red Hack: Pokémon Prototype

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

Offline

#13 2017-01-03 21:41:26

Aria Hearts
New member
Registered: 2016-12-03
Post 7/9

Re: Replacing Backsprites in Pokered

ndvslknadspovpomn I thought I checked everything but I overlooked one of the very first Pokemon in the sprite files.

I can't thank you enough, Danny. You are amazing! Thank you so much.

Offline

#14 2017-01-04 00:44:14

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

Re: Replacing Backsprites in Pokered

No problem.

The way I did this in bgb was by putting a breakpoint on many functions involved in loading mon pics, such as UncompressMonSprite, LoadFrontSpriteByMonIndex, LoadTitleMonSprite etc., then stepped through the functions until I found out which one was behaving incorrectly.

To do this in bgb, right click in the game window and select Other->Debugger. In the debugger window, select Debug->breakpoints to bring up the breakpoint window.
If you keep the .sym file in the same directory as the .gbc file, you can put labels into the breakpoint window and it will fill in the address for you, which is super helpful.
After putting a breakpoint at LoadTitleMonSprite, I wait for the title screen to come up and for it to break at the beginning of the routine, then press F7 to step one instruction at a time. This lets you observe register and memory values in between instructions, which as you could guess, helps you discover exactly when things start going wrong.

LoadTitleMonSprite calls GetMonHeader, which loads the current mon's base stats from rom to ram by calling CopyData. It was inside CopyData that I noticed for Pokemon on the title screen like Clefable, it was copying the wrong segment of memory (it was certainly not starting at the beginning of a mon's base stats). But if Bulbasaur, Ivysaur etc. work fine, then that tells me some mon in between has base stats which are not $1c bytes long.
So in bgb's memory view (the bottom window inside the debugger) I started at the beginning of Bulbasaur's base stats and went forward $1c bytes at a time to find when they stopped "lining up". Then I knew to proofread Arbok's base stats file.


Red Hack: Pokémon Prototype

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

Offline

Board footer

Powered by FluxBB