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.
Problem using custom console routine
Re: Problem using custom console routine
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:
Which obviously doesn't match what you've posted.
Do you mind providing the smallest complete example that shows the problem?
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);
}
Do you mind providing the smallest complete example that shows the problem?
Re: Problem using custom console routine
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.
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.
Re: Problem using custom console routine
No worries. We’ve all had Heisenbugs!
Re: Problem using custom console routine
Dom,
Thanks for the understanding and the time you expended. I had never heard the term Heisenbug before and I plan to steal it
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
Thanks for the understanding and the time you expended. I had never heard the term Heisenbug before and I plan to steal it

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