void Initialise() { using Kernel::HardwareAbstraction::Filesystems::Partition; using Kernel::HardwareAbstraction::Filesystems::FAT32; using Kernel::HardwareAbstraction::Filesystems::VFS::File; File* bmpimg = new File("/System/Library/Resources/[email protected]"); assert(bmpimg); uint8_t* addr = new uint8_t[bmpimg->FileSize()]; bmpimg->Read(addr); File* nbmp = new File("/System/Library/Resources/name.bmp"); assert(nbmp); uint8_t* nma = new uint8_t[nbmp->FileSize()]; nbmp->Read(nma); // 35 31 32 IN SRGB // 45 40 43 // 26 23 24 IN RGB Console::SetColour(0xFFFFFFFF); Memory::Set32((void*) GetFramebufferAddress(), 0x00, (LinearFramebuffer::GetResX() * LinearFramebuffer::GetResY()) / 2); LinearFramebuffer::BackColour = 0x00; BitmapLibrary::BitmapImage* bmp = new BitmapLibrary::BitmapImage((void*) addr); BitmapLibrary::BitmapImage* ni = new BitmapLibrary::BitmapImage((void*) nma); bmp->Render((uint16_t)((LinearFramebuffer::GetResX() - bmp->DIB->GetBitmapWidth()) / 2), (uint16_t)((LinearFramebuffer::GetResY() - Math::AbsoluteValue(bmp->DIB->GetBitmapHeight())) / 2 - 40), LinearFramebuffer::GetResX(), (uint32_t*) GetFramebufferAddress()); ni->Render((uint16_t)((LinearFramebuffer::GetResX() - ni->DIB->GetBitmapWidth()) / 2), (uint16_t)((LinearFramebuffer::GetResY() - Math::AbsoluteValue(ni->DIB->GetBitmapHeight())) / 2 + 120), LinearFramebuffer::GetResX(), (uint32_t*) GetFramebufferAddress()); delete[] nma; delete[] addr; }
extern "C" uint64_t Syscall_GetFileSize(uint64_t fd) { // this is contrary to our usual model for system calls -- this one actually does some work. using namespace Kernel::HardwareAbstraction::Filesystems::VFS; if(fd > MaxDescriptors || fd < 4) return 0; FSObject* fso = Multitasking::GetCurrentProcess()->FileDescriptors[fd].Pointer; if(fso->Type != FSObjectTypes::File) { Log(1, "Error: Descriptor (%d) is not a file, cannot get size.", fd); return 0; } File* f = (File*) fso; uint64_t ret = f->FileSize(); return ret; }
DirectDrawSurface *DirectDrawSurface::LoadSurface(const string& filename,bool flip,unsigned char *buffer,int bufsize){ unsigned char *buf; DDSHeader *dds; File* file; int len; if(buffer==NULL){ file=File::ReadFile(filename); if(file==NULL) return 0; len=file->FileSize(); buffer=new unsigned char[len]; file->Read(buffer,1,len); }else{ len=bufsize; } buf=buffer; if(strncasecmp((char*)buf,"DDS ",4)) return NULL; buf+=4; dds=(DDSHeader*)buf; buf+=sizeof(DDSHeader); unsigned int format,target; int components; // Just to silence the compiler format=0; target=0; components=0; if(!DDS_GetInfo(dds,format,components,target)) return NULL; DirectDrawSurface *surface=new DirectDrawSurface; int mipmaps; surface->buffer=buffer; mipmaps=dds->mipmapcount; if(mipmaps!=0) mipmaps--; for(int i=0; i<(target==GL_TEXTURE_CUBE_MAP?6:1); i++){ DirectDrawSurface *base; if(target==GL_TEXTURE_CUBE_MAP){ surface->mipmaps.push_back(DirectDrawSurface()); base=&surface->mipmaps.back(); }else base=surface; base->format=format; base->target=target; base->dxt=buf; base->width=dds->width; base->height=dds->height; base->depth=DDS_Clamp(dds->depth); base->pitch=DDS_GetPitch(base->width,format,components); base->size=DDS_GetSizeBytes(base->width,base->height,format,components) * base->depth; base->components=components; base->mipmapcount=mipmaps; buf+=base->size; if(flip) base->Flip(); int w,h,d; w=DDS_Clamp(base->width>>1); h=DDS_Clamp(base->height>>1); d=DDS_Clamp(base->depth>>1); for(int j=0; j<mipmaps && ( w || h ); j++){ DirectDrawSurface *mip; base->mipmaps.push_back(DirectDrawSurface()); mip=&base->mipmaps.back(); mip->format=format; mip->target=target; mip->dxt=buf; mip->width=w; mip->height=h; mip->depth=d; mip->pitch=DDS_GetPitch(w,format,components); mip->size=DDS_GetSizeBytes(w,h,format,components) * d; mip->components=components; buf+=mip->size; if(flip) mip->Flip(); w=DDS_Clamp(w>>1); h=DDS_Clamp(h>>1); d=DDS_Clamp(d>>1); } } if(target==GL_TEXTURE_CUBE_MAP && flip){ DirectDrawSurface tmp=surface->mipmaps[3]; surface->mipmaps[3]=surface->mipmaps[2]; surface->mipmaps[2]=tmp; } return surface; }