Skip to content

Commit

Permalink
[Build] Don't word-align everything by default
Browse files Browse the repository at this point in the history
Again, 11 necessary workarounds, vs. forcing byte aligment in at least
18 places, and that number would have significantly grown in the
future.

Part of P0085, funded by -Tom-.
  • Loading branch information
nmlgc committed Apr 3, 2020
1 parent ffad8cc commit 02f0a0a
Show file tree
Hide file tree
Showing 29 changed files with 27 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -192,6 +192,14 @@ binary, as compared using [mzdiff].** The only allowed exceptions are:
port developers at compile time. Self-modifying code can only do the same if
it's kept in separate ASM files.

* Don't use TCC's `-a` command-line option to force a particular code or data
alignment. Instead, directly spell out the alignment by adding padding
members to structures, and additional global variables. It's simply not
worth requiring every structure to work around it. For functions with
`switch` tables that originally were word-alignment, put a single
`#pragma option -a2` at the top of the translation unit, after all header
inclusions.

## Naming conventions

* ASM file extensions: `.asm` if they emit code, `.inc` if they don't
Expand Down
2 changes: 1 addition & 1 deletion Makefile.mak
Expand Up @@ -2,7 +2,7 @@
# -----
# Makefile for the 16-bit part of the build process

CFLAGS = -ls -Ilibs\master.lib\ -I. -Lbin\ -O -a2 -b-
CFLAGS = -ls -Ilibs\master.lib\ -I. -Lbin\ -O -b-

PIPELINE = \grzview.com
TH01 = \zunsoft.com \op.exe \reiiden.exe \fuuin.exe
Expand Down
4 changes: 0 additions & 4 deletions pc98.h
Expand Up @@ -22,8 +22,6 @@ typedef bool page_t;

#define COLOR_COUNT 16

#pragma option -a1

// The 16-color mode supports 4 bits per RGB component, for a total of
// 4,096 colors
typedef int8_t uint4_t;
Expand Down Expand Up @@ -64,8 +62,6 @@ typedef int8_t uint4_t;
typedef RGB<uint4_t, 16> RGB4;
typedef Palette<RGB4> Palette4;
#endif

#pragma option -a.
/// --------

/// Memory segments
Expand Down
2 changes: 1 addition & 1 deletion th01/formats/pf.cpp
Expand Up @@ -25,7 +25,7 @@ typedef struct {
int32_t reserved; // Always zero
} pf_header_t;

#pragma option -Z -a1
#pragma option -Z

pf_header_t *arc_pfs;
pf_header_t *file_pf;
Expand Down
2 changes: 0 additions & 2 deletions th01/formats/ptn.cpp
Expand Up @@ -11,13 +11,11 @@ extern int flag_palette_show;
// -----------------------------
#define PTN_MAGIC "HPTN"

#pragma option -a-
typedef struct {
char magic[sizeof(PTN_MAGIC) - 1];
int8_t unused_one;
int8_t image_count;
} ptn_header_t;
#pragma option -a.
// -----------------------------

ptn_error_t ptn_load_palette_show(int slot, const char *fn)
Expand Down
2 changes: 0 additions & 2 deletions th01/formats/ptn.hpp
Expand Up @@ -10,7 +10,6 @@

typedef dots_t(PTN_W) ptn_dots_t;

#pragma option -a1
struct ptn_planar_t {
ptn_dots_t B[PTN_H];
ptn_dots_t R[PTN_H];
Expand All @@ -28,7 +27,6 @@ struct ptn_file_image_t {
struct ptn_t : public ptn_file_image_t {
ptn_dots_t alpha[PTN_H]; // Derived from color #15 at load time
};
#pragma option -a.

#define PTN_SLOT_COUNT 8

Expand Down
2 changes: 0 additions & 2 deletions th01/hardware/graph.cpp
Expand Up @@ -846,7 +846,6 @@ void z_palette_fade_from(
struct hack { char x[sizeof(RESPAL_ID)]; }; // XXX
extern const hack PAL98_GRB;

#pragma option -a1
// MASTER.MAN suggests that GBR ordering is some sort of standard on PC-98.
// It does match the order of the hardware's palette register ports, after
// all. (0AAh = green, 0ACh = red, 0AEh = blue)
Expand Down Expand Up @@ -875,7 +874,6 @@ struct mcb_t {
uint8_t m_fill[3];
uint8_t m_name[8];
};
#pragma option -a.

respal_t __seg* z_respal_exist(void)
{
Expand Down
2 changes: 0 additions & 2 deletions th01/hiscore/scorelod.cpp
@@ -1,5 +1,3 @@
#pragma option -a1

extern const char SCOREDAT_ROUTE_NONE[];
extern char scoredat_name_default[];
extern const char SCOREDAT_MAGIC_0[];
Expand Down
2 changes: 0 additions & 2 deletions th01/th01.h
Expand Up @@ -29,7 +29,6 @@ typedef enum {
MODE_DEBUG = 3
} mode_t;

#pragma option -a1
typedef struct {
char id[RES_ID_LEN];
char rank;
Expand All @@ -54,4 +53,3 @@ typedef struct {
long score_highest; // among all continues
unsigned int p_value;
} resident_t;
#pragma option -a2
1 change: 1 addition & 0 deletions th01/zunsoft.c
Expand Up @@ -18,6 +18,7 @@ char logo_num;
char wave_len;
char wave_phase;
char wave_amp;
char wave_padding;
Point circle_pos[CIRCLE_COUNT];
Point star_pos[STAR_COUNT];
int frame;
Expand Down
3 changes: 0 additions & 3 deletions th02/formats/cfg.h
@@ -1,5 +1,3 @@
#pragma option -a1

#if GAME == 2
# define CFG_FN "huuma.cfg"
typedef struct {
Expand All @@ -24,4 +22,3 @@ typedef struct {
int8_t opts_sum; // Sum of all bytes in [opts]
#endif
} cfg_t;
#pragma option -a.
2 changes: 1 addition & 1 deletion th02/op_01.c
Expand Up @@ -11,7 +11,7 @@
#include "th02/formats/pi.h"
#include "th02/snd/snd.h"

#pragma option -d
#pragma option -d -a2

typedef void pascal near putfunc_t(int sel, unsigned int atrb);

Expand Down
3 changes: 3 additions & 0 deletions th02/op_04.c
Expand Up @@ -8,6 +8,7 @@
#include "th02\th02.h"

char rank = RANK_NORMAL;
int8_t rank_padding = 0;

#include "th02\score.c"

Expand All @@ -21,9 +22,11 @@ const unsigned char gbcRANKS[4][8] = {
const char *SHOTTYPES[] = {"高機動", "防御", "攻撃"};
int logo_step = 0;
char need_op_h_bft = 1;
int8_t need_op_h_bft_padding = 0;

scoredat_section_t hi;
char extra_unlocked;
int8_t extra_unlocked_padding;
unsigned int score_duration;

#include "th02\scorelod.c"
Expand Down
1 change: 1 addition & 0 deletions th02/op_05.c
Expand Up @@ -7,6 +7,7 @@
#include "th02/formats/pi.h"

char sel = 1;
int8_t sel_padding = 0;

const char *DESC[SHOTTYPE_COUNT][3] = {
" 陰陽玉の力を使わない ",
Expand Down
2 changes: 2 additions & 0 deletions th02/th02.h
Expand Up @@ -164,6 +164,7 @@ typedef struct {
char id[11]; // = RES_ID
char stage;
char debug;
int8_t padding_1;
long score;
int continues_used;
char rem_bombs;
Expand All @@ -173,6 +174,7 @@ typedef struct {
char bgm_mode;
char start_bombs;
char start_lives;
int8_t padding_2;
long frame;
int unused_1;
char unused_2;
Expand Down
2 changes: 0 additions & 2 deletions th02/zun_res1.c
Expand Up @@ -9,8 +9,6 @@
#include "th02/snd/snd.h"
#include "th02/formats/cfg.h"

#pragma option -a1

int pascal scoredat_verify(void);

char debug = 0;
Expand Down
2 changes: 1 addition & 1 deletion th02/zun_res2.c
Expand Up @@ -6,7 +6,7 @@
#include <stddef.h>
#include "th02/th02.h"

#pragma option -O- -k- -a1
#pragma option -O- -k-

extern char rank;
scoredat_section_t hi;
Expand Down
2 changes: 0 additions & 2 deletions th03/chars/chars.hpp
Expand Up @@ -12,7 +12,6 @@ typedef enum {
} playchars_t;

// Encodes a playchars_t together with its alternate palette flag.
#pragma option -a1
struct playchar_paletted_t {
unsigned char v;

Expand All @@ -24,6 +23,5 @@ struct playchar_paletted_t {
return static_cast<playchars_t>(filename_id() / 2);
}
};
#pragma option -a.

#define TO_PALETTED(playchar) ((playchar << 1) + 1)
2 changes: 0 additions & 2 deletions th03/formats/cfg.h
@@ -1,4 +1,3 @@
#pragma option -a1
#if GAME == 3
# define CFG_FN "yume.cfg"
typedef struct {
Expand All @@ -8,7 +7,6 @@
int16_t unused;
} cfg_options_t;
#endif
#pragma option -a.

#include "th02/formats/cfg.h"

Expand Down
2 changes: 0 additions & 2 deletions th03/res_yume.cpp
Expand Up @@ -13,8 +13,6 @@
#include "th03/resident.hpp"
#include "th03/formats/cfg.h"

#pragma option -a1

char debug = 0;
const cfg_options_t OPTS_DEFAULT = { SND_BGM_FM, KM_KEY_KEY, RANK_NORMAL };

Expand Down
2 changes: 0 additions & 2 deletions th03/resident.hpp
Expand Up @@ -30,7 +30,6 @@ enum game_mode_t {

#define DEMO_COUNT 4

#pragma option -a1
#define RES_ID "YUMEConfig"
typedef struct {
char id[RES_ID_LEN];
Expand All @@ -55,4 +54,3 @@ typedef struct {
unsigned char demo_num; // 0 = no demo active
int8_t unused_3[198];
} resident_t;
#pragma option -a.
2 changes: 0 additions & 2 deletions th04/formats/scoredat.h
Expand Up @@ -14,7 +14,6 @@

#define SCOREDAT_NAME_LEN 8

#pragma option -a1
typedef struct {
unsigned char g_name[SCOREDAT_PLACES][SCOREDAT_NAME_LEN + 1];
score_lebcd_t g_points[SCOREDAT_PLACES];
Expand All @@ -30,7 +29,6 @@ typedef struct {
unsigned char unused_2[SCOREDAT_PLACES];
#endif
} scoredat_t;
#pragma option -a.

typedef struct {
int8_t key1;
Expand Down
2 changes: 0 additions & 2 deletions th04/res_huma.cpp
Expand Up @@ -11,8 +11,6 @@
#include "th04/snd/snd.h"
#include "th04/formats/cfg.h"

#pragma option -a1

char debug = 0;
const cfg_options_t OPTS_DEFAULT = {
RANK_DEFAULT, CFG_LIVES_DEFAULT, CFG_BOMBS_DEFAULT,
Expand Down
2 changes: 0 additions & 2 deletions th04/resident.hpp
@@ -1,4 +1,3 @@
#pragma option -a1
#define RES_ID "HUMAConfig"
typedef struct {
char id[RES_ID_LEN];
Expand Down Expand Up @@ -55,4 +54,3 @@ typedef struct {
unsigned char turbo_mode;
int8_t unused_5[182];
} resident_t;
#pragma option -a.
2 changes: 2 additions & 0 deletions th05/p_common.cpp
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include "th05/i_shot.hpp"
#include "th02/snd/snd.h"

#pragma option -a2

char pascal near shot_cycle_init(void)
{
char cycle_flag = 0;
Expand Down
2 changes: 2 additions & 0 deletions th05/p_marisa.cpp
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include "th05/i_shot.hpp"
#define cycle _AL

#pragma option -a2

#define STAR_DISTANCE (16)
#define STAR_OFFSET(count) (8 - ((count / 2) * STAR_DISTANCE))

Expand Down
2 changes: 2 additions & 0 deletions th05/p_mima.cpp
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include "th05/i_shot.hpp"
#define cycle _AL

#pragma option -a2

void pascal near shot_mima_l2(void)
{
SHOT_FUNC_INIT(2, SC_6X, SC_3X, i++);
Expand Down
2 changes: 2 additions & 0 deletions th05/p_yuuka.cpp
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include "th05/i_shot.hpp"
#define cycle _AL

#pragma option -a2

#define YUUKA_INNER_L4 \
switch(sai.i - 1) { \
case 0: sai.angle = 186; break; \
Expand Down
2 changes: 0 additions & 2 deletions th05/res_kso.cpp
Expand Up @@ -12,8 +12,6 @@
#include "th04/snd/snd.h"
#include "th04/formats/cfg.h"

#pragma option -a1

char debug = 0;
const cfg_options_t OPTS_DEFAULT = {
RANK_DEFAULT, CFG_LIVES_DEFAULT, CFG_BOMBS_DEFAULT,
Expand Down

0 comments on commit 02f0a0a

Please sign in to comment.