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 --- 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 +++++ 12 files changed, 955 insertions(+), 21 deletions(-) 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 (limited to 'docs') 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 @@