From ea7a6ce794dbda1a7eded1d5e663897d46d21fa2 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Fri, 15 Mar 2024 15:00:41 -0600 Subject: add post about compiling for dos --- .../posts/2024-03-04-opencvjs-video-processing.md | 12 + ...2024-03-15-setting-up-macos-for-8088-dos-dev.md | 267 +++++++++++++++++ Resources/assets/posts/dosbox/hello-world.png | Bin 0 -> 233460 bytes .../posts/2024-03-04-opencvjs-video-processing.png | Bin 0 -> 27820 bytes ...024-03-15-setting-up-macos-for-8088-dos-dev.png | Bin 0 -> 32566 bytes docs/assets/posts/dosbox/hello-world.png | Bin 0 -> 233460 bytes docs/feed.rss | 290 +++++++++++++++++- .../posts/2024-03-04-opencvjs-video-processing.png | Bin 0 -> 27820 bytes ...024-03-15-setting-up-macos-for-8088-dos-dev.png | Bin 0 -> 32566 bytes docs/index.html | 34 +-- ...24-03-15-setting-up-macos-for-8088-dos-dev.html | 330 +++++++++++++++++++++ docs/posts/index.html | 15 + docs/tags/DOS.html | 73 +++++ docs/tags/JS.html | 73 +++++ docs/tags/OpenCV.html | 73 +++++ docs/tags/macOS.html | 15 + docs/tags/x86.html | 73 +++++ 17 files changed, 1234 insertions(+), 21 deletions(-) create mode 100644 Content/posts/2024-03-04-opencvjs-video-processing.md create mode 100644 Content/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.md create mode 100644 Resources/assets/posts/dosbox/hello-world.png create mode 100644 Resources/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png create mode 100644 Resources/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png create mode 100644 docs/assets/posts/dosbox/hello-world.png create mode 100644 docs/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png create mode 100644 docs/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png create mode 100644 docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html create mode 100644 docs/tags/DOS.html create mode 100644 docs/tags/JS.html create mode 100644 docs/tags/OpenCV.html create mode 100644 docs/tags/x86.html diff --git a/Content/posts/2024-03-04-opencvjs-video-processing.md b/Content/posts/2024-03-04-opencvjs-video-processing.md new file mode 100644 index 0000000..cf87fb1 --- /dev/null +++ b/Content/posts/2024-03-04-opencvjs-video-processing.md @@ -0,0 +1,12 @@ +--- +date: 2024-03-04 12:01 +description: Real time video processing with OpenCV.js in the browser +tags: HTML, JS, OpenCV +draft: true +--- + +# Video Processing W/ OpenCV.js + +Note: A really weird bug you might run into when you are trying to mess around +and reloading the page on iOS is that OpenCV just stops loading. This is a bug in +WebKit.: diff --git a/Content/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.md b/Content/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.md new file mode 100644 index 0000000..15161f5 --- /dev/null +++ b/Content/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.md @@ -0,0 +1,267 @@ +--- +date: 2024-03-15 13:16 +description: This goes through compiling Open Watcom 2 and creating simple hello-world exampls +tags: DOS, x86, macOS +draft: false +--- + +# Cross-Compiling Hello World for DOS on macOS + +Technically this should work for any platform that OpenWatcom 2 supports compiling binaries for. Some instructions are based on [a post at retrocoding.net](https://retrocoding.net/openwatcom-gateway-to-ancient-world-of-x86), + and [John Tsiombikas's post](http://nuclear.mutantstargoat.com/articles/retrocoding/dos01-setup/#hello-world-program) + +## Prerequisites + +You should already have XCode / Command Line Tools, and Homebrew installed. To compile Open Watcom for DOS you will need DOSBox (I use DOSBox-X). + +```bash +brew install --cask dosbox-x +``` + +## Compiling Open Watcom v2 + +*If this process is super annoying, I might make a custom homebrew tap to build and install Open Watcom* + +```bash +git clone https://github.com/open-watcom/open-watcom-v2 +cp open-watcom-v2/setvars.sh custom_setvars.sh +``` + +Now, edit this `setvars.sh` file. My file looks like this: + +```bash +#!/bin/zsh +export OWROOT="/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2" +export OWTOOLS=CLANG +export OWDOCBUILD=0 +export OWGUINOBUILD=0 +export OWDISTRBUILD=0 +export OWDOSBOX="/Applications/dosbox-x.app/Contents/MacOS/dosbox-x" +export OWOBJDIR=binbuildV01 +. "$OWROOT/cmnvars.sh" +echo "OWROOT=$OWROOT" +cd "$OWROOT" +``` + +Note, your `OWRTOOT` is definitely going to be in a different location. + +```bash +source ./custom_setvars.sh +./build.sh +./build.sh rel +``` + +This will build, and then copy everything to the `rel` directory inside `open-watcom-v2` directory. Since I ran this on an Apple Silicon Mac, + all the binaries for me are in the `armo64` directory. You can now move everything inside the rel folder to another location, or create a simple + script to init all variables whenever you want. + +I like having a script called `exportVarsForDOS.sh` + +```bash +#!/bin/zsh + +export WATCOM=/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2/rel +export PATH=$PATH:$WATCOM/armo64 +export EDDAT=$WATCOM/eddat + +# For DOS 8088/8086 development +export INCLUDE=$WATCOM/h +export LIB=$WATCOM/lib286 # You don't really need this +``` + +Then, when you need to load up these variables, you can simply run `source exportVarsForDOS.sh` or `. exportVarsForDOS.sh` + +## Hello World + +### Buliding without any Makefiles + +Create a new file called `example1.c` + +```c +#include + +int main() { + printf("Hello World!"); + return 0; +} +``` + +First we compile the code: + +```bash +$ wcc example1.c +Open Watcom C x86 16-bit Optimizing Compiler +Version 2.0 beta Mar 15 2024 13:11:55 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. +example1.c: 7 lines, included 818, 0 warnings, 0 errors +Code size: 19 +``` + +Then, link to make an executable: + +```bash +$ wlink name example1.exe system dos file example1.o +Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. +loading object files +searching libraries +creating a DOS executable +``` + +If you want to test this executable, jump to the section titled `Testing with DOSBox-X` below. + +### Simple Makefile + +```makefile +obj = main.o hello.o +bin = tizts.com + +CC = wcc +CFLAGS = -0 +LD = wlink + +$(bin): $(obj) + $(LD) name $@ system dos file main.o file hello.o + +.c.o: + $(CC) $(CFLAGS) $< + +clean: + rm $(obj) $(bin) +``` + +Where, `main.c` +```c +void hello(void); + +int main(void) +{ + hello(); + return 0; +} +``` + +and `hello.c` + +```c +/* hello.c */ +#include + +void hello(void) +{ + printf("Hello!"); +} +``` + +To compile into `tizts.com` simply run `wmake` + +```bash +$ wmake +➜ simple-cpp wmake +Open Watcom Make Version 2.0 beta Mar 15 2024 13:10:16 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. + wcc -0 main.c +Open Watcom C x86 16-bit Optimizing Compiler +Version 2.0 beta Mar 15 2024 13:11:55 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. +main.c(8): Warning! W138: No newline at end of file +main.c: 8 lines, included 53, 1 warnings, 0 errors +Code size: 12 + wcc -0 hello.c +Open Watcom C x86 16-bit Optimizing Compiler +Version 2.0 beta Mar 15 2024 13:11:55 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. +hello.c: 8 lines, included 818, 0 warnings, 0 errors +Code size: 17 + wlink name tizts.com system dos file main.o file hello.o +Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09 +Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved. +Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved. +Source code is available under the Sybase Open Watcom Public License. +See https://github.com/open-watcom/open-watcom-v2#readme for details. +loading object files +searching libraries +creating a DOS executable +``` + +### Using CMake + +Create a file called `CMakeLists.txt` + +```CMake +project(hello) + +set(SOURCES abc.c) + +add_executable(hello ${SOURCES}) +``` + +Where, `abc.c` is: + +```c +#include + +int main() { + printf("Does this work?"); + return 0; +} +``` + +```bash +mkdir build +cd build +``` + +And build using CMake + +``` +cmake -DCMAKE_SYSTEM_NAME=DOS -DCMAKE_SYSTEM_PROCESSOR=I86 -DCMAKE_C_FLAGS="-0 -bt=dos -d0 -oaxt" -G "Watcom WMake" ../.. +``` + +There you have it. Three different ways to compile a C program on a macOS device in 2024 that can run on an IBM PC 5150 (which was released in 1981!) + +## Testing with DOSBox-X + +```bash +cp example1.exe ~/Downloads +/Applications/dosbox-x.app/Contents/MacOS/dosbox-x +``` + +In DOSBox-X we now mount the `~/Downloads` folder as our `C:` drive + +``` +mount C ~/Downloads +``` + +Switch to the C drive + +``` +C: +``` + +Run the program: + +``` +example1 +``` + +![Running our program in DOSBox-X](/assets/posts/dosbox/hello-world.png) + +*My DOSBox setup might look slightly different than yours...* + + diff --git a/Resources/assets/posts/dosbox/hello-world.png b/Resources/assets/posts/dosbox/hello-world.png new file mode 100644 index 0000000..4e2482e Binary files /dev/null and b/Resources/assets/posts/dosbox/hello-world.png differ diff --git a/Resources/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png b/Resources/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png new file mode 100644 index 0000000..e77d3d7 Binary files /dev/null and b/Resources/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png differ diff --git a/Resources/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png b/Resources/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png new file mode 100644 index 0000000..8cba6d8 Binary files /dev/null and b/Resources/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png differ diff --git a/docs/assets/posts/dosbox/hello-world.png b/docs/assets/posts/dosbox/hello-world.png new file mode 100644 index 0000000..4e2482e Binary files /dev/null and b/docs/assets/posts/dosbox/hello-world.png differ diff --git a/docs/feed.rss b/docs/feed.rss index 4f92bc6..d242684 100644 --- a/docs/feed.rss +++ b/docs/feed.rss @@ -4,8 +4,8 @@ Navan's Archive Rare Tips, Tricks and Posts https://web.navan.dev/en - Wed, 28 Feb 2024 11:50:15 -0000 - Wed, 28 Feb 2024 11:50:15 -0000 + Fri, 15 Mar 2024 15:00:25 -0000 + Fri, 15 Mar 2024 15:00:25 -0000 250 @@ -196,6 +196,292 @@ I actually added the code to this post after running the program.

]]> + + + https://web.navan.dev/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html + + + Cross-Compiling Hello World for DOS on macOS + + + This goes through compiling Open Watcom 2 and creating simple hello-world exampls + + https://web.navan.dev/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html + Fri, 15 Mar 2024 13:16:00 -0000 + Cross-Compiling Hello World for DOS on macOS + +

