Skip to content

Commit 0b24773

Browse files
committed
Merge remote-tracking branch 'cschool/master'
2 parents 518cb7c + 0422e02 commit 0b24773

10 files changed

+41
-30
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build-uno
22
bin
33
*.swp
44
*.exe
5-
libgame/emulator/emulator
5+
*.o
6+
game/emulator/emulator

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# BackspaceInvaders
2-
Game for Arduino and LED display 64x64
1+
# libgame
2+
Game library for Arduino and LED display 64x64
33

44
This project uses Adafruit-like display:
55
https://learn.adafruit.com/32x16-32x32-rgb-led-matrix
@@ -38,3 +38,6 @@ Therefore this is logically 128x32 display.
3838
Arduino shifts 128 pixels into display registers at every iteration.
3939

4040
Demonstration of the working prototype: https://www.youtube.com/watch?v=gy7oADJboqM
41+
42+
## Tutorial
43+
See game/Template.cpp

game/Dump.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma GCC optimize ("-O3")
22

3+
#ifndef EMULATED
34
#include "libgame.h"
45
#include "font.h"
56
#include <avr/eeprom.h>
@@ -79,3 +80,4 @@ game_instance Dump = {
7980
sizeof(DumpData),
8081
(void**)(&data)
8182
};
83+
#endif

game/avrfix.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
* Version 1.0.1 *
1818
* Maximilan Rosenblattl, Andreas Wolf 2007-02-07 *
1919
****************************************************************/
20-
#ifndef TEST_ON_PC
20+
#ifndef EMULATED
2121

2222
#include <avr/io.h>
2323
#include <avr/interrupt.h>
2424
/*#include <avr/signal.h>*/
2525
#include <avr/pgmspace.h>
26+
#else
27+
#include <stdint.h>
28+
#endif
2629

2730
#include "avrfix.h"
2831
#include "avrfix_config.h"
29-
30-
#endif
3132
#if BYTE_ORDER == BIG_ENDIAN
3233
typedef struct {
3334
unsigned short ll;

game/avrfix.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
#define _AVRFIX_H
2323

2424

25-
#ifndef TEST_ON_PC
25+
#ifndef EMULATED
2626
#include <avr/io.h>
2727
#include <avr/interrupt.h>
2828
/*#include <avr/signal.h>*/
2929
#include <avr/pgmspace.h>
3030
// #include "avrfix_config.h"
31+
#else
32+
#include <stdint.h>
3133
#endif
3234

3335
/* Only two datatypes are used from the ISO/IEC standard:

game/emulator/Makefile

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
CPP_FILES := $(wildcard ../*.cpp)
22
OBJ_FILES := $(notdir $(CPP_FILES:.cpp=.o))
3-
CXXFLAGS := -DEMULATED -Wno-narrowing
3+
CXXFLAGS := -I.. -DEMULATED -Wall -fexec-charset=windows-1251 -std=c++11
4+
LIBS := -lsfml-graphics -lsfml-window -lsfml-system
45

5-
emulator: main.cpp ../*.cpp ../*.h
6-
$(CXX) -I.. -DEMULATED -Wall -fexec-charset=windows-1251 main.cpp ../*.cpp -lsfml-graphics -lsfml-window -lsfml-system -o emulator -std=c++11
6+
emulator: main.cpp ${OBJ_FILES}
7+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
8+
9+
%.o: ../%.cpp
10+
$(CXX) $(CXXFLAGS) $^ -c -o $@
711

812
clean:
9-
rm -f emulator*
13+
rm -f emulator* ${OBJ_FILES}
1014

1115
run: emulator
1216
./emulator

game/emulator/Makefile-win32

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
CPP_FILES := $(wildcard ../*.cpp)
22
OBJ_FILES := $(notdir $(CPP_FILES:.cpp=.o))
3-
CXXFLAGS := -DEMULATED -Wno-narrowing
3+
CXXFLAGS := -I.. -DEMULATED -Wall -fexec-charset=windows-1251 -mwindows -std=c++11
4+
LIBS := -lsfml-graphics -lsfml-window -lsfml-system
45

5-
emulator: main.cpp ../*.cpp
6-
$(CXX) -I.. -DEMULATED -Wall -fexec-charset=windows-1251 main.cpp ../*.cpp -lsfml-graphics -lsfml-window -lsfml-system -mwindows -o emulator -std=c++11
6+
emulator: main.cpp ${OBJ_FILES}
7+
$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@
8+
9+
%.o: ../%.cpp
10+
$(CXX) $(CXXFLAGS) $^ -c -o $@
711

812
clean:
9-
rm -f emulator*
13+
rm -f emulator* ${OBJ_FILES}
1014

1115
run: emulator
1216
./emulator

game/emulator/main.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,8 @@ unsigned long millis()
5151
void storage_init() {}
5252
void storage_format() {}
5353

54-
uint8_t storage_open(const char *name, uint8_t mode) { return 0; }
55-
56-
void storage_write_byte(uint8_t sd, uint8_t value) {}
57-
void storage_write_word(uint8_t sd, uint16_t value) {}
58-
void storage_write_dword(uint8_t sd, uint32_t value) {}
59-
size_t storage_write(uint8_t sd, void* buffer, size_t size) { return 0; }
60-
61-
uint8_t storage_read_byte(uint8_t sd) { return 0; }
62-
uint16_t storage_read_word(uint8_t sd) { return 0; }
63-
uint32_t storage_read_dword(uint8_t sd) { return 0; }
64-
size_t storage_read(uint8_t sd, void* buffer, size_t size) { return 0; }
65-
66-
void storage_delete(uint8_t sd) {}
67-
void storage_close(uint8_t sd) {}
54+
void storage_read(const char *name, void *buffer, size_t size){};
55+
bool storage_write(const char *name, const void *buffer, size_t size){return 0;};
6856

6957
uint8_t game_sprite_width(const struct game_sprite *s)
7058
{

game/games.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ extern game_instance BackspaceInvaders;
66
extern game_instance Snake;
77
extern game_instance Tester;
88
extern game_instance Raycaster;
9+
#ifndef EMULATED /* for use only on real hardware */
910
extern game_instance Dump;
10-
11+
#endif
1112
/* Register your game like so:
1213
*
1314
* extern game_instance YOUR_GAME_NAME;
@@ -20,7 +21,9 @@ game_instance instances[] = {
2021
Snake,
2122
Raycaster,
2223
Tester,
24+
#ifndef EMULATED /* for use only on real hardware */
2325
Dump,
26+
#endif
2427

2528
/* Register your game like so:
2629
*

game/libgame.h

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ using namespace std;
1818
#define pgm_read_byte(addr) (*(addr))
1919
#define pgm_read_word(addr) (*(addr))
2020
#define pgm_read_dword(addr) (*(addr))
21+
#define pgm_read_byte_near(addr) (*((uint8_t*)(addr)))
22+
#define pgm_read_word_near(addr) (*((uint16_t*)(addr)))
23+
#define pgm_read_dword_near(addr) (*((uint32_t*)(addr)))
2124
#define pgm_read_pointer(addr) (*(addr))
2225
#else
2326
#if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF)

0 commit comments

Comments
 (0)