-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppu_helper.rb
executable file
·40 lines (32 loc) · 1.17 KB
/
ppu_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# To change this template, choose Tools | Templates
# and open the template in the editor.
module PPUHelper
PATTERN_TABLE_BIT_MASK = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01]
PATTERN_TABLE_BYTE1_BIT_SHIFT = [7, 6, 5, 4, 3, 2, 1, 0]
PATTERN_TABLE_BYTE2_BIT_SHIFT = [6, 5, 4, 3, 2, 1, 0, -1]
ATTRIBUTE_TABLE_BIT_MASK = [0x03, 0x0C, 0x30, 0xC0]
ATTRIBUTE_TABLE_BIT_SHIFT = [-2, 0, 2, 4]
def initialize
end
def get_tile_index(scanline, scanline_cycle)
return (((scanline / 8).floor) * 32) + (scanline_cycle / 8).floor
end
def get_pattern_table_byte1_index(pattern_table_index, scanline)
return (pattern_table_index * 16) + (scanline % 8)
end
def get_pattern_table_byte2_index(pattern_table_index, scanline)
return ((pattern_table_index * 16) + 8) + (scanline % 8)
end
def get_attribute_table_index(tile_index)
result = 0
result += ((tile_index / 128).floor * 8) # Row of attribute table 'grids'
result += ((tile_index % 32) / 4).floor
return result
end
def get_attribute_table_square(tile_index)
square = 0
square = 2 if (tile_index % 128 >= 64)
square += 1 if (tile_index % 4 >= 2)
return square
end
end