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 --- ...24-03-15-setting-up-macos-for-8088-dos-dev.html | 330 +++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html (limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html') 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 -- cgit v1.2.3 From f6d2141a480dd6b5b8ee0e48d43bb64773232791 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 26 Mar 2024 23:38:14 -0600 Subject: add header ids --- ...24-03-15-setting-up-macos-for-8088-dos-dev.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html') 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 index bb37d00..5fd5c48 100644 --- 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 @@ -6,13 +6,13 @@ - Cross-Compiling Hello World for DOS on macOS + id="cross-compiling-hello-world-for-dos-on-macos">Cross-Compiling Hello World for DOS on macOS - - + Cross-Compiling Hello World for DOS on macOS" /> + Cross-Compiling Hello World for DOS on macOS" /> @@ -44,12 +44,12 @@
-

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

+

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).

@@ -58,7 +58,7 @@ -

Compiling Open Watcom v2

+

Compiling Open Watcom v2

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

@@ -115,9 +115,9 @@ cp open-watcom-v2/setvars.sh custo

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

-

Hello World

+

Hello World

-

Buliding without any Makefiles

+

Buliding without any Makefiles

Create a new file called example1.c

@@ -163,7 +163,7 @@ creating a DOS If you want to test this executable, jump to the section titled Testing with DOSBox-X below.

-

Simple Makefile

+

Simple Makefile

obj = main.o hello.o
@@ -251,7 +251,7 @@ creating a DOS 
-

Using CMake

+

Using CMake

Create a file called CMakeLists.txt

@@ -289,7 +289,7 @@ creating a DOS 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

+

Testing with DOSBox-X

cp example1.exe ~/Downloads
-- 
cgit v1.2.3


From 9e620084e57378952c1a7f8e0a772ebebd18932b Mon Sep 17 00:00:00 2001
From: Navan Chauhan 
Date: Wed, 27 Mar 2024 20:35:09 -0600
Subject: quick fix

---
 docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html')

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
index 5fd5c48..7fcece6 100644
--- 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
@@ -6,13 +6,13 @@
     
     
     
-    id="cross-compiling-hello-world-for-dos-on-macos">Cross-Compiling Hello World for DOS on macOS
+    Cross-Compiling Hello World for DOS on macOS
     
     
     
-    Cross-Compiling Hello World for DOS on macOS" />
-    Cross-Compiling Hello World for DOS on macOS" />
+    
+    
     
     
     
-- 
cgit v1.2.3


From 01ff93c9c16867216f2d249664803860e1d6d5eb Mon Sep 17 00:00:00 2001
From: Navan Chauhan 
Date: Wed, 27 Mar 2024 22:49:40 -0600
Subject: generate new theme

---
 ...24-03-15-setting-up-macos-for-8088-dos-dev.html | 55 +++++++++++++++-------
 1 file changed, 37 insertions(+), 18 deletions(-)

(limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html')

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
index 7fcece6..502d4c9 100644
--- 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
@@ -2,14 +2,26 @@
 
 
     
-    
+    
+    
+    
+
+    Cross-Compiling Hello World for DOS on macOS
+
+    
+
+    
+
+    
+
     
     
     
-    Cross-Compiling Hello World for DOS on macOS
     
     
-    
     
     
     
@@ -29,21 +41,27 @@
     
     
 
-
-    
-
+ + +
-
- +

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, @@ -316,14 +334,15 @@ creating a DOS 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.
-
+
-- cgit v1.2.3 From de19543d7fb44d343b052dc9b34ede78620c4a46 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Wed, 27 Mar 2024 23:36:55 -0600 Subject: Generate --- .../2024-03-15-setting-up-macos-for-8088-dos-dev.html | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html') 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 index 502d4c9..0816934 100644 --- 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 @@ -46,7 +46,7 @@
+ +
-- cgit v1.2.3 From a982ceab0b45609991179b3020a00260eed6f798 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Wed, 27 Mar 2024 23:45:59 -0600 Subject: css --- docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/posts/2024-03-15-setting-up-macos-for-8088-dos-dev.html') 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 index 0816934..9041a1e 100644 --- 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 @@ -5,6 +5,7 @@ + Cross-Compiling Hello World for DOS on macOS -- cgit v1.2.3