annotate tools/view64.c @ 1414:d6ee4dcef692

Implement multi file support in view64.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 05 Nov 2017 04:04:52 +0200
parents c29f1cea4a1c
children 1e4fb7c5527f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * view64 - Display some C64 etc graphics formats via libSDL
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2012 Tecnic Software productions (TNSP)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmlib.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmargs.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmfile.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "lib64gfx.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <SDL.h>
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 int optScrWidth, optScrHeight;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 int optForcedFormat = -1;
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
18 BOOL optProbeOnly = FALSE;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
19 size_t noptFilenames1 = 0, noptFilenames2 = 0;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
20 char **optFilenames = NULL;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
23 static const DMOptArg optList[] =
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 { 0, '?', "help", "Show this help", OPT_NONE },
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 { 2, 0, "fs", "Fullscreen", OPT_NONE },
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 { 3, 'S', "scale", "Scale image by factor (1-10)", OPT_ARGREQ },
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 { 4, 'f', "format", "Force input format (see list below)", OPT_ARGREQ },
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
30 { 5, 'p', "probe", "Probe only (no display)", OPT_NONE },
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 const int optListN = sizeof(optList) / sizeof(optList[0]);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 void dmSetScaleFactor(float factor)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 optScrWidth = (int) ((float) C64_SCR_WIDTH * factor * C64_SCR_PAR_XY);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 optScrHeight = (int) ((float) C64_SCR_HEIGHT * factor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 void argShowHelp()
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 dmPrintBanner(stdout, dmProgName, "[options] <input image file>");
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
46 dmArgsPrintHelp(stdout, optList, optListN, 0);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 printf("\nAvailable bitmap formats:\n");
1353
17199f53d8fa Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
49 for (int i = 0; i < ndmC64ImageFormats; i++)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
51 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
52 char buf[64];
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 printf("%3d | %-5s | %-15s | %s\n",
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
54 i, fmt->fext,
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
55 dmC64GetImageTypeString(buf, sizeof(buf), fmt->type),
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 fmt->name);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 switch (optN)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 case 0:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 exit(0);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 case 1:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 dmVerbosity++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
73
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 case 2:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 optVFlags |= SDL_FULLSCREEN;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 case 3:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 float factor;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if (sscanf(optArg, "%f", &factor) == 1)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 if (factor < 1 || factor >= 10)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
85 dmErrorMsg("Invalid scale factor %1.0f, see help for valid values.\n", factor);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 dmSetScaleFactor(factor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
93 dmErrorMsg("Invalid scale factor '%s'.\n", optArg);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 case 4:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 int i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if (sscanf(optArg, "%d", &i) == 1)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 if (i < 0 || i >= ndmC64ImageFormats)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
106 dmErrorMsg("Invalid image format index %d, see help for valid values.\n", i);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 optForcedFormat = i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
113 dmErrorMsg("Invalid image format argument '%s'.\n", optArg);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
118
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
119 case 5:
1395
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
120 if (dmVerbosity < 1)
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
121 dmVerbosity = 1;
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
122 optProbeOnly = TRUE;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
123 break;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
124
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
126 dmErrorMsg("Unknown option '%s'.\n", currArg);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
129
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 return TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
134 BOOL argHandleFile1(char *filename)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
136 (void) filename;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
137
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
138 noptFilenames1++;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
139 return TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
140 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
141
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
142
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
143 BOOL argHandleFile2(char *filename)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
144 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
145 if (noptFilenames2 < noptFilenames1)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
147 optFilenames[noptFilenames2++] = filename;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 return TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 BOOL dmInitializeVideo(SDL_Surface **screen)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 *screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 8, optVFlags | SDL_RESIZABLE);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 if (*screen == NULL)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
160 dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 return TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
167 void dmDumpC64Image(const char *filename, const DMC64Image *img, const DMC64ImageFormat *fmt)
1367
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
168 {
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
169 char typeStr[64];
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
170
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
171 snprintf(typeStr, sizeof(typeStr),
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
172 "%s%s%s%s",
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
173 ((img->type & D64_FMT_MC) ? "MultiColor" : "Hires"),
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
174 ((img->type & D64_FMT_ILACE) ? " Interlaced" : ""),
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
175 ((img->type & D64_FMT_FLI) ? " FLI" : ""),
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
176 ((img->type & D64_FMT_CHAR) ? " CHAR" : "")
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
177 );
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
178
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
179 dmPrint(1,
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
180 "\n%s\n"
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
181 "Format : %s [%s]\n"
1386
5c3ee6f028dc Print number of banks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1376
diff changeset
182 "Type : %s\n"
5c3ee6f028dc Print number of banks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1376
diff changeset
183 "Banks : %d\n",
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
184 filename,
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
185 fmt->name, fmt->fext,
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
186 typeStr,
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
187 img->nbanks);
1367
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
188
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
189 if (img->type & D64_FMT_ILACE)
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
190 {
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
191 char *tmps;
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
192 switch(img->laceType)
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
193 {
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
194 case D64_ILACE_COLOR: tmps = "color"; break;
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
195 case D64_ILACE_RES: tmps = "resolution"; break;
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
196 default: tmps = "ERROR"; break;
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
197 }
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
198 dmPrint(1,
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
199 "Interlace type : %s\n",
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
200 tmps);
1367
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
201 }
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
202
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
203 dmPrint(1,
1367
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
204 "Width x Height : %d x %d\n"
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
205 "CHwidth x CHheight : %d x %d\n",
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
206 img->width, img->height,
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
207 img->ch_width, img->ch_height);
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
208 }
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
209
fe1e3a756685 Add some information dumping to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1363
diff changeset
210
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
211 int dmReadC64Image(const char *filename, const DMC64ImageFormat *forced, const DMC64ImageFormat **fmt, DMC64Image **cimage)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
212 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
213 Uint8 *dataBuf = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
214 size_t dataSize;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
215 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
216
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
217 if ((ret = dmReadDataFile(NULL, filename, &dataBuf, &dataSize)) != DMERR_OK)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
218 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
219
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
220 ret = dmC64DecodeBMP(cimage, dataBuf, dataSize, 0, 2, fmt, forced);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
221
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
222 exit:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
223 dmFree(dataBuf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
224 return ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
225 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
226
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
227
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
228 int dmDecodeC64Image(const DMC64Image *cimage, const DMC64ImageFormat *fmt, SDL_Surface *surf)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
229 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
230 DMImage bmap;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
231 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
232
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
233 bmap.size = surf->pitch * cimage->height;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
234 bmap.data = surf->pixels;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
235 bmap.pitch = surf->pitch;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
236 bmap.width = cimage->width;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
237 bmap.height = cimage->height;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
238 bmap.constpal = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
239
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
240 if (fmt->convertFrom != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
241 ret = fmt->convertFrom(&bmap, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
242 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
243 ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
244
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
245 return ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
246 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
247
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
248
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 int main(int argc, char *argv[])
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 SDL_Surface *screen = NULL, *surf = NULL;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 BOOL initSDL = FALSE, exitFlag, needRedraw;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
253 const DMC64ImageFormat *forced;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
254 size_t currIndex, prevIndex;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
255 int ret;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 dmSetScaleFactor(2.0);
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
258
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 dmInitProg("view64", "Display some C64 bitmap graphics formats", "0.2", NULL, NULL);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
261 // Parse arguments, round #1
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 if (!dmArgsProcess(argc, argv, optList, optListN,
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
263 argHandleOpt, argHandleFile1, OPTH_BAILOUT))
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 exit(1);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
266 if (noptFilenames1 == 0)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
268 dmErrorMsg("No input file(s) specified, perhaps you need some --help\n");
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
269 goto exit;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
271
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
272 // Allocate space for filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
273 if ((optFilenames = dmCalloc(noptFilenames1, sizeof(char *))) == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
274 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
275 dmErrorMsg("Could not allocate memory for input file list.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
276 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
277 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
278
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
279 // Assign the filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
280 if (!dmArgsProcess(argc, argv, optList, optListN,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
281 NULL, argHandleFile2, OPTH_BAILOUT | OPTH_ONLY_OTHER))
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
282 goto exit;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
283
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
284 // Check for forced input format
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 if (optForcedFormat >= 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
287 forced = &dmC64ImageFormats[optForcedFormat];
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
288 dmMsg(0, "Forced %s format image, type %d, %s\n",
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
289 forced->name, forced->type, forced->fext);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 else
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
292 forced = NULL;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
294 // If we are simply probing, no need to initialize SDL etc
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
295 if (optProbeOnly)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
296 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
297 for (size_t n = 0; n < noptFilenames2; n++)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
298 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
299 char *filename = optFilenames[n];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
300 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
301 DMC64Image *cimage = NULL;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
302
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
303 if ((ret = dmReadC64Image(filename, forced, &fmt, &cimage)) != DMERR_OK)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
304 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
305 dmErrorMsg("Could not read image file '%s', %d: %s\n",
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
306 filename, ret, dmErrorStr(ret));
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
307 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
308 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
309 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
310 dmDumpC64Image(filename, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
311 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
312
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
313 dmC64ImageFree(cimage);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
314 }
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
315 goto exit;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
316 }
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
317
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 // Initialize libSDL
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
321 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
322 goto exit;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 initSDL = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 // Open window/set video mode
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 screen = SDL_SetVideoMode(optScrWidth, optScrHeight, 8, optVFlags | SDL_RESIZABLE);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 if (screen == NULL)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
331 dmErrorMsg("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
332 goto exit;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 // Start main loop
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
336 currIndex = 0;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
337 prevIndex = 1;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 needRedraw = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 exitFlag = FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 while (!exitFlag)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 SDL_Event event;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 while (SDL_PollEvent(&event))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 switch (event.type)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 case SDL_KEYDOWN:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 switch (event.key.keysym.sym)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
349 case SDLK_ESCAPE:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
350 exitFlag = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
351 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
352
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
353 case SDLK_LEFT:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
354 if (currIndex > 0)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
355 currIndex--;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
356 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
357
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
358 case SDLK_RIGHT:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
359 if (currIndex < noptFilenames2)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
360 currIndex++;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
361 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
362
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 needRedraw = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
369
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 case SDL_VIDEORESIZE:
941
81ff7111fedf Adjust aspect ration stuff in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
371 optScrWidth = event.resize.w;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 optScrHeight = event.resize.h;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 if (!dmInitializeVideo(&screen))
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
374 goto exit;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 needRedraw = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
378
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 case SDL_VIDEOEXPOSE:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 needRedraw = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 case SDL_QUIT:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 exit(0);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
386
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
387 if (currIndex != prevIndex)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
388 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
389 char *filename = optFilenames[currIndex];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
390 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
391 DMC64Image *cimage = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
392 char *title;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
393
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
394 if (surf != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
395 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
396 SDL_FreeSurface(surf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
397 surf = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
398 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
399
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
400 if ((ret = dmReadC64Image(filename, forced, &fmt, &cimage)) != DMERR_OK)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
401 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
402 dmErrorMsg("Failed to decode bitmap data %d: %s\n", ret, dmErrorStr(ret));
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
403 goto fail;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
404 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
405
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
406 if (fmt == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
407 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
408 dmErrorMsg("Probing could not find any matching image format. Perhaps try forcing a format via -f.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
409 goto fail;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
410 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
411
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
412 // Create surface (we are lazy and ugly)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
413 if ((surf = SDL_CreateRGBSurface(SDL_SWSURFACE, cimage->width, cimage->height, 8, 0, 0, 0, 0)) == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
414 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
415 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
416 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
417 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
418
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
419 SDL_SetColors(surf, (SDL_Color *)dmC64Palette, 0, C64_NCOLORS);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
420
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
421 if (dmDecodeC64Image(cimage, fmt, surf) == DMERR_OK)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
422 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
423 title = dm_strdup_printf("%s - %s (%d x %d) [%d / %d]",
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
424 dmProgName, filename,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
425 cimage->width, cimage->height,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
426 currIndex + 1, noptFilenames2);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
427
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
428 dmDumpC64Image(filename, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
429 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
430 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
431 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
432 title = dm_strdup_printf("%s [%d / %d]",
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
433 dmProgName,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
434 currIndex + 1, noptFilenames2);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
435 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
436
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
437 if (title != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
438 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
439 SDL_WM_SetCaption(title, dmProgName);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
440 dmFree(title);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
441 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
442
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
443 fail:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
444 if (surf == NULL && (surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 200, 8, 0, 0, 0, 0)) == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
445 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
446 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
447 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
448 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
449
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
450 needRedraw = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
451 prevIndex = currIndex;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
452 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
453
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 if (needRedraw)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
456 float aspect = (float) surf->h / (float) surf->w;
1363
3af0057f377d Adjust view64 display aspect calculations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1353
diff changeset
457 int sheight = optScrHeight / aspect;
941
81ff7111fedf Adjust aspect ration stuff in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
458 int ypos = (optScrHeight - sheight) / 2;
81ff7111fedf Adjust aspect ration stuff in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
459
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 if (SDL_MUSTLOCK(screen) != 0 && SDL_LockSurface(screen) != 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
462 dmErrorMsg("Can't lock surface.\n");
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
463 goto exit;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
465
941
81ff7111fedf Adjust aspect ration stuff in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
466 dmScaledBlitSurface8to8(surf, 0, ypos, optScrWidth, sheight, screen);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 SDL_SetColors(screen, (SDL_Color *)dmC64Palette, 0, C64_NCOLORS);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 if (SDL_MUSTLOCK(screen) != 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 SDL_UnlockSurface(screen);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 SDL_Flip(screen);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 needRedraw = FALSE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
475
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
476 SDL_Delay(50);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
479 exit:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
480 // Cleanup
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
481 dmFree(optFilenames);
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
482
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
483 if (screen != NULL)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 SDL_FreeSurface(screen);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
486 if (surf != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
487 SDL_FreeSurface(surf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
488
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 if (initSDL)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 SDL_Quit();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 return 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 }