Table Of ContentProgramming Games for The ColecoVision
and Adam
In Assembler
By Tony Cruise
Programming Games for the ColecoVision and Adam In Assembler
Copyright © 2020 Tony Cruise
All rights reserved
Special Thanks
Matt Householder - Editor,
Michael Thomasson – Forward & Cover Design,
The AtariAge Community
All rights reserved. No part of this book may be reproduced by any means including photocopying,
scanning or by any information storage retrieval system without written permission from the
publisher. The company names, logos, trademarks, games and machines depicted in this book are
copyrights of their respective owners.
Page | 2
Table of Contents
Table of Contents ......................................................................................................................................... 3
Forward by Michael Thomasson ................................................................................................................ 11
About the Author ....................................................................................................................................... 13
1. Introduction ........................................................................................................................................ 15
1.1. The ColecoVision ......................................................................................................................... 16
Specifications ...................................................................................................................................... 16
1.2. The Coleco Adam ........................................................................................................................ 17
Specifications ...................................................................................................................................... 17
2. Getting Setup ...................................................................................................................................... 18
2.1. Overview of the tools .................................................................................................................. 18
Emulators ............................................................................................................................................ 18
Advanced Text Editor .......................................................................................................................... 18
Assembler............................................................................................................................................ 18
Graphics Creation ................................................................................................................................ 18
2.2. Sprite & Tile Editor ...................................................................................................................... 19
3. Emulation ............................................................................................................................................ 20
3.1. BlueMSX ...................................................................................................................................... 20
3.2. OpenMSX .................................................................................................................................... 20
3.3. CoolCV ......................................................................................................................................... 20
3.4. ColEm .......................................................................................................................................... 21
4. Editor/Assembler/Template ............................................................................................................... 22
ConTEXT Text Editor ............................................................................................................................ 22
Z80 Syntax Mark-up file for ConTEXT (WLA-Z80 Assembler) .............................................................. 22
TNIAsm (version 0.45) ......................................................................................................................... 22
ColecoVision Assembler Templates .................................................................................................... 22
4.1. Step 1 – Setting up the text editor .............................................................................................. 23
a. Download and Install .................................................................................................................. 23
b. Setting up Z80 Syntax Highlighting ............................................................................................. 23
4.2. Step 2 – Setting up the Z80 Assembler ....................................................................................... 24
4.3. Step 3 – Add an execute key to ConTEXT for the Assembler ...................................................... 25
5. The Structure of a Game ..................................................................................................................... 28
5.1. Setup/Initialisation ...................................................................................................................... 28
Set graphics mode ............................................................................................................................... 28
Initialise Sound Hardware ................................................................................................................... 28
Page | 3
Initialise Controllers ............................................................................................................................ 28
5.2. Title/Intro/High Score Screen(s) ................................................................................................. 29
Load Graphics and Patterns and Draw Screen(s) ................................................................................ 29
Intro Screen Loop ................................................................................................................................ 29
5.3. The Game Loop ........................................................................................................................... 30
Get Player Input, Move Player ............................................................................................................ 30
Enemy spawn/initialisation ................................................................................................................. 30
Move enemies ..................................................................................................................................... 30
Collision detection .............................................................................................................................. 30
Animations .......................................................................................................................................... 30
Draw changes to screen ...................................................................................................................... 31
6. Starting Z80 Assembler ....................................................................................................................... 32
6.1. Memory and Registers ................................................................................................................ 32
6.2. Moving Things Around ................................................................................................................ 34
6.3. Let’s Do Some Maths .................................................................................................................. 35
Addition ............................................................................................................................................... 35
Subtraction .......................................................................................................................................... 35
Increasing and Decreasing .................................................................................................................. 36
7. Z80 Loops, Conditions and Bits ........................................................................................................... 37
7.1. Loops and Conditions .................................................................................................................. 37
Jumps .................................................................................................................................................. 38
7.2. Bytes, Bits and Nibbles ................................................................................................................ 40
What is Hexadecimal, You Say? .......................................................................................................... 40
8. Starting Somewhere ........................................................................................................................... 41
8.1. Definitions ................................................................................................................................... 42
8.2. Library Functions ......................................................................................................................... 45
8.3. Main Source File .......................................................................................................................... 54
9. Starting a Game .................................................................................................................................. 61
9.1. Preparing the template ............................................................................................................... 62
9.2. Initialising our graphics ............................................................................................................... 65
9.3. Displaying Our Title Screen ......................................................................................................... 66
9.4. Displaying Our Game Screen ....................................................................................................... 69
10. Move and Shoot .............................................................................................................................. 72
10.1. Moving the Player’s Ship ......................................................................................................... 72
10.2. Firing a player bullet ............................................................................................................... 74
Page | 4
10.3. Move the Player Bullet ............................................................................................................ 76
11. Enemy Movement ........................................................................................................................... 77
11.1. Step One – Asteroid Generation ............................................................................................. 77
Random Number Functions ................................................................................................................ 77
Setup Code .......................................................................................................................................... 78
Generate Enemies ............................................................................................................................... 79
11.2. Step Two – Enemy Movement ................................................................................................ 82
11.3. Summary ................................................................................................................................. 83
12. Collision Detection .......................................................................................................................... 84
12.1. Step One – Object Collisions ................................................................................................... 84
12.2. Step Two – Enemy Collisions ................................................................................................... 86
13. Scoring ............................................................................................................................................. 87
13.1. Displaying the Current Score .................................................................................................. 88
13.2. Adding to the Current Score ................................................................................................... 90
13.3. Subtracting from the Current Score ........................................................................................ 92
13.4. Calling the Display Routine ..................................................................................................... 94
13.5. Adding Scoring to our Game ................................................................................................... 95
14. Player Collisions and Lives .............................................................................................................. 96
14.1. Player Collisions ...................................................................................................................... 96
14.2. Display the Player’s Lives ........................................................................................................ 98
14.3. Game Over ............................................................................................................................ 100
15. More Enemies ............................................................................................................................... 101
15.1. Enemy Management ............................................................................................................. 101
ROM Table......................................................................................................................................... 101
RAM Table ......................................................................................................................................... 102
15.2. Updated Code ....................................................................................................................... 103
Set up ................................................................................................................................................ 103
Spawn Enemies ................................................................................................................................. 104
Move Enemies ................................................................................................................................... 106
16. TMS9918A - Graphics .................................................................................................................... 109
16.1. Video RAM Break Down ........................................................................................................ 111
Graphics Modes I & II ........................................................................................................................ 111
Text Mode ......................................................................................................................................... 112
Multicolour Mode ............................................................................................................................. 112
16.2. Hardware Sprites................................................................................................................... 113
Page | 5
16.3. Example Code – TMS Demo .................................................................................................. 114
Animating a tile pattern .................................................................................................................... 115
Animating the colour table ............................................................................................................... 116
More colour table animation ............................................................................................................ 118
17. TMS9918A - Sprites ....................................................................................................................... 120
17.1. Using Sprites.......................................................................................................................... 122
17.2. On with Our Demo ................................................................................................................ 123
Sprite shapes ..................................................................................................................................... 123
Loading Sprite Patterns ..................................................................................................................... 124
Draw Our Sprites ............................................................................................................................... 124
Animate Our Sprites .......................................................................................................................... 126
Move Our Sprites .............................................................................................................................. 128
18. Generating Sounds ........................................................................................................................ 130
18.1. SN76389A Sound Chip .......................................................................................................... 130
18.2. Sound Example ...................................................................................................................... 133
19. Sound Effects ................................................................................................................................ 135
19.1. OS 7 BIOS Sound ................................................................................................................... 136
Sounds Effects and Music Data ......................................................................................................... 136
Sound Address Table ......................................................................................................................... 139
19.2. Player Shooting ..................................................................................................................... 140
19.3. Player Laser Hitting an Enemy .............................................................................................. 144
19.4. Enemy Hitting Player ............................................................................................................. 145
19.5. Enemy Hitting the Ground .................................................................................................... 147
19.6. Adding the Sound Effects to our Game ................................................................................. 149
Adding Player Shooting Sound .......................................................................................................... 149
Adding Enemy Object Destroyed Sound ........................................................................................... 150
Adding Player Ship Destroyed Sound ................................................................................................ 151
Adding Enemy Object Hitting Planet Surface Sound ........................................................................ 152
20. Playing Music ................................................................................................................................ 153
20.1. Converting Notes to Frequencies.......................................................................................... 153
20.2. Play a Tune ............................................................................................................................ 154
20.3. Improving the Tune ............................................................................................................... 157
20.4. Adding the 2nd Track .............................................................................................................. 159
20.5. Stopping the Music ............................................................................................................... 162
21. Where to from here ...................................................................................................................... 163
Page | 6
21.1. More Enemies ....................................................................................................................... 163
21.2. More Complex Enemies ........................................................................................................ 163
21.3. Extra Lives ............................................................................................................................. 163
21.4. Increased Difficulty ............................................................................................................... 163
21.5. Music ..................................................................................................................................... 163
21.6. Arcade Touches ..................................................................................................................... 163
22. Appendix A – ColecoVision BIOS Functions (OS 7) ........................................................................ 164
TURN_OFF_SOUND ........................................................................................................................... 164
SOUND_INIT ...................................................................................................................................... 165
PLAY_IT .............................................................................................................................................. 166
PLAY_SONGS ..................................................................................................................................... 167
SOUND_MAN .................................................................................................................................... 168
22.1. Video Routines ...................................................................................................................... 169
FILL_VRAM ........................................................................................................................................ 169
GAME_OPT ........................................................................................................................................ 170
GET_VRAM ........................................................................................................................................ 171
INIT_SPR_ORDER ............................................................................................................................... 172
INIT_TABLE ........................................................................................................................................ 173
LOAD_ASCII ....................................................................................................................................... 174
MODE_1 ............................................................................................................................................ 175
PUT_VRAM ........................................................................................................................................ 176
READ_REGISTER ................................................................................................................................ 177
READ_VRAM ..................................................................................................................................... 178
WRITE_REGISTER .............................................................................................................................. 179
WRITE_VRAM .................................................................................................................................... 180
WR_SPR_NM_TBL (EOS WR_SPR_ATTRIBUT) ................................................................................... 181
22.2. Object Routines ..................................................................................................................... 182
ACTIVATE ........................................................................................................................................... 183
CALC_OFFSET .................................................................................................................................... 184
GET_BKGRND .................................................................................................................................... 185
INIT_WRITER ..................................................................................................................................... 186
PUTCOMPLEX .................................................................................................................................... 187
PUT_FRAME ...................................................................................................................................... 188
PUT_MOBILE ..................................................................................................................................... 189
PUTOBJ .............................................................................................................................................. 190
Page | 7
PUTSEMI ............................................................................................................................................ 191
PUT0SPRITE ....................................................................................................................................... 192
PX_TO_PTRN_POS ............................................................................................................................. 193
SET_UP_WRITE .................................................................................................................................. 194
WRITER .............................................................................................................................................. 195
22.3. Timer Routines ...................................................................................................................... 196
Timer Data Structures ....................................................................................................................... 196
FREE_SIGNAL ..................................................................................................................................... 197
INIT_TIMER........................................................................................................................................ 198
REQUEST_SIGNAL.............................................................................................................................. 199
TEST_SIGNAL ..................................................................................................................................... 200
TIME_MGR ........................................................................................................................................ 201
22.4. Controller Routines ............................................................................................................... 202
ARM_DBNCE ..................................................................................................................................... 203
CONT_READ ...................................................................................................................................... 204
CONTROLLER_INIT ............................................................................................................................ 205
CONTROLLER_SCAN .......................................................................................................................... 206
DECODER ........................................................................................................................................... 207
FIRE_DBNCE ...................................................................................................................................... 208
JOY_DBNCE ....................................................................................................................................... 209
KBD_DBNCE....................................................................................................................................... 210
POLLER .............................................................................................................................................. 211
UPDATE_SPINNER ............................................................................................................................. 212
22.5. Graphics Primitives ............................................................................................................... 213
ENLARGE ........................................................................................................................................... 214
REFLECT_HORZONTAL ....................................................................................................................... 215
REFLECT_VERTICAL ........................................................................................................................... 216
ROTATE_90........................................................................................................................................ 217
22.6. Miscellaneous Functions ....................................................................................................... 218
ADD816 ............................................................................................................................................. 218
BOOT_UP .......................................................................................................................................... 219
DECLSN .............................................................................................................................................. 220
DECMSN ............................................................................................................................................ 221
DISPLAY_LOGO .................................................................................................................................. 222
MSNTOLSN ........................................................................................................................................ 223
Page | 8
POWER_UP........................................................................................................................................ 224
RAND_GEN ........................................................................................................................................ 225
23. Appendix B – Adam Computer EOS .............................................................................................. 226
23.1. EOS Initialisation ................................................................................................................... 226
23.2. EOS Memory Map ................................................................................................................. 226
23.3. EOS Error Codes .................................................................................................................... 227
23.4. EOS Functions ....................................................................................................................... 228
System Operations ............................................................................................................................ 228
Simple Device Operations ................................................................................................................. 231
File Manager Operations .................................................................................................................. 237
Device Driver Operations .................................................................................................................. 243
24. Appendix C – Memory Map .......................................................................................................... 247
24.1. Memory Maps ....................................................................................................................... 247
ColecoVision General Memory Map ................................................................................................. 247
Adam General Memory Map ............................................................................................................ 247
24.2. Complete OS 7’ RAM Map .................................................................................................... 248
25. Appendix D – Z80 I/O Ports Assignments ..................................................................................... 250
25.1. ColecoVision Console ............................................................................................................ 250
Video Display Processor .................................................................................................................... 250
Sound Generator ............................................................................................................................... 250
Game Controller ................................................................................................................................ 250
Modem .............................................................................................................................................. 250
Expansion connector #2 .................................................................................................................... 250
Memory Map .................................................................................................................................... 250
Network reset ................................................................................................................................... 250
25.2. Adam Computer .................................................................................................................... 251
Memory Bank Switch Port (7fh) ........................................................................................................ 253
26. Appendix E – Distributing Your Title ............................................................................................. 254
26.1. Standard Cartridges .............................................................................................................. 254
26.2. MegaCart ............................................................................................................................... 255
26.3. High-Speed Tape ................................................................................................................... 256
27. References .................................................................................................................................... 257
27.1. References ............................................................................................................................ 257
27.2. Image Sources ....................................................................................................................... 257
28. Index .............................................................................................................................................. 258
Page | 9
Page | 10