+
+int dump_tilemap(struct tilemap *tmap, const char *fname)
+{
+ FILE *fp;
+ int i, sz = tmap->width * tmap->height;
+ uint16_t id;
+
+ if(sz <= 0) return -1;
+
+ if(!(fp = fopen(fname, "wb"))) {
+ fprintf(stderr, "dump_tilemap: failed to open %s for writing\n", fname);
+ return -1;
+ }
+
+ for(i=0; i<sz; i++) {
+ /* XXX dump in 16bit big endian for the megadrive */
+ id = (tmap->map[i] << 8) | (tmap->map[i] >> 8);
+ fwrite(&id, sizeof id, 1, fp);
+ }
+
+ fclose(fp);
+ return 0;
+}