Now I can call NFM like usual by
RAND USR 32768
But I can call it also with
PRINT USR 32768
or
PRINT USR 32768,"do something for me"+A$+N$(1)
The C program reads the string (or string expression) behind the "," (if given) and uses them as startup parameters.
That is the function that I use:
Code: Select all
void __FASTCALL__ zx_getCommand(char * buffer)
{
#asm
push HL
call restore81
rst $18 ; get next char
cp 26 ; ',' in zx char set?
jr nz, no_param ; no, no parameter given
rst $20
CALL $F55 ; routine SCANNING
CALL $13F8 ; routine STK-FETCH
LD H,D ; put ZX81 string pointer into HL
LD L,E ;
pop de ; get pointer to ASCII buffer
getstr:
push bc
push de
push hl
XREF zx81toasc
call zx81toasc ; convert (HL) into ASCII
pop hl
pop de
pop bc
ld (de),a ; store ASCII char in buffer
inc de
inc hl
dec bc ; count down string length counter
ld a,b
or c
jr nz, getstr
xor a ; terminate string with \0
ld (de), a
RET
no_param:
pop hl ; cleanup stack
ld (hl), 0 ; return empty string
ret
#endasm
}
Code: Select all
void main(void)
{
char loop_exit;
zx_getCommand(buffer);
if (*buffer)
{
/* a command line was given: PRINT USR ...,"command" or PRINT USR ...,C$ */
/* delete trailing " (which is necessary for the USB driver) */
...
The C program then must use a special exit function when having done its job:
Code: Select all
void C_exit() /* abort C program, cleanup stack, goto BASIC */
{
ZX81Slow();
#asm
rst 8 ; call error restart
defb $FF ; $FF: no error
#endasm
}
Of course the exit function is not complete, because it does not cleanup other ressources used by the C program (but works good in my program).
This exit routine is also useful, if the calling BASIC environment does no more exist (e. g. has been deleted or overwritten by another BASIC program).
Maybe you could add these or similar functions to z88dk to make that a standard feature for ZX81?
Siggi