Displaying sprites: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
(Created page with "How to display a 64*80 (4*5 tiles) sprite block at x=88, y=36. ==Loading palette== At least one palette needs to be loaded. Here SpritePalette is loaded as palette 0 and the bac...")
 
mNo edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
How to display a 64*80 (4*5 tiles) sprite block at x=88, y=36.
How to display a 64*80 (4*5 tiles) [[sprites|sprite]] block at x=88, y=36.


==Loading palette==
==Loading palette==
At least one palette needs to be loaded. Here SpritePalette is loaded as palette 0 and the backdrop color is set to black.
At least one palette needs to be loaded. Here SpritePalette is loaded as palette 0 and the backdrop color is set to black.


<pre>
<syntaxhighlight>
     lea    SpritePalette,a0
     lea    SpritePalette,a0
     lea    PALETTES,a1
     lea    PALETTES,a1
     moveq.l #16-1,d0
     moveq.l #16-1,d7
.ldpal
.ldpal
     move.w  (a0)+,(a1)+
     move.w  (a0)+,(a1)+
     dbra    .ldpal
     dbra    d7,.ldpal


     move.w  #BLACK,BACKDROPCOLOR
     move.w  #BLACK,BACKDROP
</pre>
</syntaxhighlight>


==Setting the map==
==Setting the map==
The sprite's map is an array of tile numbers and attributes. Here the 4 sprites are made of tiles 0~4 with no special attributes.
The sprite's map is an array of tile numbers and attributes. Here the 4 sprites are made of tiles 0~4 with no special attributes.


<pre>
<syntaxhighlight>
     move.w  #64,d2          ;SCB1, sprite 1
     move.w  #64,d2          ;SCB1, sprite 1
     move.w  #1,VRAM_MOD
     move.w  #1,REG_VRAMMOD
     moveq.l #4-1,d6
     moveq.l #4-1,d6
.sprites:
.sprites:
     move.w  d2,VRAM_ADDR
     move.w  d2,REG_VRAMADDR
     clr.w  d1              ;First tile is #0
     clr.w  d1              ;First tile is #0
     moveq.l #5-1,d7
     moveq.l #5-1,d7
.tiles:
.tiles:
     move.w  d1,VRAM_RW     ;Tile number
     move.w  d1,REG_VRAMRW     ;Tile number
     move.w  #0,VRAM_RW     ;No attributes
     move.w  #0,REG_VRAMRW     ;No attributes
     addq.b  #1,d1
     addq.b  #1,d1
     dbra    d7,.tiles
     dbra    d7,.tiles
     addi.w  #64,d2          ;Next sprite
     addi.w  #64,d2          ;Next sprite
     dbra    d6,.sprites
     dbra    d6,.sprites
</pre>
</syntaxhighlight>


==Setting the shrinking==
==Setting the shrinking==
No shrinking at all (full size).
No shrinking at all (full size).


<pre>
<syntaxhighlight>
     move.w  #SCB2+1,VRAM_ADDR
     move.w  #SCB2+1,REG_VRAMADDR
     moveq.l #4-1,d7
     moveq.l #4-1,d7
.zset:
.zset:
     move.w  #$0FFF,VRAM_RW
     move.w  #$0FFF,REG_VRAMRW
     dbra    d7,.zset
     dbra    d7,.zset
</pre>
</syntaxhighlight>


==Setting the size and vertical position==
==Setting the size and vertical position==
First sprite is the driving one, next are driven.
First sprite is the driving one, next are driven.


<pre>
<syntaxhighlight>
     move.w  #SCB3+1,VRAM_ADDR
     move.w  #SCB3+1,REG_VRAMADDR
     move.w  #((496-36)<<7)+5,VRAM_RW ;Y position and size for the first sprite
     move.w  #((496-36)<<7)+5,VRAM_RW ;Y position and size for the first sprite
     moveq.l #5-1-1,d7
     moveq.l #5-1-1,d7
.yset:
.yset:
     move.w  #64,VRAM_RW   ;Sticky bit only for the 3 others
     move.w  #64,REG_VRAMRW   ;Sticky bit only for the 3 others
     dbra    d7,.yset
     dbra    d7,.yset
</pre>
</syntaxhighlight>


==Setting the horizontal position==
==Setting the horizontal position==
<pre>
<syntaxhighlight>
     move.w  #SCB4+1,VRAM_ADDR
     move.w  #SCB4+1,REG_VRAMADDR
     move.w  #88<<7,VRAM_RW
     move.w  #88<<7,REG_VRAMRW
</pre>
</syntaxhighlight>
 
[[Category:Code]]
[[Category:Graphics Code]]

Latest revision as of 01:42, 11 October 2018

How to display a 64*80 (4*5 tiles) sprite block at x=88, y=36.

Loading palette

At least one palette needs to be loaded. Here SpritePalette is loaded as palette 0 and the backdrop color is set to black.

    lea     SpritePalette,a0
    lea     PALETTES,a1
    moveq.l #16-1,d7
.ldpal
    move.w  (a0)+,(a1)+
    dbra    d7,.ldpal

    move.w  #BLACK,BACKDROP

Setting the map

The sprite's map is an array of tile numbers and attributes. Here the 4 sprites are made of tiles 0~4 with no special attributes.

    move.w  #64,d2          ;SCB1, sprite 1
    move.w  #1,REG_VRAMMOD
    moveq.l #4-1,d6
.sprites:
    move.w  d2,REG_VRAMADDR
    clr.w   d1              ;First tile is #0
    moveq.l #5-1,d7
.tiles:
    move.w  d1,REG_VRAMRW      ;Tile number
    move.w  #0,REG_VRAMRW      ;No attributes
    addq.b  #1,d1
    dbra    d7,.tiles
    addi.w  #64,d2          ;Next sprite
    dbra    d6,.sprites

Setting the shrinking

No shrinking at all (full size).

    move.w  #SCB2+1,REG_VRAMADDR
    moveq.l #4-1,d7
.zset:
    move.w  #$0FFF,REG_VRAMRW
    dbra    d7,.zset

Setting the size and vertical position

First sprite is the driving one, next are driven.

    move.w  #SCB3+1,REG_VRAMADDR
    move.w  #((496-36)<<7)+5,VRAM_RW ;Y position and size for the first sprite
    moveq.l #5-1-1,d7
.yset:
    move.w  #64,REG_VRAMRW   ;Sticky bit only for the 3 others
    dbra    d7,.yset

Setting the horizontal position

    move.w  #SCB4+1,REG_VRAMADDR
    move.w  #88<<7,REG_VRAMRW