]> 4ch.mooo.com Git - 16.git/commitdiff
vgm lib touched wwww
authorsparky4 <sparky4@cock.li>
Sun, 16 Aug 2015 22:30:14 +0000 (17:30 -0500)
committersparky4 <sparky4@cock.li>
Sun, 16 Aug 2015 22:30:14 +0000 (17:30 -0500)
new file:   16/vgmsnd/common.h
modified:   16/vgmsnd/stdtype.h
modified:   16/vgmsnd/vgmSndDrv.c
modified:   16/vgmsnd/vgmSndDrv.h

16/vgmsnd/common.h [new file with mode: 0755]
16/vgmsnd/stdtype.h
16/vgmsnd/vgmSndDrv.c
16/vgmsnd/vgmSndDrv.h

diff --git a/16/vgmsnd/common.h b/16/vgmsnd/common.h
new file mode 100755 (executable)
index 0000000..fbe7807
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef __COMMON_H__
+#define __COMMON_H__
+
+#include "stdtype.h"
+#include "stdbool.h"
+
+#ifndef INLINE
+#if defined(_MSC_VER)
+#define INLINE static __inline // __forceinline
+#elif defined(__GNUC__)
+#define INLINE static __inline__
+#else
+#define INLINE static inline
+#endif
+#endif // INLINE
+
+#endif // __COMMON_H__
index 42dc92ef7909377bc733765554012df0c08207ed..b0b55606c324828acce256283ee2b7db1680cc6f 100755 (executable)
@@ -32,11 +32,11 @@ typedef   signed int                 INT32;
 \r
 // 64-bit values\r
 #ifdef _MSC_VER\r
-typedef unsigned __int64       UINT64;\r
-typedef   signed __int64        INT64;\r
+//typedef unsigned __int64     UINT64;\r
+//typedef   signed __int64      INT64;\r
 #else\r
-__extension__ typedef unsigned long long       UINT64;\r
-__extension__ typedef   signed long long        INT64;\r
+//__extension__ typedef unsigned long long     UINT64;\r
+//__extension__ typedef   signed long long      INT64;\r
 #endif\r
 #endif // _WINDOWS_H\r
 \r
index dcdb17472baa406dd57d29ef8b6ed86d54237f1d..022af5485207f96b526ffceb294bb338d907660b 100755 (executable)
@@ -8,7 +8,7 @@
 #include <stdlib.h>\r
 #include <string.h>\r
 \r
-#include <common.h>\r
+#include "common.h"\r
 #include "vgmSndDrv.h"\r
 \r
 \r
@@ -46,7 +46,7 @@ typedef struct _vgm_playback
        UINT32 vgmSmplPos;\r
        UINT32 pbSmplPos;\r
        VGM_FILE* file;\r
-       \r
+\r
        // oplChnMask:\r
        //      Music: mask of channels used/overridden by SFX\r
        //      SFX:   ID of channel used by SFX (all commands are forces to it)\r
@@ -145,16 +145,16 @@ UINT8 OpenVGMFile(const char* FileName, VGM_FILE* vgmFile)
        VGM_BASE_HDR vgmBaseHdr;\r
        FILE* hFile;\r
        UINT32 CurPos;\r
-       \r
+\r
        memset(vgmFile, 0x00, sizeof(VGM_FILE));\r
-       \r
+\r
        hFile = fopen(FileName, "rb");\r
        if (hFile == NULL)\r
                return 0xFF;\r
-       \r
+\r
        hdrSize = sizeof(VGM_BASE_HDR);\r
        readEl = fread(&vgmBaseHdr, hdrSize, 0x01, hFile);\r
-       if (readEl <= 0)\r
+       if (readEl == 0)\r
        {\r
                fclose(hFile);\r
                return 0xFE;    // read error\r
@@ -169,7 +169,7 @@ UINT8 OpenVGMFile(const char* FileName, VGM_FILE* vgmFile)
                fclose(hFile);\r
                return 0x81;    // We don't support VGM v1.10 and earlier\r
        }\r
