Skip to content

Instantly share code, notes, and snippets.

@dublindan
dublindan / disable_analogs
Created April 5, 2011 00:57
reading digital input pins
.include "p24Hxxxx.inc"
.text
.global __reset
__reset:
; Turn of analog to digital converter for all pins
mov #0xffff, W0
mov W0, AD1PCFGL
; Set RA0 through RA3 as inputs (1), the rest as outputs (0) (easy way to remember: 1 looks like I for In, 0 looks like O for Out)
mov #0xf, W0
/**
* Flags to control how message handlers may be invoked.
* Message handlers can be invoked in a number of ways, depending on the threading model and thread safety of the handler.
*/
enum HandlerFlags
{
/* Threading Model Flags *******************/
USER_MASK = 0x000f, // ..000000001111
@dublindan
dublindan / gist:671226
Created November 10, 2010 18:00
Clojure Games Test Gist
(defn clojure-games
"Test Gist for http://clojure-games.org"
[]
(println "Hello from clojure-games.org"))
class TestModule : public MessageListener
{
private:
// Instance variables which are modified by message handlers must be explicityly marked as mutable, since message handlers are const functions - this makes it obvious what is accessed.
mutable int value;
mutable const Mailbox& mailbox;
StateMachineMessageFunctor stateMachine;
// Message handlers
static void testHandler (const Message* const message, const Conversation con)
typedef unsigned int MessageID;
typedef unsigned int Conversation;
class Message
{
public:
virtual ~Message () {}
virtual const MessageID& messageID () const=0;
virtual const char* senderName () const=0;
};
template <class T> void map (std::deque<T> list, void (*f) (T)) {
for (std::deque<T>::iterator iter = list.begin(); iter != list.end(); iter++) {
#ifdef PARALLEL_MAP
ThreadPool::getIdle()->run<T>(f, *iter);
#else
f(*iter);
#endif
}
}
template <class T, class A1> void map (std::deque<T> list, void (*f) (T, A1), A1 arg1) {
#include <list>
#include <iostream>
// Replace with real mutex.
class Mutex
{
public:
void lock () {}
void unlock () {}
};
@std.in;
a = [[int\]] <- 0;
op = [[char\]] <- ' ';
b = [[int\]] <- 0;
r = [[int\]] <- 0;
0 {
clock => [[int ms]] {
("\r" + ms/1000.0 + ":" + a + op + b + "=" + r) ->std.out;
fun do-op a b op {
match op
with '+: a + b
with '-: a - b
with '*: a * b
with '/: a / b
with _: error
}
flow gen a b ops -> res {
(run-components
(make-component "Comp1"
{:init (fn [v s]
(event :print nil)
(event :set-msg "Ho")
(event :print nil)
{:msg "Hi"})
:print (fn [v s]
(println (:msg s)))
:set-msg (fn [v s]