Coding on the CV

Posts about programming the Coleco Vision
Post Reply
User avatar
Milli
Site Admin
Posts: 59
Joined: Fri Jul 19, 2019 3:13 pm
Location: Beaver Falls PA
Contact:

Coding on the CV

Post by Milli » Thu Nov 14, 2019 8:15 am

I have recently begun coding games for the CV. It basically is the same as coding for the Adam with very limited RAM (less than 1kb) and you use the OS7 ROM instead of EOS. Is anyone else doing this? I am looking for examples of sound in Assembly code.
Milli

User avatar
pearsoe
Posts: 10
Joined: Sun Jul 21, 2019 3:28 pm

Re: Coding on the CV

Post by pearsoe » Wed Nov 20, 2019 6:27 pm

Hi Milli,

I'll try to explain Colecovision sound programming as best as I can. The three best resources I have found are:
1. "Colecovision Coding Guide" by Daniel Bienvenu starting at page 198. Good documentation on sound structure.
2. "Official Colecovision Programming Manual" section 7 Sound Generation
3. Disassembling Colecovision games that actually use OS7 calls, a lot of them do not.

Here are the equates I'll reference:

SOUND_INIT: EQU 1FEEh ;B=concurrent voices+effects, HL=song table
SOUND_MGR: EQU 1FF4h
PLAY_IT: EQU 1FF1h ;B=Song number
PLAY_SONGS: EQU 1F61h
TURN_OFF_SOUND: EQU 1FD6h
NUM_SOUND_DATA_AREAS: EQU 5

Generating sound on the Colecovision using OS7 requires 4 steps:

1. Initialization
2. Sound Definitions
3. VDP routines
4. Playing (starting) a sound

1. Initialization

; Initialize Sound
CALL TURN_OFF_SOUND

LD B,NUM_SOUND_DATA_AREAS ;number of active voices+effects, minimum of 4 for 4 channel sound
LD HL,SOUND_TABLE ;pointer to memory location where you will define your sounds to their data areas, see Sound Definitions below
CALL SOUND_INIT

2. Sound definitions.

You can have multiple sounds use the same data area. Playing a sound in the same data area will of course stop the sound that was previously playing. Each sound data area requires 10 bytes of RAM.

SOUND_TABLE: ;the pointer used in initialization
;pointer to sound data,ram sound/channel data area
DW DATA_SOUND_01H,72E0h ; click sound
DW DATA_SOUND_02H,72EAh ; music channel 1
DW DATA_SOUND_03H,72F4h ; music channel 2
DW DATA_SOUND_04H,72FEh ; music channel 3
DW DATA_SOUND_05H,7308h ; music channel 4
DW 0,0 ;table must end with this

DATA_SOUND_01H:
DB 03H,00H,66H,04H,00H,00H,75H,11H
DB 10H ;sound stops after one play, no repeat

You would have one of these for each sound as defined in your SOUND_TABLE. So for this example I would need DATA_SOUND_02H, DATA_SOUND_03H, DATA_SOUND_04H and DATA_SOUND_05H also.

3. VDP routine

During your VDP Interupt routing you must call two OS7 sound routines (PLAY_SONGS and SOUND_MGR) in a specific order to play your sounds/music and keep them playing.

Example VDP routine:

VDPINT:
;Save all registers
PUSH AF
PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
EX AF,AF'
PUSH AF
EXX
PUSH BC
PUSH DE
PUSH HL
;sound routines
CALL PLAY_SONGS
CALL SOUND_MGR
;Now restore everything
POP HL
POP DE
POP BC
EXX
POP AF
EX AF,AF'
POP IY
POP IX
POP HL
POP DE
POP BC
;
IN A,(0BFh) ;Side effect allows another NMI to happen
;
POP AF
;
RETN

4. Playing (starting) a sound

In order to start a sound playing you would call the PLAY_IT OS7 routine. If you wanted to play a 4 channel song you would make 4 calls to PLAY_IT with each call starting one of the channels.

;example to play a simple sound
LD B,1 ;start sound 1
CALL PLAY_SOUND_IN_B ;play sound in B register

;example to play a 4 channel song
LD B,2 ;start music channel 1
CALL PLAY_SOUND_IN_B ;play sound in B register
LD B,3 ;start music channel 2
CALL PLAY_SOUND_IN_B ;play sound in B register
LD B,4 ;start music channel 3
CALL PLAY_SOUND_IN_B ;play sound in B register
LD B,5 ;start music channel 4
CALL PLAY_SOUND_IN_B ;play sound in B register

;--------------------------------------------------------
;Input: B song to play
PLAY_SOUND_IN_B:
PUSH AF
PUSH BC
PUSH DE
PUSH HL
PUSH IX
PUSH IY
CALL PLAY_IT
POP IY
POP IX
POP HL
POP DE
POP BC
POP AF
RET

lotonah
Posts: 12
Joined: Sat Jul 20, 2019 5:26 pm

Re: Coding on the CV

Post by lotonah » Sat Dec 07, 2019 6:21 am

I gotta say, that's a pretty epic reply :)

Someday (I keep telling myself that so I don't commit harikari) I'm gonna sit down and get back to programming... this will help a lot!

Post Reply