-       \r
+\r
        vgmFile->dataLen = vgmBaseHdr.lngEOFOffset + 0x04;\r
        vgmFile->data = (UINT8*)malloc(vgmFile->dataLen);\r
        if (vgmFile->data == NULL)\r
@@ -186,11 +186,11 @@ UINT8 OpenVGMFile(const char* FileName, VGM_FILE* vgmFile)
                //return 0xFE;  // read error\r
                vgmFile->dataLen = hdrSize + readEl;\r
        }\r
-       \r
+\r
        fclose(hFile);\r
-       \r
+\r
        memcpy(&vgmFile->header, vgmFile->data, sizeof(VGM_HEADER));\r
-       \r
+\r
        // relative -> absolute addresses\r
        vgmFile->header.lngEOFOffset += 0x04;\r
        if (vgmFile->header.lngGD3Offset)\r
@@ -200,14 +200,14 @@ UINT8 OpenVGMFile(const char* FileName, VGM_FILE* vgmFile)
        if (! vgmFile->header.lngDataOffset)\r
                vgmFile->header.lngDataOffset = 0x0C;\r
        vgmFile->header.lngDataOffset += 0x34;\r
-       \r
+\r
        CurPos = vgmFile->header.lngDataOffset;\r
        if (vgmFile->header.lngVersion < 0x0150)\r
                CurPos = 0x40;\r
        hdrSize = sizeof(VGM_HEADER);\r
        if (hdrSize > CurPos)\r
                memset((UINT8*)&vgmFile->header + CurPos, 0x00, hdrSize - CurPos);\r
-       \r
+\r
        fclose(hFile);\r
        return 0x00;\r
 }\r
@@ -216,7 +216,7 @@ void FreeVGMFile(VGM_FILE* vgmFile)
 {\r
        free(vgmFile->data);    vgmFile->data = NULL;\r
        vgmFile->dataLen = 0;\r
-       \r
+\r
        return;\r
 }\r
 \r
@@ -224,16 +224,16 @@ void FreeVGMFile(VGM_FILE* vgmFile)
 static bool DoVgmLoop(VGM_PBK* vgmPlay)\r
 {\r
        const VGM_HEADER* vgmHdr = &vgmPlay->file->header;\r
-       \r
+\r
        if (! vgmHdr->lngLoopOffset)\r
                return false;\r
-       \r
+\r
        vgmPlay->curLoopCnt ++;\r
-       \r
+\r
        vgmPlay->vgmPos = vgmHdr->lngLoopOffset;\r
        vgmPlay->vgmSmplPos -= vgmHdr->lngLoopSamples;\r
        vgmPlay->pbSmplPos -= vgmHdr->lngLoopSamples;\r
-       \r
+\r
        return true;\r
 }\r
 \r
@@ -247,7 +247,7 @@ static void UpdateVGM(VGM_PBK* vgmPlay, UINT16 Samples)
        UINT8 Command;\r
        UINT8 blockType;\r
        UINT32 blockLen;\r
-       \r
+\r
        vgmPlay->pbSmplPos += Samples;\r
        VGMPos = vgmPlay->vgmPos;\r
        VGMSmplPos = vgmPlay->vgmSmplPos;\r
@@ -373,7 +373,7 @@ static void UpdateVGM(VGM_PBK* vgmPlay, UINT16 Samples)
                        vgmPlay->vgmEnd = 0x01;\r
                        return;\r
                }\r
-               \r
+\r
                if (VGMPos >= vgmLen)\r
                        vgmPlay->vgmEnd = 0x01;\r
        }\r
@@ -381,7 +381,7 @@ static void UpdateVGM(VGM_PBK* vgmPlay, UINT16 Samples)
        vgmPlay->vgmSmplPos = VGMSmplPos;\r
        if (vgmPlay->vgmEnd)\r
                StopPlayback(vgmPlay);\r
-       \r
+\r
        return;\r
 }\r
 \r
