Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "console.h"
26
#include "lcdconsole.h"
27
#include "format.h"
28
#include <stdio.h>
29
#include <stdarg.h>
30
#include <stdbool.h>
31
#include <limits.h>
32
 
33
 
34
struct for_cprintf
35
{
36
    unsigned int consoles;
37
    size_t bytes;
38
};
39
 
40
 
41
static int cprfunc(void* ptr, unsigned char letter)
42
{
43
    struct for_cprintf* pr = (struct for_cprintf*)ptr;
44
    cputc(pr->consoles, letter);
45
    pr->bytes++;
46
    return true;
47
}
48
 
49
int cprintf(unsigned int consoles, const char* fmt, ...)
50
{
51
    va_list ap;
52
    struct for_cprintf pr;
53
 
54
    pr.consoles = consoles;
55
    pr.bytes = 0;
56
 
57
    va_start(ap, fmt);
58
    format(cprfunc, &pr, fmt, ap);
59
    va_end(ap);
60
 
61
    return pr.bytes;
62
}
63
 
64
int cvprintf(unsigned int consoles, const char* fmt, va_list ap)
65
{
66
    struct for_cprintf pr;
67
 
68
    pr.consoles = consoles;
69
    pr.bytes = 0;
70
 
71
    format(cprfunc, &pr, fmt, ap);
72
 
73
    return pr.bytes;
74
}
75
 
76
void cputc(unsigned int consoles, char string)
77
{
78
  if (consoles & 1) lcdconsole_putc(string, 0, -1);
79
}
80
 
81
void cputs(unsigned int consoles, const char* string)
82
{
83
  if (consoles & 1) lcdconsole_puts(string, 0, -1);
84
}
85
 
86
void cflush(unsigned int consoles)
87
{
88
  if (consoles & 1) lcdconsole_update();
89
}