1 /******************************************************************************/ 2 /* Mednafen Sony PS1 Emulation Module */ 3 /******************************************************************************/ 4 /* psx.h: 5 ** Copyright (C) 2011-2016 Mednafen Team 6 ** 7 ** This program is free software; you can redistribute it and/or 8 ** modify it under the terms of the GNU General Public License 9 ** as published by the Free Software Foundation; either version 2 10 ** of the License, or (at your option) any later version. 11 ** 12 ** This program is distributed in the hope that it will be useful, 13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ** GNU General Public License for more details. 16 ** 17 ** You should have received a copy of the GNU General Public License 18 ** along with this program; if not, write to the Free Software Foundation, Inc., 19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __MDFN_PSX_PSX_H 23 #define __MDFN_PSX_PSX_H 24 25 #include <mednafen/mednafen.h> 26 #include <mednafen/general.h> 27 28 using namespace Mednafen; 29 30 #include <trio/trio.h> 31 32 #include "masmem.h" 33 34 // 35 // Comment out these 2 defines for extra speeeeed. 36 // 37 #define PSX_DBGPRINT_ENABLE 1 38 #define PSX_EVENT_SYSTEM_CHECKS 1 39 40 // 41 // It's highly unlikely the user will want these if they're intentionally compiling without the debugger. 42 #ifndef WANT_DEBUGGER 43 #undef PSX_DBGPRINT_ENABLE 44 #undef PSX_EVENT_SYSTEM_CHECKS 45 #endif 46 // 47 // 48 // 49 50 namespace MDFN_IEN_PSX 51 { 52 #define PSX_DBG_ERROR 0 // Emulator-level error. 53 #define PSX_DBG_WARNING 1 // Warning about game doing questionable things/hitting stuff that might not be emulated correctly. 54 #define PSX_DBG_BIOS_PRINT 2 // BIOS printf/putchar output. 55 #define PSX_DBG_SPARSE 3 // Sparse(relatively) information debug messages(CDC commands). 56 #define PSX_DBG_FLOOD 4 // Heavy informational debug messages(GPU commands; TODO). 57 58 #if PSX_DBGPRINT_ENABLE 59 void PSX_DBG(unsigned level, const char *format, ...) noexcept MDFN_COLD MDFN_FORMATSTR(gnu_printf, 2, 3); 60 void PSX_DBG_BIOS_PUTC(uint8 c) noexcept; 61 62 #define PSX_WARNING(format, ...) { PSX_DBG(PSX_DBG_WARNING, format "\n", ## __VA_ARGS__); } 63 #define PSX_DBGINFO(format, ...) { } 64 #else 65 static INLINE void PSX_DBG(unsigned level, const char* format, ...) { } 66 static INLINE void PSX_DBG_BIOS_PUTC(uint8 c) { } 67 static INLINE void PSX_WARNING(const char* format, ...) { } 68 static INLINE void PSX_DBGINFO(const char* format, ...) { } 69 #endif 70 71 typedef int32 pscpu_timestamp_t; 72 73 bool MDFN_FASTCALL PSX_EventHandler(const pscpu_timestamp_t timestamp); 74 75 void MDFN_FASTCALL PSX_MemWrite8(pscpu_timestamp_t timestamp, uint32 A, uint32 V); 76 void MDFN_FASTCALL PSX_MemWrite16(pscpu_timestamp_t timestamp, uint32 A, uint32 V); 77 void MDFN_FASTCALL PSX_MemWrite24(pscpu_timestamp_t timestamp, uint32 A, uint32 V); 78 void MDFN_FASTCALL PSX_MemWrite32(pscpu_timestamp_t timestamp, uint32 A, uint32 V); 79 80 uint8 MDFN_FASTCALL PSX_MemRead8(pscpu_timestamp_t ×tamp, uint32 A); 81 uint16 MDFN_FASTCALL PSX_MemRead16(pscpu_timestamp_t ×tamp, uint32 A); 82 uint32 MDFN_FASTCALL PSX_MemRead24(pscpu_timestamp_t ×tamp, uint32 A); 83 uint32 MDFN_FASTCALL PSX_MemRead32(pscpu_timestamp_t ×tamp, uint32 A); 84 85 uint8 PSX_MemPeek8(uint32 A); 86 uint16 PSX_MemPeek16(uint32 A); 87 uint32 PSX_MemPeek32(uint32 A); 88 89 // Should write to WO-locations if possible 90 void PSX_MemPoke8(uint32 A, uint8 V); 91 void PSX_MemPoke16(uint32 A, uint16 V); 92 void PSX_MemPoke32(uint32 A, uint32 V); 93 94 void PSX_RequestMLExit(void); 95 void ForceEventUpdates(const pscpu_timestamp_t timestamp); 96 97 enum 98 { 99 PSX_EVENT__SYNFIRST = 0, 100 PSX_EVENT_GPU, 101 PSX_EVENT_CDC, 102 //PSX_EVENT_SPU, 103 PSX_EVENT_TIMER, 104 PSX_EVENT_DMA, 105 PSX_EVENT_FIO, 106 PSX_EVENT__SYNLAST, 107 PSX_EVENT__COUNT, 108 }; 109 110 #define PSX_EVENT_MAXTS 0x20000000 111 void PSX_SetEventNT(const int type, const pscpu_timestamp_t next_timestamp); 112 113 void PSX_SetDMACycleSteal(unsigned stealage); 114 115 void PSX_GPULineHook(const pscpu_timestamp_t timestamp, const pscpu_timestamp_t line_timestamp, bool vsync, uint32 *pixels, const MDFN_PixelFormat* const format, const unsigned width, const unsigned pix_clock_offset, const unsigned pix_clock, const unsigned pix_clock_divider); 116 117 uint32 PSX_GetRandU32(uint32 mina, uint32 maxa); 118 } 119 120 121 #include "dis.h" 122 #include "cpu.h" 123 #include "irq.h" 124 #include "gpu.h" 125 #include "dma.h" 126 //#include "sio.h" 127 #include "debug.h" 128 129 namespace MDFN_IEN_PSX 130 { 131 class PS_CDC; 132 class PS_SPU; 133 134 MDFN_HIDE extern PS_CPU *CPU; 135 MDFN_HIDE extern PS_CDC *CDC; 136 MDFN_HIDE extern PS_SPU *SPU; 137 MDFN_HIDE extern MultiAccessSizeMem<2048 * 1024, false> MainRAM; 138 } 139 140 141 #endif 142