Guest User

Untitled

a guest
Dec 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. use std::marker::PhantomData;
  2.  
  3. trait Emu {
  4. fn render_frame(&mut self);
  5. }
  6.  
  7. trait Mips64Desc {
  8. fn pc_mask(pc: u64) -> u64;
  9. fn addr_mask(addr: u64) -> u64;
  10. }
  11.  
  12. struct R4300Desc{}
  13. struct RspDesc{}
  14.  
  15. impl Mips64Desc for R4300Desc {
  16. /* type Cop0 = mips64::Cop0;
  17. type Cop1 = mips64::Fpu;
  18. */
  19. fn pc_mask(pc: u64) -> u64 {
  20. Self::addr_mask(pc)
  21. }
  22. fn addr_mask(addr: u64) -> u64 {
  23. addr & 0x1fff_ffff
  24. }
  25. }
  26.  
  27. impl Mips64Desc for RspDesc {
  28. /* type Cop0 = SpCop0;
  29. type Cop2 = SpCop2;
  30. */
  31. fn pc_mask(pc: u64) -> u64 {
  32. (pc & 0xfff) | 0x1000
  33. }
  34. fn addr_mask(addr: u64) -> u64 {
  35. addr & 0xfff
  36. }
  37. }
  38.  
  39. struct Bus<E: Emu> {
  40. func: Box<FnMut(&mut E, u64, u64)>,
  41. }
  42.  
  43. impl<E: Emu> Bus<E> {
  44. fn read(&self, addr: u64) -> u32 {
  45. println!("bus->read {}", addr);
  46. 4
  47. }
  48. fn write(&mut self, emu: &mut E, addr: u64, val: u32) {
  49. println!("bus->write: {}, {}", addr, val);
  50. (self.func)(emu, addr, val as u64);
  51. }
  52. }
  53.  
  54. struct Mips64<E: Emu, D: Mips64Desc> {
  55. regs: [u64; 32],
  56. _phantom: PhantomData<(E,D)>,
  57. }
  58.  
  59. impl<E: Emu, D:Mips64Desc> Mips64<E,D> {
  60. fn run(&self, _emu: &mut E, _cycles: u64) {
  61.  
  62. }
  63. }
  64.  
  65. struct Sp {
  66. cpu: Mips64<N64,RspDesc>,
  67. reg_status: u32,
  68. reg_control: u32,
  69. reg_imem: [u8; 4096],
  70. reg_dmem: [u8; 4096],
  71. }
  72.  
  73. struct N64 {
  74. main_cpu: Mips64<N64,R4300Desc>,
  75. rcp_bus: Bus<N64>,
  76. sp: Sp,
  77. }
  78.  
  79. impl Emu for N64 {
  80. fn render_frame(&mut self) {
  81. self.main_cpu.run(self, 1000);
  82. }
  83. }
Add Comment
Please, Sign In to add comment