Skip to content

Instantly share code, notes, and snippets.

View yupferris's full-sized avatar

Jake Taylor yupferris

View GitHub Profile
@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 / 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 / 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 / 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);
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 / 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
...
@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 / if_haxx.rs
Last active February 1, 2020 01:21
I feel dirty.
/// **UNSTABLE:** Provides a convenient way to write conditional combinational logic.
///
/// # Panics
///
/// Since this macro rewrites the referenced variable assignments using [`mux`], any panic conditions from that method apply to the generated code as well.
///
/// # Examples
///
/// ```
/// use kaze::*;
@yupferris
yupferris / livecoding-qna.md
Created April 20, 2020 11:16
What even was this?

How would you define livecoding in the demoscene? A sport? An art? Something else?

Definitely a mix of the two. There's a definitively competitive aspect that isn't necessarily present in other livecoding scenarios (eg. algorave) which makes it at least e-sports like, while still being an inherently artistic medium.

What are the reasons a shader wins over another one in a livecoding session and why, in your opinion?

It depends on the audience of course. It's the same with demos - people like what they like. For the demoscene, a cool 3D scene with lots of shiny things will often win. However, sometimes a very stylistic 2D shader will also win if it captures the audience (which is particularly common if it appeals to an "oldschool" palate, eg. by using a classic C64 color scheme/dithering style).

When did you first hear of livecoding in the demoscene?

diff --git a/rtl/src/color_thrust.rs b/rtl/src/color_thrust.rs
index 58b94d5..5fa8482 100644
--- a/rtl/src/color_thrust.rs
+++ b/rtl/src/color_thrust.rs
@@ -19,15 +19,25 @@ pub const REG_W1_DY_ADDR: u32 = 6;
pub const REG_W2_MIN_ADDR: u32 = 7;
pub const REG_W2_DX_ADDR: u32 = 8;
pub const REG_W2_DY_ADDR: u32 = 9;
-
-pub const REG_COLOR_ADDR: u32 = 10;