⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winlink.cpp

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   DWORD i,j,color32;
   DWORD *SURFDW;

   NGNoTransp = 0;              // Set this value to 1 within the appropriate
                                // video mode if you want to add a custom
                                // transparency routine or hardware
                                // transparency.  This only works if
                                // the value of newengen is equal to 1.
                                // (see ProcessTransparencies in newgfx16.asm
                                //  for ZSNES' current transparency code)

   UpdateVFrame();
   if (curblank!=0) return;

   if (!(Temp1 = LockSurface()))
   { 
      DD_Primary->Restore();
      DD_CFB->Restore();
      return;
   }

   ScreenPtr=vidbuffer;
   ScreenPtr+=16*2+32*2+256*2; 
   SurfBufD=(DWORD) &SurfBuf[0];
   SURFDW=(DWORD *) &SurfBuf[0];

   if (SurfaceX==256&&SurfaceY==224)
   {
      switch (BitDepth)
      {
         case 16:
             if (FPUCopy){
                  _asm {
                     push es
                     mov ax,ds
                     mov es,ax
                     xor eax,eax
                     mov esi,ScreenPtr
                     mov edi,SurfBufD
                  Copying3:
                     mov ecx,32
                  CopyLoop:
                     movq mm0,[esi]
                     movq mm1,[esi+8]
                     movq [edi],mm0
                     movq [edi+8],mm1
                     add esi,16
                     add edi,16
                     dec ecx
                     jnz CopyLoop
                     inc eax            
                     add edi,Temp1
                     sub edi,512
                     sub esi,512
                     add esi,576
                     cmp eax,223
                     jne Copying3
                     xor eax,eax
                     mov ecx,128
                     rep stosd
                     pop es
                     emms
                  }
             } else {
                  _asm {
                     push es
                     mov ax,ds
                     mov es,ax
                     xor eax,eax
                     mov esi,ScreenPtr
                     mov edi,SurfBufD
                  Copying:
                     mov ecx,128
                     rep movsd
                     inc eax            
                     add edi,Temp1
                     sub edi,512
                     sub esi,512
                     add esi,576
                     cmp eax,223
                     jne Copying
                     xor eax,eax
                     mov ecx,128
                     rep stosd
                     pop es
                  }
            }
            break;
      case 32:
                  _asm {
                     push es
                     mov ax,ds
                     mov es,ax
                     xor eax,eax
                     mov ebx,BitConv32Ptr
                     mov esi,ScreenPtr
                     mov edi,SurfBufD
                  Copying32b:
                     mov ecx,256
                     push eax
                     xor eax,eax
                  CopyLoop32b:
                     mov ax,[esi]
                     add esi,2
                     mov edx,[ebx+eax*4]
                     mov [edi],edx
                     add edi,4
                     loop CopyLoop32b
                     pop eax
                     inc eax
                     add edi,Temp1
                     sub edi,1024
                     sub esi,512
                     add esi,576
                     cmp eax,223
                     jne Copying32b
                     pop es
                  }
   
            SURFDW=(DWORD *) &SurfBuf[222*Temp1];
            color32=0x7F000000;
            
               for(i=0;i<256;i++)
               {
                  SURFDW[i]=color32;
               }

            SURFDW=(DWORD *) &SurfBuf[223*Temp1];
            color32=0x7F000000;
         
               for(i=0;i<256;i++)
               {
                  SURFDW[i]=color32;
               }         
            break;
      case 24:
            MessageBox (NULL, "Sorry.  ZSNESw does not work in windowed 24 bit color modes. \nClick 'OK' to switch to a full screen mode.", "DDRAW Error" , MB_ICONERROR );
            cvidmode=3;
            initwinvideo();
            Sleep(1000);
            drawscreenwin();
            break;
      default:
            UnlockSurface();
            MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR );
            cvidmode=2;
            initwinvideo();
            Sleep(1000);
            drawscreenwin();
            break;
      }
   }

   if (SurfaceX==320&&SurfaceY==240)
   {
      switch (BitDepth)
      {
         case 16:
             if (FPUCopy){
                  _asm {
                     push es
                     mov ax,ds
                     mov es,ax
                     xor eax,eax
                     xor ebx,ebx
                     mov esi,ScreenPtr
                     mov edi,SurfBufD
                  Blank1MMX:
                     xor eax,eax
                     mov ecx,160
                     rep stosd
                     sub edi,640
                     add edi,Temp1
                     add ebx,1
                     cmp ebx,8
                     jne Blank1MMX
                     xor ebx,ebx
                     pxor mm0,mm0
                  Copying2MMX:
                     mov ecx,4
                  MMXLoopA:
                     movq [edi],mm0
                     movq [edi+8],mm0
                     add edi,16
                     dec ecx
                     jnz MMXLoopA
                     mov ecx,32
                  MMXLoopB:
                     movq mm1,[esi]
                     movq mm2,[esi+8]
                     movq [edi],mm1
                     movq [edi+8],mm2
                     add esi,16
                     add edi,16
                     dec ecx
                     jnz MMXLoopB
                     mov ecx,4
                  MMXLoopC:
                     movq [edi],mm0
                     movq [edi+8],mm0
                     add edi,16
                     dec ecx
                     jnz MMXLoopC
                     inc ebx
                     add edi,Temp1
                     sub edi,640
                     sub esi,512
                     add esi,576
                     cmp ebx,223
                     jne Copying2MMX
                     xor eax,eax
                     mov ecx,128
                     rep stosd
                     pop es
                     emms
                  }
             } else {
                  _asm {
                     push es
                     mov ax,ds
                     mov es,ax
                     xor eax,eax
                     xor ebx,ebx
                     mov esi,ScreenPtr
                     mov edi,SurfBufD
                  Blank1:
                     xor eax,eax
                     mov ecx,160
                     rep stosd
                     sub edi,640
                     add edi,Temp1
                     add ebx,1
                     cmp ebx,8
                     jne Blank1
                     xor ebx,ebx
                  Copying2:
                     xor eax,eax
                     mov ecx,16
                     rep stosd
                     mov ecx,128
                     rep movsd
                     xor eax,eax
                     mov ecx,16
                     rep stosd
                     inc ebx
                     add edi,Temp1
                     sub edi,640
                     sub esi,512
                     add esi,576
                     cmp ebx,223
                     jne Copying2
                     xor eax,eax
                     mov ecx,128
                     rep stosd
                     pop es
                  }
             }
            break;
      case 32:
            for(j=0;j<8;j++)
            {
               SURFDW=(DWORD *) &SurfBuf[j*Temp1];
               color32=0x7F000000;
            
               for(i=0;i<320;i++)
               {
                  SURFDW[i]=color32;
               }
            }

            for(j=8;j<223+8;j++)
            {
               color32=0x7F000000;
               for(i=0;i<32;i++)
               {
                  SURFDW[i]=color32;
               }

               for(i=32;i<(256+32);i++)
               {
                  color32=(((*(WORD *)(ScreenPtr))&0xF800)<<8)+
                          (((*(WORD *)(ScreenPtr))&0x07E0)<<5)+
                          (((*(WORD *)(ScreenPtr))&0x001F)<<3)+0xFF000000;
//                  SURFDW[i]=color32;
                  ScreenPtr+=2;
               }

               color32=0x7F000000;
               for(i=(256+32);i<320;i++)
               {
                  SURFDW[i]=color32;
               }

               ScreenPtr=ScreenPtr+576-512;
               SURFDW=(DWORD *) &SurfBuf[(j)*Temp1];
            }
   
            for(j=(223+8);j<240;j++)
            {
               SURFDW=(DWORD *) &SurfBuf[j*Temp1];

               color32=0x7F000000;
               for(i=0;i<320;i++)
               {
                  SURFDW[i]=color32;
               }
            }
            break;
      default:
            UnlockSurface();
            MessageBox (NULL, "Mode only available in 16 and 32 bit color", "DDRAW Error" , MB_ICONERROR );
            cvidmode=2;
            initwinvideo();
            Sleep(1000);
            drawscreenwin();
            break;
      }
   }

   if (SurfaceX==512&&SurfaceY==448)
   {
      switch (BitDepth)
      {
         case 16:
            AddEndBytes=Temp1-1024;
            NumBytesPerLine=Temp1;
            WinVidMemStart=&SurfBuf[0];
            _asm
            {
               pushad
               call copy640x480x16bwin
               popad
            }
            break;
         default:
            UnlockSurface();
            MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR );
            cvidmode=2;
            initwinvideo();
            Sleep(1000);
            drawscreenwin();
         }
   }

   if (SurfaceX==640&&SurfaceY==480)
   {
      switch (BitDepth)
      {
         case 16:
            AddEndBytes=Temp1-1024;
            NumBytesPerLine=Temp1;
            WinVidMemStart=&SurfBuf[16*640*2+64*2];
            _asm
            {
               pushad
               call copy640x480x16bwin
               popad
            }
            break;
         default:
            UnlockSurface();
            MessageBox (NULL, "Mode only available in 16 bit color", "DDRAW Error" , MB_ICONERROR );
            cvidmode=2;
            initwinvideo();
            Sleep(1000);
            drawscreenwin();
         }
   }

   UnlockSurface();
}

