Skip to content

Commit d525a24

Browse files
committed
[fw-isoldr] Fixed PPM screenshot header for 320x240.
1 parent 1f7b7ff commit d525a24

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

firmware/isoldr/loader/utils.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -559,17 +559,38 @@ void video_screenshot() {
559559
req = 0;
560560
}
561561

562-
char *filename = "/DS/screenshot/game_scr_001.ppm";
563-
const char *header = "# DreamShell ISO Loader\n640 480\n255\n";
562+
char filename[] = "/DS/screenshot/game_scr_001.ppm";
563+
char header[] = "# DreamShell ISO Loader\n640 480\n255\n";
564564
const size_t header_len = strlen(header);
565565

566-
const size_t fs_sector_size = 512;
567-
const size_t buffer_size = fs_sector_size * 3;
566+
const size_t buffer_size = FS_SECTOR_SIZE * 3;
568567
uint8 *buffer = (uint8 *)malloc(buffer_size);
569568
uint8 *buffer_end = buffer + buffer_size;
570569
uint8 *pbuffer = buffer;
571570
uint32 try_cnt = 30;
572571

572+
uint32 pixel;
573+
uint32 *vraml = (uint32 *)(VIDEO_VRAM_START);
574+
uint16 *vrams = (uint16 *)(vraml);
575+
uint8 *vramb = (uint8 *)(vraml);
576+
const uint32 display_cfg = *(vuint32 *)0xa05f8044;
577+
const uint32 pixel_mode = (display_cfg >> 2) & 0x0f;
578+
const uint32 display_size = *(vuint32 *)0xa05f805c;
579+
uint32 width = 640;
580+
uint32 height = ((display_size >> 10) & 0x3ff) + 1;
581+
if(height <= 240) {
582+
width = 320;
583+
height = 240;
584+
header[23] = '0' + (width / 100);
585+
header[24] = '0' + ((width % 100) / 10);
586+
header[27] = '0' + (height / 100);
587+
header[28] = '0' + ((height % 100) / 10);
588+
} else {
589+
height = 480;
590+
}
591+
const uint32 pix_num = width * height;
592+
LOGFF("%s %dx%d %d\n", filename, width, height, pixel_mode);
593+
573594
if (buffer == NULL) {
574595
LOGFF("Can't allocate memory\n");
575596
return;
@@ -605,33 +626,15 @@ void video_screenshot() {
605626
buffer[0] = 'P';
606627
buffer[1] = '6';
607628
buffer[2] = '\n';
608-
memcpy(buffer + (fs_sector_size - header_len), header, header_len);
629+
memcpy(buffer + (FS_SECTOR_SIZE - header_len), header, header_len);
609630

610-
for (uint32 i = 64; i < (fs_sector_size - header_len); ++i) {
631+
for (uint32 i = 64; i < (FS_SECTOR_SIZE - header_len); ++i) {
611632
if (i % 64 == 0) {
612633
buffer[i] = '\n';
613634
}
614635
}
615636

616-
write(fd, buffer, fs_sector_size);
617-
618-
uint32 pixel;
619-
uint32 *vraml = (uint32 *)(VIDEO_VRAM_START);
620-
uint16 *vrams = (uint16 *)(vraml);
621-
uint8 *vramb = (uint8 *)(vraml);
622-
const uint32 display_cfg = *(vuint32 *)0xa05f8044;
623-
const uint32 pixel_mode = (display_cfg >> 2) & 0x0f;
624-
const uint32 display_size = *(vuint32 *)0xa05f805c;
625-
uint32 width = 640;
626-
uint32 height = ((display_size >> 10) & 0x3ff) + 1;
627-
if(height <= 240) {
628-
width = 320;
629-
height = 240;
630-
} else {
631-
height = 480;
632-
}
633-
const uint32 pix_num = width * height;
634-
LOGFF("%s %dx%d %d\n", filename, width, height, pixel_mode);
637+
write(fd, buffer, FS_SECTOR_SIZE);
635638

636639
for(uint32 i = 0; i < pix_num; ++i) {
637640

0 commit comments

Comments
 (0)