Problem using custom console routine

Discussion about other targets
Post Reply
jburrell7
New member
Posts: 6
Joined: Wed Dec 16, 2015 7:16 pm

Problem using custom console routine

Post by jburrell7 »

I have an unusual use case that is not working properly. I am using Z88DK to do some C programming for an FPGA project. I have a function to print to the console screen with a prototype as follows: void jlbputs_cons(char *str); As shown, the function expects a pointer to a null terminated character string.

When I do something like: jlbputs_cons("Press any key to start\r\n") the function works as expected.

LD HL, $03DA (the address of the string)
EX (SP), HL
CALL L0100
yet more code here

L03DA:
defb "Press any key to start"
defb $0D
defb $0A
defb $00

Where things break is when I do the following:

char romFileName[] = "/cores/";
and some time later:
jlbputs_cons(romFileName);

The printed output is junk. When I look at the disassembled code, I see HL loaded with the address of the string
LD HL, $006E (address of the string)
CALL L0416
PUSH HL
CALL L0100 (address of jlbputs_cons)
and so on...

then a subroutine is called that does the following:
L0416
LD A, (HL)
LD L, A
RLCA
SBC A,A
LD H, A
RET
The modified HL is pushed to the stack and the print routine is called. I have tried all sorts of recoding but the compiler insists on munging the address. For example, I have tried jlbputs_cons((char *)romFileName); and even jlbputs_cons((char *)&romFileName[0]);
The same code is produced. I tried const char romFileName[] = "/cores/"; and the same code is generated.

AFIK the definition and usage follow standard C practice so I am at a loss as to just what is happening.
User avatar
dom
Well known member
Posts: 2267
Joined: Sun Jul 15, 2007 10:01 pm

Re: Problem using custom console routine

Post by dom »

That bit of code sign extends an 8 bit value to a 16 bit value.

I suspect we're missing a couple of diagnostics, but the way I can reproduce what you're seeing is this:

Code: Select all

extern void jlbputs_cons(char *);


int main()
{
        char roms = "/cores";
        jlbputs_cons(roms);
}
Which obviously doesn't match what you've posted.

Do you mind providing the smallest complete example that shows the problem?
jburrell7
New member
Posts: 6
Joined: Wed Dec 16, 2015 7:16 pm

Re: Problem using custom console routine

Post by jburrell7 »

Dom,
I will need to get back to you on this. Before, I could not get it to work and now I cannot get it to fail.
User avatar
dom
Well known member
Posts: 2267
Joined: Sun Jul 15, 2007 10:01 pm

Re: Problem using custom console routine

Post by dom »

No worries. We’ve all had Heisenbugs!
jburrell7
New member
Posts: 6
Joined: Wed Dec 16, 2015 7:16 pm

Re: Problem using custom console routine

Post by jburrell7 »

Dom,
Thanks for the understanding and the time you expended. I had never heard the term Heisenbug before and I plan to steal it :lol:

I have tried very hard to reproduce the bug to no effect. It must have been a typo that I did not see but fixed in my flailing around.

Please consider this 'bug' squashed.

Jeff
Post Reply