Revision 0ab6b636 hw/tcx.c
b/hw/tcx.c | ||
---|---|---|
582 | 582 |
TCXState *s = opaque; |
583 | 583 |
FILE *f; |
584 | 584 |
uint8_t *d, *d1, v; |
585 |
int y, x; |
|
585 |
int ret, y, x;
|
|
586 | 586 |
|
587 | 587 |
f = fopen(filename, "wb"); |
588 |
if (!f) |
|
588 |
if (!f) { |
|
589 |
error_setg(errp, "failed to open file '%s': %s", filename, |
|
590 |
strerror(errno)); |
|
589 | 591 |
return; |
590 |
fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255); |
|
592 |
} |
|
593 |
ret = fprintf(f, "P6\n%d %d\n%d\n", s->width, s->height, 255); |
|
594 |
if (ret < 0) { |
|
595 |
goto write_err; |
|
596 |
} |
|
591 | 597 |
d1 = s->vram; |
592 | 598 |
for(y = 0; y < s->height; y++) { |
593 | 599 |
d = d1; |
594 | 600 |
for(x = 0; x < s->width; x++) { |
595 | 601 |
v = *d; |
596 |
fputc(s->r[v], f); |
|
597 |
fputc(s->g[v], f); |
|
598 |
fputc(s->b[v], f); |
|
602 |
ret = fputc(s->r[v], f); |
|
603 |
if (ret == EOF) { |
|
604 |
goto write_err; |
|
605 |
} |
|
606 |
ret = fputc(s->g[v], f); |
|
607 |
if (ret == EOF) { |
|
608 |
goto write_err; |
|
609 |
} |
|
610 |
ret = fputc(s->b[v], f); |
|
611 |
if (ret == EOF) { |
|
612 |
goto write_err; |
|
613 |
} |
|
599 | 614 |
d++; |
600 | 615 |
} |
601 | 616 |
d1 += MAXX; |
602 | 617 |
} |
618 |
|
|
619 |
out: |
|
603 | 620 |
fclose(f); |
604 | 621 |
return; |
622 |
|
|
623 |
write_err: |
|
624 |
error_setg(errp, "failed to write to file '%s': %s", filename, |
|
625 |
strerror(errno)); |
|
626 |
unlink(filename); |
|
627 |
goto out; |
|
605 | 628 |
} |
606 | 629 |
|
607 | 630 |
static void tcx24_screen_dump(void *opaque, const char *filename, bool cswitch, |
Also available in: Unified diff