Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Doom for M5Stack CardPuter #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Makefile.m5card
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Makefile for compiling Doom for ESP32 based M5Stack CardPuter

# Compiler settings
CC = xtensa-esp32-elf-gcc
CXX = xtensa-esp32-elf-g++
CFLAGS = -Iinclude -DM5STACK_MPU6886 -O3
CXXFLAGS = $(CFLAGS) -std=c++11
LDFLAGS = -Llib -lM5Stack -lM5GFX -lM5Unified -lM5Cardputer

# Source files and object files
SRCS = $(wildcard src/*.cpp) $(wildcard doomgeneric/*.c)
OBJS = $(SRCS:.cpp=.o) $(SRCS:.c=.o)

# Target binary
TARGET = doom_m5card

# Default target
all: $(TARGET)

# Compile and link
$(TARGET): $(OBJS)
$(CXX) -o $@ $^ $(LDFLAGS)

# Compile C source files
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

# Compile C++ source files
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

# Clean target
clean:
rm -f $(OBJS) $(TARGET)

# If possible, use CMake for more advanced build configurations
# Note: CMakeLists.txt must be provided in the project root for CMake to work
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ make -j4 -f Makefile.sdl

```

---

## Porting to M5Stack CardPuter

To bring the classic Doom experience to your M5Stack CardPuter, follow these setup instructions:

### Hardware Requirements

- M5Stack CardPuter
- SD card with at least 16MB of free space
- USB-C cable for programming and power supply

### Compiling and Uploading

1. Install [PlatformIO](https://platformio.org/) and the necessary ESP32 platform support.
2. Clone this repository to your local machine.
3. Place your WAD file (e.g., `doom1.wad`) in the root of the SD card and insert it into the M5Stack CardPuter.
4. Navigate to the project directory and open the `platformio.ini` file. Ensure the correct environment is selected for your M5Stack CardPuter model.
5. Compile the project by running `pio run` in the terminal.
6. Upload the game to your M5Stack CardPuter using `pio run --target upload`.
7. Once uploaded, reset the M5Stack CardPuter to start playing Doom!

Enjoy Doom on your M5Stack CardPuter and relive the classic gaming experience!

---

Expand Down
87 changes: 87 additions & 0 deletions m5card.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "doomgeneric.h"
#include <M5Cardputer.h>
#include <M5Unified.h>
#include <M5GFX.h>

#define KEYQUEUE_SIZE 16

static unsigned short s_KeyQueue[KEYQUEUE_SIZE];
static unsigned int s_KeyQueueWriteIndex = 0;
static unsigned int s_KeyQueueReadIndex = 0;

#ifdef __cplusplus
extern "C"
{
#endif

void doomgeneric_Create(int argc, char **argv);
void doomgeneric_Tick();

#ifdef __cplusplus
}
#endif

void DG_Init()
{
M5.begin();
// Initialize M5Stack Cardputer
}

void DG_DrawFrame()
{
M5.Lcd.drawBitmap(0, 0, DOOMGENERIC_RESX, DOOMGENERIC_RESY, (uint16_t *)DG_ScreenBuffer);
}

void DG_SleepMs(uint32_t ms)
{
delay(ms);
}

uint32_t DG_GetTicksMs()
{
return millis();
}

int DG_GetKey(int *pressed, unsigned char *doomKey)
{
if (s_KeyQueueReadIndex == s_KeyQueueWriteIndex)
{
// key queue is empty
return 0;
}
else
{
unsigned short keyData = s_KeyQueue[s_KeyQueueReadIndex];
s_KeyQueueReadIndex++;
s_KeyQueueReadIndex %= KEYQUEUE_SIZE;

*pressed = keyData >> 8;
*doomKey = keyData & 0xFF;

return 1;
}

return 0;
}

void setup()
{
doomgeneric_Create(0, nullptr);
}

void loop()
{
doomgeneric_Tick();
}

// int main(int argc, char **argv)
// {
// doomgeneric_Create(argc, argv);

// while (1)
// {
// doomgeneric_Tick();
// }

// return 0;
// }
25 changes: 1 addition & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,6 @@ uint32_t DG_GetTicksMs()
return millis();
}

// int DG_GetKey(int* pressed, unsigned char* key) {
// *pressed = 0;
// *key = 0;

// if(M5.BtnA.wasPressed()) {
// *pressed = 1;
// *key = KEY_ENTER;
// return 1;
// }
// else if(M5.BtnB.wasPressed()) {
// *pressed = 1;
// *key = KEY_FIRE;
// return 1;
// }
// else if(M5.BtnC.wasPressed()) {
// *pressed = 1;
// *key = KEY_USE;
// return 1;
// }

// return 0;
// }

int DG_GetKey(int *pressed, unsigned char *doomKey)
{
if (s_KeyQueueReadIndex == s_KeyQueueWriteIndex)
Expand Down Expand Up @@ -108,4 +85,4 @@ void loop()
// }

// return 0;
// }
// }
Loading