Skip to content

Commit

Permalink
refactor: improved readability
Browse files Browse the repository at this point in the history
  • Loading branch information
kg68k committed Nov 26, 2024
1 parent 9abd6af commit 1a2722b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 63 deletions.
10 changes: 5 additions & 5 deletions src/hex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 16進変換 , String 関数
// Copyright (C) 1989,1990 K.Abe, 1994 R.ShimiZu
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2024 TcbnErik

#include "hex.h"

Expand All @@ -11,7 +11,7 @@
#include "estruct.h"
#include "global.h"

char Hex[16] = "0123456789abcdef";
char HexCharTable[16] = "0123456789abcdef";

static char* ulongToDecimal(char* buf, ULONG n);

Expand Down Expand Up @@ -45,7 +45,7 @@ extern char* itox(char* buf, ULONG n, int width) {
do {
// 下位桁からテンポラリに変換
i += 1;
*--p = Hex[n & 0xf];
*--p = HexCharTable[n & 0xf];
n >>= 4;
} while (n);
do {
Expand All @@ -61,7 +61,7 @@ extern char* itox(char* buf, ULONG n, int width) {

for (i = width; --i >= 0;) {
/* 下位桁から変換 */
*--p = Hex[n & 0xf];
*--p = HexCharTable[n & 0xf];
n >>= 4;
}
}
Expand All @@ -75,7 +75,7 @@ static char* itox_without_0supress(char* buf, ULONG n, int width) {
int i;

for (i = width; --i >= 0;) {
*--p = Hex[n & 0xf];
*--p = HexCharTable[n & 0xf];
n >>= 4;
}
*buf = '\0';
Expand Down
12 changes: 6 additions & 6 deletions src/hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 16進変換, String 関数 ヘッダ
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2024 TcbnErik

#ifndef HEX_H
#define HEX_H
Expand All @@ -15,22 +15,22 @@ extern char* itox8_without_0supress(char*, ULONG);
extern char* itox6_without_0supress(char*, ULONG);
extern char* itox4_without_0supress(char*, ULONG);

extern char Hex[16];
extern char HexCharTable[16];

static inline char* itox2(char* buf, ULONG n) {
if (!Dis.Z || n >= 0x10) {
// 10 の位
*buf++ = Hex[(n >> 4) & 0xf];
*buf++ = HexCharTable[(n >> 4) & 0xf];
}
// 1 の位
*buf++ = Hex[n & 0xf];
*buf++ = HexCharTable[n & 0xf];
*buf = '\0';
return buf;
}

static inline char* itox2_without_0supress(char* buf, ULONG n) {
*buf++ = Hex[(n >> 4) & 0xf];
*buf++ = Hex[n & 0xf];
*buf++ = HexCharTable[(n >> 4) & 0xf];
*buf++ = HexCharTable[n & 0xf];
*buf = '\0';
return buf;
}
Expand Down
4 changes: 3 additions & 1 deletion src/human.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ソースコードジェネレータ
// Human68k
// Copyright (C) 2023 TcbnErik
// Copyright (C) 2024 TcbnErik

// This file is part of dis (source code generator).
//
Expand Down Expand Up @@ -258,8 +258,10 @@ static void analyzeDeviceDriver(void) {
regist_label(dev + DH_TYPE, DATLABEL | WORDSIZE | FORCE | HIDDEN);

// ストラテジルーチンと割り込みルーチンはリロケート情報があるので登録不要
// ```
// regist_label(dev + DH_STRATEGY, DATLABEL | LONGSIZE | FORCE);
// regist_label(dev + DH_INTERRUPT, DATLABEL | LONGSIZE | FORCE);
// ```

regist_label(dev + DH_NAME, DATLABEL | STRING | FORCE | HIDDEN);
regist_label(dev + DH_SIZE, DATLABEL | UNKNOWN);
Expand Down
4 changes: 2 additions & 2 deletions src/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ boolean registerLabelDebug(address adrs, lblmode mode, address target,
if (adrs == target) {
const char* b = result ? "TRUE" : "FALSE";
lblbuf* lptr = search_label(adrs);
unsigned int mode = lptr ? (unsigned int)lptr->mode : 0;
unsigned int md = lptr ? (unsigned int)lptr->mode : 0;
eprintf("\n%s:%d: registerLabel(adrs=" PRI_ADRS
", mode=$%06x) -> %s (mode=$%06x). ",
file, line, adrs, (unsigned int)mode, b, mode);
file, line, adrs, (unsigned int)mode, b, md);
}

return result;
Expand Down
107 changes: 59 additions & 48 deletions src/labelfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ラベルファイルモジュール
// Copyright (C) 1989,1990 K.Abe
// All rights reserved.
// Copyright (C) 1997-2023 TcbnErik
// Copyright (C) 2024 TcbnErik

#include <ctype.h> /* toupper */
#include <stdio.h>
Expand Down Expand Up @@ -117,6 +117,63 @@ static char* untilspace(char* ptr) {
return ptr;
}

// データ系の属性文字列を変換する
static boolean parseLabelAttrD(char** pStr, lblmode* pAttr) {
lblmode attr = DATLABEL;
char* p = *pStr;

switch (toupper(*p++)) {
default:
return FALSE;

case 'B':
attr |= BYTESIZE;
break;
case 'W':
attr |= WORDSIZE;
break;
case 'L':
attr |= LONGSIZE;
break;
case 'Q':
attr |= QUADSIZE;
break;
case 'F':
attr |= SINGLESIZE;
break;
case 'D':
attr |= DOUBLESIZE;
break;
case 'X':
attr |= EXTENDSIZE;
break;
case 'P':
attr |= PACKEDSIZE;
break;
case 'S':
attr |= STRING;
break;
case 'Z':
attr |= ZTABLE;
break;
case 'U':
attr |= UNKNOWN;
break;

case 'R':
attr |= RELTABLE;
if (toupper(*p) == 'L') {
p += 1;
attr ^= (RELTABLE ^ RELLONGTABLE);
}
break;
}

*pStr = p;
*pAttr = attr;
return TRUE;
}

// 属性文字列をopesizeに変換する
// 成功時はattrptrに書き込んでTRUEを返す
static boolean parseLabelAttribute(char* p, lblmode* attrptr) {
Expand Down Expand Up @@ -146,53 +203,7 @@ static boolean parseLabelAttribute(char* p, lblmode* attrptr) {
break;

case 'D':
c = *p++;
switch (toupper(c)) {
default:
return FALSE;

case 'B':
attr |= BYTESIZE;
break;
case 'W':
attr |= WORDSIZE;
break;
case 'L':
attr |= LONGSIZE;
break;
case 'Q':
attr |= QUADSIZE;
break;
case 'F':
attr |= SINGLESIZE;
break;
case 'D':
attr |= DOUBLESIZE;
break;
case 'X':
attr |= EXTENDSIZE;
break;
case 'P':
attr |= PACKEDSIZE;
break;
case 'S':
attr |= STRING;
break;
case 'Z':
attr |= ZTABLE;
break;
case 'U':
attr |= UNKNOWN;
break;

case 'R':
attr |= RELTABLE;
if (toupper(*p) == 'L') {
p += 1;
attr ^= (RELTABLE ^ RELLONGTABLE);
}
break;
}
if (!parseLabelAttrD(&p, &attr)) return FALSE;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ static void option_switch(int opt) {
Dis.U = TRUE;
/* fall through */
case 'X':
toUpperMemory(sizeof(Hex), Hex);
toUpperMemory(sizeof(HexCharTable), HexCharTable);
break;
case 'V':
analyzeOption_V(optarg, opt);
Expand Down

0 comments on commit 1a2722b

Please sign in to comment.