Maildump (Jul 30, 2007)

(home)


Subject: Maildump

From: "Jeff" <fyberoptic1979@...>

Jul 30, 2007

I decided to dump my codeflash since I have a DET1 demo unit and
haven't s=
een anyone else dump the code from one, so I thought I'd
post both the Win=
dows C++ app I wrote to fetch it on the PC side
(based around Cyrano Jones=
' unit_tribbles) as well as my actual
codeflash dump (v3.03a). You need h=
is spew.txt Yahoo app to dump the
data to the PC, mind you.

I plan to mod=
ify the spew.txt to let me dump the dataflash too, out
of curiosity.

Anyh=
oo, here's just the C file for anyone that wants to check it out
here:

=
/*
* Maildump.cpp
* ------------
*
* This should dump your Mailstatio=
n's codeflash, in combination
* with Cyrano Jones' "spew.txt" app for the =
Mailstation, and
* a laplink cable of course.
*
* Basic use would be as=
follows:
* 1.) connect laplink cable to MS and PC
* 2.) turn on MS
* 3.=
) run maildump on PC
* 4.) run spew on MS
*
* The MS should be on first =
to ensure parallel port signals are
* reset, otherwise your dump could be =
bad. If you think you
* did get a bad dump, it wouldn't hurt to turn the=
MS off and
* on again, waiting for the main menu to show up, just to make=

* sure it resets itself before you start listening for data.
*
* The du=
mp should be 1,048,576 bytes (1MB), and named "ms.bin",
* which is automat=
ically overwritten everytime you run the
* program.
*
* This is based ar=
ound Cyrano Jones' unit_tribbles in Pascal,
* but written to work under W=
indows (tested under XP) thanks
* to inpout32.dll, which doesn't require a=
separate driver
* to interface with I/O ports. It's pretty useful!
*
=
* Spew.txt can be gotten from the Yahoo Mailstation group's file
* section=
:
* (URL)
*
*
=
* - FyberOptic (fyberoptic@...)
*
*/

#include <windows.h>
#include=
#include <math.h>

#define PORTADDRESS 0x378

#define DATA PORTA=
DDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2

#defin=
e bsyin 0x40
#define bsyout 0x08
#define stbin 0x80
#define stbout 0x10
#de=
fine tribmask 0x07
#define dibmask 0x03

typedef short (_stdcall *inpfuncPt=
r)(short portaddr);
typedef void (_stdcall *oupfuncPtr)(short portaddr, sho=
rt datum);

inpfuncPtr inp32fp;
oupfuncPtr oup32fp;

short Inp32 (short po=
rtaddr)
{
return (inp32fp)(portaddr);
}

void Out32 (short portaddr, shor=
t datum)
{
(oup32fp)(portaddr,datum);
}

int InitIOLibrary()
{
HINSTANC=
E hLib;

hLib =3D LoadLibrary("inpout32.dll");

if (hLib =3D=3D NULL) {
=
fprintf(stderr,"LoadLibrary Failed.\n");
return -1;
}

inp32fp =3D (in=
pfuncPtr) GetProcAddress(hLib, "Inp32");

if (inp32fp =3D=3D NULL) {
fpr=
intf(stderr,"GetProcAddress for Inp32 Failed.\n");
return -1;
}

oup32f=
p =3D (oupfuncPtr) GetProcAddress(hLib, "Out32");

if (oup32fp =3D=3D NULL=
) {
fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
return -1;
}=

}

unsigned char recvtribble()
{
Out32(DATA,0); // drop busy/ack
while=
((Inp32(STATUS) & stbin) !=3D 0) {} // wait for
(inverted) strobe
unsi=
gned char mytribble =3D (Inp32(STATUS) >> 3) &
tribmask; // grab tribble
=
Out32(DATA,bsyout); // raise busy/ack
while ((Inp32(STATUS) & stbin) =3D=
=3D 0) {} // wait for
(inverted) UNstrobe

return mytribble;
}

int m=
ain(int ARGC, void **ARGV)
{

if (!InitIOLibrary()) { printf("Failed to i=
nitialize port I/O
library\n"); return -1; }

FILE * pFile;

pFile =
=3D fopen ("ms.bin" , "wb");
if (!pFile)
{
printf("Couldn't open file\n=
");
return -1;
}

unsigned char bytereceived;
int totalbytesreceived =
=3D 0;

printf("Waiting...");

while (totalbytesreceived < (1024*1024)=
) // Fetch 1MB
{
bytereceived =3D recvtribble() + (recvtribble() << 3)=
+
((recvtribble() & dibmask) << 6);
fputc ( bytereceived, pFile );
=
totalbytesreceived++;
printf("\rReceived: %d bytes (%d%%) ", =

totalbytesreceived, (int)floor(((float)totalbytesreceived /
(1024*1024))*=
100));
}
fclose (pFile);

printf("\n");

return 0;

}