Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jayc3-3 authored Aug 5, 2023
1 parent 7450884 commit 8f6d3f5
Show file tree
Hide file tree
Showing 17 changed files with 581 additions and 34 deletions.
14 changes: 13 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CFLAGS = -ffreestanding -Wall -Iinclude
LDFLAGS = -T linker.ld -ffreestanding -nostdlib -lgcc
EMUFLAGS = -net none -drive media=cdrom,format=raw,file=

OBJFILES = boot.o kernel.o framebuffer.o string.o math.o console.o
OBJFILES = boot.o kernel.o framebuffer.o string.o math.o console.o ports.o ps2.o JOSimage.o ps2Keyboard.o
COMPILENAME = JOS-0.0.1

all: iso
Expand Down Expand Up @@ -41,6 +41,18 @@ string.o: code/other/string.c
math.o: code/other/math.c
${CC} -c $< -o $@ ${CFLAGS}

ports.o: code/hardware/ports.c
${CC} -c $< -o $@ ${CFLAGS}

ps2.o: code/hardware/ps2.c
${CC} -c $< -o $@ ${CFLAGS}

JOSimage.o: code/other/JOSimage.c
${CC} -c $< -o $@ ${CFLAGS}

ps2Keyboard.o: code/hardware/ps2Keyboard.c
${CC} -c $< -o $@ ${CFLAGS}

JOS.bin: ${OBJFILES}
${LD} $^ -o ${COMPILENAME}.bin ${LDFLAGS}

Expand Down
2 changes: 1 addition & 1 deletion src/code/boot/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dd 32
section .bss
align 16
stackBottom:
resb 16384
resb 32768
stackTop:

section .text
Expand Down
59 changes: 42 additions & 17 deletions src/code/graphics/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,17 @@ int cWidth;
int cHeight;
int cTextColor;
int cBackColor;
int cTextScale;