Technically this should work for any platform that OpenWatcom 2 supports compiling binaries for. Some instructions are based on a post at retrocoding.net, + and John Tsiombikas's post

+ +

Prerequisites

+ +

You should already have XCode / Command Line Tools, and Homebrew installed. To compile Open Watcom for DOS you will need DOSBox (I use DOSBox-X).

+ +
+
brew install --cask dosbox-x
+
+
+ +

Compiling Open Watcom v2

+ +

If this process is super annoying, I might make a custom homebrew tap to build and install Open Watcom

+ +
+
git clone https://github.com/open-watcom/open-watcom-v2
+cp open-watcom-v2/setvars.sh custom_setvars.sh
+
+
+ +

Now, edit this setvars.sh file. My file looks like this:

+ +
+
#!/bin/zsh
+export OWROOT="/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2"
+export OWTOOLS=CLANG
+export OWDOCBUILD=0
+export OWGUINOBUILD=0
+export OWDISTRBUILD=0
+export OWDOSBOX="/Applications/dosbox-x.app/Contents/MacOS/dosbox-x"
+export OWOBJDIR=binbuildV01
+. "$OWROOT/cmnvars.sh"
+echo "OWROOT=$OWROOT"
+cd "$OWROOT"
+
+
+ +

Note, your OWRTOOT is definitely going to be in a different location.

