Skip to content

Instantly share code, notes, and snippets.

ident:
/[A-Za-z_.][A-Za-z0-9_.]*/
expr:
ident |
expr '+' expr |
etc.
nl:
'\' | '\r' | '\n' | EOF
@niconii
niconii / movcpu.rs
Last active November 26, 2016 08:48
A little toy CPU with only a mov instruction
fn main() {
let mut ram = [0u16; 0x2000];
let mut rom = [0xffffu16; 0xc000];
{
let mut ptr = 0x0000;
let mut mov = |dst, src| {
rom[ptr+0] = src;
rom[ptr+1] = dst;
ptr += 2;
@niconii
niconii / stackoffset.asm
Created May 7, 2016 06:50
Accessing byte at offset from stack pointer on 6502
tsx ; transfer stack pointer to X register
stx scratch ; store X in RAM
ldx #$01 ; load 0x01 into X
stx scratch+1 ; store X in RAM
ldx offset ; load offset into X
lda (scratch,x) ; perform an indirect load from *(scratch + X) into A
1+2+2+2+2+2 bytes = 11 bytes
2+3+2+3+3+6 cycles = 19 cycles
@niconii
niconii / bankswitch
Last active November 16, 2016 05:41
bankswitch(bank, address) {
push old bank to stack ; in old bank
switch code bank register to new bank ; in old bank
call bank:address ; in old bank
; function in new bank returns here
pop old bank from stack ; in new bank
switch code bank register to old bank ; in new bank
jump to label in old bank ; in new bank
@niconii
niconii / snescontroller.rs
Created March 22, 2016 16:02
A little SNES controller simulator
trait ControllerPins {
// inputs:
// latch pin (normally low)
fn latch_rising(&mut self);
fn latch_falling(&mut self);
// clock pin (normally high)
fn clock_rising(&mut self);
fn clock_falling(&mut self);
// output:
; Goal: to turn controller button samples, incoming on the x register each
; frame, into three variables:
; - cur, which represents the current state of the controller buttons
; - prs, which represents the buttons pressed this frame
; - rls, which represents the buttons released this frame
;
; Example:
; x cur prs rls
; ................ ................ ................ <- initial values
; ...........1.... ...........1.... ...........1.... ................
@niconii
niconii / bankswitch.rs
Created January 10, 2016 06:42
Messing around with an idea mentioned in https://news.ycombinator.com/item?id=10873525
extern crate sdl2;
use sdl2::pixels::Color;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::sync::mpsc::{Receiver, Sender};
enum Command {
SetBG(u8, u8, u8),
@niconii
niconii / nicode.md
Last active November 16, 2016 05:36

Escape sequences

Sequence Results in
\[ [
\] ]
\\ \

Format characters

@niconii
niconii / pipe_codes
Last active November 16, 2016 05:36
[ '['
x exchange bg/fg colors
krygbcmwn dark colors
KRYGBCMW light colors
h00 256-color
i italics
u underline
c clear all formatting
|[bxWu]Test|c
@niconii
niconii / keybase.md
Created October 10, 2015 21:58
Keybase verification

Keybase proof

I hereby claim:

  • I am niconii on github.
  • I am niconii (https://keybase.io/niconii) on keybase.
  • I have a public key whose fingerprint is 9C90 5AFA 2637 6CD7 7727 442B B306 692C E33C FE6B

To claim this, I am signing this object: