Basic Questions and Answers Thread

Discussion in 'Discussion & Q&A' started by Malevolence, Jul 7, 2009.

  1. Ashuro

    Ashuro Anti-Cosmic Metal Of Death Member

    Joined:
    Sep 27, 2014
    Messages:
    550
    Location:
    France
    Ok, since 2 days i'm on it, and i'm pretty sure, that i missed something.

    I want to create an index for this:

    Code:
    WallRun_Data1:    ; Wall Run Data for Sonic
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000       ; GHZ1, GHZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000       ; GHZ3, GHZ4
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000       ; DCZ1, DCZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000       ; DCZ3, DCZ4 (CEZ3)
            dc.w $0000, $0000, $0000, $0000, $2B00, $0040,  $3320,  $00F0             ; MZ1, MZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; MZ3, MZ4     
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; NCZ1, NCZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; NCZ3, NCZ4
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; CFZ1, CFZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; CFZ3, CFZ4
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; CEZ1, CEZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; CEZ3, CEZ4
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; XXX,     XXX
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; XXX,     XXX
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; FIZ1, FIZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; FIZ3, FIZ4
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; HFZ1, HFZ2
            dc.w $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000        ; HFZ3, HFZ4
            even
    With this:
    Code:
    ...
    ...
    WallRun_Init:
            lea        (WallRun_Data1).l,a2
    
    Load_Zone_Index:       
            moveq    #0,d0            ; clear register
            move.b    ($FFFFFE10).w,d0        ; get zone number
            lsl.w    #5,d0            ; multiply by $20 (32) (16 words)
            adda.w    d0,a2            ; add d0 to script address
    
    Load_Act_Index:
            moveq    #0,d1            ; clear register
            move.b    ($FFFFFE11).w,d1        ; get act number
            lsl.w    #3,d1            ; multiply by $08 ( 8) (4  words)
            adda.w    d1,a2            ; add d0 to script address
    
    loc_1:
            lea    ($FFFFD000).w,a1
    ...
    ...
    And... this "thing" only work for the first act of Green Hill, why?

    (Sonic 1 Hivebrain, a piece of code inspied by LZWindTunnels, to make the player run on the walls, and i want to make this routine work for every act of every zones, like for LoopTileNums, LevelSizeArray; Waterheight...).
     
  2. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    Sorry. I forgot to respond when you PM'd me about it.

    Anyway, replace this:
    Code:
            lsl.w    #5,d0            ; multiply by $20 (32) (16 words)
    with this:
    Code:
            lsl.b    #6,d0            ; multiply by $40 (64) (32 words)
            lsr.w    #3,d0            ; divide by 8 (8) (4 words) results in 32/8=4 words
    It is taken from how the code for the level layout and other stuff uses this for 2 words.
    Code:
            lsl.b    #6,d0
            lsr.w    #4,d0
     
    Ashuro likes this.
  3. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    In that case
    Code:
    Load_Act_Index:
            moveq    #0,d1            ; clear register
            move.b    ($FFFFFE11).w,d1        ; get act number
            lsl.w    #3,d1            ; multiply by $08 ( 8) (4  words)
            adda.w    d1,a2            ; add d0 to script address
    is pretty much useless, since you are now making it so that it calculates the offset from both the zone and act ID at once.

    Also, if you're going to go with that
    Code:
    move.b    ($FFFFFE10).w,d0
    move.b should be move.w, so that you get both the zone and act ID in d0.
     
    Ashuro and ProjectFM like this.
  4. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    @Novedicus: I didn't see that he split it up like that. Good catch.

    I've been messing around with the horizontal interrupt to create effects and whatnot. The problem I've been experiencing is that whenever I insert this line of code into PaltoCRAM:
    Code:
            move.l #$50000010,(a0) ;write to VSRAM
    or this one:
    Code:
            move.l #$40000010,(a0) ;write to VSRAM
    it produces random blank and occasionally non-blank tiles and a few sprites in the HUD don't load. This tile issue goes away as the tiles go offscreen:
    [​IMG]
     
  5. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    The vertical interrupt is running for longer than the V-BLANK period (mainly due to the sound driver and level rendering engine), so once it starts drawing scanlines, it allows the horizontal interrupt to be issued during the V-INT, and yeah, screwy things can happen, especially if the H-INT is run more than once. What I normally do is disable interrupts at the start of the V-INT and reenable them at the end.

    One thing to note is that because you are making it so that the H-INT doesn't run during the V-INT, you cannot run the H-INT on the scanlines in which are drawn during the V-INT. You can TRY to optimize the V-INT, but to that I say "good luck".
     
  6. Ashuro

    Ashuro Anti-Cosmic Metal Of Death Member

    Joined:
    Sep 27, 2014
    Messages:
    550
    Location:
    France
    I known it, sh*t! xD

    I've tried to do this:
    lsl.b #6,d0
    lsr.w #4,d0


    ...
    ...

    But i completely forget about this: move.w ($FFFFFE10).w,d0

    Thanks.

    EDIT:
    Still working, i've just forget to put a call somewhere in the rom.
     
    Last edited: Jul 21, 2017
  7. Pineapple Arse

    Pineapple Arse I ironically hate cold temperatures. Member

    Joined:
    Jun 19, 2016
    Messages:
    129
    Location:
    A cold place.
    This is a small question I am having, but where is the code for the snow falling before the ice cap zone act 1 boss, and how do I port the effect to a level in sonic 1?
     
    Ashuro likes this.
  8. Ashuro

    Ashuro Anti-Cosmic Metal Of Death Member

    Joined:
    Sep 27, 2014
    Messages:
    550
    Location:
    France
    This is what i wan't to know too xD
     
  9. JoenickROS

    JoenickROS ROS (bug fixing in progress) Member

    Joined:
    Feb 5, 2012
    Messages:
    929
    Good luck finding it Frost, the reason how some people have it in their hack is because they coded their own from scratch. No hacks have it ported from S3 itself. (That I know of) Maybe someone can answer your question though. Maybe look at the code for the clouds in SSZ they seem to work similar. (Although I dont hack S3K I have looked at some of its code)
     
    kenny0989 likes this.
  10. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    That doesn't seem to be the problem and disabling the H-INT during the V-INT doesn't fix. It seem that writing anything to ($C00004).l will cause the problem.

    Edit: I fixed it. The sound driver was being called every scanline of a frame when $FFFFF64F isn't 0.

    Edit 2: I was wrong. What I need to do is write to $C00004 during every scanline. However, that is what is causing the problem. Labyrinth Zone's water gets away with it because it is only being written to during one scanline each frame.
     
    Last edited: Jul 21, 2017
  11. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    How are you disabling interrupts during V-INT? How are you handling your H-INT routine?
     
  12. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    I tried disabling them by putting
    Code:
            move.w    #$8004,($C00004).l
    at loc_B10 and
    Code:
            move.w    #$8014,($C00004).l
    at loc_B64.

    I have been modifying PalToCRAM a lot to try out different things, but I am most commonly using
    Code:
            movem.l    a0-a1/d0-d1,-(sp)
            lea    ($C00000).l,a0
            lea    ($FFFFF60E).w,a1
            addq.w    #1,(a1)
            move.l #$50000010,4(a0)
            move.w (a1)+,d0
            muls.w (a1),d0
            lsr #7,d0
            move.w d0,(a0)
            movem.l    (sp)+,a0-a1/d0-d1
    
    locret_119C:
            rte
    It is based the source code of this demo.
     
  13. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    What I do is write to the SR to enable/disable interrupts ($2300 to enable, $2700 to disable), since that usually works for me. I dunno how well it would work by disabling the H-INT via VDP register, to be honest.

    Also the VDP command $50000010 translates to "Write to VSRAM at address $1000", which is invalid. You should use $40000010 to write the FG value and $40020010 for the BG.
     
    Last edited: Jul 21, 2017
    ProjectFM likes this.
  14. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    This doesn't fix it at all, so I'm pretty sure this isn't the problem.

    If you need it, the disassembly is right here.

    Also, thanks for the tip! The source code that I used had that and changing 5 to 4 doesn't seem to make any difference.
     
  15. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Oh! What you should do is have it so that the H-INT is disabled when it's loading the level data, so that when the H-INT is run, especially while it's loading tiles onto the planes, the VDP command isn't "overwritten". When it's done, enable the H-INT.

    Unfortunately, the screen may glitch up a bit a times, but as I've mentioned before, it's due to the V-INT running longer than the V-BLANK period. You would mostly see this while it's drawing new rows and columns of tiles for the level.
     
    Last edited: Jul 21, 2017
    ProjectFM likes this.
  16. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    Thank you so much.

    Thank you also for explaining the screen glitching.
     
  17. Ashuro

    Ashuro Anti-Cosmic Metal Of Death Member

    Joined:
    Sep 27, 2014
    Messages:
    550
    Location:
    France
    I don't know, i just can't figure this out.
    Just why? WHY? (dear god, why I always have a problem after another??)
    upload_2017-7-26_23-26-19.png

    Everything is ok in SonMapEd...
    So WHY THIS?!
    upload_2017-7-26_23-26-56.png

    If someone here has already had this problem, i really want some explanations xD
    Thanks!

    EDIT: Problem fixed for this moment...
    The issue comes from the sonic's art file, in fact, the $B2, $B3, $B4 ect until $C2 overwrite Ashuro's sprite (i don't know why).
     
    Last edited: Jul 26, 2017
  18. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Ashuro, this is most likely a DMA problem. Due to how DMA source offset counters increment internally, wrong data will be transferred when the data offsets cross 128 kb boundary.

    Explanation:
    The source offset of your DMA transfer (offset inside the ROM in your case) is divided by 2 (as DMA operates words) and stored as 3-byte offset inside VDP registers; its form may be represented as follows: HH MM LL.
    As DMA transfer processes, the value of HH MM LL is incremented by 1 to fetch the successive word (usually; the increment value can be changed through VPD's auto-increment register).
    There's a bug (or quirk) in DMA's internal implementation, where only two lower bytes (MM LL) are incremented properly, the high byte of the offset (HH) is never incremented. Which is why when your offset is close to 128 kb boundary and MM LL part of the offset overflows, wrong data will be transferred.

    Try aligning your art on the 128 kb boundary. In other words, put "align $20000" before the inclusion of your art ("ArtUnc_Ashuro"/"ArtUnc_Sonic"/whatever).
     
    Pacca, Ashuro and TheStoneBanana like this.
  19. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
    Other fixes include splitting up the problematic DPLC entries (which is easiest if you use macros for them), and altering the DPLC routine to automatically split problematic requests into two DMA commands.
     
    Ashuro likes this.
  20. Ashuro

    Ashuro Anti-Cosmic Metal Of Death Member

    Joined:
    Sep 27, 2014
    Messages:
    550
    Location:
    France
    @vladikcomper Oh, i already have it xD

    Code:
    ; ---------------------------------------------------------------------------
    ; Uncompressed graphics    - Sonic and Ashuro
    ; ---------------------------------------------------------------------------
        align $20000
    
    Art_Sonic:    incbin    artunc\sonic.bin    ; Sonic
            even
    Art_Ashuro:    incbin    artunc\ashuro.bin    ; Ashuro
            even
    Does it works if i load the art somewhere else in the rom?

    @MainMemory Ok, i'll try something for it. Thank you very much!