mirror of
https://github.com/D-Modem/gui.git
synced 2026-11-28 14:19:58 -08:00
Windows: build the modem into the app (Windows 98 SE and Windows 7)
- windows/: the target is now dmodem-app (output dmodem.exe), because D-Modem has a target dmodem. The app links dmodem_embed when it exists. - The app starts the built-in modem for the dmodemd line when builtin=1 (default). The DTE socket goes to WSAAsyncSelect as a TCP socket does. - CMakeLists.txt: get _WIN32_WINNT from the clang-retro config and include dmodem_retro.h for C++ files only. - ssh: build gai_strerror.c for the win98 and winme configs, because the gai_strerrorA of ws2_32 imports FormatMessageW. - CI: a new windows-98 job; the win7 job gets the submodule. The nightly release takes dmodem-win98.exe. - Docs: Windows in docs/embedded-modem.md, README.md, docs/building.md and docs/design.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTRNP9YEnRxydbrw9G
This commit is contained in:
15 files changed
+356
-53
No files matched your search
@@ -105,11 +105,41 @@ jobs:
|
||||
name: dmodem-windows-9x
|
||||
path: build/win9x/windows/dmodem.exe
|
||||
|
||||
# The app with the modem built in (external/D-Modem): Windows 98 SE,
|
||||
# ME, 2000 and later. The modem needs msvcrt and libc++, which the
|
||||
# Windows 95 build above (picolibc) does not have.
|
||||
windows-98:
|
||||
name: Windows 98 SE and later, the modem built in (clang-retro, win98)
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main
|
||||
id: clang-dos
|
||||
- name: Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends ninja-build
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -S . -B build/win98 -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake -DCLANG_RETRO_CONFIG=win98
|
||||
cmake --build build/win98
|
||||
- name: Imports (Windows 98 SE)
|
||||
run: python3 "$CLANG_DOS/share/clang-dos/check-imports.py" build/win98/windows/dmodem.exe
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dmodem-windows-98
|
||||
path: build/win98/windows/dmodem.exe
|
||||
|
||||
windows:
|
||||
name: Windows 7 and later (clang-retro)
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: clang-retro/dos-sdk/.github/actions/setup-toolchain@main
|
||||
id: clang-dos
|
||||
- name: Packages
|
||||
|
||||
@@ -62,6 +62,7 @@ jobs:
|
||||
if [ -f "dl/$1/$2" ]; then cp "dl/$1/$2" "out/${3:-$2}"; else echo "- \`${3:-$2}\`" >> missing; fi
|
||||
}
|
||||
take dmodem-windows-9x dmodem.exe dmodem-win9x.exe
|
||||
take dmodem-windows-98 dmodem.exe dmodem-win98.exe
|
||||
take dmodem-windows dmodem.exe dmodem-win7.exe
|
||||
take dmodem-linux dmodem-gui-linux-x86_64.tar.gz
|
||||
take dmodem-macos D-Modem-macos.zip
|
||||
@@ -75,8 +76,9 @@ jobs:
|
||||
echo
|
||||
echo "| File | What it is |"
|
||||
echo "| --- | --- |"
|
||||
echo "| \`dmodem-win9x.exe\` | The Windows app for Windows 95, 98, ME, NT 4.0 and later |"
|
||||
echo "| \`dmodem-win7.exe\` | The Windows app for Windows 7 and later |"
|
||||
echo "| \`dmodem-win9x.exe\` | The Windows app for Windows 95, 98, ME, NT 4.0 and later. It needs a modem that runs (dmodemd, or a COM port) |"
|
||||
echo "| \`dmodem-win98.exe\` | The Windows app with the modem built in, for Windows 98 SE, ME, 2000 and later |"
|
||||
echo "| \`dmodem-win7.exe\` | The Windows app for Windows 7 and later, with the modem built in |"
|
||||
echo "| \`dmodem-gui-linux-x86_64.tar.gz\` | The Linux app (GTK 4), x86_64. It needs GTK 4, libadwaita, PulseAudio and libsndfile. Its files are in \`usr/\`: extract it into \`/\`, for example with \`sudo tar -xzf dmodem-gui-linux-x86_64.tar.gz -C /\` |"
|
||||
echo "| \`D-Modem-macos.zip\` | The macOS app (SwiftUI), arm64 and x86_64, macOS 13 and later. Not notarized: right-click the app and select Open |"
|
||||
echo "| \`dmodem-win32-linux-x86_64.tar.gz\` | The Windows app on Linux (X11), x86_64 |"
|
||||
|
||||
+45
-9
@@ -4,9 +4,9 @@
|
||||
# The macOS app (macos/) builds with Xcode and takes the core from here.
|
||||
# With DMODEM_GUI_WINPORT, the Windows app also builds for Linux and
|
||||
# macOS, over clang-retro MFC's portable Win32 layer (winport/).
|
||||
# With DMODEM_GUI_EMBED, the Linux app has the modem in it
|
||||
# (libdmodem_embed from the D-Modem submodule, external/D-Modem): it
|
||||
# needs no dmodemd.
|
||||
# With DMODEM_GUI_EMBED, the Linux app and the Windows app (Windows 98
|
||||
# SE and later) have the modem in them (libdmodem_embed from the D-Modem
|
||||
# submodule, external/D-Modem): they need no dmodemd.
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(dmodem-gui VERSION 1.0.0 LANGUAGES C)
|
||||
|
||||
@@ -22,14 +22,20 @@ set(CLANG_RETRO_MFC "" CACHE PATH "A clang-retro MFC checkout, for DMODEM_GUI_WI
|
||||
# submodule is there (git submodule update --init)
|
||||
set(DMODEM_GUI_DMODEM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/D-Modem
|
||||
CACHE PATH "The D-Modem tree, for DMODEM_GUI_EMBED")
|
||||
if(EXISTS ${DMODEM_GUI_DMODEM_DIR}/CMakeLists.txt AND UNIX AND NOT APPLE)
|
||||
set(_embed_default ON)
|
||||
else()
|
||||
set(_embed_default OFF)
|
||||
# and the Windows app for Windows 98 SE and later: the modem is C++17 on
|
||||
# msvcrt and libc++, which the Windows 95 build (picolibc, no C++
|
||||
# library) does not have
|
||||
set(_embed_default OFF)
|
||||
if(EXISTS ${DMODEM_GUI_DMODEM_DIR}/CMakeLists.txt)
|
||||
if(UNIX AND NOT APPLE AND DMODEM_GUI_LINUX AND NOT DMODEM_GUI_WINPORT)
|
||||
set(_embed_default ON)
|
||||
elseif(WIN32 AND NOT CLANG_RETRO_CONFIG MATCHES "picolibc")
|
||||
set(_embed_default ON)
|
||||
endif()
|
||||
endif()
|
||||
option(DMODEM_GUI_EMBED "Build the modem into the Linux app (libdmodem_embed)"
|
||||
option(DMODEM_GUI_EMBED "Build the modem into the app (libdmodem_embed)"
|
||||
${_embed_default})
|
||||
if(DMODEM_GUI_EMBED AND DMODEM_GUI_LINUX)
|
||||
if(DMODEM_GUI_EMBED AND (WIN32 OR DMODEM_GUI_LINUX))
|
||||
if(NOT EXISTS ${DMODEM_GUI_DMODEM_DIR}/CMakeLists.txt)
|
||||
message(FATAL_ERROR "DMODEM_GUI_EMBED: no D-Modem in "
|
||||
"${DMODEM_GUI_DMODEM_DIR} (git submodule update --init)")
|
||||
@@ -42,7 +48,37 @@ if(DMODEM_GUI_EMBED AND DMODEM_GUI_LINUX)
|
||||
set(DMODEM_ASTERISK OFF CACHE BOOL "" FORCE)
|
||||
set(DMODEM_FREESWITCH OFF CACHE BOOL "" FORCE)
|
||||
set(DMODEM_ARI OFF CACHE BOOL "" FORCE)
|
||||
# (clang-retro: D-Modem's own toolchain file has its sources take
|
||||
# dmodem_retro.h, the clock_gettime() that the sysroots lack; here
|
||||
# its C++ sources alone, as there)
|
||||
get_directory_property(_opts COMPILE_OPTIONS)
|
||||
if(CLANG_DOS)
|
||||
# (the oldest Windows of the target, as D-Modem's toolchain file
|
||||
# has it: the .cfg's _WIN32_WINNT, else its triple's
|
||||
# windows<major>.<minor>, 9x and NT 4.0 all 0x0400)
|
||||
if(NOT DMODEM_WINNT)
|
||||
file(STRINGS ${CLANG_DOS}/bin/${CLANG_RETRO_CONFIG}.cfg _cfg_lines)
|
||||
foreach(_l ${_cfg_lines})
|
||||
if(_l MATCHES "^-D_WIN32_WINNT=(.*)$")
|
||||
set(DMODEM_WINNT ${CMAKE_MATCH_1})
|
||||
elseif(NOT DMODEM_WINNT AND _l MATCHES "windows([0-9]+)\\.([0-9]+)")
|
||||
if(CMAKE_MATCH_1 EQUAL 4)
|
||||
set(DMODEM_WINNT 0x0400)
|
||||
else()
|
||||
math(EXPR DMODEM_WINNT "${CMAKE_MATCH_1} * 256 + ${CMAKE_MATCH_2}"
|
||||
OUTPUT_FORMAT HEXADECIMAL)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set(DMODEM_WINNT ${DMODEM_WINNT} CACHE STRING
|
||||
"_WIN32_WINNT: the oldest Windows for the modem built in")
|
||||
endif()
|
||||
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-include>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:${DMODEM_GUI_DMODEM_DIR}/platforms/windows/clang-retro/dmodem_retro.h>")
|
||||
set(ENV{CLANG_DOS} ${CLANG_DOS})
|
||||
endif()
|
||||
add_subdirectory(${DMODEM_GUI_DMODEM_DIR} d-modem EXCLUDE_FROM_ALL)
|
||||
set_directory_properties(PROPERTIES COMPILE_OPTIONS "${_opts}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(core)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
Native apps for D-Modem on Windows, macOS and Linux.
|
||||
|
||||
The Linux app has the modem built in, so it needs no dmodemd. The Windows
|
||||
and macOS apps start dmodemd (or connect to a dmodemd that already runs). It
|
||||
The Linux and Windows apps have the modem built in, so they need no dmodemd.
|
||||
The macOS app starts dmodemd (or connects to a dmodemd that already runs). It
|
||||
shows the modem as a desktop program. You can dial and answer from a window,
|
||||
change the settings without AT commands, and see the results of the last
|
||||
call. All three apps are thin native shells over one small C library,
|
||||
@@ -60,7 +60,7 @@ macOS, refer to [Building](docs/building.md).
|
||||
|
||||
- [Features](docs/features.md): each page and menu of the apps, with the details of the Windows app
|
||||
- [Building](docs/building.md): Linux, Windows with clang-retro, macOS, and the Windows app on Linux and macOS
|
||||
- [The built-in modem](docs/embedded-modem.md): the modem inside the Linux app, with no dmodemd
|
||||
- [The built-in modem](docs/embedded-modem.md): the modem inside the Linux and Windows apps, with no dmodemd
|
||||
- [Design](docs/design.md): how the apps are built, what they share, hardware modems (the MultiTech MT9234MU), the Windows 9x notes, and the Windows app on Linux and macOS
|
||||
- [libdmodemctl](core/include/dmodemctl.h): the API of the library
|
||||
- [Documentation style](docs/STYLE.md): the rules for ASD-STE100 Simplified Technical English
|
||||
|
||||
+10
-2
@@ -13,14 +13,22 @@ The submodule `external/D-Modem` gives the built-in modem. Refer to
|
||||
Windows: we build the Windows app with clang-retro. Get its toolchain
|
||||
package (`clang-dos-linux-x86_64.tar.xz` or `clang-dos-windows-x86_64.zip`,
|
||||
from the [nightly release](https://github.com/clang-retro/dos-sdk/releases/tag/nightly)).
|
||||
Then set `CLANG_DOS` to the directory of the package:
|
||||
Then set `CLANG_DOS` to the directory of the package. The win98 and win7
|
||||
builds need the submodule (`git submodule update --init`) for the built-in
|
||||
modem. The win9x build does not include the built-in modem:
|
||||
|
||||
# Windows 95, 98, ME, NT 4.0 and later (no C runtime DLL)
|
||||
cmake -S . -B build/win9x -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake
|
||||
cmake --build build/win9x
|
||||
|
||||
# Windows 7 and later
|
||||
# Windows 98 SE, ME, 2000 and later, with the built-in modem
|
||||
cmake -S . -B build/win98 -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake \
|
||||
-DCLANG_RETRO_CONFIG=win98
|
||||
cmake --build build/win98
|
||||
|
||||
# Windows 7 and later, with the built-in modem
|
||||
cmake -S . -B build/win7 -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCLANG_DOS=/opt/clang-dos -DCMAKE_TOOLCHAIN_FILE=cmake/clang-retro.cmake \
|
||||
-DCLANG_RETRO_CONFIG=win7
|
||||
|
||||
+2
-2
@@ -335,8 +335,8 @@ the pty in the group of the user (`-g`). Thus dmodemd does not need root.
|
||||
Each app can also use a modem that already runs: a device path on Linux and
|
||||
macOS, or a TCP address or a COM port on Windows.
|
||||
|
||||
The Linux app does not start dmodemd by default. It runs the modem in a
|
||||
thread (`libdmodem_embed`), and its DTE is a socket. Refer to
|
||||
The Linux and Windows apps do not start dmodemd by default. They run the
|
||||
modem in a thread (`libdmodem_embed`), and its DTE is a socket. Refer to
|
||||
[The built-in modem](embedded-modem.md).
|
||||
|
||||
## Hardware modems: the MultiTech MT9234MU
|
||||
|
||||
+31
-12
@@ -1,8 +1,8 @@
|
||||
# The built-in modem
|
||||
|
||||
The Linux app has the D-Modem modem in it. Thus, the app does not need a
|
||||
separate `dmodemd`. The Windows and macOS apps still start `dmodemd` at
|
||||
this time.
|
||||
The Linux app and the Windows app (Windows 98 SE and later) have the
|
||||
D-Modem modem in them. Thus, these apps do not need a separate `dmodemd`.
|
||||
The macOS app and the Windows 95 build still use `dmodemd` at this time.
|
||||
|
||||
## What it does
|
||||
|
||||
@@ -23,19 +23,29 @@ app opens the device and starts no modem.
|
||||
|
||||
- There is no pty and no `/dev/ttyDM0` link. Other programs cannot use the
|
||||
built-in modem. To share the modem with other programs, start `dmodemd`.
|
||||
- The app does not need root.
|
||||
- The app does not need root (Linux) or a firewall exception for a TCP
|
||||
port (Windows).
|
||||
- A USB modem needs a udev rule that lets the user open the device.
|
||||
- A softmodem codec needs the user in the `audio` group.
|
||||
- The modem keeps the measurements of the line in
|
||||
`~/.local/share/dmodem-gui/dmodem0.data`.
|
||||
`~/.local/share/dmodem-gui/dmodem0.data` (Linux), or in
|
||||
`%APPDATA%\D-Modem\dmodem0.data` (Windows).
|
||||
- The **Log** page shows the log of the modem.
|
||||
|
||||
## How to use dmodemd
|
||||
|
||||
On Linux:
|
||||
|
||||
1. Open the line settings (the gear button on the Modem page).
|
||||
2. In **Advanced**, set **Built-in modem** to off.
|
||||
3. Optional: set the path of `dmodemd`.
|
||||
|
||||
On Windows, the Line Settings dialog does not have this setting yet. Close
|
||||
the app, and add this line to the `[line]` section of
|
||||
`%APPDATA%\D-Modem\dmodem.ini`:
|
||||
|
||||
builtin=0
|
||||
|
||||
The app then starts `dmodemd` as before.
|
||||
|
||||
## How to build it
|
||||
@@ -44,8 +54,11 @@ The D-Modem source is a git submodule in `external/D-Modem`. To get it:
|
||||
|
||||
git submodule update --init
|
||||
|
||||
If the submodule is there, CMake builds the built-in modem on Linux
|
||||
(`DMODEM_GUI_EMBED`, on by default). To build the app with no built-in
|
||||
If the submodule is there, CMake builds the built-in modem
|
||||
(`DMODEM_GUI_EMBED`, on by default) for the Linux app, and for the Windows
|
||||
app with the clang-retro configurations `win98`, `winme`, `win7` and later.
|
||||
It is off for `win32-picolibc` (the Windows 95 build) and for the Windows
|
||||
app on Linux and macOS (`DMODEM_GUI_WINPORT`). To build the app with no built-in
|
||||
modem, use `-DDMODEM_GUI_EMBED=OFF`. For a USB line and an ALSA line, also
|
||||
install `libusb-1.0-0-dev` and `libasound2-dev`.
|
||||
|
||||
@@ -63,8 +76,9 @@ on Linux the libusb and ALSA libraries of the system (LGPL-2.1).
|
||||
| App | Status |
|
||||
| --- | --- |
|
||||
| Linux | Done. Tested: a call from the Dial button to another D-Modem connects at 62666 bit/s (V.91), and **Stop** hangs up. |
|
||||
| Windows 7 and later | Not done. The library must build with clang-retro in the app. |
|
||||
| Windows 95 to XP | Not done. Refer to "Windows 95" below. |
|
||||
| Windows 98 SE and later | Done (`win98` build). It builds, and its imports agree with Windows 98 SE. It is not tested on Windows or Wine yet. |
|
||||
| Windows 7 and later | Done (`win7` build). It builds. It is not tested on Windows or Wine yet. |
|
||||
| Windows 95 and NT 4.0 | Not possible. Refer to "Windows 95" below. |
|
||||
| macOS | Not done. Xcode must link the library. |
|
||||
|
||||
### Windows 95
|
||||
@@ -72,6 +86,11 @@ on Linux the libusb and ALSA libraries of the system (LGPL-2.1).
|
||||
The Windows 95 build of the app uses the clang-retro configuration
|
||||
`win32-picolibc`. It has a C library (picolibc) but no C++ library. The
|
||||
modem is in C++17 and needs the `win98` configuration (msvcrt and libc++).
|
||||
One program cannot use the two C libraries. Thus, an app with the built-in
|
||||
modem will need Windows 98 SE or later. The Windows 95 build will continue
|
||||
to use `dmodemd` on TCP, or a COM port.
|
||||
One program cannot use the two C libraries. Thus, the app with the
|
||||
built-in modem needs Windows 98 SE or later. The Windows 95 build
|
||||
continues to use `dmodemd` on TCP, or a COM port. The `win98` build also
|
||||
does not operate on Windows NT 4.0: its libraries use `_vsnprintf_s` of
|
||||
msvcrt.dll, which NT 4.0 does not have.
|
||||
|
||||
On Windows, the modem gives the app a socket on the loopback interface
|
||||
(`127.0.0.1`), because Windows does not have `socketpair()`.
|
||||
Vendored
+1
-1
Submodule external/D-Modem updated: 26f9919bb5...8ba624fa41.
+3
-2
@@ -26,8 +26,9 @@ else()
|
||||
endif()
|
||||
|
||||
add_library(dmodemssh STATIC src/dmodemssh.c src/ppk.c src/agent.c)
|
||||
# (the Windows 95 build: a gai_strerrorA with no Unicode call)
|
||||
if(CLANG_RETRO_CONFIG MATCHES "picolibc")
|
||||
# (the Windows 95 build, and the Windows 98 SE and ME builds of the app
|
||||
# with the modem built in: a gai_strerrorA with no Unicode call)
|
||||
if(CLANG_RETRO_CONFIG MATCHES "picolibc|^win98|^winme")
|
||||
target_sources(dmodemssh PRIVATE src/gai_strerror.c)
|
||||
endif()
|
||||
target_include_directories(dmodemssh PUBLIC include)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* gai_strerror.c - gai_strerrorA for the Windows 95 build (clang-retro,
|
||||
* picolibc). The one of mingw-w64's libws2_32.a calls
|
||||
* gai_strerror.c - gai_strerrorA for the Windows 9x builds (clang-retro:
|
||||
* picolibc, win98 and winme). The one of mingw-w64's libws2_32.a calls
|
||||
* FormatMessageW, which Windows 9x has only as a stub.
|
||||
* This one is linked before it (ssh/CMakeLists.txt) and
|
||||
* calls FormatMessageA. (Only Windows: the macOS
|
||||
|
||||
+19
-10
@@ -3,23 +3,32 @@
|
||||
enable_language(CXX)
|
||||
enable_language(RC)
|
||||
include(sources.cmake)
|
||||
add_executable(dmodem WIN32 ${DMODEM_WIN_SOURCES} res/app.rc)
|
||||
target_include_directories(dmodem PRIVATE src)
|
||||
target_link_libraries(dmodem PRIVATE dmodemctl comctl32 wsock32 comdlg32 gdi32 winmm msacm32 shell32)
|
||||
# (the target dmodem-app, its file dmodem.exe: D-Modem's libdmodem is
|
||||
# the target dmodem, with the modem built in)
|
||||
add_executable(dmodem-app WIN32 ${DMODEM_WIN_SOURCES} res/app.rc)
|
||||
set_target_properties(dmodem-app PROPERTIES OUTPUT_NAME dmodem)
|
||||
target_include_directories(dmodem-app PRIVATE src)
|
||||
target_link_libraries(dmodem-app PRIVATE dmodemctl comctl32 wsock32 comdlg32 gdi32 winmm msacm32 shell32)
|
||||
# the Remote page's SSH: libdmodemssh (libssh, built in)
|
||||
if(TARGET dmodemssh)
|
||||
target_link_libraries(dmodem PRIVATE dmodemssh)
|
||||
target_compile_definitions(dmodem PRIVATE DMODEM_HAVE_SSH)
|
||||
target_link_libraries(dmodem-app PRIVATE dmodemssh)
|
||||
target_compile_definitions(dmodem-app PRIVATE DMODEM_HAVE_SSH)
|
||||
endif()
|
||||
if(MSVC)
|
||||
target_compile_definitions(dmodem PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_definitions(dmodem-app PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
# (a manifest of our own in app.rc)
|
||||
target_link_options(dmodem PRIVATE /MANIFEST:NO)
|
||||
target_link_options(dmodem-app PRIVATE /MANIFEST:NO)
|
||||
else()
|
||||
target_compile_options(dmodem PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
target_link_options(dmodem PRIVATE -static)
|
||||
target_compile_options(dmodem-app PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
||||
target_link_options(dmodem-app PRIVATE -static)
|
||||
endif()
|
||||
# (picolibc starts main, unless the entry point is WinMain's)
|
||||
if(CLANG_RETRO_CONFIG MATCHES "picolibc")
|
||||
target_link_options(dmodem PRIVATE -Wl,-e,WinMainCRTStartup)
|
||||
target_link_options(dmodem-app PRIVATE -Wl,-e,WinMainCRTStartup)
|
||||
endif()
|
||||
# the modem built in (libdmodem_embed, DMODEM_GUI_EMBED): Windows 98 SE
|
||||
# and later
|
||||
if(DMODEM_GUI_EMBED AND TARGET dmodem_embed)
|
||||
target_link_libraries(dmodem-app PRIVATE dmodem_embed)
|
||||
target_compile_definitions(dmodem-app PRIVATE DMODEM_GUI_EMBED)
|
||||
endif()
|
||||
+12
-2
@@ -8,8 +8,10 @@
|
||||
* clang-retro (cmake/clang-retro.cmake), or MinGW or MSVC.
|
||||
*
|
||||
* The modem is reached one of three ways (Link):
|
||||
* - dmodemd started by the app on this PC (Windows 7 and later, as
|
||||
* dmodemd needs), its DTE a TCP socket on 127.0.0.1;
|
||||
* - the modem built into the app (DMODEM_GUI_EMBED: libdmodem_embed,
|
||||
* Windows 98 SE and later), its DTE a socket; or dmodemd started by
|
||||
* the app on this PC (Windows 7 and later, as dmodemd needs), its
|
||||
* DTE a TCP socket on 127.0.0.1;
|
||||
* - a TCP address: dmodemd as a service, or on another computer;
|
||||
* - a COM port: a modem's serial port, a pico-serial, or dmodemd's
|
||||
* --com through a com0com pair.
|
||||
@@ -77,6 +79,9 @@ struct Config {
|
||||
char country[64];
|
||||
char usb[64]; /* --usb, "" for a SIP line */
|
||||
char dmodemd[MAX_PATH]; /* dmodemd.exe, "" next to the app */
|
||||
/* LINE_DMODEMD: the modem built in (DMODEM_GUI_EMBED), not
|
||||
dmodemd.exe started ([line] builtin=0) */
|
||||
int builtin;
|
||||
char tcp[256]; /* host:port */
|
||||
char com[32]; /* COM1 */
|
||||
/* the COM port's settings, as HyperTerminal's Configure: bits per
|
||||
@@ -130,6 +135,8 @@ bool link_break();
|
||||
void link_pump();
|
||||
/* socket messages (WM_APP_SOCKET) */
|
||||
void link_socket(WPARAM w, LPARAM l);
|
||||
/* the built-in modem's news (WM_APP_EMBED): a log line, or its end */
|
||||
void link_embed(WPARAM w, LPARAM l);
|
||||
void link_type(const char *data, int n);
|
||||
/* bytes to the far end as they are (a file transfer's) */
|
||||
void link_send(const char *data, int n);
|
||||
@@ -150,6 +157,9 @@ void link_wait(int tag, ResponseFn fn, void *data);
|
||||
/* a file transfer has bytes for its line, or ended (wParam 0); the
|
||||
remote's rz waits for files (wParam 1, lParam its XferLine) */
|
||||
#define WM_APP_XFER (WM_APP + 4)
|
||||
/* news from the built-in modem's thread: a log line or its end
|
||||
(lParam: link.cpp's EmbedNews, malloc'd) */
|
||||
#define WM_APP_EMBED (WM_APP + 5)
|
||||
|
||||
/* main.cpp */
|
||||
void app_log(const char *line);
|
||||
|
||||
+21
-6
@@ -96,9 +96,16 @@ void config_load(Config *c)
|
||||
app yet, so a dmodemd that runs, through TCP) */
|
||||
(void)old;
|
||||
c->line = get_i(ini, "line", LINE_TCP);
|
||||
#else
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
/* (the modem built in runs on Windows 98 SE and later) */
|
||||
(void)old;
|
||||
c->line = get_i(ini, "line", LINE_DMODEMD);
|
||||
#else
|
||||
c->line = get_i(ini, "line", old ? LINE_COM : LINE_DMODEMD);
|
||||
#endif
|
||||
#endif
|
||||
c->builtin = get_i(ini, "builtin", 1);
|
||||
get(ini, "sip-user", "", c->sip_user, sizeof(c->sip_user));
|
||||
get(ini, "sip-password", "", c->sip_password, sizeof(c->sip_password));
|
||||
get(ini, "sip-server", "", c->sip_server, sizeof(c->sip_server));
|
||||
@@ -155,6 +162,7 @@ void config_save(const Config *c)
|
||||
put(ini, "country", c->country);
|
||||
put(ini, "usb", c->usb);
|
||||
put(ini, "dmodemd", c->dmodemd);
|
||||
put_i(ini, "builtin", c->builtin);
|
||||
put(ini, "tcp", c->tcp);
|
||||
put(ini, "com", c->com);
|
||||
put_i(ini, "com-bps", c->com_bps);
|
||||
@@ -187,19 +195,26 @@ void config_summary(const Config *c, char *out, int n)
|
||||
c->com_bps, c->com_data, "NOEMS"[c->com_parity],
|
||||
c->com_stop == 1 ? "1.5" : c->com_stop == 2 ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
default: {
|
||||
/* (what runs the line: the modem built in, or dmodemd) */
|
||||
const char *who = "dmodemd";
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
if (c->builtin)
|
||||
who = "Built-in modem";
|
||||
#endif
|
||||
if (c->usb[0])
|
||||
_snprintf(out, n, "dmodemd: USB modem (%s)", c->usb);
|
||||
_snprintf(out, n, "%s: USB modem (%s)", who, c->usb);
|
||||
else if (c->sip_anonymous)
|
||||
_snprintf(out, n, "dmodemd: SIP, anonymous (no account)%s",
|
||||
c->listen ? ", taking calls" : "");
|
||||
_snprintf(out, n, "%s: SIP, anonymous (no account)%s",
|
||||
who, c->listen ? ", taking calls" : "");
|
||||
else if (!c->sip_user[0] || !c->sip_server[0])
|
||||
_snprintf(out, n, "dmodemd: SIP account not set up");
|
||||
_snprintf(out, n, "%s: SIP account not set up", who);
|
||||
else
|
||||
_snprintf(out, n, "dmodemd: SIP %s@%s%s", c->sip_user,
|
||||
_snprintf(out, n, "%s: SIP %s@%s%s", who, c->sip_user,
|
||||
c->sip_server, c->listen ? ", taking calls" : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
out[n - 1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
*
|
||||
* Only what Windows 95 has: Winsock 1.1 (WSAAsyncSelect), anonymous
|
||||
* pipes read with PeekNamedPipe, and a COM port read on the timer.
|
||||
*
|
||||
* With the modem built in (DMODEM_GUI_EMBED, Windows 98 SE and later),
|
||||
* the dmodemd line starts no dmodemd: libdmodem_embed runs the modem in
|
||||
* a thread of the app, and gives a connected socket as its DTE. The
|
||||
* thread's log lines and its end come to the main window as
|
||||
* WM_APP_EMBED.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -15,6 +21,10 @@
|
||||
|
||||
#include "app.h"
|
||||
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
#include "dmodem_embed.h"
|
||||
#endif
|
||||
|
||||
/* the commands that wait for their responses */
|
||||
struct Waiting {
|
||||
int tag;
|
||||
@@ -33,6 +43,11 @@ static int proc_n;
|
||||
static char port_out[8192]; /* what the DTE has yet to take */
|
||||
static int port_out_n;
|
||||
static int connect_tries;
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
static dmodem_embed *embed; /* the modem built in */
|
||||
static int embed_running;
|
||||
static unsigned embed_gen; /* its start's number */
|
||||
#endif
|
||||
|
||||
static int64_t now_ms()
|
||||
{
|
||||
@@ -57,6 +72,10 @@ bool link_break()
|
||||
|
||||
bool link_running()
|
||||
{
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
if (embed_running)
|
||||
return true;
|
||||
#endif
|
||||
return proc != NULL || sock != INVALID_SOCKET ||
|
||||
com != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
@@ -344,6 +363,148 @@ static bool start_dmodemd()
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
/* news from the modem's thread (WM_APP_EMBED's lParam): a log line, or
|
||||
the end (line empty) with its status */
|
||||
struct EmbedNews {
|
||||
unsigned gen;
|
||||
int end, status;
|
||||
char line[1];
|
||||
};
|
||||
|
||||
/* a log line, or the end, posted to the main window (any thread) */
|
||||
static void embed_post(unsigned gen, const char *line, int end, int status)
|
||||
{
|
||||
size_t n = line ? strlen(line) : 0;
|
||||
EmbedNews *e = (EmbedNews *)malloc(sizeof(EmbedNews) + n);
|
||||
if (!e)
|
||||
return;
|
||||
e->gen = gen;
|
||||
e->end = end;
|
||||
e->status = status;
|
||||
memcpy(e->line, line ? line : "", n + 1);
|
||||
if (!PostMessage(app.main, WM_APP_EMBED, 0, (LPARAM)e))
|
||||
free(e);
|
||||
}
|
||||
|
||||
/* a line of the modem's log (the modem's thread); ctx is the start's
|
||||
number */
|
||||
static void embed_log(void *ctx, const char *line)
|
||||
{
|
||||
embed_post((unsigned)(UINT_PTR)ctx, line, 0, 0);
|
||||
}
|
||||
|
||||
/* the modem stopped (the modem's thread) */
|
||||
static void embed_exit(void *ctx, int status)
|
||||
{
|
||||
embed_post((unsigned)(UINT_PTR)ctx, NULL, 1, status);
|
||||
}
|
||||
|
||||
/* the modem started in the app on the line settings' line, its DTE the
|
||||
socket that libdmodem_embed gives */
|
||||
static bool start_embedded()
|
||||
{
|
||||
Config &c = app.cfg;
|
||||
if (!c.usb[0] && !config_sip_ready(&c)) {
|
||||
app_message("Set up the SIP account first (Modem, Line Settings)");
|
||||
return false;
|
||||
}
|
||||
dmodem_embed_config e;
|
||||
dmodem_embed_config_init(&e);
|
||||
e.country = c.country;
|
||||
if (c.usb[0]) {
|
||||
e.line = DMODEM_EMBED_USB;
|
||||
e.usb = c.usb;
|
||||
} else {
|
||||
e.line = DMODEM_EMBED_SIP;
|
||||
if (!c.sip_anonymous) {
|
||||
e.sip_user = c.sip_user;
|
||||
e.sip_password = c.sip_password;
|
||||
e.sip_domain = c.sip_server;
|
||||
}
|
||||
e.sip_listen = c.listen;
|
||||
e.sip_t38 = c.t38;
|
||||
e.sip_v152 = c.v152;
|
||||
e.sip_v150 = c.v150;
|
||||
}
|
||||
/* the line's measurements, kept from call to call */
|
||||
char data[MAX_PATH];
|
||||
app_data_dir(data, sizeof(data) - 16);
|
||||
strcat(data, "\\dmodem0.data");
|
||||
e.data_file = data;
|
||||
if (!embed)
|
||||
embed = dmodem_embed_new();
|
||||
if (!embed)
|
||||
return false;
|
||||
embed_gen++;
|
||||
dmodem_embed_on_log(embed, embed_log, (void *)(UINT_PTR)embed_gen);
|
||||
dmodem_embed_on_exit(embed, embed_exit, (void *)(UINT_PTR)embed_gen);
|
||||
int fd = dmodem_embed_start(embed, &e);
|
||||
char m[300];
|
||||
if (fd < 0) {
|
||||
_snprintf(m, sizeof(m), "Can't start the built-in modem: %s",
|
||||
dmodem_embed_error(embed));
|
||||
m[sizeof(m) - 1] = '\0';
|
||||
app_message(m);
|
||||
app_log(m);
|
||||
return false;
|
||||
}
|
||||
_snprintf(m, sizeof(m), "The built-in modem (D-Modem %s) started.",
|
||||
dmodem_embed_version());
|
||||
m[sizeof(m) - 1] = '\0';
|
||||
app_log(m);
|
||||
embed_running = 1;
|
||||
/* (a connected socket: the same messages as a TCP line's) */
|
||||
sock = (SOCKET)fd;
|
||||
sock_ready = 1;
|
||||
WSAAsyncSelect(sock, app.main, WM_APP_SOCKET,
|
||||
FD_READ | FD_WRITE | FD_CLOSE);
|
||||
opened("Built-in modem");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* the modem built in stopped, its thread ended */
|
||||
static void stop_embedded()
|
||||
{
|
||||
if (!embed || !embed_running)
|
||||
return;
|
||||
/* (news of this start after now is not wanted) */
|
||||
embed_gen++;
|
||||
dmodem_embed_stop(embed);
|
||||
embed_running = 0;
|
||||
app_log("The built-in modem stopped.");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* see app.h */
|
||||
void link_embed(WPARAM w, LPARAM l)
|
||||
{
|
||||
(void)w;
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
EmbedNews *e = (EmbedNews *)l;
|
||||
if (e && e->gen == embed_gen) {
|
||||
if (!e->end) {
|
||||
app_log(e->line);
|
||||
if (dmc_daemon_error(e->line) && !link_open())
|
||||
app_message(e->line + 7);
|
||||
} else {
|
||||
const char *m = e->status < 0 ?
|
||||
"The built-in modem stopped (error)." :
|
||||
"The built-in modem stopped.";
|
||||
app_log(m);
|
||||
if (e->status < 0)
|
||||
app_message(m);
|
||||
embed_running = 0;
|
||||
close_port();
|
||||
app_state();
|
||||
}
|
||||
}
|
||||
free(e);
|
||||
#else
|
||||
(void)l;
|
||||
#endif
|
||||
}
|
||||
|
||||
void link_start()
|
||||
{
|
||||
if (link_running())
|
||||
@@ -357,6 +518,12 @@ void link_start()
|
||||
ok = open_com(app.cfg.com);
|
||||
break;
|
||||
default:
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
if (app.cfg.builtin) {
|
||||
ok = start_embedded();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
ok = start_dmodemd();
|
||||
break;
|
||||
}
|
||||
@@ -370,6 +537,9 @@ void link_stop()
|
||||
dmc_hangup(app.s);
|
||||
link_pump();
|
||||
}
|
||||
#ifdef DMODEM_GUI_EMBED
|
||||
stop_embedded();
|
||||
#endif
|
||||
close_port();
|
||||
if (proc) {
|
||||
/* dmodemd has no window to close: it is ended */
|
||||
|
||||
@@ -526,6 +526,9 @@ static LRESULT CALLBACK main_proc(HWND w, UINT m, WPARAM wp, LPARAM lp)
|
||||
case WM_APP_SOCKET:
|
||||
link_socket(wp, lp);
|
||||
return 0;
|
||||
case WM_APP_EMBED:
|
||||
link_embed(wp, lp);
|
||||
return 0;
|
||||
case WM_APP_REMOTE:
|
||||
remote_socket(wp, lp);
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user