- Now labels must include its number

This commit is contained in:
2023-01-10 18:55:36 +01:00
parent 3fed72a19b
commit 256f4a2d04
2 changed files with 41 additions and 9 deletions

View File

@@ -37,7 +37,6 @@ struct channel_t {
char* stack[10] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8_t stackpos = 0;
char* labels[10] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8_t numlabels = 0;
};
static channel_t channels[MAX_CHANNELS];
@@ -145,7 +144,6 @@ int chirp_play(const char* new_song) {
channels[c].tempo=44100;
channels[c].waveform=0;
channels[c].stackpos=0;
channels[c].numlabels=0;
channels[c].song = (char*)malloc( strlen( new_song ) + 1 );
strcpy( channels[c].song, new_song );
channels[c].song_ptr = channels[c].song;
@@ -207,16 +205,20 @@ int32_t interpret_next_token(const int c) { //uint8_t* buffer) {
return 0;
case '=':
channels[c].stackpos = 0;
channels[c].numlabels = 0;
channels[c].song_ptr = channels[c].song;
return 0;
case '[':
++*token;
channels[c].labels[channels[c].numlabels] = *token; //channels[c].song_ptr;
channels[c].numlabels++;
param = *++*token;
if( param >= 48 && param <= 57 ) { param -= 48; ++*token; } else { param = 0; }
channels[c].labels[uint8_t(param)] = *token; //channels[c].song_ptr;
{
char* nextpos = *token;
while(*nextpos!=']') nextpos++;
uint8_t innerblocks=0;
while(innerblocks>0 || *nextpos!=']') {
if (*nextpos=='[') innerblocks++;
if (*nextpos==']') innerblocks--;
nextpos++;
}
channels[c].stack[channels[c].stackpos]=nextpos+1;
}
channels[c].stackpos++;