initial commit
[enJine.git] / mmshow / src / main.c
bloba6ce83a03e7c5c867f840b828e3ca362c5a51d64
1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details. */
9 #include <ctype.h>
10 #include <fcntl.h>
11 #include <stdint.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <time.h>
15 #include <unistd.h>
16 #include <sys/stat.h>
17 #include <sys/types.h>
19 #include <SDL/SDL.h>
21 #include "libvideo/video.h"
24 #define XTILES 14
25 #define YTILES 8
27 static unsigned char map[32*64];
28 static unsigned char tiles[6*16*4];
31 static const unsigned char ttypes[16] = {
32 0x33, // 0x00
33 0x01, // 0x01
34 0x11, // 0x02
35 0x12, // 0x03
36 0x30, // 0x04
37 0x23, // 0x05
38 0x02, // 0x06
39 0x03, // 0x07
40 0x32, // 0x08
41 0x22, // 0x09
42 0x00, // 0x0A
43 0x21, // 0x0B
44 0x10, // 0x0C
45 0x13, // 0x0D
46 0x31, // 0x0E
47 0x20, // 0x0F
51 static void putTile (int trow, int tnum, int px, int py) {
52 int x, y, d, a;
54 a = trow*(6*16)+tnum*2;
55 for (y = 0; y < 16; ++y) {
56 for (x = 0; x < 2; ++x) {
57 unsigned char b = tnum<3 ? tiles[a+x] : 0;
58 for (d = 7; d >= 0; --d, b >>= 1) putPixel(px+x*8+d, py+y, b&0x01?7:0);
60 a += 6;
65 static void put2XTiles (unsigned char mapb, int px, int py) {
66 int trow = (mapb>>4)&0x03;
67 int tnum = ttypes[mapb&0x0f];
68 putTile(trow, (tnum>>4)&0x03, px, py);
69 putTile(trow, tnum&0x03, px+16, py);
73 static void drawMap (int mx, int my) {
74 int dx, dy;
75 char buf[16];
77 for (dy = 0; dy < YTILES; ++dy) {
78 int ox = mx;
79 for (dx = 0; dx < XTILES/2; ++dx) {
80 put2XTiles(map[my*32+mx], dx*32, dy*16);
81 sprintf(buf, "%02X", map[my*32+mx]);
82 drawOutlineText(dx*32+2, dy*16+2, buf, 15, 0);
83 mx = (mx+1)%32;
85 mx = ox; my = (my+1)%64;
90 int main (int argc, char *argv[]) {
91 static int mapX = 0;
92 static int mapY = 0;
94 static SDL_Event event;
95 static FILE *fl;
96 //static char fname[128];
97 //static char buf[1024];
98 //int ctrlDown, ta;
100 if ((fl = fopen("../gfx/tiles/blk_ded8_blobs.bin", "rb")) == NULL) { fprintf(stderr, "tiles?\n"); return 1; }
101 fread(tiles, sizeof(tiles), 1, fl);
102 fclose(fl);
104 if ((fl = fopen("../maps/map00.bin", "rb")) == NULL) { fprintf(stderr, "map?\n"); return 1; }
105 fread(map, sizeof(map), 1, fl);
106 fclose(fl);
108 videoInit();
109 if (setVMode(2, 0)) { videoDeinit(); return 1; }
110 setCaption("enJine level renderer");
111 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
114 drawOutlineText(10, 10, "test!", 15, 3);
115 drawEllipse(8, 8, 8+6*5+4, 8+8+4, 10);
116 drawCircle(45, 70, 42, 5);
117 drawIconById(ICON_ID_PENTA, 80, 90);
118 drawFilledEllipse(8+40, 8+40, 8+6*5+4+40, 8+8+4+40, 11);
119 drawFilledCircle(120, 150, 42, 5);
120 drawLine(50, 50, 100, 60, 7);
121 putPixel(49, 49, 3);
122 putPixel(101, 61, 3);
124 drawCursor(8, 8, 0);
125 drawCursor(28, 28, 1);
128 repaint:
129 drawBar(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
130 drawMap(mapX, mapY);
131 repaintScreen();
133 for (;;) {
134 while (SDL_WaitEvent(&event)) {
135 switch (event.type) {
136 case SDL_QUIT: goto quit;
137 case SDL_VIDEOEXPOSE: repaintScreen(); break;
138 case SDL_KEYDOWN:
139 //ctrlDown = event.key.keysym.mod&KMOD_CTRL;
140 switch (event.key.keysym.sym) {
141 case SDLK_ESCAPE: case SDLK_q: goto quit;
142 case SDLK_LEFT: if (mapX > 0) --mapX; goto repaint;
143 case SDLK_RIGHT: if (mapX < 31) ++mapX; goto repaint;
144 case SDLK_UP: if (mapY > 0) --mapY; goto repaint;
145 case SDLK_DOWN: if (mapY < 63) ++mapY; goto repaint;
146 default: ;
148 break;
149 default: ;
154 quit:
155 videoDeinit();
156 return 0;