From 8acec1b95d26f0e6f1090a29426995ebe54068f7 Mon Sep 17 00:00:00 2001 From: Stephen Checkoway Date: Sat, 12 Aug 2017 14:54:40 -0500 Subject: [PATCH] Make z80_types.h an internal header. Do not pollute the global namespace by defining byte, sbyte, and word. --- Makefile | 10 ++++------ include/zel/z80.h | 22 ++++++++++------------ include/zel/z80_instructions.h | 5 ++--- tests/Makefile | 2 +- tests/itest.c | 2 ++ tests/template.c | 2 ++ tests/test.c | 2 ++ tests/test_arithmetic.c | 2 ++ tests/test_load.c | 2 ++ tests/test_set.c | 2 ++ z80.c | 2 ++ z80_instructions.c | 2 ++ include/zel/z80_types.h => z80_types.h | 4 ++-- 13 files changed, 35 insertions(+), 24 deletions(-) rename include/zel/z80_types.h => z80_types.h (95%) diff --git a/Makefile b/Makefile index a3f5e47..4c80c52 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -CPPFLAGS += -Iinclude +CPPFLAGS += -I. -Iinclude CFLAGS += -O3 package := zel @@ -48,9 +48,9 @@ here := $(shell pwd) dist_source := z80.c \ z80_instructions.c \ + z80_types.h \ include/zel/z80.h \ include/zel/z80_instructions.h \ - include/zel/z80_types.h \ include/zel/z80_instruction_types.h \ tables/gen.pl \ $(spec) \ @@ -104,8 +104,8 @@ include/zel/z80_instruction_types.h: $(itables) echo >>$@ echo '#endif' >>$@ -z80.o: z80.c include/zel/z80.h include/zel/z80_instructions.h include/zel/z80_types.h include/zel/z80_instruction_types.h -z80_instructions.o: z80_instructions.c include/zel/z80_instructions.h include/zel/z80.h include/zel/z80_types.h include/zel/z80_instruction_types.h $(itables) +z80.o: z80.c z80_types.h include/zel/z80.h include/zel/z80_instructions.h include/zel/z80_instruction_types.h +z80_instructions.o: z80_instructions.c z80_types.h include/zel/z80_instructions.h include/zel/z80.h include/zel/z80_instruction_types.h $(itables) check: all $(MAKE) -C tests check @@ -140,14 +140,12 @@ install: $(INSTALL) -d $(DESTDIR)$(includedir)/zel $(INSTALL_DATA) include/zel/z80.h $(DESTDIR)$(includedir)/zel $(INSTALL_DATA) include/zel/z80_instructions.h $(DESTDIR)$(includedir)/zel - $(INSTALL_DATA) include/zel/z80_types.h $(DESTDIR)$(includedir)/zel $(INSTALL_DATA) include/zel/z80_instruction_types.h $(DESTDIR)$(includedir)/zel uninstall: uninstall-doc $(RM) $(DESTDIR)$(libdir)/libzel.a $(RM) $(DESTDIR)$(includedir)/zel/z80.h $(RM) $(DESTDIR)$(includedir)/zel/z80_instructions.h - $(RM) $(DESTDIR)$(includedir)/zel/z80_types.h $(RM) $(DESTDIR)$(includedir)/zel/z80_instruction_types.h rmdir $(DESTDIR)$(includedir)/zel diff --git a/include/zel/z80.h b/include/zel/z80.h index c3cc8c2..b1325a2 100644 --- a/include/zel/z80.h +++ b/include/zel/z80.h @@ -36,8 +36,6 @@ extern "C" { #include #endif -#include - /*! Opaque type representing a z80 processor. */ typedef struct Z80_t *Z80; @@ -91,32 +89,32 @@ typedef struct * \param cpu The \c Z80 instance making the read call. * \return The byte from memory. */ - byte (*ReadMem)(word addr, bool inst, Z80 cpu); + uint8_t (*ReadMem)(uint16_t addr, bool inst, Z80 cpu); /*! Write a byte of memory. * \param addr The address to write. * \param val The byte to write. * \param cpu The \c Z80 instance making the write call. */ - void (*WriteMem)(word addr, byte val, Z80 cpu); + void (*WriteMem)(uint16_t addr, uint8_t val, Z80 cpu); /*! Read the interrupt data. * \param n Read the \a n th byte of data. * \param cpu The \c Z80 instance making the read call. */ - byte (*ReadInterruptData)(word n, Z80 cpu); + uint8_t (*ReadInterruptData)(uint16_t n, Z80 cpu); /*! Read a byte from an I/O port. * \param addr The contents of the address bus during the * request. The low 8 bits specify the port. * \param cpu The \c Z80 instance making the read call. * \return The byte from the I/O port. */ - byte (*ReadIO)(word addr, Z80 cpu); + uint8_t (*ReadIO)(uint16_t addr, Z80 cpu); /*! Write a byte from an I/O port. * \param addr The contents of the address bus during the * request. The low 8 bits specify the port. * \param val The byte to write. * \param cpu The \c Z80 instance making the read call. */ - void (*WriteIO)(word addr, byte val, Z80 cpu); + void (*WriteIO)(uint16_t addr, uint8_t val, Z80 cpu); /*! Notify the peripherials that a return from interrupt * instruction has occured. * \param cpu The \c Z80 instance performing the notification. @@ -130,7 +128,7 @@ typedef struct * \param type The type of control flow. * \param cpu The \c Z80 instance performing the notification. */ - void (*ControlFlow)(word pc, word target, ControlFlowType type, Z80 cpu); + void (*ControlFlow)(uint16_t pc, uint16_t target, ControlFlowType type, Z80 cpu); } Z80FunctionBlock; /*! Create a new \c Z80 instance using the callbacks specified in \a blk. @@ -152,7 +150,7 @@ void Z80_Free( Z80 cpu ); * \return The number of clock ticks that have elapsed while executing * the instruction. */ -int Z80_Step( word *outPC, Z80 cpu ); +int Z80_Step( uint16_t *outPC, Z80 cpu ); /*! Check if \a cpu has halted. * \param cpu The \c Z80 instance. @@ -165,14 +163,14 @@ bool Z80_HasHalted( Z80 cpu ); * \param cpu The \c Z80 instance. * \return The contents of the register specified by \a reg. */ -word Z80_GetReg( int reg, Z80 cpu ); +uint16_t Z80_GetReg( int reg, Z80 cpu ); /*! Set a 16 bit paired register. * \param reg The register to set. * \param value The value to assign to the register. * \param cpu The \c Z80 instance. */ -void Z80_SetReg( int reg, word value, Z80 cpu ); +void Z80_SetReg( int reg, uint16_t value, Z80 cpu ); /*! Disassemble the z80 instruction pointed to by \a address into \a buffer. * \param address The address of the beginning the instruction. @@ -183,7 +181,7 @@ void Z80_SetReg( int reg, word value, Z80 cpu ); * function will be called to read the instructions. * \return The length of the instruction in bytes. */ -int Z80_Disassemble( word address, char *buffer, Z80 cpu ); +int Z80_Disassemble( uint16_t address, char *buffer, Z80 cpu ); /*! Simulate the NMI pin going active. This causes the z80 to jump to * the nmi handler. diff --git a/include/zel/z80_instructions.h b/include/zel/z80_instructions.h index 7d73f76..c6d6846 100644 --- a/include/zel/z80_instructions.h +++ b/include/zel/z80_instructions.h @@ -41,7 +41,6 @@ extern "C" { #include #endif -#include #include /*! The type of a z80 instruction. Many z80 instructions are similar @@ -220,7 +219,7 @@ extern const InstructionTemplate FDCB_Prefixed[256]; * \param data Callback data from IF_ID(). * \return The value at address \a addr. */ -typedef byte (*ReadMemFunction)(word addr, void *data); +typedef uint8_t (*ReadMemFunction)(uint16_t addr, void *data); /*! Instruction fetch and instruction decode. Fetchs and decodes the * instruction pointed to by \a address into \a *inst. @@ -232,7 +231,7 @@ typedef byte (*ReadMemFunction)(word addr, void *data); * \param data Arbitrary data passed to the \a ReadMem callback. * \return The length of the instruction. */ -int IF_ID( Instruction *inst, word address, ReadMemFunction ReadMem, void *data ); +int IF_ID( Instruction *inst, uint16_t address, ReadMemFunction ReadMem, void *data ); /*! Disassemble the instruction pointed to by \a inst into \a buffer. * \param inst Pointer to an \c Instruction. diff --git a/tests/Makefile b/tests/Makefile index 8793900..c620067 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -22,7 +22,7 @@ sources = $(wildcard test_*.c) tests = $(sources:.c=) itests = $(subst test,itest,$(tests)) -CPPFLAGS += -I../include +CPPFLAGS += -I.. -I../include CFLAGS += -O3 -Wall -Werror LDFLAGS += -L.. LIBS += -lzel diff --git a/tests/itest.c b/tests/itest.c index e58c17a..1808e19 100644 --- a/tests/itest.c +++ b/tests/itest.c @@ -22,6 +22,8 @@ #include #include +#include "z80_types.h" + extern const char *disasm[]; extern byte data[]; diff --git a/tests/template.c b/tests/template.c index 147258b..1f47e7d 100644 --- a/tests/template.c +++ b/tests/template.c @@ -2,6 +2,8 @@ #include #include +#include "z80_types.h" + byte data[] = {}; const byte interrupt_data [] = {}; const byte input_data[] = {}; diff --git a/tests/test.c b/tests/test.c index 228f77d..7d59c94 100644 --- a/tests/test.c +++ b/tests/test.c @@ -23,6 +23,8 @@ #include #include +#include "z80_types.h" + extern byte data[]; extern const size_t size; extern const byte interrupt_data[]; diff --git a/tests/test_arithmetic.c b/tests/test_arithmetic.c index 79d545a..e98abf9 100644 --- a/tests/test_arithmetic.c +++ b/tests/test_arithmetic.c @@ -2,6 +2,8 @@ #include #include +#include "z80_types.h" + const char *disasm[] = { "add a,b", "sub c", diff --git a/tests/test_load.c b/tests/test_load.c index 8a4f86b..1487891 100644 --- a/tests/test_load.c +++ b/tests/test_load.c @@ -2,6 +2,8 @@ #include #include +#include "z80_types.h" + const char *disasm[] = { "ld a,15h", "ld b,a", diff --git a/tests/test_set.c b/tests/test_set.c index 8c32a8a..2d53b3e 100644 --- a/tests/test_set.c +++ b/tests/test_set.c @@ -2,6 +2,8 @@ #include #include +#include "z80_types.h" + const char *disasm[] = { "ld ix,0020h", "set 0,(ix-10h)", diff --git a/z80.c b/z80.c index 76f8425..d8d9cc0 100644 --- a/z80.c +++ b/z80.c @@ -23,6 +23,8 @@ #include #include +#include "z80_types.h" + struct Z80_t { /* C guarantees consecutive layout */ diff --git a/z80_instructions.c b/z80_instructions.c index 02a91a6..a78bfdc 100644 --- a/z80_instructions.c +++ b/z80_instructions.c @@ -23,6 +23,8 @@ #include /* Need registers */ #include +#include "z80_types.h" + const InstructionTemplate Unprefixed[] = { #include "tables/no_prefix.tab" diff --git a/include/zel/z80_types.h b/z80_types.h similarity index 95% rename from include/zel/z80_types.h rename to z80_types.h index 147cfae..bd43e4a 100644 --- a/include/zel/z80_types.h +++ b/z80_types.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008 Steve Checkoway +/* Copyright (c) 2008, 2017 Stephen Checkoway * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ /*! \file * * Types used by the z80. - * \author Steve Checkoway + * \author Stephen Checkoway * \version 0.1 * \date 2008 */