61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
#include <system.h>
|
|
#include "gdt.c"
|
|
#include "idt.c"
|
|
#include "isrs.c"
|
|
#include "irq.c"
|
|
|
|
void system_init()
|
|
{
|
|
// Detect if color/monochrome screen
|
|
char c = (*(volatile unsigned short*)0x410)&0x30;
|
|
if (c==0x30) TextVideoRam = (byte *)0xb0000;
|
|
else TextVideoRam = (byte *)0xb8000;
|
|
|
|
// Reset cursor, use 80x25 text video mode
|
|
current_mode_width = 80;
|
|
current_mode_height = 25;
|
|
cursor_x = cursor_y = 0;
|
|
|
|
// Install GDT, IDT, ISRs and IRQs; Enable interrupts
|
|
gdt_install();
|
|
idt_install();
|
|
isrs_install();
|
|
irq_install();
|
|
RTC_get_time();
|
|
__asm__ __volatile__ ("sti");
|
|
|
|
// Install PIT timer
|
|
timer_ticks = 0;
|
|
timer_phase (100);
|
|
irq_install_handler(0, timer_handler);
|
|
|
|
// Install keyboard (part 1): install IRQ1 and start BAT test
|
|
kb_modifier_status = 0;
|
|
irq_install_handler(1, kb_handler);
|
|
kb_waitin(); outportb(0x60, 0xFF); // Reset kb
|
|
|
|
|
|
// other drivers come here!!;
|
|
|
|
|
|
|
|
// Install keyboard (part 2): BAT test results & set repeat rates
|
|
byte temp;
|
|
do temp = inportb(0x60);
|
|
while (temp!=0xAA && temp!=0xFC);
|
|
// KB failed BAT TEST
|
|
if (temp == 0xFC) puts_font("\nKeyboard error: failed BAT test.", 0x07, 0x0C);
|
|
kb_set_repeat(1, 11);
|
|
|
|
// Install keyboard (part 3): set scancode set 2
|
|
kb_set_scancodeset(2); // Set new scancode set
|
|
|
|
kb_waitin(); outportb(0x64, 0x20); // Get "Command byte"
|
|
do { temp = inportb(0x60);
|
|
} while (temp==0xFA || temp==0xAA);
|
|
|
|
temp &= 0xFF - (1<<6); // Set bit6 to 0: disable conversion
|
|
kb_waitin(); outportb(0x64, 0x60); // Function to write cmd byte
|
|
kb_waitin(); outportb(0x60, temp); // Send it
|
|
memset(kb_array, 0, 16);
|
|
} |