diff --git a/.gitignore b/.gitignore index 60b8d17..52e078a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /sys/sde/ogFont.cpp /sys/sde/ogPixCon.cpp /sys/sde/ogPixelFmt.cpp +/sys/sde/ogImage.cpp diff --git a/Makefile b/Makefile index 7352c06..2c0089b 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ WORLD_LIB_SRC=${CURDIR}/lib WORLD_LIBEXEC_SRC=${CURDIR}/libexec WORLD_BIN_SRC=${CURDIR}/bin -WORLD_INC="-I${CURDIR}/include_old -I${CURDIR}/lib/objgfx40/" +WORLD_INC="-I${CURDIR}/include_old -I${CURDIR}/lib/objgfx40/ -I${CURDIR}/lib/libcpp/include" WORLD_FLAGS=_ARCH=${_ARCH} CC="cc" CXX="c++" AS="as" AR="ar" LD="ld" NM=nm OBJDUMP= OBJCOPY="objcopy" RANLIB=ranlib WMAKE= ${MAKE} ${WORLD_FLAGS} INCLUDE=${WORLD_INC} BUILD_DIR=${CURDIR}/build diff --git a/bin/login/main.c b/bin/login/main.c index 503f96a..078b6a6 100644 --- a/bin/login/main.c +++ b/bin/login/main.c @@ -71,6 +71,7 @@ char passWord[32]; char *data2 = 0x0; struct passwd *data = 0x0; + int users = 0; if ((getuid() != 0x0) && (getgid() != 0x0)) { @@ -89,7 +90,8 @@ exit(0x1); } - fread(data,0x1000,0x1,fd); + users = fread(data,0x1000,0x1,fd) / sizeof(struct passwd); + fclose(fd); @@ -98,23 +100,20 @@ exit(0x1); } -/* we need to move this into the libc for getpwent(), etc */ -/* - foo = auth("root", "user"); - if(foo != -1) - printf("yay\n"); - else - printf("damn\n"); -*/ - login: printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)"); + getUsername: printf("\n\nLogin: "); gets((char *)&userName); + + if (userName[0] == '\0') + goto getUsername; + printf("Password: "); pgets((char *)&passWord); - for (i=0x0;i<(4096/sizeof(struct passwd));i++) { + + for (i=0x0;iClear(window->Pack(i,ii,iii)); - window->FillRect(50, 50, 100, 100, window->Pack(255, 0, 0)); - window->FillRect(50, 50, 100, 100, window->Pack(255, 0, 0)); - window->FillRect(100, 50, 150, 100, window->Pack(0, 255, 0)); - window->FillRect(150, 50, 200, 100, window->Pack(0, 0, 255)); - window->FillRect(200, 50, 250, 100, window->Pack(0, 0, 0)); - window->FillRect(250, 50, 300, 100, window->Pack(255, 255, 255)); + window->ogClear(window->ogPack(i,ii,iii)); + window->ogFillRect(50, 50, 100, 100, window->ogPack(255, 0, 0)); + window->ogFillRect(50, 50, 100, 100, window->ogPack(255, 0, 0)); + window->ogFillRect(100, 50, 150, 100, window->ogPack(0, 255, 0)); + window->ogFillRect(150, 50, 200, 100, window->ogPack(0, 0, 255)); + window->ogFillRect(200, 50, 250, 100, window->ogPack(0, 0, 0)); + window->ogFillRect(250, 50, 300, 100, window->ogPack(255, 255, 255)); window->vSDECommand(3); } } diff --git a/bin/shell/commands.c b/bin/shell/commands.c index de753b1..69cf81d 100644 --- a/bin/shell/commands.c +++ b/bin/shell/commands.c @@ -131,7 +131,7 @@ } } else if (memcmp(data->args->arg,"msg",3) == 0x0) { - printf("Posting Message\n"); + printf("Posting Message: mbox(%s), header: 0x%X, data: %s\n", argv[2], atoi(argv[3]), argv[4]); cmdMsg.header = atoi(argv[3]); sprintf(cmdMsg.data,argv[4]); mpi_postMessage(argv[2],0x1,&cmdMsg); diff --git a/lib/Makefile b/lib/Makefile index 1d10476..3a2853e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,7 +1,7 @@ # $Id: Makefile 121 2016-01-14 03:18:20Z reddawg $ # The System Makefile (C) 2002 The UbixOS Project -all: csu-code ubix_api-code libc_old-code ubix-code #libc-code# libcpp-code +all: csu-code ubix_api-code libc_old-code ubix-code libcpp-code objgfx40-code #libc-code# libcpp-code # bin tools # depend kernel tools @@ -17,7 +17,7 @@ libc-code: libc (cd libc;make) -objgfx40: src +objgfx40-code: objgfx40 (cd objgfx40;make) views: src diff --git a/lib/libcpp/Makefile b/lib/libcpp/Makefile index 628f53c..ac98e64 100644 --- a/lib/libcpp/Makefile +++ b/lib/libcpp/Makefile @@ -2,14 +2,16 @@ # $Id: Makefile 89 2016-01-12 00:20:40Z reddawg $ # Include Global 'Source' Options -Makefile.incl -Makefile.incl +include ../../Makefile.incl +include ../Makefile.incl + # Objects OBJS = libcpp.o #Include -INCLUDE = -I../../include -I./include -I../libc/include +INCLUDE += -I../libcpp/include/ +#-I../../include -I./include -I../libc/include all: $(OBJS) diff --git a/lib/libcpp/libcpp.cc b/lib/libcpp/libcpp.cc index 1132e8b..3fe8825 100644 --- a/lib/libcpp/libcpp.cc +++ b/lib/libcpp/libcpp.cc @@ -3,6 +3,15 @@ /* Don't Touch Mark */ void __pure_virtual() { while(1); } void __cxa_pure_virtual() { while(1); } + void __dso_handle() { + while (1) + asm("nop"); + } + + /* Don't plan on exiting the kernel...so do nothing. */ + int __cxa_atexit(void (*func)(void *), void * arg, void * d) { + return 0; + } } #include @@ -32,5 +41,7 @@ return; } + + /* End Don't Touch */ diff --git a/lib/objgfx40/Makefile b/lib/objgfx40/Makefile index a4cea4a..1bbff37 100644 --- a/lib/objgfx40/Makefile +++ b/lib/objgfx40/Makefile @@ -1,14 +1,16 @@ # $Id: Makefile 89 2016-01-12 00:20:40Z reddawg $ # Kernel Makefile (C) 2002 The UbixOS Project -Makefile.incl -Makefile.incl +# Include Global 'Source' Options +include ../../Makefile.incl +include ../Makefile.incl #Delete Program REMOVE = rm -f #Objects -OBJS = objgfx40.o ogFont.o ogSprite.o ogBlit.o ogPixCon.o ogPixelFmt.o +OBJS = objgfx40.o ogFont.o ogSprite.o ogPixCon.o ogPixelFmt.o +#ogBlit.o #Include INCLUDE = -I./ -I../../lib/libc/include -I../../lib/libcpp/include diff --git a/lib/objgfx40/objgfx40/ogImage.h b/lib/objgfx40/objgfx40/ogImage.h new file mode 100644 index 0000000..4852061 --- /dev/null +++ b/lib/objgfx40/objgfx40/ogImage.h @@ -0,0 +1,140 @@ +// ogImage.h + +#pragma once +#include "objgfx40.h" + + +class mstream : public std::basic_streambuf +{ +public: + mstream(char* p, std::streamsize n) { + setg(p, p, p + n); + setp(p, p + n); + } // mStream::mStream() +}; // class mstream + +class ogHeaderAbstract +{ +public: + virtual bool Deserialize(std::istream&) = 0; + virtual bool Serialize(std::ostream&) = 0; + virtual bool IsMatch() { return false; } + virtual std::string ToString() { return ""; } + virtual size_t Size() = 0; + virtual ~ogHeaderAbstract() {}; +}; // class ogHeader + +class Win3xBitmapHeader : public ogHeaderAbstract +{ +public: + uInt16 ImageFileType; // Image file type, always 4D42h ("BM") + uInt32 FileSize; // Physical size in bytes + uInt16 Reserved1; // Always 0 + uInt16 Reserved2; // Always 0 + uInt32 ImageDataOffset; // Start of image data offset in bytes + Win3xBitmapHeader() : + ImageFileType(0), + FileSize(0), + Reserved1(0), + Reserved2(0), + ImageDataOffset(0) {} + bool Deserialize(std::istream&); + std::string ToString(); + + bool IsMatch(); + bool Serialize(std::ostream&); + size_t Size(); +}; // class Win3xBitmapHeader + +class RGBQuad : public ogHeaderAbstract +{ +public: + uInt8 rgbBlue; + uInt8 rgbGreen; + uInt8 rgbRed; + uInt8 rgbReserved; + RGBQuad() : + rgbBlue(0), + rgbGreen(0), + rgbRed(0), + rgbReserved(0) {}; + RGBQuad(ogRGBA8 paletteEntry) : + rgbBlue(paletteEntry.blue), + rgbGreen(paletteEntry.green), + rgbRed(paletteEntry.red), + rgbReserved(0) {}; + bool Deserialize(std::istream&); + bool Serialize(std::ostream&); + size_t Size(); + std::string ToString(); +}; // class RGBQuad + +class Win3xBitmapInfoHeader : public ogHeaderAbstract +{ +public: + uInt32 HeaderSize; // Size of this header + uInt32 ImageWidth; // Image width in pixels + uInt32 ImageHeight; // Image height in pixels + uInt16 NumberOfImagePlanes; // Number of planes (always 1) + uInt16 BitsPerPixel; // Bits per pixel (1, 4, 8, or 24) + uInt32 CompressionMethod; // Compression method used (0, 1, or 2) + uInt32 SizeOfBitmap; // Size of the bitmap in bytes + uInt32 HorzResolution; // Horizontal resolution in pixels per meter + uInt32 VertResolution; // Vertical resolution in pixels per meter + uInt32 NumColoursUsed; // Number of colours in the image + uInt32 NumSignificantColours; // Number of important colours in palette + Win3xBitmapInfoHeader() : + HeaderSize(0), + ImageWidth(0), + ImageHeight(0), + NumberOfImagePlanes(0), + BitsPerPixel(0), + CompressionMethod(0), + SizeOfBitmap(0), + HorzResolution(0), + VertResolution(0), + NumColoursUsed(0), + NumSignificantColours(0) { }; + bool Deserialize(std::istream&); + std::string ToString(); + bool IsMatch(); + bool Serialize(std::ostream&); + size_t Size(); +}; // class Win3xBitmapInfoHeader + +union ogImageOptions +{ +}; + +enum ogImageType { NoImage, BMP }; + +class ogImage +{ +private: + static std::map > IsImage; +protected: + ogSurface * surface; + ogImageOptions * options; + std::ostream * output; + std::istream * input; + + std::map Decode; + std::map Encode; + + bool NoOp() { return false; } + + bool DecodeBMP(); + + bool EncodeBMP(); + +public: + static ogImageType ImageType(std::istream&); + static ogImageType ImageType(const std::string& filename); + ogImage(); + bool Load(const std::string& filename, ogSurface & surface); + bool Load(std::istream&, ogSurface&); + bool Save(const std::string& filename, ogSurface& surface, ogImageType, ogImageOptions * options = NULL); + bool Save(std::ostream&, ogSurface&, ogImageType, ogImageOptions * options = NULL); +}; // class ogImage + + diff --git a/lib/objgfx40/ogBlit.cpp b/lib/objgfx40/ogBlit.cpp index 04f5388..409b916 100644 --- a/lib/objgfx40/ogBlit.cpp +++ b/lib/objgfx40/ogBlit.cpp @@ -327,7 +327,7 @@ uInt8 lineCount, offset, pixCount; uInt32 nsy, ney; uInt8 *blitMaskPtr; - void *imagePtr; + uint8_t *imagePtr; uInt32 distToEdge, xRight, count; ogPixelFmt pixFmt; @@ -372,16 +372,16 @@ image = malloc(imageSize); } // if - imagePtr = image; + imagePtr = (uint8_t *)image; // If any part of the blit data is out of bounds, we need to fill it with the // transparent colour if ( (x + startX < 0) || (x + endX > (int32)src.ogGetMaxX()) || (y + startY < 0) || (y + endY > (int32)src.ogGetMaxY())) { for (count = 0; count < totalPixCount; count++) { SetPixel(imagePtr, tColour); - (uInt8 *)imagePtr += bytesPerPixel; + imagePtr += bytesPerPixel; } // for count - imagePtr = image; // reset the image pointer + imagePtr = (uint8_t *)image; // reset the image pointer } // if // first do clipping on the top edge @@ -401,7 +401,7 @@ ++blitMaskPtr; pixCount = *blitMaskPtr; ++blitMaskPtr; - if (pixCount > 0) (uInt8 *)imagePtr += pixCount*bytesPerPixel; + if (pixCount > 0) imagePtr += pixCount*bytesPerPixel; --lineCount; } // while } // for sy @@ -429,7 +429,7 @@ if (sx <= (int32)src.ogGetMaxX()) { if ((sx < 0) && (sx+pixCount > 0)) { pixCount += sx; // remember, sx is negative - (uInt8*)imagePtr -= sx*bytesPerPixel; // remember, sx is negative + imagePtr -= sx*bytesPerPixel; // remember, sx is negative sx = 0; } // if sx<0 && sx+pixcount>0 @@ -442,11 +442,11 @@ if (sx >= 0) src.ogCopyLineFrom(sx, y+sy, imagePtr, pixCount*bytesPerPixel); - (uInt8*)imagePtr += xRight; // get any remainter from right edge clip + imagePtr += xRight; // get any remainter from right edge clip } // if sx <= MaxX sx += pixCount; - (uInt8*)imagePtr += pixCount*bytesPerPixel; + imagePtr += pixCount*bytesPerPixel; } // if pixCount>0 --lineCount; @@ -654,7 +654,7 @@ ++blitMaskPtr; pixCount = *blitMaskPtr; ++blitMaskPtr; - if (pixCount > 0) (uInt8 *)imagePtr += pixCount*bytesPerPixel; + if (pixCount > 0) imagePtr += pixCount*bytesPerPixel; --lineCount; } // while } // for sy diff --git a/lib/objgfx40/ogImage.cpp b/lib/objgfx40/ogImage.cpp new file mode 100644 index 0000000..6a9660d --- /dev/null +++ b/lib/objgfx40/ogImage.cpp @@ -0,0 +1,588 @@ +#include +#include + + +#ifndef __UBIXOS_KERNEL__ +extern "C" { +#include +#include +#include +#include +} +#endif + +#ifdef __UBIXOS_KERNEL__ +extern "C" { +#include +#include +#include +#include +} + + +bool Win3xBitmapHeader::Deserialize(std::istream& stream) +{ + if (!stream) return false; + + // Read in each field, and check for any failure. Return false on failure + if (!stream.read(reinterpret_cast(&ImageFileType), sizeof(ImageFileType))) return false; + if (!stream.read(reinterpret_cast(&FileSize), sizeof(FileSize))) return false; + if (!stream.read(reinterpret_cast(&Reserved1), sizeof(Reserved1))) return false; + if (!stream.read(reinterpret_cast(&Reserved2), sizeof(Reserved2))) return false; + if (!stream.read(reinterpret_cast(&ImageDataOffset), sizeof(ImageDataOffset))) return false; + + return true; +} // bool Win3xBitmapHeader::Deserialize() + +std::string Win3xBitmapHeader::ToString() +{ + return + "ImageFileType = " + std::to_string(ImageFileType) + "\r\n" + + "FileSize = " + std::to_string(FileSize) + "\r\n" + + "Reserved1 = " + std::to_string(Reserved1) + "\r\n" + + "Reserved2 = " + std::to_string(Reserved2) + "\r\n" + + "ImageDataOffset = " + std::to_string(ImageDataOffset) + "\r\n"; +} // string Win3xBitmapHeader::ToString() + +bool Win3xBitmapHeader::IsMatch() +{ + return + (ImageFileType == 0x4D42 && + FileSize != 0 && + Reserved1 == 0 && + Reserved2 == 0 && + ImageDataOffset != 0); +} // bool Win3xBitmapHeader::IsMatch() + +bool Win3xBitmapHeader::Serialize(std::ostream& stream) +{ + if (!stream) return false; + + // Read in each field, and check for any failure. Return false on failure + if (!stream.write(reinterpret_cast(&ImageFileType), sizeof(ImageFileType))) return false; + if (!stream.write(reinterpret_cast(&FileSize), sizeof(FileSize))) return false; + if (!stream.write(reinterpret_cast(&Reserved1), sizeof(Reserved1))) return false; + if (!stream.write(reinterpret_cast(&Reserved2), sizeof(Reserved2))) return false; + if (!stream.write(reinterpret_cast(&ImageDataOffset), sizeof(ImageDataOffset))) return false; + + return true; +} // bool Win3xBitmapHeader::Serialize() + +size_t Win3xBitmapHeader::Size() +{ + return + sizeof(ImageFileType) + + sizeof(FileSize) + + sizeof(Reserved1) + + sizeof(Reserved2) + + sizeof(ImageDataOffset); +} // size_t Win3xBitmapHeader::Size() + +bool Win3xBitmapInfoHeader::Deserialize(std::istream& stream) +{ + if (!stream) return false; + + // Read in each field, and check for any failure. Return false on failure + if (!stream.read(reinterpret_cast(&HeaderSize), sizeof(HeaderSize))) return false; + if (!stream.read(reinterpret_cast(&ImageWidth), sizeof(ImageWidth))) return false; + if (!stream.read(reinterpret_cast(&ImageHeight), sizeof(ImageHeight))) return false; + if (!stream.read(reinterpret_cast(&NumberOfImagePlanes), sizeof(NumberOfImagePlanes))) return false; + if (!stream.read(reinterpret_cast(&BitsPerPixel), sizeof(BitsPerPixel))) return false; + if (!stream.read(reinterpret_cast(&CompressionMethod), sizeof(CompressionMethod))) return false; + if (!stream.read(reinterpret_cast(&SizeOfBitmap), sizeof(SizeOfBitmap))) return false; + if (!stream.read(reinterpret_cast(&HorzResolution), sizeof(HorzResolution))) return false; + if (!stream.read(reinterpret_cast(&VertResolution), sizeof(VertResolution))) return false; + if (!stream.read(reinterpret_cast(&NumColoursUsed), sizeof(NumColoursUsed))) return false; + if (!stream.read(reinterpret_cast(&NumSignificantColours), sizeof(NumSignificantColours))) return false; + + return true; +} // bool Win3xBitmapInfoHeader::Deserialize() + +std::string Win3xBitmapInfoHeader::ToString() +{ + return + "HeaderSize = " + std::to_string(HeaderSize) + "\r\n" + + "ImageWidth = " + std::to_string(ImageWidth) + "\r\n" + + "ImageHeight = " + std::to_string(ImageHeight) + "\r\n" + + "NumberOfImagePlanes = " + std::to_string(NumberOfImagePlanes) + "\r\n" + + "BitsPerPixel = "+ std::to_string(BitsPerPixel) + "\r\n" + + "CompressionMethod = " + std::to_string(CompressionMethod) + "\r\n" + + "SizeOfBitmap = " + std::to_string(SizeOfBitmap) + "\r\n" + + "HorzResolution = " + std::to_string(HorzResolution) + "\r\n" + + "VertResolution = " + std::to_string(VertResolution) + "\r\n" + + "NumColoursUsed = " + std::to_string(NumColoursUsed) + "\r\n" + + "NumSignificantColours = " + std::to_string(NumSignificantColours) + "\r\n"; +} // string Win3xBitmapInfoHeader::ToString() + +bool Win3xBitmapInfoHeader::IsMatch() +{ + return + (HeaderSize != 0 && + ImageWidth != 0 && + ImageHeight != 0 && + CompressionMethod == 0 && + (BitsPerPixel == 8 || BitsPerPixel == 24)); +} +bool Win3xBitmapInfoHeader::Serialize(std::ostream& stream) +{ + if (!stream) return false; + + // Read in each field, and return false on failure + if (!stream.write(reinterpret_cast(&HeaderSize), sizeof(HeaderSize))) return false; + if (!stream.write(reinterpret_cast(&ImageWidth), sizeof(ImageWidth))) return false; + if (!stream.write(reinterpret_cast(&ImageHeight), sizeof(ImageHeight))) return false; + if (!stream.write(reinterpret_cast(&NumberOfImagePlanes), sizeof(NumberOfImagePlanes))) return false; + if (!stream.write(reinterpret_cast(&BitsPerPixel), sizeof(BitsPerPixel))) return false; + if (!stream.write(reinterpret_cast(&CompressionMethod), sizeof(CompressionMethod))) return false; + if (!stream.write(reinterpret_cast(&SizeOfBitmap), sizeof(SizeOfBitmap))) return false; + if (!stream.write(reinterpret_cast(&HorzResolution), sizeof(HorzResolution))) return false; + if (!stream.write(reinterpret_cast(&VertResolution), sizeof(VertResolution))) return false; + if (!stream.write(reinterpret_cast(&NumColoursUsed), sizeof(NumColoursUsed))) return false; + if (!stream.write(reinterpret_cast(&NumSignificantColours), sizeof(NumSignificantColours))) return false; + + return true; +} // bool Win3xBitmapInfoHeader::Serialize() + +size_t Win3xBitmapInfoHeader::Size() +{ + return + sizeof(HeaderSize) + + sizeof(ImageWidth) + + sizeof(ImageHeight) + + sizeof(NumberOfImagePlanes) + + sizeof(BitsPerPixel) + + sizeof(CompressionMethod) + + sizeof(SizeOfBitmap) + + sizeof(HorzResolution) + + sizeof(VertResolution) + + sizeof(NumColoursUsed) + + sizeof(NumSignificantColours); +} // size_t Win3xBitmapInfoHeader::Size() + +bool RGBQuad::Deserialize(std::istream& stream) +{ + if (!stream) return false; + + // Read in each field, and return false on failure + if (!stream.read(reinterpret_cast(&rgbBlue), sizeof(rgbBlue))) return false; + if (!stream.read(reinterpret_cast(&rgbGreen), sizeof(rgbGreen))) return false; + if (!stream.read(reinterpret_cast(&rgbRed), sizeof(rgbRed))) return false; + if (!stream.read(reinterpret_cast(&rgbReserved), sizeof(rgbReserved))) return false; + + return true; +} // bool RGBQuad::Deserialize() + +std::string RGBQuad::ToString() +{ + return "rgbRed = " + to_string(rgbRed) + "\r\n" + + "rgbGreen = " + to_string(rgbGreen) + "\r\n" + + "rgbBlue = " + to_string(rgbBlue) + "\r\n" + + "rgbReserved = " + to_string(rgbReserved) + "\r\n"; +} // string RGBQuad::ToString() + +bool RGBQuad::Serialize(std::ostream& stream) +{ + if (!stream) return false; + + // Read in each field, and return false on failure + if (!stream.write(reinterpret_cast(&rgbBlue), sizeof(rgbBlue))) return false; + if (!stream.write(reinterpret_cast(&rgbGreen), sizeof(rgbGreen))) return false; + if (!stream.write(reinterpret_cast(&rgbRed), sizeof(rgbRed))) return false; + if (!stream.write(reinterpret_cast(&rgbReserved), sizeof(rgbReserved))) return false; + + return true; +} // bool RGBQuad::Serialize() +size_t RGBQuad::Size() +{ + return + sizeof(rgbBlue) + + sizeof(rgbGreen) + + sizeof(rgbRed) + + sizeof(rgbReserved); +} // size_t RGBQuad::Size() + +bool IsBMP(std::istream& stream) +{ + + // Check for BMP + Win3xBitmapHeader bmpHeader; + bmpHeader.Deserialize(stream); + Win3xBitmapInfoHeader bmpInfoHeader; + bmpInfoHeader.Deserialize(stream); + + if (bmpHeader.IsMatch() && bmpInfoHeader.IsMatch()) + { + std::cout << bmpHeader.ToString(); + std::cout << bmpInfoHeader.ToString(); + return true; + } + return false; +} // bool IsBMP() + +/********************************************** + * ogImage + **********************************************/ +static const std::map>& CreateIsImageMap() +{ + static std::map> IsImage; + + //IsImage[NoImage] = ([&](std::istream&) -> bool { return false; }); + IsImage[BMP] = &IsBMP; + return IsImage; +} // map<> CreateIsImageMap() + +std::map> ogImage::IsImage = CreateIsImageMap(); + +ogImage::ogImage() : + surface(nullptr), + options(nullptr), + input(nullptr), + output(nullptr) +{ + Decode[NoImage] = &ogImage::NoOp; + Decode[BMP] = &ogImage::DecodeBMP; + + Encode[NoImage] = &ogImage::NoOp; + Encode[BMP] = &ogImage::EncodeBMP; + +} // ogImage::ogImage() + +bool ogImage::DecodeBMP() +{ + // ogImage::ImageType() has determined we're a BMP, so we only need to do + // minimal sanity checks on the header information. + + Win3xBitmapHeader bmpHeader; + Win3xBitmapInfoHeader bmpInfoHeader; + if (!bmpHeader.Deserialize(*input)) return false; + if (!bmpInfoHeader.Deserialize(*input)) return false; + + size_t lineSize; + size_t paddington; + char linePadding[4]; + + if (bmpInfoHeader.BitsPerPixel == 8) + { + if (!surface->ogCreate(bmpInfoHeader.ImageWidth, bmpInfoHeader.ImageHeight, OG_PIXFMT_8BPP)) return false; + + lineSize = ((bmpInfoHeader.ImageWidth+3) >> 2) << 2; // round up to the nearest 4 bytes + paddington = lineSize - bmpInfoHeader.ImageWidth; // see if we have a remainder + + if (paddington > 4) return false; // this would be odd + + RGBQuad quad; + for (unsigned colour = 0; colour < 256; colour++) + { + if (!quad.Deserialize(*input)) return false; + surface->ogSetPalette(colour, quad.rgbRed, quad.rgbGreen, quad.rgbBlue, quad.rgbReserved); + } // for colour + + for (unsigned y = surface->ogGetMaxY()+1; y --> 0 ;) // y goes to 0 + { + char * ptr = reinterpret_cast(surface->ogGetPtr(0, y)); + if (ptr == nullptr) return false; // this doesn't have to be a complete failure, fix later + if (!input->read(ptr, bmpInfoHeader.ImageWidth)) return false; + if (paddington != 0) + { + if (!input->read(linePadding, paddington)) return false; // double check this + } + } // for y + } + else if (bmpInfoHeader.BitsPerPixel == 24) + { + ogPixelFmt BMPPixelFmt(24, 16,8,0,0, 8,8,8,0); + if (!surface->ogCreate(bmpInfoHeader.ImageWidth, bmpInfoHeader.ImageHeight, OG_PIXFMT_24BPP)) return false; + size_t widthInBytes = bmpInfoHeader.ImageWidth*3; // 3 represents how many bytes per pixel + lineSize = ((widthInBytes+3) >> 2) << 2; // round up to the nearest 4 bytes + paddington = lineSize - widthInBytes; // see if we have a remainder + + if (paddington > 4) return false; + + for (unsigned y = surface->ogGetMaxY()+1; y --> 0 ;) + { + char * ptr = reinterpret_cast(surface->ogGetPtr(0, y)); + if (ptr == nullptr) return false; // this doesn't have to be a complete failure, fix later + if (!input->read(ptr, widthInBytes)) return false; + if (paddington != 0) + { + if (!input->read(linePadding, paddington)) return false; + } + } // for y + } + + return true; +} // bool ogImage::DecodeBMP() + +bool ogImage::EncodeBMP() +{ + Win3xBitmapHeader bmpHeader; + Win3xBitmapInfoHeader bmpInfoHeader; + size_t paddington; + size_t lineSize; + const char linePadding[4] = {0,0,0,0}; + ogRGBA8 ogPalette[256]; // used to get the palette from the surface + + bmpHeader.ImageFileType = 0x4D42; + bmpHeader.FileSize = 0; // fill in later + //bmpHeader.Reserved1 = 0; // set by constructor + //bmpHeader.Reserved2 = 0; // set by constructor + bmpHeader.ImageDataOffset = bmpHeader.Size() + bmpInfoHeader.Size(); + + bmpInfoHeader.HeaderSize = bmpInfoHeader.Size(); + bmpInfoHeader.ImageWidth = surface->ogGetMaxX()+1; + bmpInfoHeader.ImageHeight = surface->ogGetMaxY()+1; + bmpInfoHeader.NumberOfImagePlanes = 1; + // bmpInfoHeader.BitsPerPixel is set below + bmpInfoHeader.CompressionMethod = 0; + bmpInfoHeader.SizeOfBitmap = 0; + bmpInfoHeader.HorzResolution = 0; // option + bmpInfoHeader.VertResolution = 0; // option + + switch (surface->ogGetBPP()) + { + case 8: + bmpInfoHeader.BitsPerPixel = 8; // 8bpp, 256 colours + bmpInfoHeader.NumColoursUsed = 1 << surface->ogGetBPP(); + bmpInfoHeader.NumSignificantColours = 0; // option + + // This is hard to calculate dynamically. Sod it. + bmpHeader.ImageDataOffset += 1024;// adjust by palette size + + lineSize = ((bmpInfoHeader.ImageWidth+3) >> 2) << 2; // multiple of 4 + bmpInfoHeader.SizeOfBitmap = lineSize*bmpInfoHeader.ImageHeight; + bmpHeader.FileSize = bmpHeader.ImageDataOffset+bmpInfoHeader.SizeOfBitmap; + + // Write the headers + if (!bmpHeader.Serialize(*output)) return false; + if (!bmpInfoHeader.Serialize(*output)) return false; + + // all rows are aligned to the nearest 4 bytes. Figure out if we need to pad. + paddington = lineSize-bmpInfoHeader.ImageWidth; + + surface->ogGetPalette(ogPalette); + + for (size_t index = 0; index < sizeof(ogPalette) / sizeof(ogPalette[0]); index++) + { + RGBQuad quad(ogPalette[index]); + if (!quad.Serialize(*output)) return false; + } // for index + + for (unsigned y = surface->ogGetMaxY()+1; y --> 0 ;) // y goes to 0 + { + char * ptr = reinterpret_cast(surface->ogGetPtr(0, y)); + if (ptr != nullptr) + { + if (!output->write(ptr, bmpInfoHeader.ImageWidth)) return false; + } + + // Is there any padding to add to the end of the line? + if (paddington != 0) + { + if (!output->write(linePadding, paddington)) return false; + } + } // for y + break; + case 32: + case 24: + case 16: + case 15: + // 15, 16, and 32 bpp are all treated as 24bpp + bmpInfoHeader.BitsPerPixel = 24; + bmpInfoHeader.NumColoursUsed = 0; + bmpInfoHeader.NumSignificantColours = 0; + + lineSize = ((bmpInfoHeader.ImageWidth*3+3) >> 2) << 2; + bmpInfoHeader.SizeOfBitmap = lineSize*bmpInfoHeader.ImageHeight; + bmpHeader.FileSize = bmpHeader.ImageDataOffset+bmpInfoHeader.SizeOfBitmap; + + // Write the headers + if (!bmpHeader.Serialize(*output)) return false; + if (!bmpInfoHeader.Serialize(*output)) return false; + + // all rows are aligned to the nearest 4 bytes. Figure out if we need to pad. + paddington = lineSize-bmpInfoHeader.ImageWidth*3; // 3 represents how many bytes per pixel + uInt8 red, green, blue; + + for (unsigned y = surface->ogGetMaxY()+1; y --> 0 ;) // y goes to 0 + { + for (unsigned x = 0; x <= surface->ogGetMaxX(); x++) + { + // Unpack the pixel and write it out. + surface->ogUnpack(surface->ogGetPixel(x, y), red, green, blue); + if (!output->write(reinterpret_cast(&blue), sizeof(blue))) return false; + if (!output->write(reinterpret_cast(&green), sizeof(green))) return false; + if (!output->write(reinterpret_cast(&red), sizeof(red))) return false; + } // for x + + // Is there any padding to add to the end of the line? + if (paddington != 0) + { + if (!output->write(linePadding, paddington)) return false; + } + } // for y + break; + default: + return false; // we can't encode anything else (I'm not sure there *is* anything else) + } // switch + + + return true; +} // bool ogImage::EncodeBMP() + +ogImageType ogImage::ImageType(std::istream& input) +{ + ogImageType imageType = NoImage; + // space for the header + char header[128]; // This really should be as large as the largest header we know of + + for (size_t index = 0; index < std::extent::value; index++) + { + header[index] = 0; // clear the header + } // for index + + size_t size = sizeof(header); + + if (!input.read(header, size)) return NoImage; // This isn't necessarily true. Might just be a small image. + // Figure out how many bytes we read in. + streamsize bytesRead = input.gcount(); + + if (bytesRead != 0) + { + + // Try to determine what it really is + for (auto iType : IsImage) + { + mstream mb(header, bytesRead); + // This creates a new istream from a memory stream, + // which is wrapped adound the header. + //istream stream(&mstream(header, bytesRead)); + istream stream(&mb); + if (iType.second(stream)) // Did we find it? + { + imageType = iType.first; // Found it + break; + } // if + } // for iType + + // Now seek backwards in the stream. + input.seekg(-bytesRead, std::ios_base::cur); + } + + return imageType; +} // ogImageType ogImage::ImageType() + +ogImageType ogImage::ImageType(const std::string& filename) +{ + std::ifstream input(filename, ios::in | std::ios_base::binary); + ogImageType imageType = NoImage; + + // Sanity check + if (input) + { + // Use the stream version + imageType = ogImage::ImageType(input); + + // close the file + input.close(); + } // if + + return imageType; +} // ogImageType ogImage::ImageType() + +bool ogImage::Load(const std::string& filename, ogSurface & surface) +{ + std::cout << "Loading " << filename << std::endl; + bool success = false; // assume failure + + ifstream stream(filename, ios_base::in | ios_base::binary); + + if (stream) + { + success = Load(stream, surface); + stream.close(); + } // if stream + + return success; +} // ogSurface * ogImage::Load() + +bool ogImage::Load(std::istream& stream, ogSurface& surface) +{ + // First we need to find out what type of graphics file it is: + ogImageType imageType = ogImage::ImageType(stream); + + if (imageType == NoImage) return false; + + this->surface = &surface; + this->input = &stream; + this->options = nullptr; // shouldn't be necessary + this->output = nullptr; // shouldn't be necessary + + assert(Decode.count(imageType) == 1); // make sure we can handle it + + return (this->*Decode[imageType])(); // Decode +} // bool ogImage::Load() + +bool ogImage::Save(const std::string& filename, + ogSurface &surface, + ogImageType imageType, + ogImageOptions * options) +{ + bool success = false; // assume failure + + ofstream stream(filename, ios_base::out | ios_base::binary); // try to open the file + + if (stream) + { + // Use the stream version + success = Save(stream, surface, imageType, options); + + // close the file + stream.close(); + } // if + + return success; +} // bool ogImage::Save() + +bool ogImage::Save(std::ostream& stream, + ogSurface &surface, + ogImageType imageType, + ogImageOptions * options) +{ + bool success = false; // assume failure + + if (stream && surface.ogAvail()) + { + // Since surface is a reference, it cannot [normally] be null, + // so no checking needs to be done in any of the encoder functions. + this->surface = &surface; + this->options = options; + this->output = &stream; + + assert(Encode.count(imageType) == 1); // Sanity check + + // Call the specific encoder + success = (this->*Encode[imageType])(); + } // if + + return success; +} // bool ogImage::Save() + +#if 0 +class membuf : public basic_streambuf +{ +public: + membuf(char* p, size_t n) { + setg(p, p, p + n); + setp(p, p + n); + } +} +Usage: + +char *mybuffer; +size_t length; +// ... allocate "mybuffer", put data into it, set "length" + +membuf mb(mybuffer, length); +istream reader(&mb); +// use "reader" +#endif diff --git a/lib/objgfx40/ogSprite.cpp b/lib/objgfx40/ogSprite.cpp index 872437d..548a5ea 100644 --- a/lib/objgfx40/ogSprite.cpp +++ b/lib/objgfx40/ogSprite.cpp @@ -136,7 +136,7 @@ uInt32 xx, yy, xOfs, yOfs; uInt32 rx1, ry1, rx2, ry2; uInt32 xCount, yCount, count; - void *p; + uint8_t *p; uInt32 maxX, maxY; if (!srcObject.ogAvail()) return; @@ -199,16 +199,16 @@ imageSize = xCount*yCount*bytesPerPixel; image = malloc(imageSize); - p = image; + p = (uint8_t *)image; if ( ((uInt32)x1 > maxX) || ((uInt32)y1 > maxY) || ((uInt32)x2 > maxX) || ((uInt32)y2 > maxY) ) { for (count = 0; count < (xCount*yCount); count++) { SetPixel(p, tColour); - (uInt8 *)p += bytesPerPixel; + *p += bytesPerPixel; } // for - p = image; // reset the pointer; + p = (uint8_t *)image; // reset the pointer; } // if xOfs = 0; @@ -239,9 +239,9 @@ xCount *= bytesPerPixel; for (yy = 0; yy < yCount; yy++) { - ( (uInt8 *)p ) += xOfs; + p += xOfs; srcObject.ogCopyLineFrom(rx1, ry1+yy, p, xCount); - ( (uInt8 *)p ) += xCount; + p += xCount; } return; } // ogSprite::Get @@ -474,7 +474,7 @@ uInt32 yOfs; uInt32 xLeft, xRight; int32 maxX, maxY; - void * p; + uint8_t * p; uInt8 r, g, b, a; ogPixelFmt pixfmt; @@ -491,7 +491,7 @@ if ((x+xCount < 0) || (y+yCount < 0) || (x > (int32)maxX) || (y > (int32)maxY)) return; - p = image; + p = (uint8_t *)image; if (y < 0) { yOfs = abs(y)*xCount*bytesPerPixel; @@ -514,31 +514,32 @@ destObject.ogGetPixFmt(pixfmt); - (uInt8 *)p += yOfs; + p += yOfs; + if ((destObject.ogGetPixFmtID() != pixelFmtID) || (destObject.ogIsBlending())) { for (yy = 0; yy < (uInt32)yCount; yy++) { - (uInt8 *)p += xLeft; + p += xLeft; for (xx = 0; xx < (uInt32)xCount; xx++) { Unpack(GetPixel(p), r, g, b, a); - (uInt8 *)p += bytesPerPixel; + p += bytesPerPixel; // this could probably be rawSetPixelRGBA instead destObject.ogSetPixel(x+xx, y+yy, r, g, b, a); } // for - (uInt8 *)p += xRight; + p += xRight; } // for yy } else { // pixel formats match xCount *= bytesPerPixel; for (yy = 0; yy < (uInt32)yCount; yy++) { - (uInt8 *)p += xLeft; + p += xLeft; destObject.ogCopyLineTo(x, y+yy, p, xCount); - (uInt8 *)p += xCount; - (uInt8 *)p += xRight; + p += xCount; + p += xRight; } // for } // else diff --git a/sys/fs/vfs/file.c b/sys/fs/vfs/file.c index 21a3793..498c235 100644 --- a/sys/fs/vfs/file.c +++ b/sys/fs/vfs/file.c @@ -132,13 +132,13 @@ } int sys_chdir( struct thread *td, struct sys_chdir_args *args ) { - kprintf("chdir: [%s][%s]", _current->oInfo.cwd, args->path); if ( strstr( args->path, ":" ) == 0x0 ) { sprintf( _current->oInfo.cwd, "%s%s", _current->oInfo.cwd, args->path ); } else { sprintf( _current->oInfo.cwd, args->path ); } + td->td_retval[0] = 0; return (0); } @@ -200,7 +200,6 @@ ************************************************************************/ int sys_fread( struct thread *td, struct sys_fread_args *args ) { -//void *data,long size,userFileDescriptor *userFd) { /* TODO : coredump? */ if ( args->FILE == NULL ) @@ -209,7 +208,8 @@ if ( args->FILE->fd == NULL ) return (-1); - return (fread( args->ptr, args->size, args->nmemb, args->FILE->fd )); + td->td_retval[0] = fread( args->ptr, args->size, args->nmemb, args->FILE->fd ); + return(0); } /************************************************************************ @@ -388,7 +388,7 @@ return (0x0); } - kprintf("[fO: %s]", file); + //kprintf("[fO: %s]", file); /* This Will Set Up The Descriptor Modes */ tmpFd->mode = 0; diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index e230aef..9a8e786 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -156,13 +156,6 @@ stackAddr = vmm_getFreeKernelPage(newProcess->id, stack / PAGE_SIZE); - kprintf("stackAddr: 0x%X", stackAddr); - - /* - if (stack < 0x100000) - kpanic("exec: stack not in valid area: [0x%X]\n", stack); - */ - /* Set All The Correct Thread Attributes */ newProcess->tss.back_link = 0x0; newProcess->tss.esp0 = 0x0; @@ -207,7 +200,7 @@ newProcess->files[0] = 0x0; - kprintf("EIP: 0x%X(%i)", tproc, newProcess->id); + //kprintf("EIP: 0x%X(%i)", tproc, newProcess->id); /* Set up default stack for thread here filled with arg list 3 times */ asm volatile( @@ -748,6 +741,7 @@ EXECP = (char *)tmp[i]; } strcpy((char *)tmp[i], (const char *)argv_out[i]); + kprintf("argv[%i]:%s",i, (const char *)argv_out[i]); sp += strlen((const char *)argv_out[i]) + 1; } diff --git a/sys/sde/Makefile b/sys/sde/Makefile index b48edbb..33fea55 100644 --- a/sys/sde/Makefile +++ b/sys/sde/Makefile @@ -12,7 +12,7 @@ REMOVE = rm -fr # Objects -OBJS = objgfx40.o ogFont.o ogPixelFmt.o ogPixCon.o ogDisplay_UbixOS.o sde.o main.o colours.o +OBJS = objgfx40.o ogFont.o ogPixelFmt.o ogPixCon.o ogDisplay_UbixOS.o sde.o main.o colours.o #ogImage.o CFLAGS += -fno-rtti -nostdinc++ @@ -22,6 +22,7 @@ (cp ../../lib/objgfx40/ogFont.cpp ./) (cp ../../lib/objgfx40/ogPixCon.cpp ./) (cp ../../lib/objgfx40/ogPixelFmt.cpp ./) + (cp ../../lib/objgfx40/ogImage.cpp ./) (make allBuild) allBuild: $(OBJS) diff --git a/sys/sde/main.cc b/sys/sde/main.cc index 539f78c..9963a5e 100644 --- a/sys/sde/main.cc +++ b/sys/sde/main.cc @@ -57,7 +57,7 @@ ogBitFont * font = new ogBitFont(); - font->Load("/var/fonts/ROM8X8.DPF", 0); + font->Load("/var/fonts/ROM8X14.DPF", 0); font->SetFGColor(255, 255, 255, 255); font->SetBGColor(0, 0, 0, 255); diff --git a/sys/vmm/pagefault.c b/sys/vmm/pagefault.c index 0b28425..c95860b 100644 --- a/sys/vmm/pagefault.c +++ b/sys/vmm/pagefault.c @@ -121,6 +121,7 @@ } else if (memAddr < (_current->td.vm_dsize + _current->td.vm_daddr)) { kprintf("THIS IS BAD"); + die_if_kernel("SEGFAULT", frame, 0xC); pageTable[pageTableIndex] = (uInt32) vmm_findFreePage(_current->id) | PAGE_DEFAULT; } else { diff --git a/sys/vmm/paging.c b/sys/vmm/paging.c index f8e8b39..31410c9 100644 --- a/sys/vmm/paging.c +++ b/sys/vmm/paging.c @@ -486,8 +486,7 @@ spinLock(&fkpSpinLock); /* Lets Search For A Free Page */ - for (x = PT_INDEX(VMM_KERN_START); x <= PT_INDEX(VMM_KERN_END); x++) { - + for (x = PD_INDEX(VMM_KERN_START); x <= PD_INDEX(VMM_KERN_END); x++) { if ((pageDirectory[x] & PAGE_PRESENT) != PAGE_PRESENT) /* If Page Directory Is Not Yet Allocated Allocate It */ vmm_allocPageTable(x, sysID);