diff options
Diffstat (limited to 'arm9/include')
-rw-r--r-- | arm9/include/config.h | 49 | ||||
-rw-r--r-- | arm9/include/framebuffer.h | 90 | ||||
-rw-r--r-- | arm9/include/gui.h | 30 | ||||
-rw-r--r-- | arm9/include/keyboard.h | 135 | ||||
-rw-r--r-- | arm9/include/monitor.h | 29 | ||||
-rw-r--r-- | arm9/include/spec.h | 69 | ||||
-rw-r--r-- | arm9/include/tapes.h | 27 | ||||
-rw-r--r-- | arm9/include/textmode.h | 37 | ||||
-rw-r--r-- | arm9/include/touchwrap.h | 38 | ||||
-rw-r--r-- | arm9/include/z80.h | 250 | ||||
-rw-r--r-- | arm9/include/z80_config.h | 59 | ||||
-rw-r--r-- | arm9/include/z80_private.h | 276 |
12 files changed, 1089 insertions, 0 deletions
diff --git a/arm9/include/config.h b/arm9/include/config.h new file mode 100644 index 0000000..f61bd81 --- /dev/null +++ b/arm9/include/config.h @@ -0,0 +1,49 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_CONFIG_H +#define DS48_CONFIG_H + +typedef enum +{ + DS48_STICKY_CAPS, + DS48_STICKY_SYM, + DS48_AVERAGE_TOUCHSCREEN, + DS48_NUM_CONFIG_ITEMS +} DS48_ConfigItem; + +/* Returns TRUE if config loaded from FAT device +*/ +int LoadConfig(void); + +/* Returns TRUE if config saved to FAT device +*/ +int SaveConfig(void); + +/* Gets a description for a config item. +*/ +const char *ConfigDesc(DS48_ConfigItem item); + +/* Table of configs. Done like this for simple performance reasons. +*/ +extern int DS48_Config[/*DS48_ConfigItem item*/]; + +#endif /* DS48_CONFIG_H */ diff --git a/arm9/include/framebuffer.h b/arm9/include/framebuffer.h new file mode 100644 index 0000000..ec64bdd --- /dev/null +++ b/arm9/include/framebuffer.h @@ -0,0 +1,90 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_FRAMEBUFFER_H +#define DS48_FRAMEBUFFER_H + +/* Predefined colours. +*/ +typedef enum +{ + COL_TRANSPARENT = -1, + COL_BLACK = 0, + COL_WHITE = 240, + COL_RED = 241, + COL_GREEN = 242, + COL_BLUE = 243, + COL_GUISELECT = 244, + COL_GREY = 245, + COL_LIGHTGREY = 246, + COL_DARKGREY = 247, + COL_YELLOW = 248 +} FB_Colour; + + +/* Initialise 'framebuffer' code. vram is where the 8-bit framebuffer is. + palette is the palette to use/set. +*/ +void FB_Init(uint16 *vram, uint16 *palette); + +/* Gives access to the parameters of the frame buffer. +*/ +uint16 *FB_VRAM(void); +uint16 *FB_PALETTE(void); + +/* Load the internal framebuffer font as a set of ASCII tiles (starting with + space) at tiles. The tiles will use colour COL_WHITE. +*/ +void FB_LoadASCIITiles(uint16 *tiles); + +/* Print the text into the framebuffer. +*/ +void FB_Print(const char *text, int x, int y, + FB_Colour colour, FB_Colour paper); +void FB_Centre(const char *text, int y, + FB_Colour colour, FB_Colour paper); +void FB_printf(int x, int y, FB_Colour colour, FB_Colour paper, + const char *format, ...); + +/* Lines and boxes. +*/ +void FB_HLine(int x1, int x2, int y, FB_Colour colour); +void FB_VLine(int x, int y1, int y2, FB_Colour colour); +void FB_Box(int x, int y, int w, int h, FB_Colour colour); +void FB_FillBox(int x, int y, int w, int h, FB_Colour colour); + +/* Clear to background +*/ +void FB_Clear(void); + +/* Draw the image. The image must be an 8-bit image, but with only the first + 16 palette entries used. Just to complicate matters! + + The image is assumed to be an even number of pixels wide. Also the passed + X co-ord will be forced even. + + offset is used to give an offset into the palette to place colours from the + image. Palette entries 1 - 128 will always be safe to use (these routines + will never use them). +*/ +void FB_Blit(sImage *img, int x, int y, int offset); + +#endif /* DS48_FRAMEBUFFER_H */ diff --git a/arm9/include/gui.h b/arm9/include/gui.h new file mode 100644 index 0000000..5464659 --- /dev/null +++ b/arm9/include/gui.h @@ -0,0 +1,30 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_GUI_H +#define DS48_GUI_H + +int GUI_Menu(const char *opts[]); +void GUI_Alert(int fatal, const char *text); +void GUI_Config(void); +int GUI_FileSelect(char pwd[], char selected_file[], const char *filter); + +#endif /* DS48_GUI_H */ diff --git a/arm9/include/keyboard.h b/arm9/include/keyboard.h new file mode 100644 index 0000000..fa7ec68 --- /dev/null +++ b/arm9/include/keyboard.h @@ -0,0 +1,135 @@ +/* + ds48 - Nintendo ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_KEYBOARD_H +#define DS48_KEYBOARD_H + +/* Note that the first 40 values purposefully are the keyboard matrix keys. + Note also that they are in display order, not matrix order. +*/ +typedef enum +{ + SK_1, + SK_2, + SK_3, + SK_4, + SK_5, + + SK_6, + SK_7, + SK_8, + SK_9, + SK_0, + + SK_Q, + SK_W, + SK_E, + SK_R, + SK_T, + + SK_Y, + SK_U, + SK_I, + SK_O, + SK_P, + + SK_A, + SK_S, + SK_D, + SK_F, + SK_G, + + SK_H, + SK_J, + SK_K, + SK_L, + SK_ENTER, + + SK_CAPS_SHIFT, + SK_Z, + SK_X, + SK_C, + SK_V, + + SK_B, + SK_N, + SK_M, + SK_SYMBOL_SHIFT, + SK_SPACE, + + SK_ABOUT, + SK_CONFIG, + SK_PAD_UP, + SK_PAD_DOWN, + SK_PAD_LEFT, + SK_PAD_RIGHT, + SK_PAD_A, + SK_PAD_B, + SK_PAD_X, + SK_PAD_Y, + SK_PAD_R, + SK_PAD_L, + SK_PAD_START, + SK_PAD_SELECT, + + NUM_SOFT_KEYS +} SoftKey; + +typedef struct +{ + SoftKey key; + int pressed; +} SoftKeyEvent; + + +/* Display the soft keyboard. +*/ +void SK_DisplayKeyboard(void); + +/* If dim is TRUE, then the keyboard is displayed with reduced brightness along + with the selection box. This routine simply adjusts the palette, and + assumes that the keyboard is already on display. +*/ +void SK_SetDisplayBrightness(int dim); + +/* Returns TRUE while there are still key events for this cycle +*/ +int SK_GetEvent(SoftKeyEvent *ev); + +/* Returns TRUE while there are still key events for this cycle. Unlike + SK_GetEvent this does not do joypad mappings. +*/ +int SK_GetBareEvent(SoftKeyEvent *ev); + +/* Sets a key to be 'sticky'. +*/ +void SK_SetSticky(SoftKey key, int is_sticky); + +/* Map the joypad to keys. Note that when mapped that both the key and the + joypad code will be generated. +*/ +void SK_DefinePad(SoftKey pad, SoftKey key); + +/* Returns a name for key symbols. +*/ +const char *SK_KeyName(SoftKey pad); + +#endif /* DS48_KEYBOARD_H */ diff --git a/arm9/include/monitor.h b/arm9/include/monitor.h new file mode 100644 index 0000000..fbee80b --- /dev/null +++ b/arm9/include/monitor.h @@ -0,0 +1,29 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_MONITOR_H +#define DS48_MONITOR_H + +#include "z80.h" + +void MachineCodeMonitor(Z80 *cpu); + +#endif /* DS48_MONITOR_H */ diff --git a/arm9/include/spec.h b/arm9/include/spec.h new file mode 100644 index 0000000..f9f6786 --- /dev/null +++ b/arm9/include/spec.h @@ -0,0 +1,69 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn (ianc@noddybox.demon.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ +*/ + +#ifndef DS48_SPEC_H +#define DS48_SPEC_H + +#include "z80.h" +#include "keyboard.h" + +/* Initialise the SPEC +*/ +void SPECInit(uint16 *vram, Z80 *z80); + +/* Handle keypresses +*/ +void SPECHandleKey(SoftKey k, int is_pressed); + +/* Enable fopen() loading of tape files +*/ +void SPECEnableFileSystem(int enable); + +/* Set a file to load from tape +*/ +void SPECSetTape(const Z80Byte *image, int len); + +/* Interfaces for the Z80 +*/ +Z80Byte SPECPeek(Z80 *z80, Z80Word addr); +void SPECPoke(Z80 *z80, Z80Word addr, Z80Byte val); + +#define SPECDisPeek SPECPeek + +Z80Byte SPECReadPort(Z80 *z80, Z80Word port); +void SPECWritePort(Z80 *z80, Z80Word port, Z80Byte val); + + +/* Reset the speccy +*/ +void SPECReset(Z80 *z80); + +/* Tell the Spectrum that config may have changed +*/ +void SPECReconfigure(void); + +#endif + + +/* END OF FILE */ diff --git a/arm9/include/tapes.h b/arm9/include/tapes.h new file mode 100644 index 0000000..1fbb2d7 --- /dev/null +++ b/arm9/include/tapes.h @@ -0,0 +1,27 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_TAPES_H +#define DS48_TAPES_H + +void SelectTape(void); + +#endif /* DS48_TAPES_H */ diff --git a/arm9/include/textmode.h b/arm9/include/textmode.h new file mode 100644 index 0000000..7cefdbf --- /dev/null +++ b/arm9/include/textmode.h @@ -0,0 +1,37 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_TEXTMODE_H +#define DS48_TEXTMODE_H + +/* Note that the co-ords are into the map -- the user is free to use this and + move the map around, scale it, blend it, do want they want with it... + + The routines assume they can write into this map using the ASCII code + with 32 subtracted for each char. +*/ +void TM_Init(uint16 *vram, int map_width, int map_height, int map_is_rotation); + +void TM_Cls(void); +void TM_Put(int x, int y, const char *str); +void TM_printf(int x, int y, const char *format, ...); + +#endif /* DS48_TEXTMODE_H */ diff --git a/arm9/include/touchwrap.h b/arm9/include/touchwrap.h new file mode 100644 index 0000000..2ee987a --- /dev/null +++ b/arm9/include/touchwrap.h @@ -0,0 +1,38 @@ +/* + ds48 - Nintendo DS ZX Spectrum emulator. + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS48_TOUCHWRAP_H +#define DS48_TOUCHWRAP_H + +/* Don't know whether I have a problem with my DS or the library, but sometimes + the touchscreen value is off (one co-ord generally completely out). + + To alleviate this, and as this is a simple touch screen keyboard, allow + touchs to be averaged if the config says so. And averaged touch just means + that two touchs have to happen within 5 pixels on X and Y before being + allowed. + + If not configured to average, this simply reads the touchscreen position + and returns true. +*/ +int AllowTouch(touchPosition *tp); + +#endif /* DS48_TOUCHWRAP_H */ diff --git a/arm9/include/z80.h b/arm9/include/z80.h new file mode 100644 index 0000000..e6bdfd9 --- /dev/null +++ b/arm9/include/z80.h @@ -0,0 +1,250 @@ +/* + + z80 - Z80 emulation + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ + +*/ + +#ifndef Z80_H +#define Z80_H "$Id$" + +/* Configuration +*/ +#include "z80_config.h" + + +/* ---------------------------------------- TYPES +*/ + +/* Large unsigned type +*/ +typedef unsigned long Z80Val; + + +/* 8-bit type. The emulation will exit with code 2 if this isn't 8 bits. +*/ +typedef unsigned char Z80Byte; + + +/* 8-bit signed type. The emulation will exit with code 2 if this isn't 8 bits. +*/ +typedef signed char Z80Relative; + + +/* 16-bit type. The emulation will exit with code 2 if this isn't 16 bits. +*/ +typedef unsigned short Z80Word; + + +/* A Z80 16-bit register. To access the HI/LO component use the indexes + Z80_HI_WORD and Z80_LO_WORD which will be initialised once Z80Init has been + called. +*/ +typedef union +{ + Z80Word w; + Z80Byte b[2]; +} Z80Reg; + +extern int Z80_HI_WORD; +extern int Z80_LO_WORD; + + +/* The processor +*/ +struct Z80Private; + +typedef struct +{ + Z80Word PC; + + Z80Reg AF; + Z80Reg BC; + Z80Reg DE; + Z80Reg HL; + + Z80Word AF_; + Z80Word BC_; + Z80Word DE_; + Z80Word HL_; + + Z80Reg IX; + Z80Reg IY; + + Z80Word SP; + + Z80Byte IFF1; + Z80Byte IFF2; + Z80Byte IM; + Z80Byte I; + Z80Byte R; + + struct Z80Private *priv; +} Z80; + + +/* Interfaces used to handle memory +*/ +typedef Z80Byte (*Z80ReadMemory)(Z80 *cpu, Z80Word address); +typedef void (*Z80WriteMemory)(Z80 *cpu, Z80Word address, Z80Byte value); + + +/* Interfaces needed to handle ports (IN/OUT commands) +*/ +typedef Z80Byte (*Z80ReadPort)(Z80 *cpu, Z80Word address); +typedef void (*Z80WritePort)(Z80 *cpu, Z80Word address, Z80Byte value); + + +/* Callback. Callback should return TRUE for processing to continue. +*/ +typedef int (*Z80Callback)(Z80 *cpu, Z80Val data); + + +/* Callback reasons + + eZ80_Instruction Called before the initial fetch for an instruction + (called just to once no matter how many bytes the + instruction is made up of). + + eZ80_EDHook Called when an undefined ED opcode is executed. + + eZ80_Halt Called when the HALT instruction is hit and released. + + eZ80_RETI Called when the RETI instruction is executed +*/ +typedef enum +{ + eZ80_Instruction, /* data = no cycles since reset */ + eZ80_EDHook, /* data = byte after ED opcode (only for NOP opcodes) */ + eZ80_Halt, /* data = 1 halt raised, 0 halt cleared by int */ + eZ80_RETI, /* data = ignored */ + eZ80_NO_CALLBACK /* leave at end */ +} Z80CallbackReason; + + +/* Flags in the F register +*/ +typedef enum +{ + eZ80_Carry =0x01, + eZ80_Neg =0x02, + eZ80_PV =0x04, + eZ80_Hidden3 =0x08, + eZ80_HalfCarry =0x10, + eZ80_Hidden5 =0x20, + eZ80_Zero =0x40, + eZ80_Sign =0x80 +} Z80FlagRegister; + + +/* Disassembly label -- only useful if ENABLE_DISASSEMBLER is set. + Labels are stored as an array, where a NULL in the label field marks + the end of the list. +*/ +typedef struct +{ + Z80Word address; + const char *label; +} Z80Label; + + +/* ---------------------------------------- INTERFACES +*/ + + +/* Initialises the processor. +*/ +#ifdef ENABLE_ARRAY_MEMORY +Z80 *Z80Init(Z80ReadPort read_port, + Z80WritePort write_port); +#else +Z80 *Z80Init(Z80ReadMemory read_memory, + Z80WriteMemory write_memory, + Z80ReadPort read_port, + Z80WritePort write_port, + Z80ReadMemory read_for_disassem); +#endif + + +/* Resets the processor. +*/ +void Z80Reset(Z80 *cpu); + + +/* Lodge a callback to be invoked after special events. Returns FALSE + if the callback couldn't be lodged (there is a max of 10 callbacks per + reason). +*/ +int Z80LodgeCallback(Z80 *cpu, + Z80CallbackReason reason, + Z80Callback callback); + + +/* Remove a callback. Does nothing if reason was not lodged with + Z80LodgeCallback() +*/ +void Z80RemoveCallback(Z80 *cpu, + Z80CallbackReason reason, + Z80Callback callback); + + +/* Cause an interrupt before the next opcode. + devbyte is the byte generated by the device (if any). +*/ +void Z80Interrupt(Z80 *cpu, Z80Byte devbyte); + + +/* Cause an NMI +*/ +void Z80NMI(Z80 *cpu); + + +/* Execute a single instruction. Returns FALSE if any callback returned + FALSE. +*/ +int Z80SingleStep(Z80 *cpu); + + +/* Executes until a callback returns FALSE (never returns otherwise) +*/ +void Z80Exec(Z80 *cpu); + + +/* Manipulate the cylce count of the Z80 +*/ +Z80Val Z80Cycles(Z80 *cpu); +void Z80ResetCycles(Z80 *cpu, Z80Val cycles); + + +/* Set address to label mappings for the disassembler +*/ +void Z80SetLabels(Z80Label labels[]); + + +/* Simple disassembly of memory accessed through read_for_disassem, or + Z80_MEMORY as appropriate. addr is updated on exit. +*/ +const char *Z80Disassemble(Z80 *cpu, Z80Word *addr); + +#endif + +/* END OF FILE */ diff --git a/arm9/include/z80_config.h b/arm9/include/z80_config.h new file mode 100644 index 0000000..7e02bb8 --- /dev/null +++ b/arm9/include/z80_config.h @@ -0,0 +1,59 @@ +/* + + z80 - Z80 emulation + + Copyright (C) 2007 Ian Cowburn <ianc@noddybox.co.uk> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ + +*/ + +#ifndef Z80_CONFIG_H +#define Z80_CONFIG_H "$Id$" + + +/* This file defines various compile-time configuration options + for the Z80 emulation +*/ + + +/* Define this to enable the disassembly interface +*/ +#define ENABLE_DISASSEM + + +/* Define this to enable the array-based memory model. In this mode + an externally visible Z80Byte array called Z80_MEMORY must be + defined. The macros RAMBOT and RAMTOP define the writable area of + memory and must be changed accordingly. + + In this mode the signature of Z80Init changes so that the memory functions + are not passed. ALL processor instances share the same memory. +#define ENABLE_ARRAY_MEMORY +*/ + +#ifdef ENABLE_ARRAY_MEMORY +#define RAMBOT 0x0000 +#define RAMTOP 0xffff +#endif + + +#endif + +/* END OF FILE */ diff --git a/arm9/include/z80_private.h b/arm9/include/z80_private.h new file mode 100644 index 0000000..bf51b7a --- /dev/null +++ b/arm9/include/z80_private.h @@ -0,0 +1,276 @@ +/* + + z80 - Z80 emulation + + Copyright (C) 2007 Ian Cowburn (ianc@noddybox.co.uk) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + ------------------------------------------------------------------------- + + $Id$ + + Private macros for Z80 + +*/ + +#ifndef Z80_PRIVATE_H +#define Z80_PRIVATE_H "$Id$" + +#include "z80_config.h" + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#define MAX_PER_CALLBACK 10 + + +/* ---------------------------------------- TYPES +*/ + +struct Z80Private +{ + Z80Val cycle; + + int halt; + + Z80Byte shift; + + int raise; + Z80Byte devbyte; + int nmi; + +#ifndef ENABLE_ARRAY_MEMORY + Z80ReadMemory disread; + + Z80ReadMemory mread; + Z80WriteMemory mwrite; +#endif + + Z80ReadPort pread; + Z80WritePort pwrite; + + Z80Callback callback[eZ80_NO_CALLBACK][MAX_PER_CALLBACK]; + + int last_cb; +}; + +#define PRIV cpu->priv + + +/* ---------------------------------------- ARRAY MEMORY +*/ + +#ifdef ENABLE_ARRAY_MEMORY +extern Z80Byte Z80_MEMORY[]; +#endif + + +/* ---------------------------------------- MACROS +*/ + +/* NOTE: A lot of these macros assume you have a variable called 'cpu' + which is a pointer to Z80 +*/ + + +/* Invoke a callback class +*/ +#define CALLBACK(r,d) do \ + { \ + int f; \ + \ + for(f=0;f<MAX_PER_CALLBACK;f++) \ + if (PRIV->callback[r][f]) \ + PRIV->last_cb &= \ + PRIV->callback[r][f](cpu,d);\ + } while(0) + +/* Flag register +*/ +#define C_Z80 0x01 +#define N_Z80 0x02 +#define P_Z80 0x04 +#define V_Z80 P_Z80 +#define H_Z80 0x10 +#define Z_Z80 0x40 +#define S_Z80 0x80 + +#define B3_Z80 0x08 +#define B5_Z80 0x20 + + +#define SET(v,b) (v)|=b +#define CLR(v,b) (v)&=~(b) + +#define SETFLAG(f) SET(cpu->AF.b[LO],f) +#define CLRFLAG(f) CLR(cpu->AF.b[LO],f) + +#ifdef ENABLE_ARRAY_MEMORY + +#define PEEK(addr) Z80_MEMORY[addr] + +static inline Z80Word PEEKW(Z80Word addr) +{ + return (PEEK(addr) | (Z80Word)PEEK(addr+1)<<8); +} + +#define POKE(addr,val) do \ + { \ + Z80Word ba=addr; \ + if (ba>=RAMBOT && ba<=RAMTOP) \ + Z80_MEMORY[ba]=val; \ + } while(0) + +#define POKEW(addr,val) do \ + { \ + Z80Word wa=addr; \ + Z80Word wv=val; \ + POKE(wa,wv); \ + POKE(wa+1,wv>>8); \ + } while(0) + + +#define FETCH_BYTE (Z80_MEMORY[cpu->PC++]) +#define FETCH_WORD (cpu->PC+=2, \ + Z80_MEMORY[cpu->PC-2]| \ + ((Z80Word)Z80_MEMORY[cpu->PC-1]<<8)) + +#else + +#define PEEK(addr) (PRIV->mread(cpu,addr)) +#define PEEKW(addr) FPEEKW(cpu,addr) + +#define POKE(addr,val) PRIV->mwrite(cpu,addr,val) +#define POKEW(addr,val) FPOKEW(cpu,addr,val) + +#define FETCH_BYTE (PRIV->mread(cpu,cpu->PC++)) +#define FETCH_WORD (cpu->PC+=2,FPEEKW(cpu,cpu->PC-2)) + +#endif + + +#define IS_C (cpu->AF.b[LO]&C_Z80) +#define IS_N (cpu->AF.b[LO]&N_Z80) +#define IS_P (cpu->AF.b[LO]&P_Z80) +#define IS_H (cpu->AF.b[LO]&H_Z80) +#define IS_Z (cpu->AF.b[LO]&Z_Z80) +#define IS_S (cpu->AF.b[LO]&S_Z80) + +#define CARRY IS_C + +#define IS_IX_IY (PRIV->shift==0xdd || PRIV->shift==0xfd) +#define OFFSET(off) off=(IS_IX_IY ? (Z80Relative)FETCH_BYTE:0) + +#define TSTATE(n) PRIV->cycle+=n + +#define ADD_R(v) cpu->R=((cpu->R&0x80)|((cpu->R+(v))&0x7f)) +#define INC_R ADD_R(1) + +#ifdef ENABLE_ARRAY_MEMORY + +#define PUSH(REG) do \ + { \ + Z80Word pv=REG; \ + cpu->SP-=2; \ + POKE(cpu->SP,pv); \ + POKE(cpu->SP+1,pv>>8); \ + } while(0) + +#else + +#define PUSH(REG) do \ + { \ + Z80Word pushv=REG; \ + cpu->SP-=2; \ + PRIV->mwrite(cpu,cpu->SP,pushv); \ + PRIV->mwrite(cpu,cpu->SP+1,pushv>>8);\ + } while(0) +#endif + +#define POP(REG) do \ + { \ + REG=PEEK(cpu->SP) | \ + (Z80Word)PEEK(cpu->SP+1)<<8; \ + cpu->SP+=2; \ + } while(0) + +#define SETHIDDEN(res) cpu->AF.b[LO]=(cpu->AF.b[LO]&~(B3_Z80|B5_Z80))|\ + ((res)&(B3_Z80|B5_Z80)) + +#define CALL do \ + { \ + PUSH(cpu->PC+2); \ + cpu->PC=PEEKW(cpu->PC); \ + } while(0) + +#define NOCALL cpu->PC+=2 +#define JP cpu->PC=PEEKW(cpu->PC) +#define NOJP cpu->PC+=2 +#define JR cpu->PC+=(Z80Relative)PEEK(cpu->PC)+1 +#define NOJR cpu->PC++ + +#define OUT(P,V) do \ + { \ + if (PRIV->pwrite) \ + PRIV->pwrite(cpu,P,V); \ + } while(0) + +#define IN(P) (PRIV->pread?PRIV->pread(cpu,P):0) + + + +/* ---------------------------------------- LABELS +*/ +extern Z80Label *z80_labels; + + +/* ---------------------------------------- GLOBAL GENERAL OPCODES/ROUTINES +*/ +void Z80_Decode(Z80 *cpu, Z80Byte opcode); +void Z80_InitialiseInternals(void); + + +/* ---------------------------------------- DISASSEMBLY +*/ +#ifdef ENABLE_DISASSEM +typedef void (*DIS_OP_CALLBACK)(Z80 *z80, Z80Byte op, Z80Word *pc); + +extern DIS_OP_CALLBACK dis_CB_opcode[]; +extern DIS_OP_CALLBACK dis_DD_opcode[]; +extern DIS_OP_CALLBACK dis_DD_CB_opcode[]; +extern DIS_OP_CALLBACK dis_ED_opcode[]; +extern DIS_OP_CALLBACK dis_FD_opcode[]; +extern DIS_OP_CALLBACK dis_FD_CB_opcode[]; +extern DIS_OP_CALLBACK dis_opcode_z80[]; + +const char *Z80_Dis_Printf(const char *format, ...); + +Z80Byte Z80_Dis_FetchByte(Z80 *cpu, Z80Word *pc); +Z80Word Z80_Dis_FetchWord(Z80 *cpu, Z80Word *pc); + +void Z80_Dis_Set(const char *op, const char *arg); +const char *Z80_Dis_GetOp(void); +const char *Z80_Dis_GetArg(void); +#endif /* ENABLE_DISASSEM */ + +#endif /* Z80_PRIVATE_H */ + +/* END OF FILE */ |