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/29 08:14] – appledog | javascript_terminal_v3 [2025/12/05 02:36] (current) – appledog | ||
|---|---|---|---|
| Line 34: | Line 34: | ||
| 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 an interpreter | ||
| + | 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 | ||
| + | < | ||
| + | 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 | == It's really a CPU | ||
| - | 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. | + | 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. |
| - | === Jump Table in JavaScript | + | 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 | ||
| < | < | ||
| // Define functions | // Define functions | ||
| Line 71: | Line 93: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| This example is how to support a large number of opcodes/ | This example is how to support a large number of opcodes/ | ||
| - | == The Goal of V3 | + | == Refactoring Needed |
| - | A full featured terminal like V2 but refactored | + | 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 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 |
| - | It's kind of like writing | + | In a real VM, the code would not be stored |
| - | + | ||
| - | In most cases, the input method | + | |
| == Final Thoughts | == Final Thoughts | ||
| - | Today' | + | Today' |
| - | + | ||
| - | Second, | + | |
| - | Even an 80486 had five pipelines and ran at 100mhz, and this might have already been 500 to 1000 times faster than a 6502/ | + | 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. |
| - | == More Final Thoughts | + | (--Me, in 2022). |
| - | I don't think anything similar to this really exists. There are almost ten different C64 emulators written in JavaScript here: https:// | + | |
| - | Of particular interest will probably be ZZT.js and Parchment, as well as others -- which are game engines written in JavaScript. In it's current state, Terminal V2 (using gameState) is already good enough to serve as a platform for interactive games, since enter-on-a-line is good enough. You could also use V2 as a MUD platform. So why V3? It just feels like the next step in development of the terminal, but we must be careful to step into the rabbithole of writing an entire virtual computer and OS, at least not just yet. | ||
javascript_terminal_v3.1701245699.txt.gz · Last modified: by appledog
