#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA652_A31E_A35M_AU1E_AU2F
extern void F1245_();
extern void F1250_();
extern void F1254_();

typedef struct {
        struct IOAudio LeftChannel;
        struct IOAudio RightChannel;
        struct MsgPort ReplyPort1;
        struct MsgPort ReplyPort2;
} AUDIOCH;

UBYTE G0730_uc_AudioChannelsAllocation = 0x0F;
struct Device* G3231_ps_AudioDevice;
struct IOAudio* G3227_ps_Sound1Control = NULL;
struct IOAudio* G3225_ps_Sound1LeftChannel = NULL;
struct IOAudio* G3226_ps_Sound1RightChannel = NULL;
struct IOAudio* G3230_ps_Sound2Control = NULL;
struct IOAudio* G3228_ps_Sound2LeftChannel = NULL;
struct IOAudio* G3229_ps_Sound2RightChannel = NULL;
struct MsgPort* G3234_ps_IOAudio3ReplyPort = NULL;
struct MsgPort* G3232_ps_IOAudio1ReplyPort = NULL;
struct MsgPort* G3233_ps_IOAudio2ReplyPort = NULL;
struct MsgPort* G3237_ps_IOAudio6ReplyPort = NULL;
struct MsgPort* G3235_ps_IOAudio4ReplyPort = NULL;
struct MsgPort* G3236_ps_IOAudio5ReplyPort = NULL;
int16_t G3294_;
int16_t G3295_;
unsigned int16_t G3291_ui_AudioChCount;
AUDIOCH* G3292_ps_AudioCh;
BOOLEAN G3293_B_;


void F0908_InitSound(
)
{
        G3225_ps_Sound1LeftChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3226_ps_Sound1RightChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3227_ps_Sound1Control = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3228_ps_Sound2LeftChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3229_ps_Sound2RightChannel = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        G3230_ps_Sound2Control = AllocMem((long)sizeof(struct IOAudio), MEMF_CHIP | MEMF_CLEAR);
        if ((G3225_ps_Sound1LeftChannel == NULL) || (G3226_ps_Sound1RightChannel == NULL) || (G3227_ps_Sound1Control == NULL)) {
                F9073_DisplayError(0x80F1000F);
        }
        if ((G3228_ps_Sound2LeftChannel == NULL) || (G3229_ps_Sound2RightChannel == NULL) || (G3230_ps_Sound2Control == NULL)) {
                F9073_DisplayError(0x80F1000F);
        }
        G3232_ps_IOAudio1ReplyPort = CreatePort(NULL, 0L);
        G3233_ps_IOAudio2ReplyPort = CreatePort(NULL, 0L);
        G3234_ps_IOAudio3ReplyPort = CreatePort(NULL, 0L);
        G3235_ps_IOAudio4ReplyPort = CreatePort(NULL, 0L);
        G3236_ps_IOAudio5ReplyPort = CreatePort(NULL, 0L);
        G3237_ps_IOAudio6ReplyPort = CreatePort(NULL, 0L);
        if ((G3232_ps_IOAudio1ReplyPort == NULL) || (G3233_ps_IOAudio2ReplyPort == NULL) || (G3234_ps_IOAudio3ReplyPort == NULL)) {
                F9073_DisplayError(0x80F10011);
        }
        if ((G3235_ps_IOAudio4ReplyPort == NULL) || (G3236_ps_IOAudio5ReplyPort == NULL) || (G3237_ps_IOAudio6ReplyPort == NULL)) {
                F9073_DisplayError(0x80F10011);
        }
        if (OpenDevice("audio.device", 0L, G3227_ps_Sound1Control, 0L) != 0) {
                F9073_DisplayError(0x80F10010);
        }
        G3231_ps_AudioDevice = G3227_ps_Sound1Control->ioa_Request.io_Device;


        G3227_ps_Sound1Control->ioa_Request.io_Message.mn_ReplyPort = G3234_ps_IOAudio3ReplyPort;
        G3227_ps_Sound1Control->ioa_Request.io_Message.mn_Node.ln_Pri = ADALLOC_MAXPREC;
        G3227_ps_Sound1Control->ioa_Request.io_Command = ADCMD_ALLOCATE;
        G3227_ps_Sound1Control->ioa_Data = &G0730_uc_AudioChannelsAllocation; /* Value 0x0F = allocate all 4 channels (one bit per channel) */
        G3227_ps_Sound1Control->ioa_Length = sizeof(G0730_uc_AudioChannelsAllocation);
        if (DoIO(G3227_ps_Sound1Control) != 0) {
                F9073_DisplayError(0x80F10012);
        }
        *G3225_ps_Sound1LeftChannel = *G3227_ps_Sound1Control;
        G3227_ps_Sound1Control->ioa_Request.io_Command = ADCMD_FINISH;
        G3227_ps_Sound1Control->ioa_Request.io_Flags = IOF_QUICK;
        G3227_ps_Sound1Control->ioa_Request.io_Unit = (struct Unit*)(4 | 8); /* Channel 2 & 3 */
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Command = CMD_WRITE;
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Flags = IOF_QUICK | ADIOF_PERVOL;
        G3225_ps_Sound1LeftChannel->ioa_Volume = 64;
        G3225_ps_Sound1LeftChannel->ioa_Cycles = 1;
        G3225_ps_Sound1LeftChannel->ioa_Request.io_Unit = (struct Unit*)8; /* Channel 3 produce sound on left side */
        *G3226_ps_Sound1RightChannel = *G3225_ps_Sound1LeftChannel;
        G3226_ps_Sound1RightChannel->ioa_Request.io_Message.mn_ReplyPort = G3233_ps_IOAudio2ReplyPort;
        G3226_ps_Sound1RightChannel->ioa_Request.io_Unit = (struct Unit*)4; /* Channel 2 produce sound on right side */
        *G3230_ps_Sound2Control = *G3227_ps_Sound1Control;
        G3230_ps_Sound2Control->ioa_Request.io_Unit = (struct Unit*)(1 | 2); /* Channel 0 & 1 */
        *G3228_ps_Sound2LeftChannel = *G3225_ps_Sound1LeftChannel;
        G3228_ps_Sound2LeftChannel->ioa_Request.io_Message.mn_ReplyPort = G3235_ps_IOAudio4ReplyPort;
        G3228_ps_Sound2LeftChannel->ioa_Request.io_Unit = (struct Unit*)1; /* Channel 0 produce sound on left side */
        *G3229_ps_Sound2RightChannel = *G3226_ps_Sound1RightChannel;
        G3229_ps_Sound2RightChannel->ioa_Request.io_Message.mn_ReplyPort = G3236_ps_IOAudio5ReplyPort;
        G3229_ps_Sound2RightChannel->ioa_Request.io_Unit = (struct Unit*)2; /* Channel 1 produce sound on right side */
}

