amaterasu 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +54 -0
  5. data/Gemfile +32 -0
  6. data/Gemfile.lock +267 -0
  7. data/LICENSE +21 -0
  8. data/README.md +115 -0
  9. data/Steepfile +7 -0
  10. data/exe/amaterasu +23 -0
  11. data/lib/amaterasu/cartridge/mbc1.rb +56 -0
  12. data/lib/amaterasu/cartridge/rom.rb +118 -0
  13. data/lib/amaterasu/cartridge.rb +68 -0
  14. data/lib/amaterasu/cli.rb +60 -0
  15. data/lib/amaterasu/emulator.rb +121 -0
  16. data/lib/amaterasu/game_boy/apu.rb +12 -0
  17. data/lib/amaterasu/game_boy/bus.rb +161 -0
  18. data/lib/amaterasu/game_boy/cpu/instructions/adc.rb +64 -0
  19. data/lib/amaterasu/game_boy/cpu/instructions/add16.rb +73 -0
  20. data/lib/amaterasu/game_boy/cpu/instructions/add8.rb +63 -0
  21. data/lib/amaterasu/game_boy/cpu/instructions/and.rb +62 -0
  22. data/lib/amaterasu/game_boy/cpu/instructions/base.rb +38 -0
  23. data/lib/amaterasu/game_boy/cpu/instructions/call.rb +48 -0
  24. data/lib/amaterasu/game_boy/cpu/instructions/cb_bit.rb +52 -0
  25. data/lib/amaterasu/game_boy/cpu/instructions/cb_res.rb +49 -0
  26. data/lib/amaterasu/game_boy/cpu/instructions/cb_rl.rb +70 -0
  27. data/lib/amaterasu/game_boy/cpu/instructions/cb_rlc.rb +68 -0
  28. data/lib/amaterasu/game_boy/cpu/instructions/cb_rr.rb +70 -0
  29. data/lib/amaterasu/game_boy/cpu/instructions/cb_rrc.rb +68 -0
  30. data/lib/amaterasu/game_boy/cpu/instructions/cb_set.rb +51 -0
  31. data/lib/amaterasu/game_boy/cpu/instructions/cb_sla.rb +69 -0
  32. data/lib/amaterasu/game_boy/cpu/instructions/cb_sra.rb +71 -0
  33. data/lib/amaterasu/game_boy/cpu/instructions/cb_srl.rb +69 -0
  34. data/lib/amaterasu/game_boy/cpu/instructions/cb_swap.rb +67 -0
  35. data/lib/amaterasu/game_boy/cpu/instructions/cp.rb +61 -0
  36. data/lib/amaterasu/game_boy/cpu/instructions/daa.rb +59 -0
  37. data/lib/amaterasu/game_boy/cpu/instructions/dec.rb +64 -0
  38. data/lib/amaterasu/game_boy/cpu/instructions/di.rb +21 -0
  39. data/lib/amaterasu/game_boy/cpu/instructions/ei.rb +19 -0
  40. data/lib/amaterasu/game_boy/cpu/instructions/halt.rb +19 -0
  41. data/lib/amaterasu/game_boy/cpu/instructions/inc.rb +64 -0
  42. data/lib/amaterasu/game_boy/cpu/instructions/jp.rb +54 -0
  43. data/lib/amaterasu/game_boy/cpu/instructions/jr.rb +45 -0
  44. data/lib/amaterasu/game_boy/cpu/instructions/ld16.rb +79 -0
  45. data/lib/amaterasu/game_boy/cpu/instructions/ld8.rb +210 -0
  46. data/lib/amaterasu/game_boy/cpu/instructions/ldh.rb +61 -0
  47. data/lib/amaterasu/game_boy/cpu/instructions/misc.rb +53 -0
  48. data/lib/amaterasu/game_boy/cpu/instructions/nop.rb +19 -0
  49. data/lib/amaterasu/game_boy/cpu/instructions/or.rb +56 -0
  50. data/lib/amaterasu/game_boy/cpu/instructions/pop.rb +39 -0
  51. data/lib/amaterasu/game_boy/cpu/instructions/push.rb +43 -0
  52. data/lib/amaterasu/game_boy/cpu/instructions/ret.rb +70 -0
  53. data/lib/amaterasu/game_boy/cpu/instructions/rotate.rb +120 -0
  54. data/lib/amaterasu/game_boy/cpu/instructions/rst.rb +33 -0
  55. data/lib/amaterasu/game_boy/cpu/instructions/sbc.rb +64 -0
  56. data/lib/amaterasu/game_boy/cpu/instructions/stop.rb +19 -0
  57. data/lib/amaterasu/game_boy/cpu/instructions/sub.rb +63 -0
  58. data/lib/amaterasu/game_boy/cpu/instructions/xor.rb +60 -0
  59. data/lib/amaterasu/game_boy/cpu/instructions.rb +600 -0
  60. data/lib/amaterasu/game_boy/cpu/registers.rb +264 -0
  61. data/lib/amaterasu/game_boy/cpu.rb +232 -0
  62. data/lib/amaterasu/game_boy/dma.rb +114 -0
  63. data/lib/amaterasu/game_boy/interrupts.rb +108 -0
  64. data/lib/amaterasu/game_boy/joypad.rb +127 -0
  65. data/lib/amaterasu/game_boy/oam/sprite.rb +106 -0
  66. data/lib/amaterasu/game_boy/oam.rb +29 -0
  67. data/lib/amaterasu/game_boy/ppu/modes/disabled.rb +29 -0
  68. data/lib/amaterasu/game_boy/ppu/modes/h_blank.rb +45 -0
  69. data/lib/amaterasu/game_boy/ppu/modes/oam_scan.rb +93 -0
  70. data/lib/amaterasu/game_boy/ppu/modes/rendering/bg_win_fetcher.rb +204 -0
  71. data/lib/amaterasu/game_boy/ppu/modes/rendering/pixel_emitter.rb +83 -0
  72. data/lib/amaterasu/game_boy/ppu/modes/rendering/pixel_fifo.rb +70 -0
  73. data/lib/amaterasu/game_boy/ppu/modes/rendering/sprite_fetcher.rb +140 -0
  74. data/lib/amaterasu/game_boy/ppu/modes/rendering.rb +108 -0
  75. data/lib/amaterasu/game_boy/ppu/modes/v_blank.rb +43 -0
  76. data/lib/amaterasu/game_boy/ppu/modes.rb +22 -0
  77. data/lib/amaterasu/game_boy/ppu/registers/lcd_control.rb +57 -0
  78. data/lib/amaterasu/game_boy/ppu/registers/lcd_status.rb +88 -0
  79. data/lib/amaterasu/game_boy/ppu/registers.rb +131 -0
  80. data/lib/amaterasu/game_boy/ppu.rb +207 -0
  81. data/lib/amaterasu/game_boy/ram.rb +70 -0
  82. data/lib/amaterasu/game_boy/serial.rb +91 -0
  83. data/lib/amaterasu/game_boy/timer.rb +230 -0
  84. data/lib/amaterasu/game_boy/vram/tile.rb +68 -0
  85. data/lib/amaterasu/game_boy/vram/tile_data.rb +52 -0
  86. data/lib/amaterasu/game_boy/vram/tile_map.rb +71 -0
  87. data/lib/amaterasu/game_boy/vram.rb +51 -0
  88. data/lib/amaterasu/hal/console.rb +23 -0
  89. data/lib/amaterasu/hal/sdl2/bindings.rb +59 -0
  90. data/lib/amaterasu/hal/sdl2.rb +127 -0
  91. data/lib/amaterasu/utils/bit_ops.rb +22 -0
  92. data/lib/amaterasu.rb +13 -0
  93. data/sig/akane/cartridge/rom.rbs +29 -0
  94. data/sig/akane/cartridge.rbs +12 -0
  95. data/sig/akane/cli.rbs +16 -0
  96. data/sig/akane/emulator.rbs +19 -0
  97. data/sig/akane/game_boy/apu.rbs +7 -0
  98. data/sig/akane/game_boy/bus.rbs +25 -0
  99. data/sig/akane/game_boy/cpu/instructions/adc.rbs +18 -0
  100. data/sig/akane/game_boy/cpu/instructions/add16.rbs +19 -0
  101. data/sig/akane/game_boy/cpu/instructions/add8.rbs +18 -0
  102. data/sig/akane/game_boy/cpu/instructions/and.rbs +18 -0
  103. data/sig/akane/game_boy/cpu/instructions/base.rbs +20 -0
  104. data/sig/akane/game_boy/cpu/instructions/call.rbs +18 -0
  105. data/sig/akane/game_boy/cpu/instructions/cb_bit.rbs +20 -0
  106. data/sig/akane/game_boy/cpu/instructions/cb_res.rbs +19 -0
  107. data/sig/akane/game_boy/cpu/instructions/cb_rl.rbs +21 -0
  108. data/sig/akane/game_boy/cpu/instructions/cb_rlc.rbs +21 -0
  109. data/sig/akane/game_boy/cpu/instructions/cb_rr.rbs +21 -0
  110. data/sig/akane/game_boy/cpu/instructions/cb_rrc.rbs +21 -0
  111. data/sig/akane/game_boy/cpu/instructions/cb_set.rbs +20 -0
  112. data/sig/akane/game_boy/cpu/instructions/cb_sla.rbs +21 -0
  113. data/sig/akane/game_boy/cpu/instructions/cb_sra.rbs +21 -0
  114. data/sig/akane/game_boy/cpu/instructions/cb_srl.rbs +21 -0
  115. data/sig/akane/game_boy/cpu/instructions/cb_swap.rbs +21 -0
  116. data/sig/akane/game_boy/cpu/instructions/cp.rbs +18 -0
  117. data/sig/akane/game_boy/cpu/instructions/daa.rbs +17 -0
  118. data/sig/akane/game_boy/cpu/instructions/dec.rbs +19 -0
  119. data/sig/akane/game_boy/cpu/instructions/di.rbs +13 -0
  120. data/sig/akane/game_boy/cpu/instructions/ei.rbs +13 -0
  121. data/sig/akane/game_boy/cpu/instructions/halt.rbs +13 -0
  122. data/sig/akane/game_boy/cpu/instructions/inc.rbs +19 -0
  123. data/sig/akane/game_boy/cpu/instructions/jp.rbs +18 -0
  124. data/sig/akane/game_boy/cpu/instructions/jr.rbs +18 -0
  125. data/sig/akane/game_boy/cpu/instructions/ld16.rbs +18 -0
  126. data/sig/akane/game_boy/cpu/instructions/ld8.rbs +31 -0
  127. data/sig/akane/game_boy/cpu/instructions/ldh.rbs +23 -0
  128. data/sig/akane/game_boy/cpu/instructions/misc.rbs +20 -0
  129. data/sig/akane/game_boy/cpu/instructions/nop.rbs +13 -0
  130. data/sig/akane/game_boy/cpu/instructions/or.rbs +18 -0
  131. data/sig/akane/game_boy/cpu/instructions/pop.rbs +17 -0
  132. data/sig/akane/game_boy/cpu/instructions/push.rbs +18 -0
  133. data/sig/akane/game_boy/cpu/instructions/ret.rbs +20 -0
  134. data/sig/akane/game_boy/cpu/instructions/rotate.rbs +23 -0
  135. data/sig/akane/game_boy/cpu/instructions/rst.rbs +17 -0
  136. data/sig/akane/game_boy/cpu/instructions/sbc.rbs +19 -0
  137. data/sig/akane/game_boy/cpu/instructions/stop.rbs +13 -0
  138. data/sig/akane/game_boy/cpu/instructions/sub.rbs +18 -0
  139. data/sig/akane/game_boy/cpu/instructions/xor.rbs +19 -0
  140. data/sig/akane/game_boy/cpu/instructions.rbs +12 -0
  141. data/sig/akane/game_boy/cpu/registers.rbs +56 -0
  142. data/sig/akane/game_boy/cpu.rbs +39 -0
  143. data/sig/akane/game_boy/interrupts.rbs +28 -0
  144. data/sig/akane/game_boy/joypad.rbs +25 -0
  145. data/sig/akane/game_boy/oam/sprite.rbs +30 -0
  146. data/sig/akane/game_boy/ppu/modes/disabled.rbs +17 -0
  147. data/sig/akane/game_boy/ppu/modes/h_blank.rbs +20 -0
  148. data/sig/akane/game_boy/ppu/modes/oam_scan.rbs +28 -0
  149. data/sig/akane/game_boy/ppu/modes/rendering.rbs +26 -0
  150. data/sig/akane/game_boy/ppu/modes/v_blank.rbs +20 -0
  151. data/sig/akane/game_boy/ppu/modes.rbs +13 -0
  152. data/sig/akane/game_boy/ppu.rbs +59 -0
  153. data/sig/akane/game_boy/ram.rbs +16 -0
  154. data/sig/akane/game_boy/serial.rbs +21 -0
  155. data/sig/akane/game_boy/timer.rbs +30 -0
  156. data/sig/akane/utils/bit_ops.rbs +11 -0
  157. data/sig/akane.rbs +3 -0
  158. metadata +226 -0
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Ld16 < Base
8
+ def initialize: (cpu: Cpu, target: Symbol, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol target, Symbol source) -> Proc
13
+ def ld_mem_imm16_sp: () -> void
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Ld8 < Base
8
+ def initialize: (cpu: Cpu, target: Symbol, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol target, Symbol source) -> Proc
13
+ def load_a: (Symbol source) -> Proc
14
+ def load_b: (Symbol source) -> Proc
15
+ def load_c: (Symbol source) -> Proc
16
+ def load_d: (Symbol source) -> Proc
17
+ def load_e: (Symbol source) -> Proc
18
+ def load_h: (Symbol source) -> Proc
19
+ def load_l: (Symbol source) -> Proc
20
+ def load_mem_hl: (Symbol source) -> Proc
21
+ def load_mem_hli: () -> void
22
+ def load_mem_hld: () -> void
23
+ def ld_mem_imm16_a: () -> void
24
+ def ld_a_mem_imm16: () -> void
25
+ def ld_a_mem_bc: () -> void
26
+ def ld_a_mem_de: () -> void
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Ldh < Base
8
+ IO_BASE_ADDRESS: Integer
9
+
10
+ def initialize: (cpu: Cpu, target: Symbol, source: Symbol) -> void
11
+
12
+ private
13
+
14
+ def build_logic: (Symbol target, Symbol source) -> Proc
15
+ def ldh_mem_unsig8_a: () -> void
16
+ def ldh_a_mem_unsig8: () -> void
17
+ def ldh_mem_c_a: () -> void
18
+ def ldh_a_mem_c: () -> void
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Misc < Base
8
+ def initialize: (cpu: Cpu, operation: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol operation) -> Proc
13
+ def scf: () -> void
14
+ def ccf: () -> void
15
+ def cpl: () -> void
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Nop < Base
8
+ def initialize: (cpu: Cpu) -> void
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Or < Base
8
+ def initialize: (cpu: Cpu, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol source) -> Proc
13
+ def or_a: (Integer value) -> void
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Pop < Base
8
+ def initialize: (cpu: Cpu, reg16: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol reg16) -> Proc
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Push < Base
8
+ def initialize: (cpu: Cpu, reg16: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol reg16) -> Proc
13
+ def push: (Integer value) -> void
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Ret < Base
8
+ def initialize: (cpu: Cpu, ?condition: Symbol, ?enable_ime: bool) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol ?condition, bool ?enable_ime) -> Proc
13
+ def ret_cc: (?condition: bool) -> void
14
+ def ret: () -> void
15
+ def reti: () -> void
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Rotate < Base
8
+ include Utils::BitOps
9
+
10
+ def initialize: (cpu: Cpu, operation: Symbol) -> void
11
+
12
+ private
13
+
14
+ def build_logic: (Symbol operation) -> Proc
15
+ def rlca: () -> void
16
+ def rrca: () -> void
17
+ def rla: () -> void
18
+ def rra: () -> void
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Rst < Base
8
+ def initialize: (cpu: Cpu, vector: Integer) -> void
9
+
10
+ private
11
+
12
+ def rst: (Integer vector) -> void
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Sbc < Base
8
+ def initialize: (cpu: Cpu, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def define_mnemonic: (Symbol source) -> String
13
+ def build_logic: (Symbol source) -> Proc
14
+ def sbc_a: (Integer value) -> void
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Stop < Base
8
+ def initialize: (cpu: Cpu) -> void
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Sub < Base
8
+ def initialize: (cpu: Cpu, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def build_logic: (Symbol source) -> Proc
13
+ def sub_a: (Integer value) -> void
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ class Xor < Base
8
+ def initialize: (cpu: Cpu, source: Symbol) -> void
9
+
10
+ private
11
+
12
+ def define_mnemonic: (Symbol source) -> String
13
+ def build_logic: (Symbol source) -> Proc
14
+ def xor_a: (Integer value) -> void
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Cpu
6
+ module Instructions
7
+ def self.load_base_instructions: (cpu: Cpu) -> void
8
+ def self.load_cb_instructions: (cpu: Cpu) -> void
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ module Amaterasu
2
+ module GameBoy
3
+ class Cpu
4
+ class Registers
5
+ include Utils::BitOps
6
+
7
+ attr_reader a: Integer
8
+ attr_reader f: Integer
9
+ attr_reader b: Integer
10
+ attr_reader c: Integer
11
+ attr_reader d: Integer
12
+ attr_reader e: Integer
13
+ attr_reader h: Integer
14
+ attr_reader l: Integer
15
+
16
+ attr_reader sp: Integer
17
+ attr_reader pc: Integer
18
+
19
+ def initialize: (?skip_boot_rom: bool) -> void
20
+
21
+ def a=: (Integer value) -> Integer
22
+ def f=: (Integer value) -> Integer
23
+ def b=: (Integer value) -> Integer
24
+ def c=: (Integer value) -> Integer
25
+ def d=: (Integer value) -> Integer
26
+ def e=: (Integer value) -> Integer
27
+ def h=: (Integer value) -> Integer
28
+ def l=: (Integer value) -> Integer
29
+
30
+ def af=: (Integer value) -> Integer
31
+ def bc=: (Integer value) -> Integer
32
+ def de=: (Integer value) -> Integer
33
+ def hl=: (Integer value) -> Integer
34
+ def sp=: (Integer value) -> Integer
35
+ def pc=: (Integer value) -> Integer
36
+
37
+ def af: () -> Integer
38
+ def bc: () -> Integer
39
+ def de: () -> Integer
40
+ def hl: () -> Integer
41
+
42
+ def z_flag: () -> Integer
43
+ def n_flag: () -> Integer
44
+ def h_flag: () -> Integer
45
+ def c_flag: () -> Integer
46
+
47
+ def z_flag=: (Integer bit) -> Integer
48
+ def n_flag=: (Integer bit) -> Integer
49
+ def h_flag=: (Integer bit) -> Integer
50
+ def c_flag=: (Integer bit) -> Integer
51
+
52
+ def clear_flags: () -> void
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ module Amaterasu
2
+ module GameBoy
3
+ class Cpu
4
+ INSTRUCTIONS: Hash[Integer, Proc]
5
+ CB_INSTRUCTIONS: Hash[Integer, Proc]
6
+
7
+ attr_reader registers: Registers
8
+
9
+ def initialize: (Bus bus, Hram hram, Interrupts interrupts, Proc advance_cycle, bool ?trace_cpu) -> void
10
+
11
+ def step: () -> void
12
+
13
+ def bus_read: (address: Integer) -> Integer
14
+ def bus_write: (address: Integer, value: Integer) -> void
15
+ def fetch_next_byte: () -> Integer
16
+ def fetch_next_word: () -> Integer
17
+
18
+ def sign_value: (Integer byte) -> Integer
19
+ def add16: (Integer value1, Integer value2) -> Integer
20
+ def sub16: (Integer value1, Integer value2) -> Integer
21
+
22
+ def stack_push: (value: Integer) -> void
23
+ def stack_pop: () -> Integer
24
+
25
+ def jump_to: (address: Integer) -> void
26
+ def halt: () -> void
27
+ def enable_interrupts: () -> void
28
+ def disable_interrupts: () -> void
29
+
30
+ private
31
+
32
+ def handle_interrupts: () -> void
33
+ def decode_instruction: () -> void
34
+ def execute_instruction: () -> void
35
+ def internal_processing: () -> void
36
+ def log_state: (Integer old_pc, Integer old_cycles, Instructions::Base instruction) -> void
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ module Amaterasu
2
+ module GameBoy
3
+ class Interrupts
4
+ type interrupt_types = :v_blank | :lcd_stat | :timer | :serial | :joypad
5
+
6
+ TYPES: Hash[interrupt_types, Integer]
7
+ VECTORS: Hash[interrupt_types, Integer]
8
+
9
+ def initialize: (?skip_boot_rom: bool) -> void
10
+
11
+ def if_register: () -> Integer
12
+ def ie_register: () -> Integer
13
+ def if_register=: (Integer value) -> void
14
+ def ie_register=: (Integer value) -> void
15
+
16
+ def any_pending?: () -> bool
17
+ def highest_pending: () -> interrupt_types
18
+ def request: (interrupt_types value) -> void
19
+ def service: (interrupt_types value) -> void
20
+ def priority_vector: () -> Integer
21
+ def priority_service: () -> void
22
+
23
+ private
24
+
25
+ def pending?: (interrupt_types value) -> bool
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Amaterasu
2
+ module GameBoy
3
+ class Joypad
4
+ FACE_BUTTONS: Hash[Symbol, Integer]
5
+ DPAD_BUTTONS: Hash[Symbol, Integer]
6
+
7
+ def initialize: (Interrupts interrupts) -> void
8
+
9
+ def p1: () -> Integer
10
+ def p1=: (Integer value) -> void
11
+
12
+ def press_dpad: (Symbol button) -> void
13
+ def release_dpad: (Symbol button) -> void
14
+ def press_face: (Symbol button) -> void
15
+ def release_face: (Symbol button) -> void
16
+
17
+ private
18
+
19
+ def request_interrupt: () -> void
20
+ def dpad_selected?: () -> bool
21
+ def buttons_selected?: () -> bool
22
+ def buttons_state: () -> Integer
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Oam
6
+ class Sprite
7
+ SIZE_IN_BYTES: Integer
8
+
9
+ BIT_MASK_BG_WIN_PRIORITY_SET: Integer
10
+ BIT_MASK_OBJ_Y_FLIPPED: Integer
11
+ BIT_MASK_OBJ_X_FLIPPED: Integer
12
+ BIT_MASK_USE_OBP1_PALETTE: Integer
13
+
14
+ def initialize: () -> void
15
+
16
+ def x: () -> Integer
17
+ def x_screen_pos: () -> Integer
18
+ def y: () -> Integer
19
+ def y_screen_pos: () -> Integer
20
+
21
+ def bg_win_priority_set?: () -> bool
22
+ def y_flipped?: () -> bool
23
+ def x_flipped?: () -> bool
24
+ def use_obp1_palette?: () -> bool
25
+
26
+ def inspect: () -> String
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ class Disabled
8
+ attr_reader name: String
9
+ attr_reader number: Integer
10
+
11
+ def initialize: () -> void
12
+ def tick: () -> void
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ class HBlank
8
+ attr_reader name: String
9
+ attr_reader number: Integer
10
+
11
+ def initialize: () -> void
12
+ def tick: () -> void
13
+
14
+ def to_s: () -> String
15
+ def inspect: () -> String
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ class OamScan
8
+ SCAN_DURATION_IN_DOTS: Integer
9
+
10
+ attr_reader name: String
11
+ attr_reader number: Integer
12
+
13
+ def initialize: () -> void
14
+ def tick: () -> void
15
+
16
+ def to_s: () -> String
17
+ def inspect: () -> String
18
+
19
+ private
20
+
21
+ def window_triggered?: () -> bool
22
+ def sprite_within_current_scanline?: () -> bool
23
+ def sort_sprites_by_x_positions: () -> void
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ class Rendering
8
+ attr_reader name: String
9
+ attr_reader number: Integer
10
+
11
+ def initialize: () -> void
12
+ def tick: () -> void
13
+
14
+ def to_s: () -> String
15
+ def inspect: () -> String
16
+
17
+ private
18
+
19
+ def any_sprites?: () -> bool
20
+ def sprite_offscreen?: (Oam::Sprite sprite) -> bool
21
+ def window_reached?: () -> bool
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ class VBlank
8
+ attr_reader name: String
9
+ attr_reader number: Integer
10
+
11
+ def initialize: () -> void
12
+ def tick: () -> void
13
+
14
+ def to_s: () -> String
15
+ def inspect: () -> String
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Amaterasu
4
+ module GameBoy
5
+ class Ppu
6
+ module Modes
7
+ type ppu_mode = Disabled | OamScan | Rendering | HBlank | VBlank
8
+
9
+ def self.build_hash: (ppu: Ppu) -> Hash[Symbol, ppu_mode]
10
+ end
11
+ end
12
+ end
13
+ end