Skip to content

Commit 8f5dc68

Browse files
committed
Add DOS utility.
1 parent 09accb4 commit 8f5dc68

File tree

6 files changed

+290
-0
lines changed

6 files changed

+290
-0
lines changed

dos/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## NeoPixel Tree DOS Application
2+
3+
### Build environment
4+
5+
- Install Open Watcom v2
6+
- Download mTCP source
7+
- Compile on a DOS machine (real or emulated) or cross-compile from a Windows machine (modern Windows works fine)
8+
9+
Example development flow:
10+
1. Compile on modern Windows with `wmake`
11+
2. Copy `xmastree.exe` to a shared HTTP server from the modern machine (see `sync.cmd` for a scripted example)
12+
3. Download `xmastree.exe` to the DOS machine (see `download.bat` for a scripted example)
13+
4. Execute binary
14+
15+
### Building
16+
17+
Due to the current MAKEFILE configuration it's easiest to put `TREE` under the `APPS` directory of the mTCP source.
18+
19+
- Run `wmake`
20+
21+
### Running
22+
23+
The binary must be executed in a DOS environment with a Packet Driver enabled. mTCP must be configured on the machine first, which includes:
24+
25+
- Initializing the packet driver (which will need to be downloaded for the attached NIC)
26+
- Calling DHCP or setting up a static IP
27+
- Confirming the tree can be reached and DNS lookups succeed
28+
29+
- Run `xmastree`
30+
31+
### Notes
32+
33+
- 86Box running in SLiRP mode worked fine for the DOS environment.

