Advertisement
ckirby101

Cspect plugin code redirect

Apr 8th, 2020
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         public List<sIO> Init(iCSpect _CSpect)
  2.         {
  3.  
  4.             List<sIO> ports = new List<sIO>();
  5.             for (int i=0;i<255;i++)
  6.             {
  7.                 ports.Add(new sIO(i*8192, eAccess.Memory_Read));
  8.             }
  9.  
  10.             return ports;
  11.         }
  12.  
  13.  
  14.        public byte Read(eAccess _type, int _address, out bool _isvalid)
  15.         {
  16.             _isvalid = false;
  17.  
  18.             if (state == STATE.Stopped || state == STATE.Continue) return 0;
  19.  
  20. //so if cpu reads from 0 in any bank..
  21. // we then check the return address on stack
  22. // if and redirect
  23.  
  24.  
  25.             Z80Regs regs = CSpect.GetRegs();
  26.  
  27.             if (regs.PC == 0x0000)
  28.             {
  29.                 //get address of where we jumpped from
  30.                 ushort retaddr = (ushort)(CSpect.Peek(regs.SP) | (CSpect.Peek((ushort)(regs.SP+1))*256)) ;
  31.                 retaddr--;
  32.  
  33.  
  34.                 ushort jumpaddr = 0xfff0;     // this is where i want the cpu redirected to!
  35.  
  36.                 byte lob = (byte)(jumpaddr &255);
  37.                 byte hib = (byte)((jumpaddr/256) &255);
  38.                 CSpect.Poke(regs.SP,lob);
  39.                 CSpect.Poke((ushort)(regs.SP+1),hib);
  40.                 _isvalid = true;
  41.  
  42.                 return 0xc9; //(ret command))
  43.  
  44.             }
  45.  
  46.             return 0x0;  //nop
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement