···11## mailstation-tools
2233-This is a collection of tools for working with Cidco Mailstation devices,
44-primarily the DET1.
33+This is a collection of tools for working with Cidco Mailstation devices
44+(primarily the DET1), from a Unix machine.
5566It was mostly pieced together from the now-defunct
77[mailstation Yahoo Group](https://groups.yahoo.com/neo/groups/mailstation/info)
···1212it was all posted to the public Yahoo group, I am naively assuming it is in the
1313public domain.
14141515-(Except for win32/inpout32.dll, obtained from
1515+(Except for `win32/inpout32.dll`, obtained from
1616[its website](http://www.highrez.co.uk/downloads/inpout32/) which states "This
1717product is released as open source (Freeware).")
18181919The Z80 assembly files have been updated to assemble on newer non-win32
2020assemblers.
21212222+### Compiling
2323+2424+Install [SDCC](http://sdcc.sourceforge.net/) and
2525+[hex2bin](https://sourceforge.net/projects/hex2bin/files/hex2bin/).
2626+2727+Create an `obj` directory with `mkdir obj` and then run `make`.
2828+2229### Loading code onto the Mailstation
23302431See [loader.txt](loader.txt) for a more thorough explanation.
···6976You need to type the hex values of `z80/codedump.bin` into one of the
7077application slots as detailed above.
71787272-Run `maildump.exe /code` to wait for the code dump to begin.
7979+Run `obj/recvdump -code` to wait for the code dump to begin.
73807474-Then run the new Code Dump app on the Mailstation and `maildump` should show
8181+Then run the new Code Dump app on the Mailstation and `recvdump` should show
7582its progress as it reads the transmitted data and saves it to `codeflash.bin`.
7683You may want to run it twice and compare checksums of the two resulting files.
7784···8491You need to type the hex values of `z80/datadump.bin` into one of the
8592application slots as detailed above.
86938787-Run `maildump.exe /data` to wait for the data dump to begin.
9494+Run `obj/recvdump -data` to wait for the data dump to begin.
88958989-Then run the new Data Dump app on the Mailstation and `maildump` should show
9696+Then run the new Data Dump app on the Mailstation and `recvdump` should show
9097its progress as it reads the transmitted data and saves it to `dataflash.bin`.
9198You may want to run it twice and compare checksums of the two resulting files.
9299···102109103110To extract program 0 (which lives at 0x0000) from `dataflash.bin`, run:
104111105105- app_extractor.rb -f dataflash.bin -a 0
112112+ util/app_extractor.rb -f dataflash.bin -a 0
106113107114Each of the programs can be extracted with different `-a` values.
108115
app_extractor.rb
util/app_extractor.rb
+131
util/recvdump.c
···11+/*
22+ * recvdump
33+ * based on win32/maildump.cpp by FyberOptic
44+ *
55+ * usage: recvdump [-data | -code]
66+ *
77+ * must be run as root to set iopl and use inb/outb
88+ *
99+ * assumes parallel port is at PORTADDRESS and codedump or datadump has been
1010+ * loaded on the MailStation and is running
1111+ */
1212+1313+#include <stdio.h>
1414+#include <string.h>
1515+#include <err.h>
1616+#include <unistd.h>
1717+#include <sys/types.h>
1818+#include <machine/sysarch.h>
1919+#include <machine/pio.h>
2020+2121+#define PORTADDRESS 0x378
2222+2323+#define DATA PORTADDRESS+0
2424+#define STATUS PORTADDRESS+1
2525+#define CONTROL PORTADDRESS+2
2626+2727+#define bsyin 0x40
2828+#define bsyout 0x08
2929+#define stbin 0x80
3030+#define stbout 0x10
3131+#define tribmask 0x07
3232+#define dibmask 0x03
3333+3434+unsigned char
3535+recvtribble(void)
3636+{
3737+ unsigned char mytribble;
3838+3939+ /* drop busy/ack */
4040+ outb(DATA, 0);
4141+4242+ /* wait for (inverted) strobe */
4343+ while ((inb(STATUS) & stbin) != 0)
4444+ ;
4545+4646+ /* grab tribble */
4747+ mytribble = (inb(STATUS) >> 3) & tribmask;
4848+4949+ /* raise busy/ack */
5050+ outb(DATA,bsyout);
5151+5252+ /* wait for (inverted) UNstrobe */
5353+ while ((inb(STATUS) & stbin) == 0)
5454+ ;
5555+5656+ return mytribble;
5757+}
5858+5959+int
6060+main(int argc, char *argv[])
6161+{
6262+ FILE *pFile;
6363+ unsigned int received = 0, expected = 0;
6464+ unsigned char t1, t2, t3, b;
6565+ char fn[14];
6666+ int codeflash = 0, dataflash = 0;
6767+ int x;
6868+6969+ for (x = 1; x < argc; x++) {
7070+ if (strncmp((char *)argv[x], "-code", 5) == 0)
7171+ codeflash = 1;
7272+ else if (strncmp((char *)argv[x], "-data", 5) == 0)
7373+ dataflash = 1;
7474+ else
7575+ printf("unknown parameter: %s\n", argv[x]);
7676+ }
7777+7878+ if (codeflash == dataflash) {
7979+ printf("usage: %s [-code | -data]\n", argv[0]);
8080+ return 1;
8181+ }
8282+8383+ if (codeflash) {
8484+ expected = 1024 * 1024;
8585+ strlcpy(fn, "codeflash.bin", sizeof(fn));
8686+ } else if (dataflash) {
8787+ expected = 1024 * 512;
8888+ strlcpy(fn, "dataflash.bin", sizeof(fn));
8989+ }
9090+9191+ if (geteuid() != 0)
9292+ errx(1, "must be run as root");
9393+9494+#ifdef __OpenBSD__
9595+ if (amd64_iopl(1) != 0)
9696+ errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)");
9797+#endif
9898+9999+ pFile = fopen(fn, "wb");
100100+ if (!pFile) {
101101+ printf("couldn't open file %s\n", fn);
102102+ return -1;
103103+ }
104104+105105+ printf("dumping to %s, run Code Dump on MailStation now...", fn);
106106+ fflush(stdout);
107107+108108+ while (received < expected) {
109109+ t1 = recvtribble();
110110+ t2 = recvtribble();
111111+ t3 = recvtribble();
112112+113113+ b = t1 + (t2 << 3) + ((t3 & dibmask) << 6);
114114+115115+ if (received == 0)
116116+ printf("\n");
117117+118118+ fputc(b, pFile);
119119+ received++;
120120+121121+ if (received % 1024 == 0 || received == expected) {
122122+ printf("\rreceived: %07d/%07d", received, expected);
123123+ fflush(stdout);
124124+ }
125125+ }
126126+ fclose(pFile);
127127+128128+ printf("\n");
129129+130130+ return 0;
131131+}