Debian Codegraph @

terps/tads/tads2/msdos/os0trxb.c

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header$";
4 #endif
5
6 /*
7 * Copyright (c) 2000, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 os0trxb.c - os0tr for TRX.EXE (16-bit protected-mode DOS version)
15 Function
16
17 Notes
18
19 Modified
20 03/22/00 MJRoberts - Creation
21 */
22
23 #include "os.h"
24 #include "std.h"
25 #ifdef __DPMI16__
26 #include "ltk.h"
27 #endif
28 #include "trd.h"
29
30 #include <stdlib.h>
31 #include <malloc.h>
32 #include <string.h>
33
34 static int main0(int argc, char **argv)
35 {
36 int err;
37 char *config_name;
38
39 config_name = "config.tr";
40 #ifdef __DPMI16__
41 ltkini(16384);
42 #else
43 #endif
44
45 /*
46 * Scan for -plain argument, and apply if found
47 */
48 {
49 int i;
50 for (i = 1 ; i < argc ; ++i)
51 {
52 if (!strcmp(argv[i], "-plain"))
53 os_plain();
54 }
55 }
56
57 os_init(&argc, argv, (char *)0, (char *)0, 0);
58
59 os_instbrk(1);
60 err = os0main2(argc, argv, trdmain, "", config_name, 0);
61 os_instbrk(0);
62
63 /* uninitialize the OS layer */
64 os_uninit();
65
66 return(err);
67 }
68
69 #define NEW_STACK_SIZE 65000
70
71 int main(int argc, char **argv)
72 {
73 char *stk;
74
75 /* create our own stack segment */
76 stk = (char *)malloc(NEW_STACK_SIZE);
77 if (stk == 0)
78 {
79 /*
80 * couldn't create the expanded stack - take our chances with
81 * the original one
82 */
83 return main0(argc, argv);
84 }
85 else
86 {
87 static int s_argc;
88 static char **s_argv;
89 static int s_ret;
90 unsigned int s_seg;
91 unsigned int s_ofs;
92
93 /*
94 * remember argc and argv in statics, since we're going to lose
95 * access to our stack momentarily
96 */
97 s_argc = argc;
98 s_argv = argv;
99
100 /* extract the segment and offset from our stack memoryu pointer */
101 s_seg = (unsigned int)((((unsigned long)stk) >> 16) & 0xffff);
102 s_ofs = (unsigned int)(((unsigned long)stk) & 0xffff);
103
104 /* clear the last 256 bytes of our stack */
105 memset(stk + NEW_STACK_SIZE - 256, 0, 256);
106
107 /* switch to our new stack */
108 _asm {
109 /* calculate the location of the top of our stack */
110 mov ax, s_seg
111 mov bx, s_ofs
112 add bx, NEW_STACK_SIZE - 256
113
114 /* move ss:sp to the top of our new stack */
115 mov ss, ax
116 mov sp, bx
117
118 /* set up bp as well */
119 add bp, 2
120 mov bp, bx
121 }
122
123 /* run the program */
124 s_ret = main0(s_argc, s_argv);
125
126 /*
127 * terminate without returning, since we're on this weird
128 * special stack we allocated
129 */
130 exit(s_ret);
131 }
132 }
133