So it wouldn't blow your COMPUTER up, but your fans might fly to pieces trying to cool it down. :p
I'll include a documentation update with the next update - JMP and IFJMP should definitely have some more detailing, both on the running functions/explodey aspect, and just in general, considering they're both heavily influenced by Redcode and thusly likely to confuse folks.
I know it's not immediately related to the JMP discussion, but should I think about adding an auto-save whenever you compile a program? E.G, to [ProgramName].autosave.casm? That way if your game explodes, you're not gonna lose your code. Same for the drive, maybe do an autosave of it at regular intervals?
An in-game flame-out animation might be kinda fun - if it detects the loop, the halt light comes on and steam comes outta the box.
--
public List<int> runAddresses; //assume it's initialized elsewhere public int currentCounter; //self-evident public int[] RAM; //self-evident void TimedUpdate() //this runs at the computer's clockrate to execute code and such { //code surrounding halts and such goes here runAddresses.Clear(); DoProcess(); } void DoProcess() //this actually executes op-codes & whatnot { runAddresses.Add(currentCounter); int data,opCode,arguments; //data is the memory data at RAM[currentCounter], and arguments is the last 28 bits of said data //insert all the other functions and such if(opCode==4) //JMP { int destAddress; //assume this is set by reading the arguments & whatnot if(runAddresses.Contains(destAddress)) { DoFlameout(); } } }
Rough pseudocode for how to integrate the recursive loop prevention as you suggested it. Clear the list of run addresses before running op-codes, and add the current program counter to the list of run addresses at the beginning of the op-code-runner function. If the list of run addresses contains whatever JMP is supposed to be jumping to, cause a flame-out animation & halt the processor, rather than running it.
This SHOULD catch all possible recursive JMP loops that'd cause a stack overflow, without breaking things like the Blinkenlights loop. Only situation I can think of would be something with self-modifying code looping, but...that shouldn't even be an issue (since a non-JMP call will reset the list of addresses) in the current version of the game. A multithreaded two-core version of the TC-06 could encounter problems with that, if your modification was happening on the other processor, though. :/
I do appreciate the suggestions & bug reports - thank you for providing them!
(As for halting and catching fire - I think that should literally just be "run JMP 0 0 for a special surprise" or something :P)