Class: Mos6502::CpuFlags
- Inherits:
-
Object
- Object
- Mos6502::CpuFlags
- Defined in:
- lib/mos6502/cpu_flags.rb
Instance Method Summary collapse
- #break=(flag) ⇒ Object
- #break? ⇒ Boolean
- #carry=(flag) ⇒ Object
- #carry? ⇒ Boolean
- #decimal_mode=(flag) ⇒ Object
- #decimal_mode? ⇒ Boolean
- #decode(bin) ⇒ Object
- #encode ⇒ Object
-
#initialize ⇒ CpuFlags
constructor
A new instance of CpuFlags.
- #interupt_disable=(flag) ⇒ Object
- #interupt_disable? ⇒ Boolean
- #negative=(flag) ⇒ Object
- #negative? ⇒ Boolean
- #overflow=(flag) ⇒ Object
- #overflow? ⇒ Boolean
- #reset! ⇒ Object
- #zero=(flag) ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
#initialize ⇒ CpuFlags
Returns a new instance of CpuFlags.
9 10 11 |
# File 'lib/mos6502/cpu_flags.rb', line 9 def initialize reset! end |
Instance Method Details
#break=(flag) ⇒ Object
45 46 47 |
# File 'lib/mos6502/cpu_flags.rb', line 45 def break=(flag) @break = set_flag(flag) end |
#break? ⇒ Boolean
49 50 51 |
# File 'lib/mos6502/cpu_flags.rb', line 49 def break? @break end |
#carry=(flag) ⇒ Object
13 14 15 |
# File 'lib/mos6502/cpu_flags.rb', line 13 def carry=(flag) @carry = set_flag(flag) end |
#carry? ⇒ Boolean
17 18 19 |
# File 'lib/mos6502/cpu_flags.rb', line 17 def carry? @carry end |
#decimal_mode=(flag) ⇒ Object
37 38 39 |
# File 'lib/mos6502/cpu_flags.rb', line 37 def decimal_mode=(flag) @decimal_mode = set_flag(flag) end |
#decimal_mode? ⇒ Boolean
41 42 43 |
# File 'lib/mos6502/cpu_flags.rb', line 41 def decimal_mode? @decimal_mode end |
#decode(bin) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/mos6502/cpu_flags.rb', line 76 def decode(bin) self.carry = bin & 1 self.zero = (bin >> 1) & 1 self.interupt_disable = (bin >> 2) & 1 self.decimal_mode = (bin >> 3) & 1 self.break = (bin >> 4) & 1 self.overflow = (bin >> 6) & 1 self.negative = (bin >> 7) & 1 end |
#encode ⇒ Object
69 70 71 72 73 74 |
# File 'lib/mos6502/cpu_flags.rb', line 69 def encode [ @negative, @overflow, true, true, @decimal_mode, @interupt_disable, @zero, @carry ].reduce(0) { |acc, flag| (acc << 1) + get_flag(flag) } end |
#interupt_disable=(flag) ⇒ Object
29 30 31 |
# File 'lib/mos6502/cpu_flags.rb', line 29 def interupt_disable=(flag) @interupt_disable = set_flag(flag) end |
#interupt_disable? ⇒ Boolean
33 34 35 |
# File 'lib/mos6502/cpu_flags.rb', line 33 def interupt_disable? @interupt_disable end |
#negative=(flag) ⇒ Object
61 62 63 |
# File 'lib/mos6502/cpu_flags.rb', line 61 def negative=(flag) @negative = set_flag(flag) end |
#negative? ⇒ Boolean
65 66 67 |
# File 'lib/mos6502/cpu_flags.rb', line 65 def negative? @negative end |
#overflow=(flag) ⇒ Object
53 54 55 |
# File 'lib/mos6502/cpu_flags.rb', line 53 def overflow=(flag) @overflow = set_flag(flag) end |
#overflow? ⇒ Boolean
57 58 59 |
# File 'lib/mos6502/cpu_flags.rb', line 57 def overflow? @overflow end |
#reset! ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/mos6502/cpu_flags.rb', line 86 def reset! @carry = false @zero = false @interupt_disable = false @decimal_mode = false @break = false @overflow = false @negative = false end |
#zero=(flag) ⇒ Object
21 22 23 |
# File 'lib/mos6502/cpu_flags.rb', line 21 def zero=(flag) @zero = set_flag(flag) end |
#zero? ⇒ Boolean
25 26 27 |
# File 'lib/mos6502/cpu_flags.rb', line 25 def zero? @zero end |