more command stream work

including a disassembler, large stack, and some other things
This commit is contained in:
tildearrow 2025-04-05 03:19:44 -05:00
parent 39ea7e6da0
commit f7c2fce461
5 changed files with 150 additions and 13 deletions

View file

@ -24,7 +24,7 @@
#include "../ta-log.h"
bool DivCSChannelState::doCall(unsigned int addr) {
if (callStackPos>=8) {
if (callStackPos>=16) {
readPos=0;
return false;
}
@ -47,6 +47,10 @@ DivCSChannelState* DivCSPlayer::getChanState(int ch) {
return &chan[ch];
}
unsigned int DivCSPlayer::getFileChans() {
return fileChans;
}
unsigned char* DivCSPlayer::getFastDelays() {
return fastDelays;
}
@ -471,9 +475,9 @@ bool DivCSPlayer::init() {
if (memcmp(magic,"FCS",4)!=0) return false;
unsigned int chans=stream.readI();
fileChans=stream.readI();
for (unsigned int i=0; i<chans; i++) {
for (unsigned int i=0; i<fileChans; i++) {
if (i>=DIV_MAX_CHANS) {
stream.readI();
continue;

View file

@ -39,7 +39,7 @@ struct DivCSChannelState {
int portaTarget, portaSpeed;
unsigned char arp, arpStage, arpTicks, loopCount;
unsigned int callStack[8];
unsigned int callStack[16];
unsigned char callStackPos;
unsigned int trace[DIV_MAX_CSTRACE];
@ -83,12 +83,14 @@ class DivCSPlayer {
unsigned char fastDelays[16];
unsigned char fastCmds[16];
unsigned char arpSpeed;
unsigned int fileChans;
short vibTable[64];
public:
unsigned char* getData();
size_t getDataLen();
DivCSChannelState* getChanState(int ch);
unsigned int getFileChans();
unsigned char* getFastDelays();
unsigned char* getFastCmds();
void cleanup();
@ -101,4 +103,9 @@ class DivCSPlayer {
stream(buf,len) {}
};
// command stream utilities
namespace DivCS {
int getInsLength(unsigned char ins, unsigned char ext=0);
};
#endif

View file

@ -23,7 +23,7 @@
//#define DISABLE_BLOCK_SEARCH
int getInsLength(unsigned char ins) {
int DivCS::getInsLength(unsigned char ins, unsigned char ext) {
switch (ins) {
case 0xb8: // ins
case 0xc0: // pre porta
@ -49,8 +49,11 @@ int getInsLength(unsigned char ins) {
case 0xf0: // opt
return 4;
case 0xf2: // opt command
case 0xf7: // cmd
case 0xf7: { // cmd
// determine length from secondary
if (ext==0) return 0;
return 0;
}
case 0xf8: // callb16
case 0xfc: // waits
return 3;
@ -232,6 +235,8 @@ void writePackedCommandValues(SafeWriter* w, const DivCommand& c) {
}
}
using namespace DivCS;
void reloc(unsigned char* buf, size_t len, unsigned int sourceAddr, unsigned int destAddr) {
unsigned int delta=destAddr-sourceAddr;
for (size_t i=0; i<len;) {
@ -325,6 +330,7 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
size_t subBlockID=subBlocks.size();
int insLen=getInsLength(buf[searchPos]);
bool haveSub=false;
bool onlyCalls=true;
if (insLen<1) {
logE("INS %x NOT IMPLEMENTED...",buf[searchPos]);
@ -333,6 +339,7 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
// register this block
for (size_t i=0; i<groupSize && i<stream->size();) {
if (buf[searchPos+i]!=0xf4) onlyCalls=false;
int insLenI=getInsLength(buf[searchPos+i]);
if (insLenI<1) {
logE("INS %x NOT IMPLEMENTED...",buf[searchPos+i]);
@ -356,6 +363,13 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector<SafeWriter*>& subBlock
continue;
}
// don't do anything if this block only consists of calls
if (onlyCalls) {
logW("nothing but calls.");
searchPos+=insLen;
continue;
}
// find identical blocks
for (size_t i=searchPos+groupLen; i+groupLen<stream->size();) {
int insLenI=getInsLength(buf[i]);
@ -564,6 +578,12 @@ SafeWriter* DivEngine::saveCommand() {
logV("%d",tick);
cmdStreamEnabled=oldCmdStreamEnabled;
remainingLoops=-1;
playing=false;
freelance=false;
extValuePresent=false;
BUSY_END;
// PASS 1: condense delays
// calculate delay usage
for (int h=0; h<chans; h++) {
@ -928,11 +948,5 @@ SafeWriter* DivEngine::saveCommand() {
if (sortedCmdPopularity[i]) logD("- %s: %d",cmdName[sortedCmd[i]],sortedCmdPopularity[i]);
}
remainingLoops=-1;
playing=false;
freelance=false;
extValuePresent=false;
BUSY_END;
return w;
}