No return to BASIC with inline assembled parts

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cha05e90
Member
Posts: 18
Joined: Fri Jan 04, 2019 11:06 am

No return to BASIC with inline assembled parts

Post by cha05e90 »

Hello there!

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);	
}
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Re: No return to BASIC with inline assembled parts

Post by dom »

Sorry It looks like I’m taking a little break at the moment.

However, does a normal z88dk program return cleanly to basic? It should, but if it doesn’t that that’s probably the problem.

If it does, does this program work without the printfs?
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Re: No return to BASIC with inline assembled parts

Post by dom »

To answer my own questions, using Fuse/48k (no interface1 since I've not downloaded the ROMs).

1. Yes, programs can return to basic
2. Yes, it also works with the printfs

So, at the moment I can't reproduce this issue, can you let me know what version of z88dk you're using and the compile flags you're using?
cha05e90
Member
Posts: 18
Joined: Fri Jan 04, 2019 11:06 am

Re: No return to BASIC with inline assembled parts

Post by cha05e90 »

Hi, thanks for caring! :-)

For emulation I use a setup with Fuse or Spectaculator with a ZX Spectrum 48k/128k and an Interface 1 v2-Rom. It's interesting that the code seems to work for you...

ATM I'm using the nightly build from 04.02.2020 (should be one day (?) after the official v2.0 release) and this is my compile line:

Code: Select all

zcc +zx -lm -lndos ch14_z.c -och14_z.bin -zorg60000
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Re: No return to BASIC with inline assembled parts

Post by dom »

I've downloaded if2-1.rom so I can now test with if1 and it's still working.

So, I can only presume there was an issue back in February that's now fixed, so please grab a newer nightly - you'll get interbank calls, 128k TAP file and 128k +3 disc creation as additional bonuses!
cha05e90
Member
Posts: 18
Joined: Fri Jan 04, 2019 11:06 am

Re: No return to BASIC with inline assembled parts

Post by cha05e90 »

Sounds promising - I'll download a new nightly, fingers crossed. :-)
Post Reply