How to fix the GameModeArray

Discussion in 'Tutorials Archive' started by FireRat, Aug 25, 2010.

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

    FireRat Do Not Interact With This User, Anywhere!!! Exiled

    Joined:
    Oct 31, 2009
    Messages:
    535
    ADMINISTRATORS: IF SOMEONE ADMIN READ THIS POST, PLEASE FIX MY BAD GRAMMAR IF IS POSSIBLE




    Note: This may be a No-brainer guide, but well, I notice this


    Well, if someone added too many code in Segascreen or TitleScreen, or any game mode, probably have a branch error.


    In GameModeArray, the code bra.w works practically the same as the jmp command.


    But if you change a bra.w to jmp command here, the game may not work correctly, or simply crash


    If you want fix this, don't change the bra.w command. Create new labels, but with jmp commands, like this




    GameModeArray:


    bra.w SegaScreen2 ; Sega Screen ($00)


    ; ===========================================================================


    bra.w TitleScreen2 ; Title Screen ($04)


    ; ===========================================================================


    bra.w Level2 ; Demo Mode ($08)


    ; ===========================================================================


    bra.w Level2 ; Normal Level ($0C)


    ; ===========================================================================


    bra.w SpecialStage2 ; Special Stage ($10)


    ; ===========================================================================


    bra.w ContinueScreen2 ; Continue Screen ($14)


    ; ===========================================================================


    bra.w EndingSequence2 ; End of game sequence ($18)


    ; ===========================================================================


    bra.w Credits2 ; Credits ($1C)


    ; ===========================================================================


    rts


    SegaScreen2: jmp Segascreen


    TitleScreen2: jmp TitleScreen


    Level2: jmp Level


    SpecialStage2: jmp SpecialStage


    ContinueScreen2: jmp ContinueScreen


    Credits2: jmp Credits


    EndingSequence2: jmp EndingSequence



    Credits: Just me xD
     
    Last edited by a moderator: Aug 25, 2010
    Nat The Porcupine likes this.
  2. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    It really is a beginner's guide, but it's not a no-brainer, because to be honest, it took me ages to figure out what's going on when I had this problem.


    And even though it could be in another guide, I want to add something. A problem lots of people had when they tried to add new game modes, was to know how to get it work. Simply adding a line to the array and putting this line somewhere:



    move.b #$20,($FFFFF600).w


    Didn't work.
    The problem is a line in the code above the array:



    MainGameLoop:
    move.b ($FFFFF600).w,d0 ; load Game Mode


    -> andi.w #$1C,d0


    jsr GameModeArray(pc,d0.w) ; jump to apt location in ROM


    bra.s MainGameLoop



    Let's say you got a custom Splash Screen. Since every screen mode takes 4 bytes and Credits is $1C, you think just adding a new label with $20 should do the job. But because of that andi, it doesn't. We also can't change it to $20, because then nothing works. If you know how to work with bits, the first possibility after $1C to make every game mode working (including the new one) is $3C. This of course allows you to add 8 new screens, but I doubt anyone will really be taking that much. =P
     
  3. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    The anding of 1C is to make sure that the game mode is a multiple of 4, though considering multiple 4 values get moved to the game mode ram location anyway, the anding shouldn't be necessary, and I would assume it's only there just incase they made a mistake (it would auto correct).


    Also this guide isn't too bad, pretty useful, though I do have an easier solution which should save you a bit of effort:



    MainGameLoop:
    moveq #$00,d0


    move.b ($FFFFF600).w,d0 ; load Game Mode


    move.w d0,d1


    lsr.b #$01,d1


    add.w d1,d0


    jsr GameModeArray(pc,d0.w) ; jump to apt location in ROM


    bra.s MainGameLoop


    ; ===========================================================================


    ; ---------------------------------------------------------------------------


    ; Main game mode array


    ; ---------------------------------------------------------------------------


    GameModeArray:


    jmp SegaScreen ; Sega Screen ($00)


    ; ===========================================================================


    jmp TitleScreen ; Title Screen ($04)


    ; ===========================================================================


    jmp Level ; Demo Mode ($08)


    ; ===========================================================================


    jmp Level ; Normal Level ($0C)


    ; ===========================================================================


    jmp SpecialStage ; Special Stage ($10)


    ; ===========================================================================


    jmp ContinueScreen ; Continue Screen ($14)


    ; ===========================================================================


    jmp EndingSequence ; End of game sequence ($18)


    ; ===========================================================================


    jmp Credits ; Credits ($1C)


    ; ===========================================================================


    rts


    ; ===========================================================================
     
  4. Gardeguey

    Gardeguey Well-Known Member Member

    Joined:
    Aug 6, 2010
    Messages:
    82
    Location:
    México
    Ah, come on...




    MainGameLoop:


    move.b ($FFFFF600).w,d0 ; load Game Mode


    andi.w #$1C,d0


    movea.l GameModeArray(pc,d0.w),a1 ; jump to apt location in ROM


    jsr (a1)


    jmp MainGameLoop


    ; ===========================================================================


    ; ---------------------------------------------------------------------------


    ; Main game mode array


    ; ---------------------------------------------------------------------------


    GameModeArray:


    dc.l SegaScreen ; Sega Screen ($00)


    dc.l TitleScreen ; Title Screen ($04)


    dc.l Level ; Demo Mode ($08)


    dc.l Level ; Normal Level ($0C)


    dc.l SpecialStage ; Special Stage ($10)


    dc.l ContinueScreen ; Continue Screen ($14)


    dc.l EndingSequence ; End of game sequence ($18)


    dc.l Credits ; Credits ($1C)



    with this method, now the screen modes can be placed ANYWHERE without problems.


    by the way, in my romhack, i modified the MainGameLoop routine to call the screens with 0,1,2,3,... instead of 0,4,8,$C,...



    MainGameLoop:
    moveq #0,d0


    move.b (Game_Mode).w,d0


    lsl.w #2,d0


    movea.l GameModeArray(pc,d0.w),a4


    jsr (a4)


    bra MainGameLoop


    ; ===============================================================================


    ModeID_Sega equ $0


    ModeID_GF64 equ $1


    ModeID_Title equ $2


    ModeID_Demo equ $3


    ModeID_Level equ $4


    ModeID_SS equ $5


    ModeID_Options equ $6


    ModeID_SaveSel equ $7


    ModeID_SndTest equ $8


    GameModeArray:


    dc.l SegaScreen


    dc.l GF64_Screen


    dc.l TitleScreen


    dc.l Level


    dc.l Level


    dc.l GameMode10


    dc.l Options


    dc.l SaveSelect


    dc.l SoundTest
     
    Last edited by a moderator: Aug 25, 2010
  5. FireRat

    FireRat Do Not Interact With This User, Anywhere!!! Exiled

    Joined:
    Oct 31, 2009
    Messages:
    535
    Well, I wrote this guide because yesterday have this problem, and this is my fix created quickly.


    Because I'm not having time to create my hack, I need create this quickly, and with quick fixes.


    Selbi: I have a splash screen code, but I not need another game mode, because is used just after Sega_GotoTitle. My splash screen is another part of segascreen =P
     
    Last edited by a moderator: Aug 25, 2010
  6. theocas

    theocas #! Member

    Joined:
    Apr 10, 2010
    Messages:
    375
    Meh. Markey gave me this lesson about andi and that shit on IRC (Thanks!) and I fixed this shit myself, and now I have like $28 screen modes or something.

    I better hope it ain't the OCAS Splash. Or else.
     
    Last edited by a moderator: Aug 26, 2010
Thread Status:
Not open for further replies.