void console_init(int framebufferWidth, int framebufferHeight, int textColor, int backgroundColor){
void console_init(int framebufferWidth, int framebufferHeight, int textScale, int textColor, int backgroundColor){
cWidth = (int)math_floor((double)framebufferWidth / 16.0) - 1;
cHeight = (int)math_floor((double)framebufferHeight / 16.0) - 1;
cTextScale = textScale;
cTextColor = textColor;
cBackColor = backgroundColor;

console_clear();
console_print(" ______ _____\n");
console_print(" / / __ \\/ ___/\n");
console_print(" __ / / / / /\\__ \\ \n");
console_print("/ /_/ / /_/ /___/ /\n");
console_print("\\____/\\____//____/\n");

for(int i = 0; i < cWidth-1; i++){
console_printc('-');
}
console_printc('\n');

console_print("Version 0.0.1\n\n");
console_print("INFO: Successfully initialized console\n");
console_print("INFO: Console width: ");
console_printi(cWidth);
Expand All @@ -43,6 +34,18 @@ void console_clear(void){
cursorX = 1;
cursorY = 1;

console_print(" __ ____ _____\n");
console_print(" / // __ \\/ ___/\n");
console_print(" __ / // / / /\\__ \\ \n");
console_print("/ /_/ // /_/ /___/ / \n");
console_print("\\____/ \\____/ \\___/ \n");
console_print("\nVersion 0.0.1\n");

for(int i = 0; i < cWidth-1; i++){
console_printc('-');
}
console_printc('\n');

return;
}

Expand All @@ -69,20 +72,42 @@ int console_printc(char c){

case '\r':
cursorX = 1;

return 1;

case '\b':
if(cursorX == 1){
if(cursorY < 10)
goto skip;

cursorX = cWidth;
cursorY--;
goto skip;
}
cursorX--;
skip:
fb_drawRect(cursorX*16, cursorY*16, 16, 16, cBackColor);

return 1;

default: break;
}

if(cursorX > cWidth || cursorY > cHeight)
if(c < 31)
return 1;

if(cursorX > cWidth && cursorY < cHeight){
cursorX = 1;
cursorY++;
}

if(cursorY > cHeight)
return 0;

fb_drawRect(cursorX*16, cursorY*16, 16, 16, cBackColor);
fb_drawChar(c, cursorX*16, cursorY*16, cTextColor);
fb_drawChar(c, cursorX*16, cursorY*16, cTextScale, cTextColor);
cursorX++;

if(cursorX > cWidth && cursorY < cHeight)
cursorY++;

return 1;
}

Expand Down
33 changes: 24 additions & 9 deletions src/code/graphics/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

unsigned int* fb_buffer;
int fb_pitch;
int fb_depth;
int fb_width;
int fb_height;

void fb_init(unsigned long long framebufferAddr, int pitch, int colorDepth, int width, int height){
void fb_init(unsigned long long framebufferAddr, int pitch, int width, int height){
fb_buffer = (unsigned int*)((unsigned int)framebufferAddr);
fb_pitch = pitch;
fb_depth = colorDepth;
fb_width = width;
fb_height = height;

Expand Down Expand Up @@ -52,8 +50,8 @@ void fb_drawRect(int x, int y, int w, int h, int color){;
return;
}

void fb_drawChar(char c, int x, int y, int color){
if(x > fb_width || y > fb_height || x+16 > fb_width || y+16 > fb_height){
void fb_drawChar(char c, int x, int y, int scale, int color){
if(x+16 > fb_width || y+16 > fb_height){
return;
}

Expand All @@ -62,13 +60,30 @@ void fb_drawChar(char c, int x, int y, int color){
for(int yy = 0; yy < 8; yy++){
for(int xx = 0; xx < 8; xx++){
if(glyph[yy] & (1 << xx)){
fb_putPixel(x+(xx*2), y+(yy*2), color);
fb_putPixel(x+(xx*2), y+(yy*2)+1, color);
fb_putPixel(x+(xx*2)+1, y+(yy*2), color);
fb_putPixel(x+(xx*2)+1, y+(yy*2)+1, color);
for(int xi = 0; xi < scale; xi++){
for(int yi = 0; yi < scale; yi++){
fb_putPixel(x+(xx*scale)+xi, y+(yy*scale)+yi, color);
}
}

}
}
}

return;
}

void fb_drawImage(int x, int y, int w, int h, int scale, int* pixels){
int j;
for (int l = j = 0; l < h; l++){
for (int i = 0; i < w; i++, j++){
for(int xi = 0; xi < scale; xi++){
for(int yi = 0; yi < scale; yi++){
fb_putPixel(x + (i*scale)+xi, y + (l*scale)+yi, pixels[j]);
}
}
}
}

return;
}
23 changes: 23 additions & 0 deletions src/code/hardware/ports.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <ports.h>

void ports_byteOut(unsigned short port, unsigned char data){
asm ("out %%al, %%dx" : : "a" (data), "d"(port));
return;
}

void ports_wordOut(unsigned short port, unsigned short data){
asm ("out %%ax, %%dx" : : "a" (data), "d"(port));
return;
}

unsigned char ports_byteIn(unsigned short port){
unsigned char data;
asm ("in %%dx, %%al" : "=a" (data) : "d"(port));
return data;
}

unsigned short ports_wordIn(unsigned short port){
unsigned char data;
asm ("in %%dx, %%ax" : "=a" (data) : "d"(port));
return data;
}
67 changes: 67 additions & 0 deletions src/code/hardware/ps2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <ports.h>
#include <util.h>
#include <console.h>
#include <ps2.h>

int ps2Port1 = 0;
int ps2Port2 = 0;

unsigned char ps2_readPort(unsigned short port){
char status = ports_byteIn(PS2_STATUS);
while(!CHECK_BIT(status, 0)) {status = ports_byteIn(PS2_STATUS);}
char data = ports_byteIn(port);
return data;
}

void ps2_sendPort(unsigned short port, unsigned char data){
char status = ports_byteIn(PS2_STATUS);
while(CHECK_BIT(status, 1)) {status = ports_byteIn(PS2_STATUS);}
ports_byteOut(port, data);
return;
}

int ps2_init(void){
console_print("INFO: Initalizing PS/2 driver\n");

ps2_sendPort(PS2_COMMAND, 0x20);
char configByte = ps2_readPort(PS2_DATA);

configByte &= ~(1 << 0);
configByte &= ~(1 << 1);
configByte &= ~(1 << 6);
if(CHECK_BIT(configByte, 5))
//ps2Port2 = 1;

ps2_sendPort(PS2_COMMAND, 0x60);
ps2_sendPort(PS2_DATA, configByte);

ps2_sendPort(PS2_COMMAND, 0xAD);
ps2_sendPort(PS2_COMMAND, 0xA7);

ports_byteIn(PS2_DATA);

ps2_sendPort(PS2_COMMAND, 0xAA);
if(ps2_readPort(PS2_DATA) != 0x55)
return 0;

ps2_sendPort(PS2_COMMAND, 0xAB);
if(ps2_readPort(PS2_DATA) == 0x00)
ps2Port1 = 1;

ps2_sendPort(PS2_COMMAND, 0xA9);
if(ps2_readPort(PS2_DATA) != 0x00)
ps2Port2 = 0;

if(!ps2Port1)
console_print("WARNING: PS/2 port 1 unavailable for use\n");
else
console_print("INFO: PS/2 port 1 available for use\n");
if(!ps2Port2)
console_print("WARNING: PS/2 port 2 unavailable for use\n");
else
console_print("INFO: PS/2 port 2 available for use\n");

console_print("INFO: PS/2 controller successfully initialized\n");

return 1;
}
Loading

0 comments on commit 8f6d3f5

Please sign in to comment.