├── .gitignore ├── 3rdParty └── directx │ └── lib │ ├── ddraw.lib │ └── dxguid.lib ├── CREDITS.txt ├── Gfx #1.3.h ├── MAME License.txt ├── angrylion.sln ├── angrylion.vcproj ├── main.cpp ├── n64video.cpp ├── tctables.h └── z64.h /.gitignore: -------------------------------------------------------------------------------- 1 | /angrylion.ncb 2 | /Debug 3 | /Release 4 | /*.suo 5 | /*.user 6 | -------------------------------------------------------------------------------- /3rdParty/directx/lib/ddraw.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/project64/angrylion-rdp/093754a4a53437925824317ab22ce6a56748fe14/3rdParty/directx/lib/ddraw.lib -------------------------------------------------------------------------------- /3rdParty/directx/lib/dxguid.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/project64/angrylion-rdp/093754a4a53437925824317ab22ce6a56748fe14/3rdParty/directx/lib/dxguid.lib -------------------------------------------------------------------------------- /CREDITS.txt: -------------------------------------------------------------------------------- 1 | This little RDP plugin was initially based on MESS 0.128 source code. 2 | Many thanks to Ville Linde, MooglyGuy and other people who wrote the RDP implementation in MESS 0.128. The rest of the code is by me, angrylion. 3 | Many thanks to people who helped me in various ways: olivieryuyu, marshallh, LaC, oman, pinchy, ziggy, FatCat and other folks I forgot. 4 | The code comes under MAME license. 5 | Sorry for my terrible English. 6 | 7 | angrylion 8 | -------------------------------------------------------------------------------- /Gfx #1.3.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | Common gfx plugin spec, version #1.3 maintained by zilmar (zilmar@emulation64.com) 3 | 4 | All questions or suggestions should go through the mailing list. 5 | http://www.egroups.com/group/Plugin64-Dev 6 | *********************************************************************************** 7 | 8 | Notes: 9 | ------ 10 | 11 | Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which 12 | are both passed to the DLL in InitiateGFX will generate an Interrupt from with in 13 | the plugin. 14 | 15 | The Setting of the RSP flags and generating an SP interrupt should not be done in 16 | the plugin 17 | 18 | **********************************************************************************/ 19 | #ifndef _GFX_H_INCLUDED__ 20 | #define _GFX_H_INCLUDED__ 21 | 22 | #if defined(__cplusplus) 23 | extern "C" { 24 | #endif 25 | 26 | /* Plugin types */ 27 | #define PLUGIN_TYPE_GFX 2 28 | 29 | #define EXPORT __declspec(dllexport) 30 | #define CALL _cdecl 31 | 32 | /***** Structures *****/ 33 | typedef struct { 34 | WORD Version; /* Set to 0x0103 */ 35 | WORD Type; /* Set to PLUGIN_TYPE_GFX */ 36 | char Name[100]; /* Name of the DLL */ 37 | 38 | /* If DLL supports memory these memory options then set them to TRUE or FALSE 39 | if it does not support it */ 40 | BOOL NormalMemory; /* a normal BYTE array */ 41 | BOOL MemoryBswaped; /* a normal BYTE array where the memory has been pre 42 | bswap on a dword (32 bits) boundry */ 43 | } PLUGIN_INFO; 44 | 45 | typedef struct { 46 | HWND hWnd; /* Render window */ 47 | HWND hStatusBar; /* if render window does not have a status bar then this is NULL */ 48 | 49 | BOOL MemoryBswaped; // If this is set to TRUE, then the memory has been pre 50 | // bswap on a dword (32 bits) boundry 51 | // eg. the first 8 bytes are stored like this: 52 | // 4 3 2 1 8 7 6 5 53 | 54 | BYTE * HEADER; // This is the rom header (first 40h bytes of the rom 55 | // This will be in the same memory format as the rest of the memory. 56 | BYTE * RDRAM; 57 | BYTE * DMEM; 58 | BYTE * IMEM; 59 | 60 | DWORD * MI_INTR_REG; 61 | 62 | DWORD * DPC_START_REG; 63 | DWORD * DPC_END_REG; 64 | DWORD * DPC_CURRENT_REG; 65 | DWORD * DPC_STATUS_REG; 66 | DWORD * DPC_CLOCK_REG; 67 | DWORD * DPC_BUFBUSY_REG; 68 | DWORD * DPC_PIPEBUSY_REG; 69 | DWORD * DPC_TMEM_REG; 70 | 71 | DWORD * VI_STATUS_REG; 72 | DWORD * VI_ORIGIN_REG; 73 | DWORD * VI_WIDTH_REG; 74 | DWORD * VI_INTR_REG; 75 | DWORD * VI_V_CURRENT_LINE_REG; 76 | DWORD * VI_TIMING_REG; 77 | DWORD * VI_V_SYNC_REG; 78 | DWORD * VI_H_SYNC_REG; 79 | DWORD * VI_LEAP_REG; 80 | DWORD * VI_H_START_REG; 81 | DWORD * VI_V_START_REG; 82 | DWORD * VI_V_BURST_REG; 83 | DWORD * VI_X_SCALE_REG; 84 | DWORD * VI_Y_SCALE_REG; 85 | 86 | void (*CheckInterrupts)( void ); 87 | } GFX_INFO; 88 | 89 | /****************************************************************** 90 | Function: CaptureScreen 91 | Purpose: This function dumps the current frame to a file 92 | input: pointer to the directory to save the file to 93 | output: none 94 | *******************************************************************/ 95 | EXPORT void CALL CaptureScreen ( char * Directory ); 96 | 97 | /****************************************************************** 98 | Function: ChangeWindow 99 | Purpose: to change the window between fullscreen and window 100 | mode. If the window was in fullscreen this should 101 | change the screen to window mode and vice vesa. 102 | input: none 103 | output: none 104 | *******************************************************************/ 105 | EXPORT void CALL ChangeWindow (void); 106 | 107 | /****************************************************************** 108 | Function: CloseDLL 109 | Purpose: This function is called when the emulator is closing 110 | down allowing the dll to de-initialise. 111 | input: none 112 | output: none 113 | *******************************************************************/ 114 | EXPORT void CALL CloseDLL (void); 115 | 116 | /****************************************************************** 117 | Function: DllAbout 118 | Purpose: This function is optional function that is provided 119 | to give further information about the DLL. 120 | input: a handle to the window that calls this function 121 | output: none 122 | *******************************************************************/ 123 | EXPORT void CALL DllAbout ( HWND hParent ); 124 | 125 | /****************************************************************** 126 | Function: DllConfig 127 | Purpose: This function is optional function that is provided 128 | to allow the user to configure the dll 129 | input: a handle to the window that calls this function 130 | output: none 131 | *******************************************************************/ 132 | EXPORT void CALL DllConfig ( HWND hParent ); 133 | 134 | /****************************************************************** 135 | Function: DllTest 136 | Purpose: This function is optional function that is provided 137 | to allow the user to test the dll 138 | input: a handle to the window that calls this function 139 | output: none 140 | *******************************************************************/ 141 | EXPORT void CALL DllTest ( HWND hParent ); 142 | 143 | 144 | EXPORT void CALL ReadScreen(void **dest, long *width, long *height); 145 | 146 | /****************************************************************** 147 | Function: DrawScreen 148 | Purpose: This function is called when the emulator receives a 149 | WM_PAINT message. This allows the gfx to fit in when 150 | it is being used in the desktop. 151 | input: none 152 | output: none 153 | *******************************************************************/ 154 | EXPORT void CALL DrawScreen (void); 155 | 156 | /****************************************************************** 157 | Function: GetDllInfo 158 | Purpose: This function allows the emulator to gather information 159 | about the dll by filling in the PluginInfo structure. 160 | input: a pointer to a PLUGIN_INFO stucture that needs to be 161 | filled by the function. (see def above) 162 | output: none 163 | *******************************************************************/ 164 | EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo ); 165 | 166 | /****************************************************************** 167 | Function: InitiateGFX 168 | Purpose: This function is called when the DLL is started to give 169 | information from the emulator that the n64 graphics 170 | uses. This is not called from the emulation thread. 171 | Input: Gfx_Info is passed to this function which is defined 172 | above. 173 | Output: TRUE on success 174 | FALSE on failure to initialise 175 | 176 | ** note on interrupts **: 177 | To generate an interrupt set the appropriate bit in MI_INTR_REG 178 | and then call the function CheckInterrupts to tell the emulator 179 | that there is a waiting interrupt. 180 | *******************************************************************/ 181 | EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info); 182 | 183 | /****************************************************************** 184 | Function: MoveScreen 185 | Purpose: This function is called in response to the emulator 186 | receiving a WM_MOVE passing the xpos and ypos passed 187 | from that message. 188 | input: xpos - the x-coordinate of the upper-left corner of the 189 | client area of the window. 190 | ypos - y-coordinate of the upper-left corner of the 191 | client area of the window. 192 | output: none 193 | *******************************************************************/ 194 | EXPORT void CALL MoveScreen (int xpos, int ypos); 195 | 196 | /****************************************************************** 197 | Function: ProcessDList 198 | Purpose: This function is called when there is a Dlist to be 199 | processed. (High level GFX list) 200 | input: none 201 | output: none 202 | *******************************************************************/ 203 | EXPORT void CALL ProcessDList(void); 204 | 205 | /****************************************************************** 206 | Function: ProcessRDPList 207 | Purpose: This function is called when there is a Dlist to be 208 | processed. (Low level GFX list) 209 | input: none 210 | output: none 211 | *******************************************************************/ 212 | EXPORT void CALL ProcessRDPList(void); 213 | 214 | /****************************************************************** 215 | Function: RomClosed 216 | Purpose: This function is called when a rom is closed. 217 | input: none 218 | output: none 219 | *******************************************************************/ 220 | EXPORT void CALL RomClosed (void); 221 | 222 | /****************************************************************** 223 | Function: RomOpen 224 | Purpose: This function is called when a rom is open. (from the 225 | emulation thread) 226 | input: none 227 | output: none 228 | *******************************************************************/ 229 | EXPORT void CALL RomOpen (void); 230 | 231 | /****************************************************************** 232 | Function: ShowCFB 233 | Purpose: Useally once Dlists are started being displayed, cfb is 234 | ignored. This function tells the dll to start displaying 235 | them again. 236 | input: none 237 | output: none 238 | *******************************************************************/ 239 | EXPORT void CALL ShowCFB (void); 240 | 241 | /****************************************************************** 242 | Function: UpdateScreen 243 | Purpose: This function is called in response to a vsync of the 244 | screen were the VI bit in MI_INTR_REG has already been 245 | set 246 | input: none 247 | output: none 248 | *******************************************************************/ 249 | EXPORT void CALL UpdateScreen (void); 250 | 251 | /****************************************************************** 252 | Function: ViStatusChanged 253 | Purpose: This function is called to notify the dll that the 254 | ViStatus registers value has been changed. 255 | input: none 256 | output: none 257 | *******************************************************************/ 258 | EXPORT void CALL ViStatusChanged (void); 259 | 260 | /****************************************************************** 261 | Function: ViWidthChanged 262 | Purpose: This function is called to notify the dll that the 263 | ViWidth registers value has been changed. 264 | input: none 265 | output: none 266 | *******************************************************************/ 267 | EXPORT void CALL ViWidthChanged (void); 268 | 269 | 270 | /****************************************************************** 271 | Function: FrameBufferWrite 272 | Purpose: This function is called to notify the dll that the 273 | frame buffer has been modified by CPU at the given address. 274 | input: addr rdram address 275 | val val 276 | size 1 = BYTE, 2 = WORD, 4 = DWORD 277 | output: none 278 | *******************************************************************/ 279 | EXPORT void CALL FBWrite(DWORD, DWORD); 280 | 281 | typedef struct 282 | { 283 | DWORD addr; 284 | DWORD val; 285 | DWORD size; // 1 = BYTE, 2 = WORD, 4=DWORD 286 | } FrameBufferModifyEntry; 287 | 288 | /****************************************************************** 289 | Function: FrameBufferWriteList 290 | Purpose: This function is called to notify the dll that the 291 | frame buffer has been modified by CPU at the given address. 292 | input: FrameBufferModifyEntry *plist 293 | size = size of the plist, max = 1024 294 | output: none 295 | *******************************************************************/ 296 | EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, DWORD size); 297 | 298 | /****************************************************************** 299 | Function: FrameBufferRead 300 | Purpose: This function is called to notify the dll that the 301 | frame buffer memory is beening read at the given address. 302 | DLL should copy content from its render buffer to the frame buffer 303 | in N64 RDRAM 304 | DLL is responsible to maintain its own frame buffer memory addr list 305 | DLL should copy 4KB block content back to RDRAM frame buffer. 306 | Emulator should not call this function again if other memory 307 | is read within the same 4KB range 308 | input: addr rdram address 309 | val val 310 | size 1 = BYTE, 2 = WORD, 4 = DWORD 311 | output: none 312 | *******************************************************************/ 313 | EXPORT void CALL FBRead(DWORD addr); 314 | 315 | /************************************************************************ 316 | Function: FBGetFrameBufferInfo 317 | Purpose: This function is called by the emulator core to retrieve depth 318 | buffer information from the video plugin in order to be able 319 | to notify the video plugin about CPU depth buffer read/write 320 | operations 321 | 322 | size: 323 | = 1 byte 324 | = 2 word (16 bit) <-- this is N64 default depth buffer format 325 | = 4 dword (32 bit) 326 | 327 | when depth buffer information is not available yet, set all values 328 | in the FrameBufferInfo structure to 0 329 | 330 | input: FrameBufferInfo *pinfo 331 | pinfo is pointed to a FrameBufferInfo structure which to be 332 | filled in by this function 333 | output: Values are return in the FrameBufferInfo structure 334 | ************************************************************************/ 335 | EXPORT void CALL FBGetFrameBufferInfo(void *pinfo); 336 | 337 | #if defined(__cplusplus) 338 | } 339 | #endif 340 | #endif //_GFX_H_INCLUDED__ 341 | -------------------------------------------------------------------------------- /MAME License.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/project64/angrylion-rdp/093754a4a53437925824317ab22ce6a56748fe14/MAME License.txt -------------------------------------------------------------------------------- /angrylion.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "angrylion", "angrylion.vcproj", "{D86C6E84-3371-4B20-8620-A703FF3F2CC5}" 4 | EndProject 5 | Global 6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 7 | Debug|Win32 = Debug|Win32 8 | Release|Win32 = Release|Win32 9 | EndGlobalSection 10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 11 | {D86C6E84-3371-4B20-8620-A703FF3F2CC5}.Debug|Win32.ActiveCfg = Debug|Win32 12 | {D86C6E84-3371-4B20-8620-A703FF3F2CC5}.Debug|Win32.Build.0 = Debug|Win32 13 | {D86C6E84-3371-4B20-8620-A703FF3F2CC5}.Release|Win32.ActiveCfg = Release|Win32 14 | {D86C6E84-3371-4B20-8620-A703FF3F2CC5}.Release|Win32.Build.0 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | EndGlobal 20 | -------------------------------------------------------------------------------- /angrylion.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 54 | 57 | 60 | 63 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 98 | 99 | 107 | 110 | 113 | 116 | 119 | 122 | 142 | 145 | 148 | 151 | 168 | 171 | 174 | 177 | 180 | 183 | 186 | 189 | 190 | 191 | 192 | 193 | 194 | 198 | 201 | 202 | 205 | 206 | 207 | 211 | 214 | 215 | 218 | 219 | 222 | 223 | 224 | 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "z64.h" 2 | #include "Gfx #1.3.h" 3 | 4 | extern const int screen_width = 1024, screen_height = 768; 5 | 6 | LPDIRECTDRAW7 lpdd = 0; 7 | LPDIRECTDRAWSURFACE7 lpddsprimary; 8 | LPDIRECTDRAWSURFACE7 lpddsback; 9 | DDSURFACEDESC2 ddsd; 10 | HRESULT res; 11 | RECT dst, src; 12 | INT32 pitchindwords; 13 | 14 | FILE* zeldainfo = 0; 15 | int ProcessDListShown = 0; 16 | extern int SaveLoaded; 17 | extern UINT32 command_counter; 18 | 19 | extern GFX_INFO gfx; 20 | 21 | int rdp_init(); 22 | int rdp_close(); 23 | int rdp_update(); 24 | void rdp_process_list(void); 25 | extern INLINE void popmessage(const char* err, ...); 26 | extern INLINE void fatalerror(const char* err, ...); 27 | 28 | 29 | EXPORT void CALL CaptureScreen ( char * Directory ) 30 | { 31 | } 32 | 33 | 34 | EXPORT void CALL ChangeWindow (void) 35 | { 36 | } 37 | 38 | 39 | EXPORT void CALL CloseDLL (void) 40 | { 41 | 42 | } 43 | 44 | 45 | EXPORT void CALL DllAbout ( HWND hParent ) 46 | { 47 | popmessage("angrylion's RDP, unpublished beta. MESS source code used."); 48 | } 49 | 50 | 51 | EXPORT void CALL DllConfig ( HWND hParent ) 52 | { 53 | popmessage("Nothing to configure"); 54 | } 55 | 56 | 57 | EXPORT void CALL DllTest ( HWND hParent ) 58 | { 59 | } 60 | 61 | 62 | EXPORT void CALL ReadScreen(void **dest, long *width, long *height) 63 | { 64 | } 65 | 66 | 67 | EXPORT void CALL DrawScreen (void) 68 | { 69 | } 70 | 71 | 72 | EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo ) 73 | { 74 | PluginInfo->Version = 0x0103; 75 | PluginInfo->Type = PLUGIN_TYPE_GFX; 76 | sprintf (PluginInfo->Name, "My little plugin"); 77 | 78 | 79 | 80 | PluginInfo->NormalMemory = TRUE; 81 | PluginInfo->MemoryBswaped = TRUE; 82 | } 83 | 84 | 85 | GFX_INFO gfx; 86 | 87 | EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info) 88 | { 89 | gfx = Gfx_Info; 90 | 91 | return TRUE; 92 | } 93 | 94 | 95 | EXPORT void CALL MoveScreen (int xpos, int ypos) 96 | { 97 | RECT statusrect; 98 | POINT p; 99 | p.x = p.y = 0; 100 | GetClientRect(gfx.hWnd, &dst); 101 | ClientToScreen(gfx.hWnd, &p); 102 | OffsetRect(&dst, p.x, p.y); 103 | GetClientRect(gfx.hStatusBar, &statusrect); 104 | dst.bottom -= statusrect.bottom; 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | } 114 | 115 | 116 | EXPORT void CALL ProcessDList(void) 117 | { 118 | if (!ProcessDListShown) 119 | { 120 | popmessage("ProcessDList"); 121 | ProcessDListShown = 1; 122 | } 123 | } 124 | 125 | 126 | EXPORT void CALL ProcessRDPList(void) 127 | { 128 | 129 | 130 | 131 | 132 | 133 | 134 | rdp_process_list(); 135 | return; 136 | } 137 | 138 | 139 | EXPORT void CALL RomClosed (void) 140 | { 141 | rdp_close(); 142 | if (lpddsback) 143 | { 144 | IDirectDrawSurface_Release(lpddsback); 145 | lpddsback = 0; 146 | } 147 | if (lpddsprimary) 148 | { 149 | IDirectDrawSurface_Release(lpddsprimary); 150 | lpddsprimary = 0; 151 | } 152 | if (lpdd) 153 | { 154 | IDirectDraw_Release(lpdd); 155 | lpdd = 0; 156 | } 157 | 158 | SaveLoaded = 1; 159 | command_counter = 0; 160 | } 161 | 162 | 163 | EXPORT void CALL RomOpen (void) 164 | { 165 | RECT bigrect, smallrect, statusrect; 166 | 167 | GetWindowRect(gfx.hWnd,&bigrect); 168 | GetClientRect(gfx.hWnd,&smallrect); 169 | int rightdiff = screen_width - smallrect.right; 170 | int bottomdiff = screen_height - smallrect.bottom; 171 | if (gfx.hStatusBar) 172 | { 173 | GetClientRect(gfx.hStatusBar, &statusrect); 174 | bottomdiff += statusrect.bottom; 175 | } 176 | MoveWindow(gfx.hWnd, bigrect.left, bigrect.top, bigrect.right - bigrect.left + rightdiff, bigrect.bottom - bigrect.top + bottomdiff, TRUE); 177 | 178 | 179 | DDPIXELFORMAT ftpixel; 180 | LPDIRECTDRAWCLIPPER lpddcl; 181 | 182 | res = DirectDrawCreateEx(0, (LPVOID*)&lpdd, IID_IDirectDraw7, 0); 183 | if(res != DD_OK) 184 | fatalerror("Couldn't create a DirectDraw object"); 185 | res = IDirectDraw_SetCooperativeLevel(lpdd, gfx.hWnd, DDSCL_NORMAL); 186 | if(res != DD_OK) 187 | fatalerror("Couldn't set a cooperative level. Error code %x", res); 188 | 189 | memset(&ddsd, 0, sizeof(ddsd)); 190 | ddsd.dwSize = sizeof(ddsd); 191 | ddsd.dwFlags = DDSD_CAPS; 192 | ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; 193 | 194 | 195 | res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsprimary, 0); 196 | if(res != DD_OK) 197 | fatalerror("CreateSurface for a primary surface failed. Error code %x", res); 198 | 199 | 200 | ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; 201 | ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 202 | ddsd.dwWidth = PRESCALE_WIDTH; 203 | ddsd.dwHeight = PRESCALE_HEIGHT; 204 | memset(&ftpixel, 0, sizeof(ftpixel)); 205 | ftpixel.dwSize = sizeof(ftpixel); 206 | ftpixel.dwFlags = DDPF_RGB; 207 | ftpixel.dwRGBBitCount = 32; 208 | ftpixel.dwRBitMask = 0xff0000; 209 | ftpixel.dwGBitMask = 0xff00; 210 | ftpixel.dwBBitMask = 0xff; 211 | ddsd.ddpfPixelFormat = ftpixel; 212 | res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsback, 0); 213 | if (res == DDERR_INVALIDPIXELFORMAT) 214 | fatalerror("ARGB8888 is not supported. You can try changing desktop color depth to 32-bit, but most likely that won't help."); 215 | else if(res != DD_OK) 216 | fatalerror("CreateSurface for a secondary surface failed. Error code %x", res); 217 | 218 | 219 | res = IDirectDrawSurface_GetSurfaceDesc(lpddsback, &ddsd); 220 | if (res != DD_OK) 221 | fatalerror("GetSurfaceDesc failed."); 222 | if ((ddsd.lPitch & 3) || ddsd.lPitch < (PRESCALE_WIDTH << 2)) 223 | fatalerror("Pitch of a secondary surface is either not 32 bit aligned or two small."); 224 | pitchindwords = ddsd.lPitch >> 2; 225 | 226 | 227 | res = IDirectDraw_CreateClipper(lpdd, 0, &lpddcl, 0); 228 | if (res != DD_OK) 229 | fatalerror("Couldn't create a clipper."); 230 | res = IDirectDrawClipper_SetHWnd(lpddcl, 0, gfx.hWnd); 231 | if (res != DD_OK) 232 | fatalerror("Couldn't register a windows handle as a clipper."); 233 | res = IDirectDrawSurface_SetClipper(lpddsprimary, lpddcl); 234 | if (res != DD_OK) 235 | fatalerror("Couldn't attach a clipper to a surface."); 236 | 237 | 238 | src.top = src.left = 0; 239 | src.bottom = 0; 240 | src.right = PRESCALE_WIDTH; 241 | 242 | 243 | 244 | 245 | POINT p; 246 | p.x = p.y = 0; 247 | GetClientRect(gfx.hWnd, &dst); 248 | ClientToScreen(gfx.hWnd, &p); 249 | OffsetRect(&dst, p.x, p.y); 250 | GetClientRect(gfx.hStatusBar, &statusrect); 251 | dst.bottom -= statusrect.bottom; 252 | 253 | 254 | 255 | DDBLTFX ddbltfx; 256 | ddbltfx.dwSize = sizeof(DDBLTFX); 257 | ddbltfx.dwFillColor = 0; 258 | res = IDirectDrawSurface_Blt(lpddsprimary, &dst, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); 259 | src.bottom = PRESCALE_HEIGHT; 260 | res = IDirectDrawSurface_Blt(lpddsback, &src, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); 261 | 262 | rdp_init(); 263 | 264 | 265 | } 266 | 267 | 268 | EXPORT void CALL ShowCFB (void) 269 | { 270 | rdp_update(); 271 | } 272 | 273 | 274 | 275 | EXPORT void CALL UpdateScreen (void) 276 | { 277 | rdp_update(); 278 | 279 | 280 | 281 | 282 | } 283 | 284 | 285 | EXPORT void CALL ViStatusChanged (void) 286 | { 287 | } 288 | 289 | 290 | EXPORT void CALL ViWidthChanged (void) 291 | { 292 | } 293 | 294 | 295 | 296 | EXPORT void CALL FBWrite(DWORD, DWORD) 297 | { 298 | 299 | } 300 | 301 | EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, DWORD size) 302 | { 303 | } 304 | 305 | 306 | EXPORT void CALL FBRead(DWORD addr) 307 | { 308 | } 309 | 310 | 311 | EXPORT void CALL FBGetFrameBufferInfo(void *pinfo) 312 | { 313 | } 314 | 315 | -------------------------------------------------------------------------------- /tctables.h: -------------------------------------------------------------------------------- 1 | #ifndef _TCTABLES_H 2 | #define _TCTABLES_H 3 | 4 | const INT32 norm_point_table[64] = { 5 | 0x4000, 6 | 0x3f04, 7 | 0x3e10, 8 | 0x3d22, 9 | 0x3c3c, 10 | 0x3b5d, 11 | 0x3a83, 12 | 0x39b1, 13 | 0x38e4, 14 | 0x381c, 15 | 0x375a, 16 | 0x369d, 17 | 0x35e5, 18 | 0x3532, 19 | 0x3483, 20 | 0x33d9, 21 | 0x3333, 22 | 0x3291, 23 | 0x31f4, 24 | 0x3159, 25 | 0x30c3, 26 | 0x3030, 27 | 0x2fa1, 28 | 0x2f15, 29 | 0x2e8c, 30 | 0x2e06, 31 | 0x2d83, 32 | 0x2d03, 33 | 0x2c86, 34 | 0x2c0b, 35 | 0x2b93, 36 | 0x2b1e, 37 | 0x2aab, 38 | 0x2a3a, 39 | 0x29cc, 40 | 0x2960, 41 | 0x28f6, 42 | 0x288e, 43 | 0x2828, 44 | 0x27c4, 45 | 0x2762, 46 | 0x2702, 47 | 0x26a4, 48 | 0x2648, 49 | 0x25ed, 50 | 0x2594, 51 | 0x253d, 52 | 0x24e7, 53 | 0x2492, 54 | 0x243f, 55 | 0x23ee, 56 | 0x239e, 57 | 0x234f, 58 | 0x2302, 59 | 0x22b6, 60 | 0x226c, 61 | 0x2222, 62 | 0x21da, 63 | 0x2193, 64 | 0x214d, 65 | 0x2108, 66 | 0x20c5, 67 | 0x2082, 68 | 0x2041 69 | }; 70 | 71 | const INT32 norm_slope_table[64] = { 72 | 0xf03, 73 | 0xf0b, 74 | 0xf11, 75 | 0xf19, 76 | 0xf20, 77 | 0xf25, 78 | 0xf2d, 79 | 0xf32, 80 | 0xf37, 81 | 0xf3d, 82 | 0xf42, 83 | 0xf47, 84 | 0xf4c, 85 | 0xf50, 86 | 0xf55, 87 | 0xf59, 88 | 0xf5d, 89 | 0xf62, 90 | 0xf64, 91 | 0xf69, 92 | 0xf6c, 93 | 0xf70, 94 | 0xf73, 95 | 0xf76, 96 | 0xf79, 97 | 0xf7c, 98 | 0xf7f, 99 | 0xf82, 100 | 0xf84, 101 | 0xf87, 102 | 0xf8a, 103 | 0xf8c, 104 | 0xf8e, 105 | 0xf91, 106 | 0xf93, 107 | 0xf95, 108 | 0xf97, 109 | 0xf99, 110 | 0xf9b, 111 | 0xf9d, 112 | 0xf9f, 113 | 0xfa1, 114 | 0xfa3, 115 | 0xfa4, 116 | 0xfa6, 117 | 0xfa8, 118 | 0xfa9, 119 | 0xfaa, 120 | 0xfac, 121 | 0xfae, 122 | 0xfaf, 123 | 0xfb0, 124 | 0xfb2, 125 | 0xfb3, 126 | 0xfb5, 127 | 0xfb5, 128 | 0xfb7, 129 | 0xfb8, 130 | 0xfb9, 131 | 0xfba, 132 | 0xfbc, 133 | 0xfbc, 134 | 0xfbe, 135 | 0xfbe 136 | }; 137 | 138 | #endif -------------------------------------------------------------------------------- /z64.h: -------------------------------------------------------------------------------- 1 | #ifndef __Z64_H__ 2 | #define __Z64_H__ 3 | 4 | #if defined (_MSC_VER) && (_MSC_VER >= 1500) 5 | #define _CRT_SECURE_NO_WARNINGS 6 | #endif 7 | 8 | #include 9 | 10 | #ifdef WIN32 11 | #include 12 | #include 13 | #endif 14 | 15 | #if defined (_MSC_VER) && (_MSC_VER >= 1300) 16 | #include 17 | #endif 18 | 19 | #if defined (_MSC_VER) && (_MSC_VER < 1300) 20 | typedef unsigned char UINT8; 21 | typedef signed short INT16; 22 | typedef unsigned short UINT16; 23 | #endif 24 | 25 | #if !defined (_MSC_VER) || (_MSC_VER >= 1600) 26 | #include 27 | typedef uint64_t UINT64; 28 | typedef int64_t INT64; 29 | typedef uint32_t UINT32; 30 | typedef int32_t INT32; 31 | typedef uint16_t UINT16; 32 | typedef int16_t INT16; 33 | typedef uint8_t UINT8; 34 | typedef int8_t INT8; 35 | #endif 36 | 37 | #define SP_INTERRUPT 0x1 38 | #define SI_INTERRUPT 0x2 39 | #define AI_INTERRUPT 0x4 40 | #define VI_INTERRUPT 0x8 41 | #define PI_INTERRUPT 0x10 42 | #define DP_INTERRUPT 0x20 43 | 44 | #define SP_STATUS_HALT 0x0001 45 | #define SP_STATUS_BROKE 0x0002 46 | #define SP_STATUS_DMABUSY 0x0004 47 | #define SP_STATUS_DMAFULL 0x0008 48 | #define SP_STATUS_IOFULL 0x0010 49 | #define SP_STATUS_SSTEP 0x0020 50 | #define SP_STATUS_INTR_BREAK 0x0040 51 | #define SP_STATUS_SIGNAL0 0x0080 52 | #define SP_STATUS_SIGNAL1 0x0100 53 | #define SP_STATUS_SIGNAL2 0x0200 54 | #define SP_STATUS_SIGNAL3 0x0400 55 | #define SP_STATUS_SIGNAL4 0x0800 56 | #define SP_STATUS_SIGNAL5 0x1000 57 | #define SP_STATUS_SIGNAL6 0x2000 58 | #define SP_STATUS_SIGNAL7 0x4000 59 | 60 | #define DP_STATUS_XBUS_DMA 0x01 61 | #define DP_STATUS_FREEZE 0x02 62 | #define DP_STATUS_FLUSH 0x04 63 | #define DP_STATUS_START_GCLK 0x008 64 | #define DP_STATUS_TMEM_BUSY 0x010 65 | #define DP_STATUS_PIPE_BUSY 0x020 66 | #define DP_STATUS_CMD_BUSY 0x040 67 | #define DP_STATUS_CBUF_READY 0x080 68 | #define DP_STATUS_DMA_BUSY 0x100 69 | #define DP_STATUS_END_VALID 0x200 70 | #define DP_STATUS_START_VALID 0x400 71 | 72 | #define R4300i_SP_Intr 1 73 | 74 | 75 | #define LSB_FIRST 1 76 | #ifdef LSB_FIRST 77 | #define BYTE_ADDR_XOR 3 78 | #define WORD_ADDR_XOR 1 79 | #define BYTE4_XOR_BE(a) ((a) ^ 3) 80 | #else 81 | #define BYTE_ADDR_XOR 0 82 | #define WORD_ADDR_XOR 0 83 | #define BYTE4_XOR_BE(a) (a) 84 | #endif 85 | 86 | #ifdef LSB_FIRST 87 | #define BYTE_XOR_DWORD_SWAP 7 88 | #define WORD_XOR_DWORD_SWAP 3 89 | #else 90 | #define BYTE_XOR_DWORD_SWAP 4 91 | #define WORD_XOR_DWORD_SWAP 2 92 | #endif 93 | #define DWORD_XOR_DWORD_SWAP 1 94 | 95 | #define INLINE 96 | #ifdef _MSC_VER 97 | #define STRICTINLINE __forceinline 98 | #else 99 | #define STRICTINLINE inline 100 | #endif 101 | 102 | #define PRESCALE_WIDTH 640 103 | #define PRESCALE_HEIGHT 625 104 | extern const int screen_width, screen_height; 105 | 106 | typedef unsigned int offs_t; 107 | 108 | #define rdram ((UINT32*)gfx.RDRAM) 109 | #define rsp_imem ((UINT32*)gfx.IMEM) 110 | #define rsp_dmem ((UINT32*)gfx.DMEM) 111 | 112 | #define rdram16 ((UINT16*)gfx.RDRAM) 113 | #define rdram8 (gfx.RDRAM) 114 | 115 | #define vi_origin (*(UINT32*)gfx.VI_ORIGIN_REG) 116 | #define vi_width (*(UINT32*)gfx.VI_WIDTH_REG) 117 | #define vi_control (*(UINT32*)gfx.VI_STATUS_REG) 118 | #define vi_v_sync (*(UINT32*)gfx.VI_V_SYNC_REG) 119 | #define vi_h_sync (*(UINT32*)gfx.VI_H_SYNC_REG) 120 | #define vi_h_start (*(UINT32*)gfx.VI_H_START_REG) 121 | #define vi_v_start (*(UINT32*)gfx.VI_V_START_REG) 122 | #define vi_v_intr (*(UINT32*)gfx.VI_INTR_REG) 123 | #define vi_x_scale (*(UINT32*)gfx.VI_X_SCALE_REG) 124 | #define vi_y_scale (*(UINT32*)gfx.VI_Y_SCALE_REG) 125 | #define vi_timing (*(UINT32*)gfx.VI_TIMING_REG) 126 | #define vi_v_current_line (*(UINT32*)gfx.VI_V_CURRENT_LINE_REG) 127 | 128 | #define dp_start (*(UINT32*)gfx.DPC_START_REG) 129 | #define dp_end (*(UINT32*)gfx.DPC_END_REG) 130 | #define dp_current (*(UINT32*)gfx.DPC_CURRENT_REG) 131 | #define dp_status (*(UINT32*)gfx.DPC_STATUS_REG) 132 | 133 | #endif 134 | --------------------------------------------------------------------------------