<commit_before>package nes

import (
	"image"
	"log"
)

type NES struct {
	CPU         *CPU
	PPU         *PPU
	CPUMemory   Memory
	PPUMemory   Memory
	Mapper      Mapper
	RAM         []byte
	Cartridge   *Cartridge
	Controller1 *Controller
	Controller2 *Controller
}

func NewNES(path string) (*NES, error) {
	cartridge, err := LoadNESFile(path)
	if err != nil {
		return nil, err
	}
	ram := make([]byte, 2048)
	controller1 := NewController()
	controller2 := NewController()
	mapper := NewMapper(cartridge)
	nes := NES{
		nil, nil, nil, nil,
		mapper, ram, cartridge, controller1, controller2}
	nes.CPUMemory = NewCPUMemory(&nes)
	nes.PPUMemory = NewPPUMemory(&nes)
	nes.CPU = NewCPU(&nes)
	nes.PPU = NewPPU(&nes)
	return &nes, nil
}

func (nes *NES) Step() int {
	cpuCycles := nes.CPU.Step()
	ppuCycles := cpuCycles * 3
	for i := 0; i < ppuCycles; i++ {
		nes.PPU.Step()
	}
	return cpuCycles
}

func (nes *NES) StepFrame() {
	frame := nes.PPU.Frame
	for frame == nes.PPU.Frame {
		nes.Step()
	}
}

func (nes *NES) Buffer() *image.RGBA {
	return nes.PPU.buffer
}

func (nes *NES) SetPressed(controller, button int, pressed bool) {
	switch controller {
	case 1:
		nes.Controller1.SetPressed(button, pressed)
	case 2:
		nes.Controller2.SetPressed(button, pressed)<commit_msg>NES.BackgroundColor<commit_after>package nes

import (
	"image"
	"image/color"
	"log"
)

type NES struct {
	CPU         *CPU
	PPU         *PPU
	CPUMemory   Memory
	PPUMemory   Memory
	Mapper      Mapper
	RAM         []byte
	Cartridge   *Cartridge
	Controller1 *Controller
	Controller2 *Controller
}

func NewNES(path string) (*NES, error) {
	cartridge, err := LoadNESFile(path)
	if err != nil {
		return nil, err
	}
	ram := make([]byte, 2048)
	controller1 := NewController()
	controller2 := NewController()
	mapper := NewMapper(cartridge)
	nes := NES{
		nil, nil, nil, nil,
		mapper, ram, cartridge, controller1, controller2}
	nes.CPUMemory = NewCPUMemory(&nes)
	nes.PPUMemory = NewPPUMemory(&nes)
	nes.CPU = NewCPU(&nes)
	nes.PPU = NewPPU(&nes)
	return &nes, nil
}

func (nes *NES) Step() int {
	cpuCycles := nes.CPU.Step()
	ppuCycles := cpuCycles * 3
	for i := 0; i < ppuCycles; i++ {
		nes.PPU.Step()
	}
	return cpuCycles
}

func (nes *NES) StepFrame() {
	frame := nes.PPU.Frame
	for frame == nes.PPU.Frame {
		nes.Step()
	}
}

func (nes *NES) Buffer() *image.RGBA {
	return nes.PPU.buffer
}

func (nes *NES) BackgroundColor() color.RGBA {
	return palette[nes.PPU.readPalette(0)%64]
}

func (nes *NES) SetPressed(controller, button int, pressed bool) {
	switch controller {
	case 1:
		nes.Controller1.SetPressed(button, pressed)
	case 2:
		nes.Controller2.SetPressed(button, pressed)
{'fraction_non_alphanumeric': 0.13506395786305492, 'fraction_numerical': 0.013167795334838224, 'mean_word_length': 3.689594356261023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6106151', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1048, 'n_words': 257}