Skip to content

Commit

Permalink
removed some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
davecom committed Apr 20, 2024
1 parent 68d0f7a commit a300110
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .idea/FunComputerScienceProjectsInPython.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion NESEmulator/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def read_memory(self, location: int, mode: MemMode) -> int:
# Memory map at http://wiki.nesdev.com/w/index.php/CPU_memory_map
if address < 0x2000: # main ram 2 KB goes up to 0x800
return self.ram[address % 0x800] # mirrors for next 6 KB
elif address < 0x3FFF: # 2000-2007 is PPU, up to 3FFF mirrors it every 8 bytes
elif address < 0x4000: # 2000-2007 is PPU, up to 3FFF mirrors it every 8 bytes
temp = ((address % 8) | 0x2000) # get data from ppu register
return self.ppu.read_register(temp)
elif address == 0x4016: # Joypad 1 status
Expand Down
13 changes: 4 additions & 9 deletions NESEmulator/ppu.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def step(self):

def draw_background(self):
attribute_table_address = self.nametable_address + 0x3C0
# 30 tiles in width and 32 tiles in height
# 32 tiles in width and 30 tiles in height
for y in range(30):
for x in range(32):
tile_address = self.nametable_address + y * 0x20 + x
Expand Down Expand Up @@ -116,17 +116,13 @@ def draw_background(self):
transparent_background = ((pixel & 3) == 0)
# if the background is transparent, we use the first color in the palette
color = self.palette[0] if transparent_background else self.palette[pixel]
# self.display_buffer[x_screen_loc, y_screen_loc] = NES_PALETTE[color]
self.display_buffer[x_screen_loc, y_screen_loc] = NES_PALETTE[color]
# plot pixel here draw_pixel(x_screen_loc, y_screen_loc,
# transparent_background ? palette[0] : palette[pixel]);

def draw_sprites(self, background_transparent: bool):
for i in range(SPR_RAM_SIZE - 4, -4, -4):
y_position = self.spr[i]
if y_position == 0xFF: # 0xFF is a marker for no sprite data
continue
# we actually draw sprites shifted one pixel down
background_sprite = bool((self.spr[i + 2] >> 5) & 1)
x_position = self.spr[i + 3]

Expand All @@ -140,15 +136,15 @@ def draw_sprites(self, background_transparent: bool):
sprite_line = y - y_position
if flip_y:
sprite_line = 7 - sprite_line

index = self.spr[i + 1]
bit0s_address = self.spr_pattern_table_address + (index * 16) + sprite_line
bit1s_address = self.spr_pattern_table_address + (index * 16) + sprite_line + 8
bit0s = self.read_memory(bit0s_address)
bit1s = self.read_memory(bit1s_address)
bit3and2 = ((self.spr[i + 2]) & 3) << 2
# draw the 8 pixels on this scanline
flip_x = bool((self.spr[i + 2] >> 6) & 1)

flip_x = bool((self.spr[i + 2] >> 6) & 1)
x_loc = x - x_position # position within sprite
if not flip_x:
x_loc = 7 - x_loc
Expand All @@ -166,12 +162,11 @@ def draw_sprites(self, background_transparent: bool):
# need to do this after sprite zero checking so we still count background
# sprites for sprite zero checks
if background_sprite and not background_transparent:
continue # don't draw over opaque background pixels if this is backround sprite
continue # don't draw over opaque background pixels if this is background sprite

color = bit3and2 | bit1and0
color = self.read_memory(0x3F10 + color) # pull from palette
self.display_buffer[x, y] = NES_PALETTE[color]
# draw_pixel(x, y, color)

def read_register(self, address: int) -> int:
if address == 0x2002:
Expand Down
2 changes: 1 addition & 1 deletion NESEmulator/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, filename: str):
# Read PRG_ROM and CHR_ROM, these are in multiples of 16K and 8K respectively
self.prg_rom = file.read(PRG_ROM_BASE_UNIT_SIZE * self.header.prg_rom_size)
self.chr_rom = file.read(CHR_ROM_BASE_UNIT_SIZE * self.header.chr_rom_size)
self.prg_ram = array('B', [0] * PRG_RAM_SIZE) # sprite ram
self.prg_ram = array('B', [0] * PRG_RAM_SIZE) # ram

def read_mapper0(self, address: int) -> int:
if address < 0x2000:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
setuptools~=68.2.2
Pillow~=10.1.0
Pillow~=10.3.0
pygame~=2.5.2
numpy~=1.26.1
numpy~=1.26.4

0 comments on commit a300110

Please sign in to comment.