+ +
+
source ./custom_setvars.sh
+./build.sh
+./build.sh rel
+
+
+ +

This will build, and then copy everything to the rel directory inside open-watcom-v2 directory. Since I ran this on an Apple Silicon Mac, + all the binaries for me are in the armo64 directory. You can now move everything inside the rel folder to another location, or create a simple + script to init all variables whenever you want.

+ +

I like having a script called exportVarsForDOS.sh

+ +
+
#!/bin/zsh
+
+export WATCOM=/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2/rel
+export PATH=$PATH:$WATCOM/armo64
+export EDDAT=$WATCOM/eddat
+
+# For DOS 8088/8086 development
+export INCLUDE=$WATCOM/h
+export LIB=$WATCOM/lib286 # You don't really need this
+
+
+ +

Then, when you need to load up these variables, you can simply run source exportVarsForDOS.sh or . exportVarsForDOS.sh

+ +

Hello World

+ +

Buliding without any Makefiles

+ +

Create a new file called example1.c

+ +
+
#include<stdio.h>
+
+int main() {
+    printf("Hello World!");
+    return 0;
+}
+
+
+ +

First we compile the code:

+ +
+
$ wcc example1.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+example1.c: 7 lines, included 818, 0 warnings, 0 errors
+Code size: 19
+
+
+ +

