Ver código fonte

Use proper headers

Streetwalrus Einstein 10 anos atrás
pai
commit
5f8d03e612
11 arquivos alterados com 89 adições e 25 exclusões
  1. 1 1
      .gitignore
  2. 1 6
      Makefile
  3. 1 0
      art/Makefile
  4. BIN
      art/character_walking.png
  5. 1 8
      src/graphics.c
  6. 42 0
      src/graphics.h
  7. 7 1
      src/main.c
  8. 5 0
      src/main.h
  9. 5 9
      src/map.c
  10. 16 0
      src/map.h
  11. 10 0
      src/timers.h

+ 1 - 1
.gitignore

@@ -1,8 +1,8 @@
 *.o
 *.tns
 bin
-*.h
 *.elf
 *.gdb
 art/sprites.c
+art/sprites.h
 

+ 1 - 6
Makefile

@@ -20,7 +20,6 @@ ZEHN = genzehn
 ZEHNFLAGS = --name "$(NAME)"
 
 SOURCES = $(wildcard src/*.c) art/sprites.c
-HEADERS = $(patsubst %.c,%.h,$(SOURCES))
 OBJS = $(patsubst %.c,%.o,$(SOURCES))
 
 DISTDIR = bin
@@ -29,13 +28,10 @@ EXE = $(DISTDIR)/$(NAME).tns
 
 all: $(EXE)
 
-%.o: %.c headers
+%.o: %.c
 	@echo "CC: $@"
 	@$(CC) $(CFLAGS) -c $< -o $@
 
-headers: $(SOURCES)
-	makeheaders $(SOURCES)
-
 art/sprites.c:
 	@$(MAKE) -C art/
 
@@ -52,7 +48,6 @@ $(EXE): $(ELF)
 clean:
 	rm -rf $(DISTDIR)
 	rm -f $(OBJS)
-	rm -f $(HEADERS)
 	@$(MAKE) -C art/ clean
 
 run: all

+ 1 - 0
art/Makefile

@@ -3,6 +3,7 @@ SPRITES = $(wildcard *.png)
 all:
 	@rm -f sprites.c
 	for FILE in $(SPRITES); do ConvertImg --format n2dlib $$FILE | sed "s/^static uint16_t/unsigned short/" >> sprites.c; done
+	makeheaders sprites.c
 
 clean:
 	rm -f sprites.c sprites.h

BIN
art/character_walking.png


+ 1 - 8
src/graphics.c

@@ -1,13 +1,6 @@
 #include <os.h>
 #include "graphics.h"
 
-#if INTERFACE
-typedef struct
-{
-	int x, y, w, h;
-} Rect;
-#endif
-
 #define LCD_CONTROLLER 0xC0000000
 volatile unsigned *lcd_base = (unsigned *) (LCD_CONTROLLER + 0x10);
 volatile unsigned *lcd_ris = (unsigned *) (LCD_CONTROLLER + 0x20);
@@ -101,7 +94,7 @@ void draw_pixel(unsigned x, unsigned y, unsigned short color)
 		buffer_back[x + (y * 320)] = color;
 }
 
-void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect* window)
+void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect *window)
 {
 	unsigned short color;
 	int w = window->w + x;

+ 42 - 0
src/graphics.h

@@ -0,0 +1,42 @@
+#ifndef SRC_GRAPHICS_H
+#define SRC_GRAPHICS_H
+
+typedef struct
+{
+	int x, y, w, h;
+} Rect;
+
+/*
+ * Buffer management
+ */
+
+void buffer_allocate();
+void buffer_free();
+void buffer_swap();
+void buffer_copy();
+void buffer_fill(unsigned color);
+
+
+/*
+ * Misc LCD functions
+ */
+
+void lcd_vsync();
+
+
+/*
+ * Drawing
+ */
+
+void draw_pixel(unsigned x, unsigned y, unsigned short color);
+void draw_sprite_sheet(const unsigned short *sheet, int x, int y, const Rect *window);
+
+
+/*
+ * Sprite manipulation
+ */
+
+unsigned short sprite_pixel_get(const unsigned short *sprite, unsigned x, unsigned y);
+
+#endif
+

+ 7 - 1
src/main.c

@@ -1,8 +1,14 @@
 #include <os.h>
+#include "timers.h"
+#include "graphics.h"
+#include "map.h"
 #include "main.h"
 
-int main()
+int main(int argc, char *argv[])
 {
+	(void) argc;
+	(void) argv;
+
 	buffer_allocate();
 	timer_init(0);
 

+ 5 - 0
src/main.h

@@ -0,0 +1,5 @@
+#ifndef SRC_MAIN_H
+#define SRC_MAIN_H
+
+#endif
+

+ 5 - 9
src/map.c

@@ -1,15 +1,11 @@
 #include <os.h>
+#include "timers.h"
+#include "graphics.h"
+#include "../art/sprites.h"
 #include "map.h"
 
-#if INTERFACE
-typedef struct
-{
-	unsigned w;
-	unsigned h;
-	unsigned *layer0;
-	unsigned *layer1;
-} Map;
-#endif
+static void map_walk_speed_load(unsigned time);
+static unsigned map_walk_speed_read(unsigned time, unsigned div);
 
 void map_draw(unsigned x, unsigned y, const Map map)
 {

+ 16 - 0
src/map.h

@@ -0,0 +1,16 @@
+#ifndef SRC_MAP_H
+#define SRC_MAP_H
+
+typedef struct
+{
+	unsigned w;
+	unsigned h;
+	unsigned *layer0;
+	unsigned *layer1;
+} Map;
+
+void map_draw(unsigned x, unsigned y, const Map map);
+unsigned map_collide(unsigned x, unsigned y, const Map map);
+void map_walk(unsigned x, unsigned y, Map map);
+
+#endif

+ 10 - 0
src/timers.h

@@ -0,0 +1,10 @@
+#ifndef SRC_TIMERS_H
+#define SRC_TIMERS_H
+
+void timer_init(unsigned timer);
+void timer_restore(unsigned timer);
+void timer_load(unsigned timer, unsigned value);
+unsigned timer_read(unsigned timer);
+
+#endif
+