Enlarge SDCC's stack

Pagina 3/4
1 | 2 | | 4

Van sp4

Master (214)

afbeelding van sp4

06-02-2015, 17:23

I put "extern" infront to the prototipe as follow:

extern void signal(char channel, int frequency, int volume);
extern void noise(char channel, int fnoise, char chnoiseen);
extern void play(unsigned char *stringA,  unsigned char *stringB, unsigned char *stringC);

and the problem didn't disappear.
Why?

Van Alcoholics_Anonymous

Resident (39)

afbeelding van Alcoholics_Anonymous

06-02-2015, 17:44

sp4 wrote:

and the problem didn't disappear.
Why?

@echo -------------- compilermessages -----------------
@sdcc -mz80 -c app.c
@rem  sdcc in linker mode, only tell .rel files in this line, no .c, no .asm
@sdcc -mz80  --no-std-crt0  --code-loc 0x4000 --data-loc 0xc000 -o linkresult.ihx crt0msxrom.rel app.rel  play.rel sound.rel
@echo -------------------------------------------------
@hex2bin 4000 linkresult.ihx
@copy linkresult.bin ROM.ROM

Are you including "play.h" in app.c? Make sure the whole thing is compiling, including play.rel. "play.rel" must include GLOBAL declarations for its local functions -- it should happen without the externs but to be safe...

Inside play.c:

void set_time(int channel)
{
    time[channel]=(float)60/(mus+channel)->tim;   
    time[channel]=time[channel]/0,020; 
}

... must use decimal points '.' Smile

Van sp4

Master (214)

afbeelding van sp4

06-02-2015, 18:12

I included play.rel and sound.rel inside the project and this is my comp.bat:

@echo -------------- compilermessages -----------------
@sdcc -mz80 -c app.c
@sdcc -mz80 -c play.c
@rem  sdcc in linker mode, only tell .rel files in this line, no .c, no .asm
@sdcc -mz80  --no-std-crt0  --reserve-regs-iy  --code-loc 0x4000 --data-loc 0xc000 -o linkresult.ihx crt0msxrom.rel app.rel  sound.rel play.rel 
@echo -------------------------------------------------
@hex2bin 4000 linkresult.ihx
@copy linkresult.bin ROM.ROM

When I compile and execute the program the problem don't disappear.
Why?

Van Alcoholics_Anonymous

Resident (39)

afbeelding van Alcoholics_Anonymous

06-02-2015, 18:20

Can you put app.c into the download zip as well? It seems like there is no include of play.h inside app.c

Van Grauw

Ascended (10639)

afbeelding van Grauw

06-02-2015, 18:21

@ Alcoholics_Anonymous Thanks for the info. I thought so about ix, that's why the code in the earlier thread wasn't working. But er, I read that the first argument was passed in hl, and you only needed the stack for the additional arguments? Or does it both store the 1st argument on the stack and pass it? Also, return value being in l, hl or dehl, right?

Van sp4

Master (214)

afbeelding van sp4

06-02-2015, 18:25

Alcoholics_Anonymous wrote:

Can you put app.c into the download zip as well? It seems like there is no include of play.h inside app.c

my app.c:

#include "sound.h"
#include "play.h"


extern int x, y, a, b, ray, col;

void (*function)() = (void (*)())0xc0;

void main()
{
  color(5,15,5);
  screen(8);
 
  a=50;
  b=50;
  ray=20;
  col=5;
  circle();
  while(1){};
}

Van Alcoholics_Anonymous

Resident (39)

afbeelding van Alcoholics_Anonymous

06-02-2015, 18:48

Grauw wrote:

@ Alcoholics_Anonymous Thanks for the info. I thought so about ix, that's why the code in the earlier thread wasn't working. But er, I read that the first argument was passed in hl, and you only needed the stack for the additional arguments? Or does it both store the 1st argument on the stack and pass it? Also, return value being in l, hl or dehl, right?

No there are no guarantees about what registers will hold what before the call. sdcc will try to minimize the amount of work it does to gather parameters which means different register pairs might be used to hold the values as they are pushed. I've seen values in bc, de, hl although there is a tendency to have the first param in de for vararg functions and hl otherwise. Don't forget there is a peephole optimizer step after the compile which could again change things.

Here's one code snippet where the first param is in hl:

;   printf("ENTER UP TO %u LINES OF TEXT.\n", sizeof(strings) / sizeof(unsigned char *));
	ld	hl,+___str_0
	ld	bc,+0x0014
	push	bc
	push	hl   ;;;;;;;;;;;; <- first param in hl
	call	_printf
	pop	af
	pop	af

Here's another where it isn't:

;       if ((getline(&strings[i], &sz, stdin) == -1) || (sz <= 2))
	ld	hl,+_strings
	add	hl,de
	ld	e, l
	ld	d, h
	ld	hl,+_stdin
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	push	hl
	ld	hl,+_main_sz_1_221
	push	hl
	push	de  ;;;;;;;;;;;;;;;; <- first param in de
	call	_getline
	pop	af
	pop	af
	pop	af

But yes the return values are in L, HL, DEHL. I'm not sure how float works; longlong (64-bit) is treated specially - for return values there is a hidden pointer pushed on the stack just before the return address where the returned longlong should be written. If passed as parameter I think a longlong gets an 8-byte push.

Van Alcoholics_Anonymous

Resident (39)

afbeelding van Alcoholics_Anonymous

06-02-2015, 18:46

sp4 wrote:

When I compile and execute the program the problem don't disappear.
Why?

Ah okay so we're passed this error?

?ASlink-Warning-Undefined Global '_play' referenced by module 'app'

That's the one I was focussed on. What's the new problem?

Or maybe I misunderstood... if you are still getting that error can you post a link to "sound.h" as well?

Van Grauw

Ascended (10639)

afbeelding van Grauw

06-02-2015, 19:38

Interesting, thanks for sharing.

Van sp4

Master (214)

afbeelding van sp4

06-02-2015, 20:23

Alcoholics_Anonymous wrote:
sp4 wrote:

When I compile and execute the program the problem don't disappear.
Why?

Ah okay so we're passed this error?

?ASlink-Warning-Undefined Global '_play' referenced by module 'app'

That's the one I was focussed on. What's the new problem?

Or maybe I misunderstood... if you are still getting that error can you post a link to "sound.h" as well?

My sound.c:

#include "sound.h"

/*function for put a value in PSG register*/
void sound(char reg, unsigned char val)
{
  di();
	out(0xa0,reg);
	out(0xa1,val);
	ei();
}

/*function for retrive a value of the register put in the first parameter*/
char get_PSG_REG(char reg)
{
 __asm
 ld a, 4(ix)
 out(0x00A0), a
 in a, (0x00A2)
 ld l, a
 __endasm;
}

//function for generate a beep
void beep(void){
    __asm
         call 0x00c0   ; ---> BIOS call for sound a beep
    __endasm;
}

void di() __naked {
	__asm
	di
	ret
	__endasm;
}


void ei() __naked {
	__asm
	ei
	ret
	__endasm;
}


void halt() __naked {
	__asm
	halt
	ret
	__endasm;
}


void out(char port, char n) __naked {
	port; n;

	__asm
	pop hl
	pop bc
	push bc
	out (c),b
	jp (hl)
	__endasm;
}

and this is my sound.h:

void sound(char reg, unsigned char val);
char get_PSG_REG(char reg);
void beep(void);
void di() __naked;
void ei() __naked;
void halt() __naked;
void out(char port, char n) __naked;
Pagina 3/4
1 | 2 | | 4