Commit Graph
14 Commits
Author SHA1 Message Date
Nunuhara Cabbage 55f3991546 Implement more string instructions
Implement all of the string instructions that I could get the compiler
to generate code for. Still ASCII-only.
2019-10-14 14:18:09 -07:00
Nunuhara Cabbage cc2a2c594a Floating point instructions 2019-10-13 21:32:17 -07:00
Nunuhara Cabbage b7bdd17a50 Add global variables
PUSHGLOBALPAGE and SH_GLOBALREF instructions.
2019-10-13 20:00:11 -07:00
Nunuhara Cabbage 8a40058c81 Overhaul VM design
Overhaul the VM design to more closely resemble System40.exe. See
system4.md for further details.
2019-10-13 17:51:22 -07:00
Nunuhara Cabbage 827e0a85d7 S_ASSIGN & fix SH_LOCALREF for strings 2019-10-10 21:26:41 -07:00
Nunuhara Cabbage 769e0ce0c3 Add argument types to instruction table
Not really useful for the VM, but could be used for an objdump-like
utility.
2019-10-10 07:16:48 -07:00
Nunuhara Cabbage 92710dc06a INC/DEC and DUP* instructions
Random note: The SDK compiler generates some pretty strange code for
'n++' when 'n' is a reference:

    instruction                state of stack after instruction
    -----------                --------------------------------
    PUSHLOCALPAGE              ; P(ref n)
    PUSH <variable index of n> ; P(ref n),V(ref n)
    REFREF                     ; P(n),V(n)
    DUP2                       ; P(n),V(n),P(n),V(n)
    REF                        ; P(n),V(n),n
    DUP_X2                     ; n,P(n),V(n),n
    POP                        ; n,P(n),V(n)
    INC                        ; n
    POP                        ;

This would seem to be completely equivalent to the following:

    PUSHLOCALPAGE
    PUSH <variable index of n>
    REFREF
    INC
2019-10-07 19:32:56 -07:00
Nunuhara Cabbage e629d0ad3e Use vm_value for frame_stack & implement S_REF 2019-10-07 18:30:20 -07:00
Nunuhara Cabbage 3925c8ea96 Unify stack & string_stack
Use an array of unions for the stack. I'm still not sure if System40.exe
uses separate stack for string operations or not. Need to check if POP
after S_PUSH removes the pushed string.
2019-10-07 18:04:36 -07:00
Nunuhara Cabbage 53dc8a7a44 strings: store size together with text in memory 2019-10-07 16:54:46 -07:00
Nunuhara Cabbage 626e4f47d7 Arithmetic assignment instructions (+=, -=, etc.) 2019-10-07 16:12:24 -07:00
Nunuhara Cabbage 587dc34ddb Implement ASSIGN and basic arithmetic instructions 2019-10-06 22:32:50 -07:00
Nunuhara Cabbage eb63980294 Call system.Exit after returning from main
A bit of a hack: we insert an extra 'CALLSYS 0x0' instruction
(system.Exit) at the end of the code section, then set up a stack frame
so that when main() returns, it jumps to that instruction.
2019-10-06 20:58:03 -07:00
Nunuhara Cabbage 84df756faf Initial commit
An assortment of instructions have been implemented so far, mostly basic
stuff such as stack management. The following program can be executed:

int main(void)
{
    hello(2);
    for (;;) {
        system.Peek();
        system.Sleep(1);
    }
    return 0;
}

void hello(int n)
{
    int i;
    for (i = 0; i < n; i++) {
        system.Output("Hello, world! " + string(i));
    }
}
2019-10-06 19:35:36 -07:00