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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [drivers/] [src/] [vgatext/] [vgatext.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jlechner
/*
2
 * Project: AMBA-Modules for SCARTS
3
 * Author : Martin Luipersbeck
4
 *
5
 * Description: Driver for apbvga module
6
 *
7
 */
8
 
9
#include "vgatext.h"
10
 
11
#define TO_HEX_CHAR(num) ((num) < 10 ? (num) + 0x30 : (num) + 0x37)
12
#define TO_DEC_CHAR(num) ((num) + 0x30)
13
 
14
#define CURSOR_MAX 4079
15
#define CAP_CURSOR(cursor) (cursor) = ((cursor) > CURSOR_MAX ? 0 : (cursor))
16
#define INC_CURSOR(cursor) (cursor) = ((cursor)++; (cursor) > CURSOR_MAX ? 0 : (cursor))
17
 
18
#define GET_HEX_LETTER(value, index, cursor) (TO_HEX_CHAR((((value)>>((index)*4)) & 0x0F)) + ((cursor)<<8))
19
 
20
 
21
void vgatext_initHandle(vgatext_handle_t *h, scarts_addr_t baseAddress)
22
{
23
  h->baseAddress = baseAddress;
24
  h->cursor = 0;
25
 
26
  vgatext_set_fg_color(h, 0, 255, 0);
27
  vgatext_set_bg_color(h, 0, 0, 0);
28
 
29
  vgatext_clear(h);
30
}
31
 
32
void vgatext_releaseHandle(vgatext_handle_t *h)
33
{
34
}
35
 
36
void vgatext_clear(vgatext_handle_t *h)
37
{
38
  uint8_t i, j;
39
  volatile uint32_t *data;
40
 
41
  data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
42
 
43
  while(h->cursor < CURSOR_MAX) {
44
    for(j = 0; j < 80; j++) {
45
      *data = (uint32_t)((h->cursor<<8) + 0x20);
46
      h->cursor++;
47
    }
48
  }
49
  h->cursor = 0;
50
  for(i = 0; i < 36; i++) {
51
    vgatext_newline(h);
52
  }
53
 
54
  h->cursor = 0;
55
}
56
 
57
void vgatext_set_cursor(vgatext_handle_t *h, uint16_t c)
58
{
59
  h->cursor = c;
60
}
61
 
62
void vgatext_newline(vgatext_handle_t *h)
63
{
64
  uint8_t j;
65
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
66
 
67
  h->cursor = h->cursor - h->cursor % 0x50 + 0x50;
68
  for(j = 0; j < 80; j++) {
69
    *data = (uint32_t)((h->cursor<<8) + 0x20);
70
    h->cursor++;
71
  }
72
  h->cursor -= 0x50;
73
  CAP_CURSOR(h->cursor);
74
}
75
 
76
void vgatext_printByteHex(vgatext_handle_t *h, uint8_t value)
77
{
78
  uint8_t out;
79
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
80
 
81
  out = (value>>4) & 0x0F;
82
  *data = (uint32_t)(TO_HEX_CHAR(out)) + (uint32_t)(h->cursor<<8);
83
  h->cursor++;
84
  CAP_CURSOR(h->cursor);
85
 
86
  out = value & 0x0F;
87
  *data = (uint32_t)(TO_HEX_CHAR(out)) + (uint32_t)(h->cursor<<8);
88
  h->cursor++;
89
  CAP_CURSOR(h->cursor);
90
}
91
 
92
void vgatext_printIntHex(vgatext_handle_t *h, uint32_t value)
93
{
94
  uint8_t i;
95
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
96
 
97
  for(i = 0; i < 8; i++) {
98
    *data = GET_HEX_LETTER(value, (7-i), h->cursor);
99
    h->cursor++;
100
    CAP_CURSOR(h->cursor);
101
  }
102
}
103
 
104
void vgatext_printUInt(vgatext_handle_t *h, uint32_t value)
105
{
106
  uint8_t length = 0;
107
  uint8_t chars[10];
108
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
109
 
110
  while(length < 10) {
111
    chars[length] = TO_DEC_CHAR(value % 10);
112
    length++;
113
    value /= 10;
114
    if(value == 0) {
115
      break;
116
    }
117
  }
118
 
119
  while(length > 0) {
120
    *data = chars[length-1] + (h->cursor<<8);
121
    length--;
122
    h->cursor++;
123
    CAP_CURSOR(h->cursor);
124
  }
125
}
126
 
127
void vgatext_print_str(vgatext_handle_t *h, const char* pStr, int length)
128
{
129
  uint8_t i = 0;
130
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
131
  for(i = 0; i < length; i++) {
132
    *data = (uint32_t)(pStr[i]) + (uint32_t)(h->cursor<<8);
133
    h->cursor++;
134
    CAP_CURSOR(h->cursor);
135
  }
136
}
137
 
138
void vgatext_print_char(vgatext_handle_t *h, uint8_t c)
139
{
140
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_DATA);
141
  *data = (uint32_t)(c) + (uint32_t)(h->cursor<<8);
142
  h->cursor++;
143
  CAP_CURSOR(h->cursor);
144
}
145
 
146
void vgatext_set_fg_color(vgatext_handle_t *h, uint8_t r, uint8_t g, uint8_t b)
147
{
148
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_FG_COLOR);
149
  uint32_t color = (r << 16) | (g << 8) | b;
150
  *data = color;
151
}
152
 
153
void vgatext_set_bg_color(vgatext_handle_t *h, uint8_t r, uint8_t g, uint8_t b)
154
{
155
  volatile uint32_t *data = (uint32_t *)(h->baseAddress+VGATEXT_BG_COLOR);
156
  uint32_t color = (r << 16) | (g << 8) | b;
157
  *data = color;
158
}
159
 

powered by: WebSVN 2.1.0

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