javascript_terminal_v3
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| javascript_terminal_v3 [2023/11/30 02:27] – appledog | javascript_terminal_v3 [2025/12/05 02:36] (current) – appledog | ||
|---|---|---|---|
| Line 35: | Line 35: | ||
| Note that if we are in a multi-threaded environment we can always have the game engine running in an off-UI thread. Or the implementation can launch copies in their own threads vs, manual task and context swithching which you would need to simulate in an (ex. JavaScript) implementation. But it would be transparent to the code written for the virtual machine. | Note that if we are in a multi-threaded environment we can always have the game engine running in an off-UI thread. Or the implementation can launch copies in their own threads vs, manual task and context swithching which you would need to simulate in an (ex. JavaScript) implementation. But it would be transparent to the code written for the virtual machine. | ||
| - | == It's really | + | == It's really |
| - | A monolithic atomic queue is like a CPU. Since we don't have a ROM, we write high level commands in JavaScript. Slowly, we can implement opcodes and start working more with the state machine. | + | Like BASIC. The whole thing with INPUT and SET_NAME feels like you are writing your own programming language and interpreter. But on top of that, there' |
| === BASIC Interpreter | === BASIC Interpreter | ||
| - | Instead of refactoring into a state machine, I threw together a quick BASIC class which processed commands in a program[] array. It handles print, and goto. Since it is a quick design it can not handle infinite loops or very long programs, since there is no time for the game loop to process updates and render or for the UI to make those changes to canvas. | + | < |
| + | 10 PRINT A | ||
| + | 20 GOTO 40 | ||
| + | 30 PRINT B | ||
| + | 40 PRINT C | ||
| + | 50 PRINT D | ||
| + | LIST | ||
| + | RUN | ||
| + | A | ||
| + | C | ||
| + | D | ||
| + | |||
| + | </ | ||
| + | |||
| + | Instead of refactoring into a state machine, I threw together a quick BASIC class which processed commands in a program[] array. It handles print, and goto. Since it is a quick design it can not handle infinite loops or very long programs, since there is no time for the game loop to process updates and render or for the UI to make those changes to canvas. Then I realized... refactor into a state machine? Did I even realize what I had just said? | ||
| + | |||
| + | == It's really a CPU | ||
| + | A monolithic atomic queue is kind of like a CPU. Since we don't have a ROM, we write high level commands in JavaScript. Slowly, we can implement opcodes and start working more with the state machine. | ||
| - | However, for the point of theory, yes, it is possible to write a scripting language (or a CPU simulator) and have it run in the terminal. | + | This kind of blew my mind at the time so I took a lot of time off from the project thinking about it. |
| + | == Aside | ||
| ==== Jump Table in JavaScript | ==== Jump Table in JavaScript | ||
| < | < | ||
| Line 75: | Line 93: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| This example is how to support a large number of opcodes/ | This example is how to support a large number of opcodes/ | ||
| == Refactoring Needed | == Refactoring Needed | ||
| - | V3 is V2 but with changes made in how terminal is controlled by the main program. The error of processing commands in the terminal was addressed | + | V3 is V2 but with changes made in how terminal is controlled by the main program. The code has also become somewhat spaghetti. I partially |
| - | The code has also become somewhat spaghetti. I partially addressed this by removing the Tile class from V3 and adding BASIC command processing into its own class. But much more work needs to be done on this. The BASIC class should maintain the copy of the program code. | + | In a real VM, the code would not be stored in a program[] array but in memory[] and read from there by the interpreter. There are lots of little design clashes between the idea of a VM, the idea of a Game (NetWhack) and the idea of s hybrid scripting language written in Javascript. They are not really compatable. So for a V4 the goal will be to pare down and really isolate the functionality of Terminal, and to clean up main by making a class Screen, and also perhaps a class Keyboard, class Mouse, etc. |
| - | + | ||
| - | And, in a real VM, the code would not be stored in a program[] array but in memory[] and read from there by the interpreter. There are lots of little design clashes between the idea of a VM, the idea of a Game (NetWhack) and the idea of s hybrid scripting language written in Javascript. They are not really compatable. So for a V4 the goal will be to pare down and really isolate the functionality of Terminal, and to clean up main by making a class Screen, and also perhaps a class Keyboard, class Mouse, etc. | + | |
| == Final Thoughts | == Final Thoughts | ||
| Today' | Today' | ||
| - | == The Future | + | As it stands, V3 is a sort of kludge, filled with stop-gaps. I will need time to think over everything I have learned, and one day, approach V4 from a different direction. |
| - | V4 will be whatever we do to support NetWhack, and then a pared down version will be presented as a V5 " | + | |
| + | (--Me, in 2022). | ||
javascript_terminal_v3.1701311253.txt.gz · Last modified: by appledog
