; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
        SUBT    Exported Sound constants

OldOpt  SETA    {OPT}
        OPT     OptNoList+OptNoP1List

; ***********************************
; ***    C h a n g e   L i s t    ***
; ***********************************

; Date       Name  Description
; ----       ----  -----------
; 21-Jun-1988  SKS   Added Service sub-rc's, corrected SoundCMOS definition
;                    to fit reality
; 17-May-1994  AMcC  Changed to using the preferred SWI base symbols
; 29-Sep-1994  AMcC  Added new 16-bit Sound0 SWIs (from DOCN16)
; 12-Oct-1994  AMcC  Corrected some Sound2 SWI names
; 06-Mar-2001  ADH   Added Service_Sound reason codes 6 and 7
;

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Software base pointers

SoundLevel0Base         * SoundWorkSpace
SoundLevel0Reserved     * 16*4
SoundLevel1Base         * SoundLevel0Base + SoundLevel0Reserved

SoundPhysChannels       * 8
MaxNVoices              * 32
SoundSystemNIL          * &00000003


; SCCB Sound Channel Control Block
; 8 words (for LDMIA R9,{R0-R7}) is reasonable
; size constrained to exactly 256 bytes
                        ^ 0
SoundChannelAmpGateB    # 1 ; gate + 7-bit log amp.
SoundChannelVoiceIndexB # 1 ; index to voice table
SoundChannelInstanceB   # 1 ; Voice instance no.
SoundChannelFlagsB      # 1 ; control/status bit flags
SoundChannelPitch       # 4 ; phase acc
SoundChannelTimbre      # 4 ; phase acc
SoundChannelDuration    # 4 ; no. uS? (dec counter)
SoundChannelUserParam1  # 4 ;
SoundChannelUserParam2  # 4 ;
SoundChannelUserParam3  # 4 ;
SoundChannelUserParam4  # 4 ;
SoundChannelExtension   # 0 ; START HERE -> 256 BYTES
SoundChannelCBSize * 256
SoundChannelCBLSL * 8 ; SHIFT value to index SCCBs

; Level 1 data structure
; Level1 Sound DMA Control Block
; This block is skipped for the C header, the constants on the RHS of the # confuse Hdr2H.
;NoHdr2H{
                        ^ 0 ; SoundLevel1Base
SoundLevel1FillPtr      # 4 ; code^
SoundLevel1FixupPtr     # 4 ; code^
SoundLevel1LogTable     # 4
SoundLevel1AmpTable     # 4
SoundLevel1NChannels    # 1
SoundLevel1MaxAmp       # 1
SoundLevel1NVoices      # 1
SoundLevel1reservedB    # 1
SoundLevel1MasterPitch  # 4
SoundLevel1Queue        # 4
SoundLevel1SPARE        # 4 * 8
SoundLevel1VoiceTable   # 4 * (1 + MaxNVoices)
SoundLevel1ChannelTable    # SoundPhysChannels * SoundChannelCBSize
SoundLevel1ChannelTableEnd # 0
;NoHdr2H}


; Level 2 (VOICE) data structure
; SVCB Sound Voice Control Block
                        ^ 0
SoundVoiceFill          # 4 ; fill continuation entry
SoundVoiceUpdate        # 4 ; fill (with new params) coroutine entry
SoundVoiceGateOn        # 4 ; initiallise and fill
SoundVoiceGateOff       # 4 ; kill/release coroutine entry
SoundVoiceInst          # 4 ; instantiate voice
SoundVoiceFree          # 4 ; instance control
SoundVoiceInstall       # 4 ; code install
SoundVoiceTitle         # 4 ; name string
SoundVoiceDSize         # 4 ; instance data segment size
SoundVoiceIndex         # 4 ; table install segment size
SoundVoiceCBSize        # 0


