seta10.c

来自「linux下的任天堂模拟器代码。供大家参考。」· C语言 代码 · 共 567 行 · 第 1/2 页

C
567
字号
    */    case 0x01:    {      SRAM[0x0006] = SRAM[0x0002];      SRAM[0x0007] = SRAM[0x0003];      ST010_OP01(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)SRAM, (short *)&SRAM[2], (short *)&SRAM[4], (short *)&SRAM[0x10]);    }    break;    //Sorts a bunch of values by weight    case 0x02:    {      ST010_SortDrivers(*(short*)&SRAM[0x0024], (uint16*)&SRAM[0x0040], (uint16*)&SRAM[0x0080]);    }    break;    /*    Two Dimensional Coordinate Scale    Input      0x0000-0x0001 : X0 (signed)      0x0002-0x0003 : Y0 (signed)      0x0004-0x0005 : Multiplier (signed)    Output      0x0010-0x0013 : X1 (signed)      0x0014-0x0017 : Y1 (signed)    */    case 0x03:    {      ST010_Scale(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10], (int *)&SRAM[0x14]);    }    break;    //Calculate the vector length of (x,y)    case 0x04:    {      int16 square, x,y;      x=*((int16*)SRAM);      y=*((int16*)&SRAM[2]);      square=(int16)sqrt((double)(y*y+x*x));      *((int16*)&SRAM[0x10])=square;      break;    }    //Calculate AI orientation based on specific guidelines    case 0x05:    {      int dx,dy;      int16 a1,b1,c1;      uint16 o1;      bool wrap=false;      //Target (x,y) coordinates      int16 ypos_max = ST010_WORD(0x00C0);      int16 xpos_max = ST010_WORD(0x00C2);      //Current coordinates and direction      int32 ypos = SRAM[0xC4]|(SRAM[0xC5]<<8)|(SRAM[0xC6]<<16)|(SRAM[0xC7]<<24);      int32 xpos = SRAM[0xC8]|(SRAM[0xC9]<<8)|(SRAM[0xCA]<<16)|(SRAM[0xCB]<<24);      uint16 rot = SRAM[0xCC]|(SRAM[0xCD]<<8);      //Physics      uint16 speed = ST010_WORD(0x00D4);      uint16 accel = ST010_WORD(0x00D6);      uint16 speed_max = ST010_WORD(0x00D8);      //Special condition acknowledgment      int16 system = ST010_WORD(0x00DA);      int16 flags = ST010_WORD(0x00DC);      //New target coordinates      int16 ypos_new = ST010_WORD(0x00DE);      int16 xpos_new = ST010_WORD(0x00E0);      //Backup speed      uint16 old_speed = speed;      //Mask upper bit      xpos_new &= 0x7FFF;      //Get the current distance      dx = xpos_max-(xpos>>16);      dy = ypos_max-(ypos>>16);      //Quirk: clear and move in9      SRAM[0xD2]=0xFF;      SRAM[0xD3]=0xFF;      SRAM[0xDA]=0;      SRAM[0xDB]=0;      //Grab the target angle      ST010_OP01(dy,dx,&a1,&b1,&c1,(int16 *)&o1);      //Check for wrapping      if (abs(o1-rot)>0x8000)      {        o1+=0x8000;        rot+=0x8000;        wrap=true;      }      //Special case      if (abs(o1-rot)==0x8000)      {        speed = 0x100;      }      //Slow down for sharp curves      else if (abs(o1-rot)>=0x1000)      {        uint32 slow = abs(o1-rot);        slow >>= 4; //Scaling        speed -= slow;      }      //Otherwise accelerate      else      {        speed += accel;        if (speed > speed_max)        {          //Clip speed          speed = speed_max;        }      }      //Prevent negative/positive overflow      if( abs(old_speed-speed)>0x8000)      {        if (old_speed<speed) { speed=0; }        else { speed=0xff00; }      }      //Adjust direction by so many degrees      //Be careful of negative adjustments      if ((o1>rot && (o1-rot)>0x80) || (o1<rot && (rot-o1)>=0x80))      {        if (o1<rot) { rot-=0x280; }        else if (o1>rot) { rot+=0x280; }      }      //Turn off wrapping      if (wrap) { rot-=0x8000; }      //Now check the distances (store for later)      dx = (xpos_max<<16)-xpos;      dy = (ypos_max<<16)-ypos;      dx>>=16;      dy>>=16;      //If we're in so many units of the target, signal it      if ((system && (dy<=6 && dy>=-8) && (dx<=126 && dx>=-128)) ||          (!system && (dx<=6 && dx>=-8) && (dy<=126 && dy>=-128)))      {        //Announce our new destination and flag it        xpos_max = xpos_new&0x7FFF;        ypos_max = ypos_new;        flags |= 0x08;      }      //Update position      xpos -= (ST010_Cos(rot) * 0x400 >> 15) * (speed >> 8) << 1;      ypos -= (ST010_Sin(rot) * 0x400 >> 15) * (speed >> 8) << 1;      //Quirk: mask upper byte      xpos &= 0x1FFFFFFF;      ypos &= 0x1FFFFFFF;      SRAM[0x00C0]=(uint8)(ypos_max);      SRAM[0x00C1]=(uint8)(ypos_max >> 8);      SRAM[0x00C2]=(uint8)(xpos_max);      SRAM[0x00C3]=(uint8)(xpos_max >> 8);      SRAM[0x00C4]=(uint8)(ypos);      SRAM[0x00C5]=(uint8)(ypos >> 8);      SRAM[0x00C6]=(uint8)(ypos >> 16);      SRAM[0x00C7]=(uint8)(ypos >> 24);      SRAM[0x00C8]=(uint8)(xpos);      SRAM[0x00C9]=(uint8)(xpos >> 8);      SRAM[0x00CA]=(uint8)(xpos >> 16);      SRAM[0x00CB]=(uint8)(xpos >> 24);      SRAM[0x00CC]=(uint8)(rot);      SRAM[0x00CD]=(uint8)(rot >> 8);      SRAM[0x00D4]=(uint8)(speed);      SRAM[0x00D5]=(uint8)(speed >> 8);      SRAM[0x00DC]=(uint8)(flags);      SRAM[0x00DD]=(uint8)(flags >> 8);    }    break;    /*    16-bit Multiplication    Input      0x0000-0x0001 : Multiplcand (signed)      0x0002-0x0003 : Multiplier (signed)    Output      0x0010-0x0013 : Product (signed)    */    case 0x06:    {      ST010_Multiply(*(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (int *)&SRAM[0x10]);    }    break;    /*    Mode 7 Raster Data Calculation    Input      0x0000-0x0001 : Angle (signed)    Output      0x00f0-0x024f : Mode 7 Matrix A      0x0250-0x03af : Mode 7 Matrix B      0x03b0-0x050f : Mode 7 Matrix C      0x0510-0x066f : Mode 7 Matrix D    */    case 0x07:    {      int16 data;      int32 offset = 0;      int16 Theta = ST010_WORD(0x0000);      int32 line;      for (line = 0; line < 176; line++)      {        //Calculate Mode 7 Matrix A/D data        data = ST010_M7Scale[line] * ST010_Cos(Theta) >> 15;        SRAM[0x00f0 + offset]=(uint8)(data);        SRAM[0x00f1 + offset]=(uint8)(data >> 8);        SRAM[0x0510 + offset]=(uint8)(data);        SRAM[0x0511 + offset]=(uint8)(data >> 8);        //Calculate Mode 7 Matrix B/C data        data = ST010_M7Scale[line] * ST010_Sin(Theta) >> 15;        SRAM[0x0250 + offset]=(uint8)(data);        SRAM[0x0251 + offset]=(uint8)(data >> 8);        if (data) { data = ~data; }        SRAM[0x03b0 + offset]=(uint8)(data);        SRAM[0x03b1 + offset]=(uint8)(data >> 8);        offset += 2;      }      //Shift Angle for use with Lookup table      SRAM[0x00] = SRAM[0x01];      SRAM[0x01] = 0x00;    }    break;    /*    Two dimensional Coordinate Rotation    Input      0x0000-0x0001 : X0 (signed)      0x0002-0x0003 : Y0 (signed)      0x0004-0x0005 : Angle (signed)    Output      0x0010-0x0011 : X1 (signed)      0x0012-0x0013 : Y1 (signed)    */    case 0x08:    {      ST010_Rotate(*(short*)&SRAM[0x0004], *(short*)&SRAM[0x0000], *(short*)&SRAM[0x0002], (short *)&SRAM[0x10], (short *)&SRAM[0x12]);    }    break;    default: break;  }  //Lower signal: op processed  SRAM[0x20]=0;  SRAM[0x21]=0;}

⌨️ 快捷键说明

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