Difference between revisions of "Programming:CPC Plus Hardware Sprites"
From CPCWiki - THE Amstrad CPC encyclopedia!
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | == [[ASIC]] memory addresses for HW Sprites (in HEX) == | ||
+ | |||
+ | ''' HW Sprite addresses: ''' | ||
+ | Each sprite takes 16x16=256 (#100) bytes in ASIC memory | ||
+ | ;#4000 - Sprite 0 | ||
+ | ;#4100 - Sprite 1 | ||
+ | ;#4200 - Sprite 2 | ||
+ | ;#4300 - Sprite 3 | ||
+ | ;#4400 - Sprite 4 | ||
+ | ;#4500 - Sprite 5 | ||
+ | ;#4600 - Sprite 6 | ||
+ | ;#4700 - Sprite 7 | ||
+ | ;#4800 - Sprite 8 | ||
+ | ;#4900 - Sprite 9 | ||
+ | ;#4A00 - Sprite #0A (10) | ||
+ | ;#4B00 - Sprite #0B (11) | ||
+ | ;#4C00 - Sprite #0C (12) | ||
+ | ;#4D00 - Sprite #0D (13) | ||
+ | ;#4E00 - Sprite #0E (14) | ||
+ | ;#4F00 - Sprite #0F (15) | ||
+ | |||
+ | '''HW Sprite colours:''' | ||
+ | Each sprite has its own colours (up to 4096), so 2 bytes are required for each colour. | ||
+ | ;#6422 - Sprite Color Pen 1 | ||
+ | ;#6424 - Sprite Color Pen 2 | ||
+ | ;#6426 - Sprite Color Pen 3 | ||
+ | ;#6428 - Sprite Color Pen 4 | ||
+ | ;#642a - Sprite Color Pen 5 | ||
+ | ;#642c - Sprite Color Pen 6 | ||
+ | ;#642e - Sprite Color Pen 7 | ||
+ | ;#6430 - Sprite Color Pen 8 | ||
+ | ;#6432 - Sprite Color Pen 9 | ||
+ | ;#6434 - Sprite Color Pen 10 | ||
+ | ;#6436 - Sprite Color Pen 11 | ||
+ | ;#6438 - Sprite Color Pen 12 | ||
+ | ;#643a - Sprite Color Pen 13 | ||
+ | ;#643c - Sprite Color Pen 14 | ||
+ | ;#643e - Sprite Color Pen 15 | ||
+ | |||
+ | '''HW Sprite position x,y''' | ||
+ | ;#6000 - Spr 0 Pos X | ||
+ | ;#6002 - Spr 0 Pos Y | ||
+ | ;#6008 - Spr 1 Pos X | ||
+ | ;#600a - Spr 1 Pos Y | ||
+ | ;#6010 - Spr 2 Pos X | ||
+ | ;#6012 - Spr 2 Pos Y | ||
+ | ;#6018 - Spr 3 Pos X | ||
+ | ;#601a - Spr 3 Pos Y | ||
+ | ;#6020 - Spr 4 Pos X | ||
+ | ;#6022 - Spr 4 Pos Y | ||
+ | ;#6028 - Spr 5 Pos X | ||
+ | ;#602a - Spr 5 Pos Y | ||
+ | ;#6030 - Spr 6 Pos X | ||
+ | ;#6032 - Spr 6 Pos Y | ||
+ | ;#6038 - Spr 7 Pos X | ||
+ | ;#603A - Spr 7 Pos Y | ||
+ | ;#6040 - Spr 8 Pos X | ||
+ | ;#6042 - Spr 8 Pos Y | ||
+ | ;#6048 - Spr 9 Pos X | ||
+ | ;#604a - Spr 9 Pos Y | ||
+ | ;#6050 - Spr 10 Pos X | ||
+ | ;#6052 - Spr 10 Pos Y | ||
+ | ;#6058 - Spr 11 Pos X | ||
+ | ;#605a - Spr 11 Pos Y | ||
+ | ;#6060 - Spr 12 Pos X | ||
+ | ;#6062 - Spr 12 Pos Y | ||
+ | ;#6068 - Spr 13 Pos X | ||
+ | ;#606a - Spr 13 Pos Y | ||
+ | ;#6070 - Spr 14 pos X | ||
+ | ;#6072 - Spr 14 Pos Y | ||
+ | ;#6078 - Spr 15 Pos X | ||
+ | ;#607a - Spr 15 Pos Y | ||
+ | |||
+ | '''HW Sprite resolution:''' | ||
+ | You can select sprite magnification x1, x2 or x4. | ||
+ | |||
+ | #value 00 => Sprite not visible | ||
+ | #value 01 => Sprite resolution 640 (magnify x1 - mode 2) | ||
+ | #value 10 => Sprite resolution 320 (magnify x2 - mode 1) | ||
+ | #value 11 => Sprite resolution 160 (magnify x4 - mode 0) | ||
+ | ;#6004 - Sprite 0 resolution | ||
+ | ;#600c - Sprite 1 resolution | ||
+ | ;#6014 - Sprite 2 resolution | ||
+ | ;#601c - Sprite 3 resolution | ||
+ | ;#6024 - Sprite 4 resolution | ||
+ | ;#602c - Sprite 5 resolution | ||
+ | ;#6034 - Sprite 6 resolution | ||
+ | ;#603c - Sprite 7 resolution | ||
+ | ;#6044 - Sprite 8 resolution | ||
+ | ;#604c - Sprite 9 resolution | ||
+ | ;#6054 - Sprite 10 resolution | ||
+ | ;#605c - Sprite 11 resolution | ||
+ | ;#6064 - Sprite 12 resolution | ||
+ | ;#606c - Sprite 13 resolution | ||
+ | ;#6074 - Sprite 14 resolution | ||
+ | ;#607c - Sprite 15 resolution | ||
+ | |||
+ | == Coding example == | ||
+ | |||
From the '''The Unofficial Amstrad WWW Resource''' | From the '''The Unofficial Amstrad WWW Resource''' | ||
Latest revision as of 07:04, 2 February 2014
ASIC memory addresses for HW Sprites (in HEX)
HW Sprite addresses: Each sprite takes 16x16=256 (#100) bytes in ASIC memory
- 4000 - Sprite 0
- 4100 - Sprite 1
- 4200 - Sprite 2
- 4300 - Sprite 3
- 4400 - Sprite 4
- 4500 - Sprite 5
- 4600 - Sprite 6
- 4700 - Sprite 7
- 4800 - Sprite 8
- 4900 - Sprite 9
- 4A00 - Sprite #0A (10)
- 4B00 - Sprite #0B (11)
- 4C00 - Sprite #0C (12)
- 4D00 - Sprite #0D (13)
- 4E00 - Sprite #0E (14)
- 4F00 - Sprite #0F (15)
HW Sprite colours: Each sprite has its own colours (up to 4096), so 2 bytes are required for each colour.
- 6422 - Sprite Color Pen 1
- 6424 - Sprite Color Pen 2
- 6426 - Sprite Color Pen 3
- 6428 - Sprite Color Pen 4
- 642a - Sprite Color Pen 5
- 642c - Sprite Color Pen 6
- 642e - Sprite Color Pen 7
- 6430 - Sprite Color Pen 8
- 6432 - Sprite Color Pen 9
- 6434 - Sprite Color Pen 10
- 6436 - Sprite Color Pen 11
- 6438 - Sprite Color Pen 12
- 643a - Sprite Color Pen 13
- 643c - Sprite Color Pen 14
- 643e - Sprite Color Pen 15
HW Sprite position x,y
- 6000 - Spr 0 Pos X
- 6002 - Spr 0 Pos Y
- 6008 - Spr 1 Pos X
- 600a - Spr 1 Pos Y
- 6010 - Spr 2 Pos X
- 6012 - Spr 2 Pos Y
- 6018 - Spr 3 Pos X
- 601a - Spr 3 Pos Y
- 6020 - Spr 4 Pos X
- 6022 - Spr 4 Pos Y
- 6028 - Spr 5 Pos X
- 602a - Spr 5 Pos Y
- 6030 - Spr 6 Pos X
- 6032 - Spr 6 Pos Y
- 6038 - Spr 7 Pos X
- 603A - Spr 7 Pos Y
- 6040 - Spr 8 Pos X
- 6042 - Spr 8 Pos Y
- 6048 - Spr 9 Pos X
- 604a - Spr 9 Pos Y
- 6050 - Spr 10 Pos X
- 6052 - Spr 10 Pos Y
- 6058 - Spr 11 Pos X
- 605a - Spr 11 Pos Y
- 6060 - Spr 12 Pos X
- 6062 - Spr 12 Pos Y
- 6068 - Spr 13 Pos X
- 606a - Spr 13 Pos Y
- 6070 - Spr 14 pos X
- 6072 - Spr 14 Pos Y
- 6078 - Spr 15 Pos X
- 607a - Spr 15 Pos Y
HW Sprite resolution: You can select sprite magnification x1, x2 or x4.
- value 00 => Sprite not visible
- value 01 => Sprite resolution 640 (magnify x1 - mode 2)
- value 10 => Sprite resolution 320 (magnify x2 - mode 1)
- value 11 => Sprite resolution 160 (magnify x4 - mode 0)
- 6004 - Sprite 0 resolution
- 600c - Sprite 1 resolution
- 6014 - Sprite 2 resolution
- 601c - Sprite 3 resolution
- 6024 - Sprite 4 resolution
- 602c - Sprite 5 resolution
- 6034 - Sprite 6 resolution
- 603c - Sprite 7 resolution
- 6044 - Sprite 8 resolution
- 604c - Sprite 9 resolution
- 6054 - Sprite 10 resolution
- 605c - Sprite 11 resolution
- 6064 - Sprite 12 resolution
- 606c - Sprite 13 resolution
- 6074 - Sprite 14 resolution
- 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