Annotation of previous/src/gui-sdl/dlgSCSI.c, revision 1.1.1.2

1.1       root        1: /*
                      2:   Previous - dlgSCSI.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: */
                      7: const char DlgSCSI_fileid[] = "Previous dlgSCSI.c : " __DATE__ " " __TIME__;
                      8: 
                      9: #include <assert.h>
                     10: #include "main.h"
                     11: #include "configuration.h"
                     12: #include "dialog.h"
                     13: #include "sdlgui.h"
                     14: #include "file.h"
1.1.1.2 ! root       15: #include "scsi.h"
1.1       root       16: 
                     17: 
                     18: #define SCSIDLG_OFFSET      2
                     19: #define SCSIDLG_INTERVAL    7
                     20: 
                     21: #define SCSIDLG_READONLY    1
                     22: #define SCSIDLG_LEFT        2
                     23: #define SCSIDLG_DEVTYPE     3
                     24: #define SCSIDLG_RIGHT       4
                     25: #define SCSIDLG_SELECT      5
                     26: #define SCSIDLG_NAME        6
                     27: 
                     28: #define GET_BUTTON(x)       (((x)-(SCSIDLG_OFFSET))%(SCSIDLG_INTERVAL))
                     29: #define GET_TARGET(x)       (((x)-(SCSIDLG_OFFSET))/(SCSIDLG_INTERVAL))
                     30: #define PUT_BUTTON(x,y)     (((x)*(SCSIDLG_INTERVAL))+(SCSIDLG_OFFSET)+(y))
                     31: 
1.1.1.2 ! root       32: #define SCSIDLG_OVERLAY     51
        !            33: #define SCSIDLG_EXIT        52
