aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Serpell <daniel.serpell@gmail.com>2020-05-05 10:19:11 -0400
committerDaniel Serpell <daniel.serpell@gmail.com>2020-05-05 11:12:26 -0400
commitcc32a3879ddff11becbb2e84329bb1bfd15c298c (patch)
tree95d7b45e2a07682b645c8ac2237769d6f2ec2b3e
parent7876fffb9dddbc000841546768dcfadddec58ea2 (diff)
downloademu2-cc32a3879ddff11becbb2e84329bb1bfd15c298c.tar.gz
Reformat code with clang-format.
Also fixes some comments.
-rw-r--r--src/codepage.c9
-rw-r--r--src/cpu.c54
-rw-r--r--src/cpu.h27
-rw-r--r--src/dbg.c15
-rw-r--r--src/dbg.h8
-rw-r--r--src/dis.c114
-rw-r--r--src/dos.c275
-rw-r--r--src/dos.h2
-rw-r--r--src/dosnames.c71
-rw-r--r--src/emu.h4
-rw-r--r--src/keyb.c9
-rw-r--r--src/loader.c220
-rw-r--r--src/loader.h2
-rw-r--r--src/main.c13
-rw-r--r--src/timer.c35
-rw-r--r--src/timer.h1
-rw-r--r--src/utils.c11
-rw-r--r--src/utils.h2
-rw-r--r--src/video.c186
19 files changed, 539 insertions, 519 deletions
diff --git a/src/codepage.c b/src/codepage.c
index f0c61f8..0ec0438 100644
--- a/src/codepage.c
+++ b/src/codepage.c
@@ -204,8 +204,9 @@ static int read_codepage_file(const char *fname)
if(ucode < 32 || ucode > 0xFFFF)
{
fclose(f);
- print_error("reading codepage '%s', line '%s', invalid unicode value %d\n",
- fname, line, ucode);
+ print_error(
+ "reading codepage '%s', line '%s', invalid unicode value %d\n", fname,
+ line, ucode);
}
new_table[dcode] = ucode;
}
@@ -232,8 +233,7 @@ void set_codepage(const char *cp_name)
}
}
if(!read_codepage_file(cp_name))
- print_error("missing or unknown codepage '%s', use '?' for a list.\n",
- cp_name);
+ print_error("missing or unknown codepage '%s', use '?' for a list.\n", cp_name);
}
static void list_codepages(void)
@@ -271,4 +271,3 @@ int get_dos_char(int uc)
// Assume space is always valid
return ' ';
}
-
diff --git a/src/cpu.c b/src/cpu.c
index fc8be9e..47bfe6e 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -117,9 +117,13 @@ static void PushWord(uint16_t w)
}
#ifdef CPU_PUSH_80286
-# define PUSH_SP() PushWord(wregs[SP]); break;
+#define PUSH_SP() \
+ PushWord(wregs[SP]); \
+ break;
#else
-# define PUSH_SP() PushWord(wregs[SP] - 2); break;
+#define PUSH_SP() \
+ PushWord(wregs[SP] - 2); \
+ break;
#endif
static uint16_t PopWord(void)
@@ -129,8 +133,12 @@ static uint16_t PopWord(void)
return tmp;
}
-#define PUSH_WR(reg) PushWord(wregs[reg]); break;
-#define POP_WR(reg) wregs[reg] = PopWord(); break;
+#define PUSH_WR(reg) \
+ PushWord(wregs[reg]); \
+ break;
+#define POP_WR(reg) \
+ wregs[reg] = PopWord(); \
+ break;
#define XCHG_AX_WR(reg) \
{ \
@@ -453,7 +461,7 @@ static void handle_irq(void)
if(bit)
{
uint8_t bp[16] = {0, 1, 2, 5, 3, 9, 6, 11, 15, 4, 8, 10, 14, 7, 13, 12};
- uint8_t irqn = bp[(bit * 0x9af)>>12];
+ uint8_t irqn = bp[(bit * 0x9af) >> 12];
debug(debug_int, "handle irq, mask=$%04x irq=%d\n", irq_mask, irqn);
irq_mask &= ~bit;
if(irqn < 8)
@@ -680,9 +688,15 @@ static void handle_irq(void)
} \
break;
-#define MOV_BRH(reg) wregs[reg] = ((0x00FF & wregs[reg]) | (FETCH_B() << 8)); break;
-#define MOV_BRL(reg) wregs[reg] = ((0xFF00 & wregs[reg]) | FETCH_B()); break;
-#define MOV_WRi(reg) wregs[reg] = FETCH_W(); break;
+#define MOV_BRH(reg) \
+ wregs[reg] = ((0x00FF & wregs[reg]) | (FETCH_B() << 8)); \
+ break;
+#define MOV_BRL(reg) \
+ wregs[reg] = ((0xFF00 & wregs[reg]) | FETCH_B()); \
+ break;
+#define MOV_WRi(reg) \
+ wregs[reg] = FETCH_W(); \
+ break;
#define SEG_OVERRIDE(seg) \
{ \
@@ -1733,8 +1747,7 @@ static void i_aad(void)
static void i_xlat(void)
{
- wregs[AX] =
- (wregs[AX] & 0xFF00) | GetMemDSB(wregs[BX] + (wregs[AX] & 0xFF));
+ wregs[AX] = (wregs[AX] & 0xFF00) | GetMemDSB(wregs[BX] + (wregs[AX] & 0xFF));
}
static void i_escape(void)
@@ -2261,18 +2274,14 @@ static void debug_instruction(void)
unsigned nip = (cpuGetIP() + 0xFFFF) & 0xFFFF; // substract 1!
const uint8_t *ip = memory + sregs[CS] * 16 + nip;
- debug(debug_cpu, "AX=%04X BX=%04X CX=%04X DX=%04X SP=%04X BP=%04X "
- "SI=%04X DI=%04X ",
- cpuGetAX(), cpuGetBX(), cpuGetCX(), cpuGetDX(), cpuGetSP(),
- cpuGetBP(), cpuGetSI(), cpuGetDI());
- debug(debug_cpu, "DS=%04X ES=%04X SS=%04X CS=%04X IP=%04X %s %s %s "
- "%s %s %s %s %s ",
+ debug(debug_cpu, "AX=%04X BX=%04X CX=%04X DX=%04X SP=%04X BP=%04X SI=%04X DI=%04X ",
+ cpuGetAX(), cpuGetBX(), cpuGetCX(), cpuGetDX(), cpuGetSP(), cpuGetBP(),
+ cpuGetSI(), cpuGetDI());
+ debug(debug_cpu, "DS=%04X ES=%04X SS=%04X CS=%04X IP=%04X %s %s %s %s %s %s %s %s ",
cpuGetDS(), cpuGetES(), cpuGetSS(), cpuGetCS(), nip, OF ? "OV" : "NV",
- DF ? "DN" : "UP", IF ? "EI" : "DI", SF ? "NG" : "PL",
- ZF ? "ZR" : "NZ", AF ? "AC" : "NA", PF ? "PE" : "PO",
- CF ? "CY" : "NC");
- debug(debug_cpu, "%04X:%04X %s\n", sregs[CS], nip,
- disa(ip, nip, segment_override));
+ DF ? "DN" : "UP", IF ? "EI" : "DI", SF ? "NG" : "PL", ZF ? "ZR" : "NZ",
+ AF ? "AC" : "NA", PF ? "PE" : "PO", CF ? "CY" : "NC");
+ debug(debug_cpu, "%04X:%04X %s\n", sregs[CS], nip, disa(ip, nip, segment_override));
}
static void do_instruction(uint8_t code)
@@ -2634,6 +2643,5 @@ uint16_t cpuGetStack(uint16_t disp)
void cpuTriggerIRQ(int num)
{
- irq_mask |= (1<<num);
+ irq_mask |= (1 << num);
}
-
diff --git a/src/cpu.h b/src/cpu.h
index d0b9b04..d4a426c 100644
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -1,22 +1,11 @@
-/****************************************************************************
-* *
-* Third Year Project *
-* *
-* An IBM PC Emulator *
-* For Unix and X Windows *
-* *
-* By David Hedley *
-* *
-* *
-* This program is Copyrighted. Consult the file COPYRIGHT for more details *
-* *
-****************************************************************************/
-
-/* This is CPU.H it contains definitions for cpu.c */
-
-#ifndef CPU_H
-#define CPU_H
+/*
+ * This is based on code by David Hedley, from pcemu.
+ *
+ * Most of the CPU emulation was rewritten and code was extended to support
+ * 80186 and some 81280 instructions.
+ */
+#pragma once
#include <stdint.h>
// Enable/disable 80286 stack emulation, 80286 and higher push the old value of
@@ -75,5 +64,3 @@ enum
DF = ((f)&1024) == 1024; \
OF = (f)&2048; \
}
-
-#endif
diff --git a/src/dbg.c b/src/dbg.c
index b7f3ea9..11a6dd1 100644
--- a/src/dbg.c
+++ b/src/dbg.c
@@ -29,15 +29,9 @@ void print_usage(void)
" %-18s DOS current working directory, use 'C:\\' if not given.\n"
" %-18s Set unix path as root of drive 'n', by default all drives\n"
"\t\t point to the unix working directory.\n"
- ". %-18s Set DOS code-page. Set to '?' to show lost of code-pages.\n"
- , prog_name
- , ENV_DBG_NAME
- , ENV_DBG_OPT
- , ENV_PROGNAME
- , ENV_DEF_DRIVE
- , ENV_CWD
- , ENV_DRIVE "n"
- , ENV_CODEPAGE);
+ ". %-18s Set DOS code-page. Set to '?' to show lost of code-pages.\n",
+ prog_name, ENV_DBG_NAME, ENV_DBG_OPT, ENV_PROGNAME, ENV_DEF_DRIVE, ENV_CWD,
+ ENV_DRIVE "n", ENV_CODEPAGE);
exit(EXIT_SUCCESS);
}
@@ -76,8 +70,7 @@ static FILE *open_log_file(const char *base, const char *type)
}
if(fd == -1)
print_error("can't open debug log '%s'\n", log_name);
- fprintf(stderr, "%s: %s debug log on file '%s'.\n", prog_name, type,
- log_name);
+ fprintf(stderr, "%s: %s debug log on file '%s'.\n", prog_name, type, log_name);
return fdopen(fd, "w");
}
diff --git a/src/dbg.h b/src/dbg.h
index 6d16c3f..eae3c10 100644
--- a/src/dbg.h
+++ b/src/dbg.h
@@ -5,10 +5,8 @@
extern char *prog_name;
void print_usage(void);
-void print_usage_error(const char *format, ...)
- __attribute__ ((format (printf, 1, 2)));
-void print_error(const char *format, ...)
- __attribute__ ((format (printf, 1, 2)));
+void print_usage_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
+void print_error(const char *format, ...) __attribute__((format(printf, 1, 2)));
enum debug_type
{
@@ -22,5 +20,5 @@ enum debug_type
void init_debug(const char *name);
void debug(enum debug_type, const char *format, ...)
- __attribute__ ((format (printf, 2, 3)));
+ __attribute__((format(printf, 2, 3)));
int debug_active(enum debug_type);
diff --git a/src/dis.c b/src/dis.c
index fec5f96..18aa3e6 100644
--- a/src/dis.c
+++ b/src/dis.c
@@ -10,23 +10,18 @@ static char buf[128];
#define IPOS (buf + 17)
#define EPOS (buf + 127)
-static const char *byte_reg[] = {"AL", "CL", "DL", "BL",
- "AH", "CH", "DH", "BH"};
-static const char *word_reg[] = {"AX", "CX", "DX", "BX",
- "SP", "BP", "SI", "DI"};
+static const char *byte_reg[] = {"AL", "CL", "DL", "BL", "AH", "CH", "DH", "BH"};
+static const char *word_reg[] = {"AX", "CX", "DX", "BX", "SP", "BP", "SI", "DI"};
static const char *seg_reg[] = {"ES", "CS", "SS", "DS"};
static const char *index_reg[] = {"BX+SI", "BX+DI", "BP+SI", "BP+DI",
"SI", "DI", "BP", "BX"};
-static const char *table_dx[] = {"ROL", "ROR", "RCL", "RCR",
- "SHL", "SHR", "SHL", "SAR"};
+static const char *table_dx[] = {"ROL", "ROR", "RCL", "RCR", "SHL", "SHR", "SHL", "SAR"};
static const char *table_f6[] = {"TEST", "ILL", "NOT", "NEG",
"MUL", "IMUL", "DIV", "IDIV"};
-static const char *table_fe[] = {"INC", "DEC", "ILL", "ILL",
- "ILL", "ILL", "ILL", "ILL"};
+static const char *table_fe[] = {"INC", "DEC", "ILL", "ILL", "ILL", "ILL", "ILL", "ILL"};
static const char *table_ff[] = {"INC", "DEC", "CALL", "CALL",
"JMP", "JMP", "PUSH", "ILL"};
-static const char *table_8x[] = {"ADD", "OR", "ADC", "SBB",
- "AND", "SUB", "XOR", "CMP"};
+static const char *table_8x[] = {"ADD", "OR", "ADC", "SBB", "AND", "SUB", "XOR", "CMP"};
#define BREG byte_reg[(ModRM & 0x38) >> 3]
#define WREG word_reg[(ModRM & 0x38) >> 3]
@@ -55,8 +50,7 @@ static char *get_mem(unsigned ModRM, const uint8_t *ip, const char *rg[],
if((ModRM & 0x07) != 6)
sprintf(buffer, "%s%s[%s]", cast, seg_names[seg_over], IXREG);
else
- sprintf(buffer, "%s%s[%02X%02X]", cast, seg_names[seg_over], ip[2],
- ip[1]);
+ sprintf(buffer, "%s%s[%02X%02X]", cast, seg_names[seg_over], ip[2], ip[1]);
break;
case 0x40:
if((num = ip[1]) > 127)
@@ -66,8 +60,7 @@ static char *get_mem(unsigned ModRM, const uint8_t *ip, const char *rg[],
}
else
ch = '+';
- sprintf(buffer, "%s%s[%s%c%02X]", cast, seg_names[seg_over], IXREG, ch,
- num);
+ sprintf(buffer, "%s%s[%s%c%02X]", cast, seg_names[seg_over], IXREG, ch, num);
break;
case 0x80:
if((num = (ip[2] * 256 + ip[1])) > 0x7fff)
@@ -77,8 +70,7 @@ static char *get_mem(unsigned ModRM, const uint8_t *ip, const char *rg[],
}
else
ch = '+';
- sprintf(buffer, "%s%s[%s%c%04X]", cast, seg_names[seg_over], IXREG, ch,
- num);
+ sprintf(buffer, "%s%s[%s%c%04X]", cast, seg_names[seg_over], IXREG, ch, num);
break;
case 0xc0:
strcpy(buffer, rg[ModRM & 7]);
@@ -91,10 +83,14 @@ static int get_mem_len(unsigned ModRM)
{
switch(ModRM & 0xc0)
{
- case 0x00: return ((ModRM & 0x07) == 6) ? 2 : 0;
- case 0x40: return 1;
- case 0x80: return 2;
- default: return 0;
+ case 0x00:
+ return ((ModRM & 0x07) == 6) ? 2 : 0;
+ case 0x40:
+ return 1;
+ case 0x80:
+ return 2;
+ default:
+ return 0;
}
}
@@ -119,8 +115,7 @@ static const char *decode_wordreg(const uint8_t *ip, const char *ins)
return buf;
}
-static const char *decode_jump(const uint8_t *ip, const char *ins,
- uint16_t reg_ip)
+static const char *decode_jump(const uint8_t *ip, const char *ins, uint16_t reg_ip)
{
reg_ip += 3 + ip[2] * 256 + ip[1];
fillbytes(ip, 3);
@@ -128,8 +123,7 @@ static const char *decode_jump(const uint8_t *ip, const char *ins,
return buf;
}
-static const char *decode_jump8(const uint8_t *ip, const char *ins,
- uint16_t reg_ip)
+static const char *decode_jump8(const uint8_t *ip, const char *ins, uint16_t reg_ip)
{
if(ip[1] < 0x80)
reg_ip += 2 + ip[1];
@@ -143,54 +137,43 @@ static const char *decode_jump8(const uint8_t *ip, const char *ins,
static const char *decode_far(const uint8_t *ip, const char *ins)
{
fillbytes(ip, 5);
- sprintf(IPOS, "%-7s %04X:%04X", ins, ip[4] * 256 + ip[3],
- ip[2] * 256 + ip[1]);
+ sprintf(IPOS, "%-7s %04X:%04X", ins, ip[4] * 256 + ip[3], ip[2] * 256 + ip[1]);
return buf;
}
-static const char *decode_far_ind(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_far_ind(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
fillbytes(ip, 2 + get_mem_len(ModRM));
- sprintf(IPOS, "%-7s FAR %s", ins,
- get_mem(ModRM, ip + 1, word_reg, "", seg_over));
+ sprintf(IPOS, "%-7s FAR %s", ins, get_mem(ModRM, ip + 1, word_reg, "", seg_over));
return buf;
}
-static const char *decode_memal(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_memal(const uint8_t *ip, const char *ins, int seg_over)
{
fillbytes(ip, 3);
- sprintf(IPOS, "%-7s %s[%02X%02X],AL", ins, seg_names[seg_over], ip[2],
- ip[1]);
+ sprintf(IPOS, "%-7s %s[%02X%02X],AL", ins, seg_names[seg_over], ip[2], ip[1]);
return buf;
}
-static const char *decode_memax(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_memax(const uint8_t *ip, const char *ins, int seg_over)
{
fillbytes(ip, 3);
- sprintf(IPOS, "%-7s %s[%02X%02X],AX", ins, seg_names[seg_over], ip[2],
- ip[1]);
+ sprintf(IPOS, "%-7s %s[%02X%02X],AX", ins, seg_names[seg_over], ip[2], ip[1]);
return buf;
}
-static const char *decode_almem(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_almem(const uint8_t *ip, const char *ins, int seg_over)
{
fillbytes(ip, 3);
- sprintf(IPOS, "%-7s AL,%s[%02X%02X]", ins, seg_names[seg_over], ip[2],
- ip[1]);
+ sprintf(IPOS, "%-7s AL,%s[%02X%02X]", ins, seg_names[seg_over], ip[2], ip[1]);
return buf;
}
-static const char *decode_axmem(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_axmem(const uint8_t *ip, const char *ins, int seg_over)
{
fillbytes(ip, 3);
- sprintf(IPOS, "%-7s AX,%s[%02X%02X]", ins, seg_names[seg_over], ip[2],
- ip[1]);
+ sprintf(IPOS, "%-7s AX,%s[%02X%02X]", ins, seg_names[seg_over], ip[2], ip[1]);
return buf;
}
@@ -285,8 +268,8 @@ static const char *decode_br8(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
fillbytes(ip, 2 + get_mem_len(ModRM));
- sprintf(IPOS, "%-7s %s,%s", ins,
- get_mem(ModRM, ip + 1, byte_reg, "", seg_over), BREG);
+ sprintf(IPOS, "%-7s %s,%s", ins, get_mem(ModRM, ip + 1, byte_reg, "", seg_over),
+ BREG);
return buf;
}
@@ -305,8 +288,7 @@ static const char *decode_bd8(const uint8_t *ip, const char *ins, int seg_over)
int ln = get_mem_len(ModRM);
fillbytes(ip, 3 + ln);
sprintf(IPOS, "%-7s %s,%02X", ins,
- get_mem(ModRM, ip + 1, byte_reg, "BYTE PTR ", seg_over),
- ip[ln + 2]);
+ get_mem(ModRM, ip + 1, byte_reg, "BYTE PTR ", seg_over), ip[ln + 2]);
return buf;
}
@@ -323,8 +305,8 @@ static const char *decode_ws(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
fillbytes(ip, 2 + get_mem_len(ModRM));
- sprintf(IPOS, "%-7s %s,%s", ins,
- get_mem(ModRM, ip + 1, word_reg, "", seg_over), SREG);
+ sprintf(IPOS, "%-7s %s,%s", ins, get_mem(ModRM, ip + 1, word_reg, "", seg_over),
+ SREG);
return buf;
}
@@ -350,8 +332,8 @@ static const char *decode_wr16(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
fillbytes(ip, 2 + get_mem_len(ModRM));
- sprintf(IPOS, "%-7s %s,%s", ins,
- get_mem(ModRM, ip + 1, word_reg, "", seg_over), WREG);
+ sprintf(IPOS, "%-7s %s,%s", ins, get_mem(ModRM, ip + 1, word_reg, "", seg_over),
+ WREG);
return buf;
}
@@ -381,25 +363,22 @@ static const char *decode_wd8(const uint8_t *ip, const char *ins, int seg_over)
int ln = get_mem_len(ModRM);
fillbytes(ip, 3 + ln);
sprintf(IPOS, "%-7s %s,%02X", ins,
- get_mem(ModRM, ip + 1, word_reg, "WORD PTR ", seg_over),
- ip[ln + 2]);
+ get_mem(ModRM, ip + 1, word_reg, "WORD PTR ", seg_over), ip[ln + 2]);
return buf;
}
-static const char *decode_imul_b(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_imul_b(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
uint8_t d1 = ip[2 + get_mem_len(ModRM)];
fillbytes(ip, 3 + get_mem_len(ModRM));
sprintf(IPOS, "%-7s %s,%s,%c%02X", ins, WREG,
- get_mem(ModRM, ip + 1, word_reg, "", seg_over),
- d1 > 0x7F ? '-' : '+', d1 > 0x7F ? 0x100 - d1 : d1);
+ get_mem(ModRM, ip + 1, word_reg, "", seg_over), d1 > 0x7F ? '-' : '+',
+ d1 > 0x7F ? 0x100 - d1 : d1);
return buf;
}
-static const char *decode_imul_w(const uint8_t *ip, const char *ins,
- int seg_over)
+static const char *decode_imul_w(const uint8_t *ip, const char *ins, int seg_over)
{
unsigned ModRM = ip[1];
uint8_t d1 = ip[2 + get_mem_len(ModRM)];
@@ -416,8 +395,7 @@ static const char *decode_bbitd8(const uint8_t *ip, int seg_over)
int ln = get_mem_len(ModRM);
fillbytes(ip, 3 + ln);
sprintf(IPOS, "%-7s %s,%2x", table_dx[(ModRM & 0x38) >> 3],
- get_mem(ModRM, ip + 1, byte_reg, "BYTE PTR ", seg_over),
- ip[ln + 2]);
+ get_mem(ModRM, ip + 1, byte_reg, "BYTE PTR ", seg_over), ip[ln + 2]);
return buf;
}
@@ -427,8 +405,7 @@ static const char *decode_wbitd8(const uint8_t *ip, int seg_over)
int ln = get_mem_len(ModRM);
fillbytes(ip, 3 + ln);
sprintf(IPOS, "%-7s %s,%02x", table_dx[(ModRM & 0x38) >> 3],
- get_mem(ModRM, ip + 1, word_reg, "WORD PTR ", seg_over),
- ip[ln + 2]);
+ get_mem(ModRM, ip + 1, word_reg, "WORD PTR ", seg_over), ip[ln + 2]);
return buf;
}
@@ -499,7 +476,7 @@ static const char *show_io(const uint8_t *ip, const char *ins, const char *regs)
{
fillbytes(ip, 1);
strcpy(IPOS, ins);
- strcpy(IPOS+8, regs);
+ strcpy(IPOS + 8, regs);
return buf;
}
@@ -510,8 +487,7 @@ static const char *show(const uint8_t *ip, const char *ins)
return buf;
}
-static const char *show_str(const uint8_t *ip, const char *ins,
- int segment_override)
+static const char *show_str(const uint8_t *ip, const char *ins, int segment_override)
{
fillbytes(ip, 1);
int ln = strlen(seg_names[segment_override]);
diff --git a/src/dos.c b/src/dos.c
index 06a47fe..a6745ee 100644
--- a/src/dos.c
+++ b/src/dos.c
@@ -1,5 +1,5 @@
-#include "codepage.h"
#include "dos.h"
+#include "codepage.h"
#include "dbg.h"
#include "dosnames.h"
#include "emu.h"
@@ -72,7 +72,7 @@ static void init_handles(void)
handles[3] = 0; // AUX
handles[4] = 0; // PRN
// stdin,stdout,stderr: special, eof on input, is device
- for(int i=0; i<3; i++)
+ for(int i = 0; i < 3; i++)
devinfo[i] = guess_devinfo(handles[i]);
}
@@ -97,7 +97,7 @@ static int dos_close_file(int h)
handles[h] = 0;
devinfo[h] = 0;
cpuClrFlag(cpuFlag_CF);
- for(int i=0; i<max_handles; i++)
+ for(int i = 0; i < max_handles; i++)
if(handles[i] == f)
return 0; // Still referenced, don't really close
if(f == stdin || f == stdout || f == stderr)
@@ -110,7 +110,7 @@ static void create_dir(void)
{
char *fname = dos_unix_path(cpuGetAddrDS(cpuGetDX()), 1);
debug(debug_dos, "\tmkdir '%s' ", fname);
- if( 0 != mkdir(fname, 0777) )
+ if(0 != mkdir(fname, 0777))
{
free(fname);
cpuSetFlag(cpuFlag_CF);
@@ -136,7 +136,7 @@ static void remove_dir(void)
{
char *fname = dos_unix_path(cpuGetAddrDS(cpuGetDX()), 1);
debug(debug_dos, "\trmdir '%s' ", fname);
- if( 0 != rmdir(fname) )
+ if(0 != rmdir(fname))
{
free(fname);
cpuSetFlag(cpuFlag_CF);
@@ -168,7 +168,7 @@ static void dos_open_file(int create)
}
int name_addr = cpuGetAddrDS(cpuGetDX());
char *fname = dos_unix_path(name_addr, create);
- if( !memory[name_addr] || !fname)
+ if(!memory[name_addr] || !fname)
{
debug(debug_dos, "\t(file not found)\n");
cpuSetAX(2);
@@ -230,10 +230,10 @@ static void dos_open_file(int create)
devinfo[h] = 0x80C4;
else if(!strcmp(fname, "/dev/tty"))
devinfo[h] = 0x80D3;
- else if(memory[name_addr+1] == ':')
+ else if(memory[name_addr + 1] == ':')
{
uint8_t c = memory[name_addr];
- c = (c>='a') ? c-'a' : c-'A';
+ c = (c >= 'a') ? c - 'a' : c - 'A';
if(c > 26)
c = dos_get_default_drive();
devinfo[h] = 0x0000 + c;
@@ -268,11 +268,13 @@ static void dos_show_fcb()
return;
int addr = cpuGetAddrDS(cpuGetDX());
- char *name = getstr(addr+1, 11);
- debug(debug_dos,"\tFCB:"
+ char *name = getstr(addr + 1, 11);
+ debug(debug_dos,
+ "\tFCB:"
"[d=%02x:n=%.8s.%.3s:bn=%04x:rs=%04x:fs=%08x:h=%04x:rn=%02x:ra=%08x]\n",
- memory[addr], name, name+8, get16(addr+0x0C), get16(addr+0x0E),
- get32(addr+0x10),get16(addr+0x18),memory[addr+0x20],get32(addr+0x21));
+ memory[addr], name, name + 8, get16(addr + 0x0C), get16(addr + 0x0E),
+ get32(addr + 0x10), get16(addr + 0x18), memory[addr + 0x20],
+ get32(addr + 0x21));
}
static void dos_open_file_fcb(int create)
@@ -309,13 +311,13 @@ static void dos_open_file_fcb(int create)
long sz = ftell(handles[h]);
fseek(handles[h], 0, SEEK_SET);
// Set FCB info:
- put16(fcb_addr+0x0C, 0); // block number
- put16(fcb_addr+0x0E, 128); // record size
- put32(fcb_addr+0x10, sz); // file size
- put16(fcb_addr+0x14, 0); // date of last write
- put16(fcb_addr+0x16, 0); // time of last write
- put16(fcb_addr+0x18, h); // reserved - store DOS handle!
- memory[fcb_addr+0x20] = 0; // current record
+ put16(fcb_addr + 0x0C, 0); // block number
+ put16(fcb_addr + 0x0E, 128); // record size
+ put32(fcb_addr + 0x10, sz); // file size
+ put16(fcb_addr + 0x14, 0); // date of last write
+ put16(fcb_addr + 0x16, 0); // time of last write
+ put16(fcb_addr + 0x18, h); // reserved - store DOS handle!
+ memory[fcb_addr + 0x20] = 0; // current record
debug(debug_dos, "OK.\n");
cpuClrFlag(cpuFlag_CF);
@@ -348,24 +350,24 @@ static int dos_read_record_fcb(int addr, int update)
return 2; // segment wrap in DTA
}
// Seek to block and read
- if( fseek(f, pos, SEEK_SET) )
+ if(fseek(f, pos, SEEK_SET))
return 1; // no data read
// Read
unsigned n = fread(buf, 1, rsize, f);
// Update random and block positions
- if( update )
+ if(update)
{
put32(0x21 + fcb, (pos + n) / rsize);
dos_fcb_rand_to_block(fcb);
}
- if( n == rsize )
+ if(n == rsize)
return 0; // read full record
else if(!n)
return 1; // EOF
else
{
- for(unsigned i=n; i<rsize; i++)
+ for(unsigned i = n; i < rsize; i++)
buf[i] = 0;
return 3; // read partial record
}
@@ -387,28 +389,26 @@ int dos_write_record_fcb(int addr, int update)
return 2; // segment wrap in DTA
}
// Seek to block and read
- if( fseek(f, pos, SEEK_SET) )
+ if(fseek(f, pos, SEEK_SET))
return 1; // no data read
// Write
unsigned n = fwrite(buf, 1, rsize, f);
// Update random and block positions
- if( update )
+ if(update)
{
put32(0x21 + fcb, (pos + n) / rsize);
dos_fcb_rand_to_block(fcb);
}
// Update file size
- if (pos + n > get32(fcb+0x10))
- put32(fcb+0x10, pos+n);
+ if(pos + n > get32(fcb + 0x10))
+ put32(fcb + 0x10, pos + n);
- if( n == rsize )
+ if(n == rsize)
return 0; // write full record
else
return 3; // disk full
}
-
-
// Converts Unix time_t to DOS time/date
static uint32_t get_time_date(time_t tm)
{
@@ -416,8 +416,7 @@ static uint32_t get_time_date(time_t tm)
if(localtime_r(&tm, &lt))
{
unsigned t = (lt.tm_hour << 11) | (lt.tm_min << 5) | (lt.tm_sec / 2);
- unsigned d =
- ((lt.tm_year - 80) << 9) | ((lt.tm_mon + 1) << 5) | (lt.tm_mday);
+ unsigned d = ((lt.tm_year - 80) << 9) | ((lt.tm_mon + 1) << 5) | (lt.tm_mday);
return (d << 16) | t;
}
else
@@ -488,8 +487,9 @@ static void int21_43(void)
// Each DTA (Data Transfer Area) in memory can hold a find-first data
// block. We simply encode our pointer in this area and use this struct
// to hold the values.
-#define NUM_FIND_FIRST_DTA 64
-static struct find_first_dta {
+#define NUM_FIND_FIRST_DTA 64
+static struct find_first_dta
+{
// List of files to return and pointer to current.
struct dos_file_list *find_first_list;
struct dos_file_list *find_first_ptr;
@@ -549,29 +549,29 @@ static void dos_find_next(int first)
debug(debug_dos, "\t'%s' ('%s')\n", d->dosname, d->unixname);
// Fills the Find First Data from a dos/unix name pair
- if( strcmp("//", d->unixname) )
+ if(strcmp("//", d->unixname))
{
// Normal file/directory
struct stat st;
if(0 == stat(d->unixname, &st))
{
- memory[dosDTA+0x15] = get_attributes(st.st_mode);
- put32(dosDTA+0x16, get_time_date(st.st_mtime));
- put32(dosDTA+0x1A, (st.st_size > 0x7FFFFFFF) ? 0x7FFFFFFF : st.st_size);
+ memory[dosDTA + 0x15] = get_attributes(st.st_mode);
+ put32(dosDTA + 0x16, get_time_date(st.st_mtime));
+ put32(dosDTA + 0x1A, (st.st_size > 0x7FFFFFFF) ? 0x7FFFFFFF : st.st_size);
}
else
{
- memory[dosDTA+0x15] = 0;
- put32(dosDTA+0x16, 0x10001);
- put32(dosDTA+0x1A, 0);
+ memory[dosDTA + 0x15] = 0;
+ put32(dosDTA + 0x16, 0x10001);
+ put32(dosDTA + 0x1A, 0);
}
}
else
{
// Fills volume label data
- memory[dosDTA+0x15] = 8;
- put32(dosDTA+0x16, get_time_date(time(0)));
- put32(dosDTA+0x1A, 0);
+ memory[dosDTA + 0x15] = 8;
+ put32(dosDTA + 0x16, get_time_date(time(0)));
+ put32(dosDTA + 0x1A, 0);
}
// Fills dos file name
putmem(dosDTA + 0x1E, d->dosname, 13);
@@ -623,39 +623,39 @@ static void dos_find_next_fcb(void)
int pos = 1;
for(uint8_t *c = d->dosname; *c; c++)
{
- if( *c != '.' )
- memory[ofcb+pos++] = *c;
+ if(*c != '.')
+ memory[ofcb + pos++] = *c;
else
while(pos < 9)
- memory[ofcb+pos++] = ' ';
+ memory[ofcb + pos++] = ' ';
}
while(pos < 12)
- memory[ofcb+pos++] = ' ';
+ memory[ofcb + pos++] = ' ';
// Fill drive letter
memory[ofcb] = memory[get_fcb()];
// Get file info
- if( strcmp("//", d->unixname) )
+ if(strcmp("//", d->unixname))
{
// Normal file/directory
struct stat st;
if(0 == stat(d->unixname, &st))
{
- memory[ofcb+0x0C] = get_attributes(st.st_mode);
- put32(ofcb+0x17, get_time_date(st.st_mtime));
- put32(ofcb+0x1D, (st.st_size > 0x7FFFFFFF) ? 0x7FFFFFFF : st.st_size);
+ memory[ofcb + 0x0C] = get_attributes(st.st_mode);
+ put32(ofcb + 0x17, get_time_date(st.st_mtime));
+ put32(ofcb + 0x1D, (st.st_size > 0x7FFFFFFF) ? 0x7FFFFFFF : st.st_size);
}
else
{
- memory[ofcb+0x0C] = 0;
- put32(ofcb+0x17, 0x10001);
- put32(ofcb+0x1D, 0);
+ memory[ofcb + 0x0C] = 0;
+ put32(ofcb + 0x17, 0x10001);
+ put32(ofcb + 0x1D, 0);
}
}
else
{
- memory[ofcb+0x0C] = 8;
- put32(ofcb+0x17, get_time_date(time(0)));
- put32(ofcb+0x1D, 0);
+ memory[ofcb + 0x0C] = 8;
+ put32(ofcb + 0x17, get_time_date(time(0)));
+ put32(ofcb + 0x1D, 0);
}
p->find_first_ptr++;
cpuSetAL(0x00);
@@ -670,7 +670,7 @@ static void dos_find_first_fcb(void)
dos_free_file_list(p->find_first_list);
int efcb = get_ex_fcb();
- if( memory[efcb] == 0xFF && memory[efcb+6] == 0x08 )
+ if(memory[efcb] == 0xFF && memory[efcb + 6] == 0x08)
{
p->find_first_list = calloc(2, sizeof(struct dos_file_list));
p->find_first_list[0].unixname = strdup("//");
@@ -726,7 +726,7 @@ static void dos_get_drive_info(uint8_t drive)
if(!drive)
drive = dos_get_default_drive();
else
- drive --;
+ drive--;
cpuSetAL(32); // 16k clusters
cpuSetCX(512); // 512 bytes/sector
cpuSetDX(0xFFFF); // total 1GB
@@ -750,7 +750,7 @@ static void int21_9(void)
{
int i = cpuGetAddrDS(cpuGetDX());
- for(; memory[i] != 0x24 && i<0x100000; i++)
+ for(; memory[i] != 0x24 && i < 0x100000; i++)
dos_putchar(memory[i]);
cpuSetAL(0x24);
@@ -786,7 +786,7 @@ static int run_emulator(char *file, const char *prgname, char *cmdline, char *en
// Set program name
setenv(ENV_PROGNAME, prgname, 1);
// default drive
- char drv[2] = { 0, 0 };
+ char drv[2] = {0, 0};
drv[0] = dos_get_default_drive() + 'A';
setenv(ENV_DEF_DRIVE, drv, 1);
// and CWD
@@ -840,7 +840,7 @@ static void char_input(int brk)
static uint16_t last_key;
fflush(handles[1] ? handles[1] : stdout);
- if( last_key == 0 )
+ if(last_key == 0)
{
if(devinfo[0] != 0x80D3 && handles[0])
last_key = getc(handles[0]);
@@ -849,7 +849,7 @@ static void char_input(int brk)
}
debug(debug_dos, "\tgetch = %02x '%c'\n", last_key, (char)last_key);
cpuSetAL(last_key);
- if( (last_key & 0xFF) == 0 )
+ if((last_key & 0xFF) == 0)
last_key = last_key >> 8;
else
last_key = 0;
@@ -883,7 +883,7 @@ static void int21_debug(void)
};
unsigned ax = cpuGetAX();
const char *fn;
- if((ax >> 8) < (sizeof(func_names)/sizeof(func_names[0])))
+ if((ax >> 8) < (sizeof(func_names) / sizeof(func_names[0])))
fn = func_names[ax >> 8];
else
fn = "(unknown)";
@@ -907,12 +907,12 @@ void int21()
// Fix-up return address, interchanges segment/ip:
int stack = cpuGetAddress(cpuGetSS(), cpuGetSP());
put16(stack, ip);
- put16(stack+2, cs);
- put16(stack+4, flags);
+ put16(stack + 2, cs);
+ put16(stack + 4, flags);
// Call ourselves
int21();
// Restore AH
- cpuSetAX( (old_ax & 0xFF00) | (cpuGetAX() & 0xFF) );
+ cpuSetAX((old_ax & 0xFF00) | (cpuGetAX() & 0xFF));
return;
}
debug(debug_int, "D-21%04X: BX=%04X\n", cpuGetAX(), cpuGetBX());
@@ -925,7 +925,7 @@ void int21()
exit(0);
case 1: // CHARACTER INPUT WITH ECHO
char_input(1);
- dos_putchar(cpuGetAX()&0xFF);
+ dos_putchar(cpuGetAX() & 0xFF);
break;
case 2: // PUTCH
dos_putchar(cpuGetDX() & 0xFF);
@@ -954,17 +954,17 @@ void int21()
FILE *f = handles[0] ? handles[0] : stdin;
int addr = cpuGetAddrDS(cpuGetDX());
unsigned len = memory[addr], i = 2;
- while(i < len && addr+i<0x100000)
+ while(i < len && addr + i < 0x100000)
{
int c = getc(f);
if(c == '\n' || c == EOF)
c = '\r';
- memory[addr+i] = (char)c;
+ memory[addr + i] = (char)c;
if(c == '\r')
break;
i++;
}
- memory[addr+1] = i - 2;
+ memory[addr + 1] = i - 2;
break;
}
case 0xB: // STDIN STATUS
@@ -989,7 +989,7 @@ void int21()
}
break;
case 0x0E: // SELECT DEFAULT DRIVE
- dos_set_default_drive(cpuGetDX()&0xFF);
+ dos_set_default_drive(cpuGetDX() & 0xFF);
// Number of drives = 3, 'A:', 'B:' and 'C:'
cpuSetAX(0x0E03);
break;
@@ -1024,12 +1024,12 @@ void int21()
free(fname);
if(e)
{
- debug(debug_dos, "\tcould not delete file (%d).\n",errno);
+ debug(debug_dos, "\tcould not delete file (%d).\n", errno);
cpuSetAL(0xFF);
}
else
{
- memory[fcb_addr+0x1]=0xE5; // Marker for file deleted
+ memory[fcb_addr + 0x1] = 0xE5; // Marker for file deleted
cpuSetAL(0x00);
}
break;
@@ -1072,15 +1072,15 @@ void int21()
break;
case 0x26: // Create PSP (allocate segment (singleton), and copy PSP)
{
- uint8_t *new_base = getptr(cpuGetAddress(cpuGetDX(),0), 0x100);
- uint8_t *orig = getptr(cpuGetAddress(get_current_PSP(),0), 0x100);
- if (!new_base || !orig)
+ uint8_t *new_base = getptr(cpuGetAddress(cpuGetDX(), 0), 0x100);
+ uint8_t *orig = getptr(cpuGetAddress(get_current_PSP(), 0), 0x100);
+ if(!new_base || !orig)
{
debug(debug_dos, "\tinvalid new PSP segment %04x.\n", cpuGetDX());
break;
}
// Copy PSP to the new segment, 0x80 is what DOS does - this excludes command line
- memcpy(new_base,orig, 0x80);
+ memcpy(new_base, orig, 0x80);
debug(debug_dos, "\tnew PSP segment %04x.\n", cpuGetDX());
debug(debug_dos, "\tnew PSP size %02x%02x.\n", new_base[7], new_base[6]);
debug(debug_dos, "\toriginal PSP segment %04x.\n", get_current_PSP());
@@ -1098,17 +1098,17 @@ void int21()
unsigned e = 0;
int target = dosDTA;
- while( !e && count )
+ while(!e && count)
{
- if( 0x27 == (ax >> 8) )
+ if(0x27 == (ax >> 8))
e = dos_read_record_fcb(target, 1);
else
e = dos_write_record_fcb(target, 1);
- if( e == 0 || e == 3 )
+ if(e == 0 || e == 3)
{
target += rsize;
- count --;
+ count--;
}
}
cpuSetCX(cpuGetCX() - count);
@@ -1200,7 +1200,7 @@ void int21()
}
cpuSetSI((si));
cpuSetAL(ret);
- debug(debug_dos, "%c:'%.11s'\n", dst[0]?dst[0]+'@':'*',dst+1);
+ debug(debug_dos, "%c:'%.11s'\n", dst[0] ? dst[0] + '@' : '*', dst + 1);
break;
}
case 0x2A: // GET SYSTEM DATE
@@ -1255,7 +1255,7 @@ void int21()
cpuSetBX(get16(4 * (ax & 0xFF)));
cpuSetES(get16(4 * (ax & 0xFF) + 2));
break;
- case 0x36: // get free space
+ case 0x36: // get free space
cpuSetAX(32); // 16k clusters
cpuSetBX(0xFFFF); // all free, 1GB
cpuSetCX(512); // 512 bytes/sector
@@ -1364,7 +1364,7 @@ void int21()
}
if(devinfo[cpuGetBX()] == 0x80D3 && video_active())
{
- for(unsigned i=0; i<len; i++)
+ for(unsigned i = 0; i < len; i++)
video_putch(buf[i]);
cpuSetAX(len);
}
@@ -1412,7 +1412,7 @@ void int21()
else
pos = pos + (cpuGetCX() << 16);
- debug(debug_dos, "\tlseek-%02x pos = %ld\n",ax & 0xFF, pos);
+ debug(debug_dos, "\tlseek-%02x pos = %ld\n", ax & 0xFF, pos);
if(!f)
{
cpuSetFlag(cpuFlag_CF);
@@ -1448,7 +1448,8 @@ void int21()
{
int h = cpuGetBX();
int al = ax & 0xFF;
- if((al < 4 || al == 6 || al == 7 || al == 10 || al == 12 || al == 16) && !handles[h])
+ if((al < 4 || al == 6 || al == 7 || al == 10 || al == 12 || al == 16) &&
+ !handles[h])
{
// Show error if it is a file handle.
debug(debug_dos, "\t(invalid file handle)\n");
@@ -1616,7 +1617,7 @@ void int21()
debug(debug_dos, "\tload overlay '%s'\n", fname);
int pb = cpuGetAddrES(cpuGetBX());
uint16_t load_seg = get16(pb);
- uint16_t reloc_seg = get16(pb+2);
+ uint16_t reloc_seg = get16(pb + 2);
FILE *f = fopen(fname, "rb");
if(!f || dos_read_overlay(f, load_seg, reloc_seg))
{
@@ -1643,13 +1644,13 @@ void int21()
{
// Sanitize env
int eaddr = cpuGetAddress(get16(pb), 0);
- while( memory[eaddr] != 0 && eaddr < 0xFFFFF )
+ while(memory[eaddr] != 0 && eaddr < 0xFFFFF)
{
- while( memory[eaddr] != 0 && eaddr < 0xFFFFF )
- eaddr ++;
- eaddr ++;
+ while(memory[eaddr] != 0 && eaddr < 0xFFFFF)
+ eaddr++;
+ eaddr++;
}
- if( eaddr < 0xFFFFF )
+ if(eaddr < 0xFFFFF)
env = (char *)(memory + cpuGetAddress(get16(pb), 0));
}
if(run_emulator(fname, prgname, cmdline, env))
@@ -1662,8 +1663,8 @@ void int21()
}
else
{
- debug(debug_dos, "\texec '%s': type %02xh not supported.\n",
- fname, ax & 0xFF);
+ debug(debug_dos, "\texec '%s': type %02xh not supported.\n", fname,
+ ax & 0xFF);
cpuSetFlag(cpuFlag_CF);
cpuSetAX(1);
}
@@ -1746,40 +1747,40 @@ void int21()
{
case 1:
{
- static const uint8_t data[] = { 1, 38, 0, 1, 0, 181, 1 };
+ static const uint8_t data[] = {1, 38, 0, 1, 0, 181, 1};
putmem(addr, data, 7);
- putmem(addr+7, nls_country_info, 34);
+ putmem(addr + 7, nls_country_info, 34);
cpuSetCX(41);
break;
}
case 2:
memory[addr] = 2;
- put16(addr+1, nls_uppercase_table & 0xF);
- put16(addr+3, nls_uppercase_table >> 4);
+ put16(addr + 1, nls_uppercase_table & 0xF);
+ put16(addr + 3, nls_uppercase_table >> 4);
cpuSetCX(5);
break;
case 4:
memory[addr] = 4;
- put16(addr+1, nls_uppercase_table & 0xF);
- put16(addr+3, nls_uppercase_table >> 4);
+ put16(addr + 1, nls_uppercase_table & 0xF);
+ put16(addr + 3, nls_uppercase_table >> 4);
cpuSetCX(5);
break;
case 5:
memory[addr] = 5;
- put16(addr+1, nls_terminator_table & 0xF);
- put16(addr+3, nls_terminator_table >> 4);
+ put16(addr + 1, nls_terminator_table & 0xF);
+ put16(addr + 3, nls_terminator_table >> 4);
cpuSetCX(5);
break;
case 6:
memory[addr] = 6;
- put16(addr+1, nls_collating_table & 0xF);
- put16(addr+3, nls_collating_table >> 4);
+ put16(addr + 1, nls_collating_table & 0xF);
+ put16(addr + 3, nls_collating_table >> 4);
cpuSetCX(5);
break;
case 7:
memory[addr] = 7;
- put16(addr+1, nls_dbc_set_table & 0xF);
- put16(addr+3, nls_dbc_set_table >> 4);
+ put16(addr + 1, nls_dbc_set_table & 0xF);
+ put16(addr + 3, nls_dbc_set_table >> 4);
cpuSetCX(5);
break;
default:
@@ -1850,16 +1851,16 @@ static void init_nls_data(void)
};
static const uint8_t terminator_table[24] = {
0x16, 0x00, // size of table = 22 bytes
- 0x01, // ???
- 0x00, // lowest char in filename
- 0xFF, // highest char in filename
- 0x00, // ???
- 0x00, // first excluded char
- 0x20, // last excluded char (all from 00-20 excluded)
- 0x02, // ???
- 0x0E, // number of terminator characters
- 0x2E, 0x22, 0x2F, 0x5C, 0x5B, 0x5D, 0x3A, 0x7C, 0x3C, 0x3E, 0x2B, 0x3D, 0x3B, 0x2C
- };
+ 0x01, // ???
+ 0x00, // lowest char in filename
+ 0xFF, // highest char in filename
+ 0x00, // ???
+ 0x00, // first excluded char
+ 0x20, // last excluded char (all from 00-20 excluded)
+ 0x02, // ???
+ 0x0E, // number of terminator characters
+ 0x2E, 0x22, 0x2F, 0x5C, 0x5B, 0x5D, 0x3A,
+ 0x7C, 0x3C, 0x3E, 0x2B, 0x3D, 0x3B, 0x2C};
static const uint8_t fn_uppercase[16] = {
0x3C, 0x80, // CMP AL,80
0x72, 0x0B, // JB xit
@@ -1869,18 +1870,20 @@ static void init_nls_data(void)
0x2E, // CS:
0x8A, 0x87, 2, 0, // MOV AL,[BX+0002] ; offset of uppercase table
0x5B, // POP BX
- 0xCB //xit: RETF
+ 0xCB // xit: RETF
};
static uint8_t country_info[34] = {
- 1, 0,
- '$', 0, 0, 0, 0,
- ',', 0,
- '.', 0,
- '-', 0,
- ':', 0,
- 0, 2, 0,
- 0, 0, 0, 0, // Parch uppercase function address
- ',', 0,
+ 1, 0, // Date format
+ '$', 0, 0, 0, 0, // Currency symbol string
+ ',', 0, // Thousands separator
+ '.', 0, // Decimal separator
+ '-', 0, // Date separator
+ ':', 0, // Time separator
+ 0, // Currency format
+ 2, // Digits after decimal in currency
+ 0, // Time format
+ 0, 0, 0, 0, // Uppercase function address - patched in code
+ ',', 0, // Data list separator
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
@@ -1905,7 +1908,7 @@ static void init_nls_data(void)
putmem(nls_terminator_table, terminator_table, 24);
// Collating table
- nls_collating_table = get_static_memory(256+2, 0);
+ nls_collating_table = get_static_memory(256 + 2, 0);
put16(nls_collating_table, 256); // Length
putmem(nls_collating_table + 2, collating_table, 256);
@@ -1913,8 +1916,6 @@ static void init_nls_data(void)
nls_dbc_set_table = get_static_memory(4, 0);
put16(nls_dbc_set_table, 0); // Length
put16(nls_dbc_set_table, 0); // one entry at least.
-
-
}
void init_dos(int argc, char **argv)
@@ -1942,18 +1943,18 @@ void init_dos(int argc, char **argv)
// Init memory handling - available start address at 0x800,
// ending address at 0xA0000.
- mcb_init(0x80,0xA000);
+ mcb_init(0x80, 0xA000);
// Init SYSVARS
dos_sysvars = get_static_memory(128, 0);
put16(dos_sysvars + 22, 0x0080); // First MCB
// Setup default drive
- if( getenv(ENV_DEF_DRIVE) )
+ if(getenv(ENV_DEF_DRIVE))
{
char c = getenv(ENV_DEF_DRIVE)[0];
- c = (c>='a') ? c-'a' : c-'A';
- if(c>=0 && c<=25)
+ c = (c >= 'a') ? c - 'a' : c - 'A';
+ if(c >= 0 && c <= 25)
{
dos_set_default_drive(c);
debug(debug_dos, "set default drive = '%c'\n", c + 'A');
@@ -1961,7 +1962,7 @@ void init_dos(int argc, char **argv)
}
// Setup CWD
- if( getenv(ENV_CWD) )
+ if(getenv(ENV_CWD))
{
char path[64];
memset(path, 0, 64);
@@ -2000,7 +2001,7 @@ void init_dos(int argc, char **argv)
}
const char *progname = getenv(ENV_PROGNAME);
- if( !progname )
+ if(!progname)
progname = argv[0];
// Create main PSP
diff --git a/src/dos.h b/src/dos.h
index aa4f48e..0ead371 100644
--- a/src/dos.h
+++ b/src/dos.h
@@ -1,7 +1,7 @@
#pragma once
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
void init_dos(int argc, char **argv);
void int20(void);
diff --git a/src/dosnames.c b/src/dosnames.c
index de27dcc..b98b8d3 100644
--- a/src/dosnames.c
+++ b/src/dosnames.c
@@ -1,8 +1,8 @@
#define _GNU_SOURCE
-#include "dbg.h"
#include "dosnames.h"
+#include "dbg.h"
#include "emu.h"
#include "env.h"
#include <dirent.h>
@@ -21,8 +21,8 @@ static char dos_valid_char(char c)
if(c >= 'A' && c <= 'Z')
return c;
if(c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' ||
- c == '(' || c == ')' || c == '-' || c == '@' || c == '^' || c == '_' ||
- c == '{' || c == '}' || c == '~')
+ c == '(' || c == ')' || c == '-' || c == '@' || c == '^' || c == '_' || c == '{' ||
+ c == '}' || c == '~')
return c;
if(c >= 'a' && c <= 'z')
return c - 'a' + 'A';
@@ -262,7 +262,7 @@ void dos_free_file_list(struct dos_file_list *dl)
// Transforms a string to uppercase
static void str_ucase(char *str)
{
- for(;*str;str++)
+ for(; *str; str++)
if(*str >= 'a' && *str <= 'z')
*str = *str - ('a' - 'A');
}
@@ -270,7 +270,7 @@ static void str_ucase(char *str)
// Transforms a string to lowercase
static void str_lcase(char *str)
{
- for(;*str;str++)
+ for(; *str; str++)
if(*str >= 'A' && *str <= 'Z')
*str = *str + ('a' - 'A');
}
@@ -376,7 +376,7 @@ int dos_get_default_drive(void)
// Checks if char is a valid path name character
static int char_valid(unsigned char c)
{
- if(c<32 || c=='/' || c=='\\')
+ if(c < 32 || c == '/' || c == '\\')
return 0;
else
return 1;
@@ -385,7 +385,7 @@ static int char_valid(unsigned char c)
// Checks if char is a valid path separato
static int char_pathsep(unsigned char c)
{
- if(c=='/' || c=='\\')
+ if(c == '/' || c == '\\')
return 1;
else
return 0;
@@ -400,7 +400,7 @@ static int dos_path_normalize(char *path)
// Force nul terminated
path[63] = 0;
- if( path[0] && path[1] == ':' )
+ if(path[0] && path[1] == ':')
{
drive = path[0];
if(drive >= 'A' && drive <= 'Z')
@@ -409,20 +409,20 @@ static int dos_path_normalize(char *path)
drive = drive - 'a';
else
drive = dos_default_drive;
- memmove(path, path+2,62);
+ memmove(path, path + 2, 62);
path[62] = path[63] = 0;
}
// Copy CWD to base
char base[64];
- memcpy(base,dos_cwd[drive],64);
+ memcpy(base, dos_cwd[drive], 64);
// Test for absolute path
if(path[0] == '\\' || path[0] == '/')
- memset(base,0,64);
+ memset(base, 0, 64);
// Process each component of path
int beg, end = 0;
- while(end<63 && path[end])
+ while(end < 63 && path[end])
{
beg = end;
while(char_valid(path[end]))
@@ -430,33 +430,33 @@ static int dos_path_normalize(char *path)
if(path[end] && !char_pathsep(path[end]))
break;
- if(!path[end] && end<63)
- path[end+1] = 0;
+ if(!path[end] && end < 63)
+ path[end + 1] = 0;
// Test path
path[end] = 0;
- if(!strcmp(&path[beg],".."))
+ if(!strcmp(&path[beg], ".."))
{
// Up a directory
int e = strlen(base) - 1;
- while(e>=0 && !char_pathsep(base[e]))
+ while(e >= 0 && !char_pathsep(base[e]))
e--;
- while(e>=0 && char_pathsep(base[e]))
+ while(e >= 0 && char_pathsep(base[e]))
e--;
- base[e+1] = 0;
+ base[e + 1] = 0;
}
- else if(path[beg] && strcmp(&path[beg],"."))
+ else if(path[beg] && strcmp(&path[beg], "."))
{
// Standard path, add to base
int e = strlen(base);
- if(e<63)
+ if(e < 63)
{
if(e)
{
base[e] = '\\';
e++;
}
- while(e<62 && path[beg])
+ while(e < 62 && path[beg])
{
base[e] = path[beg];
e++;
@@ -477,7 +477,7 @@ static const char *get_base_path(int drive)
{
char env[15] = ENV_DRIVE "\0\0";
env[strlen(env)] = drive + 'A';
- char * base = getenv(env);
+ char *base = getenv(env);
if(!base)
return ".";
return base;
@@ -485,7 +485,7 @@ static const char *get_base_path(int drive)
const uint8_t *dos_get_cwd(int drive)
{
- drive = drive?drive-1:dos_default_drive;
+ drive = drive ? drive - 1 : dos_default_drive;
return dos_cwd[drive];
}
@@ -511,7 +511,7 @@ int dos_change_cwd(char *path)
// changes CWD
int dos_change_dir(int addr)
{
- return dos_change_cwd(getstr(addr,63));
+ return dos_change_cwd(getstr(addr, 63));
}
// Converts a DOS full path to equivalent Unix filename
@@ -520,9 +520,9 @@ char *dos_unix_path(int addr, int force)
char *path = getstr(addr, 63);
debug(debug_dos, "\tconvert dos path '%s'\n", path);
// Check for standard paths:
- if( *path && (!strcasecmp(path, "NUL") || !strcasecmp(path+1,":NUL")) )
+ if(*path && (!strcasecmp(path, "NUL") || !strcasecmp(path + 1, ":NUL")))
return strdup("/dev/null");
- if( *path && (!strcasecmp(path, "CON") || !strcasecmp(path+1,":CON")) )
+ if(*path && (!strcasecmp(path, "CON") || !strcasecmp(path + 1, ":CON")))
return strdup("/dev/tty");
// Normalize
int drive = dos_path_normalize(path);
@@ -538,12 +538,12 @@ char *dos_unix_path_fcb(int addr, int force)
int opos = 0;
// Copy drive number from the FCB structure:
int drive = memory[addr] & 0xFF;
- if( !drive )
+ if(!drive)
drive = dos_default_drive;
else
drive = drive - 1;
// And copy file name
- char *fcb_name = getstr(addr+1, 11);
+ char *fcb_name = getstr(addr + 1, 11);
debug(debug_dos, "\tconvert dos fcb name %c:'%s'\n", drive + 'A', fcb_name);
// Build complete path, copy current directory and add FCB file name
@@ -551,17 +551,17 @@ char *dos_unix_path_fcb(int addr, int force)
memcpy(path, dos_cwd[drive], 64);
opos = strlen(path);
- for(int pos=0; pos<8 && opos<63; pos++, opos++)
- if( fcb_name[pos] == '?' )
+ for(int pos = 0; pos < 8 && opos < 63; pos++, opos++)
+ if(fcb_name[pos] == '?')
path[opos] = '?';
- else if( 0 == (path[opos] = dos_valid_char(fcb_name[pos])) )
+ else if(0 == (path[opos] = dos_valid_char(fcb_name[pos])))
break;
- if(opos<63 && (dos_valid_char(fcb_name[8]) || fcb_name[8] == '?') )
+ if(opos < 63 && (dos_valid_char(fcb_name[8]) || fcb_name[8] == '?'))
path[opos++] = '.';
- for(int pos=8; pos<11 && opos<63; pos++, opos++)
- if( fcb_name[pos] == '?' )
+ for(int pos = 8; pos < 11 && opos < 63; pos++, opos++)
+ if(fcb_name[pos] == '?')
path[opos] = '?';
- else if( 0 == (path[opos] = dos_valid_char(fcb_name[pos])) )
+ else if(0 == (path[opos] = dos_valid_char(fcb_name[pos])))
break;
path[opos] = 0;
@@ -572,7 +572,6 @@ char *dos_unix_path_fcb(int addr, int force)
return dos_unix_path_rec(base, path, force);
}
-
////////////////////////////////////////////////////////////////////
// Implements FindFirstFile
// NOTE: this frees fspec before return
diff --git a/src/emu.h b/src/emu.h
index 4963267..7397d5e 100644
--- a/src/emu.h
+++ b/src/emu.h
@@ -94,7 +94,7 @@ static inline void put16(int addr, int v)
static inline void put32(int addr, unsigned v)
{
put16(addr, v & 0xFFFF);
- put16(addr+2, v >> 16);
+ put16(addr + 2, v >> 16);
}
// Write 16 bit number
@@ -106,7 +106,7 @@ static inline int get16(int addr)
// Write 32 bit number
static inline unsigned get32(int addr)
{
- return get16(addr) + (get16(addr+2) << 16);
+ return get16(addr) + (get16(addr + 2) << 16);
}
// Copy data to CPU memory
diff --git a/src/keyb.c b/src/keyb.c
index abafd8b..0b4d0f5 100644
--- a/src/keyb.c
+++ b/src/keyb.c
@@ -1,7 +1,7 @@
#include "keyb.h"
+#include "codepage.h"
#include "dbg.h"
#include "emu.h"
-#include "codepage.h"
#include <errno.h>
#include <fcntl.h>
@@ -235,7 +235,7 @@ static int get_esc_secuence(void)
{
if(n1 == 0 && n2 == 0)
return alt_char(ch); // it is an ALT+'[' or ALT+'O'
- return 0; // ERROR!
+ return 0; // ERROR!
}
if(cn >= '0' && cn <= '9')
n2 = n2 * 10 + (cn - '0');
@@ -338,8 +338,7 @@ static int read_key(void)
if(read(tty_fd, &ch1, 1) == 0 || (ch1 & 0xC0) != 0x80 ||
read(tty_fd, &ch2, 1) == 0 || (ch2 & 0xC0) != 0x80)
return -1; // INVALID UTF-8
- return get_dos_char(((ch & 0x0F) << 12) | ((ch1 & 0x3F) << 6) |
- (ch2 & 0x3F));
+ return get_dos_char(((ch & 0x0F) << 12) | ((ch1 & 0x3F) << 6) | (ch2 & 0x3F));
}
else if((ch & 0xF8) == 0xF0)
{
@@ -417,7 +416,7 @@ int getch(int detect_brk)
int ret;
while(queued_key == -1)
{
- if( kbhit() )
+ if(kbhit())
break;
usleep(1000000);
waiting_key = 1;
diff --git a/src/loader.c b/src/loader.c
index 0e29de2..1d8225f 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -1,10 +1,10 @@
#include "loader.h"
#include "dbg.h"
#include "emu.h"
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
// Main Memory (17 * 64K, no overlap)
uint8_t memory[0x110000];
@@ -15,19 +15,22 @@ uint8_t mcb_alloc_st = 0;
// PSP (Program Segment Prefix) location
uint16_t current_PSP;
+// MS-DOS version to emulate on FCB command line parsing.
#define FCB_PARSE_DOS (3)
-int valid_fcb_sep(int i)
+static int valid_fcb_sep(int i)
{
- return isspace(i) || i == ',' || i=='=' || i==';';
+ return isspace(i) || i == ',' || i == '=' || i == ';';
}
-int valid_fcb_char(int i)
+static int valid_fcb_char(int i)
{
return isalnum(i) || (i > 127 && i < 229) || (i > 229) ||
- (i == '\\' && FCB_PARSE_DOS == 1) || strchr("!#$%&'()-@^_`{}~?<>", i);
+ (i == '\\' && FCB_PARSE_DOS == 1) ||
+ strchr("!#$%&'()-@^_`{}~?<>", i);
}
+// The FCB parsing states.
#define FCB_PARSE_INIT 0
#define FCB_PARSE_INIT_PLUS 10
#define FCB_PARSE_FCB1 1
@@ -39,7 +42,8 @@ int valid_fcb_char(int i)
#define FCB_PARSE_FCB2_EXT 5
#define FCB_PARSE_EXIT 6
-void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
+static void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2)
+{
int i = 0;
int state = FCB_PARSE_INIT;
uint8_t *offset = fcb1 + 1;
@@ -47,57 +51,77 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
*fcb2 = 0;
memset(fcb1 + 1, ' ', 11);
memset(fcb2 + 1, ' ', 11);
- while (cmd_line[i]) {
- int c=cmd_line[i];
- if(FCB_PARSE_DOS == 1 && c==';') {
- c='+';
+ while(cmd_line[i])
+ {
+ int c = cmd_line[i];
+ if(FCB_PARSE_DOS == 1 && c == ';')
+ {
+ c = '+';
}
- switch (state) {
+ switch(state)
+ {
case FCB_PARSE_INIT:
case FCB_PARSE_INIT_PLUS:
- switch (c) {
+ switch(c)
+ {
case '.':
offset = fcb1 + 9;
state = FCB_PARSE_FCB1_EXT;
break;
case '+':
- if (state == FCB_PARSE_INIT) {
+ if(state == FCB_PARSE_INIT)
+ {
state = FCB_PARSE_INIT_PLUS;
- } else {
+ }
+ else
+ {
offset = fcb2 + 1;
- state = (FCB_PARSE_DOS == 1)?FCB_PARSE_SEP:FCB_PARSE_SEP_PURGE;
+ state = (FCB_PARSE_DOS == 1) ? FCB_PARSE_SEP
+ : FCB_PARSE_SEP_PURGE;
}
break;
case '*':
- for (int j = 0; j < 8; j++) {
+ for(int j = 0; j < 8; j++)
+ {
fcb1[j + 1] = '?';
}
offset = fcb1 + 9;
break;
default:
- if (valid_fcb_sep(c)) {
- if(FCB_PARSE_DOS > 1 && state == FCB_PARSE_INIT_PLUS
- && (FCB_PARSE_DOS>2 || !isspace(c))) {
+ if(valid_fcb_sep(c))
+ {
+ if(FCB_PARSE_DOS > 1 && state == FCB_PARSE_INIT_PLUS &&
+ (FCB_PARSE_DOS > 2 || !isspace(c)))
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PURGE;
i--;
}
break;
}
- if (valid_fcb_char(c)) {
- if (cmd_line[i + 1] == ':') {
+ if(valid_fcb_char(c))
+ {
+ if(cmd_line[i + 1] == ':')
+ {
*fcb1 = toupper(c) - 'A' + 1;
i++;
- } else {
+ }
+ else
+ {
*offset = toupper(c);
offset++;
}
state = FCB_PARSE_FCB1;
- } else {
- if(FCB_PARSE_DOS == 1) {
+ }
+ else
+ {
+ if(FCB_PARSE_DOS == 1)
+ {
state = FCB_PARSE_EXIT;
- } else {
- offset = fcb2 +1;
+ }
+ else
+ {
+ offset = fcb2 + 1;
state = FCB_PARSE_SEP_PURGE;
}
}
@@ -105,48 +129,56 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
}
break;
case FCB_PARSE_FCB1:
- switch (c) {
+ switch(c)
+ {
case '.':
offset = fcb1 + 9;
state = FCB_PARSE_FCB1_EXT;
break;
case '*':
- while (offset - fcb1 - 1 < 8) {
+ while(offset - fcb1 - 1 < 8)
+ {
*offset = '?';
offset++;
}
break;
case '+':
- if (FCB_PARSE_DOS == 1)
+ if(FCB_PARSE_DOS == 1)
{
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PLUS;
break;
}
case ':':
- if (FCB_PARSE_DOS == 1)
+ if(FCB_PARSE_DOS == 1)
{
offset = fcb2 + 1;
state = FCB_PARSE_FCB2;
break;
}
default:
- if (valid_fcb_sep(c)) {
+ if(valid_fcb_sep(c))
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP;
break;
}
- if (!valid_fcb_char(c)) {
+ if(!valid_fcb_char(c))
+ {
offset = fcb2 + 1;
- if(FCB_PARSE_DOS == 1) {
+ if(FCB_PARSE_DOS == 1)
+ {
state = FCB_PARSE_EXIT;
- } else {
+ }
+ else
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PURGE;
}
break;
}
- if (offset - fcb1 - 1 < 8) {
+ if(offset - fcb1 - 1 < 8)
+ {
*offset = toupper(c);
offset++;
}
@@ -154,52 +186,63 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
}
break;
case FCB_PARSE_FCB1_EXT:
- switch (c) {
+ switch(c)
+ {
case '.':
- if(FCB_PARSE_DOS == 1) {
+ if(FCB_PARSE_DOS == 1)
+ {
offset = fcb2 + 9;
state = FCB_PARSE_FCB2_EXT;
- } else {
+ }
+ else
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PURGE;
}
break;
case '*':
- while (offset - fcb1 - 9 < 3) {
+ while(offset - fcb1 - 9 < 3)
+ {
*offset = '?';
offset++;
}
break;
case '+':
- if (FCB_PARSE_DOS == 1)
+ if(FCB_PARSE_DOS == 1)
{
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PLUS;
break;
}
case ':':
- if (FCB_PARSE_DOS == 1)
+ if(FCB_PARSE_DOS == 1)
{
offset = fcb2 + 1;
state = FCB_PARSE_FCB2;
break;
}
default:
- if (valid_fcb_sep(c)) {
+ if(valid_fcb_sep(c))
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP;
break;
}
- if (!valid_fcb_char(c)) {
- if(FCB_PARSE_DOS == 1) {
+ if(!valid_fcb_char(c))
+ {
+ if(FCB_PARSE_DOS == 1)
+ {
state = FCB_PARSE_EXIT;
- } else {
+ }
+ else
+ {
offset = fcb2 + 1;
state = FCB_PARSE_SEP_PURGE;
}
break;
}
- if (offset - fcb1 - 9 < 3) {
+ if(offset - fcb1 - 9 < 3)
+ {
*offset = toupper(c);
offset++;
}
@@ -207,7 +250,8 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
}
break;
case FCB_PARSE_SEP_PURGE:
- if (valid_fcb_sep(c)) {
+ if(valid_fcb_sep(c))
+ {
state = FCB_PARSE_SEP;
i--;
break;
@@ -215,53 +259,68 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
break;
case 3:
case 13:
- switch (c) {
+ switch(c)
+ {
case '.':
offset = fcb2 + 9;
state = FCB_PARSE_FCB2_EXT;
break;
case '+':
- if (state == FCB_PARSE_SEP) {
+ if(state == FCB_PARSE_SEP)
+ {
state = FCB_PARSE_SEP_PLUS;
- } else {
- state = FCB_PARSE_EXIT;
+ }
+ else
+ {
+ state = FCB_PARSE_EXIT;
}
break;
case '*':
- for (int j = 0; j < 8; j++) {
+ for(int j = 0; j < 8; j++)
+ {
fcb2[j + 1] = '?';
}
break;
default:
- if (valid_fcb_sep(c)) {
- if(FCB_PARSE_DOS > 2 && state == FCB_PARSE_SEP_PLUS) {
+ if(valid_fcb_sep(c))
+ {
+ if(FCB_PARSE_DOS > 2 && state == FCB_PARSE_SEP_PLUS)
+ {
state = FCB_PARSE_EXIT;
}
break;
}
- if (valid_fcb_char(c)) {
- if (cmd_line[i + 1] == ':') {
+ if(valid_fcb_char(c))
+ {
+ if(cmd_line[i + 1] == ':')
+ {
*fcb2 = toupper(c) - 'A' + 1;
i++;
- } else {
+ }
+ else
+ {
*offset = toupper(c);
offset++;
}
state = FCB_PARSE_FCB2;
- } else {
+ }
+ else
+ {
state = FCB_PARSE_EXIT;
}
break;
}
break;
case FCB_PARSE_FCB2:
- switch (c) {
+ switch(c)
+ {
case '.':
offset = fcb2 + 9;
state = FCB_PARSE_FCB2_EXT;
break;
case '*':
- while (offset - fcb2 - 1 < 8) {
+ while(offset - fcb2 - 1 < 8)
+ {
*offset = '?';
offset++;
}
@@ -272,15 +331,18 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
state = FCB_PARSE_EXIT;
break;
default:
- if (valid_fcb_sep(c)) {
+ if(valid_fcb_sep(c))
+ {
state = FCB_PARSE_EXIT;
break;
}
- if (!valid_fcb_char(c)) {
+ if(!valid_fcb_char(c))
+ {
state = FCB_PARSE_EXIT;
break;
}
- if (offset - fcb2 - 1 < 8) {
+ if(offset - fcb2 - 1 < 8)
+ {
*offset = toupper(c);
offset++;
}
@@ -288,9 +350,11 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
}
break;
case FCB_PARSE_FCB2_EXT:
- switch (c) {
+ switch(c)
+ {
case '*':
- while (offset - fcb2 - 9 < 3) {
+ while(offset - fcb2 - 9 < 3)
+ {
*offset = '?';
offset++;
}
@@ -303,15 +367,18 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
state = FCB_PARSE_EXIT;
break;
default:
- if (valid_fcb_sep(c)) {
+ if(valid_fcb_sep(c))
+ {
state = FCB_PARSE_EXIT;
break;
}
- if (!valid_fcb_char(c)) {
+ if(!valid_fcb_char(c))
+ {
state = FCB_PARSE_EXIT;
break;
}
- if (offset - fcb2 - 9 < 3) {
+ if(offset - fcb2 - 9 < 3)
+ {
*offset = toupper(c);
offset++;
}
@@ -321,7 +388,8 @@ void cmdline_to_fcb(const char *cmd_line, uint8_t *fcb1, uint8_t *fcb2) {
default:
break;
}
- if (state == FCB_PARSE_EXIT) {
+ if(state == FCB_PARSE_EXIT)
+ {
break;
}
i++;
@@ -550,8 +618,8 @@ Offset Length Description
81h 127 Command line string */
// Creates main PSP
-uint16_t create_PSP(const char *cmdline, const char *environment,
- int env_size, const char *progname)
+uint16_t create_PSP(const char *cmdline, const char *environment, int env_size,
+ const char *progname)
{
// Put environment before PSP and program name, use rounded up environment size:
int max;
@@ -589,7 +657,7 @@ uint16_t create_PSP(const char *cmdline, const char *environment,
uint8_t *dosPSP = memory + psp_seg * 16;
memset(dosPSP, 0, 256);
- dosPSP[0] = 0xCD; // 00: int20
+ dosPSP[0] = 0xCD; // 00: int20
dosPSP[1] = 0x20;
dosPSP[2] = 0x00; // 02: memory end segment
dosPSP[3] = 0x00; //
@@ -606,7 +674,7 @@ uint16_t create_PSP(const char *cmdline, const char *environment,
unsigned l = strlen(cmdline);
if(l > 126)
l = 126;
- dosPSP[128] = l; // 80: Cmd line len
+ dosPSP[128] = l; // 80: Cmd line len
memcpy(dosPSP + 129, cmdline, l);
dosPSP[129 + l] = 0x00d; // Adds an ENTER at the end
// Copy environment:
@@ -621,7 +689,7 @@ uint16_t create_PSP(const char *cmdline, const char *environment,
l = 63;
memcpy(memory + env_seg * 16 + env_size + 2, progname, l);
}
- cmdline_to_fcb(cmdline,dosPSP+0x5C,dosPSP+0x6C);
+ cmdline_to_fcb(cmdline, dosPSP + 0x5C, dosPSP + 0x6C);
return psp_mcb;
}
@@ -738,7 +806,7 @@ int dos_load_exe(FILE *f, uint16_t psp_mcb)
// An EXE file, read rest of blocks
int head_size = g16(buf + 8) * 16;
int data_blocks = g16(buf + 4);
- if(data_blocks&0xF800)
+ if(data_blocks & 0xF800)
{
debug(debug_dos, "\tinvalid number of blocks ($%04x), fixing.\n",
data_blocks);
@@ -758,7 +826,7 @@ int dos_load_exe(FILE *f, uint16_t psp_mcb)
max_sz = 0xFFFF;
// Try to resize PSP MCB
- int psp_sz =mcb_resize(psp_mcb, max_sz);
+ int psp_sz = mcb_resize(psp_mcb, max_sz);
if(psp_sz < min_sz && psp_sz < max_sz)
{
debug(debug_dos, "\texe read, not enough memory!\n");
diff --git a/src/loader.h b/src/loader.h
index 523d112..6f5bfa1 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -1,7 +1,7 @@
#pragma once
-#include <stdio.h>
#include <stdint.h>
+#include <stdio.h>
// EXE loader
uint16_t create_PSP(const char *cmdline, const char *environment, int env_size,
diff --git a/src/main.c b/src/main.c
index 0a6ada3..9bc5b09 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,9 +68,7 @@ static void int12(void)
}
// Network access, ignored.
-static void int2a(void)
-{
-}
+static void int2a(void) {}
// System Reset
static void int19(void)
@@ -142,8 +140,7 @@ static void check_exit_mem(void)
{
if(chk_mem_arr[i] != memory[i])
{
- fprintf(stderr,
- "%s: check memory: differ at byte %X, %02X != %02X\n",
+ fprintf(stderr, "%s: check memory: differ at byte %X, %02X != %02X\n",
prog_name, i, chk_mem_arr[i], memory[i]);
break;
}
@@ -239,8 +236,7 @@ int main(int argc, char **argv)
break;
case 'r':
bin_load_seg = strtol(opt, &ep, 0);
- if((*ep != 0 && *ep != ':') || bin_load_seg < 0 ||
- bin_load_seg > 0xFFFF)
+ if((*ep != 0 && *ep != ':') || bin_load_seg < 0 || bin_load_seg > 0xFFFF)
print_usage_error("binary run segment '%s' invalid.", opt);
if(*ep == 0)
{
@@ -263,8 +259,7 @@ int main(int argc, char **argv)
{
chk_mem_arr = malloc(1024 * 1024);
chk_mem_len = fread(chk_mem_arr, 1, 1024 * 1024, cf);
- fprintf(stderr, "%s: will check %X bytes.\n", argv[0],
- chk_mem_len);
+ fprintf(stderr, "%s: will check %X bytes.\n", argv[0], chk_mem_len);
atexit(check_exit_mem);
}
}
diff --git a/src/timer.c b/src/timer.c
index a8a2703..402b53b 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -1,6 +1,6 @@
-#include "dbg.h"
#include "timer.h"
+#include "dbg.h"
#include "emu.h"
#include <math.h>
@@ -18,8 +18,7 @@ void update_timer(void)
if(start_day == 0)
start_day = (tv.tv_sec - tz.tz_minuteswest * 60) / (24 * 60 * 60);
- int isec =
- (tv.tv_sec - tz.tz_minuteswest * 60) - (24 * 60 * 60) * start_day;
+ int isec = (tv.tv_sec - tz.tz_minuteswest * 60) - (24 * 60 * 60) * start_day;
long cnt = lrint((isec + tv.tv_usec * 0.000001) * 19663.0 / 1080.0);
bios_timer = cnt % 0x1800B0;
@@ -38,7 +37,7 @@ static uint16_t get_port_timer(void)
// Convert to "counts
us = us * 1.19317997037;
// And return "low part"
- return (lrint(fmod(us,16777216.0)) & 0xFFFF);
+ return (lrint(fmod(us, 16777216.0)) & 0xFFFF);
}
uint32_t get_bios_timer(void)
@@ -48,7 +47,7 @@ uint32_t get_bios_timer(void)
// Implement reading/writing to timer ports
static uint16_t port_value;
-static uint8_t port_control;
+static uint8_t port_control;
uint8_t port_timer_read(uint16_t port)
{
if(port == 0x43)
@@ -56,27 +55,27 @@ uint8_t port_timer_read(uint16_t port)
int tag = port_control & 0x30;
if(tag == 0x20)
{
- debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n",
- port, port_value >> 8, port_control);
+ debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n", port,
+ port_value >> 8, port_control);
return port_value >> 8;
}
else if(tag == 0x10)
{
- debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n",
- port, port_value & 0xFF, port_control);
+ debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n", port,
+ port_value & 0xFF, port_control);
return port_value;
}
else if(tag == 0x30)
{
- debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n",
- port, port_value & 0xFF, port_control);
+ debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n", port,
+ port_value & 0xFF, port_control);
port_control &= 0xCF;
return port_value;
}
else // (tag == 0x00)
{
- debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n",
- port, port_value >> 8, port_control);
+ debug(debug_int, "timer port read $%02x = %02x (control=%02x)\n", port,
+ port_value >> 8, port_control);
port_control |= 0x30;
return port_value >> 8;
}
@@ -91,8 +90,9 @@ void port_timer_write(uint16_t port, uint8_t val)
if(0x00 == (port_control & 0x30))
port_control |= 0x30;
port_value = get_port_timer() - last_timer;
- debug(debug_int, "timer port write $%02x = %02x (latched val=%04x control=%02x)\n",
- port, val, port_value, port_control);
+ debug(debug_int,
+ "timer port write $%02x = %02x (latched val=%04x control=%02x)\n", port,
+ val, port_value, port_control);
}
else if(port == 0x40)
{
@@ -116,8 +116,9 @@ void port_timer_write(uint16_t port, uint8_t val)
port_value = port_value | (val << 8);
last_timer = get_port_timer() + port_value;
}
- debug(debug_int, "timer port write $%02x = %02x (last=%04x val=%04x control=%02x)\n",
- port, val, last_timer, port_value, port_control);
+ debug(debug_int,
+ "timer port write $%02x = %02x (last=%04x val=%04x control=%02x)\n", port,
+ val, last_timer, port_value, port_control);
}
}
diff --git a/src/timer.h b/src/timer.h
index 3dfa5c8..f6dc952 100644
--- a/src/timer.h
+++ b/src/timer.h
@@ -8,4 +8,3 @@ uint32_t get_bios_timer(void);
void int1A(void);
uint8_t port_timer_read(uint16_t port);
void port_timer_write(uint16_t port, uint8_t val);
-
diff --git a/src/utils.c b/src/utils.c
index 3a17b65..138029a 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -11,7 +11,9 @@ const char *get_program_exe_path(void)
{
#if defined(__linux__) || defined(__CYGWIN__)
- static char exe_path[4096] = {0,};
+ static char exe_path[4096] = {
+ 0,
+ };
if(readlink("/proc/self/exe", exe_path, 4095) == -1)
return 0;
else
@@ -19,8 +21,10 @@ const char *get_program_exe_path(void)
#elif defined(__APPLE__)
- static char exe_path[4096] = {0,};
- uint32_t length=4095;
+ static char exe_path[4096] = {
+ 0,
+ };
+ uint32_t length = 4095;
if(_NSGetExecutablePath(exe_path, &length))
return 0;
else
@@ -32,4 +36,3 @@ const char *get_program_exe_path(void)
#endif
}
-
diff --git a/src/utils.h b/src/utils.h
index ea4c413..c6762d2 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -3,5 +3,3 @@
/* Returns the full path to the program executable */
const char *get_program_exe_path(void);
-
-
diff --git a/src/video.c b/src/video.c
index bfeb6e2..703b159 100644
--- a/src/video.c
+++ b/src/video.c
@@ -1,7 +1,7 @@
#include "video.h"
+#include "codepage.h"
#include "dbg.h"
#include "emu.h"
-#include "codepage.h"
#include <errno.h>
#include <fcntl.h>
@@ -147,18 +147,18 @@ static void init_video(void)
print_error("error at open TTY, %s\n", strerror(errno));
exit(1);
}
- tty_file = fdopen(tty_fd,"w");
+ tty_file = fdopen(tty_fd, "w");
atexit(exit_video);
video_initialized = 1;
// Fill the functionality table
- memory[0xC0100] = 0x08; // Only mode 3 supported
+ memory[0xC0100] = 0x08; // Only mode 3 supported
memory[0xC0101] = 0x00;
memory[0xC0102] = 0x00;
- memory[0xC0107] = 0x07; // Support 300, 350 and 400 scanlines
- memory[0xC0108] = 0x00; // Active character blocks?
- memory[0xC0109] = 0x00; // MAximum character blocks?
- memory[0xC0108] = 0xFF; // Support functions
+ memory[0xC0107] = 0x07; // Support 300, 350 and 400 scanlines
+ memory[0xC0108] = 0x00; // Active character blocks?
+ memory[0xC0109] = 0x00; // MAximum character blocks?
+ memory[0xC0108] = 0xFF; // Support functions
// Set video mode
set_text_mode(1);
@@ -179,7 +179,7 @@ static void set_color(uint8_t c)
{
static char cn[8] = "04261537";
fprintf(tty_file, "\x1b[%c;3%c;4%cm", (c & 0x08) ? '1' : '0', cn[c & 7],
- cn[(c >> 4) & 7]);
+ cn[(c >> 4) & 7]);
term_color = c;
}
}
@@ -303,11 +303,9 @@ void check_screen(void)
fflush(tty_file);
}
-static void vid_scroll_up(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
- int n)
+static void vid_scroll_up(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, int n)
{
- debug(debug_video, "scroll up %d: (%d, %d) - (%d, %d)\n", n,
- x0, y0, x1, y1);
+ debug(debug_video, "scroll up %d: (%d, %d) - (%d, %d)\n", n, x0, y0, x1, y1);
// Check parameters
if(x1 >= vid_sx)
@@ -348,11 +346,9 @@ static void vid_scroll_up(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
vm[x + y * vid_sx] = (vid_color << 8) + 0x20;
}
-static void vid_scroll_dwn(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
- unsigned n)
+static void vid_scroll_dwn(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, unsigned n)
{
- debug(debug_video, "scroll down %d: (%d, %d) - (%d, %d)\n", n,
- x0, y0, x1, y1);
+ debug(debug_video, "scroll down %d: (%d, %d) - (%d, %d)\n", n, x0, y0, x1, y1);
// Check parameters
if(x1 >= vid_sx)
@@ -405,7 +401,7 @@ static void video_putchar(uint8_t ch, uint16_t at)
else if(ch == 0x08)
{
if(vid_posx > 0)
- vid_posx --;
+ vid_posx--;
}
else
{
@@ -497,14 +493,14 @@ void int10()
uint16_t px = vid_posx;
uint16_t py = vid_posy;
vid_color = cpuGetBX() & 0xFF;
- for(int i = cpuGetCX(); i>0; i--)
+ for(int i = cpuGetCX(); i > 0; i--)
{
set_xy(px, py, (ax & 0xFF) + (vid_color << 8), 0);
- px ++;
+ px++;
if(px >= vid_sx)
{
px = 0;
- py ++;
+ py++;
if(py >= vid_sy)
py = 0;
}
@@ -536,7 +532,7 @@ void int10()
// Clear end-of-screen
unsigned max = get_last_used_row();
debug(debug_video, "set 25 lines mode %d\n", max);
- if (max > 25)
+ if(max > 25)
{
term_goto_xy(0, 24);
set_color(0x07);
@@ -544,7 +540,7 @@ void int10()
for(int y = 25; y < 64; y++)
for(int x = 0; x < 256; x++)
term_screen[y][x] = 0x0720;
- if (output_row > 24)
+ if(output_row > 24)
output_row = 24;
}
// Set 8x16 font - 80x25 mode:
@@ -558,7 +554,7 @@ void int10()
debug(debug_video, "set 43/50 lines mode\n");
// Hack - QBASIC.EXE assumes that the mode is always 50 lines on VGA,
// and *sets* the height into the BIOS area!
- if(memory[0x484]>42)
+ if(memory[0x484] > 42)
vid_sy = 50;
else
vid_sy = 43;
@@ -567,62 +563,62 @@ void int10()
}
break;
case 0x12: // ALT FUNCTION SELECT
+ {
+ int bl = cpuGetBX() & 0xFF;
+ if(bl == 0x10) // GET EGA INFO
{
- int bl = cpuGetBX() & 0xFF;
- if(bl == 0x10 ) // GET EGA INFO
- {
- cpuSetBX(0x0003);
- cpuSetCX(0x0000);
- cpuSetAX(0);
- }
- else if(bl == 0x30 ) // SET VERTICAL RESOLUTION
- {
- // TODO: select 25/28 lines
- cpuSetAX(0x1212);
- }
- else
- debug(debug_video, "UNHANDLED INT 10, AH=12 BL=%02x\n", bl);
+ cpuSetBX(0x0003);
+ cpuSetCX(0x0000);
+ cpuSetAX(0);
}
- break;
+ else if(bl == 0x30) // SET VERTICAL RESOLUTION
+ {
+ // TODO: select 25/28 lines
+ cpuSetAX(0x1212);
+ }
+ else
+ debug(debug_video, "UNHANDLED INT 10, AH=12 BL=%02x\n", bl);
+ }
+ break;
case 0x13: // WRITE STRING
+ {
+ vid_posx = cpuGetDX() & 0xFF;
+ vid_posy = cpuGetDX() >> 8;
+ if(vid_posx >= vid_sx)
+ vid_posx = vid_sx - 1;
+ if(vid_posy >= vid_sy)
+ vid_posy = vid_sy - 1;
+ int save_posx = vid_posx;
+ int save_posy = vid_posy;
+ int addr = cpuGetAddrES(cpuGetBP());
+ int cnt = cpuGetCX();
+ if(ax & 2)
{
- vid_posx = cpuGetDX() & 0xFF;
- vid_posy = cpuGetDX() >> 8;
- if(vid_posx >= vid_sx)
- vid_posx = vid_sx - 1;
- if(vid_posy >= vid_sy)
- vid_posy = vid_sy - 1;
- int save_posx = vid_posx;
- int save_posy = vid_posy;
- int addr = cpuGetAddrES(cpuGetBP());
- int cnt = cpuGetCX();
- if(ax&2)
- {
- while(cnt && addr < 0xFFFFF)
- {
- video_putchar(memory[addr], memory[addr+1]);
- addr += 2;
- cnt --;
- }
- }
- else
+ while(cnt && addr < 0xFFFFF)
{
- uint8_t at = cpuGetBX() >> 8;
- while(cnt && addr <= 0xFFFFF)
- {
- video_putchar(memory[addr], at);
- addr ++;
- cnt --;
- }
+ video_putchar(memory[addr], memory[addr + 1]);
+ addr += 2;
+ cnt--;
}
- if(!(ax & 1))
+ }
+ else
+ {
+ uint8_t at = cpuGetBX() >> 8;
+ while(cnt && addr <= 0xFFFFF)
{
- vid_posx = save_posx;
- vid_posy = save_posy;
+ video_putchar(memory[addr], at);
+ addr++;
+ cnt--;
}
- update_posxy();
}
- break;
+ if(!(ax & 1))
+ {
+ vid_posx = save_posx;
+ vid_posy = save_posy;
+ }
+ update_posxy();
+ }
+ break;
case 0x1A: // GET/SET DISPLAY COMBINATION CODE
cpuSetAX(0x001A);
cpuSetBX(0x0008); // VGA + analog color display
@@ -635,27 +631,27 @@ void int10()
{
// Store state information
memset(memory + addr, 0, 64);
- memory[addr+0] = 0x00;
- memory[addr+1] = 0x01;
- memory[addr+2] = 0x00;
- memory[addr+3] = 0xC0; // static-func table at C000:0000
- memory[addr+4] = 0x03; // Video mode
- memory[addr+5] = vid_sx;
- memory[addr+6] = vid_sx >> 8;
- memory[addr+11] = vid_posx; // page 0
- memory[addr+12] = vid_posy;
- memory[addr+27] = vid_cursor * 6; // cursor start scanline
- memory[addr+28] = vid_cursor * 7; // cursor end scanline
- memory[addr+29] = 0; // current page
- memory[addr+30] = 0xD4;
- memory[addr+31] = 0x03; // CRTC port: 03D4
- memory[addr+34] = vid_sy;
- memory[addr+35] = vid_font_lines;
- memory[addr+36] = 0x00; // font lines: 0010
- memory[addr+39] = 0x10;
- memory[addr+40] = 0x00; // # of colors: 0010
- memory[addr+42] = 2; // # of scan-lines - get from vid_sy
- memory[addr+49] = 3; // 256k memory
+ memory[addr + 0] = 0x00;
+ memory[addr + 1] = 0x01;
+ memory[addr + 2] = 0x00;
+ memory[addr + 3] = 0xC0; // static-func table at C000:0000
+ memory[addr + 4] = 0x03; // Video mode
+ memory[addr + 5] = vid_sx;
+ memory[addr + 6] = vid_sx >> 8;
+ memory[addr + 11] = vid_posx; // page 0
+ memory[addr + 12] = vid_posy;
+ memory[addr + 27] = vid_cursor * 6; // cursor start scanline
+ memory[addr + 28] = vid_cursor * 7; // cursor end scanline
+ memory[addr + 29] = 0; // current page
+ memory[addr + 30] = 0xD4;
+ memory[addr + 31] = 0x03; // CRTC port: 03D4
+ memory[addr + 34] = vid_sy;
+ memory[addr + 35] = vid_font_lines;
+ memory[addr + 36] = 0x00; // font lines: 0010
+ memory[addr + 39] = 0x10;
+ memory[addr + 40] = 0x00; // # of colors: 0010
+ memory[addr + 42] = 2; // # of scan-lines - get from vid_sy
+ memory[addr + 49] = 3; // 256k memory
cpuSetAX(0x1B1B);
}
}
@@ -676,9 +672,9 @@ uint8_t video_crtc_read(int port)
{
if(port & 1)
{
- if( crtc_port == 0x0E )
+ if(crtc_port == 0x0E)
return crtc_cursor_loc >> 8;
- if( crtc_port == 0x0F )
+ if(crtc_port == 0x0F)
return crtc_cursor_loc;
else
return 0;
@@ -691,9 +687,9 @@ void video_crtc_write(int port, uint8_t value)
{
if(port & 1)
{
- if( crtc_port == 0x0E )
+ if(crtc_port == 0x0E)
crtc_cursor_loc = (crtc_cursor_loc & 0xFF) | (value << 8);
- if( crtc_port == 0x0F )
+ if(crtc_port == 0x0F)
crtc_cursor_loc = (crtc_cursor_loc & 0xFF00) | (value);
else
debug(debug_video, "CRTC port write [%02x] <- %02x\n", crtc_port, value);
Un proyecto texto-plano.xyz