diff --git a/tty/pc-tty/ttypc.c b/tty/pc-tty/ttypc.c index 1d355801..77e5b7a2 100644 --- a/tty/pc-tty/ttypc.c +++ b/tty/pc-tty/ttypc.c @@ -169,7 +169,7 @@ int main(void) * in the graphic mode already and the text mode buffer may contain garbage */ /* Set default cursor color */ - _ttypc_vga_set(ttypc_common.vt, ttypc_common.vt->vram + ttypc_common.vt->cpos, FG_LIGHTGREY << 8, ttypc_common.vt->rows * ttypc_common.vt->cols - ttypc_common.vt->cpos); + _ttypc_vga_set(ttypc_common.vt, ttypc_common.vt->cpos, FG_LIGHTGREY << 8, ttypc_common.vt->rows * ttypc_common.vt->cols - ttypc_common.vt->cpos); /* Run pool threads */ if ((err = beginthread(ttypc_poolthr, 1, ttypc_common.pstack, sizeof(ttypc_common.pstack), &ttypc_common)) < 0) diff --git a/tty/pc-tty/ttypc_vga.c b/tty/pc-tty/ttypc_vga.c index ba56ce10..f95e9f49 100644 --- a/tty/pc-tty/ttypc_vga.c +++ b/tty/pc-tty/ttypc_vga.c @@ -61,9 +61,10 @@ static void _ttypc_vga_setctype(ttypc_t *ttypc, uint8_t from, uint8_t to) } -ssize_t _ttypc_vga_read(volatile uint16_t *vga, uint16_t *buff, size_t n) +ssize_t _ttypc_vga_read(ttypc_vt_t *vt, size_t offs, uint16_t *buff, size_t n) { size_t i; + volatile uint16_t *vga = vt->vram + offs; for (i = 0; i < n; i++) *(buff + i) = *(vga + i); @@ -72,10 +73,11 @@ ssize_t _ttypc_vga_read(volatile uint16_t *vga, uint16_t *buff, size_t n) } -ssize_t _ttypc_vga_write(ttypc_vt_t *vt, volatile uint16_t *vga, uint16_t *buff, size_t n) +ssize_t _ttypc_vga_write(ttypc_vt_t *vt, size_t offs, uint16_t *buff, size_t n) { size_t i; int pos, col, row; + volatile uint16_t *vga = vt->vram + offs; pos = vga - vt->vram; col = pos % vt->cols; @@ -98,10 +100,11 @@ ssize_t _ttypc_vga_write(ttypc_vt_t *vt, volatile uint16_t *vga, uint16_t *buff, } -volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, volatile uint16_t *vga, uint16_t val, size_t n) +volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, size_t offs, uint16_t val, size_t n) { size_t i; int pos, col, row; + volatile uint16_t *vga = vt->vram + offs; pos = vga - vt->vram; col = pos % vt->cols; @@ -124,10 +127,11 @@ volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, volatile uint16_t *vga, uint16 } -volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, volatile uint16_t *dvga, volatile uint16_t *svga, size_t n) +volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, size_t doffs, size_t soffs, size_t n) { size_t i; int pos, col, row; + volatile uint16_t *dvga = vt->vram + doffs, *svga = vt->vram + soffs; if (dvga < svga) { pos = dvga - vt->vram; @@ -181,7 +185,7 @@ void _ttypc_vga_switch(ttypc_vt_t *vt) return; /* VGA memory -> VT memory */ - _ttypc_vga_read(cvt->vram, cvt->mem, cvt->rows * cvt->cols); + _ttypc_vga_read(cvt, 0, cvt->mem, cvt->rows * cvt->cols); cvt->vram = cvt->mem; /* Set active VT, do it before writes to unlock access to the fb */ @@ -195,7 +199,7 @@ void _ttypc_vga_switch(ttypc_vt_t *vt) mutexLock(vt->lock); /* VT memory -> VGA memory */ vt->vram = ttypc->vga; - _ttypc_vga_write(vt, vt->vram, vt->mem, vt->rows * vt->cols); + _ttypc_vga_write(vt, 0, vt->mem, vt->rows * vt->cols); /* Set cursor position... */ _ttypc_vga_setcursor(vt); /* ... and visibility */ @@ -232,12 +236,12 @@ void _ttypc_vga_rollup(ttypc_vt_t *vt, unsigned int n) /* Update scrollback buffer */ _ttypc_vga_allocscrollback(vt, k); - _ttypc_vga_read(vt->vram + (vt->top + n - k) * vt->cols, vt->scrb + (vt->scrbsz - k) * vt->cols, k * vt->cols); + _ttypc_vga_read(vt, (vt->top + n - k) * vt->cols, vt->scrb + (vt->scrbsz - k) * vt->cols, k * vt->cols); /* Roll up */ if (n < vt->bottom - vt->top) { - _ttypc_vga_move(vt, vt->vram + vt->top * vt->cols, vt->vram + (vt->top + n) * vt->cols, (vt->bottom - vt->top + 1 - n) * vt->cols); - _ttypc_vga_set(vt, vt->vram + (vt->bottom + 1 - n) * vt->cols, vt->attr | ' ', n * vt->cols); + _ttypc_vga_move(vt, vt->top * vt->cols, (vt->top + n) * vt->cols, (vt->bottom - vt->top + 1 - n) * vt->cols); + _ttypc_vga_set(vt, (vt->bottom + 1 - n) * vt->cols, vt->attr | ' ', n * vt->cols); } } @@ -250,9 +254,9 @@ void _ttypc_vga_rolldown(ttypc_vt_t *vt, unsigned int n) if (vt->bottom > vt->crow) { k = min(n, vt->bottom - vt->crow); l = min(k, vt->scrbsz); - _ttypc_vga_move(vt, vt->vram + (vt->top + k) * vt->cols, vt->vram + vt->top * vt->cols, (vt->bottom - vt->top + 1 - k) * vt->cols); - _ttypc_vga_set(vt, vt->vram + vt->top * vt->cols, vt->attr | ' ', (k - l) * vt->cols); - _ttypc_vga_write(vt, vt->vram + (vt->top + k - l) * vt->cols, vt->scrb + (vt->scrbsz - l) * vt->cols, l * vt->cols); + _ttypc_vga_move(vt, (vt->top + k) * vt->cols, vt->top * vt->cols, (vt->bottom - vt->top + 1 - k) * vt->cols); + _ttypc_vga_set(vt, vt->top * vt->cols, vt->attr | ' ', (k - l) * vt->cols); + _ttypc_vga_write(vt, (vt->top + k - l) * vt->cols, vt->scrb + (vt->scrbsz - l) * vt->cols, l * vt->cols); vt->scrbsz -= l; } } @@ -274,15 +278,15 @@ void _ttypc_vga_scroll(ttypc_vt_t *vt, int n) /* Save scroll origin */ if (!vt->scrbpos) - _ttypc_vga_read(vt->vram, vt->scro, vt->rows * vt->cols); + _ttypc_vga_read(vt, 0, vt->scro, vt->rows * vt->cols); /* Copy scrollback */ vt->scrbpos += n; - _ttypc_vga_write(vt, vt->vram, vt->scrb + (vt->scrbsz - vt->scrbpos) * vt->cols, min(vt->scrbpos, vt->rows) * vt->cols); + _ttypc_vga_write(vt, 0, vt->scrb + (vt->scrbsz - vt->scrbpos) * vt->cols, min(vt->scrbpos, vt->rows) * vt->cols); /* Copy scroll origin */ if (vt->scrbpos < vt->rows) { - _ttypc_vga_write(vt, vt->vram + vt->scrbpos * vt->cols, vt->scro, (vt->rows - vt->scrbpos) * vt->cols); + _ttypc_vga_write(vt, vt->scrbpos * vt->cols, vt->scro, (vt->rows - vt->scrbpos) * vt->cols); if ((vt == vt->ttypc->vt) && vt->cst) { /* Show cursor */ @@ -303,7 +307,7 @@ void _ttypc_vga_scrollcancel(ttypc_vt_t *vt) return; /* Restore scroll origin */ - _ttypc_vga_write(vt, vt->vram, vt->scro, vt->rows * vt->cols); + _ttypc_vga_write(vt, 0, vt->scro, vt->rows * vt->cols); /* Restore cursor position... */ vt->cpos -= vt->scrbpos * vt->cols; diff --git a/tty/pc-tty/ttypc_vga.h b/tty/pc-tty/ttypc_vga.h index d8cbb5e2..52a1e0bb 100644 --- a/tty/pc-tty/ttypc_vga.h +++ b/tty/pc-tty/ttypc_vga.h @@ -159,19 +159,19 @@ enum { /* clang-format off */ /* Copies VGA screen buffer to buff */ -extern ssize_t _ttypc_vga_read(volatile uint16_t *vga, uint16_t *buff, size_t n); +extern ssize_t _ttypc_vga_read(ttypc_vt_t *vt, size_t offs, uint16_t *buff, size_t n); /* Copies buff to VGA screen buffer */ -extern ssize_t _ttypc_vga_write(ttypc_vt_t* vt, volatile uint16_t *vga, uint16_t *buff, size_t n); +extern ssize_t _ttypc_vga_write(ttypc_vt_t* vt, size_t offs, uint16_t *buff, size_t n); /* Sets VGA screen buffer characters to val */ -extern volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, volatile uint16_t *vga, uint16_t val, size_t n); +extern volatile uint16_t *_ttypc_vga_set(ttypc_vt_t *vt, size_t offs, uint16_t val, size_t n); /* Moves VGA screen memory */ -extern volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, volatile uint16_t *dvga, volatile uint16_t *svga, size_t n); +extern volatile uint16_t *_ttypc_vga_move(ttypc_vt_t *vt, size_t doffs, size_t soffs, size_t n); /* Switches to another VT */ diff --git a/tty/pc-tty/ttypc_vt.c b/tty/pc-tty/ttypc_vt.c index d87ac0bf..a00a5be6 100644 --- a/tty/pc-tty/ttypc_vt.c +++ b/tty/pc-tty/ttypc_vt.c @@ -154,7 +154,7 @@ static void _ttypc_vt_sput(ttypc_vt_t *vt, char c) case ESC_INIT: /* InseRt Mode */ if (vt->irm) - _ttypc_vga_move(vt, vt->vram + vt->cpos + 1, vt->vram + vt->cpos, vt->cols - vt->ccol - 1); + _ttypc_vga_move(vt, vt->cpos + 1, vt->cpos, vt->cols - vt->ccol - 1); _ttypc_vt_sdraw(vt, c); @@ -785,7 +785,7 @@ int ttypc_vt_init(ttypc_t *ttypc, unsigned int ttybuffsz, ttypc_vt_t *vt) _ttypc_vtf_str(vt); /* Clear screen */ - _ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cols * vt->rows); + _ttypc_vga_set(vt, 0, vt->attr | ' ', vt->cols * vt->rows); return EOK; } diff --git a/tty/pc-tty/ttypc_vtf.c b/tty/pc-tty/ttypc_vtf.c index 7699554a..68b6baf2 100644 --- a/tty/pc-tty/ttypc_vtf.c +++ b/tty/pc-tty/ttypc_vtf.c @@ -294,7 +294,7 @@ void _ttypc_vtf_aln(ttypc_vt_t *vt) vt->cpos = 0; vt->ccol = 0; vt->crow = 0; - _ttypc_vga_set(vt, vt->vram, vt->attr | 'E', vt->rows * vt->cols); + _ttypc_vga_set(vt, 0, vt->attr | 'E', vt->rows * vt->cols); } @@ -382,15 +382,15 @@ void _ttypc_vtf_clreos(ttypc_vt_t *vt) { switch (vt->parms[0]) { case 0: - _ttypc_vga_set(vt, vt->vram + vt->cpos, vt->attr | ' ', vt->cols * vt->rows - vt->cpos); + _ttypc_vga_set(vt, vt->cpos, vt->attr | ' ', vt->cols * vt->rows - vt->cpos); break; case 1: - _ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cpos + 1); + _ttypc_vga_set(vt, 0, vt->attr | ' ', vt->cpos + 1); break; case 2: - _ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cols * vt->rows); + _ttypc_vga_set(vt, 0, vt->attr | ' ', vt->cols * vt->rows); break; } } @@ -400,15 +400,15 @@ void _ttypc_vtf_clreol(ttypc_vt_t *vt) { switch (vt->parms[0]) { case 0: - _ttypc_vga_set(vt, vt->vram + vt->cpos, vt->attr | ' ', vt->cols - vt->ccol); + _ttypc_vga_set(vt, vt->cpos, vt->attr | ' ', vt->cols - vt->ccol); break; case 1: - _ttypc_vga_set(vt, vt->vram + vt->cpos - vt->ccol, vt->attr | ' ', vt->ccol + 1); + _ttypc_vga_set(vt, vt->cpos - vt->ccol, vt->attr | ' ', vt->ccol + 1); break; case 2: - _ttypc_vga_set(vt, vt->vram + vt->cpos - vt->ccol, vt->attr | ' ', vt->cols); + _ttypc_vga_set(vt, vt->cpos - vt->ccol, vt->attr | ' ', vt->cols); break; } } @@ -454,8 +454,8 @@ void _ttypc_vtf_il(ttypc_vt_t *vt) _ttypc_vga_rolldown(vt, p); } else { - _ttypc_vga_move(vt, vt->vram + vt->cpos + p * vt->cols, vt->vram + vt->cpos, (vt->bottom - vt->crow + 1 - p) * vt->cols); - _ttypc_vga_set(vt, vt->vram + vt->cpos, vt->attr | ' ', p * vt->cols); + _ttypc_vga_move(vt, vt->cpos + p * vt->cols, vt->cpos, (vt->bottom - vt->crow + 1 - p) * vt->cols); + _ttypc_vga_set(vt, vt->cpos, vt->attr | ' ', p * vt->cols); } } } @@ -470,8 +470,8 @@ void _ttypc_vtf_ic(ttypc_vt_t *vt) else if (p > vt->cols - vt->ccol) p = vt->cols - vt->ccol; - _ttypc_vga_move(vt, vt->vram + vt->cpos + p, vt->vram + vt->cpos, vt->cols - vt->ccol - p); - _ttypc_vga_set(vt, vt->vram + vt->cpos, vt->attr | ' ', p); + _ttypc_vga_move(vt, vt->cpos + p, vt->cpos, vt->cols - vt->ccol - p); + _ttypc_vga_set(vt, vt->cpos, vt->attr | ' ', p); } @@ -492,8 +492,8 @@ void _ttypc_vtf_dl(ttypc_vt_t *vt) _ttypc_vga_rollup(vt, p); } else { - _ttypc_vga_move(vt, vt->vram + vt->cpos, vt->vram + vt->cpos + p * vt->cols, (vt->bottom - vt->crow + 1 - p) * vt->cols); - _ttypc_vga_set(vt, vt->vram + (vt->bottom + 1 - p) * vt->cols, vt->attr | ' ', p * vt->cols); + _ttypc_vga_move(vt, vt->cpos, vt->cpos + p * vt->cols, (vt->bottom - vt->crow + 1 - p) * vt->cols); + _ttypc_vga_set(vt, (vt->bottom + 1 - p) * vt->cols, vt->attr | ' ', p * vt->cols); } } } @@ -508,8 +508,8 @@ void _ttypc_vtf_dch(ttypc_vt_t *vt) else if (p > vt->cols - vt->ccol) p = vt->cols - vt->ccol; - _ttypc_vga_move(vt, vt->vram + vt->cpos, vt->vram + vt->cpos + p, vt->cols - vt->ccol - p); - _ttypc_vga_set(vt, vt->vram + vt->cpos + vt->cols - p, vt->attr | ' ', p); + _ttypc_vga_move(vt, vt->cpos, vt->cpos + p, vt->cols - vt->ccol - p); + _ttypc_vga_set(vt, vt->cpos + vt->cols - p, vt->attr | ' ', p); } @@ -569,7 +569,7 @@ void _ttypc_vtf_ris(ttypc_vt_t *vt) vt->scrbpos = 0; /* Clear screen */ - _ttypc_vga_set(vt, vt->vram, vt->attr | ' ', vt->cols * vt->rows); + _ttypc_vga_set(vt, 0, vt->attr | ' ', vt->cols * vt->rows); /* Soft reset */ _ttypc_vtf_str(vt); } @@ -585,7 +585,7 @@ void _ttypc_vtf_ech(ttypc_vt_t *vt) else if (p > vt->cols - vt->ccol) p = vt->cols - vt->ccol; - _ttypc_vga_set(vt, vt->vram + vt->cpos, vt->attr | ' ', p); + _ttypc_vga_set(vt, vt->cpos, vt->attr | ' ', p); }