1 #ifndef __MDFN_PSX_PSX_H
2 #define __MDFN_PSX_PSX_H
3
4 #include <stdint.h>
5
6 #include "../masmem.h"
7 #include "../mednafen-types.h"
8 #include "../video/surface.h"
9
10 // Comment out these 2 defines for extra speeeeed.
11 #define PSX_DBGPRINT_ENABLE 1
12 #define PSX_EVENT_SYSTEM_CHECKS 1
13
14 // It's highly unlikely the user will want these if they're intentionally compiling without the debugger.
15 #ifndef WANT_DEBUGGER
16 #undef PSX_DBGPRINT_ENABLE
17 #undef PSX_EVENT_SYSTEM_CHECKS
18 #endif
19
20 #define PSX_DBG_ERROR 0 // Emulator-level error.
21 #define PSX_DBG_WARNING 1 // Warning about game doing questionable things/hitting stuff that might not be emulated correctly.
22 #define PSX_DBG_BIOS_PRINT 2 // BIOS printf/putchar output.
23 #define PSX_DBG_SPARSE 3 // Sparse(relatively) information debug messages(CDC commands).
24 #define PSX_DBG_FLOOD 4 // Heavy informational debug messages(GPU commands; TODO).
25
26 #if PSX_DBGPRINT_ENABLE
27 void PSX_DBG(unsigned level, const char *format, ...);
28
29 #define PSX_WARNING(format, ...) { PSX_DBG(PSX_DBG_WARNING, format "\n", ## __VA_ARGS__); }
30 #define PSX_DBGINFO(format, ...) { }
31 #else
PSX_DBG(unsigned level,const char * format,...)32 static void PSX_DBG(unsigned level, const char* format, ...) { }
PSX_WARNING(const char * format,...)33 static void PSX_WARNING(const char* format, ...) { }
PSX_DBGINFO(const char * format,...)34 static void PSX_DBGINFO(const char* format, ...) { }
35 #endif
36
37 typedef int32_t pscpu_timestamp_t;
38
39 bool MDFN_FASTCALL PSX_EventHandler(const int32_t timestamp);
40
41 void MDFN_FASTCALL PSX_MemWrite8(int32_t timestamp, uint32_t A, uint32_t V);
42 void MDFN_FASTCALL PSX_MemWrite16(int32_t timestamp, uint32_t A, uint32_t V);
43 void MDFN_FASTCALL PSX_MemWrite24(int32_t timestamp, uint32_t A, uint32_t V);
44 void MDFN_FASTCALL PSX_MemWrite32(int32_t timestamp, uint32_t A, uint32_t V);
45
46 uint8_t MDFN_FASTCALL PSX_MemRead8(int32_t ×tamp, uint32_t A);
47 uint16_t MDFN_FASTCALL PSX_MemRead16(int32_t ×tamp, uint32_t A);
48 uint32_t MDFN_FASTCALL PSX_MemRead24(int32_t ×tamp, uint32_t A);
49 uint32_t MDFN_FASTCALL PSX_MemRead32(int32_t ×tamp, uint32_t A);
50
51 uint8_t PSX_MemPeek8(uint32_t A);
52 uint16_t PSX_MemPeek16(uint32_t A);
53 uint32_t PSX_MemPeek32(uint32_t A);
54
55 // Should write to WO-locations if possible
56 void PSX_MemPoke8(uint32_t A, uint8_t V);
57 void PSX_MemPoke16(uint32_t A, uint16_t V);
58 void PSX_MemPoke32(uint32_t A, uint32_t V);
59
60 void PSX_RequestMLExit(void);
61 void ForceEventUpdates(const int32_t timestamp);
62
63 enum
64 {
65 PSX_EVENT__SYNFIRST = 0,
66 PSX_EVENT_GPU,
67 PSX_EVENT_CDC,
68 //PSX_EVENT_SPU,
69 PSX_EVENT_TIMER,
70 PSX_EVENT_DMA,
71 PSX_EVENT_FIO,
72 PSX_EVENT__SYNLAST,
73 PSX_EVENT__COUNT
74 };
75
76 #define PSX_EVENT_MAXTS 0x20000000
77 void PSX_SetEventNT(const int type, const int32_t next_timestamp);
78
79 void PSX_SetDMACycleSteal(unsigned stealage);
80
81 // PSX_GPULineHook modified to take surface pitch (in pixels) and upscale factor for software renderer internal upscaling
82 void PSX_GPULineHook(const int32_t timestamp, const int32_t line_timestamp, bool vsync, uint32_t *pixels, const MDFN_PixelFormat* const format, const unsigned width, const unsigned pix_clock_offset, const unsigned pix_clock, const unsigned pix_clock_divider, const unsigned surf_pitchinpix, const unsigned upscale_factor);
83
84 uint32_t PSX_GetRandU32(uint32_t mina, uint32_t maxa);
85
86 #include "dis.h"
87 #include "cpu.h"
88 #include "irq.h"
89 #include "gpu.h"
90 #include "dma.h"
91 #include "debug.h"
92
93 class PS_CDC;
94 class PS_SPU;
95
96 extern PS_CPU *PSX_CPU;
97 extern PS_CDC *PSX_CDC;
98 extern PS_SPU *PSX_SPU;
99 extern MultiAccessSizeMem<512 * 1024, uint32, false> *BIOSROM;
100 extern MultiAccessSizeMem<2048 * 1024, uint32_t, false> *MainRAM;
101 extern MultiAccessSizeMem<1024, uint32_t, false> *ScratchRAM;
102
103 #ifdef HAVE_LIGHTREC
104 enum DYNAREC {DYNAREC_DISABLED, DYNAREC_EXECUTE, DYNAREC_EXECUTE_ONE, DYNAREC_RUN_INTERPRETER};
105 extern enum DYNAREC psx_dynarec;
106 #endif
107
108 #define OVERCLOCK_SHIFT 8
109 extern int32_t psx_overclock_factor;
110
overclock_device_to_cpu(int32_t & clock)111 static INLINE void overclock_device_to_cpu(int32_t &clock) {
112 if (psx_overclock_factor) {
113 int64_t n = clock;
114
115 n = (n * psx_overclock_factor) + (1 << (OVERCLOCK_SHIFT)) - 1;
116
117 n >>= OVERCLOCK_SHIFT;
118
119 clock = n;
120 }
121 }
122
overclock_cpu_to_device(int32_t & clock)123 static INLINE void overclock_cpu_to_device(int32_t &clock) {
124 if (psx_overclock_factor) {
125 int64_t n = clock;
126
127 n = (n << OVERCLOCK_SHIFT) + (psx_overclock_factor - 1);
128
129 n /= psx_overclock_factor;
130
131 clock = n;
132 }
133 }
134
135 extern unsigned psx_gpu_overclock_shift;
136
137 #endif
138