Skip to content

Commit

Permalink
[common][msx2] switch between tilesets feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pvmm authored and felipesanches committed Aug 8, 2022
1 parent a6e4ea8 commit c02a40c
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 53 deletions.
2 changes: 1 addition & 1 deletion common/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void set_minefield_cell(minefield* mf, uint8_t x, uint8_t y, uint8_t input);
* ----------------------
*
* If coding a tile-based platform that uses **tiles.h** header, you can use
* the definition in **tiles_8x8.c** or **tiles_16x16.c** instead of writing
* the definition in **8x8_tiles.h** or **16x16_tiles.h** instead of writing
* your own.
*
* Note: some tile-based platforms use the `GROUND` tile to cover the whole
Expand Down
40 changes: 40 additions & 0 deletions platforms/msx2/16x16_cursors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "msx2.h"

/* cursor sprite */
#define CURSOR_PATTERN_ID 0
#define CURSOR_SPRITE_ID 0
#define CURSOR_X_OFFSET 0
#define CURSOR_Y_OFFSET 0

const uint8_t cursor_pattern[32] = {
0x00,0x70,0x40,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x40,0x70,0x00,
0x00,0x0E,0x02,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x02,0x0E,0x00
};


/* all black */
const uint8_t cursor_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};


/* mouse sprite */
#define MOUSE_PATTERN_ID 4
#define MOUSE_SPRITE_ID 1

const uint8_t mouse_pattern[32] = {
0x01,0x01,0x01,0x01,0x01,0x03,0x04,0xFD,
0x04,0x03,0x01,0x01,0x01,0x01,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x7E,
0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00
};


/* all black */
const uint8_t mouse_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#include <stdint.h>
#include "tiles.h"
#include "codes.h"


#define TILE_POS_X(x, y) ((x) * 8)
static const uint8_t TILE_X[MAX_VIDEO_TILES] = {
[ONE_BOMB] = TILE_POS_X(4, 0),
Expand Down
41 changes: 41 additions & 0 deletions platforms/msx2/8x8_cursors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "msx2.h"


/* cursor sprite */
#define CURSOR_PATTERN_ID 0
#define CURSOR_SPRITE_ID 0
#define CURSOR_X_OFFSET -3
#define CURSOR_Y_OFFSET -3

const uint8_t cursor_pattern[32] = {
0x07,0x18,0x23,0x5F,0x50,0x90,0xB0,0xB0,
0x90,0x50,0x5F,0x23,0x18,0x07,0x00,0x00,
0x80,0x60,0x10,0xE8,0x28,0x24,0x34,0x34,
0x24,0x28,0xE8,0x10,0x60,0x80,0x00,0x00,
};


/* all black */
const uint8_t cursor_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};


/* mouse sprite */
#define MOUSE_PATTERN_ID 4
#define MOUSE_SPRITE_ID 1

const uint8_t mouse_pattern[32] = {
0x01,0x01,0x01,0x01,0x01,0x03,0x04,0xFD,
0x04,0x03,0x01,0x01,0x01,0x01,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x7E,
0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00
};


