annotate tools/64vw.c @ 2199:f331cc750b37

Rename variable.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 13 Jun 2019 23:59:05 +0300
parents 5dc1e323d3d4
children dcd26cdc395e
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 /*
2162
875e2b7b24dd Change 64vw's short description.
Matti Hamalainen <ccr@tnsp.org>
parents: 2137
diff changeset
2 * 64vw - Displayer for various C64 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
2120
88d37ec1b4d6 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 2111
diff changeset
4 * (C) Copyright 2012-2019 Tecnic Software productions (TNSP)
407
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
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
18 int optVFlags = 0;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
19 int optScrWidth, optScrHeight;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
20 int optForcedFormat = -1;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
21 BOOL optInfoOnly = FALSE,
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
22 optProbeOnly = FALSE,
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
23 optListOnly = FALSE;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
24 size_t noptFilenames1 = 0, noptFilenames2 = 0;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
25 char **optFilenames = NULL;
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
26 char *optCharROMFilename = NULL;
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
27
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
28 DMC64MemBlock setCharROM;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
31 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
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 { 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
34 { 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
35 { 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
36 { 3, 'S', "scale", "Scale image by factor (1-10)", OPT_ARGREQ },
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
37 { 4, 'f', "format", "Force input format (see --formats)", OPT_ARGREQ },
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
38 { 5, 'F', "formats", "List supported input formats", OPT_NONE },
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
39 { 6, 'i', "info", "Print information only (no display)", OPT_NONE },
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
40 { 7, 'l', "list", "Output list of files that were recognized (implies -i)", OPT_NONE },
2184
5dc1e323d3d4 Rename short option '-p' (probe only) to '-P'.
Matti Hamalainen <ccr@tnsp.org>
parents: 2183
diff changeset
41 { 8, 'P', "probe", "Probe only (do not attempt to decode the image)", OPT_NONE },
2137
903effcd616b Use only long option for char ROM.
Matti Hamalainen <ccr@tnsp.org>
parents: 2126
diff changeset
42 { 9, 0, "char-rom", "Set character ROM file to be used.", OPT_ARGREQ },
407
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 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
46
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 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
49 {
2125
56d4dc81774b Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 2123
diff changeset
50 optScrWidth = (int) ((float) D64_SCR_WIDTH * factor * D64_SCR_PAR_XY);
56d4dc81774b Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 2123
diff changeset
51 optScrHeight = (int) ((float) D64_SCR_HEIGHT * 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
52 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
55 void argShowFormats()
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
56 {
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
57 printf(
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
58 "Available C64 bitmap formats (-f <frmt>):\n"
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
59 " frmt | Type | Description\n"
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
60 "------+-----------------+-------------------------------------\n"
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
61 );
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
62 for (int i = 0; i < ndmC64ImageFormats; i++)
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
63 {
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
64 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
65 char buf[64];
1759
027fb7313d85 Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
66 printf("%-6s| %-15s | %s%s\n",
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
67 fmt->fext,
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1761
diff changeset
68 dmC64GetImageTypeString(buf, sizeof(buf), fmt->format->type, FALSE),
1759
027fb7313d85 Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
69 fmt->name,
027fb7313d85 Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
70 fmt->flags & DM_FMT_BROKEN ? " [BROKEN]" : "");
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
71 }
1667
7f74073813c6 Display number of supported C64 image formats in --formats list of 64vw and gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1666
diff changeset
72 printf("%d formats supported.\n", ndmC64ImageFormats);
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
73 }
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
74
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
75
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 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
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 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
79 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
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
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 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
84 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 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
86 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 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
88 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 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
90 break;
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 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
93 dmVerbosity++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
95
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 case 2:
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
97 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
98 break;
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 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
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 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
103 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
104 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 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
106 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
107 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
108 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 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
112 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
115 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
116 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
117 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 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
122 optForcedFormat = -1;
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
123 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
124 {
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
125 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
126 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
127 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
128 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 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
130 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
131 }
1570
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
132 }
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
133
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
134 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
135 {
04769fa39dd4 Instead of specifying forced input format (-f) as a number in 64vw,
Matti Hamalainen <ccr@tnsp.org>
parents: 1567
diff changeset
136 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
137 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
138 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
140
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
141 case 5:
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
142 argShowFormats();
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
143 exit(0);
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
144 break;
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
145
1666
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
146 case 7:
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
147 optListOnly = TRUE;
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
148 // Fallthrough
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
149
1639
ff794644a70a Add --formats option to 64vw and remove the format listing from --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1596
diff changeset
150 case 6:
1395
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
151 if (dmVerbosity < 1)
009534f27de5 If probe mode is specified, increase verbosity to required level.
Matti Hamalainen <ccr@tnsp.org>
parents: 1391
diff changeset
152 dmVerbosity = 1;
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
153 optInfoOnly = TRUE;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
154 break;
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
155
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
156 case 8:
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
157 if (dmVerbosity < 1)
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
158 dmVerbosity = 1;
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
159 optProbeOnly = TRUE;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
160 break;
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
161
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
162 case 9:
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
163 optCharROMFilename = optArg;
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
164 break;
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
165
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 default:
2183
e3f0eaf23f4f Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 2162
diff changeset
167 dmErrorMsg("Unimplemented option argument '%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
168 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
169 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
170
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 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
172 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
175 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
176 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
177 (void) filename;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
178
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
179 noptFilenames1++;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
180 return TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
181 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
182
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
183
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
184 BOOL argHandleFile2(char *filename)
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 (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
187 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
188 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
189 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
190 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 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
193 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
196 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
197 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
198 Uint8 *dataBuf = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
199 size_t dataSize;
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1667
diff changeset
200 DMGrowBuf tmp;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
201 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
202
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
203 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
204 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
205
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
206 dmGrowBufConstCreateFrom(&tmp, dataBuf, dataSize);
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
207
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
208 if (optProbeOnly)
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
209 ret = dmC64ProbeBMP(&tmp, fmt) != DM_PROBE_SCORE_FALSE ? DMERR_OK : DMERR_NOT_SUPPORTED;
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
210 else
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
211 ret = dmC64DecodeBMP(cimage, &tmp, 0, 2, fmt, forced);
1414
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 exit:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
214 dmFree(dataBuf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
215 return 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
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
218
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
219 int dmDecodeC64Image(DMC64Image *cimage, const DMC64ImageFormat *fmt,
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
220 SDL_Surface *surf, const DMC64ImageConvSpec *spec)
1414
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 DMImage bmap;
2126
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
223 BOOL charDataSet;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
224 int ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
225
1730
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
226 memset(&bmap, 0, sizeof(bmap));
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
227 bmap.size = surf->pitch * surf->h;
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
228 bmap.data = surf->pixels;
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
229 bmap.pitch = surf->pitch;
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
230 bmap.width = surf->w;
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
231 bmap.height = surf->h;
2094
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
232
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
233 if ((ret = dmSetDefaultC64Palette(&bmap)) != DMERR_OK)
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
234 return ret;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
235
2126
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
236 if (cimage->charData[0].data == NULL)
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
237 {
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
238 memcpy(&cimage->charData[0], &setCharROM, sizeof(DMC64MemBlock));
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
239 charDataSet = TRUE;
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
240 }
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
241 else
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
242 charDataSet = FALSE;
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
243
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1761
diff changeset
244 if (fmt->format->convertFrom != NULL)
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
245 ret = fmt->format->convertFrom(&bmap, cimage, fmt, spec);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
246 else
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
247 ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt, spec);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
248
2126
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
249 if (charDataSet)
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
250 memset(&cimage->charData[0], 0, sizeof(DMC64MemBlock));
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
251
2094
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
252 SDL_SetPaletteColors(surf->format->palette, (SDL_Color *) bmap.pal->colors, 0, bmap.pal->ncolors);
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
253
4276b8c0fef0 Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents: 2089
diff changeset
254 dmPaletteFree(bmap.pal);
1730
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1729
diff changeset
255
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
256 return ret;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
257 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
258
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
259
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 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
261 {
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
262 const DMC64ImageFormat *forced;
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
263 DMC64ImageConvSpec spec;
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
264 SDL_Window *window = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
265 SDL_Renderer *renderer = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
266 SDL_Texture *texture = NULL;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
267 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
268 BOOL initSDL = FALSE, exitFlag, needRedraw;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
269 size_t currIndex, prevIndex;
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
270 int res;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1761
diff changeset
272 dmC64InitializeFormats();
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 dmSetScaleFactor(2.0);
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
274 memset(&spec, 0, sizeof(spec));
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
275 memset(&setCharROM, 0, sizeof(setCharROM));
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
276
2162
875e2b7b24dd Change 64vw's short description.
Matti Hamalainen <ccr@tnsp.org>
parents: 2137
diff changeset
277 dmInitProg("64vw", "Displayer for various C64 graphics formats", "0.4", 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
278
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
279 // 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
280 if (!dmArgsProcess(argc, argv, optList, optListN,
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
281 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
282 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
283
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
284 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
285 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
286 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
287 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
288 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
289
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
290 // Allocate space for filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
291 if ((optFilenames = dmCalloc(noptFilenames1, sizeof(char *))) == NULL)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
292 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
293 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
294 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
295 }
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 // Assign the filename pointers
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
298 if (!dmArgsProcess(argc, argv, optList, optListN,
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
299 NULL, argHandleFile2, OPTH_BAILOUT | OPTH_ONLY_OTHER))
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
300 goto exit;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
301
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
302 // 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
303 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
304 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
305 forced = &dmC64ImageFormats[optForcedFormat];
1391
f3c5f80511ae Add "probe only" mode to view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1386
diff changeset
306 dmMsg(0, "Forced %s format image, type %d, %s\n",
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1761
diff changeset
307 forced->name, forced->format->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
308 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 else
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
310 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
311
1729
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
312 // If we are simply displaying file information, no need to initialize SDL etc
f4015f6cb173 Add new option -i for printing information about the images
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
313 if (optInfoOnly || optProbeOnly)
1414
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 for (size_t n = 0; n < noptFilenames2; n++)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
316 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
317 char *filename = optFilenames[n];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
318 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
319 DMC64Image *cimage = NULL;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
320
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
321 if ((res = dmReadC64Image(filename, forced, &fmt, &cimage)) != DMERR_OK)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
322 {
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
323 if (!optListOnly && res != DMERR_NOT_SUPPORTED)
1666
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
324 {
1998
0d19d0a47faf Improve error message for not being able to decode the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 1947
diff changeset
325 dmErrorMsg("Could not decode file '%s': %s\n",
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
326 filename, dmErrorStr(res));
1666
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
327 }
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
328 }
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
329 else
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
330 if (optListOnly)
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
331 {
94d45136a6fd Add option to 64vw to list only filenames of recognized files (-l). Implies probe (-p).
Matti Hamalainen <ccr@tnsp.org>
parents: 1639
diff changeset
332 fprintf(stdout, "%s\n", filename);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
333 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
334 else
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
335 {
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
336 fprintf(stdout, "\n%s\n", filename);
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1787
diff changeset
337 dmC64ImageDump(stdout, cimage, fmt, " ");
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
338 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
339
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
340 dmC64ImageFree(cimage);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
341 }
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
342 goto exit;
938
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
343 }
ba812817a281 Various fixes in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
344
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
345 // Check character ROM filename
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
346 if (optCharROMFilename == NULL)
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
347 optCharROMFilename = DM_DEF_CHARGEN;
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
348
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
349 // Attempt to read character ROM
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
350 dmMsg(1, "Using character ROM file '%s'.\n",
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
351 optCharROMFilename);
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
352
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
353 if ((res = dmReadDataFile(NULL, optCharROMFilename,
2126
cffadb745484 Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 2125
diff changeset
354 &setCharROM.data, &setCharROM.size)) != DMERR_OK)
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
355 {
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
356 dmErrorMsg("Could not read character ROM from '%s'.\n",
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
357 optCharROMFilename);
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
358 }
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
359
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 // 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
361 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
362 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 941
diff changeset
363 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
364 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
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 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
367
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
368 // Open window
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
369 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
370 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
371 optScrWidth, optScrHeight,
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
372 optVFlags | SDL_WINDOW_RESIZABLE
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
373 //| SDL_WINDOW_HIDDEN
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
374 )) == 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
375 {
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
376 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
377 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
378 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
380 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
381 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
382 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
383 goto exit;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
384 }
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
385
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
386 // 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
387
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 // Start main loop
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
389 currIndex = 0;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
390 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
391 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
392 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
393 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
394 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 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
396 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
397 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
398 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 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
400 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
401 {
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
402 case SDLK_ESCAPE:
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
403 case SDLK_q:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
404 exitFlag = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
405 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
406
1595
1eb8c1dc81fd Add arrow up and down keys as alias controls to left and right.
Matti Hamalainen <ccr@tnsp.org>
parents: 1576
diff changeset
407 case SDLK_DOWN:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
408 case SDLK_LEFT:
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
409 if (currIndex > 0)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
410 currIndex--;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
411 else
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
412 currIndex = 0;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
413 break;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
414
2073
1ad8382e3670 Make space-key go to next image in addition to arrow right/up.
Matti Hamalainen <ccr@tnsp.org>
parents: 2072
diff changeset
415 case SDLK_SPACE:
1595
1eb8c1dc81fd Add arrow up and down keys as alias controls to left and right.
Matti Hamalainen <ccr@tnsp.org>
parents: 1576
diff changeset
416 case SDLK_UP:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
417 case SDLK_RIGHT:
1417
36016db0d0b3 Oops, the check for maximum filename index was wrong.
Matti Hamalainen <ccr@tnsp.org>
parents: 1415
diff changeset
418 if (currIndex < noptFilenames2 - 1)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
419 currIndex++;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
420 else
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
421 currIndex = noptFilenames2 - 1;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
422 break;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
423
1553
e68d3b16c79e Oops, reverse the meaning of PageUp and PageDown. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1552
diff changeset
424 case SDLK_PAGEDOWN:
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
425 if (currIndex > SET_SKIP_AMOUNT)
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
426 currIndex -= SET_SKIP_AMOUNT;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
427 else
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
428 currIndex = 0;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
429 break;
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
430
1553
e68d3b16c79e Oops, reverse the meaning of PageUp and PageDown. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1552
diff changeset
431 case SDLK_PAGEUP:
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
432 if (currIndex < noptFilenames2 - 1 - SET_SKIP_AMOUNT)
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
433 currIndex += SET_SKIP_AMOUNT;
1552
fdd3a02d830f Add Page Up and Down keys to 64vw controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 1517
diff changeset
434 else
1565
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
435 currIndex = noptFilenames2 - 1;
58aa34bb4f03 Fix page up/down skip amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
436 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
437
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
438 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
439 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
440 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
441
e5be5235e7e1 Make home/end keys to go to first and last file respectively in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1572
diff changeset
442 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
443 currIndex = noptFilenames2 - 1;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
444 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
445
1567
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
446 case SDLK_f:
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
447 optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
448 if (SDL_SetWindowFullscreen(window, optVFlags) != 0)
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
449 goto exit;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
450 break;
e81c8c7a348f Add fullscreen toggle support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1566
diff changeset
451
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 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
457 break;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
458
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
459 case SDL_WINDOWEVENT:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
460 switch (event.window.event)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
461 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
462 case SDL_WINDOWEVENT_EXPOSED:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
463 needRedraw = TRUE;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
464 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
465
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
466 case SDL_WINDOWEVENT_RESIZED:
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
467 optScrWidth = event.window.data1;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
468 optScrHeight = event.window.data2;
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
469
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
470 needRedraw = TRUE;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
471 break;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
472 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 case SDL_QUIT:
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
476 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
477 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
478
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
479 if (currIndex != prevIndex)
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
480 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
481 char *filename = optFilenames[currIndex];
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
482 const DMC64ImageFormat *fmt = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
483 DMC64Image *cimage = NULL;
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
484 char *title = NULL;
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
485
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 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
488 SDL_FreeSurface(surf);
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
489 surf = NULL;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
490 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
491
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
492 if ((res = dmReadC64Image(filename, forced, &fmt, &cimage)) != DMERR_OK)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
493 {
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
494 if (res != DMERR_NOT_SUPPORTED)
1999
64730556fd94 Only show error message if the error is other than "not supported".
Matti Hamalainen <ccr@tnsp.org>
parents: 1998
diff changeset
495 {
64730556fd94 Only show error message if the error is other than "not supported".
Matti Hamalainen <ccr@tnsp.org>
parents: 1998
diff changeset
496 dmErrorMsg("Could not decode file '%s': %s\n",
2199
f331cc750b37 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 2184
diff changeset
497 filename, dmErrorStr(res));
1999
64730556fd94 Only show error message if the error is other than "not supported".
Matti Hamalainen <ccr@tnsp.org>
parents: 1998
diff changeset
498 }
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
499 goto fail;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
500 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
501
1420
9b7915193683 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1417
diff changeset
502 if (fmt == NULL || cimage == NULL)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
503 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
504 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
505 goto fail;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
506 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
507
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
508 // Create surface (we are lazy and ugly)
1566
3b53b289df0e Use SDL_CreateRGBSurfaceWithFormat().
Matti Hamalainen <ccr@tnsp.org>
parents: 1565
diff changeset
509 if ((surf = SDL_CreateRGBSurfaceWithFormat(0,
1947
8896d5676f1b Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents: 1931
diff changeset
510 cimage->fmt->width, cimage->fmt->height,
8896d5676f1b Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents: 1931
diff changeset
511 8, SDL_PIXELFORMAT_INDEX8)) == NULL)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
512 {
1515
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
513 dmC64ImageFree(cimage);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
514 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
515 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
516 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
517
1931
410679d2fe8a "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents: 1837
diff changeset
518 if (dmDecodeC64Image(cimage, fmt, surf, &spec) == DMERR_OK)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
519 {
1572
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
520 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
521 dmProgName,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
522 currIndex + 1,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
523 noptFilenames2,
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
524 filename,
1947
8896d5676f1b Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents: 1931
diff changeset
525 cimage->fmt->width, cimage->fmt->height,
1572
4643cd757c0b Try to make the window title more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 1571
diff changeset
526 fmt->name);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
527
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
528 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
529 {
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
530 fprintf(stdout, "\n%s\n", filename);
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1787
diff changeset
531 dmC64ImageDump(stdout, cimage, fmt, " ");
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
532 }
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
533 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
534
1516
530ce92c513f Better leak fix. :D
Matti Hamalainen <ccr@tnsp.org>
parents: 1515
diff changeset
535 fail:
1515
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
536 dmC64ImageFree(cimage);
66c75f6982e2 Plug some memory leaks in 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
537
1566
3b53b289df0e Use SDL_CreateRGBSurfaceWithFormat().
Matti Hamalainen <ccr@tnsp.org>
parents: 1565
diff changeset
538 if (surf == NULL && (surf = SDL_CreateRGBSurfaceWithFormat(0,
2125
56d4dc81774b Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 2123
diff changeset
539 D64_SCR_WIDTH, D64_SCR_HEIGHT, 8, SDL_PIXELFORMAT_INDEX8)) == NULL)
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
540 {
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
541 dmErrorMsg("Could not allocate surface.\n");
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
542 goto exit;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
543 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
544
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
545
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
546 if (texture != NULL)
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
547 SDL_DestroyTexture(texture);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
548
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
549 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
550 {
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
551 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
552 goto exit;
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
553 }
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
554
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
555 if (title == NULL)
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
556 {
2072
6677535b8b9f Canonicalize the 64vw window title in case of non-supported files.
Matti Hamalainen <ccr@tnsp.org>
parents: 1999
diff changeset
557 title = dm_strdup_printf("%s - [%d / %d] %s",
6677535b8b9f Canonicalize the 64vw window title in case of non-supported files.
Matti Hamalainen <ccr@tnsp.org>
parents: 1999
diff changeset
558 dmProgName,
6677535b8b9f Canonicalize the 64vw window title in case of non-supported files.
Matti Hamalainen <ccr@tnsp.org>
parents: 1999
diff changeset
559 currIndex + 1,
2111
2d0db1e6b4a7 Oops, missing printf argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 2102
diff changeset
560 noptFilenames2,
2d0db1e6b4a7 Oops, missing printf argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 2102
diff changeset
561 filename);
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
562 }
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
563
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
564 SDL_SetWindowTitle(window, title);
1423
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
565 dmFree(title);
065dedf5890e Fix view64 window title updating.
Matti Hamalainen <ccr@tnsp.org>
parents: 1420
diff changeset
566
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
567 needRedraw = TRUE;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
568 prevIndex = currIndex;
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
569 }
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
570
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 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
572 {
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
573 SDL_RenderClear(renderer);
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1553
diff changeset
574 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
575 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
576 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
577 }
1238
e8c99da451cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
578
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
579 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
580 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581
1410
c29f1cea4a1c Rename a label.
Matti Hamalainen <ccr@tnsp.org>
parents: 1404
diff changeset
582 exit:
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
583 // Cleanup
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
584 dmFree(optFilenames);
2123
47ddbedf5b56 Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents: 2120
diff changeset
585 dmC64MemBlockFree(&setCharROM);
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
586
2102
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
587 if (texture != NULL)
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
588 SDL_DestroyTexture(texture);
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
589
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
590 if (renderer != NULL)
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
591 SDL_DestroyRenderer(renderer);
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
592
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
593 if (window != NULL)
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
594 SDL_DestroyWindow(window);
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
595
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
596 if (surf != NULL)
e0281dae2cb8 Backed out changeset dcca36701cdd
Matti Hamalainen <ccr@tnsp.org>
parents: 2094
diff changeset
597 SDL_FreeSurface(surf);
1414
d6ee4dcef692 Implement multi file support in view64.
Matti Hamalainen <ccr@tnsp.org>
parents: 1410
diff changeset
598
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 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
600 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
601
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 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
603 }