Skip to content

Instantly share code, notes, and snippets.

View jroweboy's full-sized avatar

James Rowe jroweboy

  • C wage slave :^)
View GitHub Profile
@jroweboy
jroweboy / fixed_point.h
Last active February 26, 2024 00:28
WIP llvm-mos-sdk Fixed Point math class
// Copyright 2024 LLVM-MOS Project
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.
#ifndef _FIXED_POINT_H
#define _FIXED_POINT_H
@jroweboy
jroweboy / cc65-toolchain.cmake
Last active October 16, 2022 06:39
CC65 CA65 Toolchain for CMake
# CMake toolchain file for cc65
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR 6502)
# Check for user provided CC65_PATH environment variable
list(APPEND CMAKE_PREFIX_PATH $ENV{CC65_PATH})
find_program(_CL65 cl65)
set(CMAKE_C_COMPILER ${_CL65})
@jroweboy
jroweboy / nes2header.h
Last active March 11, 2022 18:54
CC65 NES2 header macro (for use in C)
/**
* NES 2.0 header generator for cc65 (nes2header.h)
*
* USAGE: Generates a header for the NES2 format with C macros
* Before including this header, define the following values
*
* - NES2_MAPPER, NES2_SUBMAPPER
* Sets the mapper (board class) ID. For example, MMC3 is usually
* mapper 4, but TLSROM is 118 and TQROM is 119. Some mappers have
@jroweboy
jroweboy / 3ds_mic_update_rate_test.c
Created March 2, 2019 03:53
Hardware test for 3ds mic rate at which it writes to the shared mem buffer
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <3ds.h>
#include <time.h>
void sampleTest(MICU_SampleRate sampleRate) {
if(R_SUCCEEDED(MICU_StartSampling(MICU_ENCODING_PCM16_SIGNED, sampleRate, 0, micGetSampleDataSize(), true))) printf("Now recording.\n");
@jroweboy
jroweboy / main.cpp
Created September 21, 2018 01:45
Trying to figure out a good way to make handle this scenario
// place where other input state is stored
std::shared_ptr<SDL> state;
// Ties the lifetime of the SDL input code to whatever the frontend decides is important
void Init() {
state = SDL::Init();
}
void Shutdown() {
state.reset();
@jroweboy
jroweboy / file_io.cpp
Created March 11, 2015 03:48
file_io.cpp
#include "file_io.h"
#include <cstdio>
#ifdef _WIN64
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
#endif
size_t WriteBinaryFile(const std::string& filename, const void* buffer, const size_t buf_size)
{
@jroweboy
jroweboy / custom_decoder.rs
Created December 5, 2014 21:07
A sample custom decoder implementation that I wrote back in July. Still compiles, but it could be cleaner I guess
extern crate serialize;
use serialize::json;
use serialize::json::{DecodeResult, DecoderError, UnknownVariantError, MissingFieldError};
use serialize::{Decoder, Decodable};
#[deriving(Show)]
pub struct Test {
recipe_id: int,
type_: String,

Help the docs!

So! The new tutorial will be focused on building several small projects in Rust. This example is the first one: a classic 'guessing game.' This was one of the first programs I wrote when I first learned C. 😄

I'd like the feedback of the community before I actually start writing the guide. So this code will be the final code of the first real example Rust programmers see. So I want it to be good. I don't claim this code is good, I just worked something out real quick.

The idea is that I will slowly build from hello world to this final code in steps, introducing one concept at a time. Here are the concepts I'd like a Rust programmer to understand by the time they're done:

Concepts

#![feature(plugin_registrar, quote, phase)]
#![crate_type = "dylib"]
extern crate syntax;
use syntax::{ast, codemap};
use syntax::ext::base::{
SyntaxExtension, ExtCtxt, MacResult, MacExpr,
NormalTT, BasicMacroExpander,
};
@jroweboy
jroweboy / floor.rs
Created June 4, 2014 21:33
Quick Fix?
impl Server {
fn new(route_store: Arc<RWLock<RouteStore>>) -> Server {
Server {
route_store: route_store
}
}
}
impl Floor {
pub fn get(&mut self, uri: &str, handler: fn(request: &Request, response: &mut ResponseWriter) -> ()){