mirror of https://github.com/garritfra/ditto-os
garritfra
5 years ago
8 changed files with 91 additions and 31 deletions
@ -0,0 +1,6 @@
|
||||
{ |
||||
"files.associations": { |
||||
"kmain.h": "c", |
||||
"io.h": "c" |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
#include "kmain.h" |
||||
#include "io.h" |
||||
|
||||
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) { |
||||
char *fb = (char *) 0x000B8000; |
||||
fb[i] = c; |
||||
fb[i + 1] = ((fg & 0x0F) << 4) | (bg & 0x0F); |
||||
} |
||||
|
||||
void fb_move_cursor(unsigned short pos) |
||||
{ |
||||
outb(FB_COMMAND_PORT, FB_HIGH_BYTE_COMMAND); |
||||
outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF)); |
||||
outb(FB_COMMAND_PORT, FB_LOW_BYTE_COMMAND); |
||||
outb(FB_DATA_PORT, pos & 0x00FF); |
||||
} |
||||
|
||||
int write(char *buf, unsigned int len) { |
||||
for(int i = 0; i <= (int)len; i++) { |
||||
fb_write_cell((int)(i * 2), buf[i], 0, 15); |
||||
fb_move_cursor(i); |
||||
} |
||||
return 0; |
||||
} |
@ -0,0 +1,36 @@
|
||||
#ifndef INCLUDE_IO_H |
||||
#define INCLUDE_IO_H |
||||
|
||||
/* The I/O ports */ |
||||
#define FB_COMMAND_PORT 0x3D4 |
||||
#define FB_DATA_PORT 0x3D5 |
||||
|
||||
/* The I/O port commands */ |
||||
#define FB_HIGH_BYTE_COMMAND 14 |
||||
#define FB_LOW_BYTE_COMMAND 15 |
||||
|
||||
int write(char *buf, unsigned int len); |
||||
|
||||
void outb(unsigned short port, unsigned char data); |
||||
|
||||
/** fb_write_cell:
|
||||
* Writes a character with the given foreground and background to position i |
||||
* in the framebuffer. |
||||
*
|
||||
* @param i The location in the framebuffer |
||||
* @param c The character |
||||
* @param fg The foreground color |
||||
* @param bg The background color |
||||
* |
||||
* @example fb_write_cell(0, 'A', 2, 8); |
||||
*/ |
||||
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg); |
||||
|
||||
/** fb_move_cursor:
|
||||
* Moves the cursor of the framebuffer to the given position |
||||
* |
||||
* @param pos The new position of the cursor |
||||
*/ |
||||
void fb_move_cursor(unsigned short pos); |
||||
|
||||
#endif /* INCLUDE_IO_H */ |
@ -0,0 +1,11 @@
|
||||
global outb ; make the label outb visible outside this file
|
||||
|
||||
; outb - send a byte to an I/O port
|
||||
; stack: [esp + 8] the data byte
|
||||
; [esp + 4] the I/O port
|
||||
; [esp ] return address
|
||||
outb: |
||||
mov al, [esp + 8] ; move the data to be sent into the al register
|
||||
mov dx, [esp + 4] ; move the address of the I/O port into the dx register
|
||||
out dx, al ; send the data to the I/O port
|
||||
ret ; return to the calling function
|
@ -1,31 +1,11 @@
|
||||
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg); |
||||
|
||||
|
||||
int main() { |
||||
fb_write_cell(0, 'A', 2, 8); |
||||
#include "kmain.h" |
||||
#include "io.h" |
||||
|
||||
int main() |
||||
{ |
||||
fb_write_cell(0, 'A', 0, 15); |
||||
fb_write_cell(2, 'B', 0, 15); |
||||
fb_write_cell(4, 'C', 0, 15); |
||||
fb_move_cursor(6); |
||||
return 0; |
||||
} |
||||
|
||||
/** fb_write_cell:
|
||||
* Writes a character with the given foreground and background to position i |
||||
* in the framebuffer. |
||||
|
||||
*
|
||||
* @param i The location in the framebuffer |
||||
* @param c The character |
||||
* @param fg The foreground color |
||||
* @param bg The background color |
||||
* |
||||
* @example fb_write_cell(0, 'A', 2, 8); |
||||
*/ |
||||
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) { |
||||
char *fb = (char *) 0x000B8000; |
||||
fb[i] = c; |
||||
fb[i + 1] = ((fg & 0x0F) << 4) | (bg & 0x0F); |
||||
} |
||||
|
||||
struct example { |
||||
unsigned char config; /* bit 0 - 7 */ |
||||
unsigned short address; /* bit 8 - 23 */ |
||||
unsigned char index; /* bit 24 - 31 */ |
||||
} __attribute__((packed)); |
||||
} |
Loading…
Reference in new issue