Skip to content

Instantly share code, notes, and snippets.

View Jacajack's full-sized avatar
🦄

Jacek Wieczorek Jacajack

🦄
View GitHub Profile
@Jacajack
Jacajack / modrq.c
Created January 31, 2018 22:35
Simple Modbus request builder with va_arg (maybe we need this in liblightmodbus?)
//TODO polish this (and tidy!)
//Send Modbus request and parses response
int modrq( uint8_t priority, uint8_t function, uint8_t addr, uint16_t reg, uint16_t cnt, ... )
{
va_list ap;
uint16_t andmask, ormask, regtype;
uint8_t waccess;
int ec = 1;
@Jacajack
Jacajack / latexmatrix.sh
Created January 21, 2018 21:41
Converts Scilab matrix to Latex
xsel --clipboard | sed 's/ //gi' | sed 's/\./ \& /gi' | sed 's/ & $/ \\\\/g' | xclip -i
@Jacajack
Jacajack / qwcfg.sh
Last active December 2, 2017 20:52
Quick wine config
#!/bin/bash
opt1="Virtual"
opt2="Manage&Decorate"
opt3="Manage"
opt4="Nothing"
mode=$(xmessage -nearmouse -print -buttons $opt1,$opt2,$opt3,$opt4 "Please select Wine graphics mode...")
#Abort if no choice has been made
if [[ -z $mode ]]; then
@Jacajack
Jacajack / serialize.sh
Created November 23, 2017 23:23
Tired of renaming subtitle files to match with videos?
#Renames all files in the current directory containing pattern S..E.. in their names
#Extensions remain unchanged but names are simplified to just S..E..
#This routine can be put in .bashrc
function serialize( ) {
rename 's/.*(S\d\dE\d\d).*\.(.*)/$1.$2/i' *.*
}
@Jacajack
Jacajack / hmul.h
Created November 2, 2017 12:38
AVR inline assembly 8bit multiplication upper half
#define HMUL( ans, b1, b2 ) \
asm volatile( \
"mul %1, %2\n\t" \
"mov %0, r1\n\t" \
: "=l"(ans) \
: "d"(b1), "d"(b2) \
);
#define HMULS( ans, b1, b2 ) \
asm volatile( \
@Jacajack
Jacajack / midi.c
Created October 31, 2017 23:49
Simple C MIDI interpreter
//Toporny, lecz skuteczny interpreter midi
void midi( uint8_t byte )
{
//Odpowiednio: numer kanału, 3 bity statusu, limit danych w bajtach, liczba odczytanych bajtów
static uint8_t channel = 0, status = 0, dlim = 0, dread = 0;
static uint8_t dbuf[16] = {0}; //Bufor na dane
if ( byte & ( 1 << 7 ) )
{
//Bajt stanu
@Jacajack
Jacajack / compvals.sce
Created October 29, 2017 22:24
Scilab script for calculating AVR synth comparator values
clear
fcpu = 20000000;
prescaler = 1;
samplesize = 16;
noterange = 1:88;
//Calculate timer frequency
ftimer = fcpu / prescaler;
@Jacajack
Jacajack / namegen.c
Created October 8, 2017 12:06
Random name generator
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
const char *vowels = "euioay";
const char *consonants = "wrtpsdfghjklzxcvbnm";
int main( int argc, char **argv )
@Jacajack
Jacajack / fload1.c
Created October 2, 2017 19:31
File queuing service (rev. 1)
#include <stdio.h>
#include <stdlib.h>
#include "fload.h"
#define MAX_FILE_COUNT 256
static FILE *files[MAX_FILE_COUNT] = {0};
static int fcount = 0;
//Queues specific file for loading
@Jacajack
Jacajack / fontthief.asm
Created July 22, 2017 01:21
Display all characters from BIOS font
[org 0x7c00]
[bits 16]
;Stack setup
mov bp, 0xfffe
mov sp, bp
;Switch into mode 13h
mov ah, 0x00
mov al, 0x13