1

I am writing a program which has an ASCII background, animating character moving to random locations, and finally adding music

It's my first ever C64 attempt and I want to finish it in BASIC before diving into anything more complicated

I wanted my music to loop so I ruled out read / restore, and am writing frequencies and timing to locations in memory for three voices

This means if I'm to increment through the whole tune, the three locations will increment at a different pace

However, I haven't been able to write for / next routines that execute in parallel, which this would require

I saw the prog reference guide split every measure into 1/16th and got around it that way but this seems highly wasteful on memory

The loops I write wait for each other to finish before moving to the next one, or repeat them, and can't figure out if what I'm trying to do is possible

For example

Voice 1: start at memory location A, keep going until X Voice 2: from location b, keep going until y Voice 3: from location c, keep going until z

The timing data is in the memory locations and obviously isn't the same for each voice

3
  • 6
    Isn't this is a generic programming question, which can be asked without any relation to specific programming language or hardware? You have three things and must check which of the three things is next to trigger after some amount of counts and then it will have a new count which you need to again determine which is the next to trigger?
    – Justme
    Feb 5 at 10:05
  • 6
    I’m voting to close because it's a generic programming question unrelated to any specific language or platform (modern or retro) and likely better-suited to Stack Overflow or a similar programming-concepts site where many will have tackled challenges like this. FWIW Commodore BASIC V2 (as provided by the C64) doesn't natively support any form of multithreading or task synchronisation, so your solution will be using a generalised programming technique rather than a C64-specific feature. Feb 5 at 11:23
  • Also, even if it would be about using very specific C64 features from build or contemporary BASIC, the question is still way too vague, missing any substantial information about the program structure. It would need to add a least a clear code example of relevant construct used, so readers could see what the mentioned synchronisation is about and where the knobs to be turned are.
    – Raffzahn
    Feb 5 at 15:14

1 Answer 1

3

It doesn't sound like something that can be done with 3 FOR loops. You will probably end up doing a single loop, and in each iteration of the loop you will be handling separately / independently the state of all 3 voices.

For instance, you'd have a variable pointing to the active memory for voice 1, another variable for the limit for voice 1, another for flagging that voice 1 is finished; and analogous variables for voices 2 and 3. The code in the loop determines what to do for voice 1 and does it, updating the voice 1 variables. Then it does the same for voice 2 with the set of variables for voice 2. And then voice 3. Then loop back to do this again.

This loop probably wouldn't be done using FOR. FOR is the only formal way to do a loop in CBM BASIC V2, but other types of loops (LOOP..UNTIL, etc.) can be imitated using variables and IF / GOTO statements.

Not the answer you're looking for? Browse other questions tagged .