Browse Source

Add std

master
garritfra 4 years ago
parent
commit
7e2a7b4412
  1. 2
      Makefile
  2. 4
      bochsrc.txt
  3. 13
      fb.c
  4. 2
      fb.h
  5. 7
      kmain.c
  6. 17
      std.c
  7. 10
      std.h

2
Makefile

@ -1,4 +1,4 @@
OBJECTS = io.o loader.o kmain.o fb.o serial.o
OBJECTS = io.o loader.o kmain.o fb.o serial.o std.o
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c

4
bochsrc.txt

@ -1,5 +1,5 @@
megs: 32
display_library: sdl
display_library: x
romimage: file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
ata0-master: type=cdrom, path=os.iso, status=inserted
@ -7,4 +7,4 @@ boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000
com1: enabled=1, mode=file, dev=com1.out
com1: enabled=1, mode=file, dev=com1.out

13
fb.c

@ -1,4 +1,3 @@
#include "kmain.h"
#include "fb.h"
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) {
@ -15,6 +14,9 @@ void fb_move_cursor(unsigned short pos)
outb(FB_DATA_PORT, pos & 0x00FF);
}
/*
* Write frame buffer to screen
*/
int fb_write(char *buf, unsigned int len) {
for(int i = 0; i <= (int)len; i++) {
@ -24,6 +26,15 @@ int fb_write(char *buf, unsigned int len) {
return 0;
}
/** read_scan_code:
* Reads a scan code from the keyboard
*
* @return The scan code (NOT an ASCII character!)
*/
unsigned char read_scan_code(void) {
return inb(KBD_DATA_PORT);
}
void advance_cursor(void) {
fb_move_cursor(get_cursor_position() + 1);
}

2
fb.h

@ -28,6 +28,8 @@
#define VGA_COLOR_LIGHT_BROWN 14
#define VGA_COLOR_WHITE 15
#define KBD_DATA_PORT 0x60
int fb_write(char *buf, unsigned int len);

7
kmain.c

@ -1,8 +1,9 @@
#include "kmain.h"
#include "fb.h"
#include "std.h"
int main()
{
fb_write("Hello", 4);
printf("Hello");
return 0;
}
}

17
std.c

@ -0,0 +1,17 @@
#include "std.h"
#include "fb.h"
void printf(char *buf) {
fb_write(buf, strlen(buf));
}
void scanf(const char *format);
unsigned int strlen(const char *str) {
const char *s;
for (s = str; *s; ++s)
;
return (s - str);
}

10
std.h

@ -0,0 +1,10 @@
#ifndef INCLUDE_STD
#define INCLUDE_STD
void printf(char *buf);
void scanf(const char *format);
unsigned int strlen(const char *buf);
#endif
Loading…
Cancel
Save