annotate tools/64vw.c @ 1576:e5be5235e7e1

Make home/end keys to go to first and last file respectively in 64vw.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 May 2018 09:49:03 +0300
parents 4643cd757c0b
children 1eb8c1dc81fd
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 /*
1437
0d5295a5af57 Also do some renaming in here ..
Matti Hamalainen <ccr@tnsp.org>
parents: 1435
diff changeset
2 * 64vw - Display some C64 etc graphics formats via libSDL
407
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
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
15 #define SET_SKIP_AMOUNT 10
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
16
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
17
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
18 int optVFlags = 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
19 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
20 int optForcedFormat = -1;
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
21 BOOL optProbeOnly = FALSE;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
22 size_t noptFilenames1 = 0, noptFilenames2 = 0;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
23 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
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
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
26 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
27 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 { 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
29 { 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
30 { 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
31 { 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
32 { 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
33 { 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
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 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 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
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 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
42 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
43 }
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 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
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 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
49 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
50
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 printf("\nAvailable bitmap formats:\n");
1353
17199f53d8fa Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1238
diff changeset
52 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
53 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
54 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
55 char buf[64];
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
56 printf(" %-5s | %-15s | %s\n",
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
57 fmt->fext,
1494
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
58 dmC64GetImageTypeString(buf, sizeof(buf), fmt->type, FALSE),
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 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
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 }
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 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
65 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 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
67 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 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
69 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 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
71 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 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
74 dmVerbosity++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
76
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 case 2:
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
78 optVFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 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
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 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
84 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
85 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 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
87 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
88 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
89 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 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
93 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
96 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
97 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
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 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 case 4:
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
103 optForcedFormat = -1;
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
104 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
105 {
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
106 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
107 if (fmt->fext != NULL &&
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
108 strcasecmp(optArg, fmt->fext) == 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
109 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 optForcedFormat = i;
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
111 break;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
113 }
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
114
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
115 if (optForcedFormat < 0)
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
116 {
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
117 dmErrorMsg("Invalid image format argument '%s'.\n", optArg);
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
118 return FALSE;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
121
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
122 case 5:
1395
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
123 if (dmVerbosity < 1)
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
124 dmVerbosity = 1;
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
125 optProbeOnly = TRUE;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
126 break;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
127
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
129 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
130 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
131 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
132
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 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
134 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
137 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
138 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
139 (void) filename;
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 noptFilenames1++;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
142 return TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
143 }
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
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
146 BOOL argHandleFile2(char *filename)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
147 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
148 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
149 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
150 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
151 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
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 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 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
155 }
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
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
158 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
159 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
160 Uint8 *dataBuf = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
161 size_t dataSize;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
162 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
163
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
164 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
165 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
166
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
167 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
168
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
169 exit:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
170 dmFree(dataBuf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
171 return ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
172 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
173
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
174
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
175 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
176 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
177 DMImage bmap;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
178 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
179
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
180 bmap.size = surf->pitch * surf->h;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
181 bmap.data = surf->pixels;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
182 bmap.pitch = surf->pitch;
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
183 bmap.width = surf->w;
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
184 bmap.height = surf->h;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
185
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
186 if (fmt->convertFrom != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
187 ret = fmt->convertFrom(&bmap, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
188 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
189 ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
190
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
191 return ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
192 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
193
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
194
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 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
196 {
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
197 SDL_Window *window = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
198 SDL_Renderer *renderer = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
199 SDL_Texture *texture = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
200 SDL_Surface *surf = 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
201 BOOL initSDL = FALSE, exitFlag, needRedraw;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
202 const DMC64ImageFormat *forced;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
203 size_t currIndex, prevIndex;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
204 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
205
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 dmSetScaleFactor(2.0);
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
207
1437
0d5295a5af57 Also do some renaming in here ..
Matti Hamalainen <ccr@tnsp.org>
parents: 1435
diff changeset
208 dmInitProg("64vw", "Display some C64 bitmap graphics formats", "0.2", NULL, 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
209
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
210 // 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
211 if (!dmArgsProcess(argc, argv, optList, optListN,
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
212 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
213 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
214
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
215 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
216 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
217 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
218 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
219 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
220
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
221 // Allocate space for filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
222 if ((optFilenames = dmCalloc(noptFilenames1, sizeof(char *))) == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
223 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
224 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
225 goto exit;
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 // Assign the filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
229 if (!dmArgsProcess(argc, argv, optList, optListN,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
230 NULL, argHandleFile2, OPTH_BAILOUT | OPTH_ONLY_OTHER))
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
231 goto exit;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
232
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
233 // 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
234 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
235 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
236 forced = &dmC64ImageFormats[optForcedFormat];
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
237 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
238 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
239 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 else
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
241 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
242
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
243 // 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
244 if (optProbeOnly)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
245 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
246 for (size_t n = 0; n < noptFilenames2; n++)
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 char *filename = optFilenames[n];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
249 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
250 DMC64Image *cimage = NULL;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
251
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
252 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
253 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
254 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
255 filename, ret, dmErrorStr(ret));
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
256 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
257 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
258 {
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
259 fprintf(stdout, "\n%s\n", filename);
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
260 dmC64ImageDump(stdout, cimage, fmt);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
261 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
262
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
263 dmC64ImageFree(cimage);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
264 }
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
265 goto exit;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
266 }
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
267
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 // 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
269 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
270 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
271 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
272 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
273 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 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
275
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
276 // Open window
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
277 if ((window = SDL_CreateWindow(dmProgName,
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
278 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
279 optScrWidth, optScrHeight,
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
280 optVFlags | SDL_WINDOW_RESIZABLE
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
281 //| SDL_WINDOW_HIDDEN
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
282 )) == 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
283 {
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
284 dmErrorMsg("Can't create an SDL window: %s\n", SDL_GetError());
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
285 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
286 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
288 if ((renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
289 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
290 dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError());
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
291 goto exit;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
292 }
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
293
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
294 // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
295
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 // Start main loop
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
297 currIndex = 0;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
298 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
299 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
300 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
301 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
302 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 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
304 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
305 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
306 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 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
308 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
309 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
310 case SDLK_ESCAPE:
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
311 case SDLK_q:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
312 exitFlag = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
313 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
314
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
315 case SDLK_LEFT:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
316 if (currIndex > 0)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
317 currIndex--;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
318 else
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
319 currIndex = 0;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
320 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
321
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
322 case SDLK_RIGHT:
1417
36016db0d0b3 Oops, the check for maximum filename index was wrong.
Matti Hamalainen <ccr@tnsp.org>
parents: 1415
diff changeset
323 if (currIndex < noptFilenames2 - 1)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
324 currIndex++;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
325 else
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
326 currIndex = noptFilenames2 - 1;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
327 break;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
328
1553
e68d3b16c79e Oops, reverse the meaning of PageUp and PageDown. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1552
diff changeset
329 case SDLK_PAGEDOWN:
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
330 if (currIndex > SET_SKIP_AMOUNT)
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
331 currIndex -= SET_SKIP_AMOUNT;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
332 else
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
333 currIndex = 0;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
334 break;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
335
1553
e68d3b16c79e Oops, reverse the meaning of PageUp and PageDown. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1552
diff changeset
336 case SDLK_PAGEUP:
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
337 if (currIndex < noptFilenames2 - 1 - SET_SKIP_AMOUNT)
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
338 currIndex += SET_SKIP_AMOUNT;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
339 else
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
340 currIndex = noptFilenames2 - 1;
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
341 break;
1576
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
342
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
343 case SDLK_HOME:
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
344 currIndex = 0;
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
345 break;
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
346
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
347 case SDLK_END:
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
348 currIndex = noptFilenames2 - 1;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
349 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
350
1567
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
351 case SDLK_f:
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
352 optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
353 if (SDL_SetWindowFullscreen(window, optVFlags) != 0)
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
354 goto exit;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
355 break;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
356
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 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
362 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
363
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
364 case SDL_WINDOWEVENT:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
365 switch (event.window.event)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
366 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
367 case SDL_WINDOWEVENT_EXPOSED:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
368 needRedraw = TRUE;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
369 break;
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
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
371 case SDL_WINDOWEVENT_RESIZED:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
372 optScrWidth = event.window.data1;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
373 optScrHeight = event.window.data2;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
374
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
375 needRedraw = TRUE;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
376 break;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
377 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 case SDL_QUIT:
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
381 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
382 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
383
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
384 if (currIndex != prevIndex)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
385 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
386 char *filename = optFilenames[currIndex];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
387 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
388 DMC64Image *cimage = NULL;
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
389 char *title = NULL;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
390
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
391 if (surf != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
392 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
393 SDL_FreeSurface(surf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
394 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
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
397 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
398 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
399 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
400 goto fail;
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
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
403 if (fmt == NULL || cimage == NULL)
1414
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 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
406 goto fail;
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
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
409 // Create surface (we are lazy and ugly)
1566
3b53b289df0e Use SDL_CreateRGBSurfaceWithFormat().
Matti Hamalainen <ccr@tnsp.org>
parents: 1565
diff changeset
410 if ((surf = SDL_CreateRGBSurfaceWithFormat(0,
3b53b289df0e Use SDL_CreateRGBSurfaceWithFormat().
Matti Hamalainen <ccr@tnsp.org>
parents: 1565
diff changeset
411 cimage->width, cimage->height, 8, SDL_PIXELFORMAT_INDEX8)) == NULL)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
412 {
1515
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
413 dmC64ImageFree(cimage);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
414 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
415 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
416 }
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 if (dmDecodeC64Image(cimage, fmt, surf) == DMERR_OK)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
419 {
1572
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
420 title = dm_strdup_printf("%s - [%d / %d] %s (%dx%d @ %s)",
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
421 dmProgName,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
422 currIndex + 1,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
423 noptFilenames2,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
424 filename,
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
425 cimage->width, cimage->height,
1572
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
426 fmt->name);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
427
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
428 if (dmVerbosity >= 1)
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
429 {
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
430 fprintf(stdout, "\n%s\n", filename);
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
431 dmC64ImageDump(stdout, cimage, fmt);
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1483
diff changeset
432 }
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
433 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
434
1516
530ce92c513f Better leak fix. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1515
diff changeset
435 fail:
1515
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
436 dmC64ImageFree(cimage);
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
437
1566
3b53b289df0e Use SDL_CreateRGBSurfaceWithFormat().
Matti Hamalainen <ccr@tnsp.org>
parents: 1565
diff changeset
438 if (surf == NULL && (surf = SDL_CreateRGBSurfaceWithFormat(0,
1571
ad771e94af25 Use C64_SCR_* constants instead of hardcoded number values in creating surface.
Matti Hamalainen <ccr@tnsp.org>
parents: 1570
diff changeset
439 C64_SCR_WIDTH, C64_SCR_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8)) == NULL)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
440 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
441 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
442 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
443 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
444
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
445 SDL_SetPaletteColors(surf->format->palette, (SDL_Color *)dmDefaultC64Palette, 0, C64_NCOLORS);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
446
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
447 if (texture != NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
448 SDL_DestroyTexture(texture);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
449
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
450 if ((texture = SDL_CreateTextureFromSurface(renderer, surf)) == NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
451 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
452 dmErrorMsg("Could not create texture from surface: %s\n", SDL_GetError());
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
453 goto exit;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
454 }
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
455
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
456 if (title == NULL)
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
457 {
1517
1be17c662b8e Always show current filename in the window title.
Matti Hamalainen <ccr@tnsp.org>
parents: 1516
diff changeset
458 title = dm_strdup_printf("%s - %s [%d / %d]",
1be17c662b8e Always show current filename in the window title.
Matti Hamalainen <ccr@tnsp.org>
parents: 1516
diff changeset
459 dmProgName, filename,
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
460 currIndex + 1, noptFilenames2);
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
461 }
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
462
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
463 SDL_SetWindowTitle(window, title);
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
464 dmFree(title);
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
465
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
466 needRedraw = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
467 prevIndex = currIndex;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
468 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
469
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 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
471 {
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
472 SDL_RenderClear(renderer);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
473 SDL_RenderCopy(renderer, texture, NULL, NULL);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
474 SDL_RenderPresent(renderer);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 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
476 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
477
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
478 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
479 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
481 exit:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
482 // Cleanup
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
483 dmFree(optFilenames);
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
484
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
485 if (window != NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
486 SDL_DestroyWindow(window);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
487
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
488 if (texture != NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
489 SDL_DestroyTexture(texture);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
491 if (surf != NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
492 SDL_FreeSurface(surf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
493
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 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
495 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
496
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 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
498 }