Changes

Jump to: navigation, search

PlayCity

4,412 bytes added, 17:12, 17 March 2021
Restore the official CTC detection routine.
[[File:PlayCity.jpg|thumb|320px|]]
==Introduction==
Write the introduction text...  Its most important The PlayCity is a CPC expansion released on April 2014 with these 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).
Used by the standard BIOS functions
'''MC_BOOT_PROGRAM''' and '''MC_START_PROGRAM''' (vectors $BD13 and $BD16), in particular a peripheral that generates interrupts. Also used by [[FutureOS]].
The PlayCity board use this feature to be sure that the CTC and YMZs circuits are properly reseted reset before using them.
== Light Pen/Gun connector ==
For making it 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|Amstrad Magnum Phaser]] games, the most accuracy light gun system for CPC.
==Counter/Timer Circuit==
===InformationsInformation===
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]]).
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 its 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/TO0TO2) is linked to the trigger for the channel 3 (TRG3). They can be used as 2x 8-bit or 1x 16-bitcounter/timer. They generate normal interrupts and allow to use using 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
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 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-$0F90F) in the YMZ.The registers are write only. 
===Coding Examples===
====YMZ Initialization====
{| class="wikitable"
|-
! 4/N !! CTC Val !! CTC OUT Out (MHz) !! YMZ Div (MHz) !! Computer
|-
| 1 || $$01 || 2,00 || 1,00 || = CPC
|-
| $2 || || 23,67 00 || 1,33 50 ||
|-
| $3 ||$02 || 3,00 33 || 1,50 67 ||
|-
| $4 || || 3,20 50 || 1,60 75 ||= ZX
|-
| $5 || $03 || 3,33 60 || 1,67 80 ||~ MSX
|-
| $6 || || 3,43 67 || 1,71 83 ||
|-
| $7 || $04 || 3,50 71 || 1,75 86 || ZX
|-
| $8 || || 3,56 75 || 1,78 88 || MSX
|-
 | $9 || $05 || 3,60 78 || 1,80 89 ||
|-
 | 10 || $A || 3,64 80 || 1,82 90 ||
|-
| 11 || $06 B || 3,67 82 || 1,83 91 ||
|-
 | 12 || $C || 3,69 83 || 1,85 92 ||
|-
| 13 || $07 D || 3,71 85 || 1,86 92 ||
|-
 | 14 || $E || 3,73 86 || 1,87 93 ||
|-
| 15 || $08 F || 3,75 87 || 1,88 93 ||
|-
| 16 || $0 || 3,76 98 || 1,88 99 ||~ ST
|-
| ... || ... || ... || ... |||-| 256 || $00 || 3,98 || 1,99 |||-| UNSET || || 4,00 || 2,00 || = ST
|}
'''Informations'''==PlayCity coding tips==Interesting tips or "magic tricks" using the board should be documented here. If the code is long, you must put in other wiki page and link it here. ===PlayCity detection===We are going to use the NMI interrupt generator to check if our program is running in a CPC with a PlayCity board.<pre>; ---------------------------------------------------------------------------; PlayCity check; (c) 2013 SyX; --------------------------------------------------------------------------- ; ConstantesCTC_TIM1 EQU $F881 ; Channel 1 (I: Cursor CRTC | O: NMI) CTC_START_TIMER256 EQU %00110111CTC_STOP_CHANNEL EQU %00000011 ; ---------------------------------------------------------------------------; NOTE: The rows without a lower ROM must be disabled before to run this code.check_playcity ; Disable interrupts DI ; Install NMI handler LD A,$C3 ; JP $xxxx LD HL,nmi_interrupt LD ($0066),A LD ($0067),HL  ; Initialize playcity variable to 0 XOR A LD (playcity),A  ; Wait VBlank LD B,$F5.wait_vbl IN A,(C) RRA JR NC,.wait_vbl ; Initialize CTC Val were not testedtimer 1 (NMI generator) LD HL,32 ; 32 scanlines LD BC,CTC_TIM1 LD A,CTC_START_TIMER256 OUT (C),A ; Enable Timer OUT (C),L ; Set new time constant  ; Extra delay LD IX,33 * 4 - 1 ; Wait 33 scanlines CALL wait_scanlines_ix LD A,(playcity) OR A JR NZ,. It may be needed playcity_detected ; No PlayCity detected . . . .playcity_detected . . . ; ---------------------------------------------------------------------------nmi_interrupt PUSH BC PUSH AF  ; Change playcity variable LD A,$FF LD (playcity),A  ; Disable CTC timer 1 (NMI generator) LD BC,CTC_TIM1 LD A,CTC_STOP_CHANNEL OUT (C),A ; Disable Timer   POP AF POP BC EI RETN ; ---------------------------------------------------------------------------; Wait scanlines; INPUT:; IX: Scanlines to configure wait * 4 - 1; ---------------------------------------------------------------------------wait_scanlines_ix DEFS 5,0 ; (5)  .loop_wait_scanlines_ix DEFS 6 ; (6) DEC IX ; (3) LD A,IXH ; (2) OR IXL ; (2) JR NZ,.loop_wait_scanlines_ix ; (2/3) ; Total loop --> 16 * (IX - 1) + 15 RET ; (3) ; Total Routine --> 64 * SCANLINES; ---------------------------------------------------------------------------playcity DEFS 1</pre> ===PlayCity detection (alternative)===Faster and shorter, but untested or not working on all CPC.<pre>;=========================; PlayCity check; If it's present, A=1; Otherwise, A=0;-------------------------;;=========================macro PlaycityDetection ; Code for NMI management ld a,#3c ; inc a ld (#66),a ld hl,#45ed ; (inverted) opcodes for retn ld (#67),hl  ; If a Playcity is present, the code generates a NMI then stops the counter. ld bc,#F881 ; 3 NOPs CTC channel 1 ld hl,%00010111*256 + 2 ; 3 NOPs A NMI every 8 NOPs out (c),h ; 4 NOPs out (c),l ; 4 NOPs  ld a,0 ; 2 NOPs A is set to 0. If a CTC is present, it will be INCed by the INTerruption code inc hl ; 2 NOPs L=3 => Stop CTC channel nop ; 1 NOPs out (c),l ; 4 NOPs <- If a Playcity is plugged, a NMI should be raised during this opcodemend</pre> ==Downloads==In [[File:playcity_examples.zip]], you will find more examples with "falling edge" instead full sources ofusing 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)."rising edges"Another example, in [[File:test_sfx.zip]] you will find a 3 channels SFX player, you can choose the sound chip to be used by the player. == Software Supporting PlayCity == *[[Software_Supporting_PlayCity|List of software supporting the board.]] [[Category:FutureOS]][[Category:Music and sound]][[Category:Peripherals]] Website: [http://centpourcent.net centpourcent.net]
213
edits