@@ -8,6 +8,7 @@ use crate::hardware::{cpu::Cpu, cpu_bus::CpuBus};
88
99use super :: implementations:: * ;
1010
11+ #[ allow( dead_code) ]
1112fn format_hex_u8 ( value : u8 ) -> String {
1213 format ! ( "${value:02X}" )
1314}
@@ -19,7 +20,7 @@ fn format_hex_u8(value: u8) -> String {
1920// format!("${:02X}", value as u8)
2021// }
2122// }
22-
23+ # [ allow ( dead_code ) ]
2324fn format_hex_u16 ( value : u16 ) -> String {
2425 format ! ( "${value:04X}" )
2526}
@@ -45,23 +46,27 @@ pub(crate) const ACCUMULATOR: fn(cpu: &Cpu, bus: &CpuBus) -> Box<AccumulatorAddr
4546 Box :: new ( AccumulatorAddressingMode {
4647 cpu_program_counter_offset : 0 ,
4748 cpu_additional_cycles_required : 0 ,
49+ #[ cfg( feature = "cpu_logger" ) ]
4850 display : format ! ( "A" ) ,
4951 } )
5052 } ;
5153
5254/// Immediate addressing mode
5355///
5456/// Gets the next byte as the argument
57+ #[ allow( unused_variables) ]
5558pub ( crate ) const IMMEDIATE : fn ( cpu : & Cpu , bus : & CpuBus ) -> Box < MemoryAddressingMode > =
5659 |cpu : & Cpu , bus : & CpuBus | {
5760 let address = cpu. program_counter ;
5861
62+ #[ cfg( feature = "cpu_logger" ) ]
5963 let value = bus. peek ( address) ;
6064
6165 Box :: new ( MemoryAddressingMode {
6266 address,
6367 cpu_program_counter_offset : 1 ,
6468 cpu_additional_cycles_required : 0 ,
69+ #[ cfg( feature = "cpu_logger" ) ]
6570 display : format ! ( "#{}" , format_hex_u8( value) ) ,
6671 } )
6772 } ;
@@ -82,12 +87,14 @@ pub(crate) const ZERO_PAGE: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAddressingM
8287 |cpu : & Cpu , bus : & CpuBus | {
8388 let address = bus. peek ( cpu. program_counter ) as u16 ;
8489
90+ #[ cfg( feature = "cpu_logger" ) ]
8591 let value = bus. peek ( address) ;
8692
8793 Box :: new ( MemoryAddressingMode {
8894 address,
8995 cpu_program_counter_offset : 1 ,
9096 cpu_additional_cycles_required : 0 ,
97+ #[ cfg( feature = "cpu_logger" ) ]
9198 display : format ! ( "{} = {value:02X}" , format_hex_u8( address as u8 ) , ) ,
9299 } )
93100 } ;
@@ -110,12 +117,14 @@ pub(crate) const ZERO_PAGE_X_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAd
110117 let argument = cpu. program_counter ;
111118 let address = bus. peek ( argument) ;
112119 let offset_address = address. wrapping_add ( cpu. x ) as u16 ;
120+ #[ cfg( feature = "cpu_logger" ) ]
113121 let value = bus. peek ( offset_address) ;
114122
115123 Box :: new ( MemoryAddressingMode {
116124 address : offset_address,
117125 cpu_program_counter_offset : 1 ,
118126 cpu_additional_cycles_required : 0 ,
127+ #[ cfg( feature = "cpu_logger" ) ]
119128 display : format ! (
120129 "{},X @ {offset_address:02X} = {value:02X}" ,
121130 format_hex_u8( address as u8 )
@@ -141,12 +150,14 @@ pub(crate) const ZERO_PAGE_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAd
141150 let argument = cpu. program_counter ;
142151 let address = bus. peek ( argument) ;
143152 let offset_address = address. wrapping_add ( cpu. y ) as u16 ;
153+ #[ cfg( feature = "cpu_logger" ) ]
144154 let value = bus. peek ( offset_address) ;
145155
146156 Box :: new ( MemoryAddressingMode {
147157 address : offset_address,
148158 cpu_program_counter_offset : 1 ,
149159 cpu_additional_cycles_required : 0 ,
160+ #[ cfg( feature = "cpu_logger" ) ]
150161 display : format ! (
151162 "{},Y @ {offset_address:02X} = {value:02X}" ,
152163 format_hex_u8( address as u8 )
@@ -168,12 +179,14 @@ pub(crate) const ABSOLUTE: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAddressingMo
168179 |cpu : & Cpu , bus : & CpuBus | {
169180 let address = bus. peek_u16 ( cpu. program_counter ) ;
170181
182+ #[ cfg( feature = "cpu_logger" ) ]
171183 let value = bus. peek ( address) ;
172184
173185 Box :: new ( MemoryAddressingMode {
174186 address,
175187 cpu_program_counter_offset : 2 ,
176188 cpu_additional_cycles_required : 0 ,
189+ #[ cfg( feature = "cpu_logger" ) ]
177190 display : format ! ( "{} = {value:02X}" , format_hex_u16( address) ) ,
178191 } )
179192 } ;
@@ -187,6 +200,7 @@ pub(crate) const ABSOLUTE_JMP: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAddressi
187200 address,
188201 cpu_program_counter_offset : 2 ,
189202 cpu_additional_cycles_required : 0 ,
203+ #[ cfg( feature = "cpu_logger" ) ]
190204 display : format ! ( "{}" , format_hex_u16( address) ) ,
191205 } )
192206 } ;
@@ -202,6 +216,7 @@ pub(crate) const ABSOLUTE_JMP: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAddressi
202216// address,
203217// cpu_program_counter_offset: 2,
204218// cpu_additional_cycles_required: 0,
219+ // #[cfg(feature = "cpu_logger")]
205220// display: format!("{}", format_hex_u16(address)),
206221// })
207222// };
@@ -220,6 +235,7 @@ pub(crate) const ABSOLUTE_X_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
220235 |cpu : & Cpu , bus : & CpuBus | {
221236 let address = bus. peek_u16 ( cpu. program_counter ) ;
222237 let offset_address = address + cpu. x as u16 ;
238+ #[ cfg( feature = "cpu_logger" ) ]
223239 let value = bus. peek ( offset_address) ;
224240
225241 let add_cycle = offset_address & 0xFF00 != address & 0xFF00 ;
@@ -228,6 +244,7 @@ pub(crate) const ABSOLUTE_X_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
228244 address : offset_address,
229245 cpu_program_counter_offset : 2 ,
230246 cpu_additional_cycles_required : add_cycle as u8 ,
247+ #[ cfg( feature = "cpu_logger" ) ]
231248 display : format ! (
232249 "{},X @ {offset_address:04X} = {value:02X}" ,
233250 format_hex_u16( address)
@@ -249,6 +266,7 @@ pub(crate) const ABSOLUTE_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
249266 |cpu : & Cpu , bus : & CpuBus | {
250267 let address = bus. peek_u16 ( cpu. program_counter ) ;
251268 let offset_address = address. wrapping_add ( cpu. y as u16 ) ;
269+ #[ cfg( feature = "cpu_logger" ) ]
252270 let value = bus. peek ( offset_address) ;
253271
254272 let add_cycle = offset_address & 0xFF00 != address & 0xFF00 ;
@@ -257,6 +275,7 @@ pub(crate) const ABSOLUTE_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
257275 address : offset_address,
258276 cpu_program_counter_offset : 2 ,
259277 cpu_additional_cycles_required : add_cycle as u8 ,
278+ #[ cfg( feature = "cpu_logger" ) ]
260279 display : format ! (
261280 "{},Y @ {offset_address:04X} = {value:02X}" ,
262281 format_hex_u16( address)
@@ -286,6 +305,7 @@ pub(crate) const ABSOLUTE_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
286305// address: offset_address,
287306// cpu_program_counter_offset: 2,
288307// cpu_additional_cycles_required: add_cycle as u8,
308+ // #[cfg(feature = "cpu_logger")]
289309// display: format!(
290310// "{},Y @ {offset_address:04X} = {value:02X}",
291311// format_hex_u16(address)
@@ -337,6 +357,7 @@ pub(crate) const INDIRECT: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAddressingMo
337357 address,
338358 cpu_program_counter_offset : 2 ,
339359 cpu_additional_cycles_required : 0 ,
360+ #[ cfg( feature = "cpu_logger" ) ]
340361 display : format ! ( "({}) = {address:04X}" , format_hex_u16( pointer_address) ) ,
341362 } )
342363 } ;
@@ -357,12 +378,14 @@ pub(crate) const INDIRECT_X_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
357378 let high = bus. peek ( high_address) as u16 ;
358379 let address = ( high << 8 ) | low;
359380
381+ #[ cfg( feature = "cpu_logger" ) ]
360382 let value = bus. peek ( address) ;
361383
362384 Box :: new ( MemoryAddressingMode {
363385 address,
364386 cpu_program_counter_offset : 1 ,
365387 cpu_additional_cycles_required : 0 ,
388+ #[ cfg( feature = "cpu_logger" ) ]
366389 display : format ! (
367390 "({},X) @ {pointer_address:02X} = {address:04X} = {value:02X}" ,
368391 format_hex_u8( argument)
@@ -385,13 +408,16 @@ pub(crate) const INDIRECT_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
385408 let offset_address = address. wrapping_add ( cpu. y as u16 ) ;
386409 let add_cycle = offset_address & 0xFF00 != address & 0xFF00 ;
387410
411+ #[ cfg( feature = "cpu_logger" ) ]
388412 let value = bus. peek ( offset_address) ;
389413
390414 Box :: new ( MemoryAddressingMode {
391415 address : offset_address,
392416 cpu_program_counter_offset : 1 ,
393417 cpu_additional_cycles_required : add_cycle as u8 ,
418+ #[ cfg( feature = "cpu_logger" ) ]
394419 // display: format!("({}),y", format_hex_u16(address)),
420+ #[ cfg( feature = "cpu_logger" ) ]
395421 display : format ! (
396422 "({}),Y = {address:04X} @ {offset_address:04X} = {value:02X}" ,
397423 format_hex_u8( argument as u8 )
@@ -420,7 +446,9 @@ pub(crate) const INDIRECT_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
420446// address: offset_address,
421447// cpu_program_counter_offset: 1,
422448// cpu_additional_cycles_required: add_cycle as u8,
449+ // #[cfg(feature = "cpu_logger")]
423450// // display: format!("({}),y", format_hex_u16(address)),
451+ // #[cfg(feature = "cpu_logger")]
424452// display: format!(
425453// "({}),Y = {address:04X} @ {offset_address:04X} = {value:02X}",
426454// format_hex_u8(argument as u8)
@@ -431,16 +459,19 @@ pub(crate) const INDIRECT_Y_OFFSET: fn(cpu: &Cpu, bus: &CpuBus) -> Box<MemoryAdd
431459/// Relative addressing mode
432460///
433461/// Only branch instructions use this.
462+ #[ allow( unused_variables) ]
434463pub ( crate ) const RELATIVE : fn ( cpu : & Cpu , bus : & CpuBus ) -> Box < RelativeAddressingMode > =
435464 |cpu : & Cpu , bus : & CpuBus | {
436465 let address = cpu. program_counter ;
437466
467+ #[ cfg( feature = "cpu_logger" ) ]
438468 let value = bus. peek ( address) as i8 ;
439469
440470 Box :: new ( RelativeAddressingMode {
441471 address,
442472 cpu_program_counter_offset : 1 ,
443473 cpu_additional_cycles_required : 0 ,
474+ #[ cfg( feature = "cpu_logger" ) ]
444475 display : format ! (
445476 "{}" ,
446477 format_hex_u16( ( ( address as i32 ) + ( value as i32 ) + 1 ) as u16 )
0 commit comments