extern char fulladdtab[65536*2];
extern WORD vesa2_usbit;
extern WORD vesa2_clbit;
extern WORD vesa2_rpos;
extern WORD vesa2_rfull;
extern WORD vesa2_rtrcl;
extern WORD vesa2_rtrcla;
extern WORD vesa2_gpos;
extern WORD vesa2_gfull;
extern WORD vesa2_gtrcl;
extern WORD vesa2_gtrcla;
extern WORD vesa2_bpos;
extern WORD vesa2_bfull;
extern WORD vesa2_btrcl;
extern WORD vesa2_btrcla;
extern WORD nojoystickpoll;

extern void SwitchFullScreen(void);

void WinUpdateDevices()
{
   int i,j;
   unsigned char * keys;
   unsigned char keys2[256];
   HRESULT hRes;

   for (i = 0; i<256; i++)
   keys2[i]=0;
   keys=(unsigned char *)&pressed;

   if (KeyboardInput&&InputEn==1)
   {
      KeyboardInput->GetDeviceState(256, keys2);
   }
   else
   {
      return;
   }
   if (keys2[0x38]!=0&&keys2[0x3E]!=0) exit(0);
   if (keys2[0x38]!=0&&keys2[0x1c]!=0)
   {
    _asm{
      pushad
      call SwitchFullScreen
      popad
      }
      return;
   }

   for(i=0; i<256; i++)
   {
      if (keys2[i]==0) keys[i]=0;
      if (keys2[i]!=0&&keys[i]==0) keys[i]=1;
   }

   keys[0]=0;

   for(i=0; i<5; i++)
   {
      if (JoystickInput[i])
      {
         for(j=0; j<32; j++)
         {
            keys[0x100 + i * 32 + j] = 0;
         }

         JoystickInput[i]->Poll();

         if (JoystickInput[i]->GetDeviceState(sizeof(DIJOYSTATE), &js[i])==DIERR_INPUTLOST)
         {
            if (JoystickInput[i]) JoystickInput[i]->Acquire();
            if (FAILED(JoystickInput[i]->GetDeviceState(sizeof(DIJOYSTATE), &js[i]))) return;
         }

         if (!X1Disable[i])
         {
            if (js[i].lX>0) keys[0x100 + i * 32 + 0] = 1;
         }

         if (!X2Disable[i])
         {
            if (js[i].lX<0) keys[0x100 + i * 32 + 1] = 1;
         }

         if (!Y1Disable[i])
         {
            if (js[i].lY>0) keys[0x100 + i * 32 + 2] = 1;
         }

         if (!Y2Disable[i])
         {
            if (js[i].lY<0) keys[0x100 + i * 32 + 3] = 1;
         }

         if (!Z1Disable[i])
         {
            if (js[i].lZ>0) keys[0x100 + i * 32 + 4] = 1;
         }

         if (!Z2Disable[i])
         {
            if (js[i].lZ<0) keys[0x100 + i * 32 + 5] = 1;
         }

         if (!RY1Disable[i])
         {
            if (js[i].lRy>0) keys[0x100 + i * 32 + 6] = 1;
         }

         if (!RY2Disable[i])
         {
            if (js[i].lRy<0) keys[0x100 + i * 32 + 7] = 1;
         }

         if (!RZ1Disable[i])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -