Skip to content

Instantly share code, notes, and snippets.

View bokuweb's full-sized avatar
👾
Working from home

bokuweb bokuweb

👾
Working from home
View GitHub Profile
@bokuweb
bokuweb / map.rs
Last active April 11, 2018 13:35
lazy_static! {
pub static ref MAP: HashMap<u8, Opecode> = {
let mut m = HashMap::new();
m.insert(0xA9, Opecode { name: Instruction::LDA, mode: Addressing::Immediate, cycle: cycles[0xA9] });
m.insert(0xA5, Opecode { name: Instruction::LDA, mode: Addressing::ZeroPage, cycle: cycles[0xA5] });
m.insert(0xB5, Opecode { name: Instruction::LDA, mode: Addressing::ZeroPageX, cycle: cycles[0xB5] });
m.insert(0xAD, Opecode { name: Instruction::LDA, mode: Addressing::Absolute, cycle: cycles[0xAD] });
// ...
}
pub fn run<T: CpuRegisters + Debug, U: CpuBus>(registers: &mut T, bus: &mut U) -> Data {
let _code = fetch(registers, bus);
let ref map = opecode::MAP;
let code = &*map.get(&_code).unwrap();
let opeland = fetch_opeland(&code, registers, bus);
match code.name {
Instruction::LDA if code.mode == Addressing::Immediate => lda_imm(opeland, registers),
Instruction::LDA => lda(opeland, registers, bus),
Instruction::LDX if code.mode == Addressing::Immediate => ldx_imm(opeland, registers),
Instruction::LDX => ldx(opeland, registers, bus),
#[derive(Debug)]
struct Status {
negative: bool,
overflow: bool,
reserved: bool,
break_mode: bool,
decimal_mode: bool,
interrupt: bool,
zero: bool,
carry: bool,
build:
cargo rustc — release \
— target=wasm32-unknown-emscripten — \
-C opt-level=3 \
-C link-args=”-O3 -s NO_EXIT_RUNTIME=1 -s EXPORTED_FUNCTIONS=[‘_run’]”
mergeInto(LibraryManager.library, {
canvas_render: function (ptr, len) {
Module.NES.buf = new Uint8Array(Module.HEAPU8.buffer, ptr, len);
Module.NES.image.data.set(Module.NES.buf);
Module.NES.ctx.putImageData(Module.NES.image, 0, 0);
}
}
mod color;
use super::{BackgroundField, BackgroundCtx};
use super::PaletteList;
use super::{Sprite, SpritesWithCtx, SpritePosition};
use self::color::COLORS;
extern "C" {
fn canvas_render(ptr: *const u8, len: usize);
}
Address Size Device
0x0000~0x07FF 0x0800 WRAM
0x0800~0x1FFF - WRAM(mirror)
0x2000~0x2007 0x0008 PPU Registers
0x2008~0x3FFF - PPU Registers(mirror)
0x4000~0x401F 0x0020 APU I/O、PAD
0x4020~0x5FFF 0x1FE0 exROM
0x6000~0x7FFF 0x2000 exRAM
0x8000~0xBFFF 0x4000 ProgramROM
0xC000~0xFFFF 0x4000 ProgramROM
Name Size Description
A 8bit Accumrator
X 8bit Index
Y 8bit Index
S 8bit Stack Pointer(SP)
P 8bit Status
PC 16bit Program Counter(PC)
<script src="./gpu.js" type="text/javascript"></script>
<script>
const gpu = new GPU();
const n = 512;
const matMul = gpu.createKernel(function (a, b) {
var sum = 0;
for (var i = 0; i < this.constants.size; i++) {
if (false) {
sum += a[i] + b[i] * 2;
} else {
@bokuweb
bokuweb / emcc_wget.c
Created September 29, 2017 01:08 — forked from nikuuchi/emcc_wget.c
emscripten.hを使ってみた時のメモ
#include <stdio.h>
#include <stdlib.h>
#include <emscripten.h>
void onLoadCallback(const char *filename) {
FILE *fp;
char s[256];
if((fp = fopen(filename, "r")) == NULL) {
printf("file open error!!\n");