Skip to content

Instantly share code, notes, and snippets.

View yupferris's full-sized avatar

Jake Taylor yupferris

View GitHub Profile
@yupferris
yupferris / execute.sv
Created January 31, 2020 20:45
oldboi
module execute(
input wire logic reset_n,
input wire logic clk,
input wire logic [31:0] instruction,
input wire logic [31:0] register_file_read_data1,
input wire logic [31:0] register_file_read_data2,
input wire logic [31:0] alu_res,
input wire logic [31:0] pc,
input wire logic [63:0] cycle_counter_value,
@yupferris
yupferris / mem.rs
Last active January 24, 2020 20:22
emu shiz
struct Emu {
wram: [u8; lots],
sub_cpu_1: SubCpu1,
sub_cpu_2: SubCpu2,
}
impl Emu {
fn cycle(&mut self) {
self.sub_cpu_1.cycle(&mut self.wram); // "splitting" borrow is ok here since we borrow disjoint elements of self
...
fn main() {
let w = 128.1337f32;
let w_inverse = 1.0 / w;
println!("w: {}", w);
println!("w_inverse: {}", w_inverse);
fn to_fixed(x: f32, fract_bits: i32) -> i32 {
let bits = x.to_bits() as i32;
let exponent = ((bits >> 23) & 0xff) - 127 - 23 + fract_bits;
@yupferris
yupferris / reset_synchronizer.sv
Created September 4, 2019 18:17
Back to basics...
// Note that the asynchronous reset input, reset_n, should be unconstrained, eg:
// set_false_path -from [get_ports {reset_n}] -to [get_clocks {*}]
`default_nettype none
module reset_synchronizer(
input reset_n,
input clk,
output reset_n_sync);
@yupferris
yupferris / led_test.sdc
Last active September 5, 2019 17:11
Simplest possible .sdc for future reference
create_clock -name max10_clk_50 -period 20 [get_ports {max10_clk_50}]
# Note - can use `derive_pll_clocks -create_base_clocks` without specifying input clocks to derive everything when PLL's are used for all clocks
derive_pll_clocks
derive_clock_uncertainty
# Don't constrain async reset signal
set_false_path -from [get_ports {reset_n}] -to [all_registers]
# Don't constrain LED output
@yupferris
yupferris / i-win.md
Last active February 11, 2019 12:15
I beat exomizer by how much?

tl;dr

  • original released intro size: 4095 bytes
  • final size with new packer: 3892 bytes (203 bytes reduction, 4.9% better than released version)
  • best possible size w/ smallest exomizer decoder: 4001 bytes
  • best possible size w/ largest exomizer decoder: 4024 bytes
  • new packer gain over smallest exomizer size: 109 bytes (2.7% reduction)
  • new packer gain over largest exomizer size: 132 bytes (3.3% reduction)

========================================

@yupferris
yupferris / ends_with_case_insensitive.rs
Last active November 4, 2017 22:17
ffs windows, ruining my file watching with your case-insensitivity..
// This is kindof a crazy way to compare paths, and in certain unicode corner cases will not be entirely correct,
// but it's a workaround for file name case insensitivity on Windows and should be good enough for most cases.
// The general idea (matching path component suffixes) mimicks Rust's Path::ends_with.
fn ends_with_case_insensitive(path: &PathBuf, suffix: &PathBuf) -> bool {
let path_comps = path.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev();
let suffix_comps = suffix.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev();
let matching_suffix_pairs = path_comps.zip(suffix_comps).filter(|&(ref x, ref y)| x == y);
matching_suffix_pairs.count() == suffix.components().count()
}
@yupferris
yupferris / vic.txt
Created September 10, 2017 20:09
VIC pseudocode (not necessarily accurate/rigorous, but useful enough to explain stuff)
// Sometime outside of display area..
VCBASE := 0
VIDEO_COLOR_BUFFER := 0
for RASTER in 0..312 {
for line_cycle in 0..63 {
badline_condition := (RASTER & 0x07) == (YSCROLL & 0x07)
if (badline_condition) {
MODE = MODE_DISPLAY
}
@yupferris
yupferris / stuff.rs
Created June 25, 2017 19:29
wavy stuff
extern crate minifb;
extern crate time;
use minifb::{Key, Scale, WindowOptions, Window};
use std::f64::consts::PI;
fn circle(x: f64, y: f64, x_offset: f64, y_offset: f64, rad: f64) -> bool {
let x_distance = x - x_offset;
let y_distance = y - y_offset;
@yupferris
yupferris / bowling.asm
Last active March 9, 2017 21:00
Virtual Bowling sample playback routine reversing notes
// Super high-level playroutine overview:
// Timer reload set to 12, 13, 5 (depending on sample)
// Timer int fires every ??us (sample rate of ??hz)
// Store 0x1d in timer control (small interval, zero interrupt enable, clear zero status, timer enable)
// Output volume to VOICE_1_ENVELOPE_DATA
// Sample value -> register value lookup table:
0xffffd258 00 10 20 30 40 50 60 70 80 90 a0 b0 c0 d0 e0 f0
// Sample playback routine (only thing the timer is used for in this game)