teremochek wrote:
Movax12 wrote:
Unfortunately there is no room left in the ROM. If you want to add code you're going to have to figure out what you can remove or a way to add banks.
If I add a bank, then the new code will work with your code?
What is better to remove the code inside?
Another question. Which program is better to edit the code?
Or you can do what I did when I added SMB2J stuff to my SMB1 for FDS: Remove residual code. Here are some places that code can be removed, also some other ways to save space; if you follow my advice, you'll get roughly 250 free bytes (note that not everything labeled in the disassembly as 'residual' are really residual; the ones I listed are proven residual):
Code:
;In "PrintVictoryMessages:", remove these
cmp #$09
bcs IncMsgCounter
;In "Palette1_MTiles:" remove these
.db $24, $2f, $24, $3d ;flag ball (residual object)
;In "WaterPipe:" remove this:
ldy AreaObjectLength,x
;In "ScrollScreen:" remove this
sta ScrollIntervalTimer
;In "FlagpoleSlide:" remove these
cmp #FlagpoleFlagObject
bne NoFPObj
;In "NoFPObj:" remove this
inc GameEngineSubroutine
;In "UseMiscS" remove this
sty JumpCoinMiscOffset
;In "MovePlatformUp:" remove these
cpy #$29
lda #$09
;In "CheckEndofBuffer" remove all these
iny
lda (EnemyData),y
and #%00111111
cmp #$2e
beq CheckRightBounds
;In "SetupGFB" remove this
jsr GetFirebarPosition
;In "BPGet:" remove these
lda FlyCCBPriority,y
sta Enemy_SprAttrib,x
;In "DrawFlameLoop:" remove this
sta Sprite_Y_Position+12,y
;In "FirebarSpin:" remove
ldy #$18
;In "SpinCounterClockwise:" remove
ldy #$08
;In "RightPlatform:" remove
sta $00
;Remove "ResidualXSpdData:" completely
;In "CheckToAnimateEnemy:" remove this
iny
;In "DrawBrickChunks:" remove
lda #$75
;In "PowerUpGrabFreqData:" remove these at the end
.db $22, $1c, $14
;In "FindAreaMusicHeader:" remove this
sty MusicOffset_Square2
;Remove "ResidualHeaderData:" completely
Code:
;Did you know you could get 16 free bytes from changing lda BrickShatterEnvData,y in "ContinueBrickShatter:" to "lda BowserFlameEnvData,y"? They both make the same SFX but now you have 16 free bytes where the data used to be!
Optimize the following routine to get another 32 bytes:
Code:
;This is the original routine
SetPlatformTilenum:
ldx ObjectOffset
iny
jsr DumpSixSpr
lda #$02
iny
jsr DumpSixSpr
inx
jsr GetXOffscreenBits
dex
ldy Enemy_SprDataOffset,x
asl
pha
bcc SChk2
lda #$f8
sta Sprite_Y_Position,y
SChk2: pla
asl
pha
bcc SChk3
lda #$f8
sta Sprite_Y_Position+4,y
SChk3: pla
asl
pha
bcc SChk4
lda #$f8
sta Sprite_Y_Position+8,y
SChk4: pla
asl
pha
bcc SChk5
lda #$f8
sta Sprite_Y_Position+12,y
SChk5: pla
asl
pha
bcc SChk6
lda #$f8
sta Sprite_Y_Position+16,y
SChk6: pla
asl
bcc SLChk
lda #$f8
sta Sprite_Y_Position+20,y
SLChk: lda Enemy_OffscreenBits
asl
bcc ExDLPl
jsr MoveSixSpritesOffscreen
ExDLPl: rts
;okay, now change it to this:
SetPlatformTilenum:
ldx ObjectOffset
iny
jsr DumpSixSpr
lda #$02
iny
jsr DumpSixSpr
inx
jsr GetXOffscreenBits
dex
ldy Enemy_SprDataOffset,x
ldx #$06
SChk: asl
bcc SChkNx
pha
lda #$f8
sta Sprite_Y_Position,y
pla
SChkNx: iny
iny
iny
iny
dex
bne SChk
ldx ObjectOffset
tya
sec
sbc #$18
tay
lda Enemy_OffscreenBits
asl
bcc ExDLPl
jsr MoveSixSpritesOffscreen
ExDLPl: rts
There are many more ways to clear up free space. This next method will get you about 150 free bytes:
SMB1 was very wasteful with level data. For example look at this:
^The above leftmost brick can be made to a horizontal brick length 4 and the rightmost brick can be removed (see below). This can be done with various objects in ALL levels/rooms to save space while functioning the same.
The above trick can also be done with enemies while function the same, too. See below.
Before:
After:
Notice that I changed it from a 'Little Goomba' to a '2 Little Goomba (V=10).
With the above, counting every possible level, you get around 150 free bytes this way. I hope this was helpful instead of having to convert this from NROM to MMC3 and extra routines. 200 or so free bytes is a lot of free space to make many routines.
EDIT: Here is another code that can be optimized.
Code:
;Original code
CheckPlayerVertical:
lda Player_OffscreenBits
cmp #$f0
bcs ExCPV
ldy Player_Y_HighPos
dey
bne ExCPV
lda Player_Y_Position
cmp #$d0
ExCPV: rts
;Optimized code
CheckPlayerVertical:
lda Player_OffscreenBits
and #$f0
clc
beq ExCPV
sec
ExCPV: rts
;you've saved 7 bytes
EDIT2: Also, remove anything labeled as "free space" etc. They will always be bytes of $FF. They are scattered throughout the file and will add up to another 20 or so free bytes.
EDIT3: Make sure that the assembled binary file is no GREATER or LESS than 32,768 bytes. Whenever you add or minus code, you need to pad it or else there will be trouble. I can tell you are new to this. My advice is use something like Notepad++ that tells you the line numbers for when the assembler shoots out a "value out of range" or a line with an error or what not.
EDIT4: Here's one more that's easy to miss. The underwater level has a room pointer to World 3 that's never used. (Room pointers always take 3 bytes). So removing it will give you three more. I just mentioned this because this one was hard to find. But the other wasteful ones are easy.