├── 32
├── Makefile
├── asm_inc.h
├── findclos.c
├── findclos.h
├── fmemcpy.c
├── fmemcpy.h
├── memmem.c
└── memmem.h
├── .github
└── workflows
│ └── ci-build.yml
├── .travis.yml
├── LICENSE
├── README.md
├── ci_build.sh
├── ci_prereq.sh
├── ci_test.sh
├── ci_test_prereq.sh
├── comcom64.spec.rpkg
├── debian
├── changelog
├── compat
├── control
├── copyright
├── rules
└── source
│ └── format
├── makefile
├── meson.build
└── src
├── Makefile
├── ae0x.c
├── ae0x.h
├── asm.S
├── asm.h
├── asm.inc
├── clip.c
├── clip.h
├── cmdbuf.c
├── cmdbuf.h
├── command.c
├── command.h
├── compl.c
├── compl.h
├── env.c
├── env.h
├── glob_asm.h
├── int0.S
├── int23.S
├── link.sh
├── meson.build
├── mouse.c
├── mouse.h
├── ms.S
├── psp.c
├── psp.h
├── thunks_a.c
├── thunks_c.c
├── toolchain.ini
├── umb.c
└── umb.h
/.github/workflows/ci-build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 | on:
3 | pull_request:
4 | types:
5 | - opened
6 | - edited
7 | - ready_for_review
8 | - reopened
9 | - synchronize
10 | push:
11 |
12 | jobs:
13 | build:
14 | if: contains(github.event.head_commit.message, '[skip ci]') == false
15 |
16 | runs-on: ubuntu-22.04
17 |
18 | steps:
19 | - uses: actions/checkout@v4
20 |
21 | - name: package install
22 | run: ./ci_prereq.sh
23 |
24 | - name: build
25 | run: ./ci_build.sh
26 |
27 | - name: test prerequisites
28 | run: ./ci_test_prereq.sh
29 |
30 | - name: test
31 | run: ./ci_test.sh
32 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 |
3 | dist: focal
4 |
5 | if: type = cron
6 |
7 | git:
8 | depth: false
9 |
10 | #env: DOSEMU_QUIET=1
11 |
12 | before_install:
13 | - ./ci_prereq.sh
14 |
15 | install:
16 | - ./ci_build.sh
17 |
18 | before_script:
19 | - echo "before_script"
20 |
21 | script:
22 | - ./ci_test.sh
23 |
--------------------------------------------------------------------------------
/32/Makefile:
--------------------------------------------------------------------------------
1 | TOP = ..
2 | SRCDIR = $(TOP)/src
3 | DOS_CC ?= i586-pc-msdosdjgpp-gcc
4 | DOS_LD ?= i586-pc-msdosdjgpp-gcc
5 | DOS_AS ?= i586-pc-msdosdjgpp-as
6 | DOS_STRIP ?= i586-pc-msdosdjgpp-strip
7 | prefix ?= /usr/local
8 | DATADIR ?= $(prefix)/share/comcom32
9 | C_OPT = -Wall -O2 -Wmissing-declarations -Wwrite-strings -I $(SRCDIR) -I .
10 | # avoid CMOVxx instructions
11 | C_OPT += -march=i386
12 | LINK_OPT =
13 | SRCS = $(SRCDIR)/command.c $(SRCDIR)/cmdbuf.c $(SRCDIR)/ms.c \
14 | $(SRCDIR)/env.c $(SRCDIR)/psp.c $(SRCDIR)/umb.c $(SRCDIR)/ae0x.c \
15 | $(SRCDIR)/compl.c $(SRCDIR)/clip.c memmem.c fmemcpy.c findclos.c
16 | ASSRCS = $(SRCDIR)/asm.S $(SRCDIR)/int23.S $(SRCDIR)/int0.S $(SRCDIR)/mouse.S
17 | OBJS = $(notdir $(SRCS:.c=.o)) $(notdir $(ASSRCS:.S=.o))
18 | CMD = comcom32.exe
19 | REVISIONID := $(shell git describe --dirty=+)
20 | ifeq ($(REVISIONID),)
21 | REVISIONID := Non-git_build
22 | endif
23 | C_OPT += -DREV_ID=\"$(REVISIONID)\"
24 |
25 | .PHONY: all clean install uninstall
26 |
27 | ifneq ($(shell $(DOS_CC) --version 2>/dev/null),)
28 | all: $(CMD)
29 | else
30 | all:
31 | endif
32 |
33 | clean:
34 | $(RM) $(CMD) *.o version
35 |
36 | $(OBJS): $(wildcard $(SRCDIR)/*.h) $(SRCDIR)/asm.inc
37 | $(CMD): $(OBJS)
38 | $(DOS_LD) $^ $(LINK_OPT) -o $(CMD)
39 | $(DOS_STRIP) $(CMD)
40 | chmod -x $(CMD)
41 |
42 | # Common rules
43 | %.o : $(SRCDIR)/%.c
44 | $(DOS_CC) $(C_OPT) -c $< -o $@
45 |
46 | %.o : %.c
47 | $(DOS_CC) $(C_OPT) -c $< -o $@
48 |
49 | %.o : $(SRCDIR)/%.S
50 | $(DOS_CC) $(C_OPT) -c $< -o $@
51 |
52 | ifeq (,$(wildcard $(CMD)))
53 | install:
54 | @echo "Build it first or run \"make fetch\"" && false
55 | else
56 | install:
57 | endif
58 | mkdir -p $(DESTDIR)$(DATADIR)
59 | install -m 0644 $(CMD) $(DESTDIR)$(DATADIR)
60 | ln -sf $(CMD) $(DESTDIR)$(DATADIR)/command.com
61 |
62 | uninstall:
63 | rm -rf $(DATADIR)
64 |
--------------------------------------------------------------------------------
/32/asm_inc.h:
--------------------------------------------------------------------------------
1 | #define __ASM(x, y) extern x y
2 | #define __ASM_FUNC(x) void x(void)
3 | #define SEMIC ;
4 | #include "glob_asm.h"
5 | #undef __ASM
6 | #undef __ASM_FUNC
7 | #undef SEMIC
8 |
--------------------------------------------------------------------------------
/32/findclos.c:
--------------------------------------------------------------------------------
1 | /*
2 | * dj64 - 64bit djgpp-compatible tool-chain
3 | * Copyright (C) 2021-2024 @stsp
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include "findclos.h"
24 |
25 | int
26 | findclose(int handle)
27 | {
28 | __dpmi_regs r;
29 | int use_lfn = _USE_LFN;
30 |
31 | if (use_lfn)
32 | {
33 | r.x.flags |= 1; /* Always set CF before calling a 0x71NN function. */
34 | r.x.bx = handle;
35 | r.x.ax = 0x71a1;
36 | __dpmi_int(0x21, &r);
37 | if (!(r.x.flags & 1))
38 | return 0;
39 | errno = __doserr_to_errno(r.x.ax);
40 | return errno;
41 | }
42 | return 0;
43 | }
44 |
45 | int __attribute__((alias("findclose")))
46 | __findclose(int handle);
47 |
--------------------------------------------------------------------------------
/32/findclos.h:
--------------------------------------------------------------------------------
1 | #ifndef FINDCLOS_H
2 | #define FINDCLOS_H
3 |
4 | #define HAVE_FINDCLOSE 1
5 | int findclose(int handle);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/32/fmemcpy.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 stsp
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include "fmemcpy.h"
22 |
23 | static inline int get_segment_base_address(int selector, unsigned *addr)
24 | {
25 | #ifdef __LP64__
26 | return __dpmi_get_segment_base_address(selector, addr);
27 | #else
28 | return __dpmi_get_segment_base_address(selector, (unsigned long *)addr);
29 | #endif
30 | }
31 |
32 | void fmemcpy1(__dpmi_paddr dst, const void *src, unsigned len)
33 | {
34 | int rc;
35 | unsigned base;
36 | void *ptr;
37 |
38 | rc = get_segment_base_address(dst.selector, &base);
39 | assert(!rc);
40 | rc = __djgpp_nearptr_enable();
41 | assert(rc);
42 | ptr = (void *)(base + dst.offset32 + __djgpp_conventional_base);
43 | memcpy(ptr, src, len);
44 | __djgpp_nearptr_disable();
45 | }
46 |
47 | void fmemcpy2(void *dst, __dpmi_paddr src, unsigned len)
48 | {
49 | int rc;
50 | unsigned base;
51 | const void *ptr;
52 |
53 | rc = get_segment_base_address(src.selector, &base);
54 | assert(!rc);
55 | rc = __djgpp_nearptr_enable();
56 | assert(rc);
57 | ptr = (const void *)(base + src.offset32 + __djgpp_conventional_base);
58 | memcpy(dst, ptr, len);
59 | __djgpp_nearptr_disable();
60 | }
61 |
62 | /* similar to sys/movedata.h's movedata(), but the src/dst swapped! */
63 | void fmemcpy12(__dpmi_paddr dst, __dpmi_paddr src, unsigned len)
64 | {
65 | int rc;
66 | unsigned sbase, dbase;
67 | const void *sptr;
68 | void *dptr;
69 |
70 | rc = get_segment_base_address(src.selector, &sbase);
71 | assert(!rc);
72 | rc = get_segment_base_address(dst.selector, &dbase);
73 | assert(!rc);
74 | rc = __djgpp_nearptr_enable();
75 | assert(rc);
76 | sptr = (const void *)(sbase + src.offset32 + __djgpp_conventional_base);
77 | dptr = (void *)(dbase + dst.offset32 + __djgpp_conventional_base);
78 | memcpy(dptr, sptr, len);
79 | __djgpp_nearptr_disable();
80 | }
81 |
--------------------------------------------------------------------------------
/32/fmemcpy.h:
--------------------------------------------------------------------------------
1 | #ifndef FMEMCPY_H
2 | #define FMEMCPY_H
3 |
4 | #include
5 |
6 | void fmemcpy1(__dpmi_paddr dst, const void *src, unsigned len);
7 | void fmemcpy2(void *dst, __dpmi_paddr src, unsigned len);
8 | void fmemcpy12(__dpmi_paddr dst, __dpmi_paddr src, unsigned len);
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/32/memmem.c:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright (c) 2005 Pascal Gloor
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions
6 | * are met:
7 | * 1. Redistributions of source code must retain the above copyright
8 | * notice, this list of conditions and the following disclaimer.
9 | * 2. Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * 3. The name of the author may not be used to endorse or promote
13 | * products derived from this software without specific prior written
14 | * permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 | * SUCH DAMAGE.
27 | */
28 |
29 | #include
30 | //__FBSDID("$FreeBSD: src/lib/libc/string/memmem.c,v 1.2 2009/02/03 17:58:20 danger Exp $");
31 |
32 | #include
33 | #include "memmem.h"
34 |
35 | /*
36 | * Find the first occurrence of the byte string s in byte string l.
37 | */
38 |
39 | void *
40 | memmem(const void *l, size_t l_len, const void *s, size_t s_len)
41 | {
42 | register char *cur, *last;
43 | const char *cl = (const char *)l;
44 | const char *cs = (const char *)s;
45 |
46 | /* we need something to compare */
47 | if (l_len == 0 || s_len == 0)
48 | return NULL;
49 |
50 | /* "s" must be smaller or equal to "l" */
51 | if (l_len < s_len)
52 | return NULL;
53 |
54 | /* special case where s_len == 1 */
55 | if (s_len == 1)
56 | return memchr(l, (int)*cs, l_len);
57 |
58 | /* the last position where its possible to find "s" in "l" */
59 | last = (char *)cl + l_len - s_len;
60 |
61 | for (cur = (char *)cl; cur <= last; cur++)
62 | if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
63 | return cur;
64 |
65 | return NULL;
66 | }
67 |
--------------------------------------------------------------------------------
/32/memmem.h:
--------------------------------------------------------------------------------
1 | #ifndef MEMMEM_H
2 | #define MEMMEM_H
3 |
4 | void *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # comcom64
2 |
3 | comcom64 is a command.com-alike 64bit shell for DOS.
4 | This repository also contains the build recipe for 32bit version.
5 |
6 | ## building
7 |
8 | Install the needed build tools.
9 | You can see the list of them
10 | [for ubuntu](https://github.com/dosemu2/comcom64/blob/master/debian/control#L7-L14)
11 | or
12 | [for fedora](https://github.com/dosemu2/comcom64/blob/master/comcom64.spec.rpkg#L17-L24)
13 |
14 | Then just run `make`.
15 |
16 | To build the 32bit version, install
17 | [djgpp](https://www.delorie.com/djgpp/)
18 | and run `make 32`.
19 |
20 | ## installing
21 |
22 | Running `sudo make install` installs the 64bit version
23 | for the use with [dosemu2](https://github.com/dosemu2/dosemu2).
24 |
25 | ## running
26 |
27 | Just run `dosemu` and it should boot the installed comcom64.
28 |
29 | ## mouse control
30 |
31 | You can navigate the command history with mouse wheel.
32 |
33 | All buttons have 2 functions: one activates when you click on a text
34 | area outside of a cursor row, and another activates when you click
35 | inside the cursor row.
36 |
37 | Left button:
38 | - if Ctrl pressed: type clicked char; otherwise do nothing
39 | - moves the cursor to the clicked location
40 |
41 | Middle button:
42 | - Enter
43 | - BackSpace
44 |
45 | Right button:
46 | - Tab completion
47 | - truncate or clear line
48 |
49 | There is a `mouseopt` command that controls mouse behavior.
50 | It has the following switches:
51 |
52 | - /M - initialize mouse (if /M was not passed to comcom on start)
53 | - /E[1|0] - enable/disable mouse
54 | - /C[0|1] - enable/disable external control
55 |
56 | External control allows to control other programs with mouse.
57 | For example you can execute `mouseopt /c`, then run freecom and
58 | control it with mouse similar to comcom64, even though freecom
59 | is mouse-unaware by itself.
60 |
--------------------------------------------------------------------------------
/ci_build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | make deb
6 |
7 | make 32 -j 9
8 |
--------------------------------------------------------------------------------
/ci_prereq.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | sudo add-apt-repository ppa:jwt27/djgpp-toolchain
4 | sudo apt-get update
5 | sudo apt install -y \
6 | devscripts \
7 | equivs \
8 | gcc-djgpp
9 |
10 | sudo add-apt-repository ppa:stsp-0/thunk-gen
11 | sudo add-apt-repository ppa:stsp-0/dj64
12 | mk-build-deps --install --root-cmd sudo
13 |
--------------------------------------------------------------------------------
/ci_test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -e
4 |
5 | if ! dosemu -td -o boot.log -E ver ; then
6 | {
7 | echo "================== boot.log ==================="
8 | cat boot.log
9 | echo "==============================================="
10 | } >&2
11 | exit 1
12 | fi
13 |
14 | # make sure 32bit version also built
15 | ls -l 32/comcom32.exe
16 |
--------------------------------------------------------------------------------
/ci_test_prereq.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | sudo add-apt-repository ppa:dosemu2/ppa
4 |
5 | sudo apt update -q
6 |
7 | sudo apt install -y dosemu2
8 |
9 | sudo dpkg -i ../comcom64*.deb
10 |
--------------------------------------------------------------------------------
/comcom64.spec.rpkg:
--------------------------------------------------------------------------------
1 | #
2 | # spec file for package comcom64
3 | #
4 |
5 | Name: {{{ git_dir_name }}}
6 | Version: {{{ git_dir_version }}}
7 | Release: 1%{?dist}
8 | Summary: 64-bit command.com
9 |
10 | Group: System/Emulator
11 |
12 | License: GPLv3+
13 | URL: https://github.com/stsp/comcom64
14 | VCS: {{{ git_dir_vcs }}}
15 | Source0: {{{ git_dir_archive }}}
16 |
17 | BuildRequires: make
18 | BuildRequires: pkgconf-pkg-config
19 | BuildRequires: dj64dev-dj64-devel
20 | BuildRequires: git
21 | BuildRequires: grep
22 |
23 | Requires: dj64dev-dj64
24 |
25 | %description
26 | comcom64 is a 64-bit command.com.
27 |
28 | %prep
29 | {{{ git_dir_setup_macro }}}
30 |
31 | %build
32 | make %{?_smp_mflags}
33 |
34 | %check
35 |
36 | %define __arch_install_post export NO_BRP_STRIP_DEBUG=true
37 | %define debug_package %{nil}
38 | %define __strip /bin/true
39 |
40 | %install
41 | make install DESTDIR=%{buildroot} prefix=%{_prefix}
42 |
43 | %files
44 | %defattr(-,root,root)
45 | %{_datadir}/comcom64
46 |
47 | %changelog
48 | {{{ git_dir_changelog }}}
49 |
--------------------------------------------------------------------------------
/debian/changelog:
--------------------------------------------------------------------------------
1 | comcom64 (0.2-1) noble; urgency=low
2 |
3 | * 0.2
4 |
5 | -- Stas Sergeev Tue, 31 Dec 2024 14:50:00 +0300
6 |
7 | comcom64 (0.1-1) mantic; urgency=low
8 |
9 | * 0.1
10 | First working release.
11 | Dedicated to Alexey Navalny, RIP!
12 |
13 | -- Stas Sergeev Sat, 17 Feb 2024 23:40:00 +0500
14 |
--------------------------------------------------------------------------------
/debian/compat:
--------------------------------------------------------------------------------
1 | 10
2 |
--------------------------------------------------------------------------------
/debian/control:
--------------------------------------------------------------------------------
1 | Source: comcom64
2 | Section: contrib/otherosfs
3 | Priority: optional
4 | Maintainer: Stas Sergeev
5 | Standards-Version: 3.9.7
6 | Build-Depends:
7 | make,
8 | pkgconf,
9 | dj64-dev,
10 | git,
11 | grep,
12 | debhelper (>= 9~)
13 | Homepage: https://github.com/dosemu2/comcom64
14 |
15 | Package: comcom64
16 | Architecture: any
17 | # Note: ${shlibs:Depends} doesn't work as there are no elf binaries in package
18 | Depends: ${misc:Depends}, dj64
19 | Description: 64-bit command.com
20 | comcom64 is a 64-bit command.com.
21 |
--------------------------------------------------------------------------------
/debian/copyright:
--------------------------------------------------------------------------------
1 | Allen S. Cheung (allencheung@fastmail.ca)
2 | COPYRIGHT (C) 1997 CENTROID CORPORATION, HOWARD, PA 16841
3 | modified for FreeDOS-32 by Salvo Isaja and Hanzac Chen
4 | Copyright (C) 2018 Stas Sergeev (stsp)
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 |
19 | On Debian systems, the complete text of the GNU General Public License version
20 | 3 can be found in `/usr/share/common-licenses/GPL-3'.
21 |
--------------------------------------------------------------------------------
/debian/rules:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 |
3 | %:
4 | dh $@
5 |
6 | override_dh_auto_install:
7 | dh_auto_install $@ -- prefix=/usr
--------------------------------------------------------------------------------
/debian/source/format:
--------------------------------------------------------------------------------
1 | 3.0 (quilt)
2 |
--------------------------------------------------------------------------------
/makefile:
--------------------------------------------------------------------------------
1 | RELVER = alpha3
2 | PKG = comcom64-0.1$(RELVER)
3 | TGZ = $(PKG).tar.gz
4 |
5 | all: 64
6 | both: 64 32
7 |
8 | install uninstall:
9 | $(MAKE) -C src $@
10 |
11 | clean:
12 | $(MAKE) -C src clean
13 | $(MAKE) -C 32 clean
14 | $(RM) -f $(TGZ) *.zip
15 |
16 | distclean:
17 | git clean -fd || $(MAKE) clean
18 |
19 | $(TGZ):
20 | git archive -o $(CURDIR)/$(TGZ) --prefix=$(PKG)/ HEAD
21 | .PHONY: $(TGZ) 64 32 both
22 |
23 | tar: $(TGZ)
24 |
25 | rpm: comcom64.spec.rpkg
26 | git clean -fd
27 | rpkg local
28 |
29 | deb:
30 | debuild -i -us -uc -b
31 |
32 | 64:
33 | $(MAKE) -C src
34 |
35 | 32:
36 | $(MAKE) -C 32
37 |
38 | static:
39 | $(MAKE) -C src static
40 |
--------------------------------------------------------------------------------
/meson.build:
--------------------------------------------------------------------------------
1 | project('comcom64', 'c', version: '0.1', meson_version: '>= 1.4.0')
2 | subdir('src')
3 |
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | prefix ?= /usr/local
2 | DATADIR ?= $(prefix)/share/comcom64
3 | CFLAGS = -Wall -Os -Wmissing-declarations -Wwrite-strings \
4 | -ggdb3 -Wunused -Wmissing-prototypes
5 | SOURCES = command.c cmdbuf.c mouse.c env.c psp.c umb.c ae0x.c compl.c clip.c \
6 | thunks_a.c thunks_c.c
7 | HEADERS = ae0x.h cmdbuf.h compl.h psp.h command.h env.h mouse.h umb.h \
8 | glob_asm.h asm.h
9 | PDHDR = asm.h
10 | OBJECTS = $(SOURCES:.c=.o)
11 | AS_SOURCES = int23.S int0.S asm.S ms.S
12 | AS_OBJECTS = $(AS_SOURCES:.S=.o)
13 | CMD = comcom64.exe
14 | DBG = $(CMD).dbg
15 | REVISIONID := $(shell git describe --dirty=+)
16 | ifeq ($(REVISIONID),)
17 | REVISIONID := Non-git_build
18 | endif
19 | CFLAGS += -DREV_ID=\"$(REVISIONID)\"
20 | DJ64COMPACT_VA := 1
21 |
22 | .PHONY: all clean install uninstall
23 |
24 | all: $(CMD)
25 |
26 | static:
27 | $(MAKE) DJ64STATIC=1
28 |
29 | clean: clean_dj64
30 | $(RM) $(CMD)
31 |
32 | $(OBJECTS): $(HEADERS)
33 | $(AS_OBJECTS): asm.h asm.inc
34 |
35 | ifeq (,$(wildcard $(CMD)))
36 | install:
37 | @echo "Build it first or run \"make fetch\"" && false
38 | else
39 | install:
40 | endif
41 | mkdir -p $(DESTDIR)$(DATADIR)
42 | install -m 0644 $(CMD) $(DESTDIR)$(DATADIR)
43 | ln -sf $(CMD) $(DESTDIR)$(DATADIR)/command.com
44 |
45 | uninstall:
46 | rm -rf $(DATADIR)
47 |
48 | # hook in dj64 - make sure to not do that before defining `all:` target
49 | export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(prefix)/share/pkgconfig:$(prefix)/lib/pkgconfig
50 | DJMK = $(shell pkg-config --variable=makeinc dj64)
51 | ifeq ($(wildcard $(DJMK)),)
52 | ifeq ($(filter clean,$(MAKECMDGOALS)),)
53 | $(error dj64-dev not installed)
54 | endif
55 | clean_dj64:
56 | else
57 | include $(DJMK)
58 | endif
59 |
60 | ifeq ($(DJ64STATIC),1)
61 | CFLAGS += -DSTATIC_LINK
62 | endif
63 |
64 | $(CMD): $(DJ64_XLIB)
65 | ./link.sh $(LINK) $^ $(DBG) $@ $(DJ64_XLDFLAGS)
66 |
67 | info: $(CMD)
68 | djstubify -i $<
69 |
--------------------------------------------------------------------------------
/src/ae0x.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * ae0x.c: interface to int2f ax=0xae00,0xae01
4 | * Copyright (C) 2018 @andrewbird
5 | * Copyright (C) 2023-2024 @stsp
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include "env.h"
31 | #include "ae0x.h"
32 |
33 | #define CF 1
34 |
35 | struct ae0x {
36 | struct {
37 | uint8_t cmax;
38 | uint8_t clen;
39 | char cbuf[256];
40 | } __attribute__((packed)) cmdl;
41 | struct {
42 | uint8_t nlen;
43 | char nbuf[11];
44 | char _z;
45 | } __attribute__((packed)) cmdn;
46 | };
47 |
48 | static int exec_ae01(struct ae0x *s)
49 | {
50 | __dpmi_regs r = {};
51 |
52 | r.d.eax = 0xae01;
53 | r.d.edx = 0xffff;
54 | r.d.ecx = s->cmdn.nlen;
55 | /* dosmemput() was already done before ae00 */
56 | r.x.ds = __tb_segment;
57 | r.d.ebx = __tb_offset;
58 | r.d.esi = __tb_offset + sizeof(s->cmdl);
59 | r.d.edi = 0;
60 | set_env_seg();
61 | __dpmi_int(0x2f, &r);
62 | set_env_sel();
63 | if (r.x.flags & CF)
64 | return -1;
65 | dosmemget(__tb, sizeof(*s), s);
66 | return s->cmdn.nlen > 0;
67 | }
68 |
69 | int installable_command_check(char *cmd, const char *tail)
70 | {
71 | /* from RBIL
72 |
73 | AX = AE00h
74 | DX = magic value FFFFh
75 | CH = FFh
76 | CL = length of command line tail (4DOS v4.0)
77 | DS:BX -> command line buffer (see #02977)
78 | DS:SI -> command name buffer (see #02978)
79 | DI = 0000h (4DOS v4.0)
80 |
81 | Return:
82 | AL = FFh if this command is a TSR extension to COMMAND.COM
83 | AL = 00h if the command should be executed as usual
84 |
85 |
86 | Format of COMMAND.COM command line buffer:
87 |
88 | Offset Size Description (Table 02977)
89 | 00h BYTE max length of command line, as in INT 21/AH=0Ah
90 | 01h BYTE count of bytes to follow, excluding terminating 0Dh
91 | N BYTEs command line text, terminated by 0Dh
92 |
93 |
94 | Format of command name buffer:
95 |
96 | Offset Size Description (Table 02978)
97 | 00h BYTE length of command name
98 | 01h N BYTEs uppercased command name (blank-padded to 11 chars by 4DOS v4)
99 |
100 | */
101 |
102 | char *p;
103 | char *q;
104 | int i;
105 | char *name;
106 | int tlen;
107 | int nlen;
108 | __dpmi_regs r = {};
109 | struct ae0x s = {};
110 | int rc;
111 |
112 | p = strrchr(cmd, '\\');
113 | if (p)
114 | name = p + 1;
115 | else
116 | name = cmd;
117 |
118 | nlen = 0;
119 | for (p = name, q = &s.cmdn.nbuf[0], i = 0; *p; p++) {
120 | if (*p == '.') {
121 | nlen = i;
122 | if (i < 8) {
123 | memset(q + i, ' ', 8 - i);
124 | i = 8;
125 | }
126 | continue;
127 | }
128 | if (i >= sizeof(s.cmdn.nbuf))
129 | return -1;
130 | q[i++] = toupper(*p);
131 | }
132 | if (i < 11)
133 | memset(q + i, ' ', 11 - i);
134 | if (!nlen) // no dot found
135 | nlen = i;
136 | s.cmdn.nlen = nlen; // does not cover extension
137 |
138 | if (strlen(cmd) + strlen(tail) + 2 >= sizeof(s.cmdl.cbuf))
139 | return -1;
140 | s.cmdl.cmax = sizeof(s.cmdl.cbuf) - 1;
141 | if (tail[0]) {
142 | s.cmdl.clen = snprintf(s.cmdl.cbuf, sizeof(s.cmdl.cbuf),
143 | "%s %s\r", cmd, tail) - 1;
144 | tlen = strlen(tail) + 1; // account for 'space'
145 | } else {
146 | s.cmdl.clen = snprintf(s.cmdl.cbuf, sizeof(s.cmdl.cbuf), "%s\r", cmd) - 1;
147 | tlen = 0;
148 | }
149 |
150 | r.d.eax = 0xae00;
151 | r.d.ecx = 0xff00 + tlen;
152 | r.d.edx = 0xffff;
153 | r.x.ds = __tb_segment;
154 | r.d.ebx = __tb_offset;
155 | r.d.esi = __tb_offset + sizeof(s.cmdl);
156 | r.d.edi = 0;
157 | dosmemput(&s, sizeof(s), __tb);
158 | set_env("PATH", getenv("PATH"));
159 | set_env_seg();
160 | __dpmi_int(0x2f, &r);
161 | set_env_sel();
162 | if (r.x.flags & CF)
163 | return -1;
164 | dosmemget(__tb, sizeof(s), &s);
165 | if (r.h.al != 0xff)
166 | return 1;
167 | rc = exec_ae01(&s);
168 | if (rc != -1)
169 | get_env();
170 | if (rc <= 0)
171 | return rc;
172 | /* dont trust nlen here as it contains the old value */
173 | memcpy(name, s.cmdn.nbuf, sizeof(s.cmdn.nbuf));
174 | name[sizeof(s.cmdn.nbuf)] = '\0';
175 | q = strchr(name, ' ');
176 | if (!q)
177 | {
178 | /* insert dot */
179 | memmove(name + 9, name + 8, 4); // 4 includes \0
180 | name[8] = '.';
181 | }
182 | else
183 | {
184 | int spn;
185 | *q = '.';
186 | q++;
187 | spn = strspn(q, " ");
188 | if (spn)
189 | memmove(q, q + spn, strlen(q + spn) + 1);
190 | }
191 | return 1;
192 | }
193 |
--------------------------------------------------------------------------------
/src/ae0x.h:
--------------------------------------------------------------------------------
1 | #ifndef AE0X_H
2 | #define AE0X_H
3 |
4 | int installable_command_check(char *cmd, const char *tail);
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/src/asm.S:
--------------------------------------------------------------------------------
1 | #include "asm.h"
2 |
3 | .bss
4 | .global __ds
5 | __ds: .long 0
6 | .ifndef _DJ64
7 | /* We need emergency stack because __dpmi_int() alters SS in djgpp.
8 | * That was eventually fixed in dj64, hence the ifdef. */
9 | .global _cstack
10 | _cstack: .fill SIGSTK_LEN
11 | .endif
12 |
13 | #ifdef __ELF__
14 | .section .note.GNU-stack,"",%progbits
15 | #endif
16 |
--------------------------------------------------------------------------------
/src/asm.h:
--------------------------------------------------------------------------------
1 | #ifndef ASM_H
2 | #define ASM_H
3 |
4 | #ifndef __ASSEMBLER__
5 | #ifdef DJ64
6 | #include
7 | #else
8 | #include "asm_inc.h"
9 | #endif
10 |
11 | #define ASMCFUNC
12 |
13 | int ASMCFUNC do_int23(void);
14 | void ASMCFUNC do_int0(void);
15 | void ASMCFUNC do_mouse(void);
16 |
17 | #else
18 |
19 | #define SIGSTK_LEN 0x200
20 |
21 | #endif
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/asm.inc:
--------------------------------------------------------------------------------
1 | .macro handler_prolog len
2 | push %ds
3 | mov %cs:__ds, %eax
4 | mov %eax, %ds
5 | .ifndef _DJ64
6 | /* djgpp needs emergency stack because of a bug in __dpmi_int() */
7 | mov %ss, %esi
8 | mov %esp, %edi
9 | pushl __ds
10 | lea _cstack+\len, %edx
11 | push %edx
12 | lss (%esp), %esp
13 | push %esi
14 | push %edi
15 | .endif
16 | .endm
17 |
18 | .macro restore_stack
19 | .ifndef _DJ64
20 | lss (%esp), %esp
21 | .endif
22 | pop %ds
23 | .endm
24 |
--------------------------------------------------------------------------------
/src/clip.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * clip.c: winoldap clipboard support
4 | * Copyright (C) 2024 @stsp
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include "clip.h"
29 |
30 | #define CF 1
31 |
32 | static int clip_open(void)
33 | {
34 | __dpmi_regs r = {};
35 |
36 | r.d.eax = 0x1701;
37 | __dpmi_int(0x2f, &r);
38 | if ((r.x.flags & CF) || r.x.ax != 0x3244) // check dosemu2 extension
39 | return -1;
40 | return r.x.ax;
41 | }
42 |
43 | static void clip_close(void)
44 | {
45 | __dpmi_regs r = {};
46 |
47 | r.d.eax = 0x1708;
48 | __dpmi_int(0x2f, &r);
49 | }
50 |
51 | static unsigned clip_avail(int type)
52 | {
53 | __dpmi_regs r = {};
54 |
55 | r.d.eax = 0x1704;
56 | r.d.edx = type;
57 | __dpmi_int(0x2f, &r);
58 | return ((r.x.dx << 16) | r.x.ax);
59 | }
60 |
61 | int clip_read(int type, void (*cbk)(const char *buf, int len))
62 | {
63 | __dpmi_regs r = {};
64 | int rc;
65 | int ret = 0;
66 | unsigned avail;
67 |
68 | rc = clip_open();
69 | if (rc == -1)
70 | return rc;
71 | avail = clip_avail(type);
72 | while (avail > 0) {
73 | char buf[0x10000];
74 | uint16_t todo = (avail < 0xffff ? avail : 0xffff);
75 | r.d.eax = 0x1705;
76 | r.d.edx = type;
77 | r.d.edi = rc; // enable dosemu2 extension
78 | r.d.ecx = todo;
79 | r.x.es = __tb_segment;
80 | r.d.ebx = __tb_offset;
81 | __dpmi_int(0x2f, &r);
82 | if ((r.x.flags & CF) || r.x.ax != todo) {
83 | ret = -1;
84 | break;
85 | }
86 | dosmemget(__tb, todo, buf);
87 | cbk(buf, todo);
88 | ret += todo;
89 | avail -= todo;
90 | }
91 | clip_close();
92 | return ret;
93 | }
94 |
95 | int clip_write(int type, int (*cbk)(char *buf, int len))
96 | {
97 | __dpmi_regs r = {};
98 | int rc;
99 | int ret = 0;
100 | char buf[0x10000];
101 | int todo;
102 |
103 | rc = clip_open();
104 | if (rc == -1)
105 | return rc;
106 | while ((todo = cbk(buf, 0xffff)) > 0) {
107 | r.d.eax = 0x1703;
108 | r.d.edx = type;
109 | r.d.ecx = todo;
110 | r.x.es = __tb_segment;
111 | r.d.ebx = __tb_offset;
112 | dosmemput(buf, todo, __tb);
113 | __dpmi_int(0x2f, &r);
114 | if ((r.x.flags & CF) || r.x.ax == 0) {
115 | ret = -1;
116 | break;
117 | }
118 | ret += todo;
119 | }
120 | if (todo == -1)
121 | ret = -1;
122 | clip_close();
123 | return ret;
124 | }
125 |
--------------------------------------------------------------------------------
/src/clip.h:
--------------------------------------------------------------------------------
1 | #ifndef CLIP_H
2 | #define CLIP_H
3 |
4 | int clip_read(int type, void (*cbk)(const char *buf, int len));
5 | int clip_write(int type, int (*cbk)(char *buf, int len));
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/src/cmdbuf.c:
--------------------------------------------------------------------------------
1 | /* Command-line buffer handling for FreeDOS-32's COMMAND
2 | *
3 | * Copyright (C) 2005 by Hanzac Chen
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the
17 | * Free Software Foundation, Inc.,
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 | */
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include "cmdbuf.h"
27 |
28 | #ifdef __MINGW32__
29 | #define cputs(s) _cputs(s)
30 | #endif
31 |
32 | #define KEYB_FLAG_INSERT 0x0080
33 | #define KEY_ASCII(k) (k & 0x00FF)
34 | #define KEY_BACKSPACE KEY_ASCII(0x0E08)
35 |
36 | static unsigned int tail = 0;
37 | static unsigned int cur = 0;
38 |
39 | #define MAX_CMDQUEUE_LEN 0x10
40 | static char cmdqueue[MAX_CMDQUEUE_LEN][MAX_CMD_BUFLEN];
41 | static unsigned int cmdqueue_count = 0;
42 | static unsigned int cmdqueue_index = 0;
43 | static const char *hist_name = "cc.his";
44 |
45 | static void _cmdbuf_clr_line(char *cmd_buf)
46 | {
47 | unsigned int i, n;
48 | /* Clear the original command */
49 | for (i = 0, n = tail; i < n; i++) {
50 | putch(KEY_ASCII(KEY_BACKSPACE));
51 | cur--;
52 | cmdbuf_delch(cmd_buf);
53 | }
54 | }
55 |
56 | int cmdbuf_move(char *cmd_buf, int direction)
57 | {
58 | int ret = 0;
59 | switch (direction)
60 | {
61 | case UP:
62 | if (cmdqueue_index && cmdqueue[cmdqueue_index - 1][0] != '\0')
63 | {
64 | cmdqueue_index--;
65 | ret++;
66 | }
67 | break;
68 | case LEFT:
69 | if (cur != 0) {
70 | putch(KEY_ASCII(KEY_BACKSPACE));
71 | cur--;
72 | ret++;
73 | }
74 | break;
75 | case RIGHT:
76 | if (cur < tail) {
77 | putch(cmd_buf[cur]);
78 | cur++;
79 | ret++;
80 | }
81 | break;
82 | case DOWN:
83 | if (cmdqueue[cmdqueue_index][0] == '\0' ||
84 | cmdqueue_index == cmdqueue_count)
85 | break;
86 | cmdqueue_index++;
87 | ret++;
88 | break;
89 | case HOME:
90 | while (cur != 0) {
91 | putch(KEY_ASCII(KEY_BACKSPACE));
92 | cur--;
93 | ret++;
94 | }
95 | break;
96 | case END:
97 | while (cur < tail) {
98 | putch(cmd_buf[cur]);
99 | cur++;
100 | ret++;
101 | }
102 | break;
103 | case PGUP:
104 | if (cmdqueue_index && cmdqueue[0][0] != '\0') {
105 | cmdqueue_index = 0;
106 | direction = UP;
107 | ret++;
108 | }
109 | break;
110 | case PGDN:
111 | if (cmdqueue_index < cmdqueue_count) {
112 | cmdqueue_index = cmdqueue_count;
113 | direction = DOWN;
114 | ret++;
115 | }
116 | break;
117 | }
118 |
119 | if (direction == UP || direction == DOWN) {
120 | _cmdbuf_clr_line(cmd_buf);
121 | if (cmdqueue[cmdqueue_index][0] != '\0') {
122 | /* Reinput the command from the queue */
123 | cputs(cmdqueue[cmdqueue_index]);
124 | strcpy(cmd_buf, cmdqueue[cmdqueue_index]);
125 | cur = tail = strlen(cmdqueue[cmdqueue_index]);
126 | }
127 | }
128 |
129 | return ret;
130 | }
131 |
132 | void cmdbuf_delch(char *cmd_buf)
133 | {
134 | if (cur < tail) {
135 | unsigned int i;
136 | cmd_buf[cur] = 0;
137 | cmd_buf[tail] = 0;
138 |
139 | /* Move the left string to the current position */
140 | for (i = cur; i < tail-1; i++)
141 | {
142 | putch(cmd_buf[i+1]);
143 | cmd_buf[i] = cmd_buf[i+1];
144 | }
145 | putch(' ');
146 |
147 | /* Put cursor back to the current position */
148 | for (i = cur; i < tail; i++)
149 | putch(KEY_ASCII(KEY_BACKSPACE));
150 |
151 | /* Subtract the string 1 */
152 | tail--;
153 | }
154 | }
155 |
156 | void cmdbuf_clreol(char *cmd_buf)
157 | {
158 | clreol();
159 | tail = cur;
160 | cmdbuf_trunc(cmd_buf);
161 | }
162 |
163 | int cmdbuf_bksp(char *cmd_buf)
164 | {
165 | if (cur == 0)
166 | return 0;
167 | cur--;
168 | if (cur == tail - 1)
169 | {
170 | tail--;
171 | return 1;
172 | }
173 | putch(KEY_ASCII(KEY_BACKSPACE));
174 | cmdbuf_delch(cmd_buf);
175 | return 0;
176 | }
177 |
178 | void cmdbuf_clear(char *cmd_buf)
179 | {
180 | _cmdbuf_clr_line(cmd_buf);
181 | }
182 |
183 | char cmdbuf_putch(char *cmd_buf, unsigned int buf_size, char ch, unsigned short flag)
184 | {
185 | unsigned int i;
186 |
187 | if (cur < buf_size) {
188 | /* Reflect the insert method */
189 | if (!(flag&KEYB_FLAG_INSERT)) {
190 | for (i = tail; i > cur; i--)
191 | cmd_buf[i] = cmd_buf[i-1];
192 | }
193 | /* Put into cmdline buffer */
194 | cmd_buf[cur++] = ch;
195 | if ((!(flag&KEYB_FLAG_INSERT) && tail < buf_size) || cur > tail)
196 | tail++;
197 | /* Update the string on screen */
198 | for (i = cur-1; i < tail-1; i++)
199 | putch(cmd_buf[i]);
200 | if (cur == tail)
201 | return cmd_buf[tail - 1];
202 | putch(cmd_buf[tail - 1]);
203 |
204 | /* Put cursor back to the current position */
205 | for (i = cur; i < tail; i++)
206 | putch(KEY_ASCII(KEY_BACKSPACE));
207 | }
208 | return 0;
209 | }
210 |
211 | void cmdbuf_reset(void)
212 | {
213 | cmdqueue_index = cmdqueue_count;
214 | cur = tail = 0;
215 | }
216 |
217 | void cmdbuf_trunc(char *cmd_buf)
218 | {
219 | cmd_buf[tail] = '\0';
220 | }
221 |
222 | void cmdbuf_puts(const char *cmd_buf)
223 | {
224 | cur = tail = strlen(cmd_buf);
225 | }
226 |
227 | void cmdbuf_eol(void)
228 | {
229 | /* Reset the cmdbuf */
230 | cur = tail = 0;
231 | }
232 |
233 | int cmdbuf_getcur(void)
234 | {
235 | return cur;
236 | }
237 |
238 | int cmdbuf_gettail(void)
239 | {
240 | return tail;
241 | }
242 |
243 | void cmdbuf_store_tmp(const char *cmd_buf)
244 | {
245 | strcpy(cmdqueue[cmdqueue_index], cmd_buf);
246 | }
247 |
248 | void cmdbuf_store(const char *cmd_buf)
249 | {
250 | if (cmd_buf[0] == '\0')
251 | return;
252 | if (!cmdqueue_count || strcmp(cmd_buf, cmdqueue[cmdqueue_count - 1]) != 0)
253 | {
254 | const char *tmp;
255 | /* Enqueue the cmdbuf and save the current index */
256 | strcpy(cmdqueue[cmdqueue_count], cmd_buf);
257 | cmdqueue_count++;
258 | if (cmdqueue_count == MAX_CMDQUEUE_LEN)
259 | {
260 | int i;
261 | for (i = 1; i < cmdqueue_count; i++)
262 | strcpy(cmdqueue[i - 1], cmdqueue[i]);
263 | cmdqueue_count--;
264 | cmdqueue[cmdqueue_count][0] = '\0';
265 | }
266 | tmp = getenv("TEMP");
267 | if (tmp)
268 | {
269 | char pathbuf[MAXPATH];
270 | FILE *his;
271 | snprintf(pathbuf, MAXPATH, "%s\\%s", tmp, hist_name);
272 | his = fopen(pathbuf, "a");
273 | if (his)
274 | {
275 | fputs(cmd_buf, his);
276 | fputs("\n", his); // actually puts \r\n
277 | fclose(his);
278 | }
279 | }
280 | }
281 | cmdqueue_index = cmdqueue_count;
282 | }
283 |
284 | static int count_lines(FILE *f)
285 | {
286 | int c;
287 | int cnt = 0;
288 | while ((c = fgetc(f)) != EOF)
289 | {
290 | if (c == '\n')
291 | cnt++;
292 | }
293 | rewind(f);
294 | return cnt;
295 | }
296 |
297 | static int seek_to_line(FILE *f, int n)
298 | {
299 | int c;
300 | int cnt = 0;
301 | if (!n)
302 | return 0;
303 | while ((c = fgetc(f)) != EOF)
304 | {
305 | if (c == '\n')
306 | cnt++;
307 | if (cnt == n)
308 | return 0;
309 | }
310 | rewind(f);
311 | return -1;
312 | }
313 |
314 | void cmdbuf_init(void)
315 | {
316 | const char *tmp = getenv("TEMP");
317 | if (tmp)
318 | {
319 | char pathbuf[MAXPATH];
320 | FILE *his;
321 | snprintf(pathbuf, MAXPATH, "%s\\%s", tmp, hist_name);
322 | his = fopen(pathbuf, "r");
323 | if (his)
324 | {
325 | int cnt = count_lines(his);
326 | int cnt1 = cnt;
327 | /* always leave 1 empty slot */
328 | if (cnt > (MAX_CMDQUEUE_LEN - 1))
329 | {
330 | seek_to_line(his, cnt - (MAX_CMDQUEUE_LEN - 1));
331 | cnt = (MAX_CMDQUEUE_LEN - 1);
332 | }
333 | for (cmdqueue_count = 0; cmdqueue_count < cnt; cmdqueue_count++)
334 | {
335 | char *got = fgets(cmdqueue[cmdqueue_count], MAX_CMD_BUFLEN, his);
336 | if (!got)
337 | break;
338 | /* strip \n */
339 | cmdqueue[cmdqueue_count][strlen(cmdqueue[cmdqueue_count]) - 1] = '\0';
340 | }
341 | fclose(his);
342 | cmdqueue_index = cmdqueue_count;
343 | /* if history is too long, rewrite the file */
344 | if (cnt1 > cnt)
345 | {
346 | his = fopen(pathbuf, "w");
347 | if (his)
348 | {
349 | int i;
350 | for (i = 0; i < cnt; i++)
351 | {
352 | fputs(cmdqueue[i], his);
353 | fputs("\n", his); // actually puts \r\n
354 | }
355 | fclose(his);
356 | }
357 | }
358 | }
359 | }
360 | }
361 |
--------------------------------------------------------------------------------
/src/cmdbuf.h:
--------------------------------------------------------------------------------
1 | #ifndef __CMDBUF_H__
2 | #define __CMDBUF_H__
3 |
4 | /*
5 | * Command parser defines
6 | */
7 | #define MAX_CMD_BUFLEN 512 // Define max command length
8 |
9 | enum { UP, LEFT, RIGHT, DOWN, HOME, END, PGUP, PGDN };
10 |
11 | int cmdbuf_move(char *cmd_buf, int direction);
12 | void cmdbuf_delch(char *cmd_buf);
13 | int cmdbuf_bksp(char *cmd_buf);
14 | void cmdbuf_clear(char *cmd_buf);
15 | void cmdbuf_trunc(char *cmd_buf);
16 | void cmdbuf_eol(void);
17 | void cmdbuf_clreol(char *cmd_buf);
18 | void cmdbuf_puts(const char *cmd_buf);
19 | char cmdbuf_putch(char *cmd_buf, unsigned int buf_size, char ch, unsigned short flag);
20 | void cmdbuf_store(const char *cmd_buf);
21 | void cmdbuf_store_tmp(const char *cmd_buf);
22 | void cmdbuf_reset(void);
23 | void cmdbuf_init(void);
24 | int cmdbuf_getcur(void);
25 | int cmdbuf_gettail(void);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/src/command.h:
--------------------------------------------------------------------------------
1 | /* Command shell definitions and portability between
2 | * different environments, etc. by Hanzac Chen
3 | */
4 |
5 | #ifndef __COMMAND_H__
6 | #define __COMMAND_H__
7 |
8 | #include
9 |
10 | #ifdef __GNUC__
11 | #define __CMD_COMPILER__ "GCC "
12 | #endif
13 |
14 | /*
15 | * Command.com shell modes
16 | */
17 | #define SHELL_NORMAL 0 // interactive mode, user can exit
18 | #define SHELL_PERMANENT 1 // interactive mode, user cannot exit
19 | #define SHELL_SINGLE_CMD 2 // non-interactive, run one command, then exit
20 | #define SHELL_STARTUP_WITH_CMD 3 // run one command on startup, interactive thereafter, user can exit
21 |
22 | /*
23 | * Pipe defines
24 | */
25 | #define STDIN_INDEX 0
26 | #define STDOUT_INDEX 1
27 |
28 | /*
29 | * Max subdirectory level, used by /S switch within XCOPY, ATTRIB and DELTREE
30 | */
31 | #define MAX_SUBDIR_LEVEL 15
32 |
33 | /*
34 | * File transfer modes
35 | */
36 | #define FILE_XFER_COPY 0
37 | #define FILE_XFER_XCOPY 1
38 | #define FILE_XFER_MOVE 2
39 |
40 | /*
41 | * Temporarily and Slightly FIX the keyboard problem
42 | */
43 | #define GET_ENHANCED_KEYSTROKE 0x10
44 | #define GET_EXTENDED_SHIFT_STATES 0x12
45 |
46 | #define KEYB_FLAG_RSHIFT 0x0001
47 | #define KEYB_FLAG_LSHIFT 0x0002
48 | #define KEYB_FLAG_CTRL 0x0004
49 | #define KEYB_FLAG_ALT 0x0008
50 | #define KEYB_FLAG_SCROLLOCK 0x0010
51 | #define KEYB_FLAG_NUMLOCK 0x0020
52 | #define KEYB_FLAG_CAPSLOCK 0x0040
53 | #define KEYB_FLAG_INSERT 0x0080
54 |
55 | #define KEY_ASCII(k) (k & 0x00FF)
56 | #define KEY_SCANCODE(k) (k >> 0x08 )
57 | #define KEY_EXTM(k) (k & 0xFF1F)
58 | #define KEY_EXT 0x00E0
59 | #define KEY_ESC KEY_ASCII(0x011B)
60 | #define KEY_ENTER KEY_ASCII(0x1C0D)
61 | #define KEY_BACKSPACE KEY_ASCII(0x0E08)
62 | #define KEY_TAB KEY_ASCII(0x0F09)
63 | #define KEY_HOME KEY_EXTM(0x47E0)
64 | #define KEY_UP KEY_EXTM(0x48E0)
65 | #define KEY_LEFT KEY_EXTM(0x4BE0)
66 | #define KEY_RIGHT KEY_EXTM(0x4DE0)
67 | #define KEY_END KEY_EXTM(0x4FE0)
68 | #define KEY_DOWN KEY_EXTM(0x50E0)
69 | #define KEY_PGUP KEY_EXTM(0x49E0)
70 | #define KEY_PGDN KEY_EXTM(0x51E0)
71 | #define KEY_INSERT KEY_EXTM(0x52E0)
72 | #define KEY_DELETE KEY_EXTM(0x53E0)
73 |
74 | /*
75 | * Common definitions
76 | */
77 | #if defined(__MINGW32__) || defined(__WATCOMC__)
78 | #include
79 |
80 | #define _fixpath(a,b) _fullpath(b,a,_MAX_PATH)
81 | #define fnsplit(p,drive,dir,n,e) _splitpath(p,drive,dir,n,e)
82 | #define fnmerge(p,drive,dir,n,e) _makepath(p,drive,dir,n,e)
83 |
84 | /* Cursor shape */
85 | #define _NOCURSOR 0
86 | #define _SOLIDCURSOR 1
87 | #define _NORMALCURSOR 2
88 |
89 | /* Additional access() checks */
90 | #define D_OK 0x10
91 |
92 | #define FA_RDONLY 1
93 | #define FA_HIDDEN 2
94 | #define FA_SYSTEM 4
95 | #define FA_LABEL 8
96 | #define FA_DIREC 16
97 | #define FA_ARCH 32
98 | #define MAXINT (0x7fffffff)
99 | #define MAXPATH _MAX_PATH
100 | #define MAXDRIVE 3
101 | #define MAXDIR 256
102 | #define MAXFILE 256
103 | #define MAXEXT 255
104 |
105 | /* File find */
106 | typedef struct _finddata_t finddata_t;
107 | static inline int findfirst_f(const char *pathname, finddata_t *ff, int attrib, long *handle)
108 | {
109 | if (attrib == FA_LABEL) {
110 | return -1;
111 | } else {
112 | long h = _findfirst(pathname, ff);
113 | if (h != -1) {
114 | if (handle != NULL)
115 | *handle = h;
116 | return 0;
117 | } else {
118 | return -1;
119 | }
120 | }
121 | }
122 | static inline int findnext_f(finddata_t *ff, long handle)
123 | {
124 | return _findnext(handle, ff);
125 | }
126 | static inline int findclose_f(long handle)
127 | {
128 | return _findclose(handle);
129 | }
130 | #define FINDDATA_T_FILENAME(f) f.name
131 | #define FINDDATA_T_ATTRIB(f) f.attrib
132 | #define FINDDATA_T_SIZE(f) f.size
133 | #define FINDDATA_T_WDATE_YEAR(f) localtime(&f.time_write)->tm_year+1900
134 | #define FINDDATA_T_WDATE_MON(f) localtime(&f.time_write)->tm_mon+1
135 | #define FINDDATA_T_WDATE_DAY(f) localtime(&f.time_write)->tm_mday
136 | #define FINDDATA_T_WTIME_HOUR(f) localtime(&f.time_write)->tm_hour
137 | #define FINDDATA_T_WTIME_MIN(f) localtime(&f.time_write)->tm_min
138 |
139 | typedef struct _diskfree_t diskfree_t;
140 | #define DISKFREE_T_AVAIL(d) d.avail_clusters
141 | #define DISKFREE_T_TOTAL(d) d.total_clusters
142 | #define DISKFREE_T_BSEC(d) d.bytes_per_sector
143 | #define DISKFREE_T_SCLUS(d) d.sectors_per_cluster
144 |
145 | #define getdfree(d,p) _getdiskfree(d,p)
146 |
147 | #endif
148 |
149 | /*
150 | * Different compilers
151 | */
152 | #ifdef __MINGW32__
153 | #include
154 | #include
155 | #include
156 |
157 | #define pipe(filedes) _pipe(filedes, 0x4000, O_TEXT)
158 |
159 | /* Conio utilites */
160 | #define cprintf(...) _cprintf(__VA_ARGS__)
161 | #define cputs(s) _cputs(s)
162 | static CONSOLE_SCREEN_BUFFER_INFO info;
163 | static int __conio_x = 0;
164 | static int __conio_y = 0;
165 | static int __conio_top = 0;
166 | static int __conio_left = 0;
167 | static int __conio_width = 80;
168 | static int __conio_height = 25;
169 | static WORD __conio_attrib = 0x07;
170 | static void __fill_conio_info (void)
171 | {
172 | GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
173 | __conio_left = info.srWindow.Left;
174 | __conio_top = info.srWindow.Top;
175 | __conio_x = info.dwCursorPosition.X - __conio_left + 1;
176 | __conio_y = info.dwCursorPosition.Y - __conio_top + 1;
177 | __conio_width = info.srWindow.Right - info.srWindow.Left + 1;
178 | __conio_height = info.srWindow.Bottom - info.srWindow.Top + 1;
179 | __conio_attrib = info.wAttributes;
180 | }
181 | static inline void gotoxy(int x, int y)
182 | {
183 | COORD c;
184 | c.X = __conio_left + x - 1;
185 | c.Y = __conio_top + y - 1;
186 | SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
187 | }
188 | static inline void clrscr(void)
189 | {
190 | DWORD written, i;
191 | __fill_conio_info();
192 | for (i = __conio_top; i < __conio_top + __conio_height; i++) {
193 | FillConsoleOutputAttribute (GetStdHandle(STD_OUTPUT_HANDLE), __conio_attrib, __conio_width, (COORD) {__conio_left, i}, &written);
194 | FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ', __conio_width, (COORD) {__conio_left, i}, &written);
195 | }
196 | gotoxy (1, 1);
197 | }
198 | static inline void clreol(void)
199 | {
200 | COORD coord;
201 | DWORD written;
202 | __fill_conio_info();
203 | FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ', __conio_width - __conio_x + 1, coord, &written);
204 | gotoxy (__conio_x, __conio_y);
205 | }
206 | static inline void _setcursortype(int type)
207 | {
208 | CONSOLE_CURSOR_INFO cursor_info;
209 | cursor_info.bVisible = TRUE;
210 | switch (type) {
211 | case _NOCURSOR:
212 | cursor_info.bVisible = FALSE;
213 | break;
214 | case _SOLIDCURSOR:
215 | cursor_info.dwSize = 100;
216 | break;
217 | default:
218 | cursor_info.dwSize = 1;
219 | break;
220 | }
221 | SetConsoleCursorInfo (GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
222 | }
223 | #define delay(t) Sleep(t/1000)
224 |
225 | /* File attributes */
226 | static inline unsigned int setfileattr(const char *filename, unsigned int attr)
227 | {
228 | unsigned int ret = 0;
229 | DWORD win32_attr = 0;
230 |
231 | win32_attr |= attr&_A_RDONLY ? FILE_ATTRIBUTE_READONLY : 0;
232 | win32_attr |= attr&_A_HIDDEN ? FILE_ATTRIBUTE_HIDDEN : 0;
233 | win32_attr |= attr&_A_SYSTEM ? FILE_ATTRIBUTE_SYSTEM : 0;
234 | win32_attr |= attr&_A_SUBDIR ? FILE_ATTRIBUTE_DIRECTORY : 0;
235 | win32_attr |= attr&_A_ARCH ? FILE_ATTRIBUTE_ARCHIVE : 0;
236 | if (!SetFileAttributes(filename, win32_attr)) {
237 | errno = ENOENT;
238 | ret = 2; /* File not found */
239 | }
240 | return ret;
241 | }
242 | static inline unsigned int getfileattr(const char *filename, unsigned int *p_attr)
243 | {
244 | unsigned int ret = 0;
245 | DWORD win32_attr = GetFileAttributes(filename);
246 |
247 | if (win32_attr != INVALID_FILE_ATTRIBUTES) {
248 | if (p_attr != NULL) {
249 | *p_attr = 0;
250 | /* *p_attr |= attr&0 ? _A_VOLID : 0
251 | *p_attr |= attr&FILE_ATTRIBUTE_NORMAL ? _A_NORMAL : 0; */
252 | *p_attr |= win32_attr&FILE_ATTRIBUTE_READONLY ? _A_RDONLY : 0;
253 | *p_attr |= win32_attr&FILE_ATTRIBUTE_HIDDEN ? _A_HIDDEN : 0;
254 | *p_attr |= win32_attr&FILE_ATTRIBUTE_SYSTEM ? _A_SYSTEM : 0;
255 | *p_attr |= win32_attr&FILE_ATTRIBUTE_DIRECTORY ? _A_SUBDIR : 0;
256 | *p_attr |= win32_attr&FILE_ATTRIBUTE_ARCHIVE ? _A_ARCH : 0;
257 | }
258 | } else {
259 | errno = ENOENT;
260 | ret = 2; /* File not found */
261 | }
262 |
263 | return ret;
264 | }
265 | static inline int file_access(const char *filename, int flags)
266 | {
267 | if (flags & D_OK) {
268 | unsigned int attr = 0;
269 | getfileattr(filename, &attr);
270 | if (attr & _A_SUBDIR) {
271 | return 0;
272 | } else {
273 | errno = EACCES;
274 | return -1; /* not a directory */
275 | }
276 | }
277 | return access(filename, flags);
278 | }
279 | static inline int file_copytime(int desc_handle, int src_handle)
280 | {
281 | int ret;
282 | struct stat source_st;
283 | struct _utimbuf dest_ut;
284 | if ((ret = fstat(src_handle, &source_st)) == 0) {
285 | dest_ut.actime = source_st.st_atime;
286 | dest_ut.modtime = source_st.st_mtime;
287 | ret = _futime(desc_handle, &dest_ut);
288 | }
289 | return ret;
290 | }
291 | /* Disk free */
292 | static inline void setdrive(unsigned int drive, unsigned int *p_drives)
293 | {
294 | _chdrive(drive);
295 | }
296 | static inline void getdrive(unsigned int *p_drive)
297 | {
298 | if (p_drive != NULL)
299 | *p_drive = _getdrive();
300 | }
301 |
302 | #elif __WATCOMC__
303 | #ifndef __VERSION__
304 | #define __VERSION__ "1.6"
305 | #endif
306 |
307 | #ifndef __CMD_COMPILER__
308 | #define __CMD_COMPILER__ "WATCOMC "
309 | #endif
310 |
311 | int pipe( int *__phandles)
312 | {
313 | return 0;
314 | }
315 |
316 | static inline void clrscr(void)
317 | {
318 | }
319 | static inline void clreol(void)
320 | {
321 | }
322 | static inline void _setcursortype(int type)
323 | {
324 | }
325 |
326 | struct ftime {
327 | unsigned ft_tsec:5; /* 0-29, double to get real seconds */
328 | unsigned ft_min:6; /* 0-59 */
329 | unsigned ft_hour:5; /* 0-23 */
330 | unsigned ft_day:5; /* 1-31 */
331 | unsigned ft_month:4; /* 1-12 */
332 | unsigned ft_year:7; /* since 1980 */
333 | };
334 |
335 | static inline void setdrive(unsigned int drive, unsigned int *p_drives)
336 | {
337 | _dos_setdrive(drive, p_drives);
338 | }
339 | static inline void getdrive(unsigned int *p_drive)
340 | {
341 | _dos_getdrive(p_drive);
342 | }
343 |
344 | /* File attributes */
345 | static inline unsigned int setfileattr(const char *filename, unsigned int attr)
346 | {
347 | return _dos_setfileattr(filename, attr);
348 | }
349 | static inline unsigned int getfileattr(const char *filename, unsigned int *p_attr)
350 | {
351 | return _dos_getfileattr(filename, p_attr);
352 | }
353 | static inline int file_access(const char *filename, int flags)
354 | {
355 | return access(filename, flags);
356 | }
357 | static inline int file_copytime(int desc_handle, int src_handle)
358 | {
359 | int ret;
360 | unsigned short _date, _time;
361 | if ((ret = _dos_getftime(src_handle, &_date, &_time)) == 0)
362 | ret = _dos_setftime(desc_handle, _date, _time);
363 | return ret;
364 | }
365 |
366 | #elif __DJGPP__
367 | #include
368 | #include
369 | #include
370 | #include
371 | #include
372 | #include
373 | #ifndef DJ64
374 | #include "findclos.h"
375 | #endif
376 |
377 | #ifndef USE_CONIO_OUT
378 | #define cprintf printf
379 | #define cputs(s) fputs(s, stdout)
380 | #define putch(c) putchar(c)
381 | #endif
382 |
383 | #define _mkdir(dir_path) mkdir(dir_path, S_IRWXU)
384 |
385 | /* File find */
386 | typedef struct ffblk finddata_t;
387 | #define FINDDATA_T_FILENAME(f) (f).ff_name
388 | #define FINDDATA_T_ATTRIB(f) (f).ff_attrib
389 | #define FINDDATA_T_SIZE(f) (unsigned)(f).ff_fsize
390 | #define FINDDATA_T_WDATE_YEAR(f) (((f).ff_fdate>>9)&0x7F)+1980
391 | #define FINDDATA_T_WDATE_MON(f) ((f).ff_fdate>>5)&0xF
392 | #define FINDDATA_T_WDATE_DAY(f) ((f).ff_fdate)&0x1F
393 | #define FINDDATA_T_WTIME_HOUR(f) ((f).ff_ftime>>11)&0x1F
394 | #define FINDDATA_T_WTIME_MIN(f) ((f).ff_ftime>>5)&0x3F
395 | static inline int findclose_f(long handle);
396 | static inline int findfirst_f(const char *pathname, finddata_t *ff, int attrib, long *handle)
397 | {
398 | int err = findfirst(pathname, ff, attrib);
399 | if (err)
400 | return err;
401 | if (attrib == FA_DIREC && FINDDATA_T_ATTRIB(*ff) != attrib) {
402 | findclose_f(ff->lfn_handle);
403 | return -1;
404 | }
405 | if (handle)
406 | *handle = ff->lfn_handle;
407 | return 0;
408 | }
409 | static inline int findnext_f(finddata_t *ff, long handle)
410 | {
411 | return findnext(ff);
412 | }
413 | static inline int findclose_f(long handle)
414 | {
415 | #ifdef HAVE_FINDCLOSE
416 | return findclose(handle);
417 | #else
418 | return 0;
419 | #endif
420 | }
421 | /* File attributes */
422 | static inline unsigned int setfileattr(const char *filename, unsigned int attr)
423 | {
424 | return _dos_setfileattr(filename, attr);
425 | }
426 | static inline unsigned int getfileattr(const char *filename, unsigned int *p_attr)
427 | {
428 | return _dos_getfileattr(filename, p_attr);
429 | }
430 | static inline int file_access(const char *filename, int flags)
431 | {
432 | return access(filename, flags);
433 | }
434 | static inline int file_copytime(int desc_handle, int src_handle)
435 | {
436 | int ret;
437 | struct ftime file_time;
438 | if ((ret = getftime(src_handle, &file_time)) == 0)
439 | ret = setftime(desc_handle, &file_time);
440 | return ret;
441 | }
442 | /* Disk free */
443 | static inline void setdrive(unsigned int drive, unsigned int *p_drives)
444 | {
445 | _dos_setdrive(drive, p_drives);
446 | }
447 | static inline void getdrive(unsigned int *p_drive)
448 | {
449 | _dos_getdrive(p_drive);
450 | }
451 | typedef struct dfree diskfree_t;
452 | #define DISKFREE_T_AVAIL(d) d.df_avail
453 | #define DISKFREE_T_TOTAL(d) d.df_total
454 | #define DISKFREE_T_BSEC(d) d.df_bsec
455 | #define DISKFREE_T_SCLUS(d) d.df_sclus
456 |
457 | static inline int get_segment_base_address(int selector, unsigned *addr)
458 | {
459 | #ifdef DJ64
460 | return __dpmi_get_segment_base_address(selector, addr);
461 | #else
462 | return __dpmi_get_segment_base_address(selector, (unsigned long *)addr);
463 | #endif
464 | }
465 |
466 | #endif
467 |
468 | struct built_in_cmd
469 | {
470 | const char *cmd_name;
471 | void (*cmd_fn)(const char *);
472 | const char *opts;
473 | const char *help;
474 | };
475 |
476 | extern struct built_in_cmd cmd_table[];
477 | extern const int CMD_TABLE_COUNT;
478 |
479 | unsigned short keyb_get_shift_states(void);
480 |
481 | #endif
482 |
--------------------------------------------------------------------------------
/src/compl.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * compl.c: command completion machinery
4 | * Copyright (C) 2024 @stsp
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include "command.h"
25 | #include "cmdbuf.h"
26 | #include "compl.h"
27 |
28 | struct compl_s {
29 | void *opaque;
30 | const char *(*get_name)(int idx, void *arg);
31 | int num;
32 | };
33 |
34 | #define MAX_COMPLS 10
35 | struct cmpl_s {
36 | int num;
37 | struct compl_s compls[MAX_COMPLS];
38 | };
39 |
40 | static int cmpstr(const char *s1, const char *s2)
41 | {
42 | int cnt = 0;
43 | while (s1[cnt] && s2[cnt] && s1[cnt] == s2[cnt])
44 | cnt++;
45 | return cnt;
46 | }
47 |
48 | static const char *get_cmd_name(int idx, void *arg)
49 | {
50 | struct built_in_cmd *cmd = arg;
51 | assert(idx < CMD_TABLE_COUNT);
52 | return cmd[idx].cmd_name;
53 | }
54 |
55 | static const char *get_fname(int idx, void *arg)
56 | {
57 | glob_t *gl = arg;
58 | assert(idx < gl->gl_pathc);
59 | return gl->gl_pathv[idx];
60 | }
61 |
62 | static const char *get_compl_name(int idx, void *arg)
63 | {
64 | struct cmpl_s *cmpl = arg;
65 | int i;
66 |
67 | for (i = 0; i < cmpl->num; i++) {
68 | struct compl_s *c = &cmpl->compls[i];
69 | if (idx >= c->num) {
70 | idx -= c->num;
71 | continue;
72 | }
73 | return c->get_name(idx, c->opaque);
74 | }
75 | return NULL;
76 | }
77 |
78 | static int do_compl(const char *prefix, int print, int *r_len,
79 | char *r_p, const char *(*get)(int idx, void *arg),
80 | void *arg, int num)
81 | {
82 | int i, cnt = 0, idx = -1, len = strlen(prefix);
83 | char suff[MAX_CMD_BUFLEN] = "";
84 |
85 | for (i = 0; i < num; i++) {
86 | const char *c = get(i, arg);
87 | /* Note: even though strncasecmp() is used, file-name completions
88 | * are still case-sensitive because the completion candidates are
89 | * added via glob() fn, which is case-sensitive. */
90 | if (strncasecmp(prefix, c, len) == 0) {
91 | const char *p = c + len;
92 | int l = cmpstr(p, suff);
93 |
94 | strcpy(suff, p);
95 | if (cnt)
96 | suff[l] = '\0';
97 | cnt++;
98 | idx = i;
99 | if (print)
100 | puts(c);
101 | }
102 | }
103 | if (cnt == 0)
104 | return -1;
105 | *r_len = strlen(suff);
106 | strcpy(r_p, get(idx, arg) + len);
107 | if (cnt == 1)
108 | return 1;
109 | return 0;
110 | }
111 |
112 | static void glb_add(struct cmpl_s *cmpl, glob_t *gl)
113 | {
114 | struct compl_s *c = &cmpl->compls[cmpl->num++];
115 |
116 | c->opaque = gl;
117 | c->get_name = get_fname;
118 | c->num = gl->gl_pathc;
119 | }
120 |
121 | int compl_cmds(const char *prefix, int print, int *r_len, char *r_p)
122 | {
123 | char buf[MAXPATH];
124 | struct cmpl_s cmpl = { };
125 | glob_t gl_bat, gl_exe, gl_com;
126 | int err, ret = -1, cnt = 0;
127 | const char *p;
128 | const char *suff = ((p = strchr(prefix, '.')) ? "" : "*.");
129 |
130 | if (p && p[1] != '\0')
131 | return compl_fname(prefix, print, r_len, r_p);
132 | snprintf(buf, MAXPATH, "%s%sbat", prefix, suff);
133 | err = glob(buf, GLOB_ERR, NULL, &gl_bat);
134 | if (err && err != GLOB_NOMATCH)
135 | return -1;
136 | if (!err) {
137 | glb_add(&cmpl, &gl_bat);
138 | cnt += gl_bat.gl_pathc;
139 | }
140 | snprintf(buf, MAXPATH, "%s%sexe", prefix, suff);
141 | err = glob(buf, GLOB_ERR, NULL, &gl_exe);
142 | if (err && err != GLOB_NOMATCH)
143 | goto err1;
144 | if (!err) {
145 | glb_add(&cmpl, &gl_exe);
146 | cnt += gl_exe.gl_pathc;
147 | }
148 | snprintf(buf, MAXPATH, "%s%scom", prefix, suff);
149 | err = glob(buf, GLOB_ERR, NULL, &gl_com);
150 | if (err && err != GLOB_NOMATCH)
151 | goto err2;
152 | if (!err) {
153 | glb_add(&cmpl, &gl_com);
154 | cnt += gl_com.gl_pathc;
155 | }
156 |
157 | if (!p) {
158 | cmpl.compls[cmpl.num].opaque = cmd_table;
159 | cmpl.compls[cmpl.num].get_name = get_cmd_name;
160 | cmpl.compls[cmpl.num].num = CMD_TABLE_COUNT;
161 | cmpl.num++;
162 | cnt += CMD_TABLE_COUNT;
163 | }
164 |
165 | ret = do_compl(prefix, print, r_len, r_p, get_compl_name, &cmpl, cnt);
166 |
167 | globfree(&gl_com);
168 | err2:
169 | globfree(&gl_exe);
170 | err1:
171 | globfree(&gl_bat);
172 |
173 | return ret;
174 | }
175 |
176 | int compl_fname(const char *prefix, int print, int *r_len, char *r_p)
177 | {
178 | char buf[MAXPATH];
179 | glob_t gl;
180 | int err, ret;
181 |
182 | snprintf(buf, MAXPATH, "%s*", prefix);
183 | err = glob(buf, GLOB_ERR, NULL, &gl);
184 | if (err) {
185 | /* Try simplest case-insensitive match against all-upcased.
186 | * There can be quake and Quake and QuAkE dirs simultaneously
187 | * and we aren't going to iterate those. */
188 | strupr(buf);
189 | err = glob(buf, GLOB_ERR, NULL, &gl);
190 | }
191 | if (err)
192 | return -1;
193 | ret = do_compl(prefix, print, r_len, r_p, get_fname, &gl, gl.gl_pathc);
194 | globfree(&gl);
195 | return ret;
196 | }
197 |
--------------------------------------------------------------------------------
/src/compl.h:
--------------------------------------------------------------------------------
1 | #ifndef COMPL_H
2 | #define COMPL_H
3 |
4 | int compl_cmds(const char *prefix, int print, int *r_len, char *r_p);
5 | int compl_fname(const char *prefix, int print, int *r_len, char *r_p);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/src/env.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * env.c: environment handling routines
4 | * Copyright (C) 2023-2024 @stsp
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #ifdef DJ64
24 | #include
25 | #else
26 | #include "fmemcpy.h"
27 | #include "memmem.h"
28 | #endif
29 | #include
30 | #include
31 | #include "command.h"
32 | #include "umb.h"
33 | #include "env.h"
34 |
35 | #define DP(s, o) (__dpmi_paddr){ .selector = s, .offset32 = o, }
36 |
37 | extern char **environ;
38 |
39 | static unsigned short env_selector;
40 | static unsigned short env_segment;
41 | static unsigned short env_size;
42 |
43 | struct MCB {
44 | char id; /* 0 */
45 | unsigned short owner_psp; /* 1 */
46 | unsigned short size; /* 3 */
47 | char align8[3]; /* 5 */
48 | char name[8]; /* 8 */
49 | } __attribute__((packed));
50 |
51 | void set_env_seg(void)
52 | {
53 | unsigned short psp = _stubinfo->psp_selector;
54 | fmemcpy1(DP(psp, 0x2c), &env_segment, 2);
55 | }
56 |
57 | void set_env_sel(void)
58 | {
59 | unsigned short psp = _stubinfo->psp_selector;
60 | fmemcpy1(DP(psp, 0x2c), &env_selector, 2);
61 | }
62 |
63 | void set_env_size(void)
64 | {
65 | unsigned short psp = _stubinfo->psp_selector;
66 | unsigned short env_sel;
67 | unsigned env_addr;
68 | struct MCB mcb;
69 | unsigned old_env_size;
70 | int err;
71 |
72 | fmemcpy2(&env_sel, DP(psp, 0x2c), 2);
73 | err = get_segment_base_address(env_sel, &env_addr);
74 | old_env_size = __dpmi_get_segment_limit(env_sel) + 1;
75 | env_size = old_env_size;
76 | if (!err && !(env_addr & 0xf) && env_addr < 0x110000 && old_env_size == 0x10000) {
77 | dosmemget(env_addr - sizeof(mcb), sizeof(mcb), &mcb);
78 | env_size = mcb.size * 16;
79 | __dpmi_set_segment_limit(env_sel, env_size - 1);
80 | }
81 |
82 | env_selector = env_sel;
83 | env_segment = env_addr >> 4;
84 | }
85 |
86 | void get_env(void)
87 | {
88 | char *dos_environ = alloca(env_size);
89 | char *cp;
90 |
91 | fmemcpy2(dos_environ, DP(env_selector, 0), env_size);
92 | dos_environ[env_size] = 0;
93 | cp = dos_environ;
94 | do {
95 | if (*cp) {
96 | char *env = strdup(cp);
97 | putenv(env);
98 | cp += strlen(env);
99 | }
100 | cp++; /* skip to next character */
101 | } while (*cp); /* repeat until two NULs */
102 | }
103 |
104 | /* this function replaces RM env (pointed to with env_sel) with
105 | * PM env (environ[]), leaving tail intact */
106 | static void _put_env(unsigned short env_sel)
107 | {
108 | int env_count;
109 | int env_offs = 0;
110 | char *env;
111 | char *tail;
112 | int tail_sz = 3;
113 |
114 | env = alloca(env_size + tail_sz);
115 | /* back up full env, just for getting its tail */
116 | fmemcpy2(env, DP(env_sel, 0), env_size);
117 | memset(&env[env_size], 0, tail_sz);
118 | tail = memchr(env, 1, env_size);
119 | if (tail && tail[1] == '\0') {
120 | tail_sz += strlen(tail + 2) + 1;
121 | tail--;
122 | } else {
123 | tail = memmem(env, env_size, "\x0\x0", 2);
124 | if (!tail) {
125 | printf("ENV block corrupted\n");
126 | return;
127 | }
128 | tail++;
129 | if (tail - env + tail_sz > env_size || memcmp(tail, "\x0\x0\x0", 3) != 0)
130 | tail_sz = 1; /* DOS-2.0 terminator */
131 | }
132 | /* now put entire environ[] down, overwriting prev content */
133 | for (env_count = 0; environ[env_count]; env_count++) {
134 | int l = strlen(environ[env_count]) + 1;
135 | if (env_offs + l >= env_size - tail_sz) {
136 | printf("ENV buffer overflow (size %u, need %u, tail %i)\n",
137 | env_size, env_offs + l, tail_sz);
138 | break;
139 | }
140 | fmemcpy1(DP(env_sel, env_offs), environ[env_count], l);
141 | env_offs += l;
142 | }
143 | /* and preserve tail */
144 | if (env_offs + tail_sz <= env_size)
145 | fmemcpy1(DP(env_sel, env_offs), tail, tail_sz);
146 | }
147 |
148 | void put_env(void)
149 | {
150 | _put_env(env_selector);
151 | }
152 |
153 | #if !SYNC_ENV
154 | static void _set_env(const char *variable, const char *value,
155 | unsigned short env_sel, unsigned env_size)
156 | {
157 | char *env;
158 | char *tail;
159 | char *cp;
160 | char *env2;
161 | int l;
162 | int len;
163 | int tail_sz = 3;
164 |
165 | /* allocate tmp buffer for env and copy them there */
166 | env = alloca(env_size + tail_sz);
167 | fmemcpy2(env, DP(env_sel, 0), env_size);
168 | memset(&env[env_size], 0, tail_sz);
169 | cp = env2 = env;
170 | l = strlen(variable);
171 | /*
172 | Delete any existing variable with the name (var).
173 | */
174 | while (*env2 && (env2 - env) < env_size) {
175 | if ((strncmp(variable, env2, l) == 0) && (env2[l] == '=')) {
176 | cp = env2 + strlen(env2) + 1;
177 | memmove(env2, cp, env_size - (cp - env));
178 | } else {
179 | env2 += strlen(env2) + 1;
180 | }
181 | }
182 |
183 | tail = env2;
184 | cp = tail + 1;
185 | if (cp[0] == '\1' && cp[1] == '\0')
186 | tail_sz += strlen(cp + 2) + 1;
187 |
188 | /*
189 | If the variable fits, shovel it in at the end of the envrionment.
190 | */
191 | len = l + (value ? strlen(value) : 0) + 2;
192 | if (value && value[0] && (env_size - (env2 - env) - tail_sz >= len)) {
193 | memmove(env2 + len, env2, tail_sz);
194 | strcpy(env2, variable);
195 | strcat(env2, "=");
196 | strcat(env2, value);
197 | }
198 |
199 | /* now put it back */
200 | fmemcpy1(DP(env_sel, 0), env, env_size);
201 | }
202 |
203 | void set_env(const char *variable, const char *value)
204 | {
205 | _set_env(variable, value, env_selector, env_size);
206 | }
207 |
208 | void sync_env(void)
209 | {
210 | unsigned short sel;
211 | unsigned short psp = _stubinfo->psp_selector;
212 | fmemcpy2(&sel, DP(psp, 0x2c), 2);
213 | _put_env(sel);
214 | }
215 | #endif
216 |
217 | int realloc_env(unsigned new_size)
218 | {
219 | int seg, sel;
220 | unsigned int old_size = env_size;
221 |
222 | link_umb(0x80);
223 | seg = __dpmi_allocate_dos_memory(new_size >> 4, &sel);
224 | unlink_umb();
225 | if (seg != -1) {
226 | unsigned short psp = _stubinfo->psp_selector;
227 | fmemcpy1(DP(psp, 0x2c), &sel, 2);
228 | /* copy old content to preserve tail (and maybe COMSPEC) */
229 | fmemcpy12(DP(sel, 0), DP(env_selector, 0), old_size);
230 | __dpmi_free_dos_memory(env_selector);
231 | env_selector = sel;
232 | env_segment = seg;
233 | env_size = new_size;
234 | } else {
235 | printf("ERROR: env allocation of %i bytes failed!\n", env_size);
236 | return -1;
237 | }
238 | return 0;
239 | }
240 |
241 | int get_env_size(void)
242 | {
243 | return env_size;
244 | }
245 |
--------------------------------------------------------------------------------
/src/env.h:
--------------------------------------------------------------------------------
1 | #ifndef ENV_H
2 | #define ENV_H
3 |
4 | /* define to sync RM/PM env data - consumes more memory */
5 | #define SYNC_ENV 0
6 |
7 | void set_env_seg(void);
8 | void set_env_sel(void);
9 | void set_env_size(void);
10 | void get_env(void);
11 | void put_env(void);
12 | #if !SYNC_ENV
13 | void set_env(const char *variable, const char *value);
14 | void sync_env(void);
15 | #endif
16 | int realloc_env(unsigned new_size);
17 | int get_env_size(void);
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/src/glob_asm.h:
--------------------------------------------------------------------------------
1 | __ASM(unsigned short, _ds) SEMIC
2 | __ASM_FUNC(my_int23_handler) SEMIC
3 | __ASM_FUNC(my_int0_handler) SEMIC
4 | __ASM_FUNC(my_mouse_handler) SEMIC
5 | __ASM(unsigned int, _prev0_eip) SEMIC
6 | __ASM(unsigned short, _prev0_cs) SEMIC
7 |
--------------------------------------------------------------------------------
/src/int0.S:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * Copyright (C) 2023-2024 @stsp
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "asm.h"
20 | .include "asm.inc"
21 |
22 | .bss
23 | .balign 2
24 | __prev0:
25 | .global __prev0_eip
26 | __prev0_eip: .long 0
27 | .global __prev0_cs
28 | __prev0_cs: .word 0
29 |
30 | .text
31 | .global _my_int0_handler
32 | _my_int0_handler:
33 | pusha
34 | handler_prolog SIGSTK_LEN
35 | call _do_int0
36 | restore_stack
37 | popa
38 | ljmpl *__prev0
39 |
40 | #ifdef __ELF__
41 | .section .note.GNU-stack,"",%progbits
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/int23.S:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * Copyright (C) 2023-2024 @stsp
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "asm.h"
20 | .include "asm.inc"
21 |
22 | .text
23 | .global _my_int23_handler
24 | _my_int23_handler:
25 | pusha
26 | handler_prolog SIGSTK_LEN
27 | call _do_int23
28 | restore_stack
29 |
30 | or %eax, %eax
31 | jnz 1f
32 | popa
33 | iret
34 | 1:
35 | popa
36 | stc
37 | lretl
38 |
39 | #ifdef __ELF__
40 | .section .note.GNU-stack,"",%progbits
41 | #endif
42 |
--------------------------------------------------------------------------------
/src/link.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | die() {
4 | echo "$1"
5 | exit 1
6 | }
7 |
8 | LNK=$1
9 | shift
10 | L=$1
11 | shift
12 | D=$1
13 | shift
14 | O=$1
15 | shift
16 |
17 | OD=`which objdump 2>/dev/null`
18 | [ -n "$OD" ] || OD=`which llvm-objdump 2>/dev/null`
19 | [ -n "$OD" ] || die "objdump not found"
20 |
21 | FLG=$($OD -T $L | grep _shm_flags | sed -E 's/0*([^ ]+) .+/0x\1/')
22 | CMD="$LNK -d $D $L -f $FLG -o $O $*"
23 | echo $CMD
24 | $CMD
25 |
--------------------------------------------------------------------------------
/src/meson.build:
--------------------------------------------------------------------------------
1 | tg = dependency('thunk_gen')
2 | TG = tg.get_variable(pkgconfig: 'binary')
3 | PD = tg.get_variable(pkgconfig: 'pdscript')
4 | TFLAGS = ['-a', '4', '-p', '4']
5 | TARGET = 'comcom64'
6 | CMD = TARGET + '.exe'
7 | DBG = CMD + '.dbg'
8 |
9 | CFILES = [
10 | 'cmdbuf.c',
11 | 'command.c',
12 | 'ms.c',
13 | 'env.c',
14 | 'psp.c',
15 | 'umb.c',
16 | 'ae0x.c',
17 | 'compl.c',
18 | 'thunks_a.c',
19 | 'thunks_c.c'
20 | ]
21 |
22 | GEN_TMP = { '1':'thunk_calls.tmp' }
23 |
24 | tct = custom_target('thunk_calls.tmp',
25 | output: 'thunk_calls.tmp',
26 | input: 'asm.h',
27 | command: [PD, '1', '@INPUT@'],
28 | capture: true)
29 | plt_inc = custom_target('plt.inc',
30 | output: 'plt.inc',
31 | input: tct,
32 | command: [PD, '3', '@INPUT@'],
33 | capture: true)
34 | libdj = dependency('dj64')
35 | cpp = meson.get_compiler('c')
36 | sfiles = cpp.preprocess(['plt.S'],
37 | output: '@BASENAME@.s',
38 | depends: plt_inc,
39 | dependencies: libdj,
40 | compile_args: ['-D__ASSEMBLER__'])
41 |
42 | env = environment()
43 | env.set('CPP', 'cpp')
44 | env.set('srcdir', meson.current_source_dir() / 'parsers')
45 | pd = find_program(PD)
46 | gtgen = generator(pd,
47 | arguments: ['@EXTRA_ARGS@', '@INPUT@'],
48 | output: '@BASENAME@.tmp',
49 | capture: true)
50 | gt = []
51 | foreach n: GEN_TMP.keys()
52 | gt += gtgen.process('asm.h',
53 | extra_args: n,
54 | env: ['CPP=cpp', 'srcdir=' + meson.current_source_dir() / 'parsers'])
55 | endforeach
56 | GEN = { GEN_TMP['1']:gt[0] }
57 |
58 | tc = custom_target('thunk_calls.h',
59 | output: 'thunk_calls.h',
60 | input: GEN['thunk_calls.tmp'],
61 | command: [TG, TFLAGS],
62 | feed: true,
63 | capture: true)
64 |
65 | r = run_command(find_program('git'), 'describe', '--dirty=+', check: true)
66 | REVISIONID = r.stdout().strip()
67 | libcc64 = shared_library('comcom64', [CFILES],
68 | sources: [tc],
69 | c_args: ['-DREV_ID="' + REVISIONID + '"'],
70 | dependencies: libdj,
71 | link_args: ['-Wl,-Bsymbolic', '-Wl,-rpath=/usr/local/i386-pc-dj64/lib64',
72 | '-Wl,-rpath=/usr/i386-pc-dj64/lib64'],
73 | # build_rpath: ['/usr/local/i386-pc-dj64/lib64', '/usr/i386-pc-dj64/lib64']
74 | )
75 |
76 | ASFILES = [ 'int23.S', 'int0.S', 'mouse.S', 'asm.S', sfiles ]
77 | lib = static_library('dummy', ASFILES,
78 | build_by_default: false)
79 |
80 | nasm_ld = find_program(['i686-linux-gnu-ld', 'i386-elf-ld',
81 | 'x86_64-linux-gnu-ld', 'ld'], native: true)
82 | libdjs = dependency('dj64static', static: true)
83 | elf = custom_target(TARGET + '.elf',
84 | output: [TARGET + '.elf', TARGET + '.map'],
85 | input: [lib.extract_all_objects(recursive: true),
86 | # libdjs.args(link_args: true)],
87 | '/usr/local/i386-pc-dj64/lib/libc.a'],
88 | command: [nasm_ld, '-melf_i386', '-static', '--whole-archive',
89 | '-Map=@OUTPUT1@', '-o', '@OUTPUT0@', '@INPUT@'])
90 |
91 | strip = find_program(['i686-linux-gnu-strip', 'i386-elf-strip',
92 | 'x86_64-linux-gnu-strip', 'strip'], native: true)
93 | elf_s = custom_target('elf.stripped',
94 | output: '@PLAINNAME@.stripped',
95 | input: elf[0],
96 | command: [strip,
97 | '--strip-debug', '-o', '@OUTPUT0@', '@INPUT@'])
98 |
99 | link = find_program('djlink')
100 | ccexe = custom_target(CMD,
101 | output: CMD,
102 | input: [elf_s, libcc64],
103 | command: [find_program('link.sh'),
104 | link, elf_s, libcc64, DBG, '@OUTPUT0@' ],
105 | install: true,
106 | install_dir: get_option('datadir') / TARGET,
107 | install_mode: 'rw-r--r--')
108 |
109 | install_symlink('command.com',
110 | pointing_to: CMD,
111 | install_dir: get_option('datadir') / TARGET)
112 |
--------------------------------------------------------------------------------
/src/mouse.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * Copyright (C) 2023-2024 @stsp
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include "asm.h"
26 | #include "command.h"
27 | #include "mouse.h"
28 |
29 | #define CF 1
30 |
31 | #ifdef DJ64
32 | static unsigned int mouse_regs;
33 | #else
34 | static __dpmi_regs *mouse_regs;
35 | #endif
36 |
37 | static __dpmi_raddr newm;
38 | static __dpmi_raddr oldm;
39 | static unsigned old_mask;
40 | #define MEV_MASK 0xab
41 |
42 | static unsigned short popw(__dpmi_regs *r)
43 | {
44 | unsigned lina = (r->x.ss << 4) + r->x.sp;
45 | unsigned short ret = _farpeekw(_dos_ds, lina);
46 | r->x.sp += 2;
47 | return ret;
48 | }
49 |
50 | static void do_retf(__dpmi_regs *r)
51 | {
52 | r->x.ip = popw(r);
53 | r->x.cs = popw(r);
54 | }
55 |
56 | static void mvxl(int d)
57 | {
58 | __dpmi_regs r = { };
59 |
60 | while (d--) {
61 | r.x.ax = 0x500;
62 | r.x.cx = 0x4BE0;
63 | __dpmi_int(0x16, &r);
64 | }
65 | }
66 |
67 | static void mvxr(int d)
68 | {
69 | __dpmi_regs r = { };
70 |
71 | while (d--) {
72 | r.x.ax = 0x500;
73 | r.x.cx = 0x4DE0;
74 | __dpmi_int(0x16, &r);
75 | }
76 | }
77 |
78 | static void mlb(int alt_fn, int x, int y)
79 | {
80 | __dpmi_regs r = { };
81 | short c;
82 | int shift = keyb_get_shift_states();
83 |
84 | if (alt_fn) {
85 | int cx = wherex();
86 | if (cx == x)
87 | return;
88 | if (x < cx)
89 | mvxl(cx - x);
90 | else
91 | mvxr(x - cx);
92 | return;
93 | }
94 | if (!(shift & KEYB_FLAG_CTRL))
95 | return;
96 |
97 | _conio_gettext(x, y, x, y, &c);
98 |
99 | r.x.ax = 0x500;
100 | r.x.cx = c & 0xff;
101 | __dpmi_int(0x16, &r);
102 | }
103 |
104 | static void mrb(int alt_fn)
105 | {
106 | __dpmi_regs r = { };
107 |
108 | r.x.ax = 0x500;
109 | r.x.cx = alt_fn ? 0x3 : 0x0F09; // ^C or TAB
110 | __dpmi_int(0x16, &r);
111 | }
112 |
113 | static void mmb(int alt_fn)
114 | {
115 | __dpmi_regs r = { };
116 |
117 | r.x.ax = 0x500;
118 | r.x.cx = alt_fn ? 0x0E08 : 0x1c0d; // BkSp or ENTER
119 | __dpmi_int(0x16, &r);
120 | }
121 |
122 | static void mw(int delta)
123 | {
124 | __dpmi_regs r = { };
125 |
126 | r.x.ax = 0x500;
127 | if (delta < 0)
128 | r.x.cx = 0x48E0; // UP
129 | else
130 | r.x.cx = 0x50E0; // DOWN
131 | __dpmi_int(0x16, &r);
132 | }
133 |
134 | void do_mouse(void)
135 | {
136 | __dpmi_regs *r;
137 | unsigned char rows = wherey();
138 | static unsigned char prev_col, prev_row;
139 | unsigned char col, row;
140 | int dragged;
141 |
142 | #ifdef DJ64
143 | r = (__dpmi_regs *) DATA_PTR(mouse_regs);
144 | #else
145 | r = mouse_regs;
146 | #endif
147 | do_retf(r);
148 |
149 | col = r->x.cx / 8 + 1;
150 | row = r->x.dx / 8 + 1;
151 | dragged = (r->x.ax & r->x.bx & 1) && (col != prev_col
152 | || row != prev_row);
153 |
154 | if ((r->x.ax & 2) || dragged)
155 | mlb(row == rows, col, row);
156 | if (r->x.ax & 8)
157 | mrb(row == rows);
158 | if (r->x.ax & 0x20)
159 | mmb(row == rows);
160 | if (r->x.ax & 0x80)
161 | mw((char) r->h.bh);
162 |
163 | prev_col = r->x.cx / 8 + 1;
164 | prev_row = r->x.dx / 8 + 1;
165 | }
166 |
167 | int mouse_init(void)
168 | {
169 | __dpmi_regs r = { };
170 |
171 | __dpmi_int(0x33, &r);
172 | if ((r.x.flags & CF) || r.x.ax != 0xffff || r.x.bx != 3) {
173 | puts("mouse not detected");
174 | return 0;
175 | }
176 | /* check the wheel */
177 | r.x.ax = 0x11;
178 | __dpmi_int(0x33, &r);
179 | if ((r.x.flags & CF) || r.x.ax != 0x574d || (r.x.cx & 1) == 0) {
180 | puts("mouse wheel not supported");
181 | // return 0;
182 | }
183 |
184 | #ifdef DJ64
185 | mouse_regs = malloc32(sizeof(__dpmi_regs));
186 | #else
187 | mouse_regs = (__dpmi_regs *) malloc(sizeof(__dpmi_regs));
188 | #endif
189 | __dpmi_allocate_real_mode_callback(my_mouse_handler, mouse_regs,
190 | &newm);
191 | r.x.ax = 0x14;
192 | r.x.cx = MEV_MASK;
193 | r.x.es = newm.segment;
194 | r.x.dx = newm.offset16;
195 | __dpmi_int(0x33, &r);
196 | oldm.segment = r.x.es;
197 | oldm.offset16 = r.x.dx;
198 | old_mask = r.x.cx;
199 |
200 | mouse_show();
201 | return 1;
202 | }
203 |
204 | void mouse_enable(void)
205 | {
206 | __dpmi_regs r = { };
207 |
208 | __dpmi_int(0x33, &r); // reset the visibility counter
209 | if ((r.x.flags & CF) || r.x.ax != 0xffff || r.x.bx != 3) {
210 | puts("mouse not detected");
211 | return;
212 | }
213 |
214 | r.x.ax = 0x0c;
215 | r.x.cx = MEV_MASK;
216 | r.x.es = newm.segment;
217 | r.x.dx = newm.offset16;
218 | __dpmi_int(0x33, &r);
219 |
220 | mouse_show();
221 | }
222 |
223 | void mouse_disable(void)
224 | {
225 | __dpmi_regs r = { };
226 |
227 | mouse_hide();
228 |
229 | r.x.ax = 0x0c;
230 | r.x.cx = old_mask;
231 | r.x.es = oldm.segment;
232 | r.x.dx = oldm.offset16;
233 | __dpmi_int(0x33, &r);
234 | }
235 |
236 | void mouse_done(void)
237 | {
238 | mouse_disable();
239 | __dpmi_free_real_mode_callback(&newm);
240 | #ifdef DJ64
241 | free32(mouse_regs);
242 | #else
243 | free(mouse_regs);
244 | #endif
245 | }
246 |
247 | void mouse_show(void)
248 | {
249 | __dpmi_regs r = { };
250 |
251 | r.x.ax = 1;
252 | __dpmi_int(0x33, &r);
253 | }
254 |
255 | void mouse_hide(void)
256 | {
257 | __dpmi_regs r = { };
258 |
259 | r.x.ax = 2;
260 | __dpmi_int(0x33, &r);
261 | }
262 |
--------------------------------------------------------------------------------
/src/mouse.h:
--------------------------------------------------------------------------------
1 | #ifndef MS_H
2 | #define MS_H
3 |
4 | int mouse_init(void);
5 | void mouse_enable(void);
6 | void mouse_disable(void);
7 | void mouse_done(void);
8 | void mouse_show(void);
9 | void mouse_hide(void);
10 |
11 | #endif
12 |
--------------------------------------------------------------------------------
/src/ms.S:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * Copyright (C) 2023-2024 @stsp
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #include "asm.h"
20 | .include "asm.inc"
21 |
22 | .text
23 | .global _my_mouse_handler
24 | _my_mouse_handler:
25 | pusha
26 | handler_prolog SIGSTK_LEN
27 | call _do_mouse
28 | restore_stack
29 | popa
30 | iretl
31 |
32 | #ifdef __ELF__
33 | .section .note.GNU-stack,"",%progbits
34 | #endif
35 |
--------------------------------------------------------------------------------
/src/psp.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * psp.c: PSP handling routines
4 | * Copyright (C) 2023-2024 @stsp
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include "command.h"
23 | #include "psp.h"
24 |
25 | static unsigned psp_addr;
26 | static unsigned short orig_psp_seg;
27 |
28 | void set_psp_parent(void)
29 | {
30 | unsigned short psp = _stubinfo->psp_selector;
31 | unsigned short psp_seg;
32 | int err;
33 |
34 | err = get_segment_base_address(psp, &psp_addr);
35 | if (!err && !(psp_addr & 0xf) && psp_addr < 0x110000) {
36 | psp_seg = psp_addr >> 4;
37 | dosmemget(psp_addr + 0x16, 2, &orig_psp_seg);
38 | dosmemput(&psp_seg, 2, psp_addr + 0x16);
39 | }
40 | }
41 |
42 | void restore_psp_parent(void)
43 | {
44 | dosmemput(&orig_psp_seg, 2, psp_addr + 0x16);
45 | }
46 |
--------------------------------------------------------------------------------
/src/psp.h:
--------------------------------------------------------------------------------
1 | #ifndef PSP_H
2 | #define PSP_H
3 |
4 | void set_psp_parent(void);
5 | void restore_psp_parent(void);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------
/src/thunks_a.c:
--------------------------------------------------------------------------------
1 | #include
2 |
--------------------------------------------------------------------------------
/src/thunks_c.c:
--------------------------------------------------------------------------------
1 | #include "asm.h"
2 | #include
3 |
--------------------------------------------------------------------------------
/src/toolchain.ini:
--------------------------------------------------------------------------------
1 | [binaries]
2 | c = 'dj64-gcc'
3 | strip = 'djstrip'
4 | pkg-config = 'pkg-config'
5 |
--------------------------------------------------------------------------------
/src/umb.c:
--------------------------------------------------------------------------------
1 | /*
2 | * comcom64 - 64bit command.com
3 | * umb.c: UMB handling routines
4 | * Copyright (C) 2023-2024 @stsp
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #include
21 | #include "umb.h"
22 |
23 | void link_umb(unsigned char strat)
24 | {
25 | __dpmi_regs r = {};
26 | r.x.ax = 0x5803;
27 | r.x.bx = 1;
28 | __dpmi_int(0x21, &r);
29 | r.x.ax = 0x5801;
30 | r.x.bx = strat;
31 | __dpmi_int(0x21, &r);
32 | }
33 |
34 | void unlink_umb(void)
35 | {
36 | __dpmi_regs r = {};
37 | r.x.ax = 0x5803;
38 | r.x.bx = 0;
39 | __dpmi_int(0x21, &r);
40 | r.x.ax = 0x5801;
41 | r.x.bx = 0;
42 | __dpmi_int(0x21, &r);
43 | }
44 |
--------------------------------------------------------------------------------
/src/umb.h:
--------------------------------------------------------------------------------
1 | #ifndef UMB_H
2 | #define UMB_H
3 |
4 | void link_umb(unsigned char strat);
5 | void unlink_umb(void);
6 |
7 | #endif
8 |
--------------------------------------------------------------------------------