Thursday, March 24, 2011

Mount Cygwin HOME directory to Ubuntu VirtualBox

This pertains to a Ubuntu VM hosted on XP - I wanted to access my Cygwin home from within the Ubuntu VM environment. After setting up the VirtualBox share folder and booting the Ubuntu VM, the share folder has been auto-magically mounted into the virtual Ubuntu filesystem. However, it seems that I can't access the mounted drive unless I do so as root. Ungood! The trick is to remount the drive and specify uid and guid:

sudo mount GNEIDERMEIER /media/sf_GNEIDERMEIER -t vboxsf -o uid=1000,gid=1000

Setting the uid/gid to that of my Ubuntu user allows me to access the mounted share without resorting to sudo or su to root.

Tuesday, March 22, 2011

Geany Customizing Syntax Highlight

Some time ago I spent most of an afternoon figuring out how to customize the Geany editor to recognize Z80 symbols in its assembly-language syntax highlighting. Most or all of this may be covered in the Geany documentation - there may be better ways to do this but here is the recap anyway.

The problem with trying to beautify assembly language is all the variations in the "syntax", so it was no surprise that I found nothing off the shelf that would display my Z80 source code just the way I wanted it. However, after looking over a bunch of editors and IDEs available under Linux, I found that Geany provided almost exactly what I needed. It offers just a little bit of IDE functionality over the plain text editor, and the syntax highlighting is easily modified by way of configuration files and requires (almost - see below) no modification to the source code. Configuration files for all the supported programming languages are found in "/usr/local/share/geany". Getting my z80 source files to look the way I wanted was just a matter of making a few small modifications to "filetypes.asm", adding the z80-specific registers, instructions, and directives specific to the asxxx assembler I am using (I should write about asxxx another time, it is pretty awesome).

Here are the instructions I added for Z80:
ld inc and jr rst ex call xor djnz bit jp or rrca dec set res cp lddr scf

And here are the Z80 registers:
a d e b c h l hl bc de

And finally, adding a couple of additional directives for my assembler, e.g. ".org .include"

... the result is a "keywords" section that looks like the following, where I leave in the existing x86 symbols or whatever was already in there:

[keywords]
# all items must be in one line
# this is by default a very simple instruction set; not of Intel or so
instructions=hlt lad spi add sub mul div jmp jez jgz jlz swap jsr ret pushac popac addst subst mulst divst lsa lds push pop cli ldi ink lia dek ldx ld inc and jr rst ex call xor djnz bit jp or rrca dec set res cp lddr scf
registers=a d e b c h l hl bc de
directives=org list nolist page equivalent word text .org .include


Finally, I came up with a change in the actual C++ code that would allow recognition of the '$' (dollar sign) hex format still used by some assemblers. (Geany already recognized '0x' as the hex designator, which is the convention of C source code).

These changes are specific to version 1.18.1, I haven't bothered to upgrade.

On line 152 of LexAsm.cxx, change...

} else if (isascii(sc.ch) && (isdigit(sc.ch) || (sc.ch == '.' && isascii(sc.chNext) && isdigit(sc.chNext)))) {
to...
} else if ( isascii(sc.ch) &&
( isdigit(sc.ch) || (sc.ch == '.' && isascii(sc.chNext) && isdigit(sc.chNext)) ||
(sc.ch == '$' && isascii(sc.chNext) /* && isdigit(sc.chNext) */) ) ) {

That's all folks!

VirtualBox

Trying out VirtualBox to run Ubuntu 10.10 on XP. Only hit one snag - 800x600 was the best monitor I could get until I added the Guest Additions, as described a bit in this post.

The GA installation actually won't work correctly unless the kernel headers are installed as described in this post. Also worth noting that Shared Clipboard function is depend upon the GA.

Tuesday, March 15, 2011

SDCC+MSX

Trolling through the sdcc mail archives for z80 info and somehow ended on a site for an MSX demo compiled with sdcc. Realized that projects for cart-based machines are a little different than a ROM on a single-program arcade machine like what I am doing. Notably, for the ROM based setup I find that the example crt0 for Z80 should work pretty well as a starting point, as it already has stubs for the z80 vectors. I already have a template project setup for the main CPU of the Galaga machine which will build the entire 16k ROM image.

Monday, March 14, 2011

SDCC Makefile

Created small test project for sdcc to target the Z80. It links a custom crt0, and explicitly sets the locations for the code and data segment. There are two C files linked. Here is the makefile:


all: ga0.bin ga0.dasm

ga0.bin: ga0.ihx
srec_cat ga0.ihx -intel -o ga0.bin -binary

junk.rel: junk.c
sdcc -mz80 -c junk.c

main.rel: main.c
sdcc -mz80 -c main.c

mycrt.rel: crt0.s
sdasz80 -l -o mycrt.rel crt0.s

ga0.ihx: main.rel junk.rel mycrt.rel
sdcc --no-std-crt0 --code-loc 0x0200 --data-loc 0x1000 \
-V -mz80 -o ga0.ihx mycrt.rel main.rel junk.rel
# -V -mz80 -o ga0.ihx main.rel junk.rel mycrt.rel

ga0.dasm: ga0.bin
z80dasm -t -g 0x0 -l ga0.bin -o ga0.dasm

clean:
rm -f *\.rel *\.ihx *\.sym *\.lst *\.map *\.noi ga0.bin *\.dasm

The file junk.c contains a constant string so that I can verify that it goes in ROM e.g.

const char testing[]= "asdf";

I disassembled the resulting binary using z80dasm and everything seems to be where it ought.

There are some helpful discussion threads on the mailing list regarding the Z80 target.

Friday, March 11, 2011

Calling sdldz80

$ sdcc -V -mz80 -o crap.ihx main.rel junk.rel
+ "/usr/local/bin/sdldz80" -nf "crap.lnk"


Also: putting code in specific address/section.
compilation & assemble:
sdcc -mmcs51 --model-small -c src1.c --codeseg src1_codeseg ----> Defines a user defined code segment "src1_codeseg"

Linking:
sdcc -mmcs51 --model-small src1.rel -Wl -bsrc1_codeseg=0x0800 ---> Specify the location of segment.
The other functions in this segment will follow the func1(). If you do not wish this, let func1() alone be the function in src1.c

Thursday, March 10, 2011

Testing sdcc

Downloaded sdcc-src-3.0.0.tar.bz2

Disable pic support which requires gputils):

./configure --disable-pic-port --disable-pic16-port

Created a couple of C files and compiled/linked - refer to the docs - file containing the main() function MUST be the FIRST file specified in the command line:

sdcc -mz80 -c junk.c
sdcc -mz80 -c main.c
sdcc -mz80 -o crap.ihx main.rel junk.rel

Create a binary:
srec_cat crap.ihx -intel -o sadf.bin -binary

Examine the binary (unused locations are filled with 0's):
z80dasm.exe -l -g 0x0 sadf.bin | less

When sdcc, the compiler front-end, calls the linker it will cause a copy of the default linker settings to be created in the working directory (file ends with ".lnk" which will show that a crt0 module has been linked from

/usr/local/bin/../share/sdcc/lib/z80/crt0.rel

The correponding source crto.S can be found here:

/usr/local/bin/../share/sdcc/lib/src/z80/crt0.s

Examination of crto.s shows that it includes the Z80 interrupt vectors.

I will use --no-std-crt0 and provide my own crt0.rel

And here apparently is how we create and use a custom linker script::
If you want to make a custom linker script, build a dummy application and copy the script generated by SDCC. Edit the file and then call the linker directly instead of using SDCC (compile the modules individually using SDCC, then link with aslink). Be careful that you copy the linker script to someplace other than your build output directory, otherwise SDCC might accidentally overwrite it.

Not having any luck yet running sdld on it's own.