-/* readwrite.c */
+/* readwrite.c */
#include "readwrite.h"
#include <stdio.h>
#include <stdint.h>
-extern uint16_t read_uint16_bigendian( FILE * file )
+extern uint16_t read_uint16_bigendian(FILE * file)
{
uint16_t x;
x = (uint16_t) fgetc(file) << 8;
return x;
}
-extern uint32_t read_uint32_bigendian( FILE * file )
+extern uint32_t read_uint32_bigendian(FILE * file)
{
uint32_t x;
x = (uint32_t) fgetc(file) << 24;
return x;
}
-extern void write_uint16_bigendian( uint16_t x, FILE * file )
+extern void write_uint16_bigendian(uint16_t x, FILE * file)
{
fputc( x >> 8, file );
fputc( x & 0xFF, file );
}
-extern void write_uint32_bigendian( uint32_t x, FILE * file )
+extern void write_uint32_bigendian(uint32_t x, FILE * file)
{
fputc( x >> 24, file);
fputc( ( x >> 16 ) & 0xFF, file);
-/* readwrite.h:
+/* readwrite.h:
*
- * Routines for reading/writing multibyte data from/to files. They ensure a
- * defined endianness.
+ * Routines for reading/writing multibyte data from/to files. They ensure a
+ * defined endianness.
*/
#ifndef READWRITE_H
#include <stdio.h>
#include <stdint.h>
-extern uint16_t read_uint16_bigendian( FILE * file );
-extern uint32_t read_uint32_bigendian( FILE * file );
-extern void write_uint16_bigendian( uint16_t x, FILE * file );
-extern void write_uint32_bigendian( uint32_t x, FILE * file );
+extern uint16_t read_uint16_bigendian(FILE * file);
+extern uint32_t read_uint32_bigendian(FILE * file);
+extern void write_uint16_bigendian(uint16_t x, FILE * file);
+extern void write_uint32_bigendian(uint32_t x, FILE * file);
#endif
-#include "yx_uint16.h"
+/* yx_uint16.c */
-extern char yx_uint16_cmp (struct yx_uint16 a, struct yx_uint16 b) {
-// Compare two coordinates of type yx_uint16.
- if (a.y == b.y && a.x == b.x) return 1;
- else return 0; }
+#include "yx_uint16.h"
-extern struct yx_uint16 mv_yx_in_dir (enum dir d, struct yx_uint16 yx) {
-// Return yx coordinates one step to the direction d of yx.
- if (d == NORTH) yx.y--;
- else if (d == EAST) yx.x++;
- else if (d == SOUTH) yx.y++;
- else if (d == WEST) yx.x--;
- return yx; }
+extern char yx_uint16_cmp(struct yx_uint16 a, struct yx_uint16 b)
+{
+ if (a.y == b.y && a.x == b.x)
+ return 1;
+ else
+ return 0;
+}
+extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx)
+{
+ if (d == NORTH)
+ yx.y--;
+ else if (d == EAST)
+ yx.x++;
+ else if (d == SOUTH)
+ yx.y++;
+ else if (d == WEST)
+ yx.x--;
+ return yx;
+}
+/* yx_uint16.h
+ *
+ * Structs and routines for coordinates and movement in 2-dimensional space
+ * (such as the ncurses screen and game maps).
+ */
+
#ifndef YX_UINT16_H
#define YX_UINT16_H
#include <stdint.h>
-enum dir {
- NORTH = 1,
- EAST = 2,
- SOUTH = 3,
- WEST = 4 };
+/* Coordinates for maps of max. 65536x65536 cells. */
+struct yx_uint16
+{
+ uint16_t y;
+ uint16_t x;
+};
+
+/* This encodes directions. */
+
+enum dir
+{
+ NORTH = 1,
+ EAST = 2,
+ SOUTH = 3,
+ WEST = 4
+};
-struct yx_uint16 {
- uint16_t y;
- uint16_t x; };
+/* Return 1 if two yx_uint16 coordinates a and b are equal, else 0. */
+extern char yx_uint16_cmp(struct yx_uint16 a, struct yx_uint16 b);
-extern char yx_uint16_cmp (struct yx_uint16, struct yx_uint16);
-extern struct yx_uint16 mv_yx_in_dir (enum dir, struct yx_uint16);
+/* Return yx_uint16 coordinate one step from coordinate yx in direction dir. */
+extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx);
#endif