Skip to content

Instantly share code, notes, and snippets.

@seth10
seth10 / gba.h
Last active January 3, 2017 04:14
Minimal GBA platformer... with just a floor
// gba.h by eloist
#ifndef GBA_HEADER
#define GBA_HEADER
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef signed char s8;
@seth10
seth10 / main.c
Created January 4, 2017 03:30
Reorganized all code to wait for VBlank, this is before simplifying with VCount
/*
* Main written by Seth Tenembaum beginning Jan 2, 2017
*
* The purpose of this document is to come to a better understanding of the fundamentals of game developmeny by building a simple platformer from scratch at a low level (but not quite down to assembly at the moment).
*
* TODO
* - fix issue when holding left and right (actually not possible on physical hardware...)
* - subpixel positioning and detach movement speed from frame rate
* - add a single platform
* - implement a global coordinate system, array of platform positions and sizes, and a camera
@seth10
seth10 / gfx.c
Created January 7, 2017 17:22
A different idea for helper drawing method in GBA graphics mode 4 that won't work
void drawPixel_mode4(int x, int y, u8 color)
{
u16 *here = (REG_DISPCNT & BACKBUFFER ? VideoBuffer : BackBuffer) + x%(SCREEN_WIDTH/2) + y*(SCREEN_WIDTH/2);
*here = color + (*here & 0xFF00);
}
void drawRect_mode4(int x, int y, int w, int h, u8 c)
{
u16 *currentBackBuffer = REG_DISPCNT & BACKBUFFER ? VideoBuffer : BackBuffer;
int ix, iy;
@seth10
seth10 / codestyle.c
Last active January 7, 2017 20:10
No this isn't serious
p(x,y,c){(*(4<<24)&16?6<<24:0x600A<<12)+x%120+y*80=x%2==0?c+(((*(4<<24)&0x10?6<<24:0x600A<12)+x%120+y*80)&0xFF00):(u8)((*(4<<24)&0x10?6<<24:0x600A<<12)+x%120+y*80)+(c<<8);}
r(x,y,w,h,c){for(i=x/2-1;++i<(x+w+1)/2;)for(j=y-1;++j<y+h;)i*2==x-1?p(i+1,j,c):i*2==x+w-1?p(i,j,c):(*(4<<24)&16?6<<24:0x600A<<12)+i%120+j*80=c+(c<<8);}
@seth10
seth10 / motorRunSeconds_example.ino
Created January 25, 2017 14:57
go_comeback.ino example modified to just show motorRunSeconds
#include <Wire.h>
#include <EVShield.h>
// setup for this example:
// attach external power to EVShield.
// attach 2 motors to motor ports on Bank A
EVShield evshield(0x34,0x36);
void
@seth10
seth10 / slyt277.py
Last active May 12, 2017 13:35
Calibration based on TI's paper, www.ti.com/lit/SLYT277
import numpy as np
from PiStorms import PiStorms
def calibrate(psm):
def generateA(X,Y):
for (x,y) in zip(X,Y):
psm.screen.fillRect(x,y, 1,1, (255,0,0))
while psm.isKeyPressed(): pass # wait until the button is released from a possible previous press
while not psm.isKeyPressed(): pass # wait until the key is pressed down again
tsX = int(psm.screen.RAW_X()) # mindsensors_i2c.readInteger should really already return an integer
class A:
def __init__(self, param1):
print "Class A recieved a param1 of", param1
class B(A):
def __init__(self, param1, param2):
super().__init__()
print "Class B for param1", param1, "param2", param2
#a = A(111)
@seth10
seth10 / clcp_sd540c.sh
Last active May 12, 2017 13:36
bash brace expansion is fun
admin@roboRIO-1086-FRC:~$ clcp_sd540c scan
{"scan":[10,12,13,15,16,17,18]}
admin@roboRIO-1086-FRC:~$ for id in 1{0,2,3,{5..8}}; do clcp_sd540c $id name; done
status: 0
{"name":"GreenTen"}
status: 0
{"name":"YellowTw"}
status: 0
{"name":"GreenThi"}
status: 0
@seth10
seth10 / 00-TouchTest.py
Created February 23, 2017 13:55
A simple PiStorms program to print the touchscreen coordinates on screen
from PiStorms import PiStorms
psm = PiStorms()
psm.screen.drawDisplay('Raw touchscreen vals')
psm.screen.termPrintAt(8, 'Press GO to quit.')
while not psm.isKeyPressed():
psm.screen.termPrintAt(0, 'X: %d' % psm.screen.TS_X())
psm.screen.termPrintAt(1, 'Y: %d' % psm.screen.TS_Y())
@seth10
seth10 / isPrime.playground
Created February 27, 2017 21:18
Created October 4, 2015 at 12:05 AM
//: Playground - noun: a place where people can play
var n = 61
var isPrime = true
//for var factor = 2; factor < n; factor++ {
for factor in stride(from: 2, to: n/2, by: 2) {
if n % factor == 0 {
isPrime = false
break