[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple I/O for MzScheme using the printer port



Something lacking from most implementations of Scheme is any way of
controlling
hardware, so I thought I'd have a go at writing a simple extension that
offered
this facility via the printer port, having got the 'Hello World' extension
to work. Here's my initial test program, it simply pulses the output data
pins and then returns. Sorry about the tabs,  I converted them to spaces in
my text editor, but they seem to have disappeared again.

--------------------------------------------- cut here
/*
** test.c
** simple I/O for MzScheme under Win98 using the printer port
** builds OK with MSVC++ 6.0
*/

#include "escheme.h"
#include <conio.h>

#define PORT 0x3BC

Scheme_Object *scheme_initialize(Scheme_Env *env)
{
 return scheme_reload(env);
}


Scheme_Object *sch_pulse(int argc, Scheme_Object **argv)
{

 int i;

 for (i = 0; i < 1000; i++)
 {
  _outp(PORT, 0xFF);
  dly();
  _outp(PORT, 0x00);
  dly();

 }
 return scheme_true;
}


Scheme_Object *scheme_reload(Scheme_Env *env)
{
 Scheme_Object *proc;

 proc = scheme_make_prim_w_arity(sch_pulse, "pulse", 0, 0);
 scheme_add_global("pulse", proc, env);

 return scheme_true;
}

dly()
{
 unsigned long i, j;

 for (i = 0; i < 100; i++)
  for (j = 0; j < 100; j++)
   ;
}

----------------------------------------------cut here

Leon
--
Leon Heller, G1HSM leon_heller@hotmail.con
http://www.geocities.com/leon_heller
Low-cost Altera Flex design kit: http://www.leonheller.com