implement DOS compatibility

This commit is contained in:
Gregory Gauthier 2026-01-26 14:29:55 +00:00
parent 03332baf2e
commit f65b9f007d
7 changed files with 300 additions and 13 deletions

202
DOS_BUILD.md Normal file
View File

@ -0,0 +1,202 @@
# Building Cordle for DOS
Cordle is fully compatible with DOS systems using either DJGPP or Borland C compilers. The code is strictly C90 compliant and includes platform-specific conditional compilation.
## Platform Support
### Tested Environments
- **MS-DOS 6.22**
- **FreeDOS 1.3**
- **DOSBox** (with DJGPP)
- **DOSBox-X**
### Compiler Options
#### Option 1: DJGPP (Recommended)
DJGPP is a complete 32-bit C/C++ development system for DOS, based on GCC.
**Requirements:**
- DJGPP 2.05 or later
- PDCurses library (DOS port)
- GNU Make
- Minimum 2MB RAM
**Installation:**
1. Download DJGPP from http://www.delorie.com/djgpp/
2. Required packages:
- `djdev205.zip` (DJGPP development kit)
- `gcc930b.zip` (GNU C Compiler)
- `bnu234b.zip` (GNU Binutils)
- `mak43b.zip` (GNU Make)
3. Extract all to `C:\DJGPP`
4. Set environment variables in `AUTOEXEC.BAT`:
```
SET DJGPP=C:\DJGPP\DJGPP.ENV
SET PATH=C:\DJGPP\BIN;%PATH%
```
**Building PDCurses:**
1. Download PDCurses from https://pdcurses.org/
2. Extract and build:
```
cd pdcurses\dos
make -f Makefile.dj
```
3. Install:
```
copy pdcurses.a C:\DJGPP\LIB\libpdcurses.a
copy curses.h C:\DJGPP\INCLUDE\
copy panel.h C:\DJGPP\INCLUDE\
```
**Building Cordle:**
```
cd \CORDLE
make
```
This creates `CORDLE.EXE` in the `build` directory.
#### Option 2: Borland C/C++ 3.1 or Turbo C++
**Requirements:**
- Borland C/C++ 3.1 or later
- PDCurses for DOS
- Minimum 640KB RAM
**Manual Build:**
```
bcc -mc -IC:\BC\INCLUDE -LC:\BC\LIB -std=c90 src\main.c src\game.c src\ui.c src\words.c -lpdcurses -ocordle.exe
```
Note: Borland uses slightly different command-line syntax. Adjust paths as needed.
## File Paths in DOS Build
The DOS version automatically detects the platform and uses DOS-appropriate paths:
**DOS Search Order:**
1. `wordlists\` (relative to executable - for development)
2. `C:\CORDLE\wordlists\` (system installation)
3. Custom path via `--wordlist` argument
**Unix Search Order:**
1. `wordlists/` (relative to executable)
2. `/usr/local/share/cordle/wordlists/`
3. `$HOME/.local/share/cordle/wordlists/`
4. Custom path via `--wordlist` argument
## Installation on DOS
### Directory Structure
```
C:\CORDLE\
├── CORDLE.EXE
└── wordlists\
├── CORDLE_WORDS_EASY.TXT
├── CORDLE_WORDS_MEDIUM.TXT
├── CORDLE_WORDS_HARD.TXT
└── ...
```
### Quick Install
1. Create directory: `mkdir C:\CORDLE`
2. Copy `CORDLE.EXE` to `C:\CORDLE`
3. Copy `wordlists` directory to `C:\CORDLE`
4. Add to PATH in `AUTOEXEC.BAT`:
```
SET PATH=C:\CORDLE;%PATH%
```
## Running on DOS
```
C:\> cordle
C:\> cordle --easy
C:\> cordle --medium
C:\> cordle --hard
C:\> cordle --help
```
## Memory Requirements
- **Minimum:** 2MB RAM (DJGPP), 640KB (Borland)
- **Recommended:** 4MB RAM
- **Display:** VGA compatible (for colors)
- **DOS Version:** 5.0 or higher
## Troubleshooting
### "Out of memory" Error
- Increase DOS memory limit
- Use CWSDPMI.EXE memory extender (included with DJGPP)
- Free up conventional memory by unloading TSRs
### "libpdcurses.a not found"
- Verify PDCurses installation
- Check library path: `C:\DJGPP\LIB\`
### "curses.h not found"
- Copy `curses.h` to `C:\DJGPP\INCLUDE\`
### Colors Not Working
- Ensure VGA-compatible display
- Try running in DOSBox with `machine=svga_s3`
### Arrow Keys Crash (Fixed in v1.1)
- Arrow keys are now properly handled and ignored
- Update to latest version if experiencing issues
## Testing in DOSBox
A DOSBox configuration is included in the `dosbox/` directory:
```
dosbox -conf dosbox/dosbox_config_cordle.ini
```
## Platform Detection
The code automatically detects DOS vs Unix at compile time:
```c
#if defined(__MSDOS__) || defined(_MSDOS) || defined(__DOS__) || defined(MSDOS)
/* DOS-specific code */
#else
/* Unix-specific code */
#endif
```
## Differences from Unix Version
1. **Curses Library:** PDCurses instead of ncurses
2. **Path Separators:** Backslash (`\`) instead of forward slash (`/`)
3. **File Paths:** DOS-style paths (`C:\CORDLE\wordlists\`)
4. **Executable:** `.exe` extension
5. **No HOME Environment:** Uses fixed system path instead
## Source Code Portability
The code is 100% C90 compliant with:
- No C99/C11 features
- No GNU extensions
- Conditional compilation for platform differences
- Standard library only (stdio, stdlib, string, time, ctype)
- Platform-specific curses handling
## For Modern Development
For testing DOS builds on modern systems:
1. Use DOSBox-X (more accurate DOS emulation)
2. Install DJGPP within DOSBox
3. Use cross-compilation from Linux/macOS (advanced)
## License Note
Ensure PDCurses license compatibility with your distribution. PDCurses is public domain.
---
For Unix/Linux/macOS build instructions, see the main README.md.

View File

@ -1,9 +1,23 @@
# Makefile for Cordle - C90 Wordle Game
# Cross-platform build system for Unix/Linux/macOS and DOS
# Compiler and flags
CC = gcc
CFLAGS = -std=c90 -pedantic -Wpedantic -Wall -Wextra
LDFLAGS = -lncurses
# Platform detection
ifdef COMSPEC
# DOS/Windows with DJGPP detected
PLATFORM = DOS
LDFLAGS = -lpdcurses
CFLAGS += -D__MSDOS__
TARGET_EXT = .exe
else
# Unix/Linux/macOS
PLATFORM = UNIX
LDFLAGS = -lncurses
TARGET_EXT =
endif
# Directories
SRC_DIR = src
@ -16,7 +30,7 @@ SRCS = $(SRC_DIR)/main.c $(SRC_DIR)/game.c $(SRC_DIR)/ui.c $(SRC_DIR)/words.c
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
# Target executable
TARGET = $(BUILD_DIR)/cordle
TARGET = $(BUILD_DIR)/cordle$(TARGET_EXT)
# Default target
all: $(TARGET) wordlists
@ -58,12 +72,26 @@ rebuild: clean all
# Help target
help:
@echo "Cordle Makefile targets:"
@echo "Cordle Makefile - Cross-platform C90 Wordle Game"
@echo "================================================"
@echo "Detected platform: $(PLATFORM)"
@echo ""
@echo "Build targets:"
@echo " all - Build the game (default)"
@echo " clean - Remove build artifacts"
@echo " rebuild - Clean and rebuild"
@echo " install - Install to $(INSTALL_DIR)"
@echo " uninstall - Remove installed files"
@echo " install - Install to $(INSTALL_DIR) (Unix only)"
@echo " uninstall - Remove installed files (Unix only)"
@echo " help - Show this help message"
@echo ""
@echo "DOS/DJGPP Requirements:"
@echo " - DJGPP compiler (gcc for DOS)"
@echo " - PDCurses library"
@echo " - GNU Make"
@echo ""
@echo "Unix/Linux/macOS Requirements:"
@echo " - GCC compiler"
@echo " - ncurses library"
@echo " - GNU Make"
.PHONY: all clean install uninstall rebuild wordlists help

52
include/platform.h Normal file
View File

@ -0,0 +1,52 @@
/* platform.h - Platform-specific compatibility definitions */
#ifndef PLATFORM_H
#define PLATFORM_H
/* Platform detection */
#if defined(__MSDOS__) || defined(_MSDOS) || defined(__DOS__) || defined(MSDOS)
#define PLATFORM_DOS 1
#else
#define PLATFORM_UNIX 1
#endif
/* Include appropriate curses library */
#ifdef PLATFORM_DOS
#include <conio.h>
/* PDCurses on DOS uses curses.h */
#include <curses.h>
/* DOS path definitions */
#define PATH_SEP "\\"
#define WORDLIST_PATH_1 "wordlists"
#define WORDLIST_PATH_2 "C:\\CORDLE\\wordlists"
#define WORDLIST_PATH_3 NULL
/* DOS doesn't have HOME environment variable */
#define HAS_HOME_ENV 0
#else
/* Unix/Linux/macOS */
#include <curses.h>
/* Unix path definitions */
#define PATH_SEP "/"
#define WORDLIST_PATH_1 "wordlists"
#define WORDLIST_PATH_2 "/usr/local/share/cordle/wordlists"
#define WORDLIST_PATH_3_FMT "%s/.local/share/cordle/wordlists"
#define HAS_HOME_ENV 1
#endif
/* Color code compatibility */
#ifdef PLATFORM_DOS
/* PDCurses uses different color constants on some platforms */
#ifndef COLOR_WWHITE
#define COLOR_WWHITE COLOR_WHITE
#endif
#else
/* ncurses compatibility */
#ifndef COLOR_WWHITE
#define COLOR_WWHITE COLOR_WHITE
#endif
#endif
#endif /* PLATFORM_H */

View File

@ -2,7 +2,7 @@
#ifndef UI_H
#define UI_H
#include <curses.h>
#include "platform.h"
#include "game.h"
/* Color pair constants */
@ -10,7 +10,6 @@
#define COLOR_CORRECT 2
#define COLOR_PRESENT 3
#define COLOR_ABSENT 4
#define COLOR_WWHITE 7
#define COLOR_UNUSED 6
void draw_title(WINDOW* win, int y, const char* difficulty);

View File

@ -9,7 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <curses.h>
#include "../include/platform.h"
#include "../include/game.h"
#include "../include/words.h"
#include "../include/ui.h"

View File

@ -2,6 +2,7 @@
* Created by Gregory Gauthier on 06/10/2025.
*/
/* ui.c - User interface implementation */
#include "../include/platform.h"
#include "../include/ui.h"
#include <string.h>

View File

@ -3,6 +3,7 @@
*/
/* words.c - Word list management implementation */
#include "../include/words.h"
#include "../include/platform.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -13,25 +14,29 @@
static FILE* open_wordlist(const char *filename) {
FILE *file;
char filepath[512];
#if HAS_HOME_ENV
const char *home;
#endif
/* Try 1: wordlists/ relative to the current directory (for development) */
sprintf(filepath, "wordlists/%s", filename);
sprintf(filepath, "%s%s%s", WORDLIST_PATH_1, PATH_SEP, filename);
file = fopen(filepath, "r");
if (file) return file;
/* Try 2: /usr/local/share/cordle/wordlists/ (system installation) */
sprintf(filepath, "/usr/local/share/cordle/wordlists/%s", filename);
/* Try 2: system installation path */
sprintf(filepath, "%s%s%s", WORDLIST_PATH_2, PATH_SEP, filename);
file = fopen(filepath, "r");
if (file) return file;
/* Try 3: ${HOME}/.local/share/cordle/wordlists/ (user installation) */
#if HAS_HOME_ENV
/* Try 3: ${HOME}/.local/share/cordle/wordlists/ (Unix user installation) */
home = getenv("HOME");
if (home) {
sprintf(filepath, "%s/.local/share/cordle/wordlists/%s", home, filename);
sprintf(filepath, WORDLIST_PATH_3_FMT "%s%s", home, PATH_SEP, filename);
file = fopen(filepath, "r");
if (file) return file;
}
#endif
/* Try 4: filename as-is (custom path via --wordlist) */
file = fopen(filename, "r");