Skip to content

Commit 4b8f562

Browse files
committed
Added INT21 version of system to 16-bit DOS.
1 parent 5c1b99f commit 4b8f562

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

lua.pat

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,66 @@
3232
#define MAXARG_sJ ((1 << SIZE_sJ) - 1)
3333
#else
3434
#define MAXARG_sJ INT_MAX
35+
--- lua/loslib.c
36+
+++ lua/loslib.c
37+
@@ -134,6 +134,57 @@
38+
#if defined(LUA_USE_IOS)
39+
/* Despite claiming to be ISO C, iOS does not implement 'system'. */
40+
#define l_system(cmd) ((cmd) == NULL ? 0 : -1)
41+
+
42+
+/* DOS interrupt version of 'system' to avoid clib bloat */
43+
+#elif defined(_M_I86) && defined(_DOS)
44+
+
45+
+#include <dos.h>
46+
+
47+
+typedef struct ExecParamRec {
48+
+ unsigned short int envseg; /* Segment address of environment block */
49+
+ char far *cmdline; /* Pointer to command line string (ES:BX) */
50+
+ unsigned short int fcb1; /* Reserved */
51+
+ unsigned short int fcb2;
52+
+} ExecParamRec;
53+
+
54+
+static int l_system(const char *str) {
55+
+ size_t l;
56+
+ char *p, command[128];
57+
+ union REGS regs;
58+
+ struct SREGS sregs;
59+
+ ExecParamRec exec;
60+
+
61+
+ if (!str || (l = 4 + strlen(str)) > 127) /* Maximum cmdline under DOS */
62+
+ return -1;
63+
+
64+
+ if (!(p = getenv("COMSPEC")))
65+
+ p = "COMMAND.COM";
66+
+
67+
+/* Copy Lua string onto command.com */
68+
+ command[0] = (unsigned char) l;
69+
+ memcpy(&command[1], " /C ", 4);
70+
+ memcpy(&command[5], str, strlen(str));
71+
+ command[l + 1] = '\r';
72+
+
73+
+/* Clear registers and structures */
74+
+ memset(&exec, 0, sizeof(ExecParamRec)), memset(&regs, 0, sizeof(union REGS)), memset(&sregs, 0, sizeof(struct SREGS));
75+
+ exec.cmdline = command;
76+
+
77+
+ regs.x.ax = 0x4b00; /* Exec + load */
78+
+ regs.x.dx = FP_OFF(p); /* Offset of the command path string (DS:DX) */
79+
+ sregs.ds = FP_SEG(p); /* Segment of the command path string (DS:DX) */
80+
+ regs.x.bx = FP_OFF(&exec); /* Offset of the ExecParamRec structure (ES:BX) */
81+
+ sregs.es = FP_SEG(&exec); /* Segment of the ExecParamRec structure (ES:BX) */
82+
+ intdosx(&regs, &regs, &sregs); /* 0x21 Send it! */
83+
+
84+
+ if (regs.x.cflag)
85+
+ return -1;
86+
+
87+
+ regs.x.ax = 0x4D00;
88+
+ intdos(&regs, &regs);
89+
+ return regs.x.ax & 0xFF;
90+
+}
91+
+
92+
#else
93+
#define l_system(cmd) system(cmd) /* default definition */
94+
#endif
3595
--- lua/luaconf.h
3696
+++ lua/luaconf.h
3797
@@ -95,7 +95,12 @@

0 commit comments

Comments
 (0)