Setting up MS-DOS on Apple Silicon – Nibbles Edition



A few weeks back, “work” asked if I would be interested in hosting a webinar on GitHub and some of the dev tools in their stack.


Been that guy, I responded “of course”. The cool thing about this “project" or shall I say webinar, is that it ties in perfectly with my Project Genie. 


Back in collage two of the courses that were part of the curriculum were MS-DOS 5 and QBasic, and just like that my age is given away... 


Nibbles is a BASIC game program basically “Snake” and was included with MS-DOS 5 up to MS-DOS 6.22 and also a game we played a lot in class.


For this project I needed the source code, I could have searched the web for the code, but me being me, I wanted to source the original code, from the original media, being 2025 that was going to fun.


Back in the day I used to have a Microsoft TechNet subscription, and lucky enough I still have the MS-DOS 6.22 image files I created back then, digital hoarder I know. 


If you need a copy of MS-DOS and found this blog post and for me to avoid the Microsoft legal team paying me a visit, I assume you know how to use a search engine. 


Also note that the nibbles program file is on the MS-DOS 6.22 supplement disk. 


Now how do I get this up and running with current technology and on M1?


MS-DOS 6.22 was written for x86 architecture, and Apple Silicon is based on ARM architecture.


In steps QEMU, QEMU is an emulator that allows you to run an operating system designed for one hardware architecture on a different, host architecture, I know I could of used UTM for macOS (QEMU backend) but wanted to go CLI vs GUI for this. 

All the below steps are performed from the terminal. 


Firstly, let’s install QEMU, for that we need to install Homebrew.

           

                Here are the instructions to install Homebrew. 

    

    Now let’s install QEMU


            % brew install qemu

 

Let me create a <projects> directory and create a <msdos> directory within it.  

Note: you can create your own directories here but make sure you drop the MS-DOS files into your <msdos> directory. 

 

    I have done the below from my Home directory


% mkdir Projects 

% cd Projects 

% mkdir msdos 

% cd msdos

 

    Now let's create the virtual hard disk.

        % qemu-img createf qcow2 msdos.disk 128M 


The above command creates a 128MB [128M] file named [msdos.disk] using QEMU’s second generation disk format [-f qcow2]


Let’s run QEMU using the above created disk.


% qemu-system-i386 hda msdos.disk -m 64 –fda Disk1.img -boot a 


The above command creates an 80386 CPU VM (x86 family) [qemu-system-i386], using msdos.disk as its first hard drive [hda msdos.disk], the virtual machine will have 64MB of RAM [-m 64] and boot Disk1.img (first MS-DOS disk) in the first floppy disk drive [–fda Disk1.img -boot a]


Let the MS-DOS installation process begin -




This is the first setup screen, press Enter.



This step is to format the virtual hard drive, press Enter.



This step will restart the virtual machine and start installing, press Enter.




This step allows you to change the regional settings, press Enter.



 

This step shows the directory where MS-DOS will be installed, press Enter. 




We now need to change to Disk 2, on the qemu-system-i386 system menu, select Machine, then select Change floppy0... point this to Disk2.img and select Open. 


-


Now we need to change to Disk 3, on the qemu-system-i386 system menu, select Machine, then select Change floppy0... point this to Disk3.img and select Open. 


To eject Disk 3, on the qemu-system-i386 system menu, select Machine, then select Eject floppy0 and press Enter.



Press Enter, to reboot the virtual machine.



MS-DOS 6.22 is now installed, now to get the nibbles.bas file. On the qemu-system-i386 system menu, select Machine, then select Change floppy0... point this to Disk4.img (supplement disk) and select Open.



 
Type a: and press Enter (This changes drives from c: [hard drive] to the a: [floppy disk drive]).



Type setup c:\dos and press Enter. (This will run the supplement disk install program and install the files on the c drive).



Press A


Press FN + F5


    Press Y


    Press Y


The supplement disk utilities are now installed and so is nibbles.


Let's run nibbles and check that it works, Type c: and press Enter, this will change from the floppy [a drive] to the hard disk [c drive].


Type cd\dos and press Enter, this will move us into the DOS directory.


Type qbasic nibbles.bas and press Enter, this will start QBasic and load the nibbles game.


You should now see the code, to play the game we need to slow down the speed of the virtual machine, on the qemu-system-i386 system menu, select Speed and then select 30%, once that is done, press FN + Shift + F5 and follow the on-screen instructions.

Note: To exit Qbasic, press the Option key then F then X.

Now that we have the original code, we need to "copy" it out of the virtual machine, so let's do that.

First exit QEMU, on the qemu-system-i386 system menu, select qemu-system-i386 and then Quit QEMU.

Now this will drop you back into Terminal, the below is all done within Terminal.

Let's create a blank disk image for us to copy the source code to -

            % dd if=/dev/zero of=mydisk.img bs=512 count=2880

The above creates a file named mydisk.img with 2880 blocks of 512 bytes each (1.44MB) filled with zeros. 

Now let's get back into the virtual machine and attach mydisk.img to the a drive.

            % qemu-system-i386 hda msdos.disk -m 64 –fda mydisk.img


We now need to format mydisk in the a drive to make it usable, Type format a: and press Enter.


Press Enter.


This step will allow you to label the disk, press Enter.


This step will let you format another disk, press N then Enter.


Let's move to the DOS directory, Type cd\dos and press Enter.



Let's now copy nibbles to the formatted "mydisk", Type copy nibbles.bas a:\ and press Enter.


You should see 1 file(s) copied, which means nibbles has been copied across, you can now quit QEMU.

 Let's mount (open) mydisk.img in macOS so we can access the nibbles.bas file, the  below is run in Terminal.

                % hdiutil attach mydisk.img 

You should now see a "NO NAME" disk on the desktop and if you double click it you should see the nibbles.bas file.


Mission accomplished, you can now copy the file across and open it in your IDE of choice, mine for this project is Visual Studio Code (vscode).



---