[Home]Nascom 2 Notes

HomePage | RecentChanges | Preferences | My Website home page

Showing revision 14

NASCOM 2 - notes

Paul Robson has pages about the NASCOM 2. The Linux emulation is good as you have to compile it and I have a tool chain using SDCC for C code.

The NASCOM 2 site is: http://www.nascomhomepage.com/#TheNascomRepository

I have built the UNIX emulator on Ubuntu using GCC having installed enough add on packages.

Tommy Thorn has continued working on his NASCOM 2 emulator and now has a JavaScript Version. http://thorn.ws/jsnascom/jsnascom.html

( https://github.com/tommythorn/jsnascom )

He wrote the LINUX version I used below. It is being updated to load intel hex files from SDCC.

I used FIREFOX to download the emulator to my desktop, and it runs.

I added some code to the JavaScript. I added a PORT 0xA with 4 LEDs which you could set using the emulator.

( http://www.dougrice.plus.com/nascom2/JavaScript%20Nascom%202%20Emulator_files/ns_use_chrome.htm )

It needs some work to load SDCC output and the output from the assembler at http://wwwhomes.uni-bielefeld.de/achim/z80-asm.html

JavaScript NASCOM and SDCC

 usage: sdcc -V -mz80 --code-loc0x1000 --no-std-crt0 test_a.c

 The JavaScript NASCOM 2 simulator version works in Chrome / Firefox browser. ( 22/11/2014 )

 http://thorn.ws/jsnascom/jsnascom.html  
   load test_a.ihx

 The reload button allows new code to be reloaded.

 see: http://www.dougrice.plus.com/nascom2/ for files.

 It is possible to patch the JavaScript to add ports and LED [NASCOM JAVASCRIPT]? 

SDCC - Assembler

To try writing in assembler the SDCC compiler can be used. Write a C program and use the -V to get the commands. Use the .asm file as a starter.

==

http://www.dougrice.plus.com/nascom2/ has some files.

I modified xvirtualnascom.c to load other Hex file formats and the output from SDCC the small device compiler. Hello World on a Nascom emulator!

z80 assembler

I found and used this one

http://wwwhomes.uni-bielefeld.de/achim/z80-asm.html

I patched xvirtualnascom.c to load the hex files.


/*
 * ==================================================================
 * Try and add ability to read .z80 files.
 */

/* reads header of a file and tests if it's Z80 ASM file, reads address */
/* return value: 0=OK, 1=this is not a z80 asm file */
int read_header(FILE *stream,unsigned short *address, int *len)
{
 unsigned char tmp[9];
 unsigned char c[2];
 unsigned a,b;
 int ret=0;

 b=strlen(_Z80HEADER);
 tmp[b]=0;
 a=0;
 if ((fread(tmp,1,b,stream))!=b) ret=1;
 else if (strcmp(tmp,_Z80HEADER)) ret=1;
 else if (fread(c,1,2,stream)!=2) ret=1;
 else
 { *address=(c[1]<<8)|c[0]; a=b+2; }
 fseek(stream,0,SEEK_END);
 b=ftell(stream);
 fseek(stream,a,SEEK_SET);
 *len=b-a;
 return ret; 
}

unsigned  dma_write(unsigned short offset, unsigned count, FILE *from)
{

/* return  fread(memory+offset,1,count+offset<65536U?count:65536U-offset,from); */
   return  fread(ram+offset,1,count+offset<65536U?count:65536U-offset,from);

}

unsigned  dma_read(unsigned short offset, unsigned count, FILE *to)
{
/* return  fwrite(memory+offset,1,count+offset<65536U?count:65536U-offset,to); */
   return  fwrite(ram+offset,1,count+offset<65536U?count:65536U-offset,to);
}


int load_nascom_new(char *file) {
   unsigned short start;
   
   int x ; /* length */
   printf("load_nascom_new(char *file)");
   FILE *stream = fopen( file,"rb");
   
   if (!stream) {
	   stream=0;
	   /* error_msg(file,"Can't read file"); */
       printf("error load_nascom_new(char *file)");

	   return 0;
   }
   if (read_header(stream,&start,&x)) {
     fclose(stream);
     printf("error read hearer load_nascom_new(char *file)");

	 return 0; /* error */
   } else {
     dma_write(start,x,stream);
     fclose(stream);
     stream=0;
   }
   return 1  ;
}

void load_nascom(char *file)
{
  FILE *f ;	
	
  if  ( ! load_nascom_new( file) ) {	
	
  f = fopen(file, "r");
  int a, b1, b2, b3, b4, b5, b6, b7, b8;
  int count = 0;
  int ch;

  if (!f) {
    perror(file);
    exit(1);
  }

  if (vflag) printf("Loading %s", file);
  for (;!feof(f);) {
    if (fscanf(f, "%x %x %x %x %x %x %x %x %x",
	       &a, &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8)
	== 9) {
      RAM(a)   = b1;
      RAM(a+1) = b2;
      RAM(a+2) = b3;
      RAM(a+3) = b4;
      RAM(a+4) = b5;
      RAM(a+5) = b6;
      RAM(a+6) = b7;
      RAM(a+7) = b8;
      count += 8;
    }

    do 
    ch = fgetc(f); 
    while (ch != -1 && ch != '\n');
    if (ch == -1)
      break;
    }
    fclose(f);
    if (vflag) printf(". Successfully loaded %d bytes\n", count);
  }
}

SDCC

SDCC is the Small device compiler.

see: http://sdcc.sourceforge.net/

I used SDCC to build some C code to run on the Nascom.

I need to patch the putchar() function to use the NAS-SYS routines so that printf works.

/*
*
* usage: sdcc -mz80 --code-loc0x1000 --no-std-crt0 test.c
* gcc -Wall -c "%f"
*
*/
#include <stdio.h>

/* code seems to start here, when I run E1000 */

main(){
  printf("Hello World!");
  return 1 ;
}

void putchar( char x ){
/* call nascom software interupt */  
	__asm
	;x = x +1; use first parameter
	;ADD A	, #10;
  	RST	0x30;  		
	__endasm;
}

I needed to modify the xvirtualnascom.c to load .ihx files.


/*
 * :0E 1000 00 210C10E5CD5F10F1210100C96865 DB
:0E 100E 00 6C6C6F20646F75670A00DDE5DD21 F4
:07 101C 00 0000DD39DDE1C9 30
:0E102300DDE5DD210000DD39DD7E04F533CD95
:0E103100181033DDE1C9DDE5DD210000DD39F9
:0E103F00DD6E06DD6607E5DD6E04DD6605E5A7
:0E104D00210000E5212310E5CDE611F1F1F1BF
* 
*/

int load_nascom_ihx(char *file) {
   unsigned short start;
   
   int x ; /* length */
   uint hex_read, hex_len, hex_addr, hex_cmd ;
   uint hex_count, hex_data, hex_check ;
  
   FILE *stream = fopen( file,"rb");
   printf("load_nascom_ihx(char *file)");
   
   if (!stream) {
	   stream=0;
	   /* error_msg(file,"Can't read file"); */
       printf("error load_nascom_ihx(char *file)");

	   return 0;
   }
   while ( !feof( stream ) ) {
     
   /*:0E 100E 00 6C6C6F20646F75670A00DDE5DD21 F4 */
      
     hex_read = fscanf(stream,":%2x%4x%2x",&hex_len,&hex_addr,&hex_cmd);
     if (hex_read ){
       printf( "\n%x  %2d, %2d, %x  : ", hex_read, hex_len, hex_addr, hex_cmd );
      
     
       for( hex_count= 0 ; hex_count < hex_len ; hex_count++ ){
	     hex_read = fscanf(stream, "%2x",&hex_data ); 	  
         printf(" %02X", hex_data );
         RAM( hex_addr ) = hex_data ; 
         hex_addr ++;
       }    
       hex_read = fscanf(stream, "%2x\n",&hex_check);
     }
   }
   fclose(stream);
   stream=0;
   printf(" exit from load_nascom_ihx()\n");
   /* hex_read = getchar() ; */
   return 1  ;
}

Selecting SDCC or Assembler code is done by selecting the right loader functions

extern char *optarg;
extern int optind, opterr, optopt;
int getopt(int argc, char * const *argv, const char *optstring);

int main(int argc, char **argv)
{
  int c;
  
  progname = argv[0];

  xsetup(1, argv);
    

#ifdef MMU
  for (c=0; c<MEMSIZE/4; ++c) pagetable[c]=ram+(c<<12);
#endif

  while ((c = getopt(argc, argv, "m:v")) != EOF)
    switch (c) {
    case 'm':
      monitor = optarg;
      break;
    case 'v':
      vflag = 1;
      break;
    case '?':
      usage();
    }

  if (vflag)
    puts("VirtualNascom, a Nascom 2 emulator version " VERSION "\n"
	 "Copyright 2000 Tommy Thorn.  Based on\n"
	 "Yet Another Z80 Emulator version " YAZEVERSION
	 ", Copyright 1995,1998 Frank D. Cringle.\n"
	 "NasEmu comes with ABSOLUTELY NO WARRANTY; for details\n"
	 "see the file \"COPYING\" in the distribution directory.\n");

  /* load my file first ast it starts from 0 */
  /* load_nascom("../z80-asm-2.4-pre3/programs/doug.z80"); /* */
  
  /* load c program built using SDCC */
  load_nascom_ihx( "../sdcc/test.ihx" ); /* */
  load_nascom(monitor);
  /* load_nascom("basic.nal"); */
  /* load_nascom("doug.z80"); /* */


  for ( ; optind < argc; optind++)
    load_nascom(argv[optind]);

  /* simz80(pc, 20, xhandleevent); */
  /* draw the screen a lot more to slow down the key repeat */
  simz80(pc, 1, xhandleevent);
  /* we need to check for reset */
  

  fprintf(stderr,"HALT\n\r");
  fprintf(stderr,"PC   SP   IR   IX   IY   AF   BC   DE   HL   AF'  BC'  DE'  HL'\n\r");
  fprintf(stderr,"%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n\r",pc,sp,ir,ix,iy,af[af_sel],regs[regs_sel].bc,regs[regs_sel].de,regs[regs_sel].hl,af[1-af_sel],regs[1-regs_sel].bc,regs[1-regs_sel].de,regs[1-regs_sel].hl);
  exit(0);
}

Conclusion

Here are a few notes about some dabbles with emulating the NASCOM 2 and using an assembler or SDCC compiler


HomePage | RecentChanges | Preferences | My Website home page
This page is read-only | View other revisions | View current revision
Edited November 22, 2014 9:41 am by dougrice.plus.com
Search: