furnace/src/engine/zsm.h

93 lines
2.6 KiB
C
Raw Normal View History

2022-05-26 05:24:21 +00:00
/**
* Furnace Tracker - multi-system chiptune tracker
2023-01-20 00:18:40 +00:00
* Copyright (C) 2021-2023 tildearrow and contributors
2022-05-26 05:24:21 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _ZSM_H
#define _ZSM_H
//#include "engine.h"
#include "safeWriter.h"
#include "dispatch.h"
#include <stdlib.h>
#define ZSM_HEADER_SIZE 16
#define ZSM_VERSION 1
#define ZSM_YM_CMD 0x40
#define ZSM_DELAY_CMD 0x80
#define ZSM_YM_MAX_WRITES 63
#define ZSM_SYNC_MAX_WRITES 31
2022-05-26 05:24:21 +00:00
#define ZSM_DELAY_MAX 127
#define ZSM_EOF ZSM_DELAY_CMD
#define ZSM_EXT ZSM_YM_CMD
#define ZSM_EXT_PCM 0x00
#define ZSM_EXT_CHIP 0x40
#define ZSM_EXT_SYNC 0x80
#define ZSM_EXT_CUSTOM 0xC0
2022-05-26 05:24:21 +00:00
enum YM_STATE { ym_PREV, ym_NEW, ym_STATES };
enum PSG_STATE { psg_PREV, psg_NEW, psg_STATES };
class DivZSM {
2022-05-26 05:24:21 +00:00
private:
struct S_pcmInst {
int geometry;
unsigned int offset, length, loopPoint;
bool isLooped;
};
2022-09-24 07:31:10 +00:00
SafeWriter* w;
int ymState[ym_STATES][256];
int psgState[psg_STATES][64];
int pcmRateCache;
int pcmCtrlRVCache;
int pcmCtrlDCCache;
unsigned int pcmLoopPointCache;
bool pcmIsLooped;
2022-09-24 07:31:10 +00:00
std::vector<DivRegWrite> ymwrites;
std::vector<DivRegWrite> pcmMeta;
std::vector<unsigned char> pcmData;
std::vector<unsigned char> pcmCache;
std::vector<S_pcmInst> pcmInsts;
2023-08-11 08:02:18 +00:00
std::vector<DivRegWrite> syncCache;
2022-09-24 07:31:10 +00:00
int loopOffset;
int numWrites;
int ticks;
int tickRate;
int ymMask;
int psgMask;
2023-08-11 20:03:37 +00:00
bool optimize;
2022-05-26 05:24:21 +00:00
public:
2022-09-24 07:31:10 +00:00
DivZSM();
~DivZSM();
void init(unsigned int rate = 60);
int getoffset();
void writeYM(unsigned char a, unsigned char v);
void writePSG(unsigned char a, unsigned char v);
void writePCM(unsigned char a, unsigned char v);
2023-08-11 08:02:18 +00:00
void writeSync(unsigned char a, unsigned char v);
2023-08-11 20:03:37 +00:00
void setOptimize(bool o);
2022-09-24 07:31:10 +00:00
void tick(int numticks = 1);
void setLoopPoint();
SafeWriter* finish();
2022-05-26 05:24:21 +00:00
private:
void flushWrites();
void flushTicks();
};
#endif