Last modified on 2 February 2014, at 08:00

Programming:CPC Plus Hardware Sprites

Revision as of 08:00, 2 February 2014 by Fgbrain (Talk | contribs)

ASIC memory addresses for HW Sprites (in HEX)

HW Sprite addresses: Each sprites takes 16x16=256 (#100) bytes in ASIC memory

  1. 4000 - Sprite 0
  2. 4100 - Sprite 1
  3. 4200 - Sprite 2
  4. 4300 - Sprite 3
  5. 4400 - Sprite 4
  6. 4500 - Sprite 5
  7. 4600 - Sprite 6
  8. 4700 - Sprite 7
  9. 4800 - Sprite 8
  10. 4900 - Sprite 9
  11. 4A00 - Sprite #0A (10)
  12. 4B00 - Sprite #0B (11)
  13. 4C00 - Sprite #0C (12)
  14. 4D00 - Sprite #0D (13)
  15. 4E00 - Sprite #0E (14)
  16. 4F00 - Sprite #0F (15)

HW Sprite colours:

  1. 6422 - Sprite Color Pen 1
  2. 6424 - Sprite Color Pen 2
  3. 6426 - Sprite Color Pen 3
  4. 6428 - Sprite Color Pen 4
  5. 642a - Sprite Color Pen 5
  6. 642c - Sprite Color Pen 6
  7. 642e - Sprite Color Pen 7
  8. 6430 - Sprite Color Pen 8
  9. 6432 - Sprite Color Pen 9
  10. 6434 - Sprite Color Pen 10
  11. 6436 - Sprite Color Pen 11
  12. 6438 - Sprite Color Pen 12
  13. 643a - Sprite Color Pen 13
  14. 643c - Sprite Color Pen 14
  15. 643e - Sprite Color Pen 15

HW Sprite position x,y

  1. 6000 - Spr 0 Pos X
  2. 6002 - Spr 0 Pos Y
  3. 6008 - Spr 1 Pos X
  4. 600a - Spr 1 Pos Y
  5. 6010 - Spr 2 Pos X
  6. 6012 - Spr 2 Pos Y
  7. 6018 - Spr 3 Pos X
  8. 601a - Spr 3 Pos Y
  9. 6020 - Spr 4 Pos X
  10. 6022 - Spr 4 Pos Y
  11. 6028 - Spr 5 Pos X
  12. 602a - Spr 5 Pos Y
  13. 6030 - Spr 6 Pos X
  14. 6032 - Spr 6 Pos Y
  15. 6038 - Spr 7 Pos X
  16. 603A - Spr 7 Pos Y
  17. 6040 - Spr 8 Pos X
  18. 6042 - Spr 8 Pos Y
  19. 6048 - Spr 9 Pos X
  20. 604a - Spr 9 Pos Y
  21. 6050 - Spr 10 Pos X
  22. 6052 - Spr 10 Pos Y
  23. 6058 - Spr 11 Pos X
  24. 605a - Spr 11 Pos Y
  25. 6060 - Spr 12 Pos X
  26. 6062 - Spr 12 Pos Y
  27. 6068 - Spr 13 Pos X
  28. 606a - Spr 13 Pos Y
  29. 6070 - Spr 14 pos X
  30. 6072 - Spr 14 Pos Y
  31. 6078 - Spr 15 Pos X
  32. 607a - Spr 15 Pos Y

HW Sprite resolution:

  1. value 00 => Sprite not visible
  2. value 01 => Sprite resolution 640 (magnify x1 - mode 2)
  3. value 10 => Sprite resolution 320 (magnify x2 - mode 1)
  4. value 11 => Sprite resolution 160 (magnify x4 - mode 0)
  1. 6004 - Sprite 0 resolution
  2. 600c - Sprite 1 resolution
  3. 6014 - Sprite 2 resolution
  4. 601c - Sprite 3 resolution
  5. 6024 - Sprite 4 resolution
  6. 602c - Sprite 5 resolution
  7. 6034 - Sprite 6 resolution
  8. 603c - Sprite 7 resolution
  9. 6044 - Sprite 8 resolution
  10. 604c - Sprite 9 resolution
  11. 6054 - Sprite 10 resolution
  12. 605c - Sprite 11 resolution
  13. 6064 - Sprite 12 resolution
  14. 606c - Sprite 13 resolution
  15. 6074 - Sprite 14 resolution
  16. 607c - Sprite 15 resolution

Coding example

From the The Unofficial Amstrad WWW Resource

;; This example shows a CPC+ hardware sprite.
;;
;; This example is designed for CPC+ only and will
;; not work on CPC or KC Compact.
;;
;;
;; This example will compile with the MAXAM assembler
;; or the built-in assembler of WinAPE32.


;; NOTE - For this example to work, the code must not
;; be in the range &4000-&7fff inclusive. The ASIC registers
;; are paged into this range, and the code would not be
;; visible to the CPU if it was also in this range.
org &8000


;;--------------------------------------------------
;; STEP 1 - Unlock CPC+ additional features
;; unlock asic to gain access to asic registers

di
ld b,&bc
ld hl,sequence
ld e,17
.seq 
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq
ei

;;--------------------------------------------------
;; STEP 2 - Setup sprite pixel data
;;
;; The ASIC has internal "RAM" used to store the sprite pixel
;; data. If you want to change the pixel data for a sprite
;; then you need to copy new data into the internal "RAM".

;; page-in asic registers to &4000-&7fff
ld bc,&7fb8
out (c),c

;; stored sprite pixel data
ld hl,sprite_pixel_data

;; address of sprite 0 pixel data
;; sprite 0 pixel data is in the range &4000-&4100
ld de,&4000

;; length of pixel data for a single sprite (16x16 = 256)
ld bc,&100
ldir

;; page-out asic registers
ld bc,&7fa0
out (c),c

;;--------------------------------------------------
;; STEP 3 - Setup sprite palette
;;
;; The sprites use a single 15 entry sprite palette.
;; pen 0 is ALWAYS transparent.
;;
;; The sprite palette is different to the screen palette.

;; page-in asic registers to &4000-&7fff
ld bc,&7fb8
out (c),c

;; copy colours into ASIC sprite palette registers
ld hl,sprite_colours
ld de,&6422
ld bc,15*2
ldir

;; page-out asic registers
ld bc,&7fa0
out (c),c

;;--------------------------------------------------
;; STEP 4 - Setup sprite properties
;;
;; Each sprite has properties which define the x,y coordinates 
;; and x,y magnification.

;; page-in asic registers to &4000-&7fff
ld bc,&7fb8
out (c),c


;; set x coordinate for sprite 0
ld hl,100
ld (&6000),hl

;; set y coordinate for sprite 0
ld hl,100
ld (&6002),hl

;; set sprite x and y magnification
;; x magnification = 1
;; y magnification = 1
ld a,%0101
ld (&6004),a


;; page-out asic registers
ld bc,&7fa0
out (c),c

;;--------------------------------------------------
ret


;;--------------------------------------------------
;; - there is two bytes per colour.
;; - these are stored in a form that can be written direct 
;; to the CPC+ colour palette registers (i.e. xGRB)
;; - pen 0 is always transparent and doesn't have a entry
;; in the CPC+ palette

.sprite_colours
defw &0111			;; colour for sprite pen 1
defw &0222			;; colour for sprite pen 2
defw &0333			;; colour for sprite pen 3
defw &0444			;; colour for sprite pen 4
defw &0555			;; colour for sprite pen 5
defw &0666			;; colour for sprite pen 6
defw &0777			;; colour for sprite pen 7
defw &0888			;; colour for sprite pen 8
defw &0999			;; colour for sprite pen 9
defw &0aaa			;; colour for sprite pen 10
defw &0bbb			;; colour for sprite pen 11
defw &0ccc			;; colour for sprite pen 12
defw &0ddd			;; colour for sprite pen 13
defw &0eee			;; colour for sprite pen 14
defw &0fff			;; colour for sprite pen 15

;;---------------------------------------------
;; - there is one pixel per byte (bits 3..0 of each byte define the palette index for this pixel)
;; - these bytes are stored in a form that can be written direct to the ASIC
;; sprite pixel data
.sprite_pixel_data
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 0
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 1
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 2
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 3
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 4
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 5
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 6
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 7
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 8
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 9
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 10
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 11
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 12
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 13
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 14
defb &00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00,&00		;; line 15


;;----------------------------------------------------------
;; this is the sequence to unlock the ASIC extra features
.sequence
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee

See Also