putpixel, stdint
This commit is contained in:
parent
b63ec4722a
commit
fc9df72d76
39
kernel.c
39
kernel.c
|
@ -1,19 +1,20 @@
|
|||
#include"stdio.h"
|
||||
#include"stdint.h"
|
||||
#include"stdbool.h"
|
||||
|
||||
#define at at8
|
||||
#define at8(x) (*(char*)x)
|
||||
|
||||
unsigned char kbdus[128]={0,27,'1','2','3','4','5','6','7','8','9','0','-','=','\b','\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',0,'a','s','d','f','g','h','j','k','l',';','\'','`',0,'\\','z','x','c','v','b','n','m',',','.','/',0,'*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0};
|
||||
uint8_t kbdus[128]={0,27,'1','2','3','4','5','6','7','8','9','0','-','=','\b','\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',0,'a','s','d','f','g','h','j','k','l',';','\'','`',0,'\\','z','x','c','v','b','n','m',',','.','/',0,'*',0,' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'-',0,0,0,'+',0,0,0,0,0,0,0,0,0,0,0};
|
||||
|
||||
void outb(unsigned short port,unsigned char val)
|
||||
void outb(uint16_t port,uint8_t val)
|
||||
{
|
||||
asm("out %0,%1"::"a"(val),"Nd"(port));
|
||||
}
|
||||
|
||||
unsigned char inb(unsigned short port)
|
||||
uint8_t inb(uint16_t port)
|
||||
{
|
||||
unsigned char ret;
|
||||
uint8_t ret;
|
||||
asm("in %1,%0":"=a"(ret):"Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
|
@ -27,38 +28,52 @@ __attribute__ ((naked)) static void halt(void)
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
uint8_t*const vram=(uint8_t*)0xB8000;
|
||||
void putpixel(uint8_t*const screen,int32_t x,int32_t y,int32_t color)
|
||||
{
|
||||
const uint32_t width=320;
|
||||
const uint32_t height=240;
|
||||
uint32_t where=x*width+y*height;
|
||||
screen[where]=color&0xff;
|
||||
screen[where+1]=(color>>8)&0xff;
|
||||
screen[where+2]=(color>>16)&0xff;
|
||||
}
|
||||
|
||||
// Entry point
|
||||
void kernelmain(void*multiboot_structure,unsigned magicnumber)
|
||||
void kernelmain(void*multiboot_structure,uint32_t magicnumber)
|
||||
{
|
||||
|
||||
// Clear text mode buffer
|
||||
for(int i=0;i<1000;++i)
|
||||
((unsigned short*)0xb8000)[i]=0;
|
||||
for(int32_t i=0;i<1000;++i)
|
||||
((uint16_t*)0xb8000)[i]=0;
|
||||
|
||||
puts("");
|
||||
puts("");
|
||||
puts("This is an operating system or something.");
|
||||
|
||||
print("Multiboot structure:");
|
||||
printi16((int)multiboot_structure);
|
||||
printi16((int32_t)multiboot_structure);
|
||||
puts("");
|
||||
|
||||
print("Magic number:");
|
||||
printi16((int)magicnumber);
|
||||
printi16((int32_t)magicnumber);
|
||||
puts("");
|
||||
|
||||
//((char*)0x64)[0]=(unsigned char)0xaa;
|
||||
putpixel(vram,3,3,0x0000ffff);
|
||||
|
||||
//((char*)0x64)[0]=(uint8_t)0xaa;
|
||||
outb(0x64,0xaa);
|
||||
outb(0x64,0xee);
|
||||
|
||||
unsigned int lastchar=0;
|
||||
uint32_t lastchar=0;
|
||||
|
||||
stdout->seek=0;
|
||||
// Check PS/2 status register
|
||||
while(true)
|
||||
{
|
||||
|
||||
unsigned int r=inb(0x60);
|
||||
uint32_t r=inb(0x60);
|
||||
while(!(r&0x80)&&(r!=lastchar))
|
||||
{
|
||||
if(r=='\b')stdout->seek-=2;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
typedef unsigned char bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
|
9
stdint.h
Normal file
9
stdint.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
|
||||
typedef char int8_t;
|
||||
typedef long int32_t;
|
||||
typedef short int16_t;
|
23
stdio.c
23
stdio.c
|
@ -1,6 +1,7 @@
|
|||
#include"stdio.h"
|
||||
#include"stdint.h"
|
||||
|
||||
FILE*stdout=&(FILE){.fd=0,.offset=(unsigned short*)0xb8000,.seek=0};
|
||||
FILE*stdout=&(FILE){.fd=0,.offset=(uint16_t*)0xb8000,.seek=0};
|
||||
|
||||
void fputc(char c,FILE*f)
|
||||
{
|
||||
|
@ -13,7 +14,7 @@ void fputc(char c,FILE*f)
|
|||
// puts to FILE
|
||||
void fputs(FILE*f,char*s)
|
||||
{
|
||||
for(unsigned i=0;s[i];++i)
|
||||
for(uint32_t i=0;s[i];++i)
|
||||
//*f->offset++=0x1f00|s[i];
|
||||
fputc(s[i],f);
|
||||
fputc('\n',f);
|
||||
|
@ -22,15 +23,15 @@ void fputs(FILE*f,char*s)
|
|||
// print to FILE
|
||||
void fprint(FILE*f,char*s)
|
||||
{
|
||||
for(unsigned i=0;s[i];++i)
|
||||
for(uint32_t i=0;s[i];++i)
|
||||
fputc(s[i],f);
|
||||
}
|
||||
|
||||
// print integer
|
||||
void fprinti(FILE*f,int d)
|
||||
void fprinti(FILE*f,int32_t d)
|
||||
{
|
||||
char b[32];
|
||||
int i=0;
|
||||
int32_t i=0;
|
||||
|
||||
if(d<0)
|
||||
{
|
||||
|
@ -41,38 +42,38 @@ void fprinti(FILE*f,int d)
|
|||
// Get each digit as character
|
||||
while(d>0)
|
||||
{
|
||||
int m=d%10;
|
||||
int32_t m=d%10;
|
||||
d/=10;
|
||||
b[i++]=m+'0';
|
||||
}
|
||||
b[i]=0;
|
||||
|
||||
// Print reversed string
|
||||
for(i;i>=0;--i)
|
||||
for(;i>=0;--i)
|
||||
if(b[i]>31)
|
||||
fputc(b[i],f);
|
||||
}
|
||||
|
||||
// print integer (hex)
|
||||
void fprinti16(FILE*f,unsigned int d)
|
||||
void fprinti16(FILE*f,uint32_t d)
|
||||
{
|
||||
static char g[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
||||
static char b[32];
|
||||
int i=0;
|
||||
int32_t i=0;
|
||||
|
||||
fprint(f,"0x");
|
||||
|
||||
// Get each digit as character
|
||||
while(d>0)
|
||||
{
|
||||
unsigned int m=d%16;
|
||||
uint32_t m=d%16;
|
||||
d/=16;
|
||||
b[i++]=g[m];
|
||||
}
|
||||
b[i]=0;
|
||||
|
||||
// Print reversed string
|
||||
for(i;i>=0;--i)
|
||||
for(;i>=0;--i)
|
||||
if(b[i]>31)
|
||||
fputc(b[i],f);
|
||||
}
|
||||
|
|
12
stdio.h
12
stdio.h
|
@ -5,22 +5,24 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include"stdint.h"
|
||||
|
||||
#define SPACE " "
|
||||
#define WIDTH 80
|
||||
|
||||
// FILE type
|
||||
typedef struct FILE
|
||||
{
|
||||
unsigned fd;
|
||||
unsigned short*offset;
|
||||
unsigned int seek;
|
||||
uint32_t fd;
|
||||
uint16_t*offset;
|
||||
uint32_t seek;
|
||||
} FILE;
|
||||
|
||||
extern FILE*stdout;
|
||||
|
||||
void fprint(FILE*f,char*s);
|
||||
void fprinti(FILE*f,int d);
|
||||
void fprinti16(FILE*f,unsigned int d);
|
||||
void fprinti(FILE*f,int32_t d);
|
||||
void fprinti16(FILE*f,uint32_t d);
|
||||
void fputc(char c,FILE*f);
|
||||
void fputs(FILE*f,char*s);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user