void F1230_CleanupSound(
)
{
        if (G3231_ps_AudioDevice) {
                F1254_();
                F1245_();
                F1250_();
                CloseDevice(G3227_ps_Sound1Control);
                G3231_ps_AudioDevice = NULL;
        }
        if (G3225_ps_Sound1LeftChannel) {
                FreeMem(G3225_ps_Sound1LeftChannel, (long)sizeof(struct IOAudio));
        }
        G3225_ps_Sound1LeftChannel = NULL;
        if (G3226_ps_Sound1RightChannel) {
                FreeMem(G3226_ps_Sound1RightChannel, (long)sizeof(struct IOAudio));
        }
        G3226_ps_Sound1RightChannel = NULL;
        if (G3227_ps_Sound1Control) {
                FreeMem(G3227_ps_Sound1Control, (long)sizeof(struct IOAudio));
        }
        G3227_ps_Sound1Control = NULL;
        if (G3228_ps_Sound2LeftChannel) {
                FreeMem(G3228_ps_Sound2LeftChannel, (long)sizeof(struct IOAudio));
        }
        G3228_ps_Sound2LeftChannel = NULL;
        if (G3229_ps_Sound2RightChannel) {
                FreeMem(G3229_ps_Sound2RightChannel, (long)sizeof(struct IOAudio));
        }
        G3229_ps_Sound2RightChannel = NULL;
        if (G3230_ps_Sound2Control) {
                FreeMem(G3230_ps_Sound2Control, (long)sizeof(struct IOAudio));
        }
        G3230_ps_Sound2Control = NULL;
        if (G3232_ps_IOAudio1ReplyPort) {
                DeletePort(G3232_ps_IOAudio1ReplyPort);
        }
        G3232_ps_IOAudio1ReplyPort = NULL;
        if (G3233_ps_IOAudio2ReplyPort) {
                DeletePort(G3233_ps_IOAudio2ReplyPort);
        }
        G3233_ps_IOAudio2ReplyPort = NULL;
        if (G3234_ps_IOAudio3ReplyPort) {
                DeletePort(G3234_ps_IOAudio3ReplyPort);
        }
        G3234_ps_IOAudio3ReplyPort = NULL;
        if (G3235_ps_IOAudio4ReplyPort) {
                DeletePort(G3235_ps_IOAudio4ReplyPort);
        }
        G3235_ps_IOAudio4ReplyPort = NULL;
        if (G3236_ps_IOAudio5ReplyPort) {
                DeletePort(G3236_ps_IOAudio5ReplyPort);
        }
        G3236_ps_IOAudio5ReplyPort = NULL;
        if (G3237_ps_IOAudio6ReplyPort) {
                DeletePort(G3237_ps_IOAudio6ReplyPort);
        }
        G3237_ps_IOAudio6ReplyPort = NULL;
}

