#176308 - SchmendrickSchmuck - Mon Jun 20, 2011 8:09 pm
I'm trying to save a screenshot to fat on hardware. The output however is completely garbled. Any example code I've found is mostly identical.
This is the result: http://temp.dennisvanzwieten.com/DSLieroScreenshot0005.bmp
There is also 0006 and 0007. It doesn't appear to be complete garbage, as it seems to be the visible portion of the 8bit bg, heavily mangled. Text and (3D) sprites can't be seen.
I don't really know how to adjust the code below in order to make it work, since I'm not sure how it accesses the display data in the first place. I assume that using VRAM_A - VRAM_D as LCD / unmapped, you have direct access to the screen's framebuffer, but if that's the case, the result wouldn't be the way it is.
Here is my code:
[/code]
_________________
http://DSLiero.DennisvanZwieten.com - Liero for NDS!
This is the result: http://temp.dennisvanzwieten.com/DSLieroScreenshot0005.bmp
There is also 0006 and 0007. It doesn't appear to be complete garbage, as it seems to be the visible portion of the 8bit bg, heavily mangled. Text and (3D) sprites can't be seen.
I don't really know how to adjust the code below in order to make it work, since I'm not sure how it accesses the display data in the first place. I assume that using VRAM_A - VRAM_D as LCD / unmapped, you have direct access to the screen's framebuffer, but if that's the case, the result wouldn't be the way it is.
Here is my code:
Code: |
void write16(u16* address, u16 value) { u8* first=(u8*)address; u8* second=first+1; *first=value&0xff; *second=value>>8; } void write32(u32* address, u32 value) { u8* first=(u8*)address; u8* second=first+1; u8* third=first+2; u8* fourth=first+3; *first=value&0xff; *second=(value>>8)&0xff; *third=(value>>16)&0xff; *fourth=(value>>24)&0xff; } void CreateScreenshot(const char* filename) { FILE* file=fopen(filename, "wb"); REG_DISPCAPCNT=DCAP_BANK(3)|DCAP_ENABLE|DCAP_SIZE(3); while(REG_DISPCAPCNT & DCAP_ENABLE); int ysize = 384; int headerSize = sizeof(INFOHEADER) + sizeof(HEADER); u8* temp = (u8*)malloc(256 * ysize * 3 + headerSize); HEADER* header=(HEADER*)temp; INFOHEADER* infoheader=(INFOHEADER*)(temp + sizeof(HEADER)); write16(&header->type, 0x4D42); write32(&header->size, 256 * ysize * 3 + headerSize); write32(&header->offset, headerSize); write16(&header->reserved1, 0); write16(&header->reserved2, 0); write16(&infoheader->bits, 24); write32(&infoheader->size, sizeof(INFOHEADER)); write32(&infoheader->compression, 0); write32(&infoheader->width, 256); write32(&infoheader->height, ysize); write16(&infoheader->planes, 1); write32(&infoheader->imagesize, 256 * ysize * 3); write32(&infoheader->xresolution, 0); write32(&infoheader->yresolution, 0); write32(&infoheader->importantcolours, 0); write32(&infoheader->ncolours, 0); u32 vram_temp = vramSetPrimaryBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); for(int y = 0; y < ysize; y++) { for(int x = 0; x < 256;x++) { u16 color = 0; if(y > 192) color = VRAM_C[256 * 192 - (y - 191) * 256 + x]; else color = VRAM_D[256 * 192 - (y + 1) * 256 + x]; u8 b =(color & 31) << 3; u8 g =((color >> 5) & 31) << 3; u8 r =((color >> 10) & 31) << 3; temp[((y * 256) + x) * 3 + 0 + headerSize] = r; temp[((y * 256) + x) * 3 + 1 + headerSize] = g; temp[((y * 256) + x) * 3 + 2 + headerSize] = b; } } vramRestorePrimaryBanks(vram_temp); DC_FlushAll(); fwrite(temp, 1, 256 * ysize * 3 + headerSize, file); fclose(file); free(temp); } |
_________________
http://DSLiero.DennisvanZwieten.com - Liero for NDS!