2023-03-26 19:48:16 -04:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2025-01-28 18:49:19 -05:00
|
|
|
* Copyright (C) 2021-2025 tildearrow and contributors
|
2023-03-26 19:48:16 -04: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 _CMD_STREAM_H
|
|
|
|
#define _CMD_STREAM_H
|
|
|
|
|
|
|
|
#include "defines.h"
|
|
|
|
#include "safeReader.h"
|
|
|
|
|
2024-03-09 17:36:44 -05:00
|
|
|
#define DIV_MAX_CSTRACE 64
|
|
|
|
|
2023-03-26 19:48:16 -04:00
|
|
|
class DivEngine;
|
|
|
|
|
|
|
|
struct DivCSChannelState {
|
2024-03-08 17:53:37 -05:00
|
|
|
unsigned int startPos;
|
2023-03-26 19:48:16 -04:00
|
|
|
unsigned int readPos;
|
|
|
|
int waitTicks;
|
2024-03-09 17:36:44 -05:00
|
|
|
int lastWaitLen;
|
2023-03-26 19:48:16 -04:00
|
|
|
|
2023-03-27 01:40:54 -04:00
|
|
|
int note, pitch;
|
2024-08-23 13:39:14 -04:00
|
|
|
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
|
|
|
|
2025-04-05 04:19:44 -04:00
|
|
|
unsigned int callStack[16];
|
2023-03-27 01:40:54 -04:00
|
|
|
unsigned char callStackPos;
|
|
|
|
|
2024-03-09 17:36:44 -05:00
|
|
|
unsigned int trace[DIV_MAX_CSTRACE];
|
2023-03-27 01:40:54 -04:00
|
|
|
unsigned char tracePos;
|
|
|
|
|
|
|
|
bool doCall(unsigned int addr);
|
2023-03-26 19:48:16 -04:00
|
|
|
|
|
|
|
DivCSChannelState():
|
|
|
|
readPos(0),
|
|
|
|
waitTicks(0),
|
2024-03-09 17:36:44 -05:00
|
|
|
lastWaitLen(0),
|
2023-03-27 01:40:54 -04:00
|
|
|
note(-1),
|
|
|
|
pitch(0),
|
2023-03-26 19:48:16 -04:00
|
|
|
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),
|
2024-03-09 17:36:44 -05:00
|
|
|
callStackPos(0),
|
|
|
|
tracePos(0) {
|
|
|
|
for (int i=0; i<DIV_MAX_CSTRACE; i++) {
|
|
|
|
trace[i]=0;
|
|
|
|
}
|
|
|
|
}
|
2023-03-26 19:48:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class DivCSPlayer {
|
|
|
|
DivEngine* e;
|
|
|
|
unsigned char* b;
|
2024-03-08 17:53:37 -05:00
|
|
|
size_t bLen;
|
2023-03-26 19:48:16 -04:00
|
|
|
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;
|
2025-04-05 04:19:44 -04:00
|
|
|
unsigned int fileChans;
|
2023-03-27 01:40:54 -04:00
|
|
|
|
|
|
|
short vibTable[64];
|
2023-03-26 19:48:16 -04:00
|
|
|
public:
|
2024-03-08 17:53:37 -05:00
|
|
|
unsigned char* getData();
|
|
|
|
size_t getDataLen();
|
|
|
|
DivCSChannelState* getChanState(int ch);
|
2025-04-05 04:19:44 -04:00
|
|
|
unsigned int getFileChans();
|
2024-03-08 17:53:37 -05:00
|
|
|
unsigned char* getFastDelays();
|
|
|
|
unsigned char* getFastCmds();
|
2023-03-26 19:48:16 -04:00
|
|
|
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),
|
2023-03-26 19:48:16 -04:00
|
|
|
stream(buf,len) {}
|
|
|
|
};
|
|
|
|
|
2025-04-07 01:20:48 -04:00
|
|
|
struct DivCSProgress {
|
|
|
|
int stage, count, total;
|
|
|
|
DivCSProgress():
|
|
|
|
stage(0),
|
|
|
|
count(0),
|
|
|
|
total(0) {}
|
|
|
|
};
|
|
|
|
|
2025-04-05 04:19:44 -04:00
|
|
|
// command stream utilities
|
|
|
|
namespace DivCS {
|
2025-04-05 19:19:41 -04:00
|
|
|
int getCmdLength(unsigned char ext);
|
|
|
|
int getInsLength(unsigned char ins, unsigned char ext=0, unsigned char* speedDial=NULL);
|
2025-04-05 04:19:44 -04:00
|
|
|
};
|
|
|
|
|
2023-03-26 19:48:16 -04:00
|
|
|
#endif
|