Skip to content

Commit

Permalink
refactor: reduced warnings from MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
kg68k committed Oct 16, 2024
1 parent d3b2fdc commit 12a6d9c
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 199 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# run68x 2.0.2 (2024-10-17)

* `DOS _CREATE``DOS _NEWFILE``DOS _OPEN`の処理を書き直した。
* (win32) `DOS _OPEN`でオープン済みファイルを更にオープンできるようにした。
* (generic) `DOS _CREATE``DOS _NEWFILE`でキャラクタデバイスをオープン
できないようにした。
* (generic) `DOS _FILES`でファイルサイズを取得するようにした。


# run68x 2.0.1 (2024-06-12)

* `MOVEM (An)+,An`命令で`An`レジスタの値が正しくない不具合を修正。
Expand Down
6 changes: 3 additions & 3 deletions src/ansicolor-w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int WriteW32(short _type, HANDLE handle, const char *_buf, size_t _len) {
DWORD written, csize;
CONSOLE_CURSOR_INFO cci;
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coord;
COORD coord = {0};
const char *ptr;

if (_type == 1) {
Expand All @@ -54,8 +54,8 @@ int WriteW32(short _type, HANDLE handle, const char *_buf, size_t _len) {
while (*ptr) {
if (*ptr == '\033') {
unsigned char c;
int i, n = 0, m, v[6], w, h;
for (i = 0; i < 6; i++) v[i] = -1;
int i, n = 0, m = 0, w, h;
int v[6] = { -1, -1, -1, -1, -1, -1 };
ptr++;
retry:
if ((c = *ptr++) == 0) break;
Expand Down
19 changes: 9 additions & 10 deletions src/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ static UWord watchcode(int argc, char **argv) {
debuggerError("watchcode:Instruction code expression error.\n");
return 0x4afc;
}
sscanf(&argv[1][1], "%hx", &wcode);
return (UWord)wcode;
return (sscanf(&argv[1][1], "%hx", &wcode) == 1) ? (UWord)wcode : 0;
}

/*
Expand Down Expand Up @@ -409,8 +408,7 @@ static void set_breakpoint(int argc, char **argv) {

{
long unsigned int a;
sscanf(&argv[1][1], "%lx", &a);
settings.trapPc = (ULong)a;
settings.trapPc = (sscanf(&argv[1][1], "%lx", &a) == 1) ? (ULong)a : 0;
}
}

Expand All @@ -423,7 +421,7 @@ static void display_history(int argc, char **argv) {
} else if (determine_string(argv[1]) != 1) {
debuggerError("history:Argument error.\n");
} else {
sscanf(argv[1], "%d", &n);
n = (sscanf(argv[1], "%d", &n) == 1) ? n : 10;
}
OPBuf_display(n);
}
Expand All @@ -448,12 +446,14 @@ static void display_list(int argc, char **argv) {
}
if (2 <= argc) {
if (argc == 2 && determine_string(argv[1]) == 1) {
sscanf(argv[1], "%d", &n);
n = (sscanf(argv[1], "%d", &n) == 1) ? n : 10;
} else if (argc >= 2 && determine_string(argv[1]) == 2) {
sscanf(&argv[1][1], "%x", &addr);
addr = (sscanf(&argv[1][1], "%x", &addr) == 1) ? addr
: (list_addr == 0) ? pc
: list_addr;
}
if (argc == 3 && determine_string(argv[2]) == 1) {
sscanf(argv[2], "%d", &n);
n = (sscanf(argv[2], "%d", &n) == 1) ? n : 10;
}
}
for (i = 0; i < n; i++) {
Expand Down Expand Up @@ -495,8 +495,7 @@ static ULong get_stepcount(int argc, char **argv) {
return 0;
} else if (determine_string(argv[1]) == 1) {
long unsigned int a;
sscanf(argv[1], "%lu", &a);
count = (ULong)a;
count = (sscanf(argv[1], "%lu", &a) == 1) ? (ULong)a : 0;
}
return count;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dos_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Long Seek(UWord fileno, Long offset, UWord mode) {

// 最後のパスデリミタ(\ : /)の次のアドレスを求める
// パスデリミタがなければ文字列先頭を返す
char* get_filename(char* path) {
static char* get_filename(char* path) {
char* filename = path;
char* p = path;
char c;
Expand Down
10 changes: 5 additions & 5 deletions src/dos_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static ULong tryMalloc(UByte mode, ULong sizeWithHeader, ULong parent,

ULong memoryEnd = ReadULongSuper(OSWORK_MEMORY_END);
ULong memblk = ReadULongSuper(OSWORK_ROOT_PSP);
ULong next;
ULong next = 0;
for (; memblk != 0; memblk = next) {
next = ReadULongSuper(memblk + MEMBLK_NEXT);

Expand Down Expand Up @@ -206,8 +206,8 @@ Long Mfree(ULong adr) {

// 指定したプロセスが確保したメモリブロックを全て解放する
static void MfreeAll(ULong psp) {
ULong next, m;
for (m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
ULong next = 0;
for (ULong m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
next = ReadULongSuper(m + MEMBLK_NEXT);

ULong parent = ReadULongSuper(m + MEMBLK_PARENT);
Expand Down Expand Up @@ -281,8 +281,8 @@ Long SetblockHuge(ULong adr, ULong size) {
static bool is_valid_memblk(ULong memblk, ULong* nextptr) {
if (nextptr != NULL) *nextptr = 0;

ULong next, m;
for (m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
ULong next = 0;
for (ULong m = ReadULongSuper(OSWORK_ROOT_PSP);; m = next) {
next = ReadULongSuper(m + MEMBLK_NEXT);
if (m == memblk) break;
if (next == 0) return false;
Expand Down
99 changes: 51 additions & 48 deletions src/doscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static Long Gets(Long);
static Long Kflush(short);
static Long Ioctrl(short, Long);
static Long Dup(short);
static Long Dup2(short, short);
static Long Dup2(short org, short new);
static Long Dskfre(short, Long);
static Long Close(short);
static Long Fgets(Long, short);
Expand Down Expand Up @@ -91,13 +91,13 @@ static Long Exec3(ULong, Long, Long);
static void Exec4(Long);

#ifndef _WIN32
int _dos_getfileattr(char* name, void* ret) {
static int _dos_getfileattr(char* name, void* ret) {
printf("_dos_getfileattr(\"%s\")\n", name);

return 1;
}

int _dos_setfileattr(char* name, short attr) {
static int _dos_setfileattr(char* name, short attr) {
printf("_dos_setfileattr(\"%s\", %d)\n", name, attr);

return 1;
Expand All @@ -117,12 +117,12 @@ char _getche() {
return getchar();
}

void dos_getdrive(Long* drv) {
static void dos_getdrive(Long* drv) {
// printf("dos_getdrive(%p)\n", drv );
*drv = 1; // 1 = A:
}

void dos_setdrive(Long drv, Long* dmy) {
static void dos_setdrive(Long drv, Long* dmy) {
// printf("dos_setdrive(%d, %p)\n", drv, dmy );
}

Expand All @@ -136,7 +136,7 @@ int kbhit() {
return 1;
}

char ungetch(char c) {
static char ungetch(char c) {
printf("ungetch()\n");
return 0;
}
Expand All @@ -161,7 +161,7 @@ static Long DosFgetc(ULong param) {
if (finfop->onmemory.buffer) return (Long)fgetcFromOnmemory(finfop);

#ifdef _WIN32
char c;
char c = 0;
DWORD read_len = 0;
if (GetFileType(finfop->host.handle) == FILE_TYPE_CHAR) {
/* 標準入力のハンドルがキャラクタタイプだったら、ReadConsoleを試してみる。*/
Expand All @@ -171,7 +171,8 @@ static Long DosFgetc(ULong param) {
ReadConsoleInput(finfop->host.handle, &ir, 1, (LPDWORD)&read_len);
if (b == FALSE) {
/* コンソールではなかった。*/
ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL);
if (!ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL))
c = 0;
break;
}
if (read_len == 1 && ir.EventType == KEY_EVENT &&
Expand All @@ -181,7 +182,8 @@ static Long DosFgetc(ULong param) {
}
}
} else {
ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL);
if (!ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL))
c = 0;
}
return (read_len == 0) ? DOSE_ILGFNC : c;
#else
Expand Down Expand Up @@ -470,7 +472,7 @@ bool dos_call(UByte code) {
// 非リダイレクト
WriteW32(1, finfop->host.handle, c, 1);
} else {
Long nwritten;
Long nwritten = 0;
/* Win32API */
WriteFile(finfop->host.handle, c, 1, (LPDWORD)&nwritten, NULL);
}
Expand Down Expand Up @@ -540,7 +542,7 @@ bool dos_call(UByte code) {
if (GetConsoleMode(finfop->host.handle, &st) != 0) {
WriteW32(1, finfop->host.handle, data_ptr, len);
} else {
Long nwritten;
Long nwritten = 0;
/* Win32API */
WriteFile(finfop->host.handle, data_ptr, len, (LPDWORD)&nwritten,
NULL);
Expand Down Expand Up @@ -1115,8 +1117,8 @@ static Long Dup2(short org, short new) {
*/
static Long Dskfre(short drv, Long buf) {
#ifdef _WIN32
ULong SectorsPerCluster, BytesPerSector, NumberOfFreeClusters,
TotalNumberOfClusters;
ULong SectorsPerCluster = 0, BytesPerSector = 0, NumberOfFreeClusters = 0,
TotalNumberOfClusters = 0;

BOOL b = GetDiskFreeSpaceA(
NULL, (LPDWORD)&SectorsPerCluster, (LPDWORD)&BytesPerSector,
Expand Down Expand Up @@ -1193,7 +1195,7 @@ static Long fgetsFromOnmemory(FILEINFO* finfop, ULong adr) {
戻り値:エラーコード
*/
static Long Fgets(Long adr, short hdl) {
char buf[257];
char buf[257] = {0};
size_t len;

FILEINFO* finfop = &finfo[hdl];
Expand All @@ -1208,8 +1210,8 @@ static Long Fgets(Long adr, short hdl) {
{
int i = 0;
while (i < max) {
DWORD read_len;
char c;
DWORD read_len = 0;
char c = 0;

if (ReadFile(finfop->host.handle, &c, 1, (LPDWORD)&read_len, NULL) ==
FALSE)
Expand Down Expand Up @@ -1263,7 +1265,7 @@ static Long Write(short hdl, Long buf, Long len) {
}

#ifdef _WIN32
unsigned len2;
unsigned len2 = 0;
WriteFile(finfo[hdl].host.handle, mem.bufptr, mem.length, &len2, NULL);
write_len = len2;
if (finfo[hdl].host.handle == GetStdHandle(STD_OUTPUT_HANDLE))
Expand Down Expand Up @@ -1563,25 +1565,24 @@ static Long Nfiles(Long buf) {
if (!mem.bufptr) throwBusErrorOnWrite(buf + mem.length);

#ifdef _WIN32
WIN32_FIND_DATA f_data;
WIN32_FIND_DATA f_data = {0};
char* buf_ptr = mem.bufptr;
short atr = buf_ptr[0]; /* 検索すべきファイルの属性 */

{
/* todo:buf_ptrの指す領域から必要な情報を取り出して、f_dataにコピーする。*/
/* 2秒→100nsに変換する。*/
SYSTEMTIME st;
unsigned short s;

s = *((unsigned short*)&buf_ptr[24]);
st.wYear = ((s & 0xfe00) >> 9) + 1980;
st.wMonth = (s & 0x01e0) >> 5;
st.wDay = (s & 0x1f);
s = *((unsigned short*)&buf_ptr[22]);
st.wHour = (s & 0xf800) >> 11;
st.wMinute = (s & 0x07e0) >> 5;
st.wSecond = (s & 0x001f);
st.wMilliseconds = 0;
unsigned short s1 = *((unsigned short*)&buf_ptr[24]);
unsigned short s2 = *((unsigned short*)&buf_ptr[22]);
SYSTEMTIME st = {
.wYear = ((s1 & 0xfe00) >> 9) + 1980,
.wMonth = (s1 & 0x01e0) >> 5,
.wDay = (s1 & 0x1f),
.wHour = (s2 & 0xf800) >> 11,
.wMinute = (s2 & 0x07e0) >> 5,
.wSecond = (s2 & 0x001f),
.wMilliseconds = 0,
};
SystemTimeToFileTime(&st, &f_data.ftLastWriteTime);

f_data.nFileSizeHigh = 0;
Expand Down Expand Up @@ -1673,15 +1674,16 @@ static Long Getdate() {
*/
static Long Setdate(short dt) {
#ifdef _WIN32
SYSTEMTIME stime;
BOOL b;
stime.wYear = (dt >> 9) & 0x7F + 1980;
stime.wMonth = (dt >> 5) & 0xF;
stime.wDay = dt & 0x1f;
stime.wSecond = 0;
stime.wMilliseconds = 0;
// b = SetSystemTime(&stime);
b = SetLocalTime(&stime);
SYSTEMTIME stime = {
.wYear = (dt >> 9) & 0x7F + 1980,
.wMonth = (dt >> 5) & 0xF,
.wDay = dt & 0x1f,
.wSecond = 0,
.wMilliseconds = 0,
};

// BOOL b = SetSystemTime(&stime);
BOOL b = SetLocalTime(&stime);
if (!b) return -14; /* パラメータ不正 */
#else
printf("DOSCALL SETDATE:not defined yet %s %d\n", __FILE__, __LINE__);
Expand Down Expand Up @@ -1731,14 +1733,15 @@ static Long Gettime(int flag) {
*/
static Long Settim2(Long tim) {
#ifdef _WIN32
SYSTEMTIME stime;
BOOL b;
stime.wYear = (tim >> 16) & 0x1F;
stime.wMonth = (tim >> 8) & 0x3F;
stime.wDay = tim & 0x3f;
stime.wSecond = 0;
stime.wMilliseconds = 0;
b = SetSystemTime(&stime);
SYSTEMTIME stime = {
.wYear = (tim >> 16) & 0x1F,
.wMonth = (tim >> 8) & 0x3F,
.wDay = tim & 0x3f,
.wSecond = 0,
.wMilliseconds = 0,
};

BOOL b = SetSystemTime(&stime);
if (!b) return -14; /* パラメータ不正 */
#else
printf("DOSCALL SETTIM2:not defined yet %s %d\n", __FILE__, __LINE__);
Expand Down Expand Up @@ -2374,7 +2377,7 @@ Long gets2(char* str, int max) {
}
if (c == EOF) str[cnt++] = EOF;
#ifdef _WIN32
unsigned dmy;
DWORD dmy = 0;
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "\x01B[1A", 4, &dmy, NULL);
#endif
/* printf("%c[1A", 0x1B); */ /* カーソルを1行上に */
Expand Down
4 changes: 2 additions & 2 deletions src/dostrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static int codeToEscapeChar(int c) {
#define STRING_MAX_WIDTH 32

static void dumpString(const char* s) {
char buf[STRING_MAX_WIDTH + 16];
char buf[STRING_MAX_WIDTH + 16] = {0};
char* end = &buf[STRING_MAX_WIDTH];
char* p = buf;

Expand Down Expand Up @@ -590,7 +590,7 @@ static void printParam(const char* format, ULong* refParam) {
}
}

const char* printFormat(const char* format, ULong* refParam) {
static const char* printFormat(const char* format, ULong* refParam) {
while (format[0] != '\0') {
const char* bracket = strchr(format, '{');
if (bracket == NULL) break;
Expand Down
Loading

0 comments on commit 12a6d9c

Please sign in to comment.