/* all black */
const uint8_t mouse_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};
161 changes: 161 additions & 0 deletions platforms/msx2/8x8_tilemap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#define TILE_POS_X(x, y) ((x) * 8)
static const uint8_t TILE_X[MAX_VIDEO_TILES] = {
[ONE_BOMB] = TILE_POS_X(2, 0),
[TWO_BOMBS] = TILE_POS_X(4, 0),
[THREE_BOMBS] = TILE_POS_X(6, 0),
[FOUR_BOMBS] = TILE_POS_X(8, 0),
[FIVE_BOMBS] = TILE_POS_X(10, 0),
[SIX_BOMBS] = TILE_POS_X(12, 0),
[SEVEN_BOMBS] = TILE_POS_X(14, 0),
[EIGHT_BOMBS] = TILE_POS_X(16, 0),
[BLANK] = TILE_POS_X(18, 0),
[FLAG] = TILE_POS_X(20, 0),
[QUESTION_MARK] = TILE_POS_X(22, 0),
[EMPTY_FLAG] = TILE_POS_X(24, 0),
[BOMB] = TILE_POS_X(26, 0),
[EXPLOSION] = TILE_POS_X(28, 0),
[GROUND] = TILE_POS_X(30, 0),

[BOMB_ICON] = TILE_POS_X(0, 1),
[HOURGLASS] = TILE_POS_X(1, 1),

[MINEFIELD_CORNER_TOP_LEFT] = TILE_POS_X(0, 2),
[MINEFIELD_TOP_TEE] = TILE_POS_X(1, 2),
[MINEFIELD_HORIZONTAL_TOP] = TILE_POS_X(2, 2),
[MINEFIELD_HORIZONTAL_MIDDLE] = TILE_POS_X(2, 3),
[MINEFIELD_HORIZONTAL_BOTTOM] = TILE_POS_X(2, 5),
[MINEFIELD_CORNER_TOP_RIGHT] = TILE_POS_X(4, 2),

[MINEFIELD_LEFT_TEE] = TILE_POS_X(0, 3),
[MINEFIELD_CROSS] = TILE_POS_X(1, 3),
[MINEFIELD_RIGHT_TEE] = TILE_POS_X(4, 3),

[MINEFIELD_VERTICAL_LEFT] = TILE_POS_X(0, 4),
[MINEFIELD_VERTICAL_MIDDLE] = TILE_POS_X(2, 3),
[MINEFIELD_VERTICAL_RIGHT] = TILE_POS_X(4, 4),
[CLOSED_CELL] = TILE_POS_X(2, 4),

[MINEFIELD_CORNER_BOTTOM_LEFT] = TILE_POS_X(0, 5),
[MINEFIELD_BOTTOM_TEE] = TILE_POS_X(1, 5),
[MINEFIELD_CORNER_BOTTOM_RIGHT] = TILE_POS_X(4, 5),

[FRAME_TOP_LEFT] = TILE_POS_X(30, 0),
[FRAME_TOP_CENTER] = TILE_POS_X(30, 0),
[FRAME_TOP_RIGHT] = TILE_POS_X(30, 0),
[FRAME_VERTICAL_LEFT] = TILE_POS_X(30, 0),
[FRAME_VERTICAL_RIGHT] = TILE_POS_X(30, 0),
[FRAME_BOTTOM_LEFT] = TILE_POS_X(30, 0),
[FRAME_BOTTOM_CENTER] = TILE_POS_X(30, 0),
[FRAME_BOTTOM_RIGHT] = TILE_POS_X(30, 0),

[CORNER_TOP_LEFT] = TILE_POS_X(7, 2),
[CORNER_TOP_RIGHT] = TILE_POS_X(10, 2),
[CORNER_BOTTOM_LEFT] = TILE_POS_X(7, 5),
[CORNER_BOTTOM_RIGHT] = TILE_POS_X(10, 5),

[TOP_BORDER__LEFT] = TILE_POS_X(8, 2),
[TOP_BORDER__RIGHT] = TILE_POS_X(9, 2),
[BOTTOM_BORDER__LEFT] = TILE_POS_X(8, 5),
[BOTTOM_BORDER__RIGHT] = TILE_POS_X(9, 5),

[LEFT_BORDER__TOP] = TILE_POS_X(7, 3),
[LEFT_BORDER__BOTTOM] = TILE_POS_X(7, 4),
[RIGHT_BORDER__TOP] = TILE_POS_X(10, 3),
[RIGHT_BORDER__BOTTOM] = TILE_POS_X(10, 4),

[COLON] = TILE_POS_X(0, 6),
[NO_SIGN] = TILE_POS_X(12, 6),
[MINUS_SIGN] = TILE_POS_X(1, 6),
[ZERO_DIGIT] = TILE_POS_X(2, 6),
[ONE_DIGIT] = TILE_POS_X(3, 6),
[TWO_DIGIT] = TILE_POS_X(4, 6),
[THREE_DIGIT] = TILE_POS_X(5, 6),
[FOUR_DIGIT] = TILE_POS_X(6, 6),
[FIVE_DIGIT] = TILE_POS_X(7, 6),
[SIX_DIGIT] = TILE_POS_X(8, 6),
[SEVEN_DIGIT] = TILE_POS_X(9, 6),
[EIGHT_DIGIT] = TILE_POS_X(10, 6),
[NINE_DIGIT] = TILE_POS_X(11, 6),
};


