Add scrolling function for int
This commit is contained in:
parent
0e37c3d426
commit
ee414bc4aa
@ -2,11 +2,11 @@
|
||||
#include "vga.h"
|
||||
|
||||
// Need GCC > 6
|
||||
__attribute__ ((interrupt))
|
||||
void print_handler(struct interrupt_frame *frame, ulong error_code){
|
||||
__attribute__((interrupt)) void print_handler(struct interrupt_frame *frame, ulong error_code)
|
||||
{
|
||||
|
||||
printStringDetails("EXCEPTION", RED, BLACK, 0, 20);
|
||||
printInt(error_code, RED, BLACK, 11, 20);
|
||||
printStringDetails("EXCEPTION", RED, BLACK, 0, VGA_HEIGHT - 1);
|
||||
printIntDetails(error_code, RED, BLACK, 11, VGA_HEIGHT - 1);
|
||||
(void)frame;
|
||||
(void)error_code;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "interrupt.h"
|
||||
#include "vga.h"
|
||||
#include "io.h"
|
||||
#include "pic.h"
|
||||
#include "irq.h"
|
||||
#include "pic.h"
|
||||
#include "vga.h"
|
||||
|
||||
// Need GCC > 6
|
||||
__attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame)
|
||||
@ -12,8 +12,7 @@ __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame)
|
||||
if (inb(0x60) != c) {
|
||||
c = inb(0x60);
|
||||
if (c > 0) {
|
||||
printChar(c);
|
||||
printChar('\n');
|
||||
printInt(c);
|
||||
}
|
||||
}
|
||||
(void)frame;
|
||||
@ -23,6 +22,6 @@ __attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame)
|
||||
{
|
||||
static int timeCnt = 0;
|
||||
EOIIrq(IRQ_TIMER);
|
||||
printInt(timeCnt++, RED, BLACK, 20, VGA_HEIGHT -1 );
|
||||
printIntDetails(timeCnt++, RED, BLACK, 20, VGA_HEIGHT - 1);
|
||||
(void)frame;
|
||||
}
|
||||
|
2
main.c
2
main.c
@ -31,7 +31,7 @@ void kmain()
|
||||
asm volatile("sti\n");
|
||||
int count = 0;
|
||||
while (1) {
|
||||
printInt(count++, GREEN, BLACK, 0, VGA_HEIGHT - 1);
|
||||
printIntDetails(count++, GREEN, BLACK, 0, VGA_HEIGHT - 1);
|
||||
}
|
||||
printString("exiting\n");
|
||||
}
|
||||
|
28
vga.c
28
vga.c
@ -26,7 +26,26 @@ void clearScreen(uint bgColor)
|
||||
}
|
||||
}
|
||||
|
||||
void printInt(int integer, uint color, uint bgColor, int startX, int startY)
|
||||
void printInt(int integer)
|
||||
{
|
||||
char num[sizeof(int) *
|
||||
3]; // int max is 2^(sizeof(int)*8) which is (2^3)^(sizeof(int)*8/3) =
|
||||
// 8^(sizeof(int)*8/3) ~ 10^(sizeof(int)*8/3)
|
||||
int i = 0, k = 0;
|
||||
if (integer < 0) {
|
||||
printChar('-');
|
||||
}
|
||||
while (integer != 0) {
|
||||
int digit = integer % 10;
|
||||
num[i++] = (digit > 0) ? digit : -digit;
|
||||
integer = integer / 10;
|
||||
}
|
||||
for (k = i - 1; k >= 0; k--) {
|
||||
printChar(num[k] + '0');
|
||||
}
|
||||
}
|
||||
|
||||
void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY)
|
||||
{
|
||||
char num[sizeof(int) *
|
||||
3]; // int max is 2^(sizeof(int)*8) which is (2^3)^(sizeof(int)*8/3) =
|
||||
@ -57,7 +76,8 @@ void vgaScrollUp(void)
|
||||
{
|
||||
long int colorAttr = vgaBgColor << 12;
|
||||
volatile short *vga = (short *)VGA_ADDR;
|
||||
for (int i = 1; i < VGA_HEIGHT - 2; i++) { // last line is status line. Do not scroll it
|
||||
for (int i = 1; i < VGA_HEIGHT - 2;
|
||||
i++) { // last line is status line. Do not scroll it
|
||||
memcpy((void *)&vga[VGA_WIDTH * (i - 1)], (void *)&vga[VGA_WIDTH * i],
|
||||
VGA_WIDTH * sizeof(short));
|
||||
}
|
||||
@ -66,11 +86,11 @@ void vgaScrollUp(void)
|
||||
}
|
||||
}
|
||||
|
||||
void printString(const char *str) {
|
||||
void printString(const char *str)
|
||||
{
|
||||
while (*str) {
|
||||
printChar(*(str++));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void printChar(const char str)
|
||||
|
3
vga.h
3
vga.h
@ -18,7 +18,8 @@
|
||||
|
||||
int initVGA(uint bgColor, uint color);
|
||||
void clearScreen(uint bgColor);
|
||||
void printInt(int integer, uint color, uint bgColor, int startX, int startY);
|
||||
void printInt(int integer);
|
||||
void printIntDetails(int integer, uint color, uint bgColor, int startX, int startY);
|
||||
void printCharDetails(char str, uint color, uint bgColor, int startX, int startY);
|
||||
void printStringDetails(const char *str, uint color, uint bgColor, int startX, int startY);
|
||||
void printString(const char *str);
|
||||
|
Loading…
Reference in New Issue
Block a user