@@ -392,14 +392,14 @@ void InitEngine(void)
 {\r
        UINT8 curSFX;\r
        UINT8 curReg;\r
-       \r
+\r
        memset(oplRegs_Music, 0x00, 0x100);\r
        memset(&vgmPbMusic, 0x00, sizeof(VGM_PBK));\r
        vgmPbMusic.pbMode = PBMODE_MUSIC;\r
        vgmPbMusic.vgmEnd = 0xFF;\r
        vgmPbMusic.oplChnMask = 0x0000;\r
        vgmPbMusic.oplRegCache = oplRegs_Music;\r
-       \r
+\r
        for (curSFX = 0; curSFX < SFX_CHN_COUNT; curSFX ++)\r
        {\r
                memset(&oplRegs_SFX[curSFX], 0x00, sizeof(VGM_PBK));\r
@@ -409,7 +409,7 @@ void InitEngine(void)
                vgmPbSFX[curSFX].oplChnMask = curSFX;\r
                vgmPbSFX[curSFX].oplRegCache = oplRegs_SFX[curSFX];\r
        }\r
-       \r
+\r
        // reset OPL2 chip\r
        curReg = 0x00;\r
        do\r
@@ -417,26 +417,26 @@ void InitEngine(void)
                curReg --;\r
                OPL2_Write(curReg, 0x00);\r
        } while(curReg > 0x20);\r
-       \r
+\r
        OPL2_Write(0x02, TIMER1_RATE);  // set Timer 1 Period\r
        OPL2_Write(0x04, 0x01); // Timer 1 on/unmasked, Timer 2 off\r
        OPL2_Write(0x04, 0x80); // Reset Timer/IRQ Status Flags\r
-       \r
+\r
        OPL2_Write(0x01, 0x20); // Waveform Select: Enable\r
-       \r
+\r
        return;\r
 }\r
 \r
 void DeinitEngine(void)\r
 {\r
        UINT8 curSFX;\r
-       \r
+\r
        StopPlayback(&vgmPbMusic);\r
        for (curSFX = 0; curSFX < SFX_CHN_COUNT; curSFX ++)\r
                StopPlayback(&vgmPbSFX[curSFX]);\r
-       \r
+\r
        OPL2_Write(0x04, 0x00); // disable all timers\r
-       \r
+\r
        return;\r
 }\r
 \r
@@ -444,33 +444,33 @@ void DeinitEngine(void)
 UINT8 PlayMusic(VGM_FILE* vgmFile)\r
 {\r
        VGM_PBK* vgmPb = &vgmPbMusic;\r
-       \r
+\r
        if (! vgmPb->vgmEnd)\r
                StopPlayback(vgmPb);\r
-       \r
+\r
        vgmPb->file = vgmFile;\r
-       \r
+\r
        StartPlayback(vgmPb);\r
-       \r
+\r
        return 0x00;\r
 }\r
 \r
 UINT8 PlaySFX(VGM_FILE* vgmFile, UINT8 sfxChnID)\r
 {\r
        VGM_PBK* vgmPb;\r
-       \r
+\r
        if (sfxChnID >= SFX_CHN_COUNT)\r
                return 0xFF;\r
-       \r
+\r
        vgmPb = &vgmPbSFX[sfxChnID];\r
-       \r
+\r
        if (! vgmPb->vgmEnd)\r
                StopPlayback(vgmPb);\r
-       \r
+\r
        vgmPb->file = vgmFile;\r
-       \r
+\r
        StartPlayback(vgmPb);\r
-       \r
+\r
        return 0x00;\r
 }\r
 \r
@@ -488,10 +488,10 @@ UINT8 StopSFX(UINT8 sfxChnID)
                        StopPlayback(&vgmPbSFX[sfxChnID]);\r
                return 0x00;\r
        }\r
-       \r
+\r
        if (sfxChnID >= SFX_CHN_COUNT)\r
                return 0xFF;\r
-       \r
+\r
        StopPlayback(&vgmPbSFX[sfxChnID]);\r
        return 0x00;\r
 }\r
@@ -504,10 +504,10 @@ UINT8 PauseMusic(void)
                return 0x80;    // finished playing already\r
        if (vgmPbMusic.vgmEnd == 0x02)\r
                return 0x01;    // is already paused\r
