-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.c
34 lines (32 loc) · 818 Bytes
/
serial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "io.h"
#include "serial.h"
void serialPrint(char* string) {
for (int i = 0; string[i] != 0; i++) {
while ((in(0x03fd) & 0x20) == 0);
out(0x03f8, string[i]);
}
}
void serialScan(char* buffer) {
int index = 0;
while(1) {
if (in(0x03fd) % 2) {
unsigned char inByte = in(0x03f8);
if (inByte == '\r') {
buffer[index] = 0;
serialPrint("\r\n");
return;
}
else if (inByte == '\b') {
if (index > 0) {
index--;
serialPrint("\b \b");
}
}
else {
buffer[index] = inByte;
out(0x03f8, buffer[index]);
index++;
}
}
}
}