BasicIO Support code for Basic IO phrases.


§1. Line input. Read from the keyboard and store in a text.

[ ReadKeyboardIntoText new_txt;
    ! Read from the keyboard
    VM_ReadKeyboard(buffer2);
    #iftrue WORDSIZE == 2;
        BlkValueMassCopyFromArray(new_txt, buffer2 + 2, 1, buffer2->1);
    #ifnot;
        BlkValueMassCopyFromArray(new_txt, buffer2 + WORDSIZE, 4, buffer2-->0);
    #endif;
    return new_txt;
];

§2. Drawing the Status Window. These functions support drawing the status window.

Status window printing happens on the upper screen window, and outside of the paragraph control system.

[ DrawStatusLine width posb;
    #ifdef TARGET_GLULX;
        if (Status_Window.glk_ref == 0) return;
    #endif;
    @push say__p; @push say__pc;
    VM_MoveCursorInStatusLine(1, 1);
    CarryOutActivity(CONSTRUCTING_STATUS_LINE_ACT);
    VM_MainWindow();
    ClearParagraphing(18);
    @pull say__pc; @pull say__p;
];

[ DRAW_STATUS_WINDOW_R;
    DrawStatusLine();
    rfalse;
];

! A little helper text for getting the length of a value
Array status_window_table_temp_text --> [ CONSTANT_PACKED_TEXT_STORAGE; Print_Status_Window_Entry; ];
Global status_window_table_kov;
Global status_window_table_value;
[ Print_Status_Window_Entry;
    SayKindValuePair(status_window_table_kov, status_window_table_value);
];

[ DrawStatusWindowFromTable tab  chars col_kov_left col_kov_middle col_kov_right col_num_left col_num_middle col_num_right rows row width;
    if (tab == 0) {
        return;
    }
    if (tab-->0 == 0 || tab-->0 > 3) {
        IssueRTP("StatusWindowTableInvalid", "Can't redraw the status window with a table with more than 3 columns.", BasicInformKitRTPs);
        return;
    }
    rows = TableRows(tab);
    VM_StatusLineHeight(rows);
    VM_ClearWindow(Status_Window);
    ! Cache the column details in case we have a lot of rows
    switch (tab-->0) {
        1:
            col_num_middle = 1;
            col_kov_middle = TC_KOV(((tab-->1)-->1) & TB_COLUMN_NUMBER);
        2:
            col_num_left = 1;
            col_kov_left = TC_KOV(((tab-->1)-->1) & TB_COLUMN_NUMBER);
            col_num_right = 2;
            col_kov_right = TC_KOV(((tab-->2)-->1) & TB_COLUMN_NUMBER);
        3:
            col_num_left = 1;
            col_kov_left = TC_KOV(((tab-->1)-->1) & TB_COLUMN_NUMBER);
            col_num_middle = 2;
            col_kov_middle = TC_KOV(((tab-->2)-->1) & TB_COLUMN_NUMBER);
            col_num_right = 3;
            col_kov_right = TC_KOV(((tab-->3)-->1) & TB_COLUMN_NUMBER);
    }
    width = VM_ScreenWidth();
    for (row = 1: row <= rows: row++) {
        if (TableRowIsBlank(tab, row)) {
            continue;
        }
        if (col_num_left) {
            status_window_table_value = (tab-->col_num_left)-->(row + COL_HSIZE);
            if ((status_window_table_value ~= TABLE_NOVALUE) || ~~(CheckTableEntryIsBlank(tab, col_num_left, row))) {
                VM_MoveCursorInStatusLine(row, 2);
                SayKindValuePair(col_kov_left, status_window_table_value);
            }
        }
        if (col_num_right) {
            status_window_table_value = (tab-->col_num_right)-->(row + COL_HSIZE);
            if ((status_window_table_value ~= TABLE_NOVALUE) || ~~(CheckTableEntryIsBlank(tab, col_num_right, row))) {
                status_window_table_kov = col_kov_right;
                chars = TEXT_TY_BlobAccess(status_window_table_temp_text, CHR_BLOB);
                VM_MoveCursorInStatusLine(row, width - chars);
                SayKindValuePair(col_kov_right, status_window_table_value);
            }
        }
        if (col_num_middle) {
            status_window_table_value = (tab-->col_num_middle)-->(row + COL_HSIZE);
            if ((status_window_table_value ~= TABLE_NOVALUE) || ~~(CheckTableEntryIsBlank(tab, col_num_middle, row))) {
                status_window_table_kov = col_kov_middle;
                chars = TEXT_TY_BlobAccess(status_window_table_temp_text, CHR_BLOB);
                VM_MoveCursorInStatusLine(row, ((width - chars) / 2) + 1);
                SayKindValuePair(col_kov_middle, status_window_table_value);
            }
        }
    }
];