dos/TREE/MAKEFILE

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tcp_h_dir = ..\..\TCPINC\
2+
tcp_c_dir = ..\..\TCPLIB\
3+
common_h_dir = ..\..\INCLUDE
4+
5+
memory_model = -ms
6+
compile_options = -0 $(memory_model) -DCFG_H="XMASTREE.CFG" -oh -ok -os -s -oa -zp2 -zpw -we
7+
compile_options += -i=$(tcp_h_dir) -i=$(common_h_dir)
8+
9+
10+
tcpobjs = packet.obj arp.obj eth.obj ip.obj utils.obj timer.obj ipasm.obj dns.obj udp.obj trace.obj
11+
objs = xmastree.obj
12+
13+
all : clean xmastree.exe
14+
15+
clean : .symbolic
16+
@del xmastree.exe
17+
@del *.obj
18+
@del *.map
19+
20+
patch : .symbolic
21+
..\..\utils\ptach xmastree.exe xmastree.map $(memory_model)
22+
23+
.asm : $(tcp_c_dir)
24+
25+
.cpp : $(tcp_c_dir)
26+
27+
.asm.obj :
28+
wasm -0 $(memory_model) $[*
29+
30+
.cpp.obj :
31+
wpp $[* $(compile_options)
32+
33+
34+
xmastree.exe: $(tcpobjs) $(objs)
35+
wlink system dos option map option eliminate option stack=4096 name $@ file *.obj

dos/TREE/XMASTREE.CFG

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#ifndef CONFIG_H
3+
#define CONFIG_H
4+
5+
6+
// Generic configuration instructions
7+
//
8+
// Each mTCP application requires a configuration file like this to set
9+
// compile-time options for the TCP/IP library. A #define is used to
10+
// determine whether each major feature is available or not. Other #defines
11+
// are used to determine sub-features within the features.
12+
//
13+
// Notes:
14+
// - This file should stand alone; it should not require other header files
15+
// - All times are in milliseconds
16+
// - Obey any maximums in the comments; there is some static compile
17+
// time checking but it might not cover all cases
18+
19+
20+
#define MTCP_PROGRAM_NAME "xmastree"
21+
22+
23+
#include "Global.Cfg"
24+
#define COMPILE_ARP
25+
#define IP_FRAGMENTS_ON
26+
#define COMPILE_UDP
27+
#define COMPILE_DNS
28+
29+
30+
#endif

dos/TREE/XMASTREE.CPP

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#include <dos.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <time.h>
5+
6+
#include "trace.h"
7+
#include "utils.h"
8+
#include "packet.h"
9+
#include "arp.h"
10+
#include "udp.h"
11+
#include "dns.h"
12+
13+
14+
static void parseArgs( int argc, char *argv[] );
15+
static void shutdown( int rc );
16+
17+
18+
static char ServerAddrName[] = "tree.tannerstokes.com";
19+
uint16_t treePort = 8733;
20+
21+
uint8_t command_length = 0;
22+
uint8_t command_data[255];
23+
24+
// Check this flag once in a while to see if the user wants out.
25+
volatile uint8_t CtrlBreakDetected = 0;
26+
27+
void __interrupt __far ctrlBreakHandler( ) {
28+
CtrlBreakDetected = 1;
29+
}
30+
31+
void __interrupt __far ctrlCHandler( ) {
32+
// Do Nothing - Ctrl-C is a legal character
33+
}
34+
35+
36+
int main( int argc, char *argv[] ) {
37+
38+
parseArgs( argc, argv );
39+
40+
if ( Utils::parseEnv( ) != 0 ) {
41+
exit(-1);
42+
}
43+
44+
if ( Utils::initStack( 0, 0, ctrlBreakHandler, ctrlCHandler ) ) {
45+
fprintf( stderr, "\nFailed to initialize TCP/IP - exiting\n" );
46+
exit(-1);
47+
}
48+
49+
IpAddr_t ipAddr;
50+
int8_t rc = Dns::resolve( ServerAddrName, ipAddr, 1 );
51+
52+
while ( 1 ) {
53+
if ( CtrlBreakDetected ) {
54+
break;
55+
}
56+
57+
if ( biosIsKeyReady( ) ) {
58+
char c = biosKeyRead( );
59+
if ( (c == 27) || (c == 3) ) {
60+
break;
61+
}
62+
}
63+
64+
PACKET_PROCESS_SINGLE;
65+
Arp::driveArp( );
66+
Dns::drivePendingQuery( );
67+
68+
if ( !Dns::isQueryPending( ) ) {
69+
break;
70+
}
71+
}
72+
73+
rc = Dns::resolve( ServerAddrName, ipAddr, 0 );
74+
if ( rc != 0 ) {
75+
printf( "Failed to resolve DNS.\n");
76+
shutdown ( -1 );
77+
return 0;
78+
}
79+
80+
if ( command_length == 0 ) {
81+
printf( "Command length not set!\n" );
82+
shutdown ( -1 );
83+
return 0;
84+
}
85+
86+
while( 1 ) {
87+
if ( CtrlBreakDetected ) {
88+
break;
89+
}
90+
91+
if ( biosIsKeyReady( ) ) {
92+
char c = biosKeyRead( );
93+
if ( (c == 27) || (c == 3) ) {
94+
break;
95+
}
96+
}
97+
98+
PACKET_PROCESS_SINGLE;
99+
Arp::driveArp( );
100+
rc = Udp::sendUdp( ipAddr, treePort, treePort, command_length, command_data, 0 );
101+
if ( rc < 1 ) {
102+
break;
103+
}
104+
}
105+
106+
if ( rc == 0 ) {
107+
printf( "Command sent to tree!\n" );
108+
} else {
109+
printf( "There was a problem sending the packet. Return code: %d\n", rc );
110+
}
111+
112+
shutdown( 0 );
113+
}
114+
115+
116+
static void shutdown( int rc ) {
117+
Utils::endStack( );
118+
Utils::dumpStats( stderr );
119+
exit( rc );
120+
}
121+
122+
char *HelpText[] = {
123+
"\nxmastree <command> [options]\n\n",
124+
"Available commands:\n",
125+
" brightness [0-255] Set the tree's brightness\n",
126+
" fill [0-255][0-255][0-255] Fill all LEDs with a single RGB color\n",
127+
" rainbow [0-1] Show a rainbow sequence that can repeat\n",
128+
" off Turn the tree off\n",
129+
" help Show this help\n",
130+
NULL
131+
};
132+
133+
134+
void usage( void ) {
135+
uint8_t i=0;
136+
while ( HelpText[i] != NULL ) {
137+
fprintf( stderr, HelpText[i] );
138+
i++;
139+
}
140+
exit( 1 );
141+
}
142+
143+
void parseArgs( int argc, char *argv[] ) {
144+
if ( argc < 2 ) {
145+
usage ( );
146+
}
147+
148+
if ( stricmp( argv[1], "help" ) == 0 ) {
149+
usage( );
150+
}
151+
else if ( stricmp( argv[1], "brightness" ) == 0 ) {
152+
if ( argc != 3 ) {
153+
usage ( );
154+
}
155+
command_length = 2;
156+
command_data[0] = 1;
157+
command_data[1] = atoi( argv[2] );
158+
}
159+
else if ( stricmp( argv[1], "fill" ) == 0 ) {
160+
if ( argc != 5 ) {
161+
usage ( );
162+
}
163+
command_length = 4;
164+
command_data[0] = 3;
165+
command_data[1] = atoi( argv[2] );
166+
command_data[2] = atoi( argv[3] );
167+
command_data[3] = atoi( argv[4] );
168+
}
169+
else if ( stricmp( argv[1], "rainbow" ) == 0 ) {
170+
if ( argc != 3 ) {
171+
usage ( );
172+
}
173+
command_length = 2;
174+
command_data[0] = 5;
175+
command_data[1] = atoi( argv[2] );
176+
}
177+
else if ( stricmp( argv[1], "off" ) == 0 ) {
178+
if ( argc != 2 ) {
179+
usage ( );
180+
}
181+
command_length = 1;
182+
command_data[0] = 0;
183+
}
184+
else {
185+
fprintf( stderr, "Unknown option %s\n", argv[1] );
186+
usage( );
187+
}
188+
189+
}

dos/download.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:: Helper used to quickly download the latest binary into DOS
2+
htget -o xmastree.exe http://retro.tannerstokes.com/dev/xmastree.exe

dos/sync.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
copy TREE\xmastree.exe \\retro\storage\retro\dev

0 commit comments

Comments
 (0)