Using z88dk with assembler projects

Other misc things
Post Reply
User avatar
dom
Well known member
Posts: 2277
Joined: Sun Jul 15, 2007 10:01 pm

Using z88dk with assembler projects

Post by dom »

It's of course possible to use z88dk to create pure assembler projects optionally picking and choosing which library routines you may want to use.

As a simple skeleton, here's something simple for +zx:

Code: Select all

; example.asm
; zcc +zx example.asm --no-crt -create-app
	defc __crt_org_code = 30000
	org __crt_org_code

        ld      a,'A'
        rst     16
	ret
Create a .tap file using the command line at the top of the file. However this should work for pretty much all targets.

Note no crt code is invoked so the responsibility for any machine specific setup that's done by z88dk (stack, hardware etc) is passed over to your assembler code.

z88dk-appmake looks for the symbol __crt_org_code to determine the loading address and is probably the trick to getting this to work.

This works well for RAM based machines and results in code, rodata, bss, data being intermingled. For ROM based machines you'll have to define a section to contain your variables (bss) but this should be expected.

If you want to call a z88dk library routine, then locate the entry point and use `GLOBAL xxx` to import it, for example:

Code: Select all

; example.asm
; zcc +zx example.asm --no-crt -create-app
	defc __crt_org_code = 30000
	org __crt_org_code

	GLOBAL asm_strlen	;Entry: hl = string, Exit: hl = length
	
        ld      hl,mystring
        call    asm_strlen
        ret

        defm    "Hello"
        defb    0
If the library routine uses any variables then on a ROM based target you'll need to add a matching section name in your section map.
Jens
Member
Posts: 29
Joined: Sun Jul 07, 2024 11:02 am

Re: Using z88dk with assembler projects

Post by Jens »

By the way, I was looking for that but didn't find it: How do you set up banking on the assembler side? Are there standard section names? Does the linker generate/expect trampoline functions? Can you control the position of sections in the binary separately from the org?
User avatar
dom
Well known member
Posts: 2277
Joined: Sun Jul 15, 2007 10:01 pm

Re: Using z88dk with assembler projects

Post by dom »

I hope I'm answering the right question!

For banking we use pretty predictable section names:

eg for zx:

Code: Select all

    SECTION BANK_6
    org 0x060000 + CRT_ORG_BANK_6
    SECTION CODE_6
    SECTION RODATA_6
    SECTION DATA_6
    SECTION BSS_6
    SECTION BANK_6_END
eg for msx:

Code: Select all

     SECTION BANK_01
     org $010000 + CRT_ORG_BANK_01
     SECTION CODE_1
     SECTION RODATA_1
IF MSXDOS_BANKS
     SECTION DATA_1
     SECTION BSS_1
ENDIF
The "SECTION BANK_" defines the output filename, for historical reasons the +zx128 banks are decimal, but all other targets are in hex. Section names are in decimal.

Note the org address - we use 24 bit addresses where the top 8 bits embed the bank number. The org within the bank can be changed with the appropriate pragma.

Those 24 bit addresses are then used for long calls with defl providing the full address.

Code: Select all

    call.   banked_call
    defl.  far_function_pointer
Depending on the target "banked_call" is either in the crt or in library - so we have a common trampoline function for everything.

Implementation detail for far pointers is here: https://github.com/z88dk/z88dk/wiki/Mor ... c---sccz80
Jens
Member
Posts: 29
Joined: Sun Jul 07, 2024 11:02 am

Re: Using z88dk with assembler projects

Post by Jens »

Yes, you are answering the right question! I am working on a banking cartridge for SVI (using a similar trick to ZXC3 with a small CPLD to implement the logic), and I'm working on the initial menu in assembler.
User avatar
dom
Well known member
Posts: 2277
Joined: Sun Jul 15, 2007 10:01 pm

Re: Using z88dk with assembler projects

Post by dom »

Obviously these days I’m a jack-of-all-platforms rather than a specialist but I am initially surprised that MSX style mappers don’t exist on the SVI.
Jens
Member
Posts: 29
Joined: Sun Jul 07, 2024 11:02 am

Re: Using z88dk with assembler projects

Post by Jens »

AFAIK there are only three officially released cartridges, and the cartridge port is only data, address and CS. (Similar to ZX Interface 2.) There is one Flash cartridge, but that uses a counter+timer. There were definitely no commercial cartridges released with a mapper that I'm aware of.
(You could just use the expansion port to get access to all important processor pins, but that's cheating, innit? :) )
Testing goes well, so hopefully I can release it soon.
Post Reply