/********************* MM.C **************************/ /* Midi Madhouse main routines */ /** Bruce Bordner, 1986 ********/ #include "stdio.h" #define uchar unsigned char /* make all chars unsigned (for speed) */ /* macro to read an integer from keyboard input - give &var for arg */ uchar linein[20]; /* input line from keyboard for getnum macro */ #define getnum(var) fgets(linein,20,stdin); sscanf(linein,"%d",var) /* get the global data structures file... */ #include "global.mm" /* get the interrupt services routines for the Roland MPU-401... */ #include "mpu401.mm" /* round up all them dirty little internal slave functions... */ #include "dungeon.mm" /* get the MIDI music data munchers, and roll! */ #include "funky.mm" /***************************************************************/ /* All control inputs are through the IBM F-keys (1-10) in this version */ /* A menu is displayed on call; sub-menus can be stacked */ /* Function menu definitions and control functions */ /* NOTE - menu structure and menu arrays are defined in GLOBAL.MM */ /************** ****************/ ch_menu(which) /* make another menu list active and display */ struct menu which[]; {int scan; board[0].knobs = which; /* set data pointer for control() function */ fputs("\n ",stdout); fputs(which[0].descrip,stdout); /* show menu title */ fputs("\n\n",stdout); for(scan = 1;scan < 11;scan++) fprintf(stdout," F%d %s\n",scan,which[scan].descrip); return(0); } /* End ch_menu */ /************** ****************/ fill_menus() /* initialize menu data */ { /* fill root menu */ strcpy(root[0].descrip,"Main Menu "); /* menu title */ root[0].doit = NULL; root[0].doarg = NULL; strcpy(root[1].descrip,"Create a new track "); root[1].doit = add_track; root[1].doarg = NULL; strcpy(root[2].descrip,"Add unit to board "); /* Fn key actions */ root[2].doit = add_unit; root[2].doarg = NULL; strcpy(root[3].descrip,"Remove a unit "); root[3].doit = remove_unit; root[3].doarg = NULL; strcpy(root[4].descrip,"Remove a track "); root[4].doit = remove_track; root[4].doarg = NULL; strcpy(root[5].descrip,"Open a disk file "); root[5].doit = add_disk_track; root[5].doarg = NULL; strcpy(root[6].descrip,"Close a disk file "); root[6].doit = close_disk_track; root[6].doarg = NULL; strcpy(root[7].descrip,"Show stuff "); root[7].doit = ch_menu; root[7].doarg = m_show; /* switch to submenu */ strcpy(root[8].descrip,NO_D); root[8].doit = NULL; root[8].doarg = NULL; strcpy(root[9].descrip,NO_D); root[9].doit = NULL; root[9].doarg = NULL; strcpy(root[10].descrip,"Exit MIDI Madhouse "); root[10].doit = die; root[10].doarg = NULL; /* fill show submenu */ strcpy(m_show[0].descrip,"Show what? "); m_show[0].doit = NULL; m_show[0].doarg = NULL; strcpy(m_show[1].descrip,"Tracks available "); m_show[1].doit = show_tracks; m_show[1].doarg = NULL; strcpy(m_show[2].descrip,"Data on a track "); m_show[2].doit = show_tdata; m_show[2].doarg = NULL; strcpy(m_show[3].descrip,"Board configuration"); m_show[3].doit = show_board; m_show[3].doarg = NULL; strcpy(m_show[4].descrip,"Show unit knob data"); m_show[4].doit = show_patch; m_show[4].doarg = NULL; strcpy(m_show[5].descrip,NO_D); m_show[5].doit = NULL; m_show[5].doarg = NULL; strcpy(m_show[6].descrip,NO_D); m_show[6].doit = NULL; m_show[6].doarg = NULL; strcpy(m_show[7].descrip,NO_D); m_show[7].doit = NULL; m_show[7].doarg = NULL; strcpy(m_show[8].descrip,NO_D); m_show[8].doit = NULL; m_show[8].doarg = NULL; strcpy(m_show[9].descrip,NO_D); m_show[9].doit = NULL; m_show[9].doarg = NULL; strcpy(m_show[10].descrip,"Return to Main Menu"); m_show[10].doit = ch_menu; m_show[10].doarg = root; /* initiate root menu display */ ch_menu(root); return(0); } /* End fill_menus */ /************** ****************/ fill_bag() /* initialize the array of MIDI function types and pointers */ { strcpy(bag[1].geek,"Record MPU to RAM "); bag[1].finger = record; /* set ptr to function code */ bag[1].ksize = sizeof(struct knob_space); strcpy(bag[2].geek,"Record to disk trk"); bag[2].finger = rec_to_disk; bag[2].ksize = sizeof(struct knob_space); strcpy(bag[3].geek,"Play track to MPU "); bag[3].finger = play; bag[3].ksize = sizeof(struct knob_space); strcpy(bag[4].geek,"Play disk to track"); bag[4].finger = play_from_disk; bag[4].ksize = sizeof(struct knob_space); } /* End fill_bag */ /************ main operation functions ***************************/ control(what) /* watch for F-keys, do menu actions */ struct menu what[]; {uchar keyhit; /* check if any special key has been hit - if not, return */ if(!(bdos(11) & 0xFF) || (bdos(8) & 0xFF)) return(0); /* special key has been hit - read again to get IBM scan code */ keyhit = bdos(8) - 58; /* make F1 key = 1; F10 = 10 for menu index */ if((keyhit >= 36) && (keyhit <= 45)) {ch_menu(what); /* Ctrl-F1->F10 redisplays current menu */ return(0); } if((keyhit < 1) || (keyhit > 10)) return(0); /* not F-key */ if(what[keyhit].doit != NULL) /* if menu has a function for this key... */ (*what[keyhit].doit)(what[keyhit].doarg); /* ..give it a call! */ return(0); /* back to cycling through the board[] */ } /* End control */ /************** ****************/ fireup() /* initialize system and go */ { tracks[MPU_IN].tsize = 256; /* set to mpu_inbuf */ tracks[MPU_IN].tloc = mpu_inbuf; strcpy(tracks[MPU_IN].tlabel,"MPU Input Buffer"); tracks[MPU_OUT_0].tsize = 64; /* set to output buffer for track 0 */ tracks[MPU_OUT_0].tloc = mpu0_out; strcpy(tracks[MPU_OUT_0].tlabel,"MPU Output Track 0"); tracks[MPU_OUT_1].tsize = 64; /* set to output buffer for track 1 */ tracks[MPU_OUT_1].tloc = mpu1_out; strcpy(tracks[MPU_OUT_1].tlabel,"MPU Output Track 1"); tracks[MPU_OUT_2].tsize = 64; /* set to output buffer for track 2 */ tracks[MPU_OUT_2].tloc = mpu2_out; strcpy(tracks[MPU_OUT_2].tlabel,"MPU Output Track 2"); tracks[MPU_OUT_3].tsize = 64; /* set to output buffer for track 3 */ tracks[MPU_OUT_3].tloc = mpu3_out; strcpy(tracks[MPU_OUT_3].tlabel,"MPU Output Track 3"); tracks[MPU_OUT_4].tsize = 64; /* set to output buffer for track 4 */ tracks[MPU_OUT_4].tloc = mpu4_out; strcpy(tracks[MPU_OUT_4].tlabel,"MPU Output Track 4"); tracks[MPU_OUT_5].tsize = 64; /* set to output buffer for track 5 */ tracks[MPU_OUT_5].tloc = mpu5_out; strcpy(tracks[MPU_OUT_5].tlabel,"MPU Output Track 5"); tracks[MPU_OUT_6].tsize = 64; /* set to output buffer for track 6 */ tracks[MPU_OUT_6].tloc = mpu6_out; strcpy(tracks[MPU_OUT_6].tlabel,"MPU Output Track 6"); tracks[MPU_OUT_7].tsize = 64; /* set to output buffer for track 7 */ tracks[MPU_OUT_7].tloc = mpu7_out; strcpy(tracks[MPU_OUT_7].tlabel,"MPU Output Track 7"); tracks[MPU_COND_OUT].tsize = 64; /* set to buffer for conductor track */ tracks[MPU_COND_OUT].tloc = cond_out; strcpy(tracks[MPU_COND_OUT].tlabel,"MPU Conductor Track"); /* install and start mpu interrupt handler */ init_handler(); /* (currently using routines by Greg Hendershott) */ /* install control() as function 0 in board[] array */ strcpy(board[0].whatsit,"Central Scrutinizer"); board[0].funky = control; /* pointer to control() */ board[0].knobs = root; /* pointer to root[] menu */ board[0].in = NULL; board[0].out = NULL; board[0].active = 1; /* yes, it's active */ board[0].next = 0; /* loop back to itself until others added */ fputs("MIDI Madhouse is running.\nDon't panic.\nCtrl and any F-key will\ re-display the current action menu.\n",stdout); fill_bag(); /* fill bag array with data on MIDI functions */ fill_menus(); /* fill command menus with data and display root menu */ return(0); } /* End fireup() */ /************** ****************/ main() {int scan; /* initialize whatever */ fireup(); /* scan through the board[] array, call each function if it's active */ scan = 0; /* start with the Central Scrutinizer */ /* the keyboard control function will be called once on each pass through the board[] array to check for user input */ for(;;) /* ..ever */ {if(board[scan].active) /* is this unit currently active? */ (*board[scan].funky)(board[scan].knobs); /* call function, send knobs */ scan = board[scan].next; /* cycle as circular linked list */ } } /* End main */