diff --git a/src/cpu.rs b/src/cpu.rs index 21fc86d..de85556 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -15,7 +15,7 @@ const REG_N_L: usize = 5; const REG_N_HL: usize = 6; const REG_N_A: usize = 7; const REG_N_F: usize = 8; -const REG_NAMES: [&'static str; 9] = ["B", "C", "D", "E", "H", "L", "(HL)", "A", "F"]; +const REG_NAMES: [&str; 9] = ["B", "C", "D", "E", "H", "L", "(HL)", "A", "F"]; const FLAG_Z: u8 = 1 << 7; const FLAG_N: u8 = 1 << 6; @@ -88,12 +88,10 @@ impl CPU { } } - #[inline] fn read_byte(&self, addr: u16) -> u8 { self.interconnect.read_byte(addr) } - #[inline] fn load_args(&mut self, num_args: u8) -> Args { match num_args { 1 => { @@ -112,7 +110,6 @@ impl CPU { } } - #[inline] fn set_8bit_reg(&mut self, reg_id: usize, value: u8) { // Make sure that we skip the (HL) part. if reg_id == REG_N_A { @@ -127,7 +124,6 @@ impl CPU { } } - #[inline] fn get_8bit_reg(&self, reg_id: usize) -> u8 { // Make sure that we skip the (HL) part. if reg_id == REG_N_A { @@ -142,7 +138,6 @@ impl CPU { } } - #[inline] fn adc_r(&mut self, val: u8) { let old: u8 = self.regs[REG_A]; let mut new: u8 = old; @@ -162,7 +157,6 @@ impl CPU { self.set_clear_flag(FLAG_H, ((old & 0x0F) + (val & 0x0F) + c) > 0x0F); } - #[inline] fn add_r(&mut self, val: u8) { let old: u8 = self.regs[REG_A]; let new: u8 = old.wrapping_add(val); @@ -175,7 +169,6 @@ impl CPU { self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); } - #[inline] fn sbc_r(&mut self, val: u8) { let old: u8 = self.regs[REG_A]; let mut new: u8 = old as u8; @@ -199,7 +192,6 @@ impl CPU { ); } - #[inline] fn sub_r(&mut self, val: u8) { let old: u8 = self.regs[REG_A]; let new: u8 = old.wrapping_sub(val); @@ -212,7 +204,6 @@ impl CPU { self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); } - #[inline] fn cp_r(&mut self, val: u8) { let old: u8 = self.regs[REG_A]; let new: u8 = old.wrapping_sub(val); @@ -224,7 +215,6 @@ impl CPU { self.set_clear_flag(FLAG_H, carry & 0x10 == 0x10); } - #[inline] fn run_prefix_instruction(&mut self) { let instruction = self.read_byte(self.ip); self.ip += 1; @@ -595,18 +585,15 @@ impl CPU { } } - #[inline] fn get_pair_value(&self, a: usize, b: usize) -> u16 { (self.get_8bit_reg(a) as u16) << 8 | self.get_8bit_reg(b) as u16 } - #[inline] fn set_pair_value(&mut self, a: usize, b: usize, value: u16) { self.set_8bit_reg(a, (value >> 8) as u8); self.set_8bit_reg(b, value as u8); } - #[inline] fn call(&mut self, dst: u16) { let ip = self.ip; self.push(ip); @@ -614,7 +601,6 @@ impl CPU { self.ip = dst; } - #[inline] fn call_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { let dst = u16::try_from(self.load_args(2)).unwrap(); if self.debug { @@ -628,7 +614,6 @@ impl CPU { } } - #[inline] fn ret_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { if self.debug { println!("RET {}", cond_str); @@ -641,7 +626,6 @@ impl CPU { } } - #[inline] fn jmp_r(&mut self, addr: u8) { let off: i8 = addr as i8; if off < 0 { @@ -651,7 +635,6 @@ impl CPU { } } - #[inline] fn jmp_r_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { let t = u8::try_from(self.load_args(1)).unwrap(); if self.debug { @@ -665,12 +648,10 @@ impl CPU { } } - #[inline] fn jmp_p(&mut self, addr: u16) { self.ip = addr; } - #[inline] fn jmp_p_condition(&mut self, cond_str: &'static str, cond: bool) -> u8 { let t = u16::try_from(self.load_args(2)).unwrap(); if self.debug { @@ -684,7 +665,6 @@ impl CPU { } } - #[inline] fn rst(&mut self, val: u8) -> u8 { // Make sure this is correct. if self.debug { @@ -694,7 +674,6 @@ impl CPU { 16 } - #[inline] fn pop_rr(&mut self, r1: usize, r2: usize) -> u8 { if self.debug { println!("POP {}{}", REG_NAMES[r1], REG_NAMES[r2]); @@ -704,7 +683,6 @@ impl CPU { 12 } - #[inline] fn push_rr(&mut self, r1: usize, r2: usize) -> u8 { if self.debug { println!("PUSH {}{}", REG_NAMES[r1], REG_NAMES[r2]); @@ -714,7 +692,6 @@ impl CPU { 16 } - #[inline] fn dec_rr(&mut self, r1: usize, r2: usize) -> u8 { if self.debug { println!("DEC {}{}", REG_NAMES[r1], REG_NAMES[r2]); @@ -725,7 +702,6 @@ impl CPU { 8 } - #[inline] fn inc_rr(&mut self, r1: usize, r2: usize) -> u8 { if self.debug { println!("INC {}{}", REG_NAMES[r1], REG_NAMES[r2]); @@ -736,20 +712,17 @@ impl CPU { 8 } - #[inline] fn push(&mut self, val: u16) { self.interconnect.write_word(self.sp - 2, val); self.sp -= 2; } - #[inline] fn pop(&mut self) -> u16 { let v: u16 = self.interconnect.read_word(self.sp); self.sp += 2; v } - #[inline] fn ld_r_r(&mut self, reg_dst: usize, reg_src: usize) -> u8 { if self.debug { println!("LD {}, {}", REG_NAMES[reg_dst], REG_NAMES[reg_src]) @@ -763,7 +736,6 @@ impl CPU { } } - #[inline] fn ld_r_v(&mut self, r: usize) -> u8 { let val = u8::try_from(self.load_args(1)).unwrap(); if self.debug { @@ -777,7 +749,6 @@ impl CPU { } } - #[inline] fn ld_rr_vv(&mut self, r1: usize, r2: usize) -> u8 { let val = u16::try_from(self.load_args(2)).unwrap(); if self.debug { @@ -787,7 +758,6 @@ impl CPU { 12 } - #[inline] fn reg_inc(&mut self, reg_id: usize) -> u8 { if self.debug { println!("INC {}", REG_NAMES[reg_id]); @@ -801,7 +771,6 @@ impl CPU { 4 } - #[inline] fn add_rr_rr(&mut self, r1: usize, r2: usize, r3: usize, r4: usize) -> u8 { if self.debug { println!( @@ -824,7 +793,6 @@ impl CPU { 8 } - #[inline] fn reg_dec(&mut self, reg_id: usize) -> u8 { if self.debug { println!("DEC {}", REG_NAMES[reg_id]); @@ -840,7 +808,6 @@ impl CPU { 4 } - #[inline] fn ld_dref_rr_a(&mut self, r1: usize, r2: usize) -> u8 { if self.debug { println!("LD ({}{}), A", REG_NAMES[r1], REG_NAMES[r2]); @@ -851,17 +818,14 @@ impl CPU { 8 } - #[inline] fn set_flag(&mut self, flag: u8) { self.flags |= flag; } - #[inline] fn clear_flag(&mut self, flag: u8) { self.flags &= !flag; } - #[inline] fn set_clear_flag(&mut self, flag: u8, dep: bool) { if dep { self.set_flag(flag); @@ -870,7 +834,6 @@ impl CPU { } } - #[inline] fn int_(&mut self, val: u8) { if self.debug { println!("INT {:02X}", val); @@ -880,21 +843,18 @@ impl CPU { self.call(val as u16); } - #[inline] fn ret(&mut self) { let new_ip: u16 = self.pop(); //self.dump_stack(); self.ip = new_ip; } - #[inline] fn reti(&mut self) -> u8 { self.ret(); self.ime = true; 16 } - #[inline] fn handle_interrupt(&mut self, offset: u8, flag: u8) { // Remove interrupt requested flag let new_flag = self.interconnect.read_byte(0xFF0F) & !flag; diff --git a/src/display.rs b/src/display.rs index eca92bf..6fb1f88 100644 --- a/src/display.rs +++ b/src/display.rs @@ -281,14 +281,12 @@ impl Display { } } - #[inline] fn set_pixel(&mut self, x: u8, y: u8, color: sdl2::pixels::Color, origin: PixelOrigin) { let p = &mut self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X]; p.color = color; p.origin = origin; } - #[inline] fn get_pixel_origin(&self, x: u8, y: u8) -> PixelOrigin { self.pixels[(x as usize) + (y as usize) * GB_PIXELS_X].origin } @@ -324,7 +322,6 @@ impl Display { .expect("Rendering failed"); } - #[inline] pub fn vblank_interrupt(&mut self) -> bool { // Returns whether or not a vblank interrupt should be done // Yes, this is polling, and yes, this sucks. @@ -336,7 +333,6 @@ impl Display { } } - #[inline] pub fn stat_interrupt(&mut self) -> bool { if self.stat_interrupt { self.stat_interrupt = false; @@ -346,7 +342,6 @@ impl Display { } } - #[inline] pub fn write_byte(&mut self, addr: u16, val: u8) { match addr { 0x8000..=0x9FFF => { @@ -415,7 +410,6 @@ impl Display { } } - #[inline] pub fn read_byte(&self, addr: u16) -> u8 { match addr { 0x8000..=0x9FFF => { @@ -467,7 +461,6 @@ impl Display { BgMapAttributes(self.vram1[vram_offset]) } - #[inline] pub fn tick(&mut self, ticks: u16) { self.status &= 0xFC; if self.control & CTRL_LCD_DISPLAY_ENABLE == 0 { @@ -685,7 +678,6 @@ impl Display { } } - #[inline] fn get_bg_window_tile_addr(&self, tile_id: u8) -> usize { if (self.control & CTRL_BG_WINDOW_TILE_DATA_SELECT) == CTRL_BG_WINDOW_TILE_DATA_SELECT { let base_addr = 0x0000; @@ -708,7 +700,6 @@ impl Display { .unwrap(); } - #[inline] fn renderscan(&mut self) { // Points to the background map offset to use. let background_map: usize; diff --git a/src/interconnect.rs b/src/interconnect.rs index f2e164e..11592e0 100644 --- a/src/interconnect.rs +++ b/src/interconnect.rs @@ -251,12 +251,10 @@ impl Interconnect { TickResult::Continue } - #[inline] pub fn is_boot_rom(&self) -> bool { self.disable_bootrom == 0 } - #[inline] pub fn read_byte(&self, addr: u16) -> u8 { // TODO: Make this more beautiful. // TODO: if some flag set, use bios, otherwise only use rom @@ -315,7 +313,6 @@ impl Interconnect { } } - #[inline] pub fn write_byte(&mut self, addr: u16, val: u8) { // TODO: Make this more beautful /* @@ -440,13 +437,11 @@ impl Interconnect { } } - #[inline] pub fn write_word(&mut self, addr: u16, val: u16) { self.write_byte(addr, val as u8); self.write_byte(addr + 1, (val >> 8) as u8); } - #[inline] pub fn read_word(&self, addr: u16) -> u16 { self.read_byte(addr) as u16 | (self.read_byte(addr + 1) as u16) << 8 // (self.read_byte(addr) as u16) << 8 | (self.read_byte(addr + 1) as u16)