home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / cpmsim / srccpm / putsys.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-11  |  2.8 KB  |  111 lines

  1. /*
  2.  * CP/M 2.2 writes the CP/M systemfiles to system tracks of drive A
  3.  *
  4.  * Copyright (C) 1988-93 by Udo Munk
  5.  *
  6.  * History:
  7.  * 29-APR-88 Development on TARGON/35 with AT&T Unix System V.3
  8.  * 11-MAR-93 comments in english and ported to COHERENT 4.0
  9.  */
  10.  
  11. #include <stdio.h>
  12. #if defined(COHERENT) && !defined(_I386)
  13. #include <sys/fcntl.h>
  14. #else
  15. #include <fcntl.h>
  16. #endif
  17. #ifndef COHERENT
  18. #include <memory.h>
  19. #endif
  20.  
  21. /*
  22.  *    This program writes the CP/M 2.2 OS from the following files
  23.  *    onto the system tracks of the boot disk (drivea.cpm):
  24.  *
  25.  *      boot loader             boot.bin   (Mostek binary format)
  26.  *      CCP                     cpm.bin    (Mostek binary format)
  27.  *      BDOS                    cpm.bin    (Mostek binary format)
  28.  *      BIOS                    bios.bin   (Mostek binary format)
  29.  */
  30. main()
  31. {
  32.     unsigned char header[3];
  33.     unsigned char sector[128];
  34.     register int i;
  35.     int fd, drivea, readed;
  36.     void exit(), perror();
  37.     long lseek();
  38.  
  39.     /* open drive A for writing */
  40.     if ((drivea = open("../disks/drivea.cpm", O_WRONLY)) == -1) {
  41.         perror("file ../disks/drivea.cpm");
  42.         exit(1);
  43.     }
  44.     /* open boot loader (boot.bin) for reading */
  45.     if ((fd = open("boot.bin", O_RDONLY)) == -1) {
  46.         perror("file boot.bin");
  47.         exit(1);
  48.     }
  49.     /* read and check 3 byte header */
  50.     if ((readed = read(fd, (char *) header, 3)) != 3) {
  51.         perror("file boot.bin");
  52.         exit(1);
  53.     }
  54.     if (header[0] != 0xff || header[1] != 0 || header[2] != 0) {
  55.         puts("start adress of boot.bin <> 0");
  56.         exit(0);
  57.     }
  58.     /* read boot loader */
  59.     memset((char *) sector, 0, 128);
  60.     read(fd, (char *) sector, 128);
  61.     close(fd);
  62.     /* and write it to disk in drive A */
  63.     write(drivea, (char *) sector, 128);
  64.     /* open CP/M system file (cpm.bin) for reading */
  65.     if ((fd = open("cpm.bin", O_RDONLY)) == -1) {
  66.         perror("file cpm.bin");
  67.         exit(1);
  68.     }
  69.     /* read and check 3 byte header */
  70.     if ((readed = read(fd, (char *) header, 3)) != 3) {
  71.         perror("file cpm.bin");
  72.         exit(1);
  73.     }
  74.     if (header[0] != 0xff) {
  75.         puts("unknown format of cpm.bin");
  76.         exit(0);
  77.     }
  78.     /* position to CCP in cpm.bin */
  79.     lseek(fd, (long) 19 * 128 + 3, 0);
  80.     /* read CCP and BDOS from cpm.bin and write them to disk in drive A */
  81.     for (i = 0; i < 44; i++) {
  82.         if ((readed = read(fd, (char *) sector, 128)) != 128) {
  83.             perror("file cpm.bin");
  84.             exit(1);
  85.         }
  86.         write(drivea, (char *) sector, 128);
  87.     }
  88.     close(fd);
  89.     /* open BIOS (bios.bin) for reading */
  90.     if ((fd = open("bios.bin", O_RDONLY)) == -1) {
  91.         perror("file bios.bin");
  92.         exit(1);
  93.     }
  94.     /* read and check 3 byte header */
  95.     if ((readed = read(fd, (char *) header, 3)) != 3) {
  96.         perror("file bios.bin");
  97.         exit(1);
  98.     }
  99.     if (header[0] != 0xff) {
  100.         puts("unknown format of bios.bin");
  101.         exit(0);
  102.     }
  103.     /* read BIOS from bios.bin and write it to disk in drive A */
  104.     while ((readed = read(fd, (char *) sector, 128)) == 128)
  105.         write(drivea, (char *) sector, 128);
  106.     if (readed > 0)
  107.         write(drivea, (char *) sector, 128);
  108.     close(fd);
  109.     close(drivea);
  110. }
  111.