Main Page Data Structures File List Data Fields Globals Related Pages

# checkbios.cpp

Go to the documentation of this file.

    00001 /*  checkbios.cpp
    00002     Check for correct BIOS version and chip.ini settings
    00003
    00004     01.10.2001: tk, ultra cool auto-upload feature added.
    00005     27.08.2001: tk, ini string checking fixed. there was
    00006                     an error with leading/trailing spaces.
    00007     16.08.2001: tk, initial implementation.
    00008
    00009     Copyright (c)2000 by Thomas Kindler, thomas.kindler@gmx.de
    00010
    00011     This program is free software; you can redistribute it and/or
    00012     modify it under the terms of the GNU General Public License as
    00013     published by the Free Software Foundation; either version 2 of
    00014     the License, or (at your option) any later version. Read the
    00015     full License at http://www.gnu.org/copyleft for more details.
    00016 */
    00017
    00018 // include files -----
    00019 //
    00020 #include "checkbios.h"
    00021
    00022 #include <stdio.h>
    00023 #include <string.h>
    00024 #include <dos.h>
    00025 #include <process.h>
    00026 #include <stdlib.h>
    00027
    00028
    00037 #define  MAGIC_AUTO_UPLOAD  "cmd /c upload.cmd"
    00038
    00039
    00040 static void getFocus()
    00041 {
    00042   REGPACK regs;
    00043   regs.r_ax = 0x1100 | 2;
    00044   intr( 0xa0, &regs );
    00045 }
    00046
    00047
    00048 static void releaseFocus()
    00049 {
    00050   REGPACK regs;
    00051   regs.r_ax = 0x1100 | 3;
    00052   intr( 0xa0, &regs );
    00053 }
    00054
    00055
    00056 static int getBiosVersion()
    00057 {
    00058   REGPACK regs;
    00059   regs.r_ax = 0x1300;
    00060   intr(SYSTEM_INT, &regs);
    00061
    00062   return  regs.r_ax;
    00063 }
    00064
    00065
    00066 static int getBootVersion()
    00067 {
    00068   REGPACK regs;
    00069   regs.r_ax = 0x1200;
    00070   intr(SYSTEM_INT, &regs);
    00071
    00072   return  regs.r_ax;
    00073 }
    00074
    00075
    00076 static void getFeatures(int *ax, int *bx, int *dx)
    00077 {
    00078   REGPACK regs;
    00079   regs.r_ax = 0x1600;
    00080   intr(SYSTEM_INT, &regs);
    00081
    00082   *ax = regs.r_ax;
    00083   *bx = regs.r_bx;
    00084   *dx = regs.r_dx;
    00085 }
    00086
    00087
    00088 static int getIniString(char *section, char *item, char *target, int maxlen)
    00089 {
    00090   REGPACK regs;
    00091
    00092   regs.r_ax = 0x2400;
    00093
    00094   regs.r_cx = maxlen;
    00095   regs.r_bx = FP_SEG(section);
    00096   regs.r_si = FP_OFF(section);
    00097
    00098   regs.r_es = FP_SEG(item);
    00099   regs.r_di = FP_OFF(item);
    00100
    00101   regs.r_ds = FP_SEG(target);
    00102   regs.r_dx = FP_OFF(target);
    00103
    00104   intr(SYSTEM_INT, &regs);
    00105
    00106   return regs.r_ax;
    00107 }
    00108
    00109
    00116 static int getEquipment()
    00117 {
    00118   REGPACK regs;
    00119   intr(0x11, &regs);
    00120   return regs.r_ax;
    00121 }
    00122
    00123
    00127 static void trim(char *str)
    00128 {
    00129   char *head = str;
    00130   char *tail = &str[strlen(str)-1];
    00131   while (*head == ' ') head++;
    00132   while (*tail == ' ') tail--;
    00133
    00134   ++tail = '\0';
    00135   strcpy(str, head);
    00136 }
    00137
    00138
    00150 bool CheckBIOS()
    00151 {
    00152   if (getEquipment() != 0x013C) {
    00153     printf( "This program only runs on an Beck IPC@Chip SC12.\n" );
    00154 #ifdef  MAGIC_AUTO_UPLOAD
    00155     printf( "Trying to execute \""MAGIC_AUTO_UPLOAD"\"..\n");
    00156     system(MAGIC_AUTO_UPLOAD);
    00157 #endif
    00158     return false;
    00159   }
    00160
    00161   unsigned biosVersion = getBiosVersion();
    00162   if (biosVersion < 0x0103) {
    00163     printf( "You're using an outdated BIOS (%u.%02u).\n"
    00164             "Please update your BIOS to at least v1.03b.\n",
    00165             biosVersion >> 8, biosVersion & 255 );
    00166     return false;
    00167   }
    00168
    00169   unsigned bootVersion = getBootVersion();
    00170   if (bootVersion < 0x0208) {
    00171     printf( "You're using an outdated Bootstrap loader (%u.%02u).\n"
    00172             "Please update your Bootstrap to at least v2.08.\n",
    00173             bootVersion >> 8, bootVersion & 255 );
    00174     return false;
    00175   }
    00176
    00177   int ax, bx, dx;
    00178   getFeatures(&ax, &bx, &dx);
    00179   if ( !((ax & FEAT_AX_ETHERNET) &&
    00180          (dx & FEAT_DX_I2C)      &&
    00181          (dx & FEAT_DX_HWAPI)    &&
    00182          (dx & FEAT_DX_RTOS)     &&
    00183          (dx & FEAT_DX_EXTDISK))  )
    00184   {
    00185     printf( "Your BIOS lacks some features that this program needs.\n"
    00186             "Please use one of the medium (or better) BIOS versions.\n" );
    00187     return false;
    00188   }
    00189
    00190
    00191   char str1[80], str2[80];
    00192
    00193   getIniString("SERIAL", "COM_DMA", str1, sizeof(str1));
    00194   getIniString("SERIAL", "EXT_DMA", str2, sizeof(str2));
    00195   trim(str1); trim(str2);
    00196
    00197   if (stricmp(str1, "DISABLE") || stricmp(str2, "DISABLE")) {
    00198     printf( "This program makes extensive use of the DMA channels but\n"
    00199             "they're currently in use by the BIOS. Please add the following\n"
    00200             "lines to your chip.ini, and reboot your chip:\n"
    00201             "  [SERIAL]\n"
    00202             "  COM_DMA=DISABLE\n"
    00203             "  EXT_DMA=DISABLE\n"
    00204           );
    00205     return false;
    00206   }
    00207
    00208   // In fact, you can use the serial COM (not EXT!) port. But without
    00209   // any hardware, or pullups connected, you will get garbage on the
    00210   // console. Especially if the display backlight is switched on - the
    00211   // lines are very close to each other on the PCB.
    00212   //
    00213   // You have to change this check, if you need to use the COM port
    00214   // for console input.
    00215   //
    00216   getIniString("STDIO", "STDIN",  str1, sizeof(str1));
    00217   getIniString("STDIO", "STDOUT", str2, sizeof(str2));
    00218   trim(str1); trim(str2);
    00219
    00220   if (stricmp(str1, "TELNET") || stricmp(str2, "TELNET")) {
    00221     printf( "This PCB layout is not compatible with console in/output on\n"
    00222             "the serial ports. Please add the following lines to your\n"
    00223             "chip.ini, and reboot your chip:\n"
    00224             "  [STDIO]\n"
    00225             "  STDIN=TELNET\n"
    00226             "  STDOUT=TELNET\n"
    00227           );
    00228     return false;
    00229   }
    00230
    00231   // get console focus
    00232   // (and remember to give it back :)
    00233   //
    00234   getFocus();
    00235   atexit(releaseFocus);
    00236
    00237   return true;
    00238 }
    00239