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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [bios/] [serial.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#include "bios.h"
19
#include "bda.h"
20
#include "io.h"
21
 
22
extern void video_putchar(char c);
23
 
24
#define UART_DATA_PORT 0xfffa
25
#define UART_STATUS_PORT 0xfffb
26
#define UART_TX_BUSY 0x02
27
#define UART_RX_READY 0x01
28
 
29
void putchar(unsigned char c)
30
{
31
#ifdef SERIAL_STDIO
32
    outb(UART_DATA_PORT, c);
33
 
34
    while (inb(UART_STATUS_PORT) & UART_TX_BUSY)
35
        continue;
36
#endif // SERIAL_STDIO
37
 
38
    video_putchar(c);
39
 
40
    if (c == '\n')
41
        putchar('\r');
42
}
43
 
44
void serial_putchar(unsigned char c)
45
{
46
    outb(UART_DATA_PORT, c);
47
 
48
    while (inb(UART_STATUS_PORT) & UART_TX_BUSY)
49
        continue;
50
    if (c == '\n')
51
        serial_putchar('\r');
52
}
53
 
54
extern void kbd_buffer_add(unsigned short key);
55
 
56
int serial_poll(void)
57
{
58
    int ready = inb(UART_STATUS_PORT) & UART_RX_READY;
59
 
60
    if (ready)
61
        kbd_buffer_add(inb(UART_DATA_PORT));
62
 
63
    return ready;
64
}
65
 
66
void putbyte(unsigned char b)
67
{
68
    static const char hexarr[] = "0123456789abcdef";
69
 
70
    putchar(hexarr[(b & 0xf0) >> 4]);
71
    putchar(hexarr[b & 0x0f]);
72
}
73
 
74
void putstr(const char *str)
75
{
76
    char p;
77
 
78
    for (p = *str; p != 0; ++str, p = *str)
79
        putchar(p);
80
}

powered by: WebSVN 2.1.0

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