Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .---------------------------.
- ( P A R T 5 . S P R I T E S )
- `---------------------------´
- This part has examples in BASIC because this part is mostly a summary of the excellent webpage by Marcello [1]. However, I think that it illustrates quite well how sprites can be used used in Assembly too.
- o==========o
- | Contents |
- o==========o
- general contents: https://pastebin.com/hmpJmurr
- A. Activate & define
- B. Position
- C. Position beyond 255
- D. Expand sprites
- E. Collision detection
- F. Multicolor
- Y. Summary of registers
- X. References
- -<>-<>-<>-<>-<>-<>-<>-<>-
- o======================o
- | A. Activate & define |
- o======================o
- Summary: 2040_dec (pointer), V = D000_hex (base addr), V + 21 (on/off), V + 39 (color).
- 1. (Real) Base address of the VIC-II: V = 53248_dec = D000_hex.
- 2. Turn sprites on/off: V + 21 = 53269_dec (= D015_hex). Example to turn all 8 on:
- POKE 53269,255 (255 = 1111 1111_bin)
- 3. A sprite = 24 x 21 pix = (24/8) bytes x 21 lines = 3 x 21 bytes = 63 bytes. Round that up to 64 B.
- 4. Pointer for sprite zero to the location in RAM where it's 64 k of data is:
- 2040_dec (07F8_hex)
- Range: 2040 - 2047_dec. They are the last 8 bytes below the 38 kB free RAM.
- 5. Set location (pointer) in RAM to "192" for sprite number zero. This actually means
- 192 x 64 bytes = 12288 Bytes = 12 kB = 3000_hex
- in RAM, that's in the middle of the 38 kB of free RAM:
- POKE 2040,192 (= 12288_dec)
- 6. Define a 24x21 solid block sprite at 12288_dec in free RAM:
- FOR T = 12288 TO 12350: POKE T,255: NEXT
- 7. The color of sprite number zero is defined at the sprite color register: V + 39 (53287_dec, D027_hex):
- POKE 53287,1 (color white)
- o=============o
- | B. Position |
- o=============o
- Summary: V (pos).
- 1. Screen size is 320 x 200. Notice that 320 = 255 (an 8 bit number) + 65. I.e. the screen is wider than 1 byte can address.
- 2. Sprite positions are set in registers V (53248_dec = D000_hex) to V + 15 (D00F_hex). Example, set X-position for sprite zero to 255:
- POKE 53248,255
- Y-pos. for sprite zero:
- POKE 53249,200
- X-pos. for sprite 1:
- POKE 53250,255
- and so on...
- o========================o
- | C. Position beyond 255 |
- o========================o
- Summary: V + 16 (extendend X-pos).
- 1. To position sprite beyond the 255 boundary (extended X position) use V + 16 (D010_hex). It's an 8 bit register of which each bit corresponds to one sprite. Bit 0 is for sprite 0 and so on. These bits set "the ninth bit" for the X-pos for a sprite on/off. Like so for sprite 0:
- Byte D010_hex: 0000 0001
- |_ Sprite No. 0 extd. pos.
- 2. It's X-position can be 255 (1 0000 0000_bin) if the 9 bits defining it are like so:
- 1 0000 0000
- | |_ The 8 bits from byte D000_hex
- |___ Bit No. 0 of byte D010_hex
- 3. Example for X = 320 = 256 + 64 (1 0100 000_bin):
- 1 0100 0000
- | |_ Byte D000_hex is 64_dec
- |___ Byte D010_hex is 1_dec
- 4. Or, more completely to get sprite 0 to X=320 and Y=200:
- V = 53248:
- POKE V+21,1 (set sprite 0 on):
- POKE 2040,192 (set mem location for sprite 0 to 192 x 64_dec = 12288_dec):
- POKE V+39,1 (color sprite black): FOR T = 12288 TO 12350: POKE T,255: NEXT:
- POKE V+16,1 (set extended X-pos bit for sprite 0 on):
- POKE V ,64 (set X-pos to 1000_0000_bin):
- POKE V+1 ,200 (Y-pos = 200)
- o===================o
- | D. Expand sprites |
- o===================o
- Summary: V + 23 (Y), V + 29 (X)
- Expand sprites in Y direction: V + 23 = 53271_dec = D017_hex. Each bit is a sprite. Example for sprite 0:
- D017_hex: 0000 0001
- |_ Sprite 0 will be expanded in Y direction.
- o========================o
- | E. Collision detection |
- o========================o
- Summary: V + 30 (sprite-sprite), V + 31 (sprite-backgr.)
- 1. To the 8 bits in register V + 30 = D01E_hex is written if a sprite collides with another sprite. Example if D01E is 3:
- 0000 0011
- ||_ Sprite 0 collided w/ another sprite.
- |__ It collided w/ sprite 1.
- 2. Same thing goes for V + 31 (D01F_hex) for sprite collision with a character in the background.
- 3. If *any* sprite collided then bits 1 and/or 2 are set to 1 in D019_hex. Interrupts for those events are written to bit 1 and/or 2 of D01A_hex (see [5]).
- o===============o
- | F. Multicolor |
- 0===============0
- Set a sprite to be multicolor in D01C_hex. Two bits in the 24x21 bitmap now represent a color (that's 4 colors). The sprite's pixels are 2 by 1 (i.e. horizontally stretched). The background color (00_bin) is in it's "usual" place of D021_hex and is the same for every sprite.
- Two additional colors are in D025 and D026_hex. They are also the same for every sprite.
- The forth color is different for every sprite and are at their "usual" places from D027 to D02E_hex.
- o=========================o
- | Y. Summary of registers |
- o=========================o
- Registers in hex:
- 07F8 - F Pointers to sprite data in RAM
- D000 - F X- and Y-positions of sprites on screen
- D010 Extended X-positions on/off
- D015 Turn sprites on/off
- D017 & D Expand in X- & Y-direction
- D01E & F Collision detection
- D027 - E Colors of sprites
- o===============o
- | X. References |
- o===============o
- [1] Good tutorial:
- http://retro64.altervista.org/blog/programming-sprites-the-commodore-64-simple-tutorial-using-basic-v2/
- [2] "C64 Assembly programming" by Mark Andrews, Howard W. Sams & Co. publ., ISBN 0-672-22244-5 (1985).
- [3] "The master memory map for the C64" by P. Pavelko and T. Kelly, Prentice Hall, ISBN 0-13-574351-6 (1983).
- [4] "C64 programmer's reference guide", Commodore Business Machines and Howard W. Sams and Co. publ., First ed. (1983).
- [5] HTML C64 memory map by Joe Forster:
- https://sta.c64.org/cbm64mem.html
Add Comment
Please, Sign In to add comment