ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: APPS/TASKMGR/TASKMGR.CC

Source reference: APPS/TASKMGR/TASKMGR.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path APPS/TASKMGR/TASKMGR.CC
Lines 166
Bytes 3369
SHA-256 d0db8a395f6db80d19d40354a8932461f92ce7dfc78f6a43f279295c310895bc
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
— No preprocessor include detected.

Detected symbols

Line Symbol
7 task_num
36 main

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

char g_name[64];
char g_num[16];
int g_prev;
int g_sel;
int g_scroll;

void task_num(int value) {
  int i;
  int d;
  int n;
  char tmp[16];
  if (value < 0) {
    value = 0;
  }
  if (value == 0) {
    storeb(g_num, 48);
    storeb(g_num + 1, 0);
    return;
  }
  i = 0;
  while (value > 0) {
    d = value - (value / 10) * 10;
    storeb(tmp + i, 48 + d);
    value = value / 10;
    i = i + 1;
  }
  n = 0;
  while (i > 0) {
    i = i - 1;
    storeb(g_num + n, loadb(tmp + i));
    n = n + 1;
  }
  storeb(g_num + n, 0);
}

void main() {
  int live;
  int n;
  int i;
  int y;
  int mb;
  int my;
  int row;
  int view;
  int max_off;
  int list_h;
  int list_w;
  int k;
  g_prev = 0;
  g_sel = 0;
  g_scroll = 0;
  while (1) {
    live = win_begin(480, 340, "Tasks");
    if (live == 0) {
      return;
    }
    n = app_count();
    text(8, 24, "Heap used/free KB", 0x00504038);
    task_num(sys_heap_used_kb());
    text(180, 24, g_num, 0x001C1814);
    task_num(sys_heap_free_kb());
    text(270, 24, g_num, 0x001C1814);
    text(8, 40, "PMM free pages", 0x00504038);
    task_num(sys_pmm_free_pages());
    text(180, 40, g_num, 0x001C1814);
    text(8, 56, "Frame p50/p95 ms", 0x00504038);
    task_num(sys_frame_p50());
    text(180, 56, g_num, 0x001C1814);
    task_num(sys_frame_p95());
    text(270, 56, g_num, 0x001C1814);
    text(8, 72, "click raise   Close kills", 0x00504038);
    fillrgb(win_w() - 80, 24, 56, 18, 0x00C02828);
    text(win_w() - 70, 27, "Close", 0x00FFFFFF);
    list_w = win_w() - 28;
    list_h = win_h() - 108 - 18;
    view = list_h / 18;
    if (view < 1) {
      view = 1;
    }
    if (g_sel < 0) {
      g_sel = 0;
    }
    if (g_sel >= n) {
      if (n > 0) {
        g_sel = n - 1;
      } else {
        g_sel = 0;
      }
    }
    if (g_sel < g_scroll) {
      g_scroll = g_sel;
    }
    if (g_sel >= g_scroll + view) {
      g_scroll = g_sel - view + 1;
    }
    max_off = n - view;
    if (max_off < 0) {
      max_off = 0;
    }
    g_scroll = win_vscroll(win_w() - 18, 108, list_h, max_off, view, g_scroll);
    i = g_scroll;
    y = 108;
    row = 0;
    while (i < n) {
      if (row >= view) {
        i = n;
      } else {
        if (i == g_sel) {
          fillrgb(6, y, list_w - 4, 16, 0x00406080);
        } else {
          fillrgb(6, y, list_w - 4, 16, 0x00203040);
        }
        if (app_info(i, g_name)) {
          text(10, y + 1, g_name, 0x00FFFFFF);
        }
        y = y + 18;
        row = row + 1;
        i = i + 1;
      }
    }
    k = ev_key();
    while (k) {
      if (k == 7) {
        if (g_sel > 0) {
          g_sel = g_sel - 1;
        }
      }
      if (k == 8) {
        if (g_sel + 1 < n) {
          g_sel = g_sel + 1;
        }
      }
      if (k == 3) {
        app_raise(g_sel);
      }
      k = ev_key();
    }
    if (win_click(win_w() - 80, 24, 56, 18)) {
      if (n > 0) {
        app_kill(g_sel);
      }
    }
    mb = mouse_btn();
    if (mb) {
      if (g_prev == 0) {
        my = mouse_y() - win_oy();
        if (my >= 108) {
          if (my < 108 + list_h) {
            row = (my - 108) / 18;
            i = g_scroll + row;
            if (i >= 0) {
              if (i < n) {
                g_sel = i;
                app_raise(i);
              }
            }
          }
        }
      }
    }
    g_prev = mb;
    win_end();
    wait(1);
  }
}

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-d0db8a395f6db80d Reviewed source: da3df29cb397 Class: generated-source-reference