summary refs log tree commit diff
path: root/src/main.rs
blob: 2fcee187da205bd8ed19c2e16c41406a093706e5 (plain) (blame)
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
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: AGPL-3.0-or-later

//! 6502 Emulator written in Rust. Based off of information from Dave's playlist
//! <https://www.youtube.com/playlist?list=PLLwK93hM93Z13TRzPx9JqTIn33feefl37>
//! using the now defunct obelisk 6502 documentation.
//!
//! Many comments are sourced from the Obelisk 6502 documentation
//! <https://web.archive.org/web/20210501031403/http://www.obelisk.me.uk/index.html>

mod cpu;
mod instruction;
mod memory;

use tracing::level_filters::LevelFilter;

use cpu::Cpu;
use memory::Memory;

fn main() {
	tracing_subscriber::fmt()
		.with_max_level(LevelFilter::TRACE)
		.init();

	let mut cpu = Cpu::new();
	let mut memory = Memory::new();

	cpu.reset(&mut memory);

	// little program
	if let Some(opcode) = memory.data.get_mut(0xFFFC) {
		*opcode = 0x20;
	}
	if let Some(opcode) = memory.data.get_mut(0xFFFD) {
		*opcode = 0x42;
	}
	if let Some(opcode) = memory.data.get_mut(0xFFFE) {
		*opcode = 0x42;
	}
	if let Some(opcode) = memory.data.get_mut(0x4242) {
		*opcode = 0xA9;
	}
	if let Some(opcode) = memory.data.get_mut(0x4243) {
		*opcode = 0x84;
	}
	// end program

	cpu.execute(9, &mut memory);
}