Skip to content

A TCP Socket I/O Driver Framework for Z88DK

February 11, 2016

16-02-11 huzzah - a driver

The telnet server i got working is on the 1802 but i think the Z80 will better be able to handle the multi-user version.  I’m trying to establish the sockets as Z88dk stream drivers so i can use things like fopen() fprintf() etc.  On the advice of alvin from the z88dk forums I’m updating the drivers and crt I built before.

With a lot of help I have

  • added a new folder  C:\apps\z88dk\libsrc\_DEVELOPMENT\target\zmc\driver\character\zmc_00_io_sock with two files zmc_00_io_sock_ichar_msg_getc.asm and putc.asm
  • Added files zmc_00_io_sock.asm and .lst to the folder above that (…\character)
  • added invocations of the drivers to the zmc_crt_99.m4 file in C:\apps\z88dk\libsrc\_DEVELOPMENT\target\zmc\startup and run M4 to create the .asm version
  • rerun ‘winmake zmc’ in the C:\apps\z88dk\libsrc\_DEVELOPMENT folder

now I can reference SOCK0…SOCK7 in my code as below

/*
   test the socket driver framework
*/
#include <stdio.h>
extern FILE *SOCK0;extern FILE *SOCK1;extern FILE *SOCK2;
FILE* socket[3]={SOCK0,SOCK1,SOCK2};
void main()
{
	unsigned char c='*'; unsigned int i;
	printf("Hello via printf\n");
	fprintf(SOCK0,"Hello via fprintf(SOCK0)\n");

	printf("SOCK2 says:%c\n",getc(SOCK2));
	printf("SOCK1 says:%c\n",getc(SOCK1));
	printf("SOCK0 says:%c\n",getc(SOCK0));

}

For the moment the output routine just sends the output to serial and the input for socket N just returns the ascii digit N.

INCLUDE "clib_cfg.asm"
SECTION code_driver
PUBLIC zmc_00_io_sock_ichar_msg_getc
EXTERN error_mc

zmc_00_io_sock_ichar_msg_getc:

   ;   enter:  ix = & FDSTRUCT.JP
   ;    exit:  a = char after character set translation
   ;           carry set on error with hl=0 (err) or -1 (eof)
   ; can use:  af, bc, de, hl

   ;;;;; getchar here
   ;;;;; (ix+14) = socket number 0..7
;stub socket input routine always returns socket number as an ascii digit e.g. 0x30 for socket 0  
   ld A,(ix+14)	; that's it!
   or A,#0x30
   ; A = ascii code
   
   cp CHAR_CTRL_D
   jp z, error_mc              ; generate EOF
   
   cp 13
   jr z, cr
   
   cp 10
   jr z, lf
   
   or a
   ret

lf:

   ld a,CHAR_LF
   ret

cr:

   ld a,CHAR_CR
   ret
Advertisements

From → Olduino/Z, telnet

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: