disable debug
[AROS.git] / rom / devs / console / charmap.c
bloba1ed931b595eaf70b93d5df1849274793dde310a
1 /*
2 Copyright © 2010-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Code for CONU_CHARMAP console units.
6 Lang: english
7 */
9 #include "charmap.h"
10 #include <proto/exec.h>
11 #include <string.h>
13 struct charmap_line *charmap_dispose_line(struct charmap_line *line)
15 struct charmap_line *next = NULL;
16 if (line)
18 next = line->next;
19 if (line->size)
21 if (line->text)
22 FreeMem(line->text, line->size);
23 if (line->fgpen)
24 FreeMem(line->fgpen, line->size);
25 if (line->bgpen)
26 FreeMem(line->bgpen, line->size);
28 FreeMem(line, sizeof(struct charmap_line));
30 return next;
33 VOID charmap_dispose_lines(struct charmap_line *line)
35 while ((line = charmap_dispose_line(line)));
38 struct charmap_line *charmap_newline(struct charmap_line *next,
39 struct charmap_line *prev)
41 struct charmap_line *newline =
42 (struct charmap_line *)AllocMem(sizeof(struct charmap_line),
43 MEMF_ANY);
44 newline->next = next;
45 newline->prev = prev;
46 if (next)
47 next->prev = newline;
48 if (prev)
49 prev->next = newline;
50 newline->text = 0;
51 newline->fgpen = 0;
52 newline->bgpen = 0;
53 newline->flags = 0;
54 newline->size = 0;
55 return newline;
59 // FIXME: **much** faster if add capacity to charmap_line and allocate
60 // a few characters at a time
61 VOID charmap_resize(struct charmap_line *line, ULONG newsize)
63 char *text = line->text;
64 BYTE *fgpen = line->fgpen;
65 BYTE *bgpen = line->bgpen;
66 BYTE *flags = line->flags;
67 ULONG size = line->size;
69 if (newsize)
71 line->text = (char *)AllocMem(newsize, MEMF_ANY);
72 if (line->text)
73 memset(line->text, 0, newsize);
74 line->fgpen = (BYTE *) AllocMem(newsize, MEMF_ANY);
75 if (line->fgpen)
76 memset(line->fgpen, 0, newsize);
77 line->bgpen = (BYTE *) AllocMem(newsize, MEMF_ANY);
78 if (line->bgpen)
79 memset(line->bgpen, 0, newsize);
80 line->flags = (BYTE *) AllocMem(newsize, MEMF_ANY);
81 if (line->flags)
82 memset(line->flags, 0, newsize);
83 line->size = newsize;
85 else
87 line->text = 0;
88 line->fgpen = 0;
89 line->bgpen = 0;
90 line->flags = 0;
91 line->size = 0;
94 if (text && line->text)
95 memcpy(line->text, text, size);
96 if (fgpen && line->fgpen)
97 memcpy(line->fgpen, fgpen, size);
98 if (bgpen && line->bgpen)
99 memcpy(line->bgpen, bgpen, size);
100 if (flags && line->flags)
101 memcpy(line->flags, flags, size);
103 if (text)
104 FreeMem(text, size);
105 if (fgpen)
106 FreeMem(fgpen, size);
107 if (bgpen)
108 FreeMem(bgpen, size);
109 if (flags)
110 FreeMem(flags, size);