bd_c64import.c \
bd_gameplay.c \
bd_graphics.c \
+ bd_colors.c \
bd_random.c \
bd_sound.c
bd_c64import.o \
bd_gameplay.o \
bd_graphics.o \
+ bd_colors.o \
bd_random.o \
bd_sound.o
gd_cave_adler_checksum_more(cave, &a, &b);
return (b << 16) + a;
}
-
-/* return c64 color with index. */
-GdColor gd_c64_color(int index)
-{
- return (GD_COLOR_TYPE_C64 << 24) + index;
-}
#define BD_CAVE_H
#include "bd_elements.h"
+#include "bd_colors.h"
#include "bd_random.h"
-// colors
-
-typedef unsigned int GdColor;
-
-/* color internal:
- XXRRGGBB;
- XX is 0 for RGB,
- 1 for c64 colors (bb=index)
- 3 for c64dtv (bb=index)
- 2 for atari colors (bb=index)
-*/
-
-typedef enum _color_type
-{
- GD_COLOR_TYPE_RGB = 0,
- GD_COLOR_TYPE_C64 = 1,
- GD_COLOR_TYPE_C64DTV = 2,
- GD_COLOR_TYPE_ATARI = 3,
-
- GD_COLOR_TYPE_UNKNOWN /* should be the last one */
-} GdColorType;
-
-/* traditional c64 color indexes. */
-#define GD_COLOR_INDEX_BLACK (0)
-#define GD_COLOR_INDEX_WHITE (1)
-#define GD_COLOR_INDEX_RED (2)
-#define GD_COLOR_INDEX_CYAN (3)
-#define GD_COLOR_INDEX_PURPLE (4)
-#define GD_COLOR_INDEX_GREEN (5)
-#define GD_COLOR_INDEX_BLUE (6)
-#define GD_COLOR_INDEX_YELLOW (7)
-#define GD_COLOR_INDEX_ORANGE (8)
-#define GD_COLOR_INDEX_BROWN (9)
-#define GD_COLOR_INDEX_LIGHTRED (10)
-#define GD_COLOR_INDEX_GRAY1 (11)
-#define GD_COLOR_INDEX_GRAY2 (12)
-#define GD_COLOR_INDEX_LIGHTGREEN (13)
-#define GD_COLOR_INDEX_LIGHTBLUE (14)
-#define GD_COLOR_INDEX_GRAY3 (15)
-
-#define GD_GDASH_BLACK (0x000000)
-#define GD_GDASH_WHITE (0xFFFFFF)
-#define GD_GDASH_RED (0x880000)
-#define GD_GDASH_CYAN (0xAAFFEE)
-#define GD_GDASH_PURPLE (0xCC44CC)
-#define GD_GDASH_GREEN (0x00CC55)
-#define GD_GDASH_BLUE (0x0000AA)
-#define GD_GDASH_YELLOW (0xEEEE77)
-#define GD_GDASH_ORANGE (0xDD8855)
-#define GD_GDASH_BROWN (0x664400)
-#define GD_GDASH_LIGHTRED (0xFF7777)
-#define GD_GDASH_GRAY1 (0x333333)
-#define GD_GDASH_GRAY2 (0x777777)
-#define GD_GDASH_LIGHTGREEN (0xAAFF66)
-#define GD_GDASH_LIGHTBLUE (0x0088FF)
-#define GD_GDASH_GRAY3 (0xBBBBBB)
-
-#define GD_COLOR_INVALID (0xFFFFFFFF)
-
-
/******************************************
*
* BIG STRUCT HANDLING
unsigned int gd_cave_adler_checksum(GdCave *cave);
void gd_cave_adler_checksum_more(GdCave *cave, unsigned int *a, unsigned int *b);
-GdColor gd_c64_color(int);
-
#endif // BD_CAVE_H
--- /dev/null
+/*
+ * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "main_bd.h"
+
+
+static char *c64_color_names[] =
+{
+ "Black",
+ "White",
+ "Red",
+ "Cyan",
+ "Purple",
+ "Green",
+ "Blue",
+ "Yellow",
+ "Orange",
+ "Brown",
+ "LightRed",
+ "Gray1",
+ "Gray2",
+ "LightGreen",
+ "LightBlue",
+ "Gray3",
+};
+
+/* return c64 color with index. */
+GdColor gd_c64_color(int index)
+{
+ return (GD_COLOR_TYPE_C64 << 24) + index;
+}
+
+/* return atari color with index. */
+GdColor gd_atari_color(int index)
+{
+ return (GD_COLOR_TYPE_ATARI << 24) + index;
+}
+
+/* return c64dtv color with index. */
+GdColor gd_c64dtv_color(int index)
+{
+ return (GD_COLOR_TYPE_C64DTV << 24) + index;
+}
+
+/* return "unknown color" */
+static GdColor unknown_color(void)
+{
+ return (GD_COLOR_TYPE_UNKNOWN << 24);
+}
+
+/* make up GdColor from r,g,b values. */
+GdColor gd_color_get_from_rgb(int r, int g, int b)
+{
+ return (GD_COLOR_TYPE_RGB << 24) + (r << 16) + (g << 8) + b;
+}
+
+GdColor gd_color_get_from_string(const char *color)
+{
+ int i, r, g, b;
+
+ for (i = 0; i < ARRAY_SIZE(c64_color_names); i++)
+ if (strEqualCase(color, c64_color_names[i]))
+ return gd_c64_color(i);
+
+ /* we do not use sscanf(color, "atari..." as may be lowercase */
+ if (strEqualCaseN(color, "Atari", strlen("Atari")))
+ {
+ const char *b = color + strlen("Atari");
+ int c;
+
+ if (sscanf(b, "%02x", &c) == 1)
+ return gd_atari_color(c);
+
+ Warn("Unknown Atari color: %s", color);
+
+ return unknown_color();
+ }
+
+ /* we do not use sscanf(color, "c64dtv..." as may be lowercase */
+ if (strEqualCaseN(color, "C64DTV", strlen("C64DTV")))
+ {
+ const char *b = color + strlen("C64DTV");
+ int c;
+
+ if (sscanf(b, "%02x", &c) == 1)
+ return gd_c64dtv_color(c);
+
+ Warn("Unknown C64DTV color: %s", color);
+
+ return unknown_color();
+ }
+
+ /* may or may not have a # */
+ if (color[0] == '#')
+ color++;
+
+ if (sscanf(color, "%02x%02x%02x", &r, &g, &b) != 3)
+ {
+ i = gd_random_int_range(0, 16);
+
+ Warn("Unkonwn color %s", color);
+
+ return unknown_color();
+ }
+
+ return gd_color_get_from_rgb(r, g, b);
+}
+
+const char *gd_color_get_string(GdColor color)
+{
+ static char text[16];
+
+ if (gd_color_is_c64(color))
+ {
+ return c64_color_names[color & 0xff];
+ }
+
+ if (gd_color_is_atari(color))
+ {
+ sprintf(text, "Atari%02x", color & 0xff);
+ return text;
+ }
+
+ if (gd_color_is_dtv(color))
+ {
+ sprintf(text, "C64DTV%02x", color & 0xff);
+ return text;
+ }
+
+ sprintf(text, "#%02x%02x%02x", (color >> 16) & 255, (color >> 8) & 255, color & 255);
+ return text;
+}
+
+boolean gd_color_is_c64(GdColor color)
+{
+ return (color >> 24) == GD_COLOR_TYPE_C64;
+}
+
+boolean gd_color_is_atari(GdColor color)
+{
+ return (color >> 24) == GD_COLOR_TYPE_ATARI;
+}
+
+boolean gd_color_is_dtv(GdColor color)
+{
+ return (color >> 24) == GD_COLOR_TYPE_C64DTV;
+}
+
+boolean gd_color_is_unknown(GdColor color)
+{
+ return (color >> 24) == GD_COLOR_TYPE_UNKNOWN;
+}
+
+GdColor gd_gdash_color(int c)
+{
+ /* these values are taken from the title screen, drawn by cws. */
+ /* so menus and everything else will look nice! */
+ /* the 16 colors that can be used are the same as on c64. */
+ /* "Black", "White", "Red", "Cyan", "Purple", "Green", "Blue", "Yellow", */
+ /* "Orange", "Brown", "LightRed", "Gray1", "Gray2", "LightGreen", "LightBlue", "Gray3", */
+ /* not in the png: cyan, purple. gray3 is darker in the png. */
+ /* 17th color is the player's leg in the png. i not connected it to any c64 */
+ /* color, but it is used for theme images for example. */
+ const GdColor gdash_colors[] =
+ {
+ 0x000000, 0xffffff, 0xe33939, 0x55aaaa, 0xaa55aa, 0x71aa55, 0x0039ff, 0xffff55,
+ 0xe37139, 0xaa7139, 0xe09080, 0x555555, 0x717171, 0xc6e38e, 0xaaaaff, 0x8e8e8e,
+
+ 0x5555aa,
+ };
+
+ return gdash_colors[c];
+}
--- /dev/null
+/*
+ * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef BD_COLORS_H
+#define BD_COLORS_H
+
+
+typedef unsigned int GdColor;
+
+/* color internal:
+ XXRRGGBB;
+ XX is 0 for RGB,
+ 1 for c64 colors (bb=index)
+ 3 for c64dtv (bb=index)
+ 2 for atari colors (bb=index)
+*/
+
+typedef enum _color_type
+{
+ GD_COLOR_TYPE_RGB = 0,
+ GD_COLOR_TYPE_C64 = 1,
+ GD_COLOR_TYPE_C64DTV = 2,
+ GD_COLOR_TYPE_ATARI = 3,
+
+ GD_COLOR_TYPE_UNKNOWN /* should be the last one */
+} GdColorType;
+
+/* traditional c64 color indexes. */
+#define GD_COLOR_INDEX_BLACK (0)
+#define GD_COLOR_INDEX_WHITE (1)
+#define GD_COLOR_INDEX_RED (2)
+#define GD_COLOR_INDEX_PURPLE (4)
+#define GD_COLOR_INDEX_CYAN (3)
+#define GD_COLOR_INDEX_GREEN (5)
+#define GD_COLOR_INDEX_BLUE (6)
+#define GD_COLOR_INDEX_YELLOW (7)
+#define GD_COLOR_INDEX_ORANGE (8)
+#define GD_COLOR_INDEX_BROWN (9)
+#define GD_COLOR_INDEX_LIGHTRED (10)
+#define GD_COLOR_INDEX_GRAY1 (11)
+#define GD_COLOR_INDEX_GRAY2 (12)
+#define GD_COLOR_INDEX_LIGHTGREEN (13)
+#define GD_COLOR_INDEX_LIGHTBLUE (14)
+#define GD_COLOR_INDEX_GRAY3 (15)
+
+#define GD_GDASH_BLACK (gd_gdash_color(GD_COLOR_INDEX_BLACK))
+#define GD_GDASH_WHITE (gd_gdash_color(GD_COLOR_INDEX_WHITE))
+#define GD_GDASH_RED (gd_gdash_color(GD_COLOR_INDEX_RED))
+#define GD_GDASH_PURPLE (gd_gdash_color(GD_COLOR_INDEX_PURPLE))
+#define GD_GDASH_CYAN (gd_gdash_color(GD_COLOR_INDEX_CYAN))
+#define GD_GDASH_GREEN (gd_gdash_color(GD_COLOR_INDEX_GREEN))
+#define GD_GDASH_BLUE (gd_gdash_color(GD_COLOR_INDEX_BLUE))
+#define GD_GDASH_YELLOW (gd_gdash_color(GD_COLOR_INDEX_YELLOW))
+#define GD_GDASH_ORANGE (gd_gdash_color(GD_COLOR_INDEX_ORANGE))
+#define GD_GDASH_BROWN (gd_gdash_color(GD_COLOR_INDEX_BROWN))
+#define GD_GDASH_LIGHTRED (gd_gdash_color(GD_COLOR_INDEX_LIGHTRED))
+#define GD_GDASH_GRAY1 (gd_gdash_color(GD_COLOR_INDEX_GRAY1))
+#define GD_GDASH_GRAY2 (gd_gdash_color(GD_COLOR_INDEX_GRAY2))
+#define GD_GDASH_LIGHTGREEN (gd_gdash_color(GD_COLOR_INDEX_LIGHTGREEN))
+#define GD_GDASH_LIGHTBLUE (gd_gdash_color(GD_COLOR_INDEX_LIGHTBLUE))
+#define GD_GDASH_GRAY3 (gd_gdash_color(GD_COLOR_INDEX_GRAY3))
+
+#define GD_GDASH_MIDDLEBLUE (gd_gdash_color(16))
+
+#define GD_COLOR_INVALID (0xFFFFFFFF)
+
+
+/* color */
+GdColor gd_c64_color(int index);
+GdColor gd_atari_color(int index);
+GdColor gd_c64dtv_color(int index);
+GdColor gd_color_get_from_rgb(int r, int g, int b);
+GdColor gd_color_get_from_string(const char *color);
+const char *gd_color_get_string(GdColor color);
+
+boolean gd_color_is_c64(GdColor color);
+boolean gd_color_is_atari(GdColor color);
+boolean gd_color_is_dtv(GdColor color);
+boolean gd_color_is_unknown(GdColor color);
+
+GdColor gd_gdash_color(int c);
+
+#endif // BD_COLORS_H
#include "bd_gameplay.h"
#include "bd_c64import.h"
#include "bd_graphics.h"
+#include "bd_colors.h"
#include "bd_random.h"
#include "bd_sound.h"