/ = copy of pngwen's code\r
16/ = the current code sparky4 is working with\r
16/modex16/ = pngwen's code archived\r
+src/ = source of project~\r
\r
TODO not in particular order~:\r
DONE 1. SCROLLING!!!!!!!\r
DONE 5. sprite rendering\r
6. text box rendering\r
7. text rendering\r
-8. map loading\r
+DONE! YAY! 8. map loading\r
9. map rendering~\r
10. map and item interation\r
11. item inventory~\r
DONE 15. 8088 detection to turn off vsync!\r
16. (very important!) optoimize draw row and draw col\r
\r
-17. merge map system and interperator from verge 2\r
+not needed ... really... 17. merge map system and interperator from verge 2\r
18. save feature!\r
19. (also important) interperator! and possibly custom map system\r
20. (also important) lua scripting system!\r
#include <string.h>
#include <errno.h>
#include "../jsmn.c"
+#include "../../../lib/types.h"
/*
* An example of reading JSON from stdin and printing its content to stdout.
* The output looks like YAML, but I'm not sure if it's really compatible.
- */
+ */\r
+
+char *js_sv;
+
+typedef struct {\r
+ //bitmap_t *data;
+ byte *data;\r
+ word tileHeight;\r
+ word tileWidth;\r
+ unsigned int rows;\r
+ unsigned int cols;\r
+} tiles_t;\r
+\r
+typedef struct {\r
+ byte *data;\r
+ tiles_t *tiles;\r
+ int width;\r
+ int height;\r
+} map_t;
static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&
return -1;
}
-static int dump(const char *js, jsmntok_t *t, size_t count, int indent) {
+static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *js_sv,*/ map_t *map) {
int i, j, k;
if (count == 0) {
return 0;
}
+ /* We may want to do strtol() here to get numeric value */
if (t->type == JSMN_PRIMITIVE) {
- printf("%.*s", t->end - t->start, js+t->start);
+ if(js_sv == "height")
+ {
+ map->height = (int)strtol(js+t->start, (char **)js+t->end, 10);
+ printf("h:[%d]\n", map->height);
+ }else if(js_sv == "width")
+ {
+ map->width = (int)strtol(js+t->start, (char **)js+t->end, 10);
+ printf("w:[%d]\n", map->width);
+ }
return 1;
+ /* We may use strndup() to fetch string value */
} else if (t->type == JSMN_STRING) {
- printf("'%.*s'", t->end - t->start, js+t->start);
- /*if (jsoneq(js, t, "image") == 0) {
- printf("- image: %.*s\n", t->end-t->start,
- js + t->start);
- }*/
+ //printf("'%.*s'", t->end - t->start, js+t->start);
+ if (jsoneq(js, t, "height") == 0 && indent==1)
+ {
+ js_sv="height";//strdup(js+t->start);//, t->end - t->start);
+ printf("%s\n", js_sv);
+ }else if (jsoneq(js, t, "width") == 0 && indent==1)
+ {
+ js_sv="width";//strdup(js+t->start);//, t->end - t->start);
+ printf("%s\n", js_sv);
+ }else js_sv=NULL;
return 1;
} else if (t->type == JSMN_OBJECT) {
- printf("\n");
+ //printf("\n");
j = 0;
for (i = 0; i < t->size; i++) {
//for (k = 0; k < indent; k++) printf("\t");
- j += dump(js, t+1+j, count-j, indent+1);
- printf(": ");
- j += dump(js, t+1+j, count-j, indent+1);
- printf("\n");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf(": ");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf("\n");
}
return j+1;
} else if (t->type == JSMN_ARRAY) {
j = 0;
- printf("\n");
+ //printf("==\n");
for (i = 0; i < t->size; i++) {
//for (k = 0; k < indent-1; k++) printf("\t");
- printf("\t-");
- j += dump(js, t+1+j, count-j, indent+1);
- printf("\n");
+ //printf("\t-");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf("==\n");
}
return j+1;
}
return 0;
}
-int main() {
+int loadmap(char *mn, map_t *map)
+{
int r;
int eof_expected = 0;
char *js = NULL;
jsmntok_t *tok;
size_t tokcount = 2;
- FILE *fh = fopen("../../../../data/test.map", "r");
+ FILE *fh = fopen(mn, "r");
/* Prepare parser */
jsmn_init(&p);
goto again;
}
} else {
- dump(js, tok, p.toknext, 0);
+ dump(js, tok, p.toknext, 0, map);
//fprintf(stdout, "[[[[%d]]]]\n", sizeof(tok));
- printf("[\n%d\n]", jslen);
+ //printf("[\n%d\n]", jslen);
eof_expected = 1;
}
}
return 0;
}
+
+int main()
+{
+ map_t map;
+ loadmap("../../../../data/test.map", &map);
+ return 0;
+}
#include <stdio.h>
#include <conio.h> // just for wait
#include <time.h> // just for wait
-#include "src\lib\types.h"
+#include "src/lib/types.h"
/* Control codes for all keys on the keyboard */
//here temperarly
--- /dev/null
+#include "src/lib/mapread.h"
+
+static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
+ if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&
+ strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
+ return 0;
+ }
+ return -1;
+}
+
+static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *js_sv,*/ map_t *map) {
+ int i, j, k;
+ if (count == 0) {
+ return 0;
+ }
+ /* We may want to do strtol() here to get numeric value */
+ if (t->type == JSMN_PRIMITIVE) {
+ if(js_sv == "height")
+ {
+ map->height = (int)strtol(js+t->start, (char **)js+t->end, 10);
+ printf("h:[%d]\n", map->height);
+ }else if(js_sv == "width")
+ {
+ map->width = (int)strtol(js+t->start, (char **)js+t->end, 10);
+ printf("w:[%d]\n", map->width);
+ }
+ return 1;
+ /* We may use strndup() to fetch string value */
+ } else if (t->type == JSMN_STRING) {
+ //printf("'%.*s'", t->end - t->start, js+t->start);
+ if (jsoneq(js, t, "height") == 0 && indent==1)
+ {
+ js_sv="height";//strdup(js+t->start);//, t->end - t->start);
+ printf("%s\n", js_sv);
+ }else if (jsoneq(js, t, "width") == 0 && indent==1)
+ {
+ js_sv="width";//strdup(js+t->start);//, t->end - t->start);
+ printf("%s\n", js_sv);
+ }else js_sv=NULL;
+ return 1;
+ } else if (t->type == JSMN_OBJECT) {
+ //printf("\n");
+ j = 0;
+ for (i = 0; i < t->size; i++) {
+ //for (k = 0; k < indent; k++) printf("\t");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf(": ");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf("\n");
+ }
+ return j+1;
+ } else if (t->type == JSMN_ARRAY) {
+ j = 0;
+ //printf("==\n");
+ for (i = 0; i < t->size; i++) {
+ //for (k = 0; k < indent-1; k++) printf("\t");
+ //printf("\t-");
+ j += dump(js, t+1+j, count-j, indent+1, map);
+ //printf("==\n");
+ }
+ return j+1;
+ }
+ return 0;
+}
+
+int loadmap(char *mn, map_t *map)
+{
+ int r;
+ int eof_expected = 0;
+ char *js = NULL;
+ size_t jslen = 0;
+ char buf[BUFSIZ];
+
+ jsmn_parser p;
+ jsmntok_t *tok;
+ size_t tokcount = 2;
+
+ FILE *fh = fopen(mn, "r");
+
+ /* Prepare parser */
+ jsmn_init(&p);
+
+ /* Allocate some tokens as a start */
+ tok = malloc(sizeof(*tok) * tokcount);
+ if (tok == NULL) {
+ fprintf(stderr, "malloc(): errno=%d\n", errno);
+ return 3;
+ }
+
+ for (;;) {
+ /* Read another chunk */
+ r = fread(buf, 1, sizeof(buf), fh);
+ if (r < 0) {
+ fprintf(stderr, "fread(): %d, errno=%d\n", r, errno);
+ return 1;
+ }
+ if (r == 0) {
+ if (eof_expected != 0) {
+ return 0;
+ } else {
+ fprintf(stderr, "fread(): unexpected EOF\n");
+ return 2;
+ }
+ }
+
+ js = realloc(js, jslen + r + 1);
+ if (js == NULL) {
+ fprintf(stderr, "realloc(): errno=%d\n", errno);
+ return 3;
+ }
+ strncpy(js + jslen, buf, r);
+ jslen = jslen + r;
+
+again:
+ r = jsmn_parse(&p, js, jslen, tok, tokcount);
+ if (r < 0) {
+ if (r == JSMN_ERROR_NOMEM) {
+ tokcount = tokcount * 2;
+ tok = realloc(tok, sizeof(*tok) * tokcount);
+ if (tok == NULL) {
+ fprintf(stderr, "realloc(): errno=%d\n", errno);
+ return 3;
+ }
+ goto again;
+ }
+ } else {
+ dump(js, tok, p.toknext, 0, map);
+ //fprintf(stdout, "[[[[%d]]]]\n", sizeof(tok));
+ //printf("[\n%d\n]", jslen);
+ eof_expected = 1;
+ }
+ }
+
+ return 0;
+}
+
+/*int main()
+{
+ map_t map;
+ loadmap("../../../../data/test.map", &map);
+ return 0;
+}*/
--- /dev/null
+#ifndef _LIBMAPREAD_H_
+#define _LIBMAPREAD_H_
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "src/lib/jsmn/jsmn.c"
+#include "src/lib/modex16.h"
+
+char *js_sv;
+
+typedef struct {\r
+ bitmap_t *data;
+ word tileHeight;\r
+ word tileWidth;\r
+ unsigned int rows;\r
+ unsigned int cols;\r
+} tiles_t;\r
+\r
+typedef struct {\r
+ byte *data;\r
+ tiles_t *tiles;\r
+ int width;\r
+ int height;\r
+} map_t;
+
+static int jsoneq(const char *json, jsmntok_t *tok, const char *s);
+static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *js_sv,*/ map_t *map);
+int loadmap(char *mn, map_t *map);
+
+#endif/*_LIBMAPREAD_H_*/
-#include "src\lib\modex16.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>
-#include <string.h>\r
-#include "src\lib\dos_kb.h"\r
-#include "16\lib\x\modex.h"\r
+#include "src\lib\dos_kb.h"
+#include "src\lib\mapread.c"\r
+//#include "16\lib\x\modex.h"\r
#include "src\lib\wtest\wtest.c"\r
-#include "src\lib\planar.c"\r
+#include "src\lib\planar.c"
//====#include "src\lib\ems.c"\r
\r
//word far *clock= (word far*) 0x046C; /* 18.2hz clock */\r
\r
-typedef struct {\r
+/*typedef struct {\r
bitmap_t *data;\r
word tileHeight;\r
word tileWidth;\r
tiles_t *tiles;\r
int width;\r
int height;\r
-} map_t;\r
+} map_t;*/\r
\r
\r
typedef struct {\r
//#define LOOPMAX (TILEWH/SPEED)\r
\r
//place holder definitions\r
-#define MAPX 200\r
-#define MAPY 150\r
+//#define MAPX 200\r
+//#define MAPY 150\r
#define TRIGGX 10\r
#define TRIGGY 9\r
\r
exit(0);\r
}*/\r
\r
- /* create the map */\r
- map = allocMap(MAPX,MAPY); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly\r
+ /* create the map */
+ loadmap("data/test.map", &map);\r
+ map = allocMap(map.width,map.height); //20x15 is the resolution of the screen you can make maps smaller than 20x15 but the null space needs to be drawn properly\r
//if(isEMS()) printf("%d tesuto\n", coretotalEMS());\r
initMap(&map);\r
mv.map = ↦\r
//right movement\r
if(npc0.d == 2)\r
{\r
- if(npc0.tx < MAPX && !(npc0.tx+1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty))\r
+ if(npc0.tx < map.width && !(npc0.tx+1 == TRIGGX && npc0.ty == TRIGGY) && !(npc0.tx+1 == player.tx && npc0.ty == player.ty))\r
{\r
if(npc0.q<=(TILEWH/SPEED))\r
{\r
//down movement\r
if(npc0.d == 3)\r
{\r
- if(npc0.ty < MAPY && !(npc0.tx == TRIGGX && npc0.ty+1 == TRIGGY) && !(npc0.tx == player.tx && npc0.ty == player.ty+1))\r
+ if(npc0.ty < map.height && !(npc0.tx == TRIGGX && npc0.ty+1 == TRIGGY) && !(npc0.tx == player.tx && npc0.ty == player.ty+1))\r
{\r
if(npc0.q<=(TILEWH/SPEED))\r
{\r
if((keyp(77) && !keyp(75) && player.d == 0) || player.d == 2)\r
{\r
if(player.d == 0){ player.d = 2; }\r
- if(bg->tx >= 0 && bg->tx+20 < MAPX && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))\r
+ if(bg->tx >= 0 && bg->tx+20 < map.width && player.tx == bg->tx + 10 && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r
player.q++;\r
} else { player.q = 1; player.d = 0; player.tx++; }\r
}\r
- else if(player.tx < MAPX && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))\r
+ else if(player.tx < map.width && !(player.tx+1 == TRIGGX && player.ty == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r
if((keyp(75) && !keyp(77) && player.d == 0) || player.d == 4)\r
{\r
if(player.d == 0){ player.d = 4; }\r
- if(bg->tx > 0 && bg->tx+20 <= MAPX && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))\r
+ if(bg->tx > 0 && bg->tx+20 <= map.width && player.tx == bg->tx + 10 && !(player.tx-1 == TRIGGX && player.ty == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r
if((keyp(80) && !keyp(72) && player.d == 0) || player.d == 3)\r
{\r
if(player.d == 0){ player.d = 3; }\r
- if(bg->ty >= 0 && bg->ty+15 < MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))\r
+ if(bg->ty >= 0 && bg->ty+15 < map.height && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r
player.q++;\r
} else { player.q = 1; player.d = 0; player.ty++; }\r
}\r
- else if(player.ty < MAPY && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))\r
+ else if(player.ty < map.height && !(player.tx == TRIGGX && player.ty+1 == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r
if((keyp(72) && !keyp(80) && player.d == 0) || player.d == 1)\r
{\r
if(player.d == 0){ player.d = 1; }\r
- if(bg->ty > 0 && bg->ty+15 <= MAPY && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))\r
+ if(bg->ty > 0 && bg->ty+15 <= map.height && player.ty == bg->ty + 8 && !(player.tx == TRIGGX && player.ty-1 == TRIGGY))\r
{\r
if(player.q<=(TILEWH/SPEED))\r
{\r