added glad

This commit is contained in:
Lauchmelder 2022-08-31 18:47:44 +02:00
parent a24235b586
commit 89c3553088
23 changed files with 11790 additions and 22 deletions

View file

@ -1,14 +1,52 @@
mod nes;
mod bus;
mod cpu;
mod instructions;
mod addressing;
mod cartridge;
mod mnemonic;
mod renderer;
use nes::NES;
use std::ffi::{c_void, CStr};
use glfw::{Context};
use nes::nes::NES;
use renderer::context;
fn main() {
let nes = NES::new();
nes.powerup();
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
let (mut window, events) = glfw.create_window(800, 800, "Rusty NES Emulator", glfw::WindowMode::Windowed)
.expect("Failed to create GLFW window.");
window.set_key_polling(true);
window.make_current();
let res: i32;
unsafe
{
res = context::init_opengl(
&mut glfw as *mut _ as *mut c_void,
|glfw, name| (&mut *(glfw as *mut glfw::Glfw)).get_proc_address_raw(CStr::from_ptr(name).to_str().unwrap()));
}
if res != 0 {
eprintln!("Failed to initialize GLAD.");
return;
}
while !window.should_close()
{
glfw.poll_events();
for (_, event) in glfw::flush_messages(&events)
{
match event
{
_ => {}
}
}
unsafe { context::clear(); }
window.swap_buffers();
}
return;
}

View file

@ -1,4 +1,4 @@
use crate::cpu::{CPU, FetchType};
use crate::nes::cpu::{CPU, FetchType};
#[macro_export]
macro_rules! instr_size

View file

@ -1,8 +1,8 @@
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use crate::cpu::CPU;
use crate::cartridge::Cartridge;
use crate::nes::cpu::CPU;
use crate::nes::cartridge::Cartridge;
pub struct Bus
{

View file

@ -1,8 +1,8 @@
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use crate::bus::Bus;
use crate::instructions::INSTRUCTION_SET;
use crate::nes::bus::Bus;
use crate::nes::instructions::INSTRUCTION_SET;
pub enum FetchType
{

View file

@ -1,7 +1,7 @@
use crate::cpu::{CPU, FetchType};
use crate::bus::Bus;
use crate::addressing::AddrFn;
use crate::mnemonic::Mnemonic;
use crate::nes::cpu::{CPU, FetchType};
use crate::nes::bus::Bus;
use crate::nes::addressing::AddrFn;
use crate::nes::mnemonic::Mnemonic;
use crate::instr_size;
use std::cell::Ref;

8
src/nes/mod.rs Normal file
View file

@ -0,0 +1,8 @@
pub mod nes;
mod cpu;
mod bus;
mod addressing;
mod instructions;
mod mnemonic;
mod cartridge;

View file

@ -1,7 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
use crate::bus::Bus;
use crate::cpu::CPU;
use crate::nes::bus::Bus;
use crate::nes::cpu::CPU;
pub struct NES
{
@ -28,10 +28,10 @@ impl NES
pub fn powerup(&self)
{
self.cpu.borrow_mut().powerup();
}
loop
{
self.cpu.borrow_mut().cycle();
}
pub fn clock(&self)
{
self.cpu.borrow_mut().cycle();
}
}

12
src/renderer/context.rs Normal file
View file

@ -0,0 +1,12 @@
use std::ffi::c_void;
extern "C"
{
#[allow(improper_ctypes)]
pub fn init_opengl(
loader: *mut c_void,
f: fn(*mut c_void, *const i8) -> *const c_void
) -> i32;
pub fn clear();
}

1
src/renderer/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod context;