Compare commits
2 Commits
745656eb2d
...
61f1852420
Author | SHA1 | Date | |
---|---|---|---|
61f1852420 | |||
32b0d990df |
@ -5,7 +5,7 @@ BUILD_DIR = ../build/CoreLib
|
|||||||
OBJ_FOLDER = ../bin/CoreLib
|
OBJ_FOLDER = ../bin/CoreLib
|
||||||
OUTPUTFILE = $(BUILD_DIR)/libCoreLib.a
|
OUTPUTFILE = $(BUILD_DIR)/libCoreLib.a
|
||||||
|
|
||||||
OFILES = $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o
|
OFILES = $(OBJ_FOLDER)/ctype.o $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o
|
||||||
|
|
||||||
.phony: all
|
.phony: all
|
||||||
all: $(OUTPUTFILE)
|
all: $(OUTPUTFILE)
|
||||||
@ -15,6 +15,11 @@ $(OUTPUTFILE): $(OFILES)
|
|||||||
pwd
|
pwd
|
||||||
ar -rc $(OUTPUTFILE) $(OFILES)
|
ar -rc $(OUTPUTFILE) $(OFILES)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$(OBJ_FOLDER)/ctype.o: ctype.cpp
|
||||||
|
$(CPP) -c ctype.cpp -o $(OBJ_FOLDER)/ctype.o $(CFLAGS)
|
||||||
|
|
||||||
$(OBJ_FOLDER)/memory.o: Memory.cpp
|
$(OBJ_FOLDER)/memory.o: Memory.cpp
|
||||||
$(CPP) -c Memory.cpp -o $(OBJ_FOLDER)/memory.o $(CFLAGS)
|
$(CPP) -c Memory.cpp -o $(OBJ_FOLDER)/memory.o $(CFLAGS)
|
||||||
|
|
||||||
|
141
CoreLib/ctype.cpp
Normal file
141
CoreLib/ctype.cpp
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
//
|
||||||
|
// Created by nigel on 25/02/23.
|
||||||
|
//
|
||||||
|
#include "ctype.h"
|
||||||
|
|
||||||
|
int isupper (int ch){
|
||||||
|
if( ch >= 'A' && ch <= 'Z'){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int islower (int ch){
|
||||||
|
if(ch >= 'a' && ch <= 'z'){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isalpha (int ch) {
|
||||||
|
if(isupper(ch)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(islower(ch)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int isdigit (int ch){
|
||||||
|
if(ch >= '0' && ch <= '9'){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isxdigit (int ch){
|
||||||
|
if(isdigit(ch)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ch >= 'a' && ch <= 'f'){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ch >= 'A' && ch <= 'F'){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iscntrl (int ch){
|
||||||
|
if(ch >= 0x00 && ch <= 0x1f )
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x7f)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int isgraph (int ch){
|
||||||
|
if(isdigit(ch))
|
||||||
|
return 1;
|
||||||
|
if(isupper(ch))
|
||||||
|
return 1;
|
||||||
|
if(islower(ch))
|
||||||
|
return 1;
|
||||||
|
if(ispunct(ch))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isspace(int ch){
|
||||||
|
if (ch == 0x20)
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x0c)
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x0a)
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x0d)
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x09)
|
||||||
|
return 1;
|
||||||
|
if(ch == 0x0b)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isblank (int ch){
|
||||||
|
if( ch == 0x20 || ch == 0x09)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ispunct(int ch){
|
||||||
|
if(ch >= '!' && ch <= '~')
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isprint (int ch){
|
||||||
|
if (isdigit(ch))
|
||||||
|
return 1;
|
||||||
|
if(isupper(ch))
|
||||||
|
return 1;
|
||||||
|
if(islower(ch))
|
||||||
|
return 1;
|
||||||
|
if(ispunct(ch))
|
||||||
|
return 1;
|
||||||
|
if(isspace(ch))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int tolower(int ch){
|
||||||
|
|
||||||
|
if(islower(ch)) return ch;
|
||||||
|
int diff = 'a' - 'A';
|
||||||
|
return ch + diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
int toupper(int ch){
|
||||||
|
if(isupper(ch)) return ch;
|
||||||
|
int diff = 'a' - 'A';
|
||||||
|
return ch - diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int isalnum (int ch){
|
||||||
|
if(isdigit(ch)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isalpha(ch)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
21
CoreLib/ctype.h
Normal file
21
CoreLib/ctype.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by nigel on 25/02/23.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//NOTE: Uses default locale
|
||||||
|
int isupper (int ch);
|
||||||
|
int islower (int ch);
|
||||||
|
int isalpha (int ch);
|
||||||
|
int isdigit (int ch);
|
||||||
|
int isxdigit (int ch);
|
||||||
|
int iscntrl (int ch);
|
||||||
|
int isgraph(int ch);
|
||||||
|
int isspace(int ch);
|
||||||
|
int isblank(int ch);
|
||||||
|
int ispunct(int ch);
|
||||||
|
int isprint(int ch);
|
||||||
|
int isalnum (int ch);
|
||||||
|
int tolower(int ch);
|
||||||
|
int toupper(int ch);
|
||||||
|
|
@ -122,6 +122,8 @@ extern "C" void kernel ()
|
|||||||
printf(" [Size: %d bytes, Attributes: %d]\n", entry->ATTR, entry->FileSize);
|
printf(" [Size: %d bytes, Attributes: %d]\n", entry->ATTR, entry->FileSize);
|
||||||
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY ){
|
if(entry->ATTR & FAT::ATTRIBUTES::ATTR_DIRECTORY ){
|
||||||
FAT::OpenSubdir(entry, bpb);
|
FAT::OpenSubdir(entry, bpb);
|
||||||
|
} else {
|
||||||
|
FAT::readFile(entry, bpb);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,6 @@ uint16_t FAT::GetFATEntry (BiosParameterBlock* bpb, unsigned int cluster){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t FAT::DetermineFreeSpace()
|
uint16_t FAT::DetermineFreeSpace()
|
||||||
{
|
{
|
||||||
// Loop through all FAT entries in all FAT's
|
// Loop through all FAT entries in all FAT's
|
||||||
@ -180,8 +178,6 @@ unsigned int FAT::RootDirSize(BiosParameterBlock* bpb)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t* ReadFAT (BiosParameterBlock& bpb , bool DEBUG = false ) {
|
uint16_t* ReadFAT (BiosParameterBlock& bpb , bool DEBUG = false ) {
|
||||||
uint32_t FATAddress = /*StartAddress*/ 0x00 + bpb.RsvdSecCnt ;
|
uint32_t FATAddress = /*StartAddress*/ 0x00 + bpb.RsvdSecCnt ;
|
||||||
uint16_t* FAT = (uint16_t*)malloc(sizeof (uint16_t) * 256);
|
uint16_t* FAT = (uint16_t*)malloc(sizeof (uint16_t) * 256);
|
||||||
@ -253,42 +249,29 @@ void FAT::OpenSubdir(DIR* directory, BiosParameterBlock* bpb ){
|
|||||||
printf("LFN\n");
|
printf("LFN\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FAT::readFile(DIR* fileEntry , BiosParameterBlock* bpb){
|
||||||
|
unsigned int cluster = fileEntry->FstClusLo;
|
||||||
|
unsigned int FATEntry = FAT::GetFATEntry(bpb, cluster);
|
||||||
|
unsigned int root_dir_sectors = FAT::RootDirSize(bpb);
|
||||||
|
unsigned int fat_size = bpb->FATSz16;
|
||||||
|
unsigned int first_data_sector = bpb->RsvdSecCnt + (bpb->NumFATs * fat_size) + root_dir_sectors;
|
||||||
|
unsigned int file_data_sector = ((cluster -2) * bpb->SecPerClus) + first_data_sector;
|
||||||
|
printf("FAT entry = %x\n", FATEntry);
|
||||||
|
uint16_t data[256];
|
||||||
|
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, file_data_sector, data);
|
||||||
|
|
||||||
void readFile(uint32_t DataRegion, DIR* entry, uint16_t FATentry, BiosParameterBlock& bpb ){
|
for (unsigned short n : data)
|
||||||
printf("Show contents");
|
{
|
||||||
|
|
||||||
printf("Start cluster of the file: 0x%x\n", entry->FileSize);
|
|
||||||
|
|
||||||
printf("IS it only 1 cluster? %s\n", FATentry == 0xFFFF ? "Yes" : "No");
|
|
||||||
|
|
||||||
uint32_t sector = DataRegion + ((entry->FileSize - 0x02) * bpb.SecPerClus);
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t dataBlob[256];
|
|
||||||
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob);
|
|
||||||
for (unsigned short n: dataBlob) {
|
|
||||||
kterm_put(n & 0x00ff);
|
kterm_put(n & 0x00ff);
|
||||||
|
|
||||||
kterm_put(n >> 8);
|
kterm_put(n >> 8);
|
||||||
}
|
}
|
||||||
kterm_put('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
file fsysFatDirectory (const char* DirectoryName){
|
file fsysFatDirectory (const char* DirectoryName){
|
||||||
file file;
|
file file;
|
||||||
|
@ -83,6 +83,7 @@ public:
|
|||||||
static int GetSectorOfRootDirectory(BiosParameterBlock*);
|
static int GetSectorOfRootDirectory(BiosParameterBlock*);
|
||||||
static unsigned int RootDirSize(BiosParameterBlock*);
|
static unsigned int RootDirSize(BiosParameterBlock*);
|
||||||
static void OpenSubdir (DIR*, BiosParameterBlock*);
|
static void OpenSubdir (DIR*, BiosParameterBlock*);
|
||||||
|
static void readFile(DIR*, BiosParameterBlock*);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user