Then, link to make an executable:

+ +
+
$ wlink name example1.exe system dos file example1.o
+Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+loading object files
+searching libraries
+creating a DOS executable 
+
+
+ +

If you want to test this executable, jump to the section titled Testing with DOSBox-X below.

+ +

Simple Makefile

+ +
+
obj = main.o hello.o
+bin = tizts.com
+
+CC = wcc
+CFLAGS = -0
+LD = wlink
+
+$(bin): $(obj)
+    $(LD) name $@ system dos file main.o file hello.o 
+
+.c.o:
+    $(CC) $(CFLAGS) $<
+
+clean:
+    rm $(obj) $(bin)
+
+
+ +

Where, main.c

+ +
+
void hello(void);
+
+int main(void)
+{
+    hello();
+    return 0;
+}
+
+
+ +

and hello.c

+ +
+
/* hello.c */
+#include <stdio.h>
+
+void hello(void)
+{
+    printf("Hello!");
+}
+
+
+ +

To compile into tizts.com simply run wmake

+ +
+
$ wmake
+➜  simple-cpp wmake
+Open Watcom Make Version 2.0 beta Mar 15 2024 13:10:16
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+    wcc -0 main.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+main.c(8): Warning! W138: No newline at end of file
+main.c: 8 lines, included 53, 1 warnings, 0 errors
+Code size: 12
+    wcc -0 hello.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+hello.c: 8 lines, included 818, 0 warnings, 0 errors
+Code size: 17
+    wlink name tizts.com system dos file main.o file hello.o
+Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+loading object files
+searching libraries
+creating a DOS executable
+
+
+ +

Using CMake

+ +

Create a file called CMakeLists.txt

+ +
+
project(hello)
+
+set(SOURCES abc.c)
+
+add_executable(hello ${SOURCES})
+
+
+ +

Where, abc.c is:

+ +
+
#include <stdio.h>
+
+int main() {
+    printf("Does this work?");
+    return 0;
+}
+
+
+ +
+
mkdir build
+cd build
+
+
+ +

And build using CMake

+ +
cmake -DCMAKE_SYSTEM_NAME=DOS -DCMAKE_SYSTEM_PROCESSOR=I86 -DCMAKE_C_FLAGS="-0 -bt=dos -d0 -oaxt" -G "Watcom WMake" ../..
+
+ +

There you have it. Three different ways to compile a C program on a macOS device in 2024 that can run on an IBM PC 5150 (which was released in 1981!)

+ +

Testing with DOSBox-X

+ +
+
cp example1.exe ~/Downloads
+/Applications/dosbox-x.app/Contents/MacOS/dosbox-x
+
+
+ +

In DOSBox-X we now mount the ~/Downloads folder as our C: drive

+ +
mount C ~/Downloads
+
+ +

Switch to the C drive

+ +
C:
+
+ +

Run the program:

+ +
example1
+
+ +

Running our program in DOSBox-X

+ +

My DOSBox setup might look slightly different than yours...

+]]>
+
+ https://web.navan.dev/posts/hello-world.html diff --git a/docs/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png b/docs/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png new file mode 100644 index 0000000..e77d3d7 Binary files /dev/null and b/docs/images/opengraph/posts/2024-03-04-opencvjs-video-processing.png differ diff --git a/docs/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png b/docs/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png new file mode 100644 index 0000000..8cba6d8 Binary files /dev/null and b/docs/images/opengraph/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.png differ diff --git a/docs/index.html b/docs/index.html index 3bee970..f6a4942 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,6 +50,21 @@

Recent Posts

For all posts go to Posts diff --git a/docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html b/docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html new file mode 100644 index 0000000..bb37d00 --- /dev/null +++ b/docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html @@ -0,0 +1,330 @@ + + + + + + + + + Cross-Compiling Hello World for DOS on macOS + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +

