OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable/] [mp3/] [sw/] [console-xess/] [screen.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 268 lampret
#include <stdio.h>
2
#include "screen.h"
3
 
4
unsigned long fg_color = COLOR_WHITE;
5
unsigned long bg_color = COLOR_BLACK;
6
int cx = 0;
7
int cy = 0;
8
 
9
extern unsigned char font[256][12];
10
static char screen[CHARSY][CHARSX];
11
 
12
void put_char_xy (int x, int y, char c) {
13
  int i, j;
14
  screen[y][x] = c;
15
  x *= CHAR_WIDTH;
16
  y *= CHAR_HEIGHT;
17
  for (i = 0; i < CHAR_HEIGHT; i++) {
18
    int t = font[(unsigned char)c][i];
19
    for (j = 0; j < CHAR_WIDTH; j++) {
20
      if (t & 1)
21
        PUT_PIXEL(x + j, y + i, fg_color);
22
      else
23
        PUT_PIXEL(x + j, y + i, bg_color);
24
       t >>= 1;
25
    }
26
  }
27
}
28
 
29
static void scroll() {
30
  int x,y;
31
  for (y = 1; y < CHARSY; y++)
32
    for (x = 0; x < CHARSX; x++)
33
      put_char_xy (x, y-1, screen[y][x]);
34
  for (x = 0; x < CHARSX; x++)
35
    put_char_xy (x, CHARSY-1, ' ');
36
  cy--;
37
}
38
 
39
void put_char(char c) {
40
  int t;
41
  switch (c) {
42
  case '\n':
43
    cy++;
44
    cx = 0;
45
    if (cy >= CHARSY)
46
      scroll();
47
    break;
48
  case '\r':
49
    cx = 0;
50
    break;
51
  case '\t':
52
    for (t = 0; t < 8 - cx & 7; t++)
53
      put_char(' ');
54
    break;
55
  default:
56
    cx++;
57
    if(cx >= CHARSX) put_char('\n');
58
    put_char_xy(cx, cy, c);
59
    break;
60
  }
61
}
62
 
63
void screen_clear () {
64
  int x, y;
65
  for (y = 0; y < CHARSY; y++)
66
    for (x = 0; x < CHARSX; x++)
67
      put_char_xy (x, y, ' ');
68
  cx = cy = 0;
69
}
70
 
71
void put_string(char *s) {
72
  while (*s) {
73
    put_char (*s);
74
    s++;
75
  }
76
}
77
 
78
void screen_init () {
79
  SET_PALLETE(COLOR_BLACK, 0, 0, 0);
80
  SET_PALLETE(COLOR_WHITE, 255, 255, 255);
81
 
82
  /* Set screen offset */
83
  *((unsigned long *)SCREEN_BUFFER_REG) = SCREEN_BUFFER;
84
 
85
  /* Turn screen on */
86
  *((unsigned long *)SCREEN_REG) = 0x00000001;
87
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.