11. WIP Trig Scheme Functions

11.1. DONE Trig Scheme Loader

CLOSED: [2020-04-20 Mon 22:54] The top-level scheme loader is called s9_load_trig.

<<trig_function_declarations>>=
void s9_load_trig(void);
<<trig_functions>>=
<<trig_scheme_functions>>
static S9_PRIM trig_primitives[] = {
<<trig_scheme_entries>>
    {NULL}
};
void s9_load_trig(void)
{
    monolith_scheme_add_primitives("monolith",
                                   trig_primitives);
}

11.2. DONE Create Trig Page

CLOSED: [2020-04-20 Mon 22:54] A new trig page is created with monolith:trig-new.

<<trig_scheme_entries>>=
{
    "monolith:trig-new",
    pp_trig_new, 1, 1,
    {S9_T_STRING, S9_T_ANY, S9_T_ANY}
},
<<trig_scheme_functions>>=
static s9_cell pp_trig_new(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    int rc;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_newpage(dict, &pg, str, strlen(str));
    if(!rc) {
        return monolith_scheme_error(
            "Could not create trig page (maybe it already exists?)",
            s9_car(x));
    }

    page_trig(pg);
    return S9_UNSPECIFIC;
}

11.3. DONE Goto Pool Position

CLOSED: [2020-04-20 Mon 22:54] Sets the position in the cell pool.

<<trig_scheme_entries>>=
{
    "monolith:trig-goto",
    pp_trig_goto, 2, 2,
    {S9_T_STRING, S9_T_INTEGER, S9_T_ANY}
},
<<trig_scheme_functions>>=
static s9_cell pp_trig_goto(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_trig_d *trig;
    int rc;
    int pos;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if (!rc) {
        return monolith_scheme_error(
            "Could not find trig page",
            s9_car(x));
    }

    x = s9_cdr(x);

    pos = monolith_scheme_integer(NULL, s9_car(x));

    if (pos < 1 || pos >= 32) {
        return monolith_scheme_error(
            "position out of range:",
            s9_car(x));
    }

    trig = monolith_page_data_get(pg);

    trig_vm_goto(&trig->tvm, pos - 1);

    return S9_UNSPECIFIC;
}

11.4. TODO Set Cell

Sets the cell at a particular position, both the command word and data word. Setting both to 0 clears the cell.

11.5. TODO Cell Bit Toggle

Toggles the bit of a cell in the VM. Addressed via the word (0cmd, 1dat), and the local bit position.

11.6. TODO Cell Bit Set

Sets the bit of a cell in the VM. Toggles the bit of a cell in the VM. Addressed via the word (0cmd, 1dat), and the local bit position.

11.7. Reset

Sends a signal to Trig to reset on the position on the next clock.

<<trig_scheme_entries>>=
{
    "monolith:trig-reset",
    pp_trig_reset, 1, 1,
    {S9_T_STRING, S9_T_ANY, S9_T_ANY}
},
<<trig_scheme_functions>>=
static s9_cell pp_trig_reset(s9_cell x)
{
    const char *str;
    monolith_d *m;
    monolith_dict *dict;
    monolith_page *pg;
    page_trig_d *trig;
    int rc;

    m = monolith_data_get();
    dict = monolith_dict_get(m);

    str = monolith_scheme_string(s9_car(x));

    rc = monolith_dict_lookup(dict, &pg, str, strlen(str));
    if (!rc) {
        return monolith_scheme_error(
            "Could not find trig page",
            s9_car(x));
    }

    trig = monolith_page_data_get(pg);

    trig->please_reset = 1;

    return S9_UNSPECIFIC;
}



prev | home | next