void F1231_(P4364_, P4365_, P4366_, P4367_, P4368_, P4369_)
register struct IOAudio* P4364_;
UBYTE* P4365_;
ULONG P4366_;
UWORD P4367_;
UWORD P4368_;
UWORD P4369_;
{
        P4364_->ioa_Data = P4365_;
        P4364_->ioa_Length = P4366_;
        P4364_->ioa_Period = P4367_;
        P4364_->ioa_Cycles = P4368_;
        P4364_->ioa_Volume = P4369_;
}

BOOLEAN F1232_(
)
{
        if (!CheckIO(G3225_ps_Sound1LeftChannel) || !CheckIO(G3226_ps_Sound1RightChannel)) {
                return C0_FALSE;
        }
        return C1_TRUE;
}

BOOLEAN F1233_(
)
{
        if (!CheckIO(G3228_ps_Sound2LeftChannel) || !CheckIO(G3229_ps_Sound2RightChannel)) {
                return C0_FALSE;
        }
        return C1_TRUE;
}

void F1234_(P4358_, P4359_, P4360_)
struct IOAudio* P4358_;
struct IOAudio* P4359_;
struct IOAudio* P4360_;
{
        if (!CheckIO(P4359_) || !CheckIO(P4360_)) {
                P4358_->ioa_Request.io_Command = ADCMD_FINISH;
                M009_CLEAR(P4358_->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                M009_CLEAR(P4359_->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                M009_CLEAR(P4360_->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                BeginIO(P4358_);
                WaitIO(P4359_);
                WaitIO(P4360_);
                P4358_->ioa_Request.io_Command = CMD_STOP;
                DoIO(P4358_);
        }
}

void F1235_(P4361_, P4362_, P4363_)
struct IOAudio* P4361_;
struct IOAudio* P4362_;
struct IOAudio* P4363_;
{
        if (!CheckIO(P4362_) || !CheckIO(P4363_)) {
                P4361_->ioa_Request.io_Command = ADCMD_FINISH;
                M008_SET(P4361_->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                BeginIO(P4361_);
                WaitIO(P4362_);
                WaitIO(P4363_);
                M009_CLEAR(P4361_->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                P4361_->ioa_Request.io_Command = CMD_STOP;
                DoIO(P4361_);
        }
}

BOOLEAN F1236_(
)
{
        if (F1232_()) {
                return C0_FALSE;
        }
        if (F1233_()) {
                return C1_TRUE;
        }
        if (G3294_ >= G3295_) {
                return C1_TRUE;
        }
        return C0_FALSE;
}

void F1237_(
)
{
        F1234_(G3227_ps_Sound1Control, G3225_ps_Sound1LeftChannel, G3226_ps_Sound1RightChannel);
}

void F1238_(
)
{
        F1235_(G3227_ps_Sound1Control, G3225_ps_Sound1LeftChannel, G3226_ps_Sound1RightChannel);
}

BOOLEAN F1239_(
)
{
        return F1232_();
}

void F1240_(P4325_, P4326_, P4327_, P4328_, P4329_, P4330_, P4331_, P4332_)
long P4325_;
long P4326_;
int16_t P4327_;
int16_t P4328_;
int16_t P4329_;
int16_t P4330_;
int16_t P4331_;
int16_t P4332_;
{
        if (F1232_() == 0) {
                if (G3294_ > P4331_) {
                        if (P4332_ == 0) {
                                return;
                        }
                        F1238_();
                } else {
                        F1237_();
                }
        }
        G3294_ = P4331_;
        F1231_(G3225_ps_Sound1LeftChannel, P4325_, P4326_, P4327_, P4328_, P4329_);
        F1231_(G3226_ps_Sound1RightChannel, P4325_, P4326_, P4327_, P4328_, P4330_);
        BeginIO(G3225_ps_Sound1LeftChannel);
        BeginIO(G3226_ps_Sound1RightChannel);
        G3227_ps_Sound1Control->ioa_Request.io_Command = CMD_START;
        DoIO(G3227_ps_Sound1Control);
}

void F1241_(
)
{
        F1234_(G3230_ps_Sound2Control, G3228_ps_Sound2LeftChannel, G3229_ps_Sound2RightChannel);
}

void F1242_(
)
{
        F1235_(G3230_ps_Sound2Control, G3228_ps_Sound2LeftChannel, G3229_ps_Sound2RightChannel);
}

BOOLEAN F1243_(
)
{
        return F1233_();
}

void F1244_(P4333_, P4334_, P4335_, P4336_, P4337_, P4338_, P4339_, P4340_)
long P4333_;
long P4334_;
int16_t P4335_;
int16_t P4336_;
int16_t P4337_;
int16_t P4338_;
int16_t P4339_;
int16_t P4340_;
{
        if (F1233_() == 0) {
                if (G3294_ > P4339_) {
                        if (P4340_ == 0) {
                                return;
                        }
                        F1242_();
                } else {
                        F1241_();
                }
        }
        G3295_ = P4339_;
        F1231_(G3228_ps_Sound2LeftChannel, P4333_, P4334_, P4335_, P4336_, P4337_);
        F1231_(G3229_ps_Sound2RightChannel, P4333_, P4334_, P4335_, P4336_, P4338_);
        BeginIO(G3228_ps_Sound2LeftChannel);
        BeginIO(G3229_ps_Sound2RightChannel);
        G3230_ps_Sound2Control->ioa_Request.io_Command = CMD_START;
        DoIO(G3230_ps_Sound2Control);
}

void F1245_(
)
{
        F1237_();
        F1241_();
}

void F1246_(
)
{
        F1238_();
        F1242_();
}

BOOLEAN F1247_(
)
{
        if (!F1239_() || !F1243_()) {
                return C0_FALSE;
        }
        return C1_TRUE;
}

int16_t F1248_(P4341_, P4342_, P4343_, P4344_, P4345_, P4346_, P4347_, P4348_)
long P4341_;
long P4342_;
int16_t P4343_;
int16_t P4344_;
int16_t P4345_;
int16_t P4346_;
int16_t P4347_;
int16_t P4348_;
{
        register int16_t L4746_;


        if (((L4746_ = F1236_()) == 0) || G3293_B_) {
                F1240_(P4341_, P4342_, P4343_, P4344_, P4345_, P4346_, P4347_, P4348_);
        } else {
                F1244_(P4341_, P4342_, P4343_, P4344_, P4345_, P4346_, P4347_, P4348_);
        }
        return L4746_;
}

BOOLEAN F1249_(P4357_)
register unsigned int16_t P4357_;
{
        register AUDIOCH* L4754_;
        register long L4755_;


        G3291_ui_AudioChCount = P4357_;
        L4755_ = P4357_ * sizeof(AUDIOCH);
        if ((L4754_ = G3292_ps_AudioCh = AllocMem(L4755_, MEMF_CLEAR)) == NULL) {
                return C0_FALSE;
        }
        while (P4357_--) {
                L4754_->LeftChannel = *G3228_ps_Sound2LeftChannel;
                L4754_->RightChannel = *G3229_ps_Sound2RightChannel;
                L4754_->ReplyPort1 = *G3235_ps_IOAudio4ReplyPort;
                L4754_->ReplyPort2 = *G3236_ps_IOAudio5ReplyPort;
                L4754_->LeftChannel.ioa_Request.io_Message.mn_ReplyPort = &L4754_->ReplyPort1;
                L4754_->LeftChannel.ioa_Request.io_Command = CMD_WRITE;
                L4754_->LeftChannel.ioa_Request.io_Flags = ADIOF_PERVOL | IOF_QUICK;
                L4754_->LeftChannel.ioa_Cycles = 1;
                L4754_->RightChannel.ioa_Request.io_Message.mn_ReplyPort = &L4754_->ReplyPort2;
                L4754_->RightChannel.ioa_Request.io_Command = CMD_WRITE;
                L4754_->RightChannel.ioa_Request.io_Flags = ADIOF_PERVOL | IOF_QUICK;
                L4754_->RightChannel.ioa_Cycles = 1;
                L4754_++;
        }
        return C1_TRUE;
}

void F1250_(
)
{
        if (G3292_ps_AudioCh && G3231_ps_AudioDevice) {
                F1254_();
                FreeMem(G3292_ps_AudioCh, (long)G3291_ui_AudioChCount * sizeof(AUDIOCH));
        }
        G3292_ps_AudioCh = NULL;
}

void F1251_(unsigned int16_t P4349_, unsigned int16_t* P4350_, long P4351_, int16_t P4352_, int16_t P4353_, int16_t P4354_)
{
        register AUDIOCH* L4747_;


        if (P4349_ <= G3291_ui_AudioChCount) {
                L4747_ = G3292_ps_AudioCh + P4349_;
                F1231_(&L4747_->LeftChannel, P4350_, P4351_, P4352_, 1, P4353_);
                F1231_(&L4747_->RightChannel, P4350_, P4351_, P4352_, 1, P4354_);
        }
}

void F1252_(
)
{
        register AUDIOCH* L4748_;
        register int16_t L4749_;


        L4748_ = G3292_ps_AudioCh;
        L4749_ = 0;
        while (G3291_ui_AudioChCount > L4749_) {
                BeginIO(&L4748_->LeftChannel);
                BeginIO(&L4748_->RightChannel);
                G3230_ps_Sound2Control->ioa_Request.io_Command = CMD_START;
                DoIO(G3230_ps_Sound2Control);
                L4749_++;
                L4748_++;
        }
        G3293_B_ = C1_TRUE;
}

void F1253_FadeOutSound(P4355_i_Volume, P4356_i_Period)
register int16_t P4355_i_Volume;
register int16_t P4356_i_Period;
{
        register AUDIOCH* L4750_;
        register int16_t L4751_;


        if (G3292_ps_AudioCh) {
                while (P4355_i_Volume--) {
                        if (P4355_i_Volume == 0) {
                                P4356_i_Period = 60;
                        }
                        L4750_ = G3292_ps_AudioCh;
                        L4751_ = 0;
                        while (G3291_ui_AudioChCount > L4751_) {
                                L4750_->LeftChannel.ioa_Volume = P4355_i_Volume;
                                L4750_->LeftChannel.ioa_Period = P4356_i_Period;
                                L4750_->RightChannel.ioa_Volume = P4355_i_Volume;
                                L4750_->RightChannel.ioa_Period = P4356_i_Period;
                                L4751_++;
                                L4750_++;
                        }
                        G3230_ps_Sound2Control->ioa_Volume = P4355_i_Volume;
                        G3230_ps_Sound2Control->ioa_Period = P4356_i_Period;
                        G3230_ps_Sound2Control->ioa_Request.io_Command = ADCMD_PERVOL;
                        M009_CLEAR(G3230_ps_Sound2Control->ioa_Request.io_Flags, ADIOF_SYNCCYCLE);
                        DoIO(G3230_ps_Sound2Control);
                        if (P4355_i_Volume != 0) {
                                Delay(3L);
                        }
                }
        }
}

void F1254_(
)
{
        register AUDIOCH* L4752_;
        register int16_t L4753_;


        L4752_ = G3292_ps_AudioCh;
        if (L4752_ != NULL) {
                for (L4753_ = 0; G3291_ui_AudioChCount > L4753_; L4753_++, L4752_++) {
                        F1234_(G3230_ps_Sound2Control, &L4752_->LeftChannel, &L4752_->RightChannel);
                }
        }
        G3293_B_ = C0_FALSE;
}
#endif
#ifdef MEDIA692_X31J
int16_t G3323_i_Unreferenced;


void F0060_SOUND_Play_CPSX(P0084_pui_SoundData, P0085_i_Period, P0086_i_SoundVolume)
unsigned int16_t* P0084_pui_SoundData;
int16_t P0085_i_Period;
int16_t P0086_i_SoundVolume;
{
        int16_t L4836_i_Unreferenced;


        if (*P0084_pui_SoundData) {
                asm {
                                moveq   #0,d1
                                moveq   #0x67,d0        /* ADPCMMOD */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                movea.l P0084_pui_SoundData(a6),a1    /* Address of sound data */
                                moveq   #0,d2
                                move.w  (a1)+,d2        /* First word: 4 bit sample count */
                                addq.w  #1,d2
                                lsr.w   #1,d2           /* Byte count = sample count / 2 */
                                move.w  P0085_i_Period(a6),d1
                                moveq   #0x60,d0        /* ADPCMOUT */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                }
        }
}
#endif
#ifdef MEDIA670_F31E_F31J
void F2264_INIT_PCM_SOUND(
void
)
{
        if (SND_init(G4104_SWORK)) {
                exit(0);
        }
        SND_elevol_set(1, 100, 100);
        SND_elevol_mute(49);
}

void F0060_SOUND_Play_CPSX(
unsigned char*   P0084_puc_SoundData SEPARATOR
unsigned int16_t P0085_i_Period      SEPARATOR /* Number of sound samples for F31E and F31J */
int16_t          P0086_i_SoundVolume FINAL_SEPARATOR
{
        long L6552_i_Frequency;
        int L6553_;/* Channel number 64..71 */
        int L6554_;
        unsigned int L6555_;
        unsigned int16_t L6558_;
        unsigned int16_t L6559_;
        unsigned char L6557_;


#ifdef MEDIA488_F20E_F20J
        L6558_ = *((unsigned int16_t*)P0084_puc_SoundData); /* First word of sound data contains number of sound samples */
        L6558_ = (L6558_ << 8) | (L6558_ >> 8); /* Convert from big endian to little endian */
#endif
#ifdef MEDIA670_F31E_F31J
        L6558_ = P0085_i_Period;
#endif
        if (L6558_ > 31936) { /* Make sure number of sample is small enough to fit in G4096_PLAY_BUF buffer */
                L6558_ = 31936;
        }
        for (L6559_ = 0; L6559_ < L6558_; L6559_++) {
#ifdef MEDIA488_F20E_F20J
                L6557_ = P0084_puc_SoundData[L6559_ + 2];
#endif
#ifdef MEDIA670_F31E_F31J
                L6557_ = P0084_puc_SoundData[L6559_] + 0x80;
#endif
                if (L6557_ & 0x80) {
                        L6557_ ^= 0x7F;
                }
                G4096_PLAY_BUF[32 + L6559_] = L6557_;
        }
        L6552_i_Frequency = 5500; /* 5500 Hertz */
        memcpy(G4096_PLAY_BUF, "ABCDEFGH", 9); /* Sound Name. Writes 9 bytes but there are only 8 bytes for sound name in buffer. Final '\0' is overwritten by Sound ID */
        *(int*)&G4096_PLAY_BUF[8] = 0x55555555; /* Sound ID */
        *(int*)&G4096_PLAY_BUF[12] = L6558_ ; /* Data length */
        *(int*)&G4096_PLAY_BUF[16] = 0; /* Loop point */
        *(int*)&G4096_PLAY_BUF[20] = 0; /* Loop length */
        *(int*)&G4096_PLAY_BUF[24] = L6552_i_Frequency * 98 / 1000; /* Sampling frequency (2 bytes) */
        *(int*)&G4096_PLAY_BUF[26] = 0 ; /* Correction value of the original sound (2 bytes) */
        *(int*)&G4096_PLAY_BUF[28] = 60 ; /* Musical scale of original sound (1 byte) followed by 3 0x00 bytes of reserved area */
        L6554_ = 64;
        L6555_ = P0086_i_SoundVolume;
        /* G4126_ = (int16_t)(G4126_ + 1) % 8; ANOMALY_FMT with modulo. cx, dx registers used instead of ecx, edx, machine code 2 bytes too large */
        _inline(0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90);
        _inline(0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90);
        L6553_ = G4126_ + 64;
        SND_pcm_mode_set(8);
        while (SND_pcm_status(L6553_));
        SND_pcm_play(L6553_, L6554_, L6555_, G4096_PLAY_BUF);
}

void F2258_SetVolume(
int16_t P6107_ FINAL_SEPARATOR
{
        if (P6107_ < 0) {
                P6107_ = 0;
        }
        G4116_ = 0;
        G4117_ = P6107_;
        SND_elevol_set(1, P6107_, P6107_);
        SND_elevol_mute(49);
}

void F0814_TRansition_MIDIMusic(
void
)
{
        G4116_ = 1;
}

void F0710_WaitSoundPlayComplete(
void
)
{
#ifdef MEDIA670_F31E_F31J
        int16_t L6551_;


        for (L6551_ = 0; L6551_< 8; L6551_++) {
                while (SND_pcm_status(L6551_ + 64));
        }
#endif
}
#endif
