I'm trying to include some inline-assembler to one of my little C-try-outs. while *simple* "self-contained" assembler works nicely as expected I have problems with the shown source here:
It's Andrew Pennell's assembler routine for establishing stream #14/channel "Z" for reading #14 outputs to z$. Whatever I try (even compiling it a a "normal" machine code and "call" it from my C program doesn't work. In most of the cases it never returns from the (C) machine code after the second "printf()". So I'm doing something wrong, but I could not figure out what exactly.
Is it maybe the fact that Andrews code extends the CHAN area and therefore moves the BASIC space? If I RANDOMIZE USR the compiled assembler part directly (address looked up via Spectaculator debugger) everthing works like it should - therefore I assume the culprit is something other than that...
Code: Select all
/*
Z80 asm for z88dk.
A. Pennell's "z$-channel-#14-routine"
*/
#include <conio.h>
#include <stdio.h>
#include <spectrum.h>
#include <zxinterface1.h>
#define PROG 0x5c53
#define VARS 0x5c4b
int ch14z(void)
{
#asm
SETUP:
ld hl, (PROG)
dec hl
push bc
push hl
ld bc,11
call 0x1655
pop de
ld hl, OUTCH-SETUP
pop bc
add hl,bc
push de
ex de,hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ex de,hl
ld bc,LABEL-OUTCH
add hl,bc
ld bc,9
ldir
pop hl
inc hl
ld bc,(0x5c4f)
and a
sbc hl,bc
ld (0x5c32),hl
ld bc,0
ret
LABEL:
defw 0x15c4
defm "Z"
defw 0x28
defw 0x28
defw 11
OUTCH:
push af
ld hl,(VARS)
L1:
ld a,(hl)
cp 0x5a
jr z,FOUND
cp 0x80
jp z,0x0670
call 0x19b8
ex de,hl
jr L1
FOUND:
inc hl
ld c,(hl)
inc hl
ld b,(hl)
inc bc
push bc
push hl
add hl,bc
call 0x1652
inc hl
ex de,hl
pop hl
pop bc
ld (hl),b
dec hl
ld (hl),c
pop af
ld (de),a
and a
ret
#endasm
}
int main(void)
{
printf("Start Of Routine!\n");
ch14z();
printf("End Of Routine!\n");
return (0);
}