CTAOS v5
This commit is contained in:
@ -1,92 +1,81 @@
|
||||
/***** cmos.c ********************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* CMOS I/O Routines *
|
||||
* ================= *
|
||||
* *
|
||||
* ! IMPORTANT NOTE ! Close interrupts before any CMOS operation *
|
||||
************************************************************ cta os */
|
||||
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
#include "cmos.h"
|
||||
|
||||
volatile byte i86_cmos_data[128];
|
||||
|
||||
void i86_cmos_write ()
|
||||
/*****************************************************************
|
||||
* !!!!!!!!!! IMPORTANT NOTE !!!!!!!!!! *
|
||||
* You should close interrupts before any CMOS operation. *
|
||||
*****************************************************************/
|
||||
inline unsigned char i86_cmos_read (unsigned char address)
|
||||
{
|
||||
byte i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
//asm volatile ("cli");
|
||||
outportb(0x70, i);
|
||||
iowait();
|
||||
outportb(0x71, i86_cmos_data[i]);
|
||||
//asm volatile ("sti");
|
||||
}
|
||||
outportb(0x70, address); iowait();
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
void i86_cmos_read ()
|
||||
inline void i86_cmos_write (unsigned char address, unsigned char val)
|
||||
{
|
||||
byte i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
//asm volatile ("cli");
|
||||
outportb(0x70, i);
|
||||
iowait();
|
||||
i86_cmos_data[i] = inportb(0x71);
|
||||
//asm volatile ("sti");
|
||||
}
|
||||
outportb(0x70, address); iowait();
|
||||
outportb(0x71, val);
|
||||
}
|
||||
|
||||
void i86_cmos_write_clock (const TIME* time)
|
||||
{
|
||||
unsigned char BCD = ((i86_cmos_read(0x0b)&4)==0) ? 1 : 0;
|
||||
unsigned char ampm = ((i86_cmos_read(0x0b)&2)==0) ? 1 : 0;
|
||||
|
||||
i86_cmos_write (0, (BCD) ? (time->second%10) | (time->second/10*16) : time->second); // Seconds
|
||||
i86_cmos_write (2, (BCD) ? (time->minute%10) | (time->minute/10*16) : time->minute); // Minutes
|
||||
|
||||
if (ampm && time->hour > 12) // Hours
|
||||
i86_cmos_write (4, (BCD) ? (((time->hour - 12) % 10) | ((time->hour - 12)/10*16) | 0x80) : (time->hour | 0x80) );
|
||||
|
||||
else if (ampm && time->hour == 0) // Midnight convention: 12 PM = 00:00
|
||||
i86_cmos_write (4, (BCD) ? 0x92 : 0x8C);
|
||||
|
||||
else i86_cmos_write (4, (BCD) ? (time->hour%10) | (time->hour/10*16) : time->hour); // 24h / AM
|
||||
|
||||
i86_cmos_write (6, (BCD) ? (time->weekday%10) | (time->weekday/10*16) : time->weekday); // Weekday
|
||||
i86_cmos_write (7, (BCD) ? (time->day%10) | (time->day/10*16) : time->day); // Day
|
||||
i86_cmos_write (8, (BCD) ? (time->month%10) | (time->month/10*16) : time->month); // Month
|
||||
i86_cmos_write (9, (BCD) ? (time->year%10) | (time->year/10*16) : time->year); // Year
|
||||
i86_cmos_write (0x32, (BCD) ? (time->century%10) | (time->century/10*16) : time->century); // Century
|
||||
}
|
||||
|
||||
void i86_cmos_read_clock(TIME* tim)
|
||||
{
|
||||
i86_cmos_read();
|
||||
unsigned char BCD = ((i86_cmos_read(0x0b)&4)==0) ? 1 : 0;
|
||||
unsigned char am_pm = ((i86_cmos_read(0x0b)&2)==0) ? 1 : 0;
|
||||
|
||||
if ((i86_cmos_data[0x0b]&4)==0) // BCD = true;
|
||||
{
|
||||
tim->seconds = (i86_cmos_data[0x00]%16) + 10*(i86_cmos_data[0x00]/16);
|
||||
tim->minutes = (i86_cmos_data[0x02]%16) + 10*(i86_cmos_data[0x02]/16);
|
||||
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
||||
if (i86_cmos_data[0x04]&80) { // pm
|
||||
tim->hours = ((i86_cmos_data[0x04]-0x80)%16) + 10*((i86_cmos_data[0x04]-0x80)/16);
|
||||
tim->am_pm = 1;
|
||||
}
|
||||
else { // am
|
||||
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
||||
tim->am_pm = 0;
|
||||
}
|
||||
}
|
||||
else { // 24 hours
|
||||
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
||||
if (tim->hours > 12) {
|
||||
tim->am_pm = 1;
|
||||
tim->hours -= 12;
|
||||
}
|
||||
else tim->am_pm = 0;
|
||||
}
|
||||
tim->second = (BCD) ? (i86_cmos_read(0x00)%16) + 10*(i86_cmos_read(0x00)/16): i86_cmos_read(0x00);
|
||||
tim->minute = (BCD) ? (i86_cmos_read(0x02)%16) + 10*(i86_cmos_read(0x02)/16): i86_cmos_read(0x02);
|
||||
|
||||
tim->weekday = (i86_cmos_data[0x06]%16) + 10*(i86_cmos_data[0x06]/16);
|
||||
tim->day = (i86_cmos_data[0x07]%16) + 10*(i86_cmos_data[0x07]/16);
|
||||
tim->month = (i86_cmos_data[0x08]%16) + 10*(i86_cmos_data[0x08]/16);
|
||||
tim->year = (i86_cmos_data[0x09]%16) + 10*(i86_cmos_data[0x09]/16);
|
||||
tim->century = (i86_cmos_data[0x32]%16) + 10*(i86_cmos_data[0x32]/16);
|
||||
}
|
||||
|
||||
else {//BCD = false;
|
||||
tim->seconds = i86_cmos_data[0x00];
|
||||
tim->minutes = i86_cmos_data[0x02];
|
||||
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
||||
if (i86_cmos_data[0x04]&80) { // pm
|
||||
tim->hours = i86_cmos_data[0x04]-0x80;
|
||||
tim->am_pm = 1;
|
||||
}
|
||||
else { // am
|
||||
tim->hours = i86_cmos_data[0x04];
|
||||
tim->am_pm = 0;
|
||||
}
|
||||
}
|
||||
else { // 24 hours
|
||||
tim->hours = i86_cmos_data[0x02];
|
||||
if (tim->hours > 12) {
|
||||
tim->am_pm = 1;
|
||||
tim->hours -= 12;
|
||||
}
|
||||
else tim->am_pm = 0;
|
||||
}
|
||||
tim->weekday = i86_cmos_data[0x06];
|
||||
tim->day = i86_cmos_data[0x07];
|
||||
tim->month = i86_cmos_data[0x08];
|
||||
tim->year = i86_cmos_data[0x09];
|
||||
tim->century = i86_cmos_data[0x32];
|
||||
// Time is PM
|
||||
if (am_pm && i86_cmos_read(0x04)&80) {
|
||||
tim->hour = (BCD) ? ((i86_cmos_read(0x04)-0x80)%16) + 10*((i86_cmos_read(0x04)-0x80)/16): i86_cmos_read(0x04)-0x80;
|
||||
tim->hour += 12;
|
||||
}
|
||||
// 24Hour format, or AM
|
||||
else tim->hour = (BCD) ? (i86_cmos_read(0x04)%16) + 10*(i86_cmos_read(0x04)/16): i86_cmos_read(0x04);
|
||||
|
||||
tim->weekday = (BCD) ? (i86_cmos_read(0x06)%16) + 10*(i86_cmos_read(0x06)/16): i86_cmos_read(0x06);
|
||||
tim->day = (BCD) ? (i86_cmos_read(0x07)%16) + 10*(i86_cmos_read(0x07)/16): i86_cmos_read(0x07);
|
||||
tim->month = (BCD) ? (i86_cmos_read(0x08)%16) + 10*(i86_cmos_read(0x08)/16): i86_cmos_read(0x08);
|
||||
tim->year = (BCD) ? (i86_cmos_read(0x09)%16) + 10*(i86_cmos_read(0x09)/16): i86_cmos_read(0x09);
|
||||
tim->century = (BCD) ? (i86_cmos_read(0x32)%16) + 10*(i86_cmos_read(0x32)/16): i86_cmos_read(0x32);
|
||||
}
|
||||
|
||||
|
||||
unsigned char i86_cmos_read_floppy_drives ()
|
||||
{
|
||||
outportb (0x70, 0x10);
|
||||
return inportb(0x71);
|
||||
}
|
@ -1,10 +1,17 @@
|
||||
/***** cmos.h ********************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. *
|
||||
* *
|
||||
* CMOS I/O Routines *
|
||||
* ================= *
|
||||
* *
|
||||
* ! IMPORTANT NOTE ! Close interrupts before any CMOS operation *
|
||||
************************************************************ cta os */
|
||||
|
||||
#ifndef __CMOS_H
|
||||
#define __CMOS_H
|
||||
|
||||
extern volatile byte i86_cmos_data[128];
|
||||
|
||||
extern void i86_cmos_write ();
|
||||
extern void i86_cmos_read ();
|
||||
extern void i86_cmos_write_clock (const TIME* time);
|
||||
extern void i86_cmos_read_clock (TIME *tim);
|
||||
extern unsigned char i86_cmos_read_floppy_drives ();
|
||||
|
||||
#endif
|
@ -4,8 +4,6 @@
|
||||
#include "../idt/idt.h"
|
||||
#define cpuid(in, a, b, c, d) __asm__("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
|
||||
|
||||
|
||||
|
||||
// initializes cpu resources
|
||||
void i86_cpu_initialize()
|
||||
{
|
||||
@ -21,15 +19,10 @@ void i86_cpu_shutdown()
|
||||
|
||||
char* i86_cpu_get_vender()
|
||||
{
|
||||
static char vender[13];
|
||||
dword unused, arr[3];
|
||||
int i;
|
||||
dword unused;
|
||||
dword static arr[3];
|
||||
|
||||
cpuid(0, unused, arr[0], arr[2], arr[1]);
|
||||
|
||||
for (i=0; i<12; i++)
|
||||
vender[i] = (arr[i/4]>>(i%4*8)) && 0xFF;
|
||||
|
||||
vender[12] = 0;
|
||||
return vender;
|
||||
return (char*) arr;
|
||||
}
|
18
SysCore/hal/dma/compile.bat
Normal file
18
SysCore/hal/dma/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/dma.o dma.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
137
SysCore/hal/dma/dma.c
Normal file
137
SysCore/hal/dma/dma.c
Normal file
@ -0,0 +1,137 @@
|
||||
/***** dma.c *********************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* Direct Memory Access (DMA) Routines *
|
||||
* =================================== *
|
||||
* *
|
||||
************************************************************ cta os */
|
||||
|
||||
#include "dma.h"
|
||||
#include <system.h>
|
||||
|
||||
enum DMA0_IO {
|
||||
DMA0_STATUS_REG = 0x08,
|
||||
DMA0_COMMAND_REG = 0x08,
|
||||
DMA0_REQUEST_REG = 0x09,
|
||||
DMA0_CHANMASK_REG = 0x0a,
|
||||
DMA0_MODE_REG = 0x0b,
|
||||
DMA0_CLEARBYTE_FLIPFLOP_REG = 0x0c,
|
||||
DMA0_TEMP_REG = 0x0d,
|
||||
DMA0_MASTER_CLEAR_REG = 0x0d,
|
||||
DMA0_CLEAR_MASK_REG = 0x0e,
|
||||
DMA0_MASK_REG = 0x0f
|
||||
};
|
||||
|
||||
enum DMA1_IO {
|
||||
DMA1_STATUS_REG = 0xd0,
|
||||
DMA1_COMMAND_REG = 0xd0,
|
||||
DMA1_REQUEST_REG = 0xd2,
|
||||
DMA1_CHANMASK_REG = 0xd4,
|
||||
DMA1_MODE_REG = 0xd6,
|
||||
DMA1_CLEARBYTE_FLIPFLOP_REG = 0xd8,
|
||||
DMA1_INTER_REG = 0xda,
|
||||
DMA1_UNMASK_ALL_REG = 0xdc,
|
||||
DMA1_MASK_REG = 0xde
|
||||
};
|
||||
|
||||
void i86_dma_set_address(unsigned short channel, unsigned char low, unsigned char high)
|
||||
{
|
||||
if (channel > 7) return; // Ignore if channel > 7
|
||||
|
||||
// Calculate port
|
||||
unsigned short port = (channel >= 4) ? 4*(channel - 4) + 0xc0 : 2*channel;
|
||||
|
||||
// Set address
|
||||
outportb (port, low);
|
||||
outportb (port, high);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_set_count (unsigned short channel, unsigned char low, unsigned char high)
|
||||
{
|
||||
if (channel > 7) return; // Ignore if channel > 7
|
||||
|
||||
// Calculate port
|
||||
unsigned short port = (channel >= 4) ? 4*(channel - 4) + 0xc2
|
||||
: (2*channel) + 1;
|
||||
|
||||
// Set count
|
||||
outportb (port, low);
|
||||
outportb (port, high);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_set_external_page_registers (unsigned char channel, unsigned char val)
|
||||
{
|
||||
unsigned short port = 0;
|
||||
|
||||
switch (channel) {
|
||||
case 1: port = 0x83; break;
|
||||
case 2: port = 0x81; break;
|
||||
case 3: port = 0x82; break;
|
||||
// <- nothing should ever write to chan 4
|
||||
case 5: port = 0x89; break;
|
||||
case 6: port = 0x87; break;
|
||||
case 7: port = 0x88; break;
|
||||
default: if (channel == 4 || channel > 14) return;
|
||||
}
|
||||
|
||||
outportb(port, val);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_mask_channel (unsigned char channel)
|
||||
{
|
||||
if (channel <= 4) outportb (DMA0_CHANMASK_REG, (1<< (channel -1)));
|
||||
else outportb (DMA1_CHANMASK_REG, (1<< (channel -5)));
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_unmask_channel (unsigned char channel)
|
||||
{
|
||||
if (channel <= 4) outportb (DMA0_CHANMASK_REG, channel);
|
||||
else outportb (DMA1_CHANMASK_REG, channel);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_unmask_all()
|
||||
{
|
||||
outportb (DMA1_UNMASK_ALL_REG, 0xff);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_reset_flipflop (unsigned char dma)
|
||||
{
|
||||
switch (dma) {
|
||||
case 0: outportb (DMA0_CLEARBYTE_FLIPFLOP_REG, 0xff);
|
||||
case 1: outportb (DMA1_CLEARBYTE_FLIPFLOP_REG, 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
void i86_dma_reset ()
|
||||
{
|
||||
outportb (DMA0_TEMP_REG, 0xff);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_set_mode(unsigned char channel, unsigned char mode)
|
||||
{
|
||||
unsigned char dma = (channel < 4) ? 0:1;
|
||||
unsigned char chan = (dma == 0) ? channel : channel-4;
|
||||
|
||||
i86_dma_mask_channel (channel);
|
||||
outportb ((channel < 4) ? DMA0_MODE_REG : DMA1_MODE_REG, chan | mode);
|
||||
i86_dma_unmask_all ();
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_set_read (unsigned char channel)
|
||||
{
|
||||
i86_dma_set_mode (channel, DMA_MODE_READ_TRANSFER | DMA_MODE_TRANSFER_SINGLE);
|
||||
}
|
||||
|
||||
|
||||
void i86_dma_set_write (unsigned char channel)
|
||||
{
|
||||
i86_dma_set_mode (channel, DMA_MODE_WRITE_TRANSFER | DMA_MODE_TRANSFER_SINGLE);
|
||||
}
|
42
SysCore/hal/dma/dma.h
Normal file
42
SysCore/hal/dma/dma.h
Normal file
@ -0,0 +1,42 @@
|
||||
/***** dma.h *********************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* Direct Memory Access (DMA) Routines *
|
||||
* =================================== *
|
||||
* *
|
||||
************************************************************ cta os */
|
||||
|
||||
#ifndef __DMA__H__
|
||||
#define __DMA__H__
|
||||
|
||||
enum DMA_MODE_REG_MASK {
|
||||
DMA_MODE_MASK_SEL = 3,
|
||||
|
||||
DMA_MODE_MASK_TRA = 0xc,
|
||||
DMA_MODE_SELF_TEST = 0,
|
||||
DMA_MODE_READ_TRANSFER = 4,
|
||||
DMA_MODE_WRITE_TRANSFER = 8,
|
||||
|
||||
DMA_MODE_MASK_AUTO = 0x10,
|
||||
DMA_MODE_MASK_IDEC = 0x20,
|
||||
|
||||
DMA_MODE_MASK = 0xc0,
|
||||
DMA_MODE_TRANSFER_ON_DEMAND = 0,
|
||||
DMA_MODE_TRANSFER_SINGLE = 0x40,
|
||||
DMA_MODE_TRANSFER_BLOCK = 0x80,
|
||||
DMA_MODE_TRANSFER_CASCADE = 0xC0
|
||||
};
|
||||
|
||||
extern void i86_dma_set_address(unsigned short channel, unsigned char low, unsigned char high);
|
||||
extern void i86_dma_set_count (unsigned short channel, unsigned char low, unsigned char high);
|
||||
extern void i86_dma_set_external_page_registers (unsigned char channel, unsigned char val);
|
||||
extern void i86_dma_mask_channel (unsigned char channel);
|
||||
extern void i86_dma_unmask_channel (unsigned char channel);
|
||||
extern void i86_dma_unmask_all();
|
||||
extern void i86_dma_reset_flipflop (unsigned char dma);
|
||||
extern void i86_dma_reset ();
|
||||
extern void i86_dma_set_mode(unsigned char channel, unsigned char mode);
|
||||
extern void i86_dma_set_read (unsigned char channel);
|
||||
extern void i86_dma_set_write (unsigned char channel);
|
||||
|
||||
#endif
|
18
SysCore/hal/floppy/compile.bat
Normal file
18
SysCore/hal/floppy/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/floppy.o floppy.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
356
SysCore/hal/floppy/floppy.c
Normal file
356
SysCore/hal/floppy/floppy.c
Normal file
@ -0,0 +1,356 @@
|
||||
/***** floppy.c ******************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* Floppy Drive I/O Routines *
|
||||
* ========================= *
|
||||
* *
|
||||
************************************************************ cta os */
|
||||
#include "../irq/irq.h"
|
||||
#include "../dma/dma.h"
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
|
||||
|
||||
// Used ports:
|
||||
// ***********
|
||||
// Digital Output Register (DOR): 0x3f2
|
||||
// Main Status Register (MSR): 0x3f4
|
||||
// Data Register (FIFO): 0x3f5
|
||||
// Configuration Control Register (CTRL): 0x3f7
|
||||
|
||||
unsigned char floppy_drives_installed;
|
||||
volatile unsigned char i86_floppy_new_interrupt;
|
||||
struct {
|
||||
unsigned char type;
|
||||
unsigned char data_rate;
|
||||
unsigned char step_rate_time;
|
||||
unsigned char head_load_time;
|
||||
unsigned char head_unload_time;
|
||||
unsigned char sectors_per_track;
|
||||
} fd[2];
|
||||
|
||||
|
||||
// Initialize DMA
|
||||
unsigned char i86_floppy_initialize_dma(unsigned char* buffer, unsigned length)
|
||||
{
|
||||
union { unsigned char byt[4]; // Low[0], Mid[1], Hi[2]
|
||||
unsigned long l;
|
||||
} a, c;
|
||||
|
||||
a.l = (unsigned) buffer;
|
||||
c.l = (unsigned) length-1;
|
||||
|
||||
// Check for buffer issues
|
||||
if ((a.l >> 24) || (c.l >> 16) || (((a.l & 0xffff)+c.l) >> 16)) return 0;
|
||||
|
||||
i86_dma_reset();
|
||||
i86_dma_mask_channel(2); // Mask channel 2
|
||||
i86_dma_reset_flipflop(1); // FlipFlop reset on DMA1
|
||||
|
||||
i86_dma_set_address(2, a.byt[0], a.byt[1]); // Buffer address
|
||||
i86_dma_reset_flipflop(1); // FlipFlop reset on DMA2
|
||||
|
||||
i86_dma_set_count(2, c.byt[0], c.byt[1]); // Set count
|
||||
i86_dma_set_read(2);
|
||||
i86_dma_unmask_all();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline void i86_floppy_disable_controller() {
|
||||
outportb (0x3F2, 0);
|
||||
}
|
||||
|
||||
inline void i86_floppy_enable_controller() {
|
||||
outportb (0x3F2, 4 | 8);
|
||||
}
|
||||
|
||||
|
||||
inline unsigned char i86_floppy_send_command (unsigned char command)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 750; i++)
|
||||
if (inportb(0x3F4) & 128) {
|
||||
outportb(0x3F5, command); return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline unsigned char i86_floppy_read_data ()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 750; i++)
|
||||
if (inportb(0x3F4) & 0x80)
|
||||
return inportb(0x3F5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline void i86_floppy_check_int(unsigned* st0, unsigned* cyl)
|
||||
{
|
||||
i86_floppy_send_command(0x8);
|
||||
*st0 = i86_floppy_read_data();
|
||||
*cyl = i86_floppy_read_data();
|
||||
}
|
||||
|
||||
|
||||
extern unsigned i86_pit_get_tick_count();
|
||||
extern unsigned i86_pit_get_frequency();
|
||||
|
||||
|
||||
inline unsigned char i86_floppy_wait()
|
||||
{
|
||||
unsigned temp = i86_pit_get_tick_count();
|
||||
unsigned freq = i86_pit_get_frequency();
|
||||
|
||||
while (i86_floppy_new_interrupt==0)
|
||||
if (temp + (3*freq) == i86_pit_get_frequency()) return 0; // timeout
|
||||
|
||||
i86_floppy_new_interrupt = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void i86_floppy_motor (unsigned char drive, unsigned char on)
|
||||
{
|
||||
if (drive >= floppy_drives_installed) return;
|
||||
|
||||
// Read DOR register
|
||||
unsigned char dor = inportb(0x3F2);
|
||||
|
||||
// Un/set selected drive motor
|
||||
if (on) dor |= drive << 4;
|
||||
else dor &= ~(drive << 4);
|
||||
|
||||
// Write DOR
|
||||
outportb (0x3F2, dor);
|
||||
|
||||
// Wait a fifth of a second for motor to turn on
|
||||
unsigned temp = i86_pit_get_tick_count();
|
||||
unsigned freq = i86_pit_get_frequency();
|
||||
while (temp + (freq/5) > i86_pit_get_tick_count());
|
||||
}
|
||||
|
||||
|
||||
void i86_floppy_handler(ISR_stack_regs *r)
|
||||
{
|
||||
i86_floppy_new_interrupt = 1;
|
||||
}
|
||||
|
||||
|
||||
void i86_floppy_drive_data (unsigned char drv, unsigned char dma)
|
||||
{
|
||||
unsigned data = 0;
|
||||
if (drv >= floppy_drives_installed) return;
|
||||
|
||||
outportb(0x3F7, fd[drv].data_rate);
|
||||
|
||||
i86_floppy_send_command (0x3);
|
||||
|
||||
data = ((fd[drv].step_rate_time & 0xf) << 4) | (fd[drv].head_unload_time & 0xf);
|
||||
i86_floppy_send_command (data);
|
||||
|
||||
data = (fd[drv].head_load_time <<1 ) | (dma) ? 1 : 0;
|
||||
i86_floppy_send_command (data);
|
||||
}
|
||||
|
||||
|
||||
inline void i86_floppy_select(unsigned char drive)
|
||||
{
|
||||
if (drive >= floppy_drives_installed) return;
|
||||
|
||||
// Send mechanical drive data
|
||||
i86_floppy_drive_data(drive, 1);
|
||||
|
||||
// Select drive in DOR register
|
||||
outportb (0x3F2, 4 | 8 | drive);
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned char i86_floppy_calibrate(unsigned drive)
|
||||
{
|
||||
unsigned st0, cyl;
|
||||
|
||||
if (drive >= floppy_drives_installed) return 0;
|
||||
|
||||
i86_floppy_motor (drive, 1);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 15; i++) {
|
||||
i86_floppy_new_interrupt = 0;
|
||||
i86_floppy_send_command(0x7);
|
||||
i86_floppy_send_command(drive);
|
||||
i86_floppy_wait();
|
||||
i86_floppy_check_int(&st0, &cyl);
|
||||
|
||||
if (!cyl) {
|
||||
i86_floppy_motor(drive, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
i86_floppy_motor(drive, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void i86_floppy_reset()
|
||||
{
|
||||
unsigned st0, cyl;
|
||||
|
||||
i86_floppy_new_interrupt = 0;
|
||||
i86_floppy_disable_controller();
|
||||
i86_floppy_enable_controller();
|
||||
i86_floppy_wait();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
i86_floppy_check_int(&st0, &cyl);
|
||||
|
||||
unsigned char drive;
|
||||
for (drive = 0; drive < floppy_drives_installed; drive++) {
|
||||
i86_floppy_drive_data(drive, 1);
|
||||
i86_floppy_calibrate(drive);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void i86_floppy_read_sector_imp (unsigned* where, unsigned char drive, unsigned char head, unsigned char track, unsigned char sector)
|
||||
{
|
||||
unsigned st0, cyl;
|
||||
|
||||
i86_floppy_select (drive);
|
||||
i86_floppy_initialize_dma((unsigned char*) where, 512);
|
||||
i86_dma_set_read(2);
|
||||
|
||||
i86_floppy_new_interrupt = 0;
|
||||
|
||||
i86_floppy_send_command(0x06 | 0x80 | 0x40 );
|
||||
i86_floppy_send_command(head<<2 | drive);
|
||||
i86_floppy_send_command(track);
|
||||
i86_floppy_send_command(head);
|
||||
i86_floppy_send_command(sector);
|
||||
i86_floppy_send_command(0x02);
|
||||
i86_floppy_send_command( ((sector+1) >= fd[drive].sectors_per_track) ? fd[drive].sectors_per_track : sector+1);
|
||||
i86_floppy_send_command(0x1b);
|
||||
i86_floppy_send_command(0xff);
|
||||
|
||||
i86_floppy_wait();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 7; i++) i86_floppy_read_data();
|
||||
|
||||
i86_floppy_check_int (&st0, &cyl);
|
||||
}
|
||||
|
||||
|
||||
unsigned char i86_floppy_seek (unsigned drive, unsigned cyl, unsigned head)
|
||||
{
|
||||
unsigned st0, cyl0;
|
||||
|
||||
if (drive >= floppy_drives_installed) return 0;
|
||||
|
||||
i86_floppy_select (drive);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 20; i++) {
|
||||
i86_floppy_new_interrupt = 0;
|
||||
i86_floppy_send_command (0xF);
|
||||
i86_floppy_send_command ( (head) << 2 | drive);
|
||||
i86_floppy_send_command (cyl);
|
||||
|
||||
i86_floppy_wait();
|
||||
i86_floppy_check_int(&st0, &cyl0);
|
||||
|
||||
if (cyl0 == cyl) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline void i86_floppy_lba_to_chs (int lba, unsigned char drive, unsigned char *head, unsigned char *track, unsigned char *sectors)
|
||||
{
|
||||
*head = (lba % (fd[drive].sectors_per_track * 2)) / fd[drive].sectors_per_track;
|
||||
*track = lba / (fd[drive].sectors_per_track * 2);
|
||||
*sectors = lba % fd[drive].sectors_per_track + 1;
|
||||
}
|
||||
|
||||
extern unsigned char i86_cmos_read_floppy_drives();
|
||||
const char* types[] = {
|
||||
"Nonexistant", "5.25\", unsupported.", "5.25\", unsupported.",
|
||||
"3.5\", 720kb", "3.5\", 1.44mb", "3.5\", 2.88 mb"};
|
||||
|
||||
void i86_floppy_install()
|
||||
{
|
||||
unsigned char temp = i86_cmos_read_floppy_drives();
|
||||
int i;
|
||||
|
||||
// Set fd0 and fd1 types
|
||||
fd[1].type = temp & 0xf;
|
||||
fd[0].type = temp >> 4;
|
||||
|
||||
// SRT = 16 - (ms * datarate / 500000);
|
||||
// HLT = ms * datarate / 1000000
|
||||
// HUT = ms * datarate / 8000000
|
||||
|
||||
// Set up
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (fd[i].type >= 3) floppy_drives_installed++; // 5.25" drives unsupported
|
||||
if (fd[i].type == 3) { // 720 kb, DD
|
||||
fd[i].data_rate = 2; // speed = 250 kbps
|
||||
fd[i].step_rate_time = 12; // 16 - (ms * 250000 / 500000), ms = 8
|
||||
fd[i].head_load_time = 7;
|
||||
fd[i].head_unload_time = 7;
|
||||
fd[i].sectors_per_track = 9;
|
||||
}
|
||||
else if (fd[i].type == 4) { // 1.44 MB, HD
|
||||
fd[i].data_rate = 0; // speed = 500 kbps
|
||||
fd[i].step_rate_time = 8;
|
||||
fd[i].head_load_time = 15;
|
||||
fd[i].head_unload_time = 15;
|
||||
fd[i].sectors_per_track = 18;
|
||||
}
|
||||
else if (fd[i].type == 5) { // 2.88 MB, ED
|
||||
fd[i].data_rate = 3; // speed = 1000 kbps;
|
||||
fd[i].step_rate_time = 0;
|
||||
fd[i].head_load_time = 30;
|
||||
fd[i].head_unload_time = 30;
|
||||
fd[i].sectors_per_track = 36;
|
||||
}
|
||||
}
|
||||
if (floppy_drives_installed == 0) return; // No drives to set
|
||||
|
||||
// Install handler
|
||||
i86_irq_install_handler(6, i86_floppy_handler);
|
||||
i86_floppy_reset();
|
||||
}
|
||||
|
||||
|
||||
unsigned char i86_floppy_driver_enabled()
|
||||
{
|
||||
return (floppy_drives_installed>0);
|
||||
}
|
||||
|
||||
|
||||
unsigned* i86_read_sector (unsigned* where, unsigned char drive, int sectorLBA)
|
||||
{
|
||||
if (drive >= floppy_drives_installed) return 0;
|
||||
if ((unsigned)(where) > (0xFFFF - 513)) return 0;
|
||||
|
||||
// convert lba to chs
|
||||
unsigned head, track, sector;
|
||||
i86_floppy_lba_to_chs(sectorLBA, drive, (unsigned char*)&head, (unsigned char*)&track, (unsigned char*) §or);
|
||||
|
||||
// start motor
|
||||
i86_floppy_motor(drive, 1);
|
||||
if (!i86_floppy_seek(drive, track, head)) return 0;
|
||||
|
||||
i86_floppy_read_sector_imp(where, drive, head, track, sector);
|
||||
i86_floppy_motor(drive, 0);
|
||||
|
||||
return (unsigned*)where;
|
||||
}
|
19
SysCore/hal/floppy/floppy.h
Normal file
19
SysCore/hal/floppy/floppy.h
Normal file
@ -0,0 +1,19 @@
|
||||
/***** floppy.h ******************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* Floppy Drive I/O Routines *
|
||||
* ========================= *
|
||||
* *
|
||||
************************************************************ cta os */
|
||||
|
||||
extern unsigned char i86_floppy_initialize_dma(unsigned char* buffer, unsigned length);
|
||||
extern void i86_floppy_motor (unsigned char drive, unsigned char on);
|
||||
extern void i86_floppy_handler(ISR_stack_regs *r);
|
||||
extern void i86_floppy_drive_data (unsigned char drv, unsigned char dma);
|
||||
extern unsigned char i86_floppy_calibrate(unsigned drive);
|
||||
extern void i86_floppy_reset();
|
||||
extern void i86_floppy_read_sector_imp (unsigned* where, unsigned char drive, unsigned char head, unsigned char track, unsigned char sector);
|
||||
extern unsigned char i86_floppy_seek (unsigned drive, unsigned cyl, unsigned head);
|
||||
extern void i86_floppy_install();
|
||||
extern unsigned char i86_floppy_driver_enabled();
|
||||
extern unsigned* i86_read_sector (unsigned* where, unsigned char drive, int sectorLBA);
|
@ -2,7 +2,7 @@
|
||||
* gdt.c - GLOBAL DESCRIPTOR TABLE *
|
||||
* Contains function prototypes for setting up the GDT *
|
||||
******************************************************************/
|
||||
#define MAX_DESCRIPTORS 3
|
||||
#define MAX_DESCRIPTORS 5
|
||||
#include "gdt.h"
|
||||
|
||||
/* Our GDT, with 3 entries, and finally our special GDT pointer */
|
||||
@ -59,6 +59,12 @@ void i86_gdt_install()
|
||||
* this entry's access byte says it's a Data Segment */
|
||||
i86_gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
|
||||
/* User mode Code segment*/
|
||||
i86_gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
|
||||
|
||||
/* User mode data segment*/
|
||||
i86_gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
|
||||
|
||||
/* Flush out the old GDT and install the new changes! */
|
||||
i86_gdt_flush();
|
||||
}
|
||||
|
@ -10,24 +10,26 @@
|
||||
#include "irq/irq.h"
|
||||
#include "isrs/isrs.h"
|
||||
#include "keyboard/keyus.h"
|
||||
#include "floppy/floppy.h"
|
||||
|
||||
// initialize hardware devices
|
||||
void i86_hal_initialize () {
|
||||
|
||||
// initialize motherboard controllers and system timer
|
||||
i86_cpu_initialize (); // (install GDT, IDT)
|
||||
i86_isrs_install(); // (install ISR handler)
|
||||
i86_irq_install(); // (install IRQ handler)
|
||||
// initialize motherboard controllers and system timer
|
||||
i86_cpu_initialize (); // (install GDT, IDT)
|
||||
i86_isrs_install(); // (install ISR handler)
|
||||
i86_irq_install(); // (install IRQ handler)
|
||||
|
||||
// install PIT and system clock; pit at 100 Hz
|
||||
i86_kb_install_partone();
|
||||
i86_cmos_read_clock((TIME*)&_internal_clock);
|
||||
// install PIT and system clock; pit at 100 Hz
|
||||
i86_kb_install_partone();
|
||||
i86_cmos_read_clock((TIME*)&_internal_clock);
|
||||
i86_pit_install (100);
|
||||
i86_kb_install_parttwo();
|
||||
|
||||
// enable interrupts
|
||||
i86_start_interrupts();
|
||||
|
||||
// enable interrupts
|
||||
i86_start_interrupts();
|
||||
|
||||
i86_floppy_install();
|
||||
}
|
||||
|
||||
// shutdown hardware devices
|
||||
@ -46,58 +48,14 @@ void reboot()
|
||||
__asm__ __volatile__ ("hlt");
|
||||
}
|
||||
|
||||
//! notifies hal interrupt is done
|
||||
/*inline void interruptdone (unsigned int intno) {
|
||||
|
||||
//! insure its a valid hardware irq
|
||||
if (intno > 16)
|
||||
return;
|
||||
|
||||
//! test if we need to send end-of-interrupt to second pic
|
||||
if (intno >= 8)
|
||||
i86_pic_send_command (0x20, 0xA1);
|
||||
|
||||
//! always send end-of-interrupt to primary pic
|
||||
i86_pic_send_command (0x20, 0x21);
|
||||
}
|
||||
*/
|
||||
|
||||
//! output sound to speaker
|
||||
void sound (unsigned frequency) {
|
||||
|
||||
//! sets frequency for speaker. frequency of 0 disables speaker
|
||||
outportb (0x61, 3 | (byte)(frequency<<2) );
|
||||
outportb (0x61, 3 | (unsigned char)(frequency<<2) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//! sets new interrupt vector
|
||||
/*void _cdecl setvect (int intno, void (_cdecl far &vect) ( ) ) {
|
||||
|
||||
//! install interrupt handler! This overwrites prev interrupt descriptor
|
||||
i86_install_ir (intno, I86_IDT_DESC_PRESENT | I86_IDT_DESC_BIT32,
|
||||
0x8, vect);
|
||||
}
|
||||
|
||||
|
||||
//! returns current interrupt vector
|
||||
void (_cdecl far * _cdecl getvect (int intno)) ( ) {
|
||||
|
||||
//! get the descriptor from the idt
|
||||
idt_descriptor* desc = i86_get_ir (intno);
|
||||
if (!desc)
|
||||
return 0;
|
||||
|
||||
//! get address of interrupt handler
|
||||
uint32_t addr = desc->baseLo | (desc->baseHi << 16);
|
||||
|
||||
//! return interrupt handler
|
||||
I86_IRQ_HANDLER irq = (I86_IRQ_HANDLER)addr;
|
||||
return irq;
|
||||
}
|
||||
|
||||
*/
|
||||
//! returns cpu vender
|
||||
const char* get_cpu_vender () {
|
||||
|
||||
@ -108,19 +66,18 @@ const char* get_cpu_vender () {
|
||||
/***************************************************************************************
|
||||
* Keyboard Routines *
|
||||
***************************************************************************************/
|
||||
char getch()
|
||||
/*char getch()
|
||||
{
|
||||
kb_key alpha = getkey();
|
||||
return alpha.character;
|
||||
}
|
||||
-> moved in conio library
|
||||
}*/
|
||||
|
||||
char scancode_to_ascii(byte scancode, byte status)
|
||||
char scancode_to_ascii(unsigned char scancode, unsigned char status)
|
||||
{
|
||||
if ((status&1) || (status&2)) return kbdus_map_shift[scancode];
|
||||
else return kbdus_map[scancode];
|
||||
}
|
||||
|
||||
byte get_key_status (byte scancode)
|
||||
unsigned char get_key_status (unsigned char scancode)
|
||||
{
|
||||
if (scancode&0xF0) return kb_lights_status&0x0F;
|
||||
else if (scancode&0x80) return kb_modifier_status&0x7F;
|
||||
@ -153,7 +110,7 @@ void kb_set_repeat(float rate, int delay){
|
||||
3.7, 3.3, 3.0, 2.7, 2.5, 2.3, 2.1, 2.0} ;
|
||||
|
||||
|
||||
byte r,d;
|
||||
unsigned char r,d;
|
||||
|
||||
for (r = 0; rate != rates[r] && r < 32; r++)
|
||||
if (rate==32) return;
|
||||
@ -179,6 +136,6 @@ void kb_set_repeat(float rate, int delay){
|
||||
|(reserved) | lock | lock | lock |
|
||||
+-----------+-------+-------+--------+
|
||||
***************************************/
|
||||
void kb_set_LEDs(byte status) {
|
||||
void kb_set_LEDs(unsigned char status) {
|
||||
i86_kb_set_LEDs(status);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __IRQ_H
|
||||
#define __IRQ_H
|
||||
|
||||
#include <regs.h>
|
||||
|
||||
/* These are own ISRs that point to our special IRQ handler
|
||||
* instead of the regular 'fault_handler' function */
|
||||
|
||||
|
@ -36,10 +36,10 @@ char *exception_messages[] = {
|
||||
};
|
||||
|
||||
|
||||
void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
set_default_colors (0x01, 0x0F); clrscr();
|
||||
puts (" Blue Screen Of Death\n");
|
||||
//void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
//{
|
||||
//set_default_colors (0x01, 0x0F); clrscr();
|
||||
/*puts_pos (0, 0, " Blue Screen Of Death\n");
|
||||
int i; for (i = 79; i>=0; i--) putc('=');
|
||||
puts_pos_font (15, 2, "A fatal error has occured, CTA OS has been halted.", 0x01, 0x0C);
|
||||
puts_pos_font (10, 4, "gs", 0x01, 0x0B); put_hex_pos(15, 4, r->gs);
|
||||
@ -67,8 +67,8 @@ void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
puts_pos_font (10, 20, "useresp", 0x01, 0x0B); put_hex_pos(17, 20, r->useresp);
|
||||
puts_pos_font (10, 21, "ss", 0x01, 0x0B); put_hex_pos(17, 21, r->ss);
|
||||
|
||||
puts_pos_font (29, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}
|
||||
puts_pos_font (29, 24, "!!! System Halted !!!", 0x01, 0x0C);*/
|
||||
//}
|
||||
|
||||
/*void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
@ -76,4 +76,9 @@ void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
puts_pos(50, 24, exception_messages[r->int_no]);
|
||||
|
||||
puts_pos_font (5, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
||||
}*/
|
||||
}*/
|
||||
|
||||
void _STOP_ERROR_SCREEN (ISR_stack_regs *r)
|
||||
{
|
||||
cprintf ("%#0C** Fatal Error: "); cprintf("%#0E %s \n\r", exception_messages[r->int_no]);
|
||||
}
|
@ -6,128 +6,130 @@
|
||||
#define KB_KEY_LCTRL 0x90 // 1001 0000
|
||||
#define KB_KEY_RCTRL 0xA0 // 1010 0000
|
||||
#define KB_KEY_FSHIFT 0xC0 // 1100 0000
|
||||
extern volatile byte kb_modifier_status;
|
||||
extern volatile unsigned char kb_modifier_status;
|
||||
|
||||
#define KB_PREFIX_GRAY 0x01 // Gray
|
||||
#define KB_PREFIX_BREAK 0x02 // Break code
|
||||
#define KB_PREFIX_PAUSE 0x04 // Pause/break key
|
||||
#define KB_PREFIX_PAUSE1 0x08 // Recieved first byte from pause/break
|
||||
extern volatile byte kb_prefix;
|
||||
#define KB_PREFIX_PAUSE1 0x08 // Recieved first unsigned char from pause/break
|
||||
extern volatile unsigned char kb_prefix;
|
||||
|
||||
#define KB_KEY_SCROLL 0xF1 // 1111 0001
|
||||
#define KB_KEY_NUM 0xF2 // 1111 0010
|
||||
#define KB_KEY_CAPS 0xF4 // 1111 0100
|
||||
extern volatile byte kb_lights_status;
|
||||
extern volatile unsigned char kb_lights_status;
|
||||
|
||||
extern byte kb_scancode_set;
|
||||
#define KB_KEY_PAUSE 0x00
|
||||
#define KB_KEY_F9 0x01
|
||||
#define KB_KEY_F7 0x02
|
||||
#define KB_KEY_F5 0X03
|
||||
#define KB_KEY_F3 0x04
|
||||
#define KB_KEY_F1 0x05
|
||||
#define KB_KEY_F2 0x06
|
||||
#define KB_KEY_F12 0x07
|
||||
#define KB_KEY_PRINTSCRN 0x08
|
||||
#define KB_KEY_F10 0x09
|
||||
#define KB_KEY_F8 0x0A
|
||||
#define KB_KEY_F6 0x0B
|
||||
#define KB_KEY_F4 0x0C
|
||||
#define KB_KEY_TAB 0x0D
|
||||
#define KB_KEY_TILDA 0x0E
|
||||
#define KB_KEY_Q 0x15
|
||||
#define KB_KEY_1 0x16
|
||||
#define KB_KEY_Z 0x1A
|
||||
#define KB_KEY_S 0x1B
|
||||
#define KB_KEY_A 0x1C
|
||||
#define KB_KEY_W 0x1D
|
||||
#define KB_KEY_2 0x1E
|
||||
#define KB_KEY_LWIN 0x1F
|
||||
#define KB_KEY_C 0x21
|
||||
#define KB_KEY_X 0x22
|
||||
#define KB_KEY_D 0x23
|
||||
#define KB_KEY_E 0x24
|
||||
#define KB_KEY_4 0x25
|
||||
#define KB_KEY_3 0x26
|
||||
#define KB_KEY_RWIN 0x27
|
||||
#define KB_KEY_SPACE 0x29
|
||||
#define KB_KEY_V 0x2A
|
||||
#define KB_KEY_F 0x2B
|
||||
#define KB_KEY_T 0x2C
|
||||
#define KB_KEY_R 0x2D
|
||||
#define KB_KEY_5 0x2E
|
||||
#define KB_KEY_MENU 0x2F
|
||||
#define KB_KEY_N 0x31
|
||||
#define KB_KEY_B 0x32
|
||||
#define KB_KEY_H 0x33
|
||||
#define KB_KEY_G 0x34
|
||||
#define KB_KEY_Y 0x35
|
||||
#define KB_KEY_6 0x36
|
||||
#define KB_KEY_M 0x3A
|
||||
#define KB_KEY_J 0x3B
|
||||
#define KB_KEY_U 0x3C
|
||||
#define KB_KEY_7 0x3D
|
||||
#define KB_KEY_8 0x3E
|
||||
#define KB_KEY_COMMA 0x41
|
||||
#define KB_KEY_K 0x42
|
||||
#define KB_KEY_I 0x43
|
||||
#define KB_KEY_O 0x44
|
||||
#define KB_KEY_0 0x45
|
||||
#define KB_KEY_9 0x46
|
||||
#define KB_KEY_PERIOD 0x49
|
||||
#define KB_KEY_SLASH 0x4A
|
||||
#define KB_KEY_L 0x4B
|
||||
#define KB_KEY_SEMICOLON 0x4C
|
||||
#define KB_KEY_P 0x4D
|
||||
#define KB_KEY_DASH 0x4E
|
||||
#define KB_KEY_APOSTROPHE 0x52
|
||||
#define KB_KEY_LBRACKET 0x54
|
||||
#define KB_KEY_EQUAL 0x55
|
||||
#define KB_KEY_NUMPAD_ENTER 0x59
|
||||
#define KB_KEY_ENTER 0x5A
|
||||
#define KB_KEY_RBRACKET 0x5B
|
||||
#define KB_KEY_BACKSLASH 0x5D
|
||||
#define KB_KEY_END 0x5E
|
||||
#define KB_KEY_LEFT 0x5F
|
||||
#define KB_KEY_HOME 0x60
|
||||
#define KB_KEY_INSERT 0x61
|
||||
#define KB_KEY_DELETE 0x62
|
||||
#define KB_KEY_DOWN 0x63
|
||||
#define KB_KEY_RIGHT 0x64
|
||||
#define KB_KEY_UP 0x65
|
||||
#define KB_KEY_BACKSPACE 0x66
|
||||
#define KB_KEY_PGDOWN 0x67
|
||||
#define KB_KEY_PGUP 0x68
|
||||
#define KB_KEY_NUMPAD_1 0x69
|
||||
#define KB_KEY_NUMPAD_SLASH 0x6A
|
||||
#define KB_KEY_NUMPAD_4 0x6B
|
||||
#define KB_KEY_NUMPAD_7 0x6C
|
||||
#define KB_KEY_NUMPAD_0 0x70
|
||||
#define KB_KEY_NUMPAD_COLON 0x71
|
||||
#define KB_KEY_NUMPAD_2 0x72
|
||||
#define KB_KEY_NUMPAD_5 0x73
|
||||
#define KB_KEY_NUMPAD_6 0x74
|
||||
#define KB_KEY_NUMPAD_8 0x75
|
||||
#define KB_KEY_ESC 0x76
|
||||
#define KB_KEY_F11 0x78
|
||||
#define KB_KEY_NUMPAD_PLUS 0x79
|
||||
#define KB_KEY_NUMPAD_3 0x7A
|
||||
#define KB_KEY_NUMPAD_MINUS 0x7B
|
||||
#define KB_KEY_NUMPAD_ASTERISK 0x7C
|
||||
#define KB_KEY_NUMPAD_9 0x7D
|
||||
extern unsigned char kb_scancode_set;
|
||||
|
||||
enum KB_KEYS {
|
||||
KB_KEY_PAUSE = 0x00
|
||||
KB_KEY_F9 = 0x01
|
||||
KB_KEY_F7 = 0x02
|
||||
KB_KEY_F5 = 0X03
|
||||
KB_KEY_F3 = 0x04
|
||||
KB_KEY_F1 = 0x05
|
||||
KB_KEY_F2 = 0x06
|
||||
KB_KEY_F12 = 0x07
|
||||
KB_KEY_PRINTSCRN = 0x08
|
||||
KB_KEY_F10 = 0x09
|
||||
KB_KEY_F8 = 0x0A
|
||||
KB_KEY_F6 = 0x0B
|
||||
KB_KEY_F4 = 0x0C
|
||||
KB_KEY_TAB = 0x0D
|
||||
KB_KEY_TILDA = 0x0E
|
||||
KB_KEY_Q = 0x15
|
||||
KB_KEY_1 = 0x16
|
||||
KB_KEY_Z = 0x1A
|
||||
KB_KEY_S = 0x1B
|
||||
KB_KEY_A = 0x1C
|
||||
KB_KEY_W = 0x1D
|
||||
KB_KEY_2 = 0x1E
|
||||
KB_KEY_LWIN = 0x1F
|
||||
KB_KEY_C = 0x21
|
||||
KB_KEY_X = 0x22
|
||||
KB_KEY_D = 0x23
|
||||
KB_KEY_E = 0x24
|
||||
KB_KEY_4 = 0x25
|
||||
KB_KEY_3 = 0x26
|
||||
KB_KEY_RWIN = 0x27
|
||||
KB_KEY_SPACE = 0x29
|
||||
KB_KEY_V = 0x2A
|
||||
KB_KEY_F = 0x2B
|
||||
KB_KEY_T = 0x2C
|
||||
KB_KEY_R = 0x2D
|
||||
KB_KEY_5 = 0x2E
|
||||
KB_KEY_MENU = 0x2F
|
||||
KB_KEY_N = 0x31
|
||||
KB_KEY_B = 0x32
|
||||
KB_KEY_H = 0x33
|
||||
KB_KEY_G = 0x34
|
||||
KB_KEY_Y = 0x35
|
||||
KB_KEY_6 = 0x36
|
||||
KB_KEY_M = 0x3A
|
||||
KB_KEY_J = 0x3B
|
||||
KB_KEY_U = 0x3C
|
||||
KB_KEY_7 = 0x3D
|
||||
KB_KEY_8 = 0x3E
|
||||
KB_KEY_COMMA = 0x41
|
||||
KB_KEY_K = 0x42
|
||||
KB_KEY_I = 0x43
|
||||
KB_KEY_O = 0x44
|
||||
KB_KEY_0 = 0x45
|
||||
KB_KEY_9 = 0x46
|
||||
KB_KEY_PERIOD = 0x49
|
||||
KB_KEY_SLASH = 0x4A
|
||||
KB_KEY_L = 0x4B
|
||||
KB_KEY_SEMICOLON = 0x4C
|
||||
KB_KEY_P = 0x4D
|
||||
KB_KEY_DASH = 0x4E
|
||||
KB_KEY_APOSTROPHE = 0x52
|
||||
KB_KEY_LBRACKET = 0x54
|
||||
KB_KEY_EQUAL = 0x55
|
||||
KB_KEY_NUMPAD_ENTER = 0x59
|
||||
KB_KEY_ENTER = 0x5A
|
||||
KB_KEY_RBRACKET = 0x5B
|
||||
KB_KEY_BACKSLASH = 0x5D
|
||||
KB_KEY_END = 0x5E
|
||||
KB_KEY_LEFT = 0x5F
|
||||
KB_KEY_HOME = 0x60
|
||||
KB_KEY_INSERT = 0x61
|
||||
KB_KEY_DELETE = 0x62
|
||||
KB_KEY_DOWN = 0x63
|
||||
KB_KEY_RIGHT = 0x64
|
||||
KB_KEY_UP = 0x65
|
||||
KB_KEY_BACKSPACE = 0x66
|
||||
KB_KEY_PGDOWN = 0x67
|
||||
KB_KEY_PGUP = 0x68
|
||||
KB_KEY_NUMPAD_1 = 0x69
|
||||
KB_KEY_NUMPAD_SLASH = 0x6A
|
||||
KB_KEY_NUMPAD_4 = 0x6B
|
||||
KB_KEY_NUMPAD_7 = 0x6C
|
||||
KB_KEY_NUMPAD_0 = 0x70
|
||||
KB_KEY_NUMPAD_COLON = 0x71
|
||||
KB_KEY_NUMPAD_2 = 0x72
|
||||
KB_KEY_NUMPAD_5 = 0x73
|
||||
KB_KEY_NUMPAD_6 = 0x74
|
||||
KB_KEY_NUMPAD_8 = 0x75
|
||||
KB_KEY_ESC = 0x76
|
||||
KB_KEY_F11 = 0x78
|
||||
KB_KEY_NUMPAD_PLUS = 0x79
|
||||
KB_KEY_NUMPAD_3 = 0x7A
|
||||
KB_KEY_NUMPAD_MINUS = 0x7B
|
||||
KB_KEY_NUMPAD_ASTERISK = 0x7C
|
||||
KB_KEY_NUMPAD_9 = 0x7D
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
byte status;
|
||||
byte lights;
|
||||
byte scancode;
|
||||
byte character;
|
||||
unsigned char status;
|
||||
unsigned char lights;
|
||||
unsigned char scancode;
|
||||
unsigned char character;
|
||||
} kb_key;
|
||||
|
||||
|
||||
extern char getch();
|
||||
extern kb_key get_key();
|
||||
extern scancode_to_ascii(byte scancode);
|
||||
extern byte get_key_status(byte scancode);
|
||||
extern scancode_to_ascii(unsigned char scancode);
|
||||
extern unsigned char get_key_status(unsigned char scancode);
|
||||
extern void kb_set_repeat(float rate, int delay);
|
||||
extern void kb_set_LEDs(byte status);
|
||||
extern void kb_set_LEDs(unsigned char status);
|
@ -28,18 +28,18 @@ const char kbdus_map_shift[] = {
|
||||
};
|
||||
|
||||
|
||||
volatile byte kb_array[16];
|
||||
volatile byte kb_newdata;
|
||||
volatile byte kb_modifier_status;
|
||||
volatile byte kb_prefix;
|
||||
volatile byte kb_lights_status;
|
||||
byte kb_scancode_set;
|
||||
volatile unsigned char kb_array[16];
|
||||
volatile unsigned char kb_newdata;
|
||||
volatile unsigned char kb_modifier_status;
|
||||
volatile unsigned char kb_prefix;
|
||||
volatile unsigned char kb_lights_status;
|
||||
unsigned char kb_scancode_set;
|
||||
|
||||
|
||||
void i86_kb_set_key(byte scancode, byte val)
|
||||
void i86_kb_set_key(unsigned char scancode, unsigned char val)
|
||||
{
|
||||
byte pos = scancode/8;
|
||||
byte offset = scancode%8;
|
||||
unsigned char pos = scancode/8;
|
||||
unsigned char offset = scancode%8;
|
||||
|
||||
if (val) {
|
||||
kb_array[pos] |= 1<<offset;
|
||||
@ -48,16 +48,16 @@ void i86_kb_set_key(byte scancode, byte val)
|
||||
else kb_array[pos] &= 0xFF - (1<<offset);
|
||||
}
|
||||
|
||||
byte i86_kb_get_key(byte scancode)
|
||||
unsigned char i86_kb_get_key(unsigned char scancode)
|
||||
{
|
||||
byte pos = scancode/8;
|
||||
byte offset = scancode%8;
|
||||
unsigned char pos = scancode/8;
|
||||
unsigned char offset = scancode%8;
|
||||
return (kb_array[pos]&(1<<offset));
|
||||
}
|
||||
|
||||
|
||||
void i86_kb_handler(ISR_stack_regs *r) {
|
||||
byte scancode = inportb(0x60);
|
||||
unsigned char scancode = inportb(0x60);
|
||||
|
||||
switch (scancode) {
|
||||
case 0x00: // Error 0x00
|
||||
@ -165,7 +165,6 @@ void i86_kb_handler(ISR_stack_regs *r) {
|
||||
if (ok==2) reboot();
|
||||
}
|
||||
|
||||
outportb(0x20, 0x20);
|
||||
}
|
||||
|
||||
|
||||
@ -210,11 +209,11 @@ kb_key getkey()
|
||||
250 | 500 | 750 | 1000
|
||||
|
||||
***************************************/
|
||||
void i86_kb_set_repeat(byte rate, byte delay)
|
||||
void i86_kb_set_repeat(unsigned char rate, unsigned char delay)
|
||||
{
|
||||
if (rate>3 || delay>31) return;
|
||||
|
||||
byte out = rate<<5 | delay;
|
||||
unsigned char out = rate<<5 | delay;
|
||||
while ((inportb(0x64)&2) != 0);
|
||||
outportb(0x60, 0xF3);
|
||||
while ((inportb(0x64)&2) != 0);
|
||||
@ -231,7 +230,7 @@ void i86_kb_set_repeat(byte rate, byte delay)
|
||||
|(reserved) | lock | lock | lock |
|
||||
+-----------+-------+-------+--------+
|
||||
***************************************/
|
||||
void i86_kb_set_LEDs(byte status)
|
||||
void i86_kb_set_LEDs(unsigned char status)
|
||||
{
|
||||
while ((inportb (0x64)&2)!=0);
|
||||
outportb (0x60, 0xED);
|
||||
@ -248,7 +247,7 @@ void i86_kb_set_LEDs(byte status)
|
||||
2 Set to scancode set 2
|
||||
3 Set to scancode set 3
|
||||
***************************************/
|
||||
void i86_kb_set_scancodeset(byte set)
|
||||
void i86_kb_set_scancodeset(unsigned char set)
|
||||
{
|
||||
if (set>3) return;
|
||||
|
||||
@ -261,7 +260,7 @@ void i86_kb_set_scancodeset(byte set)
|
||||
kb_scancode_set = set;
|
||||
}
|
||||
|
||||
byte i86_kb_get_scancodeset() {
|
||||
unsigned char i86_kb_get_scancodeset() {
|
||||
return kb_scancode_set;
|
||||
}
|
||||
|
||||
@ -298,7 +297,7 @@ int i86_kb_install_parttwo()
|
||||
int ret = 0;
|
||||
|
||||
// Wait for BAT test results
|
||||
byte temp;
|
||||
unsigned char temp;
|
||||
do temp = inportb(0x60);
|
||||
while (temp!=0xAA && temp!=0xFC);
|
||||
|
||||
@ -311,13 +310,13 @@ int i86_kb_install_parttwo()
|
||||
i86_kb_set_scancodeset(2); // Set new scancode set
|
||||
|
||||
i86_kb_waitin();
|
||||
outportb(0x64, 0x20); // Get "Command byte"
|
||||
outportb(0x64, 0x20); // Get "Command unsigned char"
|
||||
|
||||
do { temp = inportb(0x60);
|
||||
} while (temp==0xFA || temp==0xAA);
|
||||
|
||||
temp &= 0xFF - (1<<6); // Set bit6 to 0: disable conversion
|
||||
i86_kb_waitin(); outportb(0x64, 0x60); // Function to write cmd byte
|
||||
i86_kb_waitin(); outportb(0x64, 0x60); // Function to write cmd unsigned char
|
||||
i86_kb_waitin(); outportb(0x60, temp); // Send it
|
||||
memset((void*)kb_array, 0, 16);
|
||||
|
||||
|
@ -4,22 +4,22 @@
|
||||
extern const char kbdus_map[0x80];
|
||||
extern const char kbdus_map_shift[0x80];
|
||||
|
||||
extern volatile byte kb_modifier_status;
|
||||
extern volatile byte kb_prefix;
|
||||
extern volatile byte kb_lights_status;
|
||||
extern byte kb_scancode_set;
|
||||
extern volatile unsigned char kb_modifier_status;
|
||||
extern volatile unsigned char kb_prefix;
|
||||
extern volatile unsigned char kb_lights_status;
|
||||
extern unsigned char kb_scancode_set;
|
||||
|
||||
extern void i86_kb_set_key(byte scancode, byte val);
|
||||
extern void i86_kb_set_LEDs(byte status);
|
||||
extern void i86_kb_set_repeat(byte rate, byte delay);
|
||||
extern void i86_kb_set_scancodeset(byte set);
|
||||
extern byte i86_kb_get_key(byte scancode);
|
||||
extern void i86_kb_set_key(unsigned char scancode, unsigned char val);
|
||||
extern void i86_kb_set_LEDs(unsigned char status);
|
||||
extern void i86_kb_set_repeat(unsigned char rate, unsigned char delay);
|
||||
extern void i86_kb_set_scancodeset(unsigned char set);
|
||||
extern unsigned char i86_kb_get_key(unsigned char scancode);
|
||||
extern void i86_kb_handler(ISR_stack_regs *r);
|
||||
extern kb_key getkey();
|
||||
extern void i86_kb_set_repeat(byte rate, byte delay);
|
||||
extern void i86_kb_set_LEDs(byte status);
|
||||
extern void i86_kb_set_scancodeset(byte set);
|
||||
extern byte i86_kb_get_scancodeset();
|
||||
extern void i86_kb_set_repeat(unsigned char rate, unsigned char delay);
|
||||
extern void i86_kb_set_LEDs(unsigned char status);
|
||||
extern void i86_kb_set_scancodeset(unsigned char set);
|
||||
extern unsigned char i86_kb_get_scancodeset();
|
||||
extern void i86_kb_waitin();
|
||||
extern void i86_kb_waitout();
|
||||
extern void i86_kb_install_partone();
|
||||
|
@ -30,13 +30,31 @@ goto cmos
|
||||
|
||||
:cpu
|
||||
cd cpu
|
||||
@echo * Compiling Central Processing Unit...
|
||||
@echo * Compiling Central Processing Unit (CPU)...
|
||||
del %objpath%\cpu.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cpu.o cpu.c
|
||||
if not exist %objpath%\cpu.o goto error
|
||||
|
||||
cd..
|
||||
|
||||
|
||||
:dma
|
||||
cd dma
|
||||
@echo * Compiling Direct Memory Access Controller (DMAC)...
|
||||
del %objpath%\dma.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/dma.o dma.c
|
||||
if not exist %objpath%\dma.o goto error
|
||||
cd..
|
||||
|
||||
|
||||
:floppy
|
||||
cd floppy
|
||||
@echo * Compiling Floppy Driver...
|
||||
del %objpath%\floppy.o
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/floppy.o floppy.c
|
||||
if not exist %objpath%\floppy.o goto error
|
||||
cd..
|
||||
|
||||
:gdt
|
||||
cd gdt
|
||||
@echo * Compiling Global Descriptor Table...
|
||||
|
@ -50,6 +50,11 @@ void i86_pit_install(int freq)
|
||||
|
||||
}
|
||||
|
||||
TIME i86_pit_get_time()
|
||||
{
|
||||
return _internal_clock;
|
||||
}
|
||||
|
||||
unsigned char i86_pit_is_initialized()
|
||||
{
|
||||
return _pit_init;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define __PIT_H
|
||||
|
||||
#include<regs.h>
|
||||
extern volatile unsigned int _pit_ticks;
|
||||
extern volatile unsigned int _pit_ticks;
|
||||
extern volatile unsigned int _pit_frequency;
|
||||
extern volatile TIME _internal_clock;
|
||||
|
||||
|
Reference in New Issue
Block a user