; Channel Flags Byte: (31:24 of control word)
;
;   7                           0
; +---+---+---+---+---+---+---+---+
; | Q | K | I | F | A | V | F2| F1|
; +---+---+---+---+---+---+---+---+
; Z - Quiet (inactive)
; K - Kill Pending
; I - Initialise Pending
; F - Fill Pending
; A - Active Flag
; V - oVerrun Flag
; F2,F1 - 2-bit Flush Pending counter

SoundChannelGateOff      * 2_10000000 ; carefully priority-encoded
SoundChannelGateOn       * 2_01000000
SoundChannelUpdate       * 2_00100000
SoundChannelReserved     * 2_00010000
SoundChannelActive       * 2_00001000
SoundChannelOverrun      * 2_00000100
SoundChannelFlush2       * 2_00000010
SoundChannelFlush1       * 2_00000001
; composites
SoundChannelFlushPending * 2_00000011
SoundChannelForceFlush   * 2_00000010


; SoundCMOS bit allocation

;   7   6   5   4   3   2   1   0
; +---+---+---+---+---+---+---+---+
; | S |     L     |       V       |
; +---+---+---+---+---+---+---+---+

; S = 0/1 -> speaker off/on
; L = 3-bit 'loudness' field, 0..7 -> &01..&7F
; V = 4-bit default channel 0 voice, 0..15 -> 1..16


SWIClass SETS Sound0SWI_Name

        ^       Sound0SWI_Base

        AddSWI  Configure
        AddSWI  Enable
        AddSWI  Stereo
        AddSWI  Speaker
        AddSWI  Mode
        AddSWI  LinearHandler
        AddSWI  SampleRate
        AddSWI  ReadSysInfo
        AddSWI  SelectDefaultController
        AddSWI  EnumerateControllers
        AddSWI  ControllerInfo

        ^       Sound1SWI_Base

        AddSWI  Volume
        AddSWI  SoundLog
        AddSWI  LogScale
        AddSWI  InstallVoice
        AddSWI  RemoveVoice
        AddSWI  AttachVoice
        AddSWI  ControlPacked ; was 'Sound' but not in module!
        AddSWI  Tuning
        AddSWI  Pitch
        AddSWI  Control
        AddSWI  AttachNamedVoice
        AddSWI  ReadControlBlock
        AddSWI  WriteControlBlock

        ^       Sound2SWI_Base

        AddSWI  QInit
        AddSWI  QSchedule
        AddSWI  QRemove
        AddSWI  QFree
        AddSWI  QSDispatch
        AddSWI  QTempo
        AddSWI  QBeat
        AddSWI  QInterface


                                ^       0 ; Sound system service sub-rc's
Service_SoundLevel0Alive        #       1
Service_SoundLevel0Dying        #       1
Service_SoundLevel1Alive        #       1
Service_SoundLevel1Dying        #       1
Service_SoundLevel2Alive        #       1
Service_SoundLevel2Dying        #       1
Service_SharedSoundAlive        #       1
Service_SharedSoundDying        #       1
Service_SoundConfigChanging     #       1
Service_SoundEnabled            #       1
Service_SoundDisabled           #       1
Service_SoundAutoTune           #       1

; Sound_ReadSysInfo reason codes
; Start from 1 due to braindead Sound0 SWI dispatch not erroring on unknown SWI!
                                ^       1
Sound_RSI_Features              #       1
Sound_RSI_DefaultController     #       1

; Sound_RSI_Features flags
Sound_RSI_Feature_Service8910         * 1 ; Service calls 8/9/10 generated (SoundConfigChanging, SoundEnabled, SoundDisabled)
Sound_RSI_Feature_ControllerSelection * 2 ; SelectDefaultController, EnumerateControllers, ControllerInfo SWIs supported

; Sound_ControllerInfo reason codes
                                ^       0
Sound_CtlrInfo_DisplayName      #       1
Sound_CtlrInfo_MixerDevice      #       1
Sound_CtlrInfo_SampleRates      #       1


        OPT     OldOpt
        END
