Using Code::Blocks for MTX Development

A request was made on MEMORUUM for:

The author has done some research and identified Code::Blocks as an IDE which provides a possible development environment, and has begun to develop a library of routines. This document outlines the installation and use of Code::Blocks. The description is aimed at Microsoft Windows users, but all the relevent programs are also available for Linux.

This is a work in progress and is subject to any feedback on the forum

Installation

The following items are required:

Install Python, SDCC and Code::Blocks in that order. Unzip MTX_Projects ina suitable location for your code development.

Configuration

The first time Code::Blocks is started, it should scan your system and identify which compilers you have. On the compiler selection screen (no screenshot available), select SDCC and then click the button to make that the default compiler. Close the dialog.

Once the main Code::Blocks window has opened, select "Settinss / Compiler..." from the menu. Ensure that "Small Device C Compiler" is selected. Then under the "Compiler settings" tab, and the "Compiler Flags" sub tag, scroll down, and check the option "[CPU] Zilog Z80 (-mz80)".

Select Z80 compiler option

Next select the "Toolchain executables" tab. Change the "Linker for static libs" from "sdcclib.exe" to "sdar.exe". Then click OK to close the dialog.

Edit linker executable

It is now possible to test the configuration by compiling the library and demonstration program. From the menu select "File / Open..." and open the "MTX_Projects\MTX_Projects.workspace" file. This will load two projects: "MTXLib" and "demo".

Code::Blocks main window

Select "Build / Build workspace" from the menu. This should:"

Demo program screenshot

This has built the library source. It is not necessary to redo this unless the library is changed.

Context Sensitive Help

The Windows version of Code::Blocks is able to provide context sensitive help. To configure this select "Settings / Environment..." from the menu. On the left hand pane of the resulting dialog, scroll down to the bottom and select "Help files". Then on the right hand side, click the "Add" button. Set the help title to "MTXLib" then click "OK".

Setting the help title

At the next dialog, select "Yes" to browse for the file location:

Browse for the file location?

Browse to select "MTX_Projects\MTXLib\docs\routines\MTXLib.html". You will have to select "All files (*.*)" in the file open dialog to find this file. Click "Open" to select the file. The full path of this file will now be shown in the edit box just below the main box. Edit this path, replacing "MTXLib" by "$(keyword)". The full path should then look something like:

      MTX_Projects\MTXLib\docs\routines\$(keyword).html
    

Check the "This is the default help file" option. Optionally (your preference) check the "Open this file with the embedded help viewer". Set the "Default keyword value to "MTXLib".

The help configuration dialog

Click "OK" to confirm the configuration and close the dialog.

Having configured this, if you open a C source file in the Code::Blocks editor, position the cursor on the name of an MTXLib subroutine, and type the <F1> key, then help on that routine will be opened.

Creating a New Program

To create a new program, select "File / New / Project..." from the menu. From the resulting dialog select "Empty Project", then click "Go".

New Project dialog

Work through the new project wizard. For the resulting RUN file to be visible to MEMU, the project title should be lower case, have no spaces and be no more than 8 characters. Create a new folder under "MTX_Projects" for the project. The name of the new folder should be the same as the title of the project.

With SDCC there seems to be little point in separate "Release" and "Debug" builds, so just select the "Release" build, and name the output directories "bin\" and "obj\".

Set new project configurations

Select your new project, then from the menu select "Project / Build options...". From the resulting dialog, select the "Linker settings" tab. Under the "Link libraries" box, click the "Add" button and browse and select "..\MTXLib\lib\MTXLib.lib". When asked "Keep this as a relative path", answer "Yes". Next, in the "Other linker options" box, paste:

      --code-loc 0x8000 ..\MTXLib\lib\crt0.rel
    
Setting link options

Select the "Search directories" tab. Select the "Compiler sub-tab. Click the "Add" button at the bottom and browse and select "..\MTXLib\include". When asked "Keep this as a relative path", answer "Yes".

Select location of include files

Next, select the "Pre/post build steps" tab. In the "Post build steps" box, paste:

cmd /c ..\MTXLib\tools\ihx2mtxrun.py $(PROJECT_DIR)$(TARGET_OUTPUT_FILE)
cmd /c ..\MTXLib\tools\mtxrun.bat $(TARGET_OUTPUT_DIR) $TARGET_OUTPUT_BASENAME).run
    

Finally, check the "Always execute, even if target is up-to-date" option. Click "OK" to close the dialog.

Setting post-build options

You may now add your C source files, and selecting "Build / Build" from the menu should compile, link and run your program.

Structure of MTX_Projects

The folder structure of "MTX_Projects" is:

Limitations

Code::Blocks is a complex program, and the author has only spent a few days using it, so with more experience it may be able to resolve some of these issues.