Cross-Compiling Hello World for DOS on macOS

+ +

Technically this should work for any platform that OpenWatcom 2 supports compiling binaries for. Some instructions are based on a post at retrocoding.net, + and John Tsiombikas's post

+ +

Prerequisites

+ +

You should already have XCode / Command Line Tools, and Homebrew installed. To compile Open Watcom for DOS you will need DOSBox (I use DOSBox-X).

+ +
+
brew install --cask dosbox-x
+
+
+ +

Compiling Open Watcom v2

+ +

If this process is super annoying, I might make a custom homebrew tap to build and install Open Watcom

+ +
+
git clone https://github.com/open-watcom/open-watcom-v2
+cp open-watcom-v2/setvars.sh custom_setvars.sh
+
+
+ +

Now, edit this setvars.sh file. My file looks like this:

+ +
+
#!/bin/zsh
+export OWROOT="/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2"
+export OWTOOLS=CLANG
+export OWDOCBUILD=0
+export OWGUINOBUILD=0
+export OWDISTRBUILD=0
+export OWDOSBOX="/Applications/dosbox-x.app/Contents/MacOS/dosbox-x"
+export OWOBJDIR=binbuildV01
+. "$OWROOT/cmnvars.sh"
+echo "OWROOT=$OWROOT"
+cd "$OWROOT"
+
+
+ +

Note, your OWRTOOT is definitely going to be in a different location.

+ +
+
source ./custom_setvars.sh
+./build.sh
+./build.sh rel
+
+
+ +

This will build, and then copy everything to the rel directory inside open-watcom-v2 directory. Since I ran this on an Apple Silicon Mac, + all the binaries for me are in the armo64 directory. You can now move everything inside the rel folder to another location, or create a simple + script to init all variables whenever you want.

+ +

I like having a script called exportVarsForDOS.sh

+ +
+
#!/bin/zsh
+
+export WATCOM=/Users/navanchauhan/Developer/8088Stuff/open-watcom-v2/rel
+export PATH=$PATH:$WATCOM/armo64
+export EDDAT=$WATCOM/eddat
+
+# For DOS 8088/8086 development
+export INCLUDE=$WATCOM/h
+export LIB=$WATCOM/lib286 # You don't really need this
+
+
+ +

Then, when you need to load up these variables, you can simply run source exportVarsForDOS.sh or . exportVarsForDOS.sh

+ +

Hello World

+ +

Buliding without any Makefiles

+ +

Create a new file called example1.c

+ +
+
#include<stdio.h>
+
+int main() {
+    printf("Hello World!");
+    return 0;
+}
+
+
+ +

First we compile the code:

+ +
+
$ wcc example1.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+example1.c: 7 lines, included 818, 0 warnings, 0 errors
+Code size: 19
+
+
+ +

Then, link to make an executable:

+ +
+
$ wlink name example1.exe system dos file example1.o
+Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+loading object files
+searching libraries
+creating a DOS executable 
+
+
+ +

If you want to test this executable, jump to the section titled Testing with DOSBox-X below.

+ +

Simple Makefile

+ +
+
obj = main.o hello.o
+bin = tizts.com
+
+CC = wcc
+CFLAGS = -0
+LD = wlink
+
+$(bin): $(obj)
+    $(LD) name $@ system dos file main.o file hello.o 
+
+.c.o:
+    $(CC) $(CFLAGS) $<
+
+clean:
+    rm $(obj) $(bin)
+
+
+ +

Where, main.c

+ +
+
void hello(void);
+
+int main(void)
+{
+    hello();
+    return 0;
+}
+
+
+ +

and hello.c

+ +
+
/* hello.c */
+#include <stdio.h>
+
+void hello(void)
+{
+    printf("Hello!");
+}
+
+
+ +

To compile into tizts.com simply run wmake