#define PAGE2_OFFSET 256
#define TILE_POS_Y(x, y) ((y) * 8 + PAGE2_OFFSET)
static const uint16_t TILE_Y[MAX_VIDEO_TILES] = {
[ONE_BOMB] = TILE_POS_Y(2, 0),
[TWO_BOMBS] = TILE_POS_Y(4, 0),
[THREE_BOMBS] = TILE_POS_Y(6, 0),
[FOUR_BOMBS] = TILE_POS_Y(8, 0),
[FIVE_BOMBS] = TILE_POS_Y(10, 0),
[SIX_BOMBS] = TILE_POS_Y(12, 0),
[SEVEN_BOMBS] = TILE_POS_Y(14, 0),
[EIGHT_BOMBS] = TILE_POS_Y(16, 0),
[BLANK] = TILE_POS_Y(18, 0),
[FLAG] = TILE_POS_Y(20, 0),
[QUESTION_MARK] = TILE_POS_Y(22, 0),
[EMPTY_FLAG] = TILE_POS_Y(24, 0),
[BOMB] = TILE_POS_Y(26, 0),
[EXPLOSION] = TILE_POS_Y(28, 0),
[GROUND] = TILE_POS_Y(30, 0),

[BOMB_ICON] = TILE_POS_Y(0, 1),
[HOURGLASS] = TILE_POS_Y(1, 1),

[MINEFIELD_CORNER_TOP_LEFT] = TILE_POS_Y(0, 2),
[MINEFIELD_TOP_TEE] = TILE_POS_Y(1, 2),
[MINEFIELD_HORIZONTAL_TOP] = TILE_POS_Y(2, 2),
[MINEFIELD_HORIZONTAL_MIDDLE] = TILE_POS_Y(2, 3),
[MINEFIELD_HORIZONTAL_BOTTOM] = TILE_POS_Y(2, 5),
[MINEFIELD_CORNER_TOP_RIGHT] = TILE_POS_Y(4, 2),

[MINEFIELD_LEFT_TEE] = TILE_POS_Y(0, 3),
[MINEFIELD_CROSS] = TILE_POS_Y(1, 3),
[MINEFIELD_RIGHT_TEE] = TILE_POS_Y(4, 3),

[MINEFIELD_VERTICAL_LEFT] = TILE_POS_Y(0, 4),
[MINEFIELD_VERTICAL_MIDDLE] = TILE_POS_Y(2, 3),
[MINEFIELD_VERTICAL_RIGHT] = TILE_POS_Y(4, 4),
[CLOSED_CELL] = TILE_POS_Y(2, 4),

[MINEFIELD_CORNER_BOTTOM_LEFT] = TILE_POS_Y(0, 5),
[MINEFIELD_BOTTOM_TEE] = TILE_POS_Y(1, 5),
[MINEFIELD_CORNER_BOTTOM_RIGHT] = TILE_POS_Y(4, 5),

[CORNER_TOP_LEFT] = TILE_POS_Y(7, 2),
[CORNER_TOP_RIGHT] = TILE_POS_Y(10, 2),
[CORNER_BOTTOM_LEFT] = TILE_POS_Y(7, 5),
[CORNER_BOTTOM_RIGHT] = TILE_POS_Y(10, 5),

[FRAME_TOP_LEFT] = TILE_POS_Y(30, 0),
[FRAME_TOP_CENTER] = TILE_POS_Y(30, 0),
[FRAME_TOP_RIGHT] = TILE_POS_Y(30, 0),
[FRAME_VERTICAL_LEFT] = TILE_POS_Y(30, 0),
[FRAME_VERTICAL_RIGHT] = TILE_POS_Y(30, 0),
[FRAME_BOTTOM_LEFT] = TILE_POS_Y(30, 0),
[FRAME_BOTTOM_CENTER] = TILE_POS_Y(30, 0),
[FRAME_BOTTOM_RIGHT] = TILE_POS_Y(30, 0),

[TOP_BORDER__LEFT] = TILE_POS_Y(8, 2),
[TOP_BORDER__RIGHT] = TILE_POS_Y(9, 2),
[BOTTOM_BORDER__LEFT] = TILE_POS_Y(8, 5),
[BOTTOM_BORDER__RIGHT] = TILE_POS_Y(9, 5),

[LEFT_BORDER__TOP] = TILE_POS_Y(7, 3),
[LEFT_BORDER__BOTTOM] = TILE_POS_Y(7, 4),
[RIGHT_BORDER__TOP] = TILE_POS_Y(10, 3),
[RIGHT_BORDER__BOTTOM] = TILE_POS_Y(10, 4),

[COLON] = TILE_POS_Y(0, 6),
[NO_SIGN] = TILE_POS_Y(12, 6),
[MINUS_SIGN] = TILE_POS_Y(1, 6),
[ZERO_DIGIT] = TILE_POS_Y(2, 6),
[ONE_DIGIT] = TILE_POS_Y(3, 6),
[TWO_DIGIT] = TILE_POS_Y(4, 6),
[THREE_DIGIT] = TILE_POS_Y(5, 6),
[FOUR_DIGIT] = TILE_POS_Y(6, 6),
[FIVE_DIGIT] = TILE_POS_Y(7, 6),
[SIX_DIGIT] = TILE_POS_Y(8, 6),
[SEVEN_DIGIT] = TILE_POS_Y(9, 6),
[EIGHT_DIGIT] = TILE_POS_Y(10, 6),
[NINE_DIGIT] = TILE_POS_Y(11, 6),
};
16 changes: 12 additions & 4 deletions platforms/msx2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ else
Z80_CFLAGS := $(Z80_CFLAGS)
endif

