UDG in Assembly

edited August 2012 in Development
How do you create User Definable Graphic and move it around the screen? In C64 its as easy as:
SPRITEENABLE = $d015
SPRITEPOINTER = $07f8

=* 2000

Sprite
 !byte $00, $0f, $ff	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000
 !byte $00, $00, $00	; 000000000000000000000000

*= 3000

; enabling it (1= sprite 0, 3 = sprite 0, 1, 7 = sprite 0, 1, 2 etc)

 lda #$07

 sta SPRITEENABLE		; turn on sprites 0 and 1

; then pointing to it

 lda #(Sprite/$40)

 sta SPRITEPOINTER		; set sprite pointer for sprite 0

; setting it's color
SPRITE0COLOR = $d027

; and then setting it's position using the registers
SPRITE0X = $d000
SPRITE0Y = $d001
Is it as easy as this or harder? Any assistance would be greatly appreciated.

Sincerely,

ZXogger
Post edited by Zxogger on

Comments

  • edited August 2012
    In the case of the spectrum, there is no dedicated sprite hardware or toolset to manage them. Instead, you have the CPU and the entire RAM at your disposal to use it as you see fit.

    So, while creating a sprite from bit patterns isn't particularly difficult (quite similar to how you do it above actually), moving the sprites around is a bit more complicated because of the way the speccy's display is arranged.

    You could look around in the development section of this forum to see various threads on the very same topic. Or you could have a look at some of the tutorials in the Chuntey blog (see my sig) regarding sprite handling. There are also *tons* of books in the archive that you can download and refer to at your leisure on the subject.

    This forums is of course always at your disposal in case you need any specific tips and help in this regard. :)
  • edited August 2012
    Looks like you're talking about sprites rather than UDGs. The Spectrum doesn't have hardware sprites, but it does have the rather excellent splib sprite library for z88dk. This probably isn't the most up to date link, but it should get you started: http://www.timexsinclair.org/alvin/
  • edited August 2012
    UDG is a concept from Spectrum implementation of Basic. In assembler you theoretically could call the ROM routines dealing with UDG (they are the same routines used to print letters) but forget it :) It's always better to write something your own than to rely on slow and limited ROM procedures.

    Some simplest "sprite"
    LD HL,16000
     LD DE,16384
     LD B,8
    Loop:
     LD A,(HL)
     LD (DE),A
     INC HL
     INC D
     DJNZ Loop
     RET
    

    It will copy from the ROM graphics making the "P" letter but you can point to any other graphics.

    All sprite drawing in Spectrum is copying data to screen memory. There is not any other way.

    This example is sprite drawing at "equal" position - fitting it precisely into a grid 32x24, a bit similar to text mode. Drawing just anywhere is much harder and you'll have to learn the Spectrum screen organisation. It's not easy for beginner but don't give up and you'll eventually get it :)
  • edited August 2012
    Here's some TAPs (with instructions) of useful magazine type-in sprite routines from TTFn.

    Star Tip 7 (Sprite Moving), Raffaelle Cecco, Your Sinclair, Dec'87
    Sprite Designer, Toni Baker, Your Spectrum, Dec'84
    Sprite Designer, Chris Wood, Your Spectrum, Oct'85
    Sprite Creator, Roger Allen, Sinclair Programs, Dec'84
    Sprite Editor, Robert Newman, Your Computer, Jun'85
    Sprite Designer, Dom Early, Your Sinclair, Apr'88
    Sprite Editor, Simon Owen, Your Sinclair, Aug'88
    Sprite Grabber, Steve Anderson, Your Sinclair, Nov'92
  • edited August 2012
    Here's some TAPs (with instructions) of useful magazine type-in sprite routines...

    Well knowing Simon Owen's work that one might suit the OP, but really unless you want to write your own routine from scratch there's no good reason not to use Alvin's splib.
Sign In or Register to comment.