summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-10-25 11:08:26 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-10-25 11:08:58 (GMT)
commit71d03da3943610111b88e9fa9aef2b3fc5da3f5f (patch)
tree94a14cdc1e15c79206b072e91783a93d928373ae
parent0ef16e247a1cb7ec05dc4f78b9499df3713f9ef9 (diff)
downloadabc80sim-71d03da3943610111b88e9fa9aef2b3fc5da3f5f.zip
abc80sim-71d03da3943610111b88e9fa9aef2b3fc5da3f5f.tar.gz
abc80sim-71d03da3943610111b88e9fa9aef2b3fc5da3f5f.tar.bz2
abc80sim-71d03da3943610111b88e9fa9aef2b3fc5da3f5f.tar.xz
Change to standard uint8_t and uint16_t types
-rw-r--r--Makefile2
-rw-r--r--abc80.c8
-rw-r--r--abc80_mem.c20
-rw-r--r--configure.in4
-rw-r--r--io.c8
-rw-r--r--z80.c104
-rw-r--r--z80.h39
-rw-r--r--z80dis.c6
8 files changed, 95 insertions, 96 deletions
diff --git a/Makefile b/Makefile
index 68728d1..b3a5368 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ mandir = ${datarootdir}/man
datarootdir = ${prefix}/share
CC = gcc
-CFLAGS = -g -O2 -W -Wall
+CFLAGS = -g -O2 -W -Wall -std=c99 -pedantic
LDFLAGS =
LIBS = -lSDL -lpthread
diff --git a/abc80.c b/abc80.c
index 74103fc..ac6c432 100644
--- a/abc80.c
+++ b/abc80.c
@@ -18,9 +18,9 @@ volatile int event_pending = 1;
* and return its numeric value.
*/
static char *hexstring = "0123456789ABCDEF";
-static uchar gethex(char *p)
+static uint8_t gethex(char *p)
{
- return (uchar)(((strchr(hexstring, *p) - hexstring) << 4)
+ return (uint8_t)(((strchr(hexstring, *p) - hexstring) << 4)
+ (strchr(hexstring, *(p + 1)) - hexstring));
}
@@ -32,7 +32,7 @@ static uchar gethex(char *p)
static void
load_sysfile(FILE *sysfile)
{
- uchar *memory;
+ uint8_t *memory;
char line[128];
char *pos;
int len;
@@ -66,7 +66,7 @@ load_sysfile(FILE *sysfile)
*/
static void load_rom(const struct rom *rom)
{
- uchar *memory = mem_rom_address();
+ uint8_t *memory = mem_rom_address();
memcpy(memory + rom->offset, rom->data, rom->size);
}
diff --git a/abc80_mem.c b/abc80_mem.c
index 3367467..6fa46ab 100644
--- a/abc80_mem.c
+++ b/abc80_mem.c
@@ -13,7 +13,7 @@
#define VIDEO_LEN (0x0400)
#define RAM_START (0x8000)
-static uchar memory[MEMORY_SIZE];
+static uint8_t memory[MEMORY_SIZE];
/*
* Macros to determine quickly if an address is writeable.
@@ -30,7 +30,7 @@ void mem_init(void)
/*
* hack to let us initialize the ROM memory
*/
-uchar *mem_rom_address(void)
+uint8_t *mem_rom_address(void)
{
return memory;
}
@@ -39,13 +39,13 @@ uchar *mem_rom_address(void)
/*
* hack to get a pointer into the Z80 "memory"
*/
-uchar *mem_get_addr(ushort address)
+uint8_t *mem_get_addr(uint16_t address)
{
return &memory[address];
}
-uchar mem_read(ushort address)
+uint8_t mem_read(uint16_t address)
{
if (DEBUG_READ(address)) {
printf("Accessed:\t0x%04x %5d : %02x\n",
@@ -55,7 +55,7 @@ uchar mem_read(ushort address)
}
-void mem_write(ushort address, uchar value)
+void mem_write(uint16_t address, uint8_t value)
{
if ((address & VIDEO_MASK) == VIDEO_START) {
/*
@@ -78,12 +78,12 @@ void mem_write(ushort address, uchar value)
/*
* Words are stored with the low-order byte in the lower address.
*/
-ushort mem_read_word(ushort address)
+uint16_t mem_read_word(uint16_t address)
{
- uchar b0, b1;
+ uint8_t b0, b1;
b0 = memory[address];
- b1 = memory[(ushort)(address + 1)];
+ b1 = memory[(uint16_t)(address + 1)];
if (DEBUG_READ(address)) {
printf("Accessed:\t0x%04x %5d : %02x%02x\n",
@@ -94,7 +94,7 @@ ushort mem_read_word(ushort address)
}
-void mem_write_word(ushort address, ushort value)
+void mem_write_word(uint16_t address, uint16_t value)
{
mem_write(address, value);
mem_write(address+1, value >> 8);
@@ -109,7 +109,7 @@ void mem_write_word(ushort address, ushort value)
* Note that a count of zero => move 64K bytes.
*/
void
-mem_block_transfer(ushort dest, ushort source, int direction, ushort count)
+mem_block_transfer(uint16_t dest, uint16_t source, int direction, uint16_t count)
{
if(direction > 0)
{
diff --git a/configure.in b/configure.in
index 0fb3498..972bec8 100644
--- a/configure.in
+++ b/configure.in
@@ -17,8 +17,8 @@ AC_PROG_INSTALL
dnl If we have gcc, add appropriate options
PA_ADD_CFLAGS([-W])
PA_ADD_CFLAGS([-Wall])
-dnl PA_ADD_CFLAGS([-std=c99])
-dnl PA_ADD_CFLAGS([-pedantic])
+PA_ADD_CFLAGS([-std=c99])
+PA_ADD_CFLAGS([-pedantic])
dnl Look for programs...
AC_CHECK_PROGS(NROFF, nroff, false)
diff --git a/io.c b/io.c
index 4ee8dac..6cdf17c 100644
--- a/io.c
+++ b/io.c
@@ -4,8 +4,8 @@
#include "z80.h"
#include "screen.h"
-static uchar inports[256];
-static uchar outports[256];
+static uint8_t inports[256];
+static uint8_t outports[256];
#define READ_MODE 0
#define WRITE_MODE 1
@@ -27,7 +27,7 @@ static struct {
* Set a port to a value which the z80 can read later.
*/
void
-set_in_port(int port, uchar value)
+set_in_port(int port, uint8_t value)
{
inports[port] = value;
}
@@ -48,7 +48,7 @@ extern int printer_in(int, int);
* dispatch possible actions.
*/
void
-z80_out(int port, uchar value)
+z80_out(int port, uint8_t value)
{
if ( port == 1 )
abcbus_select = value & 0x3f;
diff --git a/z80.c b/z80.c
index bf77ada..c9d9a3b 100644
--- a/z80.c
+++ b/z80.c
@@ -40,7 +40,7 @@ static void diffstate(void);
* Tables and routines for computing various flag values:
*/
-static uchar sign_carry_overflow_table[] =
+static uint8_t sign_carry_overflow_table[] =
{
0,
OVERFLOW_MASK | SIGN_MASK,
@@ -52,7 +52,7 @@ static uchar sign_carry_overflow_table[] =
CARRY_MASK | SIGN_MASK,
};
-static uchar half_carry_table[] =
+static uint8_t half_carry_table[] =
{
0,
0,
@@ -64,7 +64,7 @@ static uchar half_carry_table[] =
HALF_CARRY_MASK,
};
-static uchar subtract_sign_carry_overflow_table[] =
+static uint8_t subtract_sign_carry_overflow_table[] =
{
0,
CARRY_MASK | SIGN_MASK,
@@ -76,7 +76,7 @@ static uchar subtract_sign_carry_overflow_table[] =
CARRY_MASK | SIGN_MASK,
};
-static uchar subtract_half_carry_table[] =
+static uint8_t subtract_half_carry_table[] =
{
0,
HALF_CARRY_MASK,
@@ -242,7 +242,7 @@ static void do_sbc_word_flags(int a, int b, int result)
static void do_flags_dec_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(OVERFLOW_MASK | HALF_CARRY_MASK
| ZERO_MASK | SIGN_MASK);
@@ -262,7 +262,7 @@ static void do_flags_dec_byte(int value)
static void do_flags_inc_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SUBTRACT_MASK | OVERFLOW_MASK
| HALF_CARRY_MASK | ZERO_MASK | SIGN_MASK);
@@ -287,7 +287,7 @@ static void do_flags_inc_byte(int value)
static void do_and_byte(int value)
{
int result;
- uchar clear, set;
+ uint8_t clear, set;
result = (REG_A &= value);
@@ -308,7 +308,7 @@ static void do_and_byte(int value)
static void do_or_byte(int value)
{
int result; /* the result of the or operation */
- uchar clear, set;
+ uint8_t clear, set;
result = (REG_A |= value);
@@ -329,7 +329,7 @@ static void do_or_byte(int value)
static void do_xor_byte(int value)
{
int result; /* the result of the xor operation */
- uchar clear, set;
+ uint8_t clear, set;
result = (REG_A ^= value);
@@ -438,7 +438,7 @@ static void do_sbc_word(int value)
do_sbc_word_flags(a, value, result);
}
-static void do_add_word_index(ushort *regp, int value)
+static void do_add_word_index(uint16_t *regp, int value)
{
int a, result;
@@ -512,7 +512,7 @@ static void do_cpir(void)
static void do_test_bit(int value, int bit)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | OVERFLOW_MASK | SUBTRACT_MASK);
set = HALF_CARRY_MASK;
@@ -530,7 +530,7 @@ static int rl_byte(int value)
* operation, setting flags as appropriate.
*/
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -567,7 +567,7 @@ static int rr_byte(int value)
* operation, setting flags as appropriate.
*/
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -604,7 +604,7 @@ static int rlc_byte(int value)
* This does not do the right thing for the RLCA instruction.
*/
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -635,7 +635,7 @@ static int rlc_byte(int value)
static int rrc_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -670,7 +670,7 @@ static int rrc_byte(int value)
*/
static void do_rla(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(HALF_CARRY_MASK | SUBTRACT_MASK | CARRY_MASK);
set = 0;
@@ -692,7 +692,7 @@ static void do_rla(void)
static void do_rra(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(HALF_CARRY_MASK | SUBTRACT_MASK | CARRY_MASK);
set = 0;
@@ -713,7 +713,7 @@ static void do_rra(void)
static void do_rlca(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(HALF_CARRY_MASK | SUBTRACT_MASK | CARRY_MASK);
set = 0;
@@ -732,7 +732,7 @@ static void do_rlca(void)
static void do_rrca(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(HALF_CARRY_MASK | SUBTRACT_MASK | CARRY_MASK);
set = 0;
@@ -751,7 +751,7 @@ static void do_rrca(void)
static int sla_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -776,7 +776,7 @@ static int sla_byte(int value)
static int sra_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -807,7 +807,7 @@ static int sra_byte(int value)
static int srl_byte(int value)
{
- uchar clear, set;
+ uint8_t clear, set;
int result;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
@@ -892,7 +892,7 @@ static void do_lddr(void)
static void do_ld_a_i(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | OVERFLOW_MASK |
SUBTRACT_MASK);
@@ -913,7 +913,7 @@ static void do_ld_a_i(void)
static void do_ld_a_r(void)
{
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | OVERFLOW_MASK |
SUBTRACT_MASK);
@@ -1055,7 +1055,7 @@ static void do_rld(void)
* Rotate-left-decimal.
*/
int old_value, new_value;
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
SUBTRACT_MASK);
@@ -1086,7 +1086,7 @@ static void do_rrd(void)
* Rotate-right-decimal.
*/
int old_value, new_value;
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK | PARITY_MASK |
SUBTRACT_MASK);
@@ -1178,7 +1178,7 @@ static int in_with_flags(int port)
*/
int value;
- uchar clear, set;
+ uint8_t clear, set;
clear = ~(SIGN_MASK | ZERO_MASK | HALF_CARRY_MASK |
PARITY_MASK | SUBTRACT_MASK);
@@ -1329,7 +1329,7 @@ do_int(void)
static void do_CB_instruction(void)
{
- uchar instruction;
+ uint8_t instruction;
instruction = mem_read(REG_PC++);
@@ -2099,9 +2099,9 @@ static void do_CB_instruction(void)
}
-static void do_indexed_instruction(ushort *ixp)
+static void do_indexed_instruction(uint16_t *ixp)
{
- uchar instruction;
+ uint8_t instruction;
instruction = mem_read(REG_PC++);
@@ -2140,8 +2140,8 @@ static void do_indexed_instruction(ushort *ixp)
case 0x35: /* dec (ix + offset) */
{
- ushort address;
- uchar value;
+ uint16_t address;
+ uint8_t value;
address = *ixp + (char) mem_read(REG_PC++);
value = mem_read(address) - 1;
mem_write(address, value);
@@ -2155,7 +2155,7 @@ static void do_indexed_instruction(ushort *ixp)
case 0xE3: /* ex (sp), ix */
{
- ushort temp;
+ uint16_t temp;
temp = mem_read_word(REG_SP);
mem_write_word(REG_SP, *ixp);
*ixp = temp;
@@ -2164,8 +2164,8 @@ static void do_indexed_instruction(ushort *ixp)
case 0x34: /* inc (ix + offset) */
{
- ushort address;
- uchar value;
+ uint16_t address;
+ uint8_t value;
address = *ixp + (char) mem_read(REG_PC++);
value = mem_read(address) + 1;
mem_write(address, value);
@@ -2278,7 +2278,7 @@ static void do_indexed_instruction(ushort *ixp)
case 0xCB:
{
char offset;
- uchar sub_instruction;
+ uint8_t sub_instruction;
offset = (char) mem_read(REG_PC++);
sub_instruction = mem_read(REG_PC++);
@@ -2403,7 +2403,7 @@ static void do_indexed_instruction(ushort *ixp)
static void do_ED_instruction(void)
{
- uchar instruction;
+ uint8_t instruction;
instruction = mem_read(REG_PC++);
@@ -2621,14 +2621,14 @@ static void do_ED_instruction(void)
}
/* Hack, hack, see if we can speed this up. */
-/*extern uchar *memory;*/
+/*extern uint8_t *memory;*/
/*#define MEM_READ(a) ((a < 0x3000) ? memory[a] : mem_read(a));*/
/* #define MEM_READ(a) (((((a) - 0x3000) & 0xffff) >= 0xc00) ? memory[a] : mem_read(a)) */
int z80_run(int continuous)
{
- uchar instruction;
- ushort address; /* generic temps */
+ uint8_t instruction;
+ uint16_t address; /* generic temps */
/* loop to do a z80 instruction */
do {
@@ -2967,7 +2967,7 @@ int z80_run(int continuous)
case 0x35: /* dec (hl) */
{
- uchar value = mem_read(REG_HL) - 1;
+ uint8_t value = mem_read(REG_HL) - 1;
mem_write(REG_HL, value);
do_flags_dec_byte(value);
}
@@ -2994,7 +2994,7 @@ int z80_run(int continuous)
/* Zaks says no flag changes. */
if(--REG_B != 0)
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
@@ -3010,7 +3010,7 @@ int z80_run(int continuous)
case 0x08: /* ex af, af' */
{
- ushort temp;
+ uint16_t temp;
temp = REG_AF;
REG_AF = REG_AF_PRIME;
REG_AF_PRIME = temp;
@@ -3019,7 +3019,7 @@ int z80_run(int continuous)
case 0xEB: /* ex de, hl */
{
- ushort temp;
+ uint16_t temp;
temp = REG_DE;
REG_DE = REG_HL;
REG_HL = temp;
@@ -3028,7 +3028,7 @@ int z80_run(int continuous)
case 0xE3: /* ex (sp), hl */
{
- ushort temp;
+ uint16_t temp;
temp = mem_read_word(REG_SP);
mem_write_word(REG_SP, REG_HL);
REG_HL = temp;
@@ -3037,7 +3037,7 @@ int z80_run(int continuous)
case 0xD9: /* exx */
{
- ushort tmp;
+ uint16_t tmp;
tmp = REG_BC_PRIME;
REG_BC_PRIME = REG_BC;
REG_BC = tmp;
@@ -3089,7 +3089,7 @@ int z80_run(int continuous)
case 0x34: /* inc (hl) */
{
- uchar value = mem_read(REG_HL) + 1;
+ uint8_t value = mem_read(REG_HL) + 1;
mem_write(REG_HL, value);
do_flags_inc_byte(value);
}
@@ -3199,7 +3199,7 @@ int z80_run(int continuous)
case 0x18: /* jr offset */
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
@@ -3208,7 +3208,7 @@ int z80_run(int continuous)
case 0x20: /* jr nz, offset */
if(!ZERO_FLAG)
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
@@ -3220,7 +3220,7 @@ int z80_run(int continuous)
case 0x28: /* jr z, offset */
if(ZERO_FLAG)
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
@@ -3232,7 +3232,7 @@ int z80_run(int continuous)
case 0x30: /* jr nc, offset */
if(!CARRY_FLAG)
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
@@ -3244,7 +3244,7 @@ int z80_run(int continuous)
case 0x38: /* jr c, offset */
if(CARRY_FLAG)
{
- uchar byte_value;
+ uint8_t byte_value;
byte_value = mem_read(REG_PC++);
REG_PC += (char) byte_value;
}
diff --git a/z80.h b/z80.h
index d4c6673..144ba58 100644
--- a/z80.h
+++ b/z80.h
@@ -16,19 +16,18 @@
#include <stdio.h>
#include <ctype.h>
#include <time.h>
+#include <inttypes.h>
#include <sys/types.h>
#define TRUE (1)
#define FALSE (0)
-typedef unsigned char uchar;
-
struct twobyte
{
#ifdef WORDS_LITTLEENDIAN
- uchar low, high;
+ uint8_t low, high;
#else
- uchar high, low;
+ uint8_t high, low;
#endif
};
@@ -36,7 +35,7 @@ struct twobyte
typedef union
{
struct twobyte byte;
- ushort word;
+ uint16_t word;
} wordregister;
struct z80_state_struct
@@ -55,18 +54,18 @@ struct z80_state_struct
wordregister de_prime;
wordregister hl_prime;
- uchar i; /* interrupt-page address register */
- /* uchar r; */ /* no memory-refresh register, just fetch random values */
+ uint8_t i; /* interrupt-page address register */
+ /* uint8_t r; */ /* no memory-refresh register, just fetch random values */
- uchar iff1, iff2;
- uchar interrupt_mode;
+ uint8_t iff1, iff2;
+ uint8_t interrupt_mode;
int nmi_in_progress; /* to prevent multiple simultaneous NMIs */
int nminterrupt; /* used to signal a non maskable interrupt */
int interrupt; /* used to signal an interrupt */
- uchar i_vector; /* offset into interrupt-page from _external_ device */
+ uint8_t i_vector; /* offset into interrupt-page from _external_ device */
};
#define Z80_ADDRESS_LIMIT (1 << 16)
@@ -161,19 +160,19 @@ extern struct z80_state_struct z80_state;
extern void z80_reset(void);
extern int z80_run(int);
extern void mem_init(void);
-extern uchar mem_read(ushort);
-extern void mem_write(ushort, uchar);
-extern uchar *mem_rom_address(void);
-extern uchar *mem_get_addr(ushort);
-extern ushort mem_read_word(ushort);
-extern void mem_write_word(ushort, ushort);
-extern void mem_block_transfer(ushort, ushort, int, ushort);
-extern void set_in_port(int, uchar);
-extern void z80_out(int, uchar);
+extern uint8_t mem_read(uint16_t);
+extern void mem_write(uint16_t, uint8_t);
+extern uint8_t *mem_rom_address(void);
+extern uint8_t *mem_get_addr(uint16_t);
+extern uint16_t mem_read_word(uint16_t);
+extern void mem_write_word(uint16_t, uint16_t);
+extern void mem_block_transfer(uint16_t, uint16_t, int, uint16_t);
+extern void set_in_port(int, uint8_t);
+extern void z80_out(int, uint8_t);
extern int z80_in(int);
extern void io_init(void);
extern int disassemble(int);
-extern int DAsm(ushort pc, char *T, int *target);
+extern int DAsm(uint16_t pc, char *T, int *target);
extern void load_basic(int);
/*
diff --git a/z80dis.c b/z80dis.c
index 7762da0..d18d524 100644
--- a/z80dis.c
+++ b/z80dis.c
@@ -245,14 +245,14 @@ int disassemble(int pc)
}
-int DAsm(ushort pc, char *T, int *target)
+int DAsm(uint16_t pc, char *T, int *target)
{
const char *S,*P;
char PP,*R;
int I;
int table;
char XReg;
- ushort pc0 = pc;
+ uint16_t pc0 = pc;
if ( target ) *target = -1;
@@ -333,5 +333,5 @@ int DAsm(ushort pc, char *T, int *target)
*R = '\0';
/* Return the number of consumed bytes */
- return (ushort)(pc-pc0);
+ return (uint16_t)(pc-pc0);
}