Is -DAMALLOC supported with 8080 ?

Post Reply
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Is -DAMALLOC supported with 8080 ?

Post by jacotton »

CFLAGS = +cpm -Wall -clib=8080 --list --c-code-in-asm -s -m -subtype=z80pack -DAMALLOC
LINKOP = +cpm -create-app -clib=8080 -subtype=z80pack -DAMALLOC
CC = zcc

zcc +cpm -create-app -clib=8080 -subtype=z80pack -DAMALLOC -ote_ansi te_ansi.o
Error at file 'free.asm' line 14: symbol '_heap' not defined
Error at file 'malloc.asm' line 16: symbol '_heap' not defined
Errors in source file /home/jay/projects/z88dk/lib/config//../..//lib/target/cpm/classic/cpm_crt0.asm:
Error at file 'free.asm' line 14: symbol '_heap' not defined
Error at file 'malloc.asm' line 16: symbol '_heap' not defined
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Is -DAMALLOC supported with 8080 ?

Post by dom »

Seems to be good for this example - maybe you've not included stdlib.h/malloc.h?

Code: Select all

#include <stdlib.h>
#include <stdio.h>

int main() {
        void *p = malloc(10);

        printf("%x\n",p);
}

% zcc +cpm malloc.c -DAMALLOC -clib=8080
%  ln -s a.bin a.com
% z88dk-ticks a.com
c723
99048
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: Is -DAMALLOC supported with 8080 ?

Post by jacotton »

This does not seem to be defined DEFINED_USING_amalloc in z88dk/lib/target/cpm/classic/cpm_crt0.asm

Your example does compile.

Here are the headers included in my case.

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
jacotton
Member
Posts: 89
Joined: Fri Nov 24, 2017 1:35 am

Re: Is -DAMALLOC supported with 8080 ?

Post by jacotton »

O.k. I got around the bug using zpgrama-include:zpragma.inc

zpragma.inc
#pragma output USING_amalloc

I think the issue is that I use multiple build command to create a binary, so the -D is not getting passed from one section to the next.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Is -DAMALLOC supported with 8080 ?

Post by dom »

Oh, sorry, I've re-read your post again, yes I know what this is.

Have a read of the first few paragraphs here: https://github.com/z88dk/z88dk/wiki/Classic--Pragmas

Basically with the one line compilation (as my example) the pragmas are kept, but with the two stage compilation you're using the pragmas are lost, so you need to use a zpragma.inc file to hold them.

The difficulty is that AMALLOC is turned on by preprocessor #define and the pragma isn't (yet) documented - they're in malloc.h so just copy the one you want and put into your zpragma.inc file.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Is -DAMALLOC supported with 8080 ?

Post by dom »

:) Bit of a crossover there, glad you solved it though!
Post Reply