1.1       root       34: 
                     35: 
                     36: /* The SCSI dialog: */
                     37: static SGOBJ scsidlg[] =
                     38: {
                     39:     { SGBOX, 0, 0, 0,0, 64,29, NULL },
                     40:        { SGTEXT, 0, 0, 27,1, 10,1, "SCSI disks" },
                     41: 
                     42:        { SGTEXT, 0, 0, 2,3, 14,1, "SCSI Disk 0:" },
                     43:     { SGTEXT, 0, 0, 15,3, 14,1, NULL },
                     44:     { SGBUTTON, 0, 0, 36, 3, 3, 1, "\x04" },
                     45:     { SGTEXT, 0, 0, 40, 3, 8, 1, NULL },
                     46:     { SGBUTTON, 0, 0, 49, 3, 3, 1, "\x03" },
                     47:        { SGBUTTON, 0, 0, 54,3, 8,1, "Browse" },
                     48:        { SGTEXT, 0, 0, 3,4, 58,1, NULL },
                     49:     
                     50:     { SGTEXT, 0, 0, 2,6, 14,1, "SCSI Disk 1:" },
                     51:     { SGTEXT, 0, 0, 15,6, 14,1, NULL },
                     52:     { SGBUTTON, 0, 0, 36, 6, 3, 1, "\x04" },
                     53:     { SGTEXT, 0, 0, 40, 6, 8, 1, NULL },
                     54:     { SGBUTTON, 0, 0, 49, 6, 3, 1, "\x03" },
                     55:     { SGBUTTON, 0, 0, 54,6, 8,1, "Browse" },
                     56:     { SGTEXT, 0, 0, 3,7, 58,1, NULL },
                     57:     
                     58:     { SGTEXT, 0, 0, 2,9, 14,1, "SCSI Disk 2:" },
                     59:     { SGTEXT, 0, 0, 15,9, 14,1, NULL },
                     60:     { SGBUTTON, 0, 0, 36, 9, 3, 1, "\x04" },
                     61:     { SGTEXT, 0, 0, 40, 9, 8, 1, NULL },
                     62:     { SGBUTTON, 0, 0, 49, 9, 3, 1, "\x03" },
                     63:     { SGBUTTON, 0, 0, 54,9, 8,1, "Browse" },
                     64:     { SGTEXT, 0, 0, 3,10, 58,1, NULL },
                     65: 
                     66:     { SGTEXT, 0, 0, 2,12, 14,1, "SCSI Disk 3:" },
                     67:     { SGTEXT, 0, 0, 15,12, 14,1, NULL },
                     68:     { SGBUTTON, 0, 0, 36, 12, 3, 1, "\x04" },
                     69:     { SGTEXT, 0, 0, 40, 12, 8, 1, NULL },
                     70:     { SGBUTTON, 0, 0, 49, 12, 3, 1, "\x03" },
                     71:     { SGBUTTON, 0, 0, 54,12, 8,1, "Browse" },
                     72:     { SGTEXT, 0, 0, 3,13, 58,1, NULL },
                     73: 
                     74:     { SGTEXT, 0, 0, 2,15, 14,1, "SCSI Disk 4:" },
                     75:     { SGTEXT, 0, 0, 15,15, 14,1, NULL },
                     76:     { SGBUTTON, 0, 0, 36, 15, 3, 1, "\x04" },
                     77:     { SGTEXT, 0, 0, 40, 15, 8, 1, NULL },
                     78:     { SGBUTTON, 0, 0, 49, 15, 3, 1, "\x03" },
                     79:     { SGBUTTON, 0, 0, 54,15, 8,1, "Browse" },
                     80:     { SGTEXT, 0, 0, 3,16, 58,1, NULL },
                     81: 
                     82:     { SGTEXT, 0, 0, 2,18, 14,1, "SCSI Disk 5:" },
                     83:     { SGTEXT, 0, 0, 15,18, 14,1, NULL },
                     84:     { SGBUTTON, 0, 0, 36, 18, 3, 1, "\x04" },
                     85:     { SGTEXT, 0, 0, 40, 18, 8, 1, NULL },
                     86:     { SGBUTTON, 0, 0, 49, 18, 3, 1, "\x03" },
                     87:     { SGBUTTON, 0, 0, 54,18, 8,1, "Browse" },
                     88:     { SGTEXT, 0, 0, 3,19, 58,1, NULL },
                     89: 
                     90:     { SGTEXT, 0, 0, 2,21, 14,1, "SCSI Disk 6:" },
                     91:     { SGTEXT, 0, 0, 15,21, 14,1, NULL },
                     92:     { SGBUTTON, 0, 0, 36, 21, 3, 1, "\x04" },
                     93:     { SGTEXT, 0, 0, 40, 21, 8, 1, NULL },
                     94:     { SGBUTTON, 0, 0, 49, 21, 3, 1, "\x03" },
                     95:     { SGBUTTON, 0, 0, 54,21, 8,1, "Browse" },
                     96:     { SGTEXT, 0, 0, 3,22, 58,1, NULL },
                     97: 
1.1.1.2 ! root       98: #if ENABLE_TESTING
        !            99:     { SGCHECKBOX, 0, 0, 3,24, 21,1, "Don't write to disk images, use temporary overlay" },
        !           100: #else
        !           101:     { SGTEXT, 0, 0, 3,24, 21,1, "" },
        !           102: #endif
        !           103: 
1.1       root      104:     { SGBUTTON, SG_DEFAULT, 0, 21,26, 21,1, "Back to main menu" },
                    105:        { -1, 0, 0, 0,0, 0,0, NULL }
                    106: };
                    107: 
                    108: 
                    109: #define SCSIDLG_EJECT_WARNING   "WARNING: Don't eject manually if a guest system is running. Risk of data loss. Eject now?"
                    110: #define SCSIDLG_NODEV_NOTICE    "No image selected for harddisk drive. Ignoring drive."
                    111: 
                    112: /**
                    113:  * Let user browse given directory, set directory if one selected.
                    114:  * return false if none selected, otherwise return true.
                    115:  */
                    116: /*static bool DlgDisk_BrowseDir(char *dlgname, char *confname, int maxlen)
                    117: {
                    118:        char *str, *selname;
                    119: 
                    120:        selname = SDLGui_FileSelect(confname, NULL, false);
                    121:        if (selname)
                    122:        {
                    123:                strcpy(confname, selname);
                    124:                free(selname);
                    125: 
                    126:                str = strrchr(confname, PATHSEP);
                    127:                if (str != NULL)
                    128:                        str[1] = 0;
                    129:                File_CleanFileName(confname);
                    130:                File_ShrinkName(dlgname, confname, maxlen);
                    131:                return true;
                    132:        }
                    133:        return false;
                    134: }*/
                    135: 
                    136: 
                    137: /* Draw device type selector */
                    138: 
