ROM building glitch?

Discussion in 'Discussion and Q&A Archive' started by redhotsonic, Feb 16, 2012.

Thread Status:
Not open for further replies.
  1. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Here I am again, another problem, probably the weirdest one yet, but it gets rid of a lot of bugs! Any help would be most grateful!


    You can skip this story (spoiler) if you like and get on with the real problem.

    I have put Sonic 3 sprites in my game, so as you could imagine, the Sonic running across the SEGA logo went wrong. I couldn't be bothered to fix it. But later on, I put RHS in the game, and he uses the traditional Sonic 2 sprites. So, I thought I would fix Sonic at the SEGA logo. I made it load RHS's art, his running DPLC's and mappings, but no matter what I tried, it never worked.


    Here are some codes that I've done, can you see where I went wrong?


    You might want to read about the problem I have first before looking into depth about this code



    Code:
    ; ===========================================================================
    
    ; ----------------------------------------------------------------------------
    
    ; Object B0 - SEGA screen? (Unknown)
    
    ; ----------------------------------------------------------------------------
    
    
    
    ; Sprite_3A1DC:
    
    ObjB0:
    
    moveq #0,d0
    
    move.b routine(a0),d0
    
    move.w off_3A1EA(pc,d0.w),d1
    
    jmp off_3A1EA(pc,d1.w)
    
    
    
    ; ===========================================================================
    
    
    
    off_3A1EA:
    
    dc.w loc_3A1F6-off_3A1EA
    
    dc.w loc_3A2F4-off_3A1EA; 1
    
    dc.w loc_3A32C-off_3A1EA; 2
    
    dc.w loc_3A396-off_3A1EA; 3
    
    dc.w loc_3A3CC-off_3A1EA; 4
    
    dc.w return_3A3F6-off_3A1EA; 5
    
    
    
    ; ===========================================================================
    
    
    
    loc_3A1F6:
    
    bsr.w LoadSubObject
    
    move.w #$1E8,x_pos(a0)
    
    move.w #$F0,objoff_A(a0)
    
    move.w #$B,objoff_2A(a0)
    
    move.w #2,($FFFFF662).w
    
    bset #0,render_flags(a0)
    
    bset #0,status(a0)
    
    lea ($FFFFE138).w,a1
    
    lea byte_3A76C(pc),a2
    
    moveq #0,d0
    
    moveq #$22,d6
    
    
    
    loc_3A22A:
    
    move.b (a2)+,d0
    
    add.w d0,(a1)
    
    addq.w #8,a1
    
    dbf d6,loc_3A22A
    
    lea off_3A294(pc),a1
    
    ; lea (ArtUnc_Sonic).l,a3
    
      lea (ArtUnc_S2sonicart).l,a3
    
    conloc_3A22A:
    
    lea (Metablock_Table).l,a5
    
    moveq #3,d5
    
    
    
    ; etc, etc




    Code:
    ; ===========================================================================
    
    ; These next four things are pointers to Sonic's dereferenced
    
    ; DPLC entries of his "running animation" frames for the SEGA screen.
    
    ; I want that DPLC data split into a binary file for use with editors,
    
    ; but unfortunately there's no way to refer to BINCLUDE'd bytes
    
    ; from within AS, so I put an educated guess (default) here and
    
    ; run an external program (fixpointer.exe) to fix it later.
    
    ; WARNING: the build script needs editing if you rename this label
    
    
    
    ;off_3A294:
    
    ; dc.l (MapRUnc_Sonic+$33A) ;dc.l word_7181A
    
    ; dc.l (MapRUnc_Sonic+$340) ;dc.l word_71820
    
    ; dc.l (MapRUnc_Sonic+$346) ;dc.l word_71826
    
    ;  dc.l (MapRUnc_Sonic+$34C) ;dc.l word_7182C
    
    
    
    off_3A294: dc.l MapRUnc_RHS_2DE  ; 0 ; DATA XREF: h+232C0t h+23324o ...
    
      dc.l MapRUnc_RHS_2E4  ; 1
    
      dc.l MapRUnc_RHS_2EA  ; 2
    
      dc.l MapRUnc_RHS_2F0  ; 3
    
    ; The above is RHS's running DPLC's, I've trippled checked
    
    
    
    word_3A2A4:
    
    dc.w $FFFF,	0,$FFFF, $B00, $201
    
    dc.w $FFFF,  $C0,$FFFF, $E00, $303; 5
    
    dc.w $FFFF, $2C0,$FFFF,$1600, $201; 10
    
    dc.w $FFFF, $380,$FFFF,$1900, $303; 15
    
    dc.w $FFFF, $580,$FFFF,$2100, $201; 20
    
    dc.w $FFFF, $640,$FFFF,$2400, $303; 25
    
    dc.w $FFFF, $840,$FFFF,$2C00, $201; 30
    
    dc.w $FFFF, $900,$FFFF,$2F00, $303; 35




    Code:
    ; ------------------------------------------------------------------------------
    
    ; sprite mappings
    
    ; Gigantic Sonic (2x size) mappings for the SEGA screen
    
    ; ------------------------------------------------------------------------------
    
    ;ObjB1_MapUnc_3A5A6: BINCLUDE "S3Sonic/mapsega.bin"
    
    ;ObjB1_MapUnc_3A5A6:
    
    ; BINCLUDE "mappings/sprite/objB1.bin" ;try thisArtUnc_3A5A6
    
    ArtUnc_3A5A6:	; DATA XREF: h+23616o h+23620o ...
    
      dc.w word_3A5B0-ArtUnc_3A5A6; 0
    
      dc.w word_3A5E2-ArtUnc_3A5A6; 1
    
      dc.w word_3A614-ArtUnc_3A5A6; 2
    
      dc.w word_3A646-ArtUnc_3A5A6; 3
    
      dc.w word_3A678-ArtUnc_3A5A6; 4
    
    word_3A5B0: dc.w 6   ; DATA XREF: h+23632o
    
      dc.w $D80F,	0,	0,$FFF0; 0
    
      dc.w $D807,  $10,	8,  $10; 4
    
      dc.w $F80F,  $18,   $C,$FFE0; 8
    
      dc.w $180F,  $28,  $14,$FFE0; 12
    
      dc.w $F80F,  $38,  $1C,	0; 16
    
      dc.w $180F,  $48,  $24,	0; 20
    
    word_3A5E2: dc.w 6   ; DATA XREF: h+23632o
    
      dc.w $D80F,  $58,  $2C,$FFF0; 0
    
      dc.w $D807,  $68,  $34,  $10; 4
    
      dc.w $F80F,  $70,  $38,$FFE0; 8
    
      dc.w $180F,  $80,  $40,$FFE0; 12
    
      dc.w $F80F,  $90,  $48,	0; 16
    
      dc.w $180F,  $A0,  $50,	0; 20
    
    word_3A614: dc.w 6   ; DATA XREF: h+23632o
    
      dc.w $D80F,  $B0,  $58,$FFF0; 0
    
      dc.w $D807,  $C0,  $60,  $10; 4
    
      dc.w $F80F,  $C8,  $64,$FFE0; 8
    
      dc.w $180F,  $D8,  $6C,$FFE0; 12
    
      dc.w $F80F,  $E8,  $74,	0; 16
    
      dc.w $180F,  $F8,  $7C,	0; 20
    
    word_3A646: dc.w 6   ; DATA XREF: h+23632o
    
      dc.w $D80F, $108,  $84,$FFF0; 0
    
      dc.w $D807, $118,  $8C,  $10; 4
    
      dc.w $F80F, $120,  $90,$FFE0; 8
    
      dc.w $180F, $130,  $98,$FFE0; 12
    
      dc.w $F80F, $140,  $A0,	0; 16
    
      dc.w $180F, $150,  $A8,	0; 20
    
    word_3A678: dc.w 2   ; DATA XREF: h+23632o
    
      dc.w $FC00,	0,	0,$FFF8; 0
    
      dc.w $FC00,	0,	0,	0; 4
    
      even
    sprite glitching (well I played through my whole ROM twice this way and never came across it, even by going to the places it normally happens, it was fine).





    Here is a video demonstrating what I am trying to say. As you can see, after if finally opens the ROM, Sonic is there. Resetting the ROM still shows Sonic (as you can see) But when I close the ROM then reload the same ROM, Sonic has gone again. Resetting the ROM stills shows no Sonic.



    Sorry for the crap sound and video quality, the video freezes at the 0:13 point for a second for some reason





    Has anyone else ever encountered this bug and no how to fix it? I'd greatly appreciate it.



    P.S I do have this





    Code:
    ;---------------------------------------------------------------------------------------
    
    ;Uncompressed art
    
    ;
    
    ;Patterns for Sonic 2
    
    ;---------------------------------------------------------------------------------------
    
    align $20000
    
    ArtUnc_S2sonicart:	 BINCLUDE "artuncompressedRHSart.bin"

    With the alignment, Sonic isn't there. Without the alignment, there's garbled "Knuckles" sprites.


    [​IMG]


    Loading the ROM quickly with $20000 alignment


    [​IMG]


    Loading the ROM anytime with $20000 alignment


    [​IMG]


    Loading the ROM quickly without alignment


    [​IMG]


    Loading the ROM anytime without alignment


    Cheers,


    redhotsonic


    EDIT: Forgot to mention, I'm using Xenowhirl's 2007 disassembly.
     
    Last edited by a moderator: Feb 17, 2012
  2. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    I'm really no expert, but maybe a problem with the beginning of the rom or its end?


    Could you post what's from the beginning of your disassembly till the "errortrap:" routine?


    How's the end btw? "EndOfRom: END"?
     
  3. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Once I plunked in S3's sprites, iirc I added 'even' instead of align and that helped it load up for me. Without that it would lock up...
     
  4. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England




    Sure:



    Beginning of ASM:



    Code:
    ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    ; start of ROM
    
    StartOfRom:
    
    if * <> 0
    
    fatal "StartOfRom was ${*} but it should be 0"
    
    endif
    
    ;Vectors:
    
    dc.l System_Stack, EntryPoint, ErrorTrap, ErrorTrap; 4
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 8
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 12
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 16
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 20
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 24
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 28
    
    dc.l H_Int, ErrorTrap, V_Int, ErrorTrap; 32
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 36
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 40
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 44
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 48
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 52
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 56
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 60
    
    dc.l ErrorTrap, ErrorTrap, ErrorTrap, ErrorTrap; 64
    
    ; byte_200:
    
    Header:
    
    dc.b "SEGA GENESIS " ; Console name
    
    dc.b "(C)SEGA 1992.SEP" ; Copyright/Date
    
    dc.b "SONIC 2 RECREATION BETA REDHOTSONIC DATE28/01/12" ; Domestic name
    
    dc.b "SONIC 2 RECREATION BETA REDHOTSONIC DATE28/01/12" ; International name
    
    dc.b "GM 00001051-01" ; Version
    
    ; word_18E
    
    Checksum:
    
    dc.w $D951 ; Checksum (patched later if incorrect)
    
    dc.b "J " ; I/O Support
    
    dc.l StartOfRom ; ROM Start
    
    ; dword_1A4
    
    ROMEndLoc:
    
    dc.l EndOfRom-1 ; ROM End
    
    dc.l $FF0000 ; RAM Start
    
    dc.l $FFFFFF ; RAM End
    
    dc.b " " ; Backup RAM ID
    
    dc.l $20202020 ; Backup RAM start address
    
    dc.l $20202020 ; Backup RAM end address
    
    dc.b " " ; Modem support
    
    dc.b " " ; Notes
    
    dc.b "JUE " ; Country
    
    EndOfHeader:
    
    ; ===========================================================================
    
    ; Crash/Freeze the 68000. Note that the Z80 continues to run, so the music keeps playing.
    
    ; loc_200:
    
    ErrorTrap:
    
    nop
    
    nop
    
    bra.s ErrorTrap




    End of ASM:



    Code:
     align $20000
    
    ArtUnc_S2sonicart: BINCLUDE "artuncompressedRHSart.bin"
    
    
    
    Nem_LevSel: binclude "LS_BG/GFX2.bin"
    
    even
    
    
    
    Eni_LevSel: binclude "LS_BG/Map2.bin"
    
    even
    
    
    
    Pal_LevSel: binclude "LS_BG/Pal2.bin"
    
    even
    
    
    
    ;==========================
    
    
    
    EndOfRom:
    
    END


    With the align $2000, even, or nothing, it won't work, if I put it above or underneath the art.bin
     
  5. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    Maybe you could try without fixing the pointers and/or checksum :/
     
  6. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Tried that, didn't work. but...

    It's now fixed, I think. Don't understand how lol


    Thanks guys!
     
  7. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Touche ^_^. Very puzzling indeed, glad to see you have it sorted out, I'll certainly keep everything said here in mind. Glad you have it fixed and can't wait to see what content you have brewing! :)
     
  8. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I can't keep brewing, the game has been randomly freezing recently. Ever since I ported object manager, so I've gone wrong somewhere. Just don't know where. It can happen when underwater, when about to get hurt, or just when running, etc.
     
  9. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    More than likely something is misaligned make sure there is an even or in your case as I assume you are using the AS version of sonic 2 use


    Code:
    align 2
    
    after all bincludes and after all data labels but not after each command by the was so don't put an align 2 after every dc.l dc.w dc.b just at the end off it that should more than likely fix everything
     
  10. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    It's not that, I think it's something to do with the respawn_index. It had to become a word for the S3K object manager.



    Code:
    anim_frame = $1B
    
    anim = $1C
    
    next_anim = $1D
    
    respawn_index = $1E ; and $35, it's now a word ; was just 23.
    
    anim_frame_duration = $23
    
    status = $22 ; note: exact meaning depends on the object... for sonic/tails: bit 0: leftfacing. bit 1: inair. bit 2: spinning. bit 3: onobject. bit 4: rolljumping. bit 5: pushing. bit 6: underwater.
    
    routine = $24 ; used to be 24
    
    routine_secondary = $25 ; used to be 25
    
    angle = $26 ; angle about the z=0 axis (360 degrees = 256)
    
    ; ---------------------------------------------------------------------------
    
    ; conventions followed by many objects but NOT sonic/tails:
    
    collision_flags = $20
    
    collision_property = $21
    
    ; $23 is free
    
    subtype = $28


    anim_frame_duration used to be a word, but I've fixed that by changing all the words to bytes. Here's a gameover example:





    Code:
    loc_13FEE:
    
    btst #0,mapping_frame(a0)
    
    bne.w BranchTo17_DisplaySprite
    
    ;tst.w (Game_paused).w ; is game already paused?
    
    ;beq.w loc_1407E ; if yes, branch
    
    move.b (Ctrl_1_Press).w,d0
    
    or.b (Ctrl_2_Press).w,d0
    
    andi.b #$70,d0
    
    bne.s loc_14014
    
    tst.b anim_frame_duration(a0) ; anim_frame_duration - change from .w to .b
    
    beq.s loc_14014
    
    ; -----------------------------------------------------------------------------------
    
      move.b  ($FFFFFE05).w,d0 ; Move Game Frame timer to d0
    
      andi.b  #3,d0 ; andi by 3
    
      bne.s + ; if d0 does NOT equal 0, skip subtracting 1 byte from anim_frame_duration
    
    ; otherwise, subtract 1 byte from anim_frame_duration
    
    ; -----------------------------------------------------------------------------------
    
    subq.b #1,anim_frame_duration(a0) ; anim_frame_duration - change from .w to .b
    
    + ; new label, so the above can skip the subtraction of anim_frame_duration correctly
    
    bra.w DisplaySprite

    Instead of counting down every frame, it counts down every 4 frames. I tested it and it works fine.


    I think it's where I stuck respawn_index. Here's a video. You'll notice I jump over the crab at first, but when I go back to him, he's gone. I touch his position, freeze. The freezing usually occurs when I'm about to touch something.


    EDIT: Thanks to flamewings code, I can pinpoint why it's happening.


    It is definately respawn_index. Some objects do NOT respawn when you leave and re-enter the area if you haven't destroyed them. This can happen to badniks, springs, anything. Then when you go to touch where they originally were, BOOM, error.


    [​IMG]


    In the RARE case that it doesn't freeze when you touch their location where they should be, this triggers something else. As soon as you next get hurt, it will freeze.


    [​IMG]


    I changed the text between both builds from flamewing to redhotsonic =P
     
    Last edited by a moderator: Feb 19, 2012
  11. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    341689 or 536B9 is not dividable by 2 and 12BB5 or 76725 is also not dividable by 2 so in other words it is not at an even address now there are more than likly one of two possibilities


    1: something is not even aligned


    2: as you said you have converted anim_frame_duration from a word to a byte maybe somewhere it is still a word Take this code for an example I believe that it wouldn't work




    move.b (a1)+,d1;even though a1 started out at an even address it is now an odd address as adding one to an even number makes it an ;odd number as far as I am ;aware move.b can read odd address were as move.w needs to be even


    move.w (a1)+,d1;can't read from odd address
     
    Last edited by a moderator: Feb 19, 2012
  12. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I will go through my ASM file tomorrow and after all dc.b's and BINCLUDES, I will add an even at the end.


    Although something is more than likely not aligned, I still think respawn_index is the cause. I will post an update tomorrow. I will spend some time on adding all EVENs, then I will test. If it still occurs, it's definitely respawn_index being moved from $23 to $1E and $1F.


    anim_frame_duration is DEFINITELY all .b's, I've checked over 5 times.
     
    Last edited by a moderator: Feb 19, 2012
  13. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    Ok glad you got it figured I relay do hope that this works because I saw the video to your hack and looks cool ignoring the crash so don't give up on it.
     
  14. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Update. EHZ never freezes anymore, neither does any other level except ARZ. It still keeps freezing and I'm not sure how to solve it. May not be an alignment problem after all.
     
  15. Sonic master

    Sonic master Well-Known Member Member

    Joined:
    Mar 27, 2010
    Messages:
    303
    On the plus side aligning every thing did help a lot only one more level to go nice work redhotsonic!
     
  16. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Seems like ARZ is now fixed. Flamewing pinpointed the line that was causing the problem. This was all due to the new S3K object management, but now it's implemented and no more freezing =)
     
Thread Status:
Not open for further replies.