-       \r
+\r
        StopPlayback(&vgmPbMusic);\r
        vgmPbMusic.vgmEnd = 0x02;\r
-       \r
+\r
        return 0x00;\r
 }\r
 \r
@@ -519,9 +519,9 @@ UINT8 ResumeMusic(void)
                return 0x80;    // finished playing already\r
        if (! (vgmPbMusic.vgmEnd & 0x02))\r
                return 0x01;    // is not paused\r
-       \r
+\r
        vgmPbMusic.vgmEnd &= ~0x02;\r
-       \r
+\r
        return 0x00;\r
 }\r
 \r
@@ -533,25 +533,25 @@ static void StartPlayback(VGM_PBK* vgmPb)
                vgmPb->vgmEnd = 0xFF;\r
                return;\r
        }\r
-       \r
+\r
        vgmPb->vgmEnd = 0x00;   // set to 'running'\r
        vgmPb->vgmPos = vgmPb->file->header.lngDataOffset;\r
        vgmPb->vgmSmplPos = 0;\r
        vgmPb->pbSmplPos = 0;\r
        vgmPb->curLoopCnt = 0;\r
        memset(vgmPb->workRAM, 0x00, 0x04);\r
-       \r
+\r
        if (vgmPb->pbMode == PBMODE_SFX)\r
        {\r
                UINT8 curReg;\r
-               \r
+\r
                curReg = 0xB0 | vgmPb->oplChnMask;\r
                if (oplRegs_Music[curReg] & 0x20)\r
                        OPL2_Write(curReg, oplRegs_Music[curReg] & ~0x20);      // send Key Off\r
-               \r
+\r
                vgmPbMusic.oplChnMask |= (1 << vgmPb->oplChnMask);      // mask out music channel\r
        }\r
-       \r
+\r
        return;\r
 }\r
 \r
@@ -559,12 +559,12 @@ static void StopPlayback(VGM_PBK* vgmPb)
 {\r
        if (vgmPb->vgmEnd & 0x80)\r
                return;\r
-       \r
+\r
        if (vgmPb->pbMode == PBMODE_MUSIC)\r
        {\r
                UINT8 curReg;\r
                UINT16 chnMask;\r
-               \r
+\r
                chnMask = 0x0001;\r
                for (curReg = 0xB0; curReg < 0xB9; curReg ++, chnMask <<= 1)\r
                {\r
@@ -582,7 +582,7 @@ static void StopPlayback(VGM_PBK* vgmPb)
                        vgmPb->oplRegCache[curReg] &= ~0x1F;\r
                        OPL2_Write(curReg, vgmPb->oplRegCache[curReg]); // send Key Off\r
                }\r
-               \r
+\r
                vgmPb->vgmEnd = 0x01;\r
        }\r
        else //if (vgmPb->pbMode == PBMODE_SFX)\r
@@ -590,16 +590,16 @@ static void StopPlayback(VGM_PBK* vgmPb)
                UINT8 regID;\r
                UINT8 curReg;\r
                UINT8 opMask;\r
-               \r
+\r
                curReg = 0xB0 | vgmPb->oplChnMask;\r
                if (vgmPb->oplRegCache[0x0C] & 0x20)\r
                {\r
                        vgmPb->oplRegCache[0x0C] &= ~0x20;\r
                        OPL2_Write(curReg, vgmPb->oplRegCache[0x0C]);   // send Key Off\r
                }\r
-               \r
+\r
                vgmPb->vgmEnd = 0x01;\r
-               \r
+\r
                if (! vgmPbMusic.vgmEnd)        // if (music is playing)\r
                {\r
                        opMask = CHN_OPMASK[vgmPb->oplChnMask];\r
@@ -613,11 +613,11 @@ static void StopPlayback(VGM_PBK* vgmPb)
                                curReg = SFX_REGS[regID] | vgmPb->oplChnMask;\r
                                OPL2_Write(curReg, oplRegs_Music[curReg]);      // restore Music register\r
                        }\r
-                       \r
+\r
                        vgmPbMusic.oplChnMask &= ~(1 << vgmPb->oplChnMask);\r
                }\r
        }\r