+ +
+
$ wmake
+➜  simple-cpp wmake
+Open Watcom Make Version 2.0 beta Mar 15 2024 13:10:16
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+    wcc -0 main.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+main.c(8): Warning! W138: No newline at end of file
+main.c: 8 lines, included 53, 1 warnings, 0 errors
+Code size: 12
+    wcc -0 hello.c
+Open Watcom C x86 16-bit Optimizing Compiler
+Version 2.0 beta Mar 15 2024 13:11:55
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+hello.c: 8 lines, included 818, 0 warnings, 0 errors
+Code size: 17
+    wlink name tizts.com system dos file main.o file hello.o
+Open Watcom Linker Version 2.0 beta Mar 15 2024 13:10:09
+Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
+Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
+Source code is available under the Sybase Open Watcom Public License.
+See https://github.com/open-watcom/open-watcom-v2#readme for details.
+loading object files
+searching libraries
+creating a DOS executable
+
+
+ +

Using CMake

+ +

Create a file called CMakeLists.txt

+ +
+
project(hello)
+
+set(SOURCES abc.c)
+
+add_executable(hello ${SOURCES})
+
+
+ +

Where, abc.c is:

+ +
+
#include <stdio.h>
+
+int main() {
+    printf("Does this work?");
+    return 0;
+}
+
+
+ +
+
mkdir build
+cd build
+
+
+ +

And build using CMake

+ +
cmake -DCMAKE_SYSTEM_NAME=DOS -DCMAKE_SYSTEM_PROCESSOR=I86 -DCMAKE_C_FLAGS="-0 -bt=dos -d0 -oaxt" -G "Watcom WMake" ../..
+
+ +

There you have it. Three different ways to compile a C program on a macOS device in 2024 that can run on an IBM PC 5150 (which was released in 1981!)

+ +

Testing with DOSBox-X

+ +
+
cp example1.exe ~/Downloads
+/Applications/dosbox-x.app/Contents/MacOS/dosbox-x
+
+
+ +

In DOSBox-X we now mount the ~/Downloads folder as our C: drive

+ +
mount C ~/Downloads
+
+ +

Switch to the C drive

+ +
C:
+
+ +

Run the program:

+ +
example1
+
+ +

Running our program in DOSBox-X

+ +

My DOSBox setup might look slightly different than yours...

+ +
If you have scrolled this far, consider subscribing to my mailing list here. You can subscribe to either a specific type of post you are interested in, or subscribe to everything with the "Everything" list.
+ +
+ +
+
+ + + + + \ No newline at end of file diff --git a/docs/posts/index.html b/docs/posts/index.html index 4194100..2d9d613 100644 --- a/docs/posts/index.html +++ b/docs/posts/index.html @@ -52,6 +52,21 @@
    +
  • Cross-Compiling Hello World for DOS on macOS
  • +
      +
    • This goes through compiling Open Watcom 2 and creating simple hello-world exampls
    • +
    • Published On: 2024-03-15 13:16
    • +
    • Tags: + + DOS, + + x86, + + macOS + +
    + +
  • Interacting with underlying element in HTML
    • With CSS you can disable any interactions with an element and directly control the underlying element
    • diff --git a/docs/tags/DOS.html b/docs/tags/DOS.html new file mode 100644 index 0000000..3a75f5b --- /dev/null +++ b/docs/tags/DOS.html @@ -0,0 +1,73 @@ + + + + + + + + + "DOS" + + + + + + + + + + + + + + + + + + + + + +
      +
      + + +
      +

      DOS

      Posts tagged 'DOS'

      +
      + + + + + + + + \ No newline at end of file diff --git a/docs/tags/JS.html b/docs/tags/JS.html new file mode 100644 index 0000000..b01594b --- /dev/null +++ b/docs/tags/JS.html @@ -0,0 +1,73 @@ + + + + + + + + + "JS" + + + + + + + + + + + + + + + + + + + + + +
      +
      + + +
      +

      JS

      Posts tagged 'JS'

      +
      + + + + + + + + \ No newline at end of file diff --git a/docs/tags/OpenCV.html b/docs/tags/OpenCV.html new file mode 100644 index 0000000..ddaa485 --- /dev/null +++ b/docs/tags/OpenCV.html @@ -0,0 +1,73 @@ + + + + + + + + + "OpenCV" + + + + + + + + + + + + + + + + + + + + + +
      +
      + + +
      +

      OpenCV

      Posts tagged 'OpenCV'

      +
      + + + + + + + + \ No newline at end of file diff --git a/docs/tags/macOS.html b/docs/tags/macOS.html index 8b70731..028aef3 100644 --- a/docs/tags/macOS.html +++ b/docs/tags/macOS.html @@ -49,6 +49,21 @@