| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef _CMD_STREAM_H |
| 21 |
#define _CMD_STREAM_H |
| 22 |
|
| 23 |
#include "defines.h" |
| 24 |
#include "safeReader.h" |
| 25 |
|
| 26 |
#define DIV_MAX_CSTRACE 64 |
| 27 |
#define DIV_MAX_CSSTACK 128 |
| 28 |
|
| 29 |
class DivEngine; |
| 30 |
|
| 31 |
struct DivCSChannelState { |
| 32 |
unsigned int startPos; |
| 33 |
unsigned int readPos; |
| 34 |
int waitTicks; |
| 35 |
int lastWaitLen; |
| 36 |
|
| 37 |
int note, pitch; |
| 38 |
int volume, volMax, volSpeed, volSpeedTarget; |
| 39 |
int vibratoDepth, vibratoRate, vibratoPos, vibratoRange, vibratoShape; |
| 40 |
int portaTarget, portaSpeed; |
| 41 |
unsigned char arp, arpStage, arpTicks; |
| 42 |
|
| 43 |
unsigned int callStack[DIV_MAX_CSSTACK]; |
| 44 |
unsigned char callStackPos, callStackSize; |
| 45 |
|
| 46 |
unsigned int trace[DIV_MAX_CSTRACE]; |
| 47 |
unsigned char tracePos; |
| 48 |
|
| 49 |
bool doCall(unsigned int addr); |
| 50 |
|
| 51 |
DivCSChannelState(): |
| 52 |
readPos(0), |
| 53 |
waitTicks(0), |
| 54 |
lastWaitLen(0), |
| 55 |
note(-1), |
| 56 |
pitch(0), |
| 57 |
volume(0x7f00), |
| 58 |
volMax(0), |
| 59 |
volSpeed(0), |
| 60 |
volSpeedTarget(-1), |
| 61 |
vibratoDepth(0), |
| 62 |
vibratoRate(0), |
| 63 |
vibratoPos(0), |
| 64 |
portaTarget(0), |
| 65 |
portaSpeed(0), |
| 66 |
arp(0), |
| 67 |
arpStage(0), |
| 68 |
arpTicks(0), |
| 69 |
callStackPos(0), |
| 70 |
callStackSize(0), |
| 71 |
tracePos(0) { |
| 72 |
for (int i=0; i<DIV_MAX_CSTRACE; i++) { |
| 73 |
trace[i]=0; |
| 74 |
} |
| 75 |
} |
| 76 |
}; |
| 77 |
|
| 78 |
class DivCSPlayer { |
| 79 |
DivEngine* e; |
| 80 |
unsigned char* b; |
| 81 |
unsigned short* bAccessTS; |
| 82 |
size_t bLen; |
| 83 |
SafeReader stream; |
| 84 |
DivCSChannelState chan[DIV_MAX_CHANS]; |
| 85 |
unsigned char fastDelays[16]; |
| 86 |
unsigned char fastCmds[16]; |
| 87 |
unsigned char arpSpeed; |
| 88 |
unsigned int fileChans; |
| 89 |
unsigned int curTick, fastDelaysOff, fastCmdsOff, deltaCyclePos; |
| 90 |
bool longPointers; |
| 91 |
bool bigEndian; |
| 92 |
|
| 93 |
short vibTable[64]; |
| 94 |
public: |
| 95 |
unsigned char* getData(); |
| 96 |
unsigned short* getDataAccess(); |
| 97 |
size_t getDataLen(); |
| 98 |
DivCSChannelState* getChanState(int ch); |
| 99 |
unsigned int getFileChans(); |
| 100 |
unsigned char* getFastDelays(); |
| 101 |
unsigned char* getFastCmds(); |
| 102 |
unsigned int getCurTick(); |
| 103 |
void cleanup(); |
| 104 |
bool tick(); |
| 105 |
bool init(); |
| 106 |
DivCSPlayer(DivEngine* en, unsigned char* buf, size_t len): |
| 107 |
e(en), |
| 108 |
b(buf), |
| 109 |
bAccessTS(NULL), |
| 110 |
bLen(len), |
| 111 |
stream(buf,len) {} |
| 112 |
}; |
| 113 |
|
| 114 |
struct DivCSProgress { |
| 115 |
int stage, count, total; |
| 116 |
int optStage, findTotal; |
| 117 |
int optCurrent, optTotal; |
| 118 |
int findCurrent, expandCurrent; |
| 119 |
int origCurrent, origCount; |
| 120 |
DivCSProgress(): |
| 121 |
stage(0), |
| 122 |
count(0), |
| 123 |
total(0), |
| 124 |
optStage(0), |
| 125 |
findTotal(0), |
| 126 |
optCurrent(0), |
| 127 |
optTotal(0), |
| 128 |
findCurrent(0), |
| 129 |
expandCurrent(0), |
| 130 |
origCurrent(0), |
| 131 |
origCount(0) {} |
| 132 |
}; |
| 133 |
|
| 134 |
struct DivCSOptions { |
| 135 |
bool longPointers; |
| 136 |
bool bigEndian; |
| 137 |
bool noCmdCallOpt; |
| 138 |
bool noDelayCondense; |
| 139 |
bool noSubBlock; |
| 140 |
|
| 141 |
DivCSOptions(): |
| 142 |
longPointers(false), |
| 143 |
bigEndian(false), |
| 144 |
noCmdCallOpt(false), |
| 145 |
noDelayCondense(false), |
| 146 |
noSubBlock(false) {} |
| 147 |
}; |
| 148 |
|
| 149 |
// command stream utilities |
| 150 |
namespace DivCS { |
| 151 |
int getCmdLength(unsigned char ext); |
| 152 |
int getInsLength(unsigned char ins, unsigned char ext=0, unsigned char* speedDial=NULL); |
| 153 |
}; |
| 154 |
|
| 155 |
#endif |