home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / FD10.ZIP / fd.c < prev    next >
C/C++ Source or Header  |  1995-05-15  |  12KB  |  485 lines

  1. /*
  2.  * FD.C    version 1.0    by Darren Bane (c) 1995 All rights reserved.
  3.  * 
  4.  * Legal Stuff
  5.  * 
  6.  * This program is free software; you can redistribute it and/or modify it under
  7.  * the terms of the GNU General Public License as published by the Free
  8.  * Software Foundation; either version 2 of the License, or (at your option)
  9.  * any later version.
  10.  * 
  11.  * This program is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14.  * more details.
  15.  * 
  16.  * You should have received a copy of the GNU General Public License along with
  17.  * this program; if not, write to the Free Software Foundation, Inc., 675
  18.  * Mass Ave, Cambridge, MA 02139, USA.
  19.  * 
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <file.h>
  24. #include <window.h>
  25. #include <freedos.h>
  26. #include "yerror.h"    // This line must come before ctrl_c.h so that word is
  27. // declared
  28. #include "ctrl_c.h"
  29.  
  30. #define DRVE            0x0001    /* Masks for isolating status bits */
  31. #define DRV_MASK        0x00c0    /* Bits to mask off no of disk drives */
  32. #define DRV_SHIFT       0x06
  33. #define PRN_SHIFT       0x0E
  34. #define EQUIPCK         0x11    /* Check equipment function */
  35. #define VIDEO           0x0030    /* Mask to find initial video mode */
  36. #define EGA             0x0000    /* Determines EGA monitor fitted */
  37. #define BW4025          0x0010/* Determines if Black/White 40x25 */
  38. #define BW8025          0x0020/* Determines if Black/White 80x25 */
  39. #define HERC            0x0030    /* Determines if Monochrome Hercules */
  40. #define MAXPATH         0x51    /* Maximum path length */
  41. #define TRUE 1
  42.  
  43. /*
  44.  * Default LONG number size is 4 bytes (32 bits). If you wish to change this
  45.  * (up to 256 bits), edit the 'LSIZE EQU 4' in the LONGMATH.ASM file in the
  46.  * library. You also have to adjust the sizes of all array declarations which
  47.  * are to contain LONG numbers. For this demo, just adjust the constant
  48.  * defined below.
  49.  */
  50.  
  51. #define    LSIZE    4        /* 32 bit numbers */
  52.  
  53. /* Color index's for different window types */
  54. #define    MENU    0
  55. #define    TEXT    1
  56. #define    PAUSE    2
  57.  
  58. void            cleanup(void);
  59. void            long_to_string();
  60. void            System_Information(void);
  61. void            Disk_Information(void);
  62. void            title();
  63. void            pause(void);
  64. word            biosmemory(void);
  65. word            get_equip(void);
  66. byte            test_drive(byte drive);
  67.  
  68. /*
  69.  * This temporary variable used by the LONGMATH functions is useful, because
  70.  * it will contain the remainder after a division.
  71.  */
  72. extern char     Longreg[];
  73.  
  74. char           *Main_Menu[] =
  75. {
  76.     NULL,
  77.     NULL,
  78.     NULL
  79. };
  80.  
  81. /* Pointer to active color selections, and default values */
  82. unsigned       *color, m_colors[] =
  83. {REVERSE, REVERSE, NORMAL},    /* Monochrome defaults */
  84.                 c_colors[] =
  85. {B_GREEN | F_RED, B_BLUE | F_RED | F_GREEN | F_BLUE, B_RED |
  86.  F_GREEN};            /* Color defaults */
  87.  
  88. /* Pointer for access to title window */
  89. struct WINDOW  *titlewin;
  90.  
  91. main(int argc, char *argv[])
  92. {
  93.     int             Option;
  94.  
  95.     msgInit();
  96.     if (argc > 1)
  97.     hlpScreen();
  98.     ctrl_c(INTERCEPT);
  99.     titlewin = wopen(0, 0, 80, 3, WBOX2 | WCOPEN | B_RED | F_RED | F_GREEN |
  100.              F_BLUE);
  101.     color = (W_BASE == 0xB000) ? m_colors : c_colors;
  102.     wopen(0, 3, 80, 22, WSAVE | WBOX1 | WCOPEN | B_GREEN | B_BLUE);
  103.     wcursor_off();
  104.     Main_Menu[0] = msgLock(M_sysinfo);
  105.     msgUnlock(M_sysinfo);
  106.     Main_Menu[1] = msgLock(M_diskinfo);
  107.     msgUnlock(M_diskinfo);
  108.     for (;;) {
  109.     title(msgLock(M_title));
  110.     msgUnlock(M_title);
  111.     if (wmenu(10, 10, WCOPEN | WBOX2 | color[MENU],
  112.           Main_Menu, &Option))
  113.         break;
  114.     switch (Option) {
  115.     case 0:
  116.         System_Information();
  117.         break;
  118.     case 1:
  119.         Disk_Information();
  120.     }
  121.     }
  122.     title(msgLock(M_goodbye));
  123.     msgUnlock(M_goodbye);
  124.     wclose();
  125.     wclose();
  126.     wcursor_line();
  127.     ctrl_c(RELEASE);
  128. }                /* End of main() */
  129.  
  130. void 
  131. System_Information(void)
  132. {
  133.     USEREGS
  134.     struct WINDOW  *sys_info;
  135.     int             hour, minute, second, day, month, year, OS_Version,
  136.                     number, hdrives;
  137.     word            equip;
  138.     byte            i;
  139.  
  140.     title(msgLock(M_sysinfo));
  141.     msgUnlock(M_sysinfo);
  142.     sys_info = wopen(5, 4, 70, 16, WSAVE | WBOX2 | WCOPEN | color[TEXT]);
  143.  
  144.     /* Print time and todays date */
  145.  
  146.     get_time(&hour, &minute, &second);
  147.     get_date(&day, &month, &year);
  148.     wprintf(msgLock(M_time), hour, minute,
  149.         second, day, month, year);
  150.     msgUnlock(M_time);
  151.  
  152.     /* Print version of MS-DOS */
  153.  
  154.     OS_Version = version();
  155.     wprintf(msgLock(M_os), msgLock(M_msdos), OS_Version >> 8, OS_Version & 0x00FF);
  156.     msgUnlock(M_os);
  157.     msgUnlock(M_msdos);
  158.  
  159.     /* Get equipment status value */
  160.  
  161.     equip = get_equip();
  162.  
  163.     /* Find and print number of disk drives attached */
  164.  
  165.     number = ((equip & DRV_MASK) >> DRV_SHIFT) + 1;
  166.     wprintf(msgLock(M_drives), (equip & DRVE) != DRVE ? 0 : number);
  167.     msgUnlock(M_drives);
  168.  
  169.     /* Print number of printers attached */
  170.  
  171.     number = equip >> PRN_SHIFT;
  172.     wprintf(msgLock(M_printers), "", number);
  173.     msgUnlock(M_printers);
  174.  
  175.     /* Print number of comms cards attached */
  176.  
  177.     number = ((equip & 0x0e00) >> 9);
  178.     wprintf(msgLock(M_comms), "", number);
  179.     msgUnlock(M_comms);
  180.  
  181.     /* Print initial video mode */
  182.  
  183.     wprintf(msgLock(M_initvideo), "");
  184.     msgUnlock(M_initvideo);
  185.     switch (equip & VIDEO) {
  186.     case HERC:
  187.     wputs(msgLock(M_herc));
  188.     msgUnlock(M_herc);
  189.     break;
  190.     case BW8025:
  191.     wputs(msgLock(M_cga80));
  192.     msgUnlock(M_cgac80);
  193.     break;
  194.     case BW4025:
  195.     wputs(msgLock(M_cga40));
  196.     msgUnlock(M_cgac40);
  197.     break;
  198.     case EGA:
  199.     wputs(msgLock(M_ega));
  200.     msgUnlock(M_ega);
  201.     }
  202.     wprintf(msgLock(M_currvideo), "");
  203.     msgUnlock(M_currvideo);
  204.  
  205.     /* Find and print current video mode */
  206.  
  207.     _AX = 0x0F00;
  208.     geninterrupt(0x10);
  209.     switch (_AL) {
  210.     case 0:
  211.     wputs(msgLock(M_cga40));
  212.     msgUnlock(M_cga40);
  213.     break;
  214.     case 1:
  215.     wputs(msgLock(M_cga40c));
  216.     msgUnlock(M_cga40c);
  217.     break;
  218.     case 2:
  219.     wputs(msgLock(M_cga80));
  220.     msgUnlock(M_cga80);
  221.     break;
  222.     case 3:
  223.     wputs(msgLock(M_cga80c));
  224.     msgUnlock(M_cga80c);
  225.     break;
  226.     case 4:
  227.     wputs(msgLock(M_cga320));
  228.     msgUnlock(M_cga320);
  229.     break;
  230.     case 5:
  231.     wputs(msgLock(M_cga320c));
  232.     msgUnlock(M_cga320c);
  233.     break;
  234.     case 6:
  235.     wputs(msgLock(M_cga640));
  236.     msgUnlock(M_cga640);
  237.     break;
  238.     default:
  239.     wputs(msgLock(M_herc));
  240.     msgUnlock(M_herc);
  241.     }
  242.  
  243.     /* Print whether co-processor attached */
  244.  
  245.     wputs(msgLock(M_copro));
  246.     msgUnlock(M_copro);
  247.     if (((equip & 0x0002) >> 1) == 1) {
  248.     wputs(msgLock(M_yes));
  249.     msgUnlock(M_yes);
  250.     } else {
  251.     wputs(msgLock(M_no));
  252.     msgUnlock(M_no);
  253.     }
  254.  
  255.     /* Print whether game card installed */
  256.  
  257.     wprintf(msgLock(M_game), "");
  258.     msgUnlock(M_game);
  259.     number = ((equip & 0x1000) >> 12);
  260.     switch (number) {
  261.     case 0:
  262.     wputs(msgLock(M_no));
  263.     msgUnlock(M_no);
  264.     break;
  265.     case 1:
  266.     wputs(msgLock(M_yes));
  267.     msgUnlock(M_yes);
  268.     }
  269.  
  270.     /* Print whether mouse is installed */
  271.  
  272.     wprintf(msgLock(M_mouse), "");
  273.     _AX = 0x0000;
  274.     geninterrupt(0x33);
  275.     if (_AL == 0) {
  276.     wputs(msgLock(M_no));
  277.     msgUnlock(M_no);
  278.     } else {
  279.     wputs(msgLock(M_yes));
  280.     msgUnlock(M_yes);
  281.     }
  282.  
  283.     /* Print size of motherboard memory */
  284.  
  285.     wprintf(msgLock(M_mothermem), "", (((equip & 0x000c) >> 2) * 16) + 16);
  286.     msgUnlock(M_mothermem);
  287.  
  288.     /* Print size of main memory */
  289.  
  290.     wprintf(msgLock(M_mainmem), "", biosmemory());
  291.     msgUnlock(M_mainmem);
  292.  
  293.     /* Print location of program segment */
  294.  
  295.     wprintf(msgLock(M_psp), "", PSP);
  296.     msgUnlock(M_psp);
  297.  
  298.     //Print the number of hard drives installed
  299.  
  300.     hdrives = 0;
  301.     for (i = 0x80; i < 0x80 + 26; i++)
  302.         if (!test_drive(i))
  303.             hdrives++;
  304.     wprintf(msgLock(M_hdrives), "", hdrives);
  305.     msgUnlock(M_hdrives);
  306.     pause();
  307.     wclose();
  308. }
  309.  
  310. void 
  311. Disk_Information(void)
  312. {
  313.     USEREGS
  314.     int             done, number;
  315.     struct FF_block ffblk;
  316.     struct WINDOW  *disk_info;
  317.     char            diskused[LSIZE], diskcap[LSIZE], diskfree[LSIZE], curdir[PATH_SIZE];
  318.  
  319.     title(msgLock(M_diskinfo));
  320.     msgUnlock(M_diskinfo);
  321.     disk_info = wopen(5, 6, 70, 11, WSAVE | WBOX2 | WCOPEN | color[TEXT]);
  322.  
  323.     /* Print current directory */
  324.  
  325.     getdir(curdir);
  326.     wprintf(msgLock(M_curdir), "", curdir);
  327.     msgUnlock(M_curdir);
  328.  
  329.     /* Print number of files in current directory */
  330.  
  331.     number = 0;
  332.     done = findfirst("*.*", ffblk, 0);
  333.     while (!done) {
  334.     number++;
  335.     done = findnext(ffblk);
  336.     }
  337.     wprintf(msgLock(M_nofiles), number);
  338.     msgUnlock(M_nofiles);
  339.  
  340.     /* Find information about disk */
  341.  
  342.     _AX = 0x3600;
  343.     _DX = 0x0000;
  344.     geninterrupt(0x21);
  345.  
  346.     /* Print information about disk */
  347.  
  348.     wprintf(msgLock(M_maxclusters), "", _DX);
  349.     msgUnlock(M_maxclusters);
  350.     wprintf(msgLock(M_unusedclusters), "", _BX);
  351.     msgUnlock(M_unusedclusters);
  352.     wprintf(msgLock(M_sectorscluster), "", _AX);
  353.     msgUnlock(M_sectorscluster);
  354.     wprintf(msgLock(M_bytessector), "", _CX);
  355.     msgUnlock(M_bytessector);
  356.  
  357.     /* Calculate information about disk */
  358.  
  359.     longset(diskused, _BX);    /* Temporarily store BX here */
  360.     longset(diskcap, _CX);    /* And store CX here */
  361.     longset(diskfree, _AX);    /* diskfree = AX */
  362.     longmul(diskfree, diskcap);    /* diskfree *= CX */
  363.     longcpy(diskcap, diskfree);    /* diskcap = AX * CX */
  364.     longmul(diskfree, diskused);/* diskfree *= BX */
  365.     longset(diskused, _DX);    /* Temporary storage for DX now */
  366.     longmul(diskcap, diskused);    /* diskcap *= DX */
  367.     longcpy(diskused, diskcap);    /* diskused = diskcap */
  368.     longsub(diskused, diskfree);/* diskused -= diskfree */
  369.  
  370.     /* Print MAX disk capacity */
  371.  
  372.     long_to_string(curdir, diskcap, 10);
  373.     wprintf(msgLock(M_maxcap), "", curdir);
  374.     msgUnlock(M_maxcap);
  375.  
  376.     /* Print SPACE used */
  377.  
  378.     long_to_string(curdir, diskused, 10);
  379.     wprintf(msgLock(M_used), "", curdir);
  380.     msgUnlock(M_used);
  381.  
  382.     /* Print SPACE unused */
  383.  
  384.     long_to_string(curdir, diskfree, 10);
  385.     wprintf(msgLock(M_free), "", curdir);
  386.     msgUnlock(M_free);
  387.     pause();
  388.     wclose();
  389. }
  390.  
  391. /*
  392.  * biosmemory(void) Returns memory size
  393.  */
  394.  
  395. word 
  396. biosmemory(void)
  397. {
  398.     USEREGS
  399.  
  400.     geninterrupt(0x12);        /* Call memory interrupt */
  401.     return _AX;            /* Get value from AX register */
  402. }
  403.  
  404. word 
  405. get_equip(void)
  406. {
  407.     USEREGS
  408.  
  409.     geninterrupt(0x11);        /* Get equipment */
  410.     return _AX;
  411. }
  412.  
  413. /*
  414.  * Convert a LONG number into a printable string
  415.  */
  416. void 
  417. long_to_string(unsigned char *string, unsigned char *n1, unsigned char base)
  418. {
  419.     unsigned        sp;
  420.     unsigned char   c, stack[(LSIZE * 25) / 10 + 1];
  421.  
  422.     /*
  423.      * Long number registers
  424.      */
  425.  
  426.     char            temp1[LSIZE], temp2[LSIZE];
  427.  
  428.     longcpy(temp2, n1);
  429.     longset(temp1, base);
  430.  
  431.     /* Stack up digits in reverse order */
  432.     sp = 0;
  433.     do {
  434.     longdiv(temp2, temp1);
  435.     stack[sp++] = ((c = *Longreg) > 9) ? c + '7' : c + '0';
  436.     }
  437.     while (longtst(temp2));
  438.  
  439.     /* Unstack digits into output buffer */
  440.     do
  441.     *string++ = stack[--sp];
  442.     while (sp);
  443.     *string = 0;
  444. }
  445.  
  446. /*
  447.  * Draw a title on the title window
  448.  */
  449. void 
  450. title(char *string)
  451. {
  452.     w_clwin(titlewin);
  453.     w_gotoxy((78 / 2) - (strlen(string) / 2), 0, titlewin);
  454.     w_puts(string, titlewin);
  455. }
  456.  
  457. /*
  458.  * Pause for a key to be pressed
  459.  */
  460. void 
  461. pause(void)
  462. {
  463.     wopen(40, 20, 37, 3, WSAVE | WBOX2 | WCOPEN | color[PAUSE]);
  464.     wcursor_off();
  465.     wgotoxy(5, 1);
  466.     wputs(msgLock(M_press));
  467.     msgUnlock(M_press);
  468.     wgetc();
  469.     wclose();
  470. }
  471.  
  472. /*
  473.  * Test for existance of a hard drive
  474.  */
  475.  
  476. byte 
  477. test_drive(byte drive) asm
  478. {
  479.     MOV        DL, 4[BP]        ; Get drive ID
  480.     MOV        AH, 10h          ; Drive status function
  481.     INT        13h              ; Ask BIOS
  482.     MOV        AL, AH           ; Get value
  483.     XOR        AH, AH           ; Zero high
  484. }
  485.