1.1.1.2 ! root      139: static void DlgSCSI_DrawDevtypeSelect(void) {
1.1       root      140:     int i;
                    141:     
                    142:     for (i = 0; i < ESP_MAX_DEVS; i++) {
                    143:         switch (ConfigureParams.SCSI.target[i].nDeviceType) {
                    144:             case DEVTYPE_HARDDISK:
                    145:                 scsidlg[PUT_BUTTON(i,SCSIDLG_DEVTYPE)].txt = "Harddisk";
                    146:                 scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Select";
                    147:                 break;
                    148:             case DEVTYPE_CD:
                    149:                 scsidlg[PUT_BUTTON(i,SCSIDLG_DEVTYPE)].txt = " CD-ROM ";
                    150:                 if (ConfigureParams.SCSI.target[i].bDiskInserted) {
                    151:                     scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Eject";
                    152:                 } else {
                    153:                     scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Insert";
                    154:                 }
                    155:                 break;
                    156:             case DEVTYPE_FLOPPY:
                    157:                 scsidlg[PUT_BUTTON(i,SCSIDLG_DEVTYPE)].txt = " Floppy ";
                    158:                 if (ConfigureParams.SCSI.target[i].bDiskInserted) {
                    159:                     scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Eject";
                    160:                 } else {
                    161:                     scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Insert";
                    162:                 }
                    163:                 break;
                    164:             case DEVTYPE_NONE:
                    165:                 scsidlg[PUT_BUTTON(i,SCSIDLG_DEVTYPE)].txt = "";
                    166:                 scsidlg[PUT_BUTTON(i,SCSIDLG_SELECT)].txt = "Select";
                    167:                 break;
                    168:                 
                    169:             default:
                    170:                 scsidlg[PUT_BUTTON(i,SCSIDLG_DEVTYPE)].txt = " Error! ";
                    171:                 break;
                    172:         }
                    173:         if (ConfigureParams.SCSI.target[i].bWriteProtected) {
                    174:             scsidlg[PUT_BUTTON(i,SCSIDLG_READONLY)].txt = "read-only";
                    175:         } else {
                    176:             scsidlg[PUT_BUTTON(i,SCSIDLG_READONLY)].txt = "";
                    177:         }
                    178:     }
                    179: }
                    180: 
                    181: /**
                    182:  * Show and process the hard disk dialog.
                    183:  */
                    184: void DlgSCSI_Main(void)
                    185: {
                    186:     int but;
                    187:     int i;
                    188:     char dlgname_scsi[ESP_MAX_DEVS][64];
                    189: 
                    190:        SDLGui_CenterDlg(scsidlg);
                    191: 
                    192:        /* Set up dialog to actual values: */
                    193:     DlgSCSI_DrawDevtypeSelect();
                    194: 
                    195:     /* SCSI disk image: */
                    196:     for (i = 0; i < ESP_MAX_DEVS; i++) {
                    197:         if (ConfigureParams.SCSI.target[i].bDiskInserted) {
                    198:             File_ShrinkName(dlgname_scsi[i], ConfigureParams.SCSI.target[i].szImageName,
                    199:                             scsidlg[PUT_BUTTON(i,SCSIDLG_NAME)].w);
                    200:         } else {
                    201:             dlgname_scsi[i][0] = '\0';
                    202:         }
                    203:         scsidlg[PUT_BUTTON(i,SCSIDLG_NAME)].txt = dlgname_scsi[i];
                    204:     }
                    205:     
1.1.1.2 ! root      206:     /* Write Protection */
        !           207:     if(ConfigureParams.SCSI.nWriteProtection == WRITEPROT_ON) scsidlg[SCSIDLG_OVERLAY].state |= SG_SELECTED;
        !           208:     else                                                      scsidlg[SCSIDLG_OVERLAY].state &= ~SG_SELECTED;
        !           209: 
1.1       root      210:        /* Draw and process the dialog */
1.1.1.2 ! root      211:        do {
1.1       root      212:                but = SDLGui_DoDialog(scsidlg, NULL);
                    213:         
                    214:         if (but>=SCSIDLG_OFFSET && but<((SCSIDLG_INTERVAL*ESP_MAX_DEVS)+SCSIDLG_OFFSET)) {
                    215:             
                    216:             switch (GET_BUTTON(but)) {
                    217:                 case SCSIDLG_LEFT:
                    218:                     ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType+=NUM_DEVTYPES-1;
                    219:                     ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType%=NUM_DEVTYPES;
                    220:                     DlgSCSI_DrawDevtypeSelect();
                    221:                     break;
                    222:                 case SCSIDLG_RIGHT:
                    223:                     ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType++;
                    224:                     ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType%=NUM_DEVTYPES;
                    225:                     DlgSCSI_DrawDevtypeSelect();
                    226:                     break;
                    227:                 case SCSIDLG_SELECT:
                    228:                     if ((ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType == DEVTYPE_CD ||
                    229:                          ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType == DEVTYPE_FLOPPY) &&
                    230:                         ConfigureParams.SCSI.target[GET_TARGET(but)].bDiskInserted) {
                    231:                         if (DlgAlert_Query(SCSIDLG_EJECT_WARNING)) {
                    232:                             ConfigureParams.SCSI.target[GET_TARGET(but)].bDiskInserted = false;
                    233:                             ConfigureParams.SCSI.target[GET_TARGET(but)].szImageName[0] = '\0';
                    234:                             scsidlg[PUT_BUTTON(GET_TARGET(but),SCSIDLG_NAME)].txt[0] = '\0';
1.1.1.2 ! root      235:                             SCSI_Eject(GET_TARGET(but));
1.1       root      236:                         }
                    237:                     } else if (SDLGui_DiskSelect(dlgname_scsi[GET_TARGET(but)],
                    238:                                                  ConfigureParams.SCSI.target[GET_TARGET(but)].szImageName,
                    239:                                                  scsidlg[PUT_BUTTON(GET_TARGET(but),SCSIDLG_NAME)].w,
                    240:                                                  &ConfigureParams.SCSI.target[GET_TARGET(but)].bWriteProtected)) {
                    241:                         ConfigureParams.SCSI.target[GET_TARGET(but)].bDiskInserted = true;
                    242:                         if (ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType == DEVTYPE_NONE) {
                    243:                             ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType = DEVTYPE_HARDDISK;
                    244:                         }
1.1.1.2 ! root      245:                         if (ConfigureParams.SCSI.target[GET_TARGET(but)].nDeviceType != DEVTYPE_HARDDISK) {
        !           246:                             SCSI_Insert(GET_TARGET(but));
        !           247:                         }
1.1       root      248:                     }
                    249:                     DlgSCSI_DrawDevtypeSelect();
                    250:                     break;
                    251:                     
                    252:                 default:
                    253:                     break;
                    254:             }
                    255:         }
1.1.1.2 ! root      256: #if ENABLE_TESTING
        !           257:         ConfigureParams.SCSI.nWriteProtection = (scsidlg[SCSIDLG_OVERLAY].state & SG_SELECTED) ? WRITEPROT_ON : WRITEPROT_OFF;
        !           258: #else
        !           259:         ConfigureParams.SCSI.nWriteProtection = WRITEPROT_OFF;
        !           260: #endif
1.1       root      261:        }
                    262:        while (but != SCSIDLG_EXIT && but != SDLGUI_QUIT
                    263:                && but != SDLGUI_ERROR && !bQuitProgram);
                    264:     
                    265:     /* Check for invalid combinations */
                    266:     for (i = 0; i < ESP_MAX_DEVS; i++) {
                    267:         if (ConfigureParams.SCSI.target[i].nDeviceType==DEVTYPE_NONE) {
                    268:             ConfigureParams.SCSI.target[i].bDiskInserted = false;
                    269:             ConfigureParams.SCSI.target[i].szImageName[0] = '\0';
                    270:             ConfigureParams.SCSI.target[i].bWriteProtected = false;
                    271:         }
                    272:         if (ConfigureParams.SCSI.target[i].nDeviceType==DEVTYPE_HARDDISK &&
                    273:             ConfigureParams.SCSI.target[i].bDiskInserted == false) {
                    274:             DlgAlert_Notice(SCSIDLG_NODEV_NOTICE);
                    275:             ConfigureParams.SCSI.target[i].nDeviceType = DEVTYPE_NONE;
                    276:             ConfigureParams.SCSI.target[i].bWriteProtected = false;
                    277:         }
                    278:         if (ConfigureParams.SCSI.target[i].nDeviceType==DEVTYPE_CD) {
                    279:             ConfigureParams.SCSI.target[i].bWriteProtected = true;
                    280:         }
                    281:     }
                    282: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.