home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / z / zsim20.zip / Z80EXMPL.C < prev    next >
C/C++ Source or Header  |  1992-12-02  |  2KB  |  73 lines

  1.  
  2. /*
  3.   example c program to use the Z80 simulator without cpmbios
  4.  
  5.   (c) 1992 Jürgen Weber
  6.            Wiesentalstraße 1
  7.            7170 Schwäbisch Hall
  8.            Germany
  9.  
  10.   tcc -ml z80exmpl.c z80iface.obj Z80EMU.OBJ
  11.  
  12.   Z80EMU.OBJ contains the machine code of the Z80 simulation
  13.   z80iface.asm is an assembler interface between the emulation
  14.   and a c program that uses Z80EMU
  15.  
  16.   usage of Z80EMU.OBJ within your code is allowed
  17.   only for private purposes.
  18.   If you want to sell a program that contains
  19.   Z80EMU.OBJ contact me first.
  20.  
  21. */
  22.  
  23. #include <alloc.h>
  24. #include <dos.h>
  25.  
  26. _emulate(unsigned z80seg,
  27.           void far (*calln_handler)(int far *),
  28.            void far (*halt_handler)(void));
  29.  
  30. void far halt_handler(void)
  31. {
  32.     puts("halt_handler called");
  33. }
  34.  
  35. void far calln_handler(int far *regs) /* *regs can be changed */
  36. {
  37. /* AH=undef, AL=xx in ED ED xx, BX=HL, CX=BC, DX=DE, SI=PC */
  38.     printf("calln executed, AX=%x, BX=%x, CX=%x, DX=%x, SI=%x\n",
  39.             regs[0],regs[1],regs[2],regs[3],regs[4]);
  40.     regs[1]++;
  41. }
  42.  
  43. void main()
  44. {
  45.  char far *p;
  46.  unsigned z80seg;
  47.  
  48.  if((p=farmalloc(65536l+15l))==NULL) {
  49.     puts("Not enough memory.");
  50.     exit(1);
  51.  }
  52.  z80seg=FP_SEG(p);
  53.  if (FP_OFF(p)) z80seg++; /* Add one paragraph, o.k. because +15l */
  54.  p=MK_FP(z80seg,0);
  55.  /* now it would be a good idea, to clear
  56.     the 64K Z80 space */
  57.  
  58. /* if you use the banked version you could set the banking this way */
  59.  setcfg(z80seg,0,z80seg,0);
  60.  
  61.  /* Enter some z80 codes */
  62.  *p++=0x76; /* HALT */
  63.  *p++=0xed; /* CALLN 0 */
  64.  *p++=0xed;
  65.  *p++=0x00;
  66.  *p++=0xed; /* CALLN 0xff to end emulation */
  67.  *p++=0xed;
  68.  *p++=0xff;
  69.  emulate(z80seg,calln_handler,halt_handler);
  70.  printf("returned from emulation\n");
  71. }
  72.  
  73.