-       \r
+\r
        return;\r
 }\r
 \r
@@ -627,13 +627,13 @@ static void OPL_CachedWrite(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
 {\r
        UINT8 regChn;\r
        UINT8 ramOfs;\r
-       \r
+\r
        if (vgmPb->pbMode == PBMODE_MUSIC)\r
        {\r
                if (reg == 0x01)\r
                        data |= 0x20;   // enforce "Waveform Select Enable" bit\r
                vgmPb->oplRegCache[reg] = data;\r
-               \r
+\r
                ramOfs = SFX_REGS_REV[reg >> 4];\r
                if (ramOfs < 0x0A)      // Operator 20/40/60/80/E0\r
                {\r
@@ -652,11 +652,11 @@ static void OPL_CachedWrite(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
        {\r
                if (reg == 0xBD)\r
                        return; // no rhythm register for SFX\r
-               \r
+\r
                ramOfs = SFX_REGS_REV[reg >> 4];\r
                if (ramOfs == 0xFF)\r
                        return;\r
-               \r
+\r
                if (ramOfs < 0x0A)      // Operator 20/40/60/80/E0\r
                {\r
                        regChn = CHN_OPMASK_REV[reg & 0x1F];\r
@@ -665,7 +665,7 @@ static void OPL_CachedWrite(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
                        ramOfs += (regChn & 0x80) >> 7;\r
                        regChn &= 0x7F;\r
                        vgmPb->oplRegCache[ramOfs] = data;\r
-                       \r
+\r
                        if (regChn != vgmPb->oplChnMask)\r
                        {\r
                                // force command to current channel\r
@@ -678,11 +678,11 @@ static void OPL_CachedWrite(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
                        if (regChn >= 0x09)\r
                                return; // ignore writes to invalid channels\r
                        vgmPb->oplRegCache[ramOfs] = data;\r
-                       \r
+\r
                        reg = (reg & 0xF0) | vgmPb->oplChnMask;\r
                }\r
        }\r
-       \r
+\r
        OPL2_Write(reg, data);\r
        return;\r
 }\r
@@ -704,7 +704,7 @@ static void ym3812_write(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
                if (! vgmPb->workRAM[0x00])     // "Wave Select Enable" off?\r
                        data = 0x00;    // disable waveforms\r
        }\r
-       \r
+\r
        OPL_CachedWrite(vgmPb, reg, data);\r
        return;\r
 }\r
@@ -722,7 +722,7 @@ static void ym3512_write(VGM_PBK* vgmPb, UINT8 reg, UINT8 data)
                else\r
                        return; // ignore Y8950 DeltaT writes\r
        }\r
-       \r
+\r
        OPL_CachedWrite(vgmPb, reg, data);\r
        return;\r
 }\r
@@ -738,12 +738,12 @@ void UpdateSoundEngine(void)
 {\r
        UINT8 tmrMask;\r
        UINT8 curSFX;\r
-       \r
+\r
        tmrMask = OPL2_ReadStatus();\r
        if (! (tmrMask & 0x40))\r
                return; // wait for overflow\r
        OPL2_Write(0x04, 0x80); // Reset Timer/IRQ Status Flags\r
-       \r
+\r
        if (! vgmPbMusic.vgmEnd)\r
                UpdateVGM(&vgmPbMusic, VGM_UPD_RATE);\r
        for (curSFX = 0; curSFX < SFX_CHN_COUNT; curSFX ++)\r
@@ -751,6 +751,6 @@ void UpdateSoundEngine(void)
                if (! vgmPbSFX[curSFX].vgmEnd)\r
                        UpdateVGM(&vgmPbSFX[curSFX], VGM_UPD_RATE);\r
        }\r
-       \r
+\r
        return;\r
 }\r
index b3a38f02d174ae15794b897704942724e731bd6a..e121c6802dfe04d25f1a542365edd953758188ea 100755 (executable)
@@ -6,7 +6,7 @@ extern "C"
 {\r
 #endif\r
 \r
-#include <stdtype.h>\r
+#include "stdtype.h"\r
 \r
 typedef struct _vgm_file_header\r
 {\r