Difference between revisions of "PlayCity"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
Line 185: Line 185:
 
"rising edges".
 
"rising edges".
 
==Downloads==
 
==Downloads==
You will find [[File:playcity_examples.zip|here]] more examples with full sources of using the CTC, a customized arkos player that let you play songs using an external YMZ and the ReSeT party demo disk that includes a CPC version of the PT3 Turbo Sound player (6 channels song format).
+
In [[File:playcity_examples.zip]], you will find more examples with full sources of using the CTC, a customized arkos player that let you play songs using an external YMZ and the ReSeT party demo disk that includes a CPC version of the PT3 Turbo Sound player (6 channels song format).

Revision as of 13:04, 9 July 2014

Introduction

Write the introduction text...


Its most important features are:

  • 6 audio channels sound with programmable frequency (stereo line out and speaker mono mix in).
  • 4 counter/timer channels for programmable interrupt (including NMI).
  • IM2 vectorized interrupt support.
  • Raster lines interrupt support.
  • CRTC hardware CURSOR interrupt support.
  • The LIGHT PEN/GUN connector.

Hardware Installation

  • Power OFF your Amstrad / Schneider CPC.
  • Attach the PlayCity board to one free MotherX4 slot.
  • Turn ON your computer, and enjoy!

Peripheral Soft Reset

All expansion peripherals should be reset when an output is performed to I/O port $F8FF.

Used by the standard BIOS functions MC_BOOT_PROGRAM and MC_START_PROGRAM (vectors $BD13 and $BD16), in particular a peripheral that generates interrupts.

The PlayCity board use this feature to be sure that the CTC and YMZs circuits are properly reseted before using them.

Light Pen/Gun connector

For making easier to adapt Light Pens/Guns from other systems or new ones, we added a 4 pins connector to the board. The connections are labeled in the board as VCC (+5V), TR (Trigger or D7), LS (Light Sensor) and GND.

Making the system compatible with Amstrad Magnum Phaser games, the most accuracy light gun system for CPC.

Counter/Timer Circuit

Informations

The Z84C30 has four independently programmable counter/timer channels interfaced directly with the Z80 CPU. You can get full information in the CTC datasheet (File:Z80ctc.pdf).

The first thing to consider is how those channels are linked to the PlayCity board.

Channel 0 ($F880)

The channel 0 is exclusively used to generate the frequency of the two embedded soundchips (YMZ294). The input for the trigger (TRG0) is the 4 MHz system clock of the CPC. The output signal (ZC/TO0) is sent to the clock pins of the soundchips.

Channel 1 ($F881)

The channel 1 is typically used to generate raster interrupts. The input (TRG1) is linked to the CRTC CURSOR signal. The output (ZC/TO1) is connected to the NMI pin of the Z80.

Used as a counter, it's synchronized with the CRTC CURSOR signal, generating a smooth high priority rasters interrupt. Used as a timer (prescaler set to 256), it's 15.625 kHz signal is scanline-synchronized. That means the time constant is the number of scanlines to wait before to send an NMI.

Channel 2/3 ($F882/$F883)

The channels 2 and 3 are dedicated to general purpose usages. Yes, it's for you! The input for the trigger (TRG2) is the 4 MHz system clock. The output (ZC/TO0) is linked to the trigger for the channel 3 (TRG3). They can be used as 2x 8-bit or 1x 16-bit counter/timer. They generate normal interrupts and allow to use the Z80 vector interrupt (mode 2) too.

Coding examples

Each channel is programmed with two bytes; a third is necessary when interrupts are enabled. Once started, the CTC countdown automaticaly reloads its time constant and resume counting. Interrupt processing is simplified because only one vector need to be specified; the CTC internally generates an unique vector for each channel.

Before programming the CTC channels, you need to set the lower byte for the vectorized interrupts.

Vector interrupts

; Set Vector lower byte to 0
LD BC,$F880
OUT (C),0

Channel 0 example