SCREEN_LAYOUT := -DSCREEN_WIDTH=32 -DSCREEN_HEIGHT=26 -DMINEFIELD_X_OFFSET=1 -DMINEFIELD_Y_OFFSET=2 \
-DHOURGLASS_X_POS=24 -DHOURGLASS_Y_POS=14 -DBOMB_ICON_X_POS=24 -DBOMB_ICON_Y_POS=11 -DENABLE_TIMER \
-DENABLE_COUNTER
# 16x16 tiles by default
ifndef _8X8_TILES
SCREEN_LAYOUT := $(SCREEN_LAYOUT) -D_16X16_TILES
TILE_FILE := classic.xpm
else
SCREEN_LAYOUT := $(SCREEN_LAYOUT) -D_8X8_TILES
TILE_FILE := mines8x8.xpm
endif

MAKE := make
Z80_CC := sdcc
Z80_AS := sdasz80
HEXTOOL := hex2bin
#HEXTOOL := ./tools/MSXhex
SC5TOOL := ./tools/SCREEN5
BINTOOL := ./tools/MSXbin
TILE_FILE := classic.xpm

BUILDDIR := build
TARGET := $(BUILDDIR)/mines
Expand All @@ -33,9 +44,6 @@ Z80_LIBS :=

.PHONY: all clean tools openmsx run
all: $(TARGET).rom
SCREEN_LAYOUT := -D_16X16_TILES -DSCREEN_WIDTH=32 -DSCREEN_HEIGHT=26 -DMINEFIELD_X_OFFSET=1 -DMINEFIELD_Y_OFFSET=2 \
-DHOURGLASS_X_POS=24 -DHOURGLASS_Y_POS=14 -DBOMB_ICON_X_POS=24 -DBOMB_ICON_Y_POS=11 -DENABLE_TIMER \
-DENABLE_COUNTER
$(TARGET).rom: $(OBJECTS) $(COMMON) $(BUILDDIR)/crt0.rel
$(Z80_CC) $(Z80_CFLAGS) $(Z80_LDFLAGS) $(Z80_LIBS) --code-loc $(CODE) --data-loc $(DATA) $(BUILDDIR)/crt0.rel $(OBJECTS) $(COMMON) -o $(TARGET).ihx
#$(HEXTOOL) $(TARGET).ihx -o $(TARGET).rom -e ROM -p 0xFF -s 0x4000 -l $(ROM_MAX)
Expand Down
8 changes: 8 additions & 0 deletions platforms/msx2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@
* openMSX emulator with C-BIOS ROM

**Note:** The hex2bin tool can be compiled from sources available at https://gitlab.com/reidrac/ubox-msx-lib/-/blob/main/tools/hex2bin-2.0 or you can also use binaries downloaded from https://sourceforge.net/projects/hex2bin/files/

### Tileset selection

The default tileset is the classic windows theme (16x16), but you can select the grassland tileset (8x8) by typing the following command:
```
$ _8X8_TILES=1 make clean all
```
![Screenshot](screenshot2.jpg)
46 changes: 5 additions & 41 deletions platforms/msx2/cursors.h
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
#include "msx2.h"

/* cursor sprite */
#define CURSOR_PATTERN_ID 0
#define CURSOR_SPRITE_ID 0
#define CURSOR_X_OFFSET 0
#define CURSOR_Y_OFFSET 0

const uint8_t cursor_pattern[32] = {
0x00,0x70,0x40,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x40,0x70,0x00,
0x00,0x0E,0x02,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x02,0x0E,0x00
};


/* all black */
const uint8_t cursor_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};


/* mouse sprite */
#define MOUSE_PATTERN_ID 4
#define MOUSE_SPRITE_ID 1

const uint8_t mouse_pattern[32] = {
0x01,0x01,0x01,0x01,0x01,0x03,0x04,0xFD,
0x04,0x03,0x01,0x01,0x01,0x01,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x7E,
0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00
};


/* all black */
const uint8_t mouse_colors[16] = {
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
};

#ifdef _16X16_TILES
# include "16x16_cursors.h"
#else
# include "8x8_cursors.h"
#endif
Loading

0 comments on commit c02a40c

Please sign in to comment.