escaped percents in printf
This commit is contained in:
parent
5c32c17474
commit
2312b6fbc1
20
serial.c
20
serial.c
@ -43,41 +43,31 @@ u64 serial_write(const char* buffer, const u64 size) {
|
||||
/*
|
||||
* Writes a given buffer to the com1 serial port for debugging in bochs
|
||||
*/
|
||||
u64 idx = 0;
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 1, 0x00);
|
||||
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
|
||||
0x00);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 3, 0x80);
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_LINE_ENABLE);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 0, 0x03);
|
||||
// quarter speed hopefully the fifo quue wont fill this way
|
||||
serialport_write_byte(SERIAL_COM1_BASE,
|
||||
SERIAL_DEFAULT_LINE_CFG);
|
||||
0x01);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 1, 0x00);
|
||||
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
|
||||
0x00);
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 3, 0x03);
|
||||
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_DEFAULT_LINE_CFG);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 2, 0xC7);
|
||||
serialport_write_byte(SERIAL_FIFO_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_DEFAULT_BUFFER_CFG);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 4, 0x0B);
|
||||
serialport_write_byte(SERIAL_MODEM_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
0x0B);
|
||||
|
||||
for(idx = 0; idx < size; idx++) {
|
||||
u64 idx;
|
||||
for(idx =0; idx < size; idx++) {
|
||||
serialport_write_byte(SERIAL_COM1_BASE, buffer[idx]);
|
||||
/*
|
||||
if(serial_fifo_empty(SERIAL_COM1_BASE == 0x02)) {
|
||||
serialport_write_byte(SERIAL_COM1_BASE, buffer[idx]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
19
stlio.c
19
stlio.c
@ -1,5 +1,8 @@
|
||||
#include "stlio.h"
|
||||
|
||||
static u8 COLOR_FG = Green;
|
||||
static u8 COLOR_BG = White;
|
||||
|
||||
// We are assuming null-terminated strings here
|
||||
u64 strlen(char* buffer) {
|
||||
char* c;
|
||||
@ -7,7 +10,7 @@ u64 strlen(char* buffer) {
|
||||
return (u64)(c - buffer);
|
||||
}
|
||||
void putch(const char c) {
|
||||
write_cell_fb(c, Green, White);
|
||||
write_cell_fb(c, COLOR_FG, COLOR_BG);
|
||||
}
|
||||
|
||||
u64 write(const char* buffer, const u64 size) {
|
||||
@ -19,7 +22,7 @@ u64 write(const char* buffer, const u64 size) {
|
||||
//write(_line, sizeof(_line));
|
||||
}
|
||||
else {
|
||||
write_cell_fb(buffer[i], Green, White);
|
||||
write_cell_fb(buffer[i], COLOR_FG, COLOR_BG);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
@ -32,13 +35,23 @@ u64 read(const u64 n) {
|
||||
|
||||
void printf(char* fmt) {
|
||||
u64 i;
|
||||
for(i = 0; i < strlen(fmt);i++) {
|
||||
u64 size = strlen(fmt);
|
||||
for(i = 0; i < size;i++) {
|
||||
char c = fmt[i];
|
||||
switch(c) {
|
||||
case '\n': {
|
||||
frame_buffer_newline();
|
||||
break;
|
||||
}
|
||||
case '%': {
|
||||
/* only do something if the situation calls for it
|
||||
* NOTE: this call might not do anything interesting
|
||||
*/
|
||||
if((i+1) < size) {
|
||||
write_cell_fb(fmt[c], COLOR_FG, COLOR_BG);
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
default: {
|
||||
putch(c);
|
||||
}
|
||||
|
1
stlio.h
1
stlio.h
@ -5,4 +5,5 @@
|
||||
u64 strlen(char*);
|
||||
u64 write(const char*, const u64);
|
||||
u64 read(const u64);
|
||||
static void __printf_percent(const char c);
|
||||
void printf(char*);
|
||||
|
8
tests.c
8
tests.c
@ -5,10 +5,12 @@
|
||||
|
||||
void test_write() {
|
||||
clear_fb();
|
||||
char* msg1 = "Writing this to fbout\nOh yea and serial 0x3f8";
|
||||
char* msg1 = "Writing this to fbout\n";
|
||||
char* serial1 = "0123456789abcdef0123456789abcdef";
|
||||
char* msg2 = "serial write has finished";
|
||||
|
||||
printf(msg1);
|
||||
serial_write(msg1, strlen(msg1));
|
||||
char* msg2 = "\nserial write has finished";
|
||||
serial_write(serial1, strlen(serial1));
|
||||
printf(msg2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user