; Set both YMZ294 clocks to sound like the CPC AY-3-8912
LD BC,$F880
LD HL,$7F01
OUT (C),H ; $7F = Clock generator
OUT (C),L  ; $01 = CPC AY

Channel 2 example

; Start CTC channel 2 in timer mode (prescalar 256 and set new time constant)
LD H,%10110111 ; Timer mode and preescalar 256
LD L,1 ; Time constant
LD BC,$F882
OUT (C),H  ; Enable Timer
OUT (C),L ; Set new time constant
; Stop CTC channel 2
LD BC,$F882
LD A,%00000011
OUT (C),A ; Disable Timer 2

Channel 2/3 example

; Start CTC channel 2 and 3 in 16-bit counter mode
LD BC,$F882
LD HL,32768 ; Timer constant
LD A,%11110111 ; Counter mode
OUT (C),A ; Enable Timer 2
OUT (C),L ; Set new time constant (lower byte)
INC BC
OUT (C),A ; Enable Timer 3
OUT (C),H ; Set new time constant (high byte)
; Stop CTC channel 2 and 3 (16 bit mode)
LD BC,$F882
LD A,%00000011
OUT (C),A ; Disable Timer 2
INC BC
OUT (C),A ; Disable Timer 3

Don't forget to use RETN for NMI handlers as well as RETI for normal interrupt handlers. In other case, the Z80 CPU will not aknowledge the next interrupt properly.

Audio Channels

Informations

The PlayCity board is populated with two AY compatible soundchips, adding 6 stereo channels. The YMZ294 eliminate the I/O port and improve the CPU interface through /CS, /WR control signals and a 8-bit data bus. Each sound chip can be directly programmed using two dedicated I/O ports for registers and data. No initialization code is required.

By default, the YMZs are clocked at 4 MHz but run internaly at 2 MHz. So, they will sound like an Atari ST, while you don't change the frequency by reprograming the CTC Channel 0.

YMZ294 Registers

They are exactly the same than the PSG, only remember there is not PSG I/O registers ($0E-$0F9) in the YMZ.

Coding Examples

YMZ Initialization

YMZ_SELECT, select a YMZ register. Use the port $F984 for the right channels and port $F988 for the left channels.

YMZ_WRITE, write a byte in the selected register. Use the port $F884 for the right channels and port $F888 for the left channels.

; Initialization of the YMZ registers
LD A,$D
.loop_init_ymz
LD BC,YMZ_SELECT
OUT (C),A ; Register
LD BC,YMZ_WRITE
CP 7
JR NZ,.send_zero
LD A,$3F ; Noise and Tone disabled
OUT (C),A ; Write in YMZ R7
LD A,6
JR .loop_init_ymz
.send_zero
OUT (C),0 ; Write 0 in the selected YMZ register
DEC A
JP P,.loop_init_ymz

CTC/YMZ Useful Values

4/N CTC Val CTC OUT (MHz) YMZ Div (MHz) Computer
1 $01 2,00 1,00 CPC
2 2,67 1,33
3 $02 3,00 1,50
4 3,20 1,60
5 $03 3,33 1,67
6 3,43 1,71
7 $04 3,50 1,75 ZX
8 3,56 1,78 MSX
9 $05 3,60 1,80
10 3,64 1,82
11 $06 3,67 1,83
12 3,69 1,85
13 $07 3,71 1,86
14 3,73 1,87
15 $08 3,75 1,88
16 3,76 1,88
... ... ... ...
256 $00 3,98 1,99
UNSET 4,00 2,00 ST

Informations: The rows without a CTC Val aree not tested. It may be needed to configure the CTC channel 0 with "falling edge" instead of "rising edges".

Downloads

In File:Playcity examples.zip, you will find more examples with full sources of using the CTC, a customized arkos player that let you play songs using an external YMZ and the ReSeT party demo disk that includes a CPC version of the PT3 Turbo Sound player (6 channels song format).