#include <stdint.h>
#include "arch.h"
#include "video.h"
#include "k_defines.h"
#include "ints.h"
#include "descriptor.h"
#include "pic.h"
#include "./drivers/mindrvr.h"
typedef unsigned char __int8;
typedef unsigned short int __int16;
typedef unsigned int __int32;
typedef long long int __int64;
void testint(void);
extern int printf(char*,...);
extern int testfat(void);
extern int ticks;
extern int InitializeMemoryManager(void);
extern short console_cursor_xpos;
extern short console_cursor_ypos;
extern int console_color_attribut;
#define VK_A 0x1e61
#define VK_B 0x3062
#define VK_C 0x2e63
#define VK_D 0x2064
#define VK_E 0x1265
#define VK_F 0x2166
#define VK_G 0x2267
#define VK_H 0x2368
#define VK_I 0x1769
#define VK_J 0x246a
#define VK_K 0x256b
#define VK_L 0x266c
#define VK_M 0x326d
#define VK_N 0x316e
#define VK_O 0x186f
#define VK_P 0x1970
#define VK_Q 0x1071
#define VK_R 0x1372
#define VK_S 0x1f73
#define VK_T 0x1474
#define VK_U 0x1675
#define VK_V 0x2f76
#define VK_W 0x1177
#define VK_X 0x2d78
#define VK_Y 0x2c7a
#define VK_Z 0x1579
#define VK_BACKSPACE 0xe08
#define VK_RETURN 0x1c0d
#define VK_ESC 0x11b
#define VK_F1 0x3b00
#define VK_F2 0x3c00
#define VK_F3 0x3d00
#define VK_F4 0x3e00
#define VK_F5 0x3f00
#define VK_F6 0x4000
#define VK_F7 0x4100
#define VK_F8 0x4200
#define VK_F9 0x4300
#define VK_F10 0x4400
#define MAXKEYCODES 29
struct {
unsigned short keycode;
unsigned int extended;
unsigned int shift;
char *consolecode;
} __attribute__((packed)) GERMAN_KEYBOARD_STRUCT[MAXKEYCODES] = {
VK_A, 0, 0, "a" ,
VK_B, 0, 0, "b" ,
VK_C, 0, 0, "c" ,
VK_D, 0, 0, "d" ,
VK_E, 0, 0, "e" ,
VK_F, 0, 0, "f" ,
VK_G, 0, 0, "g" ,
VK_H, 0, 0, "h" ,
VK_I, 0, 0, "i" ,
VK_J, 0, 0, "j" ,
VK_K, 0, 0, "k" ,
VK_L, 0, 0, "l" ,
VK_M, 0, 0, "m" ,
VK_N, 0, 0, "n" ,
VK_O, 0, 0, "o" ,
VK_P, 0, 0, "p" ,
VK_Q, 0, 0, "q" ,
VK_R, 0, 0, "r" ,
VK_S, 0, 0, "s" ,
VK_T, 0, 0, "t" ,
VK_U, 0, 0, "u" ,
VK_V, 0, 0, "v" ,
VK_W, 0, 0, "w" ,
VK_X, 0, 0, "x" ,
VK_Y, 0, 0, "y" ,
VK_Z, 0, 0, "z" ,
VK_BACKSPACE, 0,0, "\b" ,
VK_RETURN, 0,0, "\n" ,
0, 0, 0, "\0"
};
void nl(void)
{
console_cursor_xpos = 0;
console_cursor_ypos++;
}
struct CDROM_VolumeDescriptor
{
unsigned char type;
char ident[5];
unsigned char version;
char desc_type[2048-7+1];
} __attribute__((packed)) CD_VolumeDescriptor;
struct CDROM_BootRecord
{
unsigned char type;
char ident[5];
unsigned char version;
char sys_ident[32];
char boot_ident[32];
char boot_res[2048-64-7+1];
} __attribute__((packed)) CD_BootRecord;
struct CDROM_VolumeDescriptorSetTerminator
{
unsigned char type;
char ident[5];
unsigned char version;
char desc_type[2048-7+1];
} __attribute__((packed)) CD_VolumeSetTerminator;
struct CDROM_DirectoryItem {
__int8 sizeof_diritem;
__int8 number_of_extsectors;
__int32 first_sector;
__int32 sizeof_datarange;
__int8 created_year; // since 1900
__int8 created_month;
__int8 created_day;
__int8 created_hour;
__int8 created_minute;
__int8 created_second;
__int8 gmt;
__int8 flags;
__int8 sizeof_interleaved_files;
__int8 wideof_block_files;
__int32 volume_sequence_number;
__int8 length_ident;
char ident[8];
} __attribute__((packed))
CD_DirectoryItem;
struct CDROM_PrimaryVolumeDescriptor {
unsigned char type;
char ident[5];
unsigned char version;
unsigned char unused_field_1;
char sys_ident[32];
char vol_ident[32];
char unused_field_2[8];
int vol_space_size;
char unused_field_3[32];
int vol_set_size;
int vol_seq_number;
int log_block_size;
int path_table_size;
int location_L_path_table;
int location_L_path_table_optional;
int location_M_path_table;
int location_M_path_table_optional;
char root_directory_record[34];
char volume_set_ident[128];
char publisher_ident[128];
char data_preparer_ident[128];
char application_ident[128];
char copyright_ident[37];
char abstract_file_ident[37];
char bib_file_ident[37];
char volume_creation_date_time[17];
char volume_modification_date_time[17];
char volume_expiration_date_time[17];
char volume_effective_date_time[17];
int file_structure_version;
char reserved_byte;
char application_use[512];
char reserved[653];
} __attribute__((packed)) CD_PrimaryVolume;
struct CDROM_VolumeTerminator {
int type;
char ident[5];
} __attribute__((packed)) CD_VolumeTerminator;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned long long int QWORD;
typedef int BOOL;
const BOOL TRUE = 1;
const BOOL FALSE = 0;
struct CDROM_iso9660_directory_record {
uint8_t record_size;
uint8_t num_sectors_extattrrec;
uint32_t data_sector;
uint32_t data_sector_be;
uint32_t data_size;
uint32_t data_size_be;
WORD year;
BYTE month;
BYTE day;
BYTE hour;
BYTE minute;
BYTE second;
uint8_t flags;
uint8_t interleaved_unit_size;
uint8_t interleaved_gap_size;
uint16_t volume_seq;
uint16_t volume_seq_be;
uint8_t identifier_length;
char identifier[34];
} __attribute__ ((packed)) CD_iso9660_directory_record;
struct disk_packet
{
byte size_pack;
byte reserved1;
byte no_of_blocks;
byte reserved2;
word offset;
word segment;
dword lba1;
dword lba2;
} __attribute__((packed)) disk_pack;
// file system parameters
const BYTE HIDDEN_FLAG = 1;
const BYTE DIRECTORY_FLAG = 2;
struct directory_record
{
WORD version;
WORD sector;
WORD sector_opt1;
WORD sector_opt2;
WORD sector_opt3;
WORD length;
WORD length_opt1;
WORD length_opt2;
WORD length_opt3;
BYTE year;
BYTE month;
BYTE day;
BYTE hour;
BYTE minute;
BYTE second;
BYTE res2;
BYTE flag;
char res3[6];
uint8_t ident_length;
char ident[12];
BYTE padding;
} __attribute__((packed)) DIR_RECORD;
void LBASectorRead(void *buffer, unsigned long lba)
{
unsigned char bError = 0;
REGS regs;
disk_pack.size_pack = 16;
disk_pack.no_of_blocks = 1;
disk_pack.reserved1 = 0;
disk_pack.reserved2 = 0;
disk_pack.segment = (((unsigned int)buffer >> 16) << 12);
disk_pack.offset = ((unsigned int)buffer & 0xffff);
disk_pack.lba2 = lba >> 32;
disk_pack.lba1 = lba & 0xffffffff;
regs.b.ds = (((unsigned int)&disk_pack >> 16) << 12);
regs.b.si = ((unsigned int)&disk_pack &0xffff);
regs.b.dl = 0x9f;
regs.b.ah = 0x42;
int386(0x13,®s,®s);
}
char *malloc_ptr;
void *malloc(int size)
{
void *ret;
ret = (void*)malloc_ptr;
malloc_ptr += size;
return ret;
}
struct StreamHandler
{
int cursorPosition;
char* data;
unsigned int data_size;
};
typedef struct StreamHandler FILE;
void seek(FILE* handle, int bytes)
{
handle->cursorPosition += bytes;
}
char getc(FILE* handle)
{
int pos = handle->cursorPosition;
handle->cursorPosition++;
return handle->data[pos];
}
int read(FILE* handle, char* out, unsigned int bytes)
{
memcpy(out, handle->data + handle->cursorPosition, bytes);
return bytes;
}
#define READ_DIR_SIZE 4
void zeige_dir(void)
{
struct directory_record dr[READ_DIR_SIZE];
FILE *f;
char buffer[2048] = { 0 };
char nil[108];
LBASectorRead(buffer,23);
f->cursorPosition = 0;
f->data = buffer;
f->data_size = sizeof(DIR_RECORD) * READ_DIR_SIZE;
seek(f,108);
read(f,(char*)&dr,sizeof(DIR_RECORD)*3);
int count;
for (count = 0; count < 3; count++)
{
if (dr[count].version <= 0) break;
if (dr[count].flag == 0)
{ dr[count].ident[dr[count].ident_length-2] = '\0'; } else
{ dr[count].ident[dr[count].ident_length-0] = '\0'; }
printf("%02d.%02d.%02d %02d:%02d:%02d %8d %s",
dr[count].day,
dr[count].month,
dr[count].year+1900,
dr[count].hour,
dr[count].minute,
dr[count].second,
dr[count].length,
dr[count].ident); nl();
}
}
#define curpos() \
{ \
if (cur > 80-x0) VideoGotoXY (cur-80+x0, y0+1); \
else VideoGotoXY (x0+cur, y0); \
}
#define MAXCMDLEN 512
static char cmd[MAXCMDLEN];
void edit(void)
{
char c;
unsigned n, cur=0, len=0,
x0 = console_cursor_xpos,
y0 = console_cursor_ypos;
for (;;)
switch (c=ConsoleGetChar())
{
case '\r' : cmd[len]='\0';
printf("\n"); return;
case '\b' : if (cur > 0)
{
cur--; curpos();
for (n=cur; n < len-1; n++)
{
cmd[n]=cmd[n+1];
printf("%c",cmd[n]);
}
printf(" "); len--;
curpos();
}
break;
case 27 : VideoGotoXY (x0,y0); cur=0;
for (n=len+1; n > 0; n--)
printf(" ");
len=0; VideoGotoXY(x0,y0);
break;
case '\f' :
case '\t' : printf("\a");
break;
case 0 : switch (ConsoleGetChar())
{
case 75 : /* links */
if (cur==0) printf("\a");
else cur--;
curpos(); break;
case 77 : /* rechts */
if (cur==len) printf("\a");
else cur++;
curpos(); break;
default : printf("\a");
}
break;
default : {
if (len >= MAXCMDLEN-1)
printf("u");
else
{
cmd[cur++]=c; printf("%c",c);
if (len < cur) len=cur;
if (len > 80-x0 && y0==25)
y0=24;
}
}
}
}
int testint_flag = 0;
extern void testsector(void);
void BootMain(char *boot_cmd)
{
REGS regs;
int i,c,k, pos = 0, cpos = 0;
int puffer_pos = 1;
char line[1024];
short sx = 0,sy=15;
VideoClearScreen(0);
printf("kaBOX Version 0.1 (c) 2005 Jens Kallup"); nl();
printf("BETA-Version!"); nl(); nl();
if (InitializeMemoryManager() == 0) {
printf("Drücken Sie eine Taste zum Neustart des Computers."); nl();
ConsoleGetChar();
VideoClearScreen(0);
return;
}
//RunLoader();
//nl();
//printf("1. --> %d\n", testint_flag);
//int386(0x21,®s,®s);
//printf("2. --> %d\n", testint_flag);
//nl(); // printf("ret from int 21"); nl();
console_cursor_ypos = 15;
console_cursor_xpos = 0;
{
//static unsigned char buffer[2048] = { 0 };
//LBASectorRead(buffer,16);
LBASectorRead(&CD_VolumeDescriptor,16);
zeige_dir();
}
printf("System erfolgreich geladen, bereit fuer Eingabe,\n");
console_cursor_xpos = 0;
for (;;)
{
printf(":>");
edit();
printf("\n-> %s\n",cmd);
}
}