Help with sprites

Discussion in 'Engineering & Reverse Engineering' started by Sik, May 27, 2006.

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


    Sik is pronounced as "seek", not as "sick". Tech Member
    being an asshole =P
    I need help with this code. This theorically should add a sprite to the sprite list, but when I add a second sprite the first one goes wrong. Theorically it should only affect the last sprite entity of the previous one, but it overwrites the size, too. Don't worry, the first sprite is being written correctly, that part of the code is OK.

    Here D0 is X, D1 is Y, D2 is size and D3 is the number of the first tile.

    Code (Text):
    1. RAMLastSprite equ $FF0001
    3. ???
    5. AddSprite:
    6. movem.l d0-d6, -(sp)
    7. move.l #$F800, d5
    9. move.b (RAMLastSprite).l, d4
    10. beq AddSpriteFirst
    11. cmp.b #80, d4
    12. beq AddSpriteEnd
    14. andi.w #$FF, d4
    15. lsl.w #3, d4
    16. add.w d4, d5
    17. lsr.w #3, d4
    18. subq.w #6, d5
    19. lsl.l #2, d5
    20. lsr.w #2, d5
    21. ori.w #$4000, d5
    22. swap d5
    23. move.l d5, ($C00004).l
    24. move.w ($C00000).l, d6
    25. andi.w #$FF00, d6
    26. andi.w #$FF, d4
    27. or.w d6, d4
    28. move.l d5, ($C00004).l
    29. move.w d4, ($C00000).l
    30. andi.w #$FF, d4
    32. move.l #$F800, d5
    33. lsl.w #3, d4
    34. add.w d4, d5
    35. AddSpriteFirst:
    36. lsl.l #2, d5
    37. lsr.w #2, d5
    38. ori.w #$4000, d5
    39. swap d5
    40. move.l d5, ($C00004).l
    42. lsl.w #8, d2
    43. move.w d1, ($C00000).l
    44. move.w d2, ($C00000).l
    45. move.w d3, ($C00000).l
    46. move.w d0, ($C00000).l
    48. addq.b #1, d4
    49. move.b d4, (RAMLastSprite).l
    51. AddSpriteEnd:
    52. movem.l (sp)+, d0-d6
    53. rts
    I hope you can help me.
  2. Korama


    Tech Member
    Code (Text):
    1. ori.w #$4000, d5
    2. swap d5
    3. move.l d5, ($C00004).l
    4. move.w ($C00000).l, d6
    The bit that you set there with the ori.w instruction sets the VDP access mode to "VRAM write". But you want to *read* from VRAM, don't you? :(
    Remove the ori.w instruction here (VRAM read access has no special bits set in this command) and it should work as intended by you.
  3. Mask of Destiny

    Mask of Destiny

    Tech Member
    Well he would also have to add the equivalent operation after the read so that the subsequent write works properly.

    Honestly though, I think he would be better off storing a copy of the sprite list in RAM, editing that copy and using DMA to copy it to VRAM once per frame. It makes the code for maintaining the list much simpler and is probably faster in the long run (at least when you're dealing with more than just a couple of sprites anyway).
  4. Sik


    Sik is pronounced as "seek", not as "sick". Tech Member
    being an asshole =P
    Bah, I noticed it accidentally when checking something about the CRAM in Sega2. By the way, there are still some errors around there, since I needed to change something more than that. But it worked finally (however it took all the data registers!). Nevermind.

    By the way, I spend more time trying to fix DRX's bugs: I don't know how his codes work, he makes A LOT of errors. I.e. the VBlank is disabled not only because the register #1 is wrong, but because the interrupts are disabled, too! And his SRAM example? He set it in the header as for odd only writes, but he's performing even writes! Man, please check carefully everything. :/
Thread Status:
Not open for further replies.