furnace/src/engine/cmdStream.h

121 lines
2.8 KiB
C
Raw Normal View History

/**
* Furnace Tracker - multi-system chiptune tracker
2025-01-28 18:49:19 -05:00
* Copyright (C) 2021-2025 tildearrow and contributors
*
* 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 _CMD_STREAM_H
#define _CMD_STREAM_H
#include "defines.h"
#include "safeReader.h"
#define DIV_MAX_CSTRACE 64
class DivEngine;
struct DivCSChannelState {
2024-03-08 17:53:37 -05:00
unsigned int startPos;
unsigned int readPos;
int waitTicks;
int lastWaitLen;
2023-03-27 01:40:54 -04:00
int note, pitch;
int volume, volMax, volSpeed, volSpeedTarget;
2023-03-27 01:40:54 -04:00
int vibratoDepth, vibratoRate, vibratoPos;
int portaTarget, portaSpeed;
2025-04-04 06:01:49 -04:00
unsigned char arp, arpStage, arpTicks, loopCount;
2023-03-27 01:40:54 -04:00
unsigned int callStack[16];
2023-03-27 01:40:54 -04:00
unsigned char callStackPos;
unsigned int trace[DIV_MAX_CSTRACE];
2023-03-27 01:40:54 -04:00
unsigned char tracePos;
bool doCall(unsigned int addr);
DivCSChannelState():
readPos(0),
waitTicks(0),
lastWaitLen(0),
2023-03-27 01:40:54 -04:00
note(-1),
pitch(0),
volume(0x7f00),
volMax(0),
2023-03-27 01:40:54 -04:00
volSpeed(0),
2024-08-23 14:24:24 -04:00
volSpeedTarget(-1),
2023-03-27 01:40:54 -04:00
vibratoDepth(0),
vibratoRate(0),
vibratoPos(0),
portaTarget(0),
portaSpeed(0),
arp(0),
arpStage(0),
arpTicks(0),
2025-04-04 06:01:49 -04:00
loopCount(0),
callStackPos(0),
tracePos(0) {
for (int i=0; i<DIV_MAX_CSTRACE; i++) {
trace[i]=0;
}
}
};
class DivCSPlayer {
DivEngine* e;
unsigned char* b;
2024-03-08 17:53:37 -05:00
size_t bLen;
SafeReader stream;
DivCSChannelState chan[DIV_MAX_CHANS];
unsigned char fastDelays[16];
unsigned char fastCmds[16];
2023-03-27 04:29:43 -04:00
unsigned char arpSpeed;
unsigned int fileChans;
2023-03-27 01:40:54 -04:00
short vibTable[64];
public:
2024-03-08 17:53:37 -05:00
unsigned char* getData();
size_t getDataLen();
DivCSChannelState* getChanState(int ch);
unsigned int getFileChans();
2024-03-08 17:53:37 -05:00
unsigned char* getFastDelays();
unsigned char* getFastCmds();
void cleanup();
bool tick();
bool init();
DivCSPlayer(DivEngine* en, unsigned char* buf, size_t len):
e(en),
b(buf),
2024-03-08 17:53:37 -05:00
bLen(len),
stream(buf,len) {}
};
2025-04-07 01:20:48 -04:00
struct DivCSProgress {
int stage, count, total;
DivCSProgress():
stage(0),
count(0),
total(0) {}
};
// command stream utilities
namespace DivCS {
int getCmdLength(unsigned char ext);
int getInsLength(unsigned char ins, unsigned char ext=0, unsigned char* speedDial=NULL);
};
#endif