Basic Questions and Answers Thread

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

  1. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    Just a quick clarification question; is the following an effective way to convert byte values into word values (with d0 as the output)?

    Code:
        move.l    #$0,d0
        move.b    {byte value to convert},d0
        asr.w        #$2,d0
    I haven't really tackled this before, and I want to make sure this code is sound so I can get to work on the more interesting parts of the code.

    EDIT: Further experimentation suggests that this is completely unnecessary. I gotta stop over thinking things...
     
    Last edited: Sep 18, 2016
  2. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    The shift is done with bits, so if you wanted to shift a byte into the word area, you'd have to shift by 8. Just remember: asr is a signed shift, so be careful that your value isn't signed when using it. Otherwise, use the lsr instruction.
     
    Last edited: Sep 18, 2016
  3. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    furthermore if you do lsr.w #8, you would effectively shift out the byte you just read, you silly. You'd probably be shifting left instead.
     
  4. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,902
    Location:
    italy
    Pacguy, d0 will always contain a 32-bit value, it's up to you to decide how many bits you want to use. With your first move.l you effectively set d0 to value $00000000. With your move.b you then set d0 to value $000000xx, where $xx is a byte. If you then read a byte out of d0, it will be $xx; if you read a word out of d0, it will be $00xx; I won't lie, you will be surprised to know what happens if you read a dword out of d0 (just kidding, it will be $000000xx). I think this is what you were confused about, so you probably don't need to shift at all.

    If, instead, you actually want to shift $000000xx to $0000xx00 as Dan and Natsumi assumed, then just read their posts and disregard mine :p

    For the record, if you want to zero a register in a faster way, you can use moveq instead of move.l:
    Code:
    moveq #$0, d0
    moveq can't always be used, but in this case it can, and it will yield the same result as your move.l, just a bit faster.
     
    Last edited: Sep 20, 2016
    Pacca likes this.
  5. Ziro_

    Ziro_ Mentally Skewed Member

    Joined:
    Aug 1, 2016
    Messages:
    59
    Location:
    What are you a cop
    I am trying to add super sonic using 2005 hivebrain assembly. I keep getting the error in the title



    Code:
    LoadSonicDynPLC:            ; XREF: Obj01_Control; et al
            moveq    #0,d0
            move.b    $1A(a0),d0    ; load frame number
            cmp.b    ($FFFFF766).w,d0
            beq.s    locret_13C96
            move.b    d0,($FFFFF766).w
            lea    (SonicDynPLC).l,a2
            tst.b    ($FFFFFE19).w        ; is sonic super?
            beq.s    LoadSonicDynPLCCont    ; if not, branch
            lea    (SuperSonicDynPLC).l,a2
            bra.s    LoadSonic
    LoadSonicDynPLCCont:
            add.w    d0,d0
            adda.w    (a2,d0.w),a2
            moveq    #0,d5
            move.b    (a2)+,d5
            subq.w    #1,d5
            bmi.s    locret_13C96
            move.w    #$F000,d4
            move.l    #Art_Sonic,d6        ; load Sonic's art
            bra.s    SPLC_ReadEntry
    SPLC_ReadEntry:
            moveq    #0,d1
            move.b    (a2)+,d1
            lsl.w    #8,d1
            move.b    (a2)+,d1
            move.w    d1,d3
            lsr.w    #8,d3
            andi.w    #$F0,d3
            addi.w    #$10,d3
            andi.w    #$FFF,d1
            lsl.l    #5,d1
            add.l    d6,d1
            move.w    d4,d2
            add.w    d3,d4
            add.w    d3,d4
            jsr    (QueueDMATransfer).l
            dbf    d5,SPLC_ReadEntry    ; repeat for number of entries
    
    locret_13C96:
            rts  
    ; End of function LoadSonicDynPLC
    Staff edit: Merged into Basic Q&A thread, title was 'Illegal Zero length short branch'.
     
    Last edited by a moderator: Sep 20, 2016
  6. FireRat

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

    Joined:
    Oct 31, 2009
    Messages:
    535
    Code:
           bra.s    SPLC_ReadEntry
    SPLC_ReadEntry:
    
    Why would you do that?
     
  7. LuigiXHero

    LuigiXHero Well-Known Member Member

    Joined:
    Mar 22, 2014
    Messages:
    280
  8. LazloPsylus

    LazloPsylus The Railgun Member

    Joined:
    Nov 25, 2009
    Messages:
    Location:
    Academy City
    There's your zero-length branch. The branch is to a location the PC will already be in processing the instruction, so the relative distance is zero. Branching 0 bytes away is not liked by the assembler at all and is unnecessary, so there's your error.
     
  9. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    I've run into a problem that seems to simply be beyond me. So, in Sonic 2 (on a slightly dated github disasm), I'm trying to make Sonic use different mappings, artwork, and dplcs based on the value of a ram address. So far, I have the mappings and art loading functioning exactly as I'd expect. The dplcs, however, are a different matter. Although I'm trying to test with exact copies of Sonics art, mappings, and dplcs, the art tiles loaded up by the new dplcs differ wildly from what the original ones do, despite the fact the files are identical, and both load up just fine in SonMapEd. What truly confounds me, however, is that one of the dplcs from my list do in fact work, and has been working for some time. Why this seemingly random set of dplcs (which have been edited extensively in SonMapEd), while the default dplcs with default artwork and mappings don't work doesn't make sense to me, and I can't wrap my head around why either does or doesn't work.

    So, this is how I changed the code to allow for swapping the dplcs:
    Code:
    LoadSonicDynPLC_Part2:
        cmp.b    (Sonic_LastLoadedDPLC).w,d0
        beq.s    return_1B89A
        move.b    d0,(Sonic_LastLoadedDPLC).w
        ;lea    (MapRUnc_Sonic).l,a2
        jsr    LoadCustomDPLCsRoutine   ;load custom dplcs
        add.w    d0,d0
        adda.w    (a2,d0.w),a2
        move.w    (a2)+,d5
        subq.w    #1,d5
        bmi.s    return_1B89A
        move.w    #tiles_to_bytes(ArtTile_ArtUnc_Sonic),d4
    and this is some example code for LoadCustomDPLCsRoutine:
    Code:
       cmp.b    #$0,($<Ram Address To read>).w
        bne.s    load1DPLCs
        lea    (MapRUnc_0).l,a2
        rts
    
    load1DPLCs:
        cmp.b    #$1,(<Ram Address To read>).w
        bne.s    load2DPLCs
        lea    (MapRUnc_1).l,a2
        rts
    
    ...
    The biggest issue is that I honestly can't tell what any of this code does, you can see my trying to comment the code below in an unsuccessful attempt to figure out what's even going on:

    Code:
    SPLC_ReadEntry:
        moveq    #0,d1            ;clear d1
        move.w    (a2)+,d1    ;move something to do with dplcs into d1
        move.w    d1,d3        ;copy d1 into d3
        lsr.w    #8,d3            ;shift d3 8 bits to the right
        andi.w    #$F0,d3    ;and d3?
        addi.w    #$10,d3    ;and d3 again?
        andi.w    #$FFF,d1    ;and d3 further??? d3 is a shifted, and'd thing based on dplcs...
        lsl.l    #5,d1            ;shift d1 to the left 5 bits
        jsr    loadPokeArts    ;add artwork address into d1
        ;addi.l    #ArtUnc_Sonic,d1
        move.w    d4,d2        ;copy d4 into d2, d4 holds properly adjusted pointer to VRAM of Sonics art
        add.w    d3,d4            ;add d3 (weird thing involving dplcs, possibly which tiles should load?) to d4 (adjusted pointer to VRAM of Sonics art)
        add.w    d3,d4            ;do the above again, for some reason (perhaps because art address is adjusted?)
        jsr    (QueueDMATransfer).l    ;I think this writes to VRAM
        dbf    d5,SPLC_ReadEntry    ; repeat for number of entries
    I hold all the data for the mappings in a section underneath sonics old mappings, which are used for the Sega Screen.

    Code:
    ;--------------------------------------------------------------------------------------
    ; Sprite Dynamic Pattern Reloading
    ; Sonic DPLCs           ; MapRUnc_714E0:
    ;--------------------------------------------------------------------------------------
    ; WARNING: the build script needs editing if you rename this label
    ;          or if you move Sonic's running frame to somewhere else than frame $2D
    MapRUnc_Sonic:    BINCLUDE    "mappings/spriteDPLC/Sonic.bin"
        even
    ;poke dplcs
    MapRUnc_0:    BINCLUDE    "<path>"    ; 0
        even
    MapRUnc_1:    BINCLUDE    "<path>"        ; 1
        even
    MapRUnc_2:    BINCLUDE    "<path>"        ; 2
        even
    I have the art setup in a similar fashion, between Sonics art and Tails' art, and can confirm that the art does load properly when using MapRUnc_Sonic in place of many of my new dplc options. However, when attempting to read MapRUnc_0 (a copy of MapRUnc_Sonic) with the same artwork, things get out of hand; it often loads or even skips all my added artwork, and loads artwork from tails on occasion!

    However, the 9th set of dplcs, which isn't a direct copy of Sonics original dplcs at the moment, but was at some point, has worked for quite some time, despite being at the end of the list. Does anyone have any idea what's going on here? I only have a basic understanding of what dplcs do, and know practically nothing about writing to vram. I also just can't keep track of what the code is doing with the addresses of the artwork and dplcs to actually figure this out on my own...

    EDIT: I did everything right here. I just messed up the file paths :I
     
    Last edited: Sep 20, 2016
  10. Kurk

    Kurk Oh Yeah Member

    Joined:
    Jul 30, 2016
    Messages:
    99
    Location:
    Kurkistan
    I have a huge problem. so i was adding new art to labyrinth zone. i was playin through, but then when i got into the water, it gave me an illigal instruction. i don't know why this happens. i have attached a screenshot if it helps.
     

    Attached Files:

  11. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    We're going to need way more information then what you've given to help. The screenshot tells us nothing, as the only barely useful S1 crash debugger is off screen, and you've told us nothing about what you've changed. What did you do to the code to cause this?
     
    Soldaten likes this.
  12. Baraksha

    Baraksha Well-Known Member Member

    Joined:
    Dec 23, 2015
    Messages:
    99
    Ok, so I was was wondering , is it possible to have an act in sonic 1 that is longer then 64 chunks and higher then 8 chunks?
     
  13. MainMemory

    MainMemory Well-Known Member Member

    Joined:
    Mar 29, 2011
    Messages:
    922
    Not without changing how levels are loaded and stored in RAM. In RAM, the layout is copied to a fixed size buffer with 64x8 chunks interleaved between foreground and background (basically, the same as S2 uses). One potential solution is to port the S3K layout format, but this would require a lot of edits to everything that accesses the level layout data (drawing, collision, dynamic level events, etc).
     
  14. Baraksha

    Baraksha Well-Known Member Member

    Joined:
    Dec 23, 2015
    Messages:
    99
    Ok then, I think i'll pass
     
  15. GenesisDoes

    GenesisDoes What Nintendont Member

    Joined:
    Jan 2, 2016
    Messages:
    159
    Location:
    Pittsburgh, PA
    Is there anyway to manually re-align BG deform after instantly moving the player and camera? My warp door object moves Sonic and the camera to a pre-defined location from a jump table, but the BG deform tends to get unaligned both on the x and y-axis. (See picture for an example. Notice the black squares due to the deform reading blocks out of range of the ROM Chunks)
     

    Attached Files:

  16. B. Comet

    B. Comet Is fun still infinite? Member

    Joined:
    Aug 19, 2016
    Messages:
    83
    Location:
    South America Zone
    This might sound noobish, but...

    All right, all the objects of Green Hill Act 3 refuses to be deleted or changed, and this happens with the Marble Zone as well, someone can say to me how to fix this issue?
    And when I use HivePal to change the colors of the Green Hill water cicle, my hack turns in a red screen.
     
    Last edited: Sep 22, 2016
  17. Pacca

    Pacca Having an online identity crisis since 2019 Member

    Joined:
    Jul 5, 2014
    Messages:
    1,175
    Location:
    Limbo
    Which level editor are you using? The objects issue sounds like an issue with the editors configuration, but we can't help very much if we don't know which one is being used.

    As for the second issue, where does the red screen occur? Is the title screen completely red, or does it go red at boot? If it's the later, then using a disassembly typically fixes that. Try making sure the palettes are the same length before and after, that will ensure that the palette cycles are reading the data properly.

    If you're not using a disassembly, then don't be surprised if you get limited help; most hackers don't have much experience with direct rom hacking these days. If you are using one, and are already doing what I said above, then I have no idea what could be wrong :I
     
  18. B. Comet

    B. Comet Is fun still infinite? Member

    Joined:
    Aug 19, 2016
    Messages:
    83
    Location:
    South America Zone
    I am using SonLVL, and the rom gets red at the boot.
     
  19. JoenickROS

    JoenickROS ROS (bug fixing in progress) Member

    Joined:
    Feb 5, 2012
    Messages:
    929
    Is autofix checksum on for the emulator you are using?
     
  20. B. Comet

    B. Comet Is fun still infinite? Member

    Joined:
    Aug 19, 2016
    Messages:
    83
    Location:
    South America Zone
    Probably not. I use Gens+.