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.

z88dk or sdcc ?

Not sure that z88dk is going to work for me. Concern about how well the linker output can be controlled and how well it works for rommable code:

Z80 will need special consideration for placing startup code and interrupt vectors. Not seeing anything in z88dk akin to an ld script where sections and memory placement can be specified.

Noted that z88dk supports an asxxx assembler output mode, so it could work better to assemble select modules in C and integrate them with my existing asxxx project.

sdcc looks promising based on based on ASXXXX and targets many micros including Z80. Some useful Z80 specific info on the wiki and good documentation. Article on ColecoVision development.

Wednesday, March 9, 2011

z88dk Compile and Link Example

Today I want to link a C file, with an assembly module which is fixed in place, while also allowing the linker to link the CRT0 into the configuration.

Makefile:

all: test.bin

junk.o: junk.asm
zcc -o junk.o -c junk.asm

test.o: test.c
zcc -o test.o -c test.c

test.bin: test.o junk.o
zcc +rex -o test.bin test.o junk.o



$ cat junk.asm

org $8100
junk:
xor a
jp junk


However, the z88 linker has simply added my assembly module to the end of the binary image and not at $8100(excerpt...)

l8031h:
xor a
jp l8031h

Tuesday, March 8, 2011

z88dk Target

Looking at the instructions for porting the z88dk to a new machine target.. if "system is ROM based, base the startup file on lib/rex_crt0.asm"

So lets see what the rex configuration will do.. (wasn't that a pocket organizer Jerry Seinfeld gave to his father?)

The relevant example is in "z88dk\examples\rex". I created a C file test.c with only an empty main() block ... and compiled thusly:

zcc +rex -o test.bin test.c

I downloaded and compiled (under Cygwin gcc) the disassembler "z80dasm-1.1.2.tar.gz".

Ran the disassembler against test.bin and got exactly just the codes from lib/rex_crt0.asm

The custom crt0 is created in "lib" and the configuration .cfg file should be created in the lib/config directory for the target. (According to "z88dk/doc/zcc.html#config" we can create that configuration file anywhere.)

Z88DK

I started fooling around with Z88DK

Building the kit from the source distro - z88dk-src-1.9.tgz - in Cygwin on Win XP. Compiler is "gcc version 4.3.4 20090804" (Target: i686-pc-cygwin).

Following the instructions in z88dk/README.1st ... I created the following config file for my shell environment:

Z88DK=~/z88dk
export Z80_OZFILES=$Z88DK/lib/
export ZCCCFG=$Z88DK/lib/config/
export PATH=$Z88DK/bin:$PATH

In ./z88dk/src/z80asm/z80pass.c I had to change 3 references to "getline" to "mygetline" to avoid a naming conflict with getline declared in . Should change z80pass.c to make this a static instead.

Once the build completed, run make in "/z88dk/examples/embedded" to build one of the sample app.