Class: Mos6502::CpuFlags

Inherits:
Object
  • Object
show all
Defined in:
lib/mos6502/cpu_flags.rb

Instance Method Summary collapse

Constructor Details

#initializeCpuFlags

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#encodeObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


25
26
27
# File 'lib/mos6502/cpu_flags.rb', line 25

def zero?
  @zero
end