{"id":9981,"date":"2025-03-19T03:00:00","date_gmt":"2025-03-19T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=9981"},"modified":"2025-03-20T09:07:27","modified_gmt":"2025-03-20T13:07:27","slug":"old-school-programming-with-turbo-c","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=9981","title":{"rendered":"Old-school programming with Turbo C"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"9981\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">1    <\/span>\r\n<\/div><\/div>\n<p>These days, <em>retrocomputing<\/em> is a popular topic. It\u2019s fun to explore old systems and experience what it was like to run classic systems like DOS. DOS had a lot of great applications and games, which is why it had such staying power during it\u2019s time. A growing trend is <em>retroprogramming<\/em> where developers create programs on these retro systems using classic tools, with all the limitations that go with running an operating system from the 1980s.<\/p>\n\n\n\n<p>During the 1980s and in the 1990s, one popular development platform for building DOS applications was <em>Borland Turbo C<\/em> and <em>Turbo C\/C++<\/em>. Some years ago, Borland released both of these (plus <em>Turbo Pascal<\/em>) for free via their \u201cMuseum\u201d website. Later, Embarcadero acquired Borland, but maintained the Museum, now under the name \u201cCode Central.\u201d You can still find these classic programs on the CC website, but you\u2019ll need to set up a free account to download them. Both Turbo C 2.01 and its successor, Turbo C\/C++ 1.01, are listed on the CC <a href=\"https:\/\/cc.embarcadero.com\/PopularDownloads.aspx\">popular downloads<\/a> page, for example.<\/p>\n\n\n\n<p>Borland C\/C++ 1.01 runs great on FreeDOS, although you may need to disable APM with <code>FDAPM \/off<\/code> at the command line. Note that the four arrow keys may produce a \u201cdouble tap\u201d effect, as though you hit an arrow key twice, depending on your system. This is due to a mix of how the keyboard BIOS worked in later systems and how Borland&#8217;s TurboVision managed keyboard input. Using the arrow keys on the ten-key keypad instead is one workaround. If you use QEMU, you can also add <code>-global i8042.kbd-throttle=on<\/code> to the QEMU command line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exploring-turbo-cc\">Exploring Turbo C\/C++<\/h2>\n\n\n\n<p>Released in February 1991 (but with a 1990 copyright date) Borland\u2019s Turbo C\/C++ was a modern development system. More than just a compiler, Turbo C\/C++ provided an integrated development environment in a small package.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2025\/03\/tcpp101.webp\" alt=\"Turbo C\/C++ 1.01 running on FreeDOS\" class=\"wp-image-9982\"\/><\/figure>\n\n\n\n<p>Turbo C\/C++ included a comprehensive help system with a searchable index. For example, if you wanted to write a program that involved text windows with colors (defined in <code>conio.h<\/code>) you could bring up the help index and press <strong>C<\/strong> to jump ahead to the topics starting with that letter, including the \u201c<strong>c<\/strong>onio.h\u201d entry. Navigate to the topic you want to learn about using the arrow keys or tab, and hit Enter to see details.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2025\/03\/tcpphelp.webp\" alt=\"Showing the \u2018conio.h\u2019 entry\" class=\"wp-image-9983\"\/><\/figure>\n\n\n\n<p>The comprehensive help system also included code samples. Continuing with my previous example, you could navigate to the \u201cwindow\u201d topic to show its syntax, notes, related items, and a programming example.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2025\/03\/tcpphelp2.webp\" alt=\"Program example for the \u201cwindow\u201d topic\" class=\"wp-image-9984\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"application-development\">Application development<\/h2>\n\n\n\n<p>Writing programs in Turbo C\/C++ is a breeze. The IDE follows the PC user interface guidelines that made many DOS applications feel immediately familiar: hit the Alt key to activate the menu, or Alt and a highlighted letter to open a menu, like Alt+F to open the <strong>F<\/strong>ile menu. Navigate through menu items using the up\/down arrow keys, or between top-level menus with the left\/right arrow keys. Press Enter on a menu item to use it.<\/p>\n\n\n\n<p>Write your program in the editor and you can compile it using the <strong>C<\/strong>ompile menu. If the build was successful, you\u2019ll see a \u201cSuccess\u201d message, then you can run your program with the <strong>R<\/strong>un action to see if everything works correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2025\/03\/tcppbuild.webp\" alt=\"Compiling a program using the IDE\" class=\"wp-image-9985\"\/><\/figure>\n\n\n\n<p>You can do all of that without leaving the IDE. That\u2019s peanuts in today\u2019s development environments\u2014but consider that Turbo C\/C++ comes from an era when computers measured memory in <em>megabytes<\/em>, like 16 MB or even 32 MB if you had a lot of money to invest in a computer. Similarly, computers of that age might have had a hard disk that was around 100 MB. My computer in 1990 had an 80 MB hard drive, which I later upgraded to 120 MB in 1991. Yet the Borland IDE\u2014including the compiler, libraries, debugger, tools, and help system\u2014required only about 5.8 MB of disk space.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-test-program-in-turbo-cc\">A test program in Turbo C\/C++<\/h2>\n\n\n\n<p>Writing DOS programs in Turbo C\/C++ is otherwise the same as any other DOS compiler. Note that due to when it was released, Borland C\/C++ 1.01 on supports \u201cANSI C\u201d programming; the original ANSI C standard was ratified in 1989 and published in 1990, so Borland was an early adopter of ANSI C on DOS.<\/p>\n\n\n\n<p>A neat feature in DOS was direct access to video memory using the <code>conio.h<\/code> family of functions. This allowed programs to manipulate the screen very quickly, such as to create text windows and menus. With <code>conio.h<\/code> on Turbo C\/++, you could call the <code>window<\/code> function to define a region on the screen to use as a \u201cwindow,\u201d and set text color with <code>textcolor<\/code> and background colors using <code>textbackground<\/code>. If you defined a window and set a background color, the <code>clrscr<\/code> function would clear the window with that background color. Other functions defined input and output on the console, like <code>getch<\/code> to read a key from the keyboard buffer.<\/p>\n\n\n\n<p>Here\u2019s a sample program to define a small window on the screen, filled in white, then print some red text. This demonstrates several features available through <code>conio.h<\/code> and provides a quick-start to write your own DOS programs:<\/p>\n\n\n\n<p>Note that the Borland <code>conio.h<\/code> implementation doesn\u2019t reset the text window to the full screen upon exit. You need to restore the text window on your own; I\u2019ve written a <code>clearscreen<\/code> function to make that easier.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;conio.h&gt;\n\nvoid clearscreen()\n{\n    window(1,1,80,25); \/* default win *\/\n    textcolor(7);\n    textbackground(0);\n    clrscr();\n}\n\nint main()\n{\n    clearscreen();\n\n    \/* make a window *\/\n\n    window(30,10,50,15); \/* left, top, right, bot *\/\n    textbackground(7); \/* white *\/\n    clrscr(); \/* win *\/\n\n    \/* print some text *\/\n\n    textcolor(4); \/* red *\/\n    cputs(\"hello world\");\n\n    \/* done *\/\n\n    getch();\n\n    clearscreen();\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2025\/03\/tcpprun.webp\" alt=\"Running the test program\" class=\"wp-image-9986\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Explore retroprogramming on FreeDOS with this popular freeware IDE.<\/p>\n","protected":false},"author":33,"featured_media":3514,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[340,150],"tags":[267,152],"class_list":["post-9981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freedos","category-programming","tag-freedos","tag-programming"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9981"}],"version-history":[{"count":2,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9981\/revisions"}],"predecessor-version":[{"id":10010,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9981\/revisions\/10010"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3514"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}