Basic Questions & Answers thread

Discussion in 'Engineering & Reverse Engineering' started by Tweaker, May 29, 2008.

  1. Brainulator

    Brainulator

    Regular garden-variety member Member
    You're welcome... I figured since I saw no updates, then...
    I should have mentioned that the second instruction given may have to be changed to a JSR, depending on how far it is.

    Can I take a closer look at the code you've created for that bit of the monitor icon item? I just want to make sure that nothing's gone with what I said.
     
  2. RazorKillBen

    RazorKillBen

    Benny the Hog Member
    10
    1
    1
    London, UK
    Sonic Seasons
    Sure - it's literally ironically, exactly what you'd typed too:

    Code (Text):
    1. Pow_ChkRings:
    2.     cmpi.b   #6,d0        ; does monitor contain 10 rings?
    3.     bne.s    Pow_ChkS
    4.  
    5.     moveq    #palid_GHZ_Alt,d0; Load alternative level palette
    6.     jsr      (PalLoad1).l
    It doesn't seem to matter what palette is loaded into memory with moveq - even if I don't add the command it crashes when hitting the monitor displaying either a LINE EMULATOR 1111 error or mostly ILLEGAL INSTRUCTION. Essentially, when the monitor is broken, I wanted the level palette to change (I removed the whiteout fade code to make it as simple as possible for the example!). Not sure what I'm missing as I assumed it would be as easy as load palette into memory, run sub routine, deep joy was had by all.
     
  3. Brainulator

    Brainulator

    Regular garden-variety member Member
    I think I figured it out: it's the same problem that afflicts the Chemical Plant Zone boss in Sonic 2: PalLoad1 writes to register d7, but d7 is used as a loop counter so that the object execution routine knows what to process. Thankfully, d1 is unused past the initial routine jump code, so we can use that to our advantage. To fix this, do either of the following:

    Fairly simple. I guess you could use the stack pointer or d2/d3/d4/d5/d6 for this, too, but d1 works well enough for our purposes.
    Code (Text):
    1. Pow_ChkRings:
    2.     cmpi.b  #6,d0   ; does monitor contain 10 rings?
    3.     bne.s   Pow_ChkS
    4.  
    5.     moveq   #palid_GHZ_Alt,d0   ; Load alternative level palette
    6.     move.b  d7,d1   ; Back up d7
    7.     jsr (PalLoad1).l
    8.     move.b  d1,d7   ; Restore d7
    A bit lengthier, but just as suitable:
    Code (Text):
    1. Pow_ChkRings:
    2.     cmpi.b  #6,d0   ; does monitor contain 10 rings?
    3.     bne.s   Pow_ChkS
    4.  
    5.     moveq   #palid_GHZ_Alt,d0   ; Load alternative level palette
    6.     lea (PalPointers).l,a1
    7.     lsl.w   #3,d0
    8.     adda.w  d0,a1
    9.     movea.l (a1)+,a2    ; get palette data address
    10.     movea.w (a1)+,a3    ; get target RAM address
    11.     adda.w  #v_pal_dry_dup-v_pal_dry,a3     ; skip to "main" RAM address
    12.     move.w  (a1)+,d1    ; get length of palette data
    13.  
    14. @loop:
    15.     move.l  (a2)+,(a3)+ ; move data to RAM
    16.     dbf d1,@loop
    Note that if you optimize things and are only using the one palette, you can replace the four lines (not counting the space) after the BNE instruction with this:
    Code (Text):
    1. lea (PalPointers+(palid_GHZ_Alt<<3)).l,a1

    This is, of course, assuming you made sure to put an RTS at the end of your code... right? Either way, let me know if this fixes the problem!
     
  4. RazorKillBen

    RazorKillBen

    Benny the Hog Member
    10
    1
    1
    London, UK
    Sonic Seasons
    Thanks so much, genuinely, for trying to get this resolved. I really appreciate it.

    So I did try exactly what you'd mentioned (albeit, I copied into the d6 register) previously, but I still got the crash. So I tried copying your code word-for-word in-case I was overwriting an important data register, but it's still crashing in-game. Freezes with a small graphical tear, although the ILLEGAL INSTRUCTION and any error messages are not present now. On one occasion, there was a slight screen flash (almost like a special stage entry flash) before crash but can't seem to replicate it since.

    EDIT: The ILLEGAL INSTRUCTION error is still present, it was just off screen...

    I tried copying the second code block and this doesn't crash the game! However, it also doesn't seem to have any effect at all either. I've also tried using alternate palettes (SBZ for example) just to ensure it's not an issue with the palette code, but it isn't. No palette swaps, no graphical changes at all. I'm at a bit of a loss as to what's causing the problem!
     
    Last edited: Nov 12, 2021
  5. Brainulator

    Brainulator

    Regular garden-variety member Member
    I made two mistakes, it turns out. First of all, those move.b instructions in the first method should be move.w instructions. Second, for both methods, the jump should be changed to point to PalLoad2 instead. Hopefully, this should do it.
     
  6. Alex Field

    Alex Field

    シュート! カオス・エメラルド・ザが消えようとしている! Member
    138
    78
    28
    Downunda, Mobius
    Sonic the Hedgehog 2+, Sonic the Hedgehog 3+
    In the Nick Arcade prototype, Green Hill Zone uses this code to load level layouts.
    Code (Text):
    1. LevelLayoutLoad_GHZ:
    2.         move.w    (Current_ZoneAndAct).w,d0
    3.         lsl.b    #6,d0
    4.         lsr.w    #5,d0
    5.         move.w    d0,d2
    6.         add.w    d0,d0
    7.         add.w    d2,d0
    8.         add.w    d1,d0
    9.         lea    (LevelLayout_Index).l,a1
    10.         move.w    (a1,d0.w),d0
    11.         lea    (a1,d0.w),a1
    12.         moveq    #0,d1
    13.         move.w    d1,d2
    14.         move.b    (a1)+,d1
    15.         move.b    (a1)+,d2
    16.  
    17. loc_7426:
    18.         move.w    d1,d0
    19.         movea.l    a3,a0
    20.  
    21. loc_742A:
    22.         move.b    (a1)+,d3
    23.         subq.b    #1,d3
    24.         bcc.s    loc_7440
    25.         moveq    #0,d3
    26.         move.b    d3,(a0)+
    27.         move.b    d3,(a0)+
    28.         move.b    d3,$FE(a0)
    29.         move.b    d3,$FF(a0)
    30.         bra.s    loc_7456
    31. ; ===========================================================================
    32.  
    33. loc_7440:
    34.         lsl.b    #2,d3
    35.         addq.b    #1,d3
    36.         move.b    d3,(a0)+
    37.         addq.b    #1,d3
    38.         move.b    d3,(a0)+
    39.         addq.b    #1,d3
    40.         move.b    d3,$FE(a0)
    41.         addq.b    #1,d3
    42.         move.b    d3,$FF(a0)
    43.  
    44. loc_7456:
    45.         dbf    d0,loc_742A
    46.         lea    $200(a3),a3
    47.         dbf    d2,loc_7426
    48.         rts
    49. ; End of function LevelLayoutLoad_GHZ
    Not sure what it does though; best I can tell it loads four chunks instead of one (probably since the GHZ layout data is the same as Sonic 1's), but I'm not sure about that.
     
  7. RazorKillBen

    RazorKillBen

    Benny the Hog Member
    10
    1
    1
    London, UK
    Sonic Seasons
    We're so close! So the move.w instructions has fixed the crashing - PalLoad2 does change the palette, but applies it to the object layer, so Sonic, Rings, HUD and Badniks and not the level layer. PalLoad1 does not change anything.
     
  8. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,551
    145
    43
    SonLVL
    It is dynamically converting the layout data from 256x256 chunks to 128x128 by multiplying the source ID by 4 and copying it into four adjacent slots in the layout buffer, incrementing by one each time. Except for the 0 chunk, which just writes four 0s. So, given the value $14, it subtracts 1 ($13), multiplies by 4 ($4C), adds 1 ($4D), then fills in a 4-chunk section of the layout, giving you:
    Code (Text):
    1. 4D 4E
    2. 4F 50
     
  9. Brainulator

    Brainulator

    Regular garden-variety member Member
    You'll have to modify or duplicate the palette pointers themselves.
     
  10. Cioss

    Cioss

    Member
    9
    1
    3
    France
    idk if it'd fit here, but idk where else

    ok so my friend and i are trying to figure out how we'd be able to use gradients (aka hblank), and we have no clue how, for example, the gradient flickers, and when we want to make for example a gradient that goes from fluo yellow purple it turns into this monstrosity
    [​IMG]
    so, my question here is basically, how do i properly use hblank to make a cool gradient without screwing it up