about summary refs log tree commit diff stats
path: root/prototypes/browse/17-file-state-broken/screen-position-state.mu
blob: e5767de87c59b97da5c4eced3741b05a0fe60f62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
type screen-position-state {
  nrows: int  # const
  ncols: int  # const
  toprow: int
  botrow: int
  leftcol: int
  rightcol: int
  row: int
  col: int
}

fn init-screen-position-state self: (addr screen-position-state), nrows: int, ncols: int {
  # hardcoded parameters:
  #   top-margin
  #   page-margin
  #   page-width
  var dest/eax: (addr int) <- copy 0
  # self->nrows = nrows
  # self->ncols = ncols
  # self->toprow = top-margin
  # self->botrow = nrows
  # self->leftcol = page-margin
  # self->rightcol = self->leftcol + page-width
  # start-drawing(self)
}

fn start-drawing self: (addr screen-position-state) {
  # self->row = toprow
  # self->col = leftcol
}

fn add-char self: (addr screen-position-state), c: byte {
  # print c
  # self->col++
  # if (self->col > self->rightcol) next-line(self)
}

fn next-line self: (addr screen-position-state) {
  # self->row++
  # if (self->row > self->botrow) next-page(self)
}

fn next-page self: (addr screen-position-state) {
  # self->leftcol = self->rightcol + 5
  # self->rightcol = self->leftcol + page-width
}

fn done-drawing? self: (addr screen-position-state) -> result/eax: boolean {
  # self->rightcol >= self->ncols
}