articles
Cross-dev under Linux
Written by Krusty on 15 January 2012
... Very fast introduction in editing with vim
The editor is one of the most important software (even more important than the assembler), because it is the application you will use the more often. Indeed you spend more time to write code than to assemble it! One very good choice is VIM (Message to Eliot, it also works on windows). If you do not know this editor, you have to understand that the learning curve is quite difficult. But when you have experimented DAMS, you are ready to use any kind of editor ;)

This very short article will not interest a lot of people, but it can help a lot newcomers (or myself if I need to change my machine...).

Basic Editing
If you do not know this editor, you have to understand it works in two main modes: the editing mode and the command mode (this may not be disturbing for DAMS users).

- You can access the editing mode by pressing [ESC] i from the command mode.
- You can access the command mode by pressing [ESC] from the editing mode.

It will be too long to explain how this editor works because so much powerful that it is hard to know everything... This page seems to explain very well how to use it.

Syntax Highlighting
By default, the editor is not able to do syntax highlighting of a z80 source. Copy this file in the folder syntax in the configuration folder of them (i.e., ~/.vim/syntax): it gives all the required informations to analyze the various elements of the sources in order to color them. Of course, DAMS is not able to do that. Syntactic coloration does not help you to code better, but it gives a better coding experience less boring than a monochrome screen.

The specifications of the highlighting correspond to a source for the Sjasmplus assembler, but they can be easily modified to match your assembler. It is necessary to inform vim which files are z80 files. You must add the following lines to your vimrc configuration (i.e., ~/.vimrc) in order to consider all the file with .z80, .src or .asm extension as z80 files:
au BufRead,BufNewFile *.z80		set filetype=z80 
au BufRead,BufNewFile *.src set filetype=z80
au BufRead,BufNewFile *.asm set filetype=z80


Without and with syntaxic coloration
Without and with syntaxic coloration


Code folding
It can be interesting to fold your code. This allows you to virtually reduce the height of your source code (in number of lines), by hiding pieces of code you are not working with them. This is done by configuring z80 files with:
set foldmethod=marker

To do that, copy this file in ~/.vim/ftplugin/. It contains all the configuration parameters specifics to a z80 source file. I have also configured it to display line numbers, highlight the current line, indent automatically code (for DAMS user, indentation allows to build visual blocs of code having a particular meaning, in order to ease the understanding of the code) and specify the size of the tabs. Basically, when the cursor is inside a zone with the folding markers: "{{{" and "}}}", typing "zc" or "zo" close or open the fold. You can find more information about folding here.

Folded code closed
Folded code closed


Folded code opened
Folded code opened


Tag navigation in the source file
Vim allows you to manipulate tags inside your source code. Basically tags are informations generated from your source code allowing to navigate inside: from a function call, you can jump to the function definition (cursor on the called label, then CTRL+K). This way, you have not to manually find your line of interest. With a specific extension (explained later in the text), you can even see the whole tag list in a window of your editor and ask to jump at its definition by double-clicking on it. The tags are automatically generated by vim thanks to a third party software called exhuberant ctags. So, you must install it : ctags.sourceforge.net. Sadly this tool does not understand assembly files, so it is necessary to configure it. Copy past these lines in a file named ~/.ctags (create it if necessary):
--langmap=z80:.asm 
--regex-z80=/^([a-zA-Z][a-zA-Z0-9_]*)/\1/l,label/
--regex-z80=/^([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]+[eE][qQ][uU][[:space:]]/\1/d,define/
--regex-z80=/[[:space:]]*macro[[:space:]]+([a-zA-Z_0-9]*)[[:space:]]*/\1/m,macro/

It allows to get three types of tags:

- the labels
- the definitions (labels before equ)
- the macros

To be able to graphically browse the tags, it is necessary to install the vim extension Tagbar and configure it like that (in the .vimrc file):
let g:tagbar_type_z80 = { 
\ 'ctagstype' : 'z80',
\ 'kinds' : [
\ 'd:define',
\ 'l:label',
\ 'm:macro',
\ ],
\ 'sort' : 1,
\}

" Open tagbar for cpc files
autocmd BufEnter *.asm nested TagbarOpen

These configuration lines explain how to display the tag list and ask to always display it when opening a z80 file. You can find more information about tags here.

Illustration of the tag utilisation
Illustration of the tag utilisation


EOF
Feel free to give me more informations on vim or ctags configurations if necessary. I have not talked about assembling files because there are too many available assemblers, more or less compatible and complex, and I have not yet made a clear choice on what is the best to use. Anyway, automatically building explanations for a whole project from the sources can be a future article (i.e., phactory without graphical interface with 100% unix tools ;) ).

Read the 9 comment(s) about this article
Online: TotO
Kill All Humans!