//--------------------------------------------------------------------------- // Serial Port //--------------------------------------------------------------------------- void agenda_serial_replace(int) { if (UpdateBaud) RS232_CalculateBaud(bool(mfp_reg[MFPR_UCR] & BIT_7),mfp_get_timer_control_register(3),true); if (SerialPort.AreBytesToCome()){ SerialPort.NextByte(); if ((mfp_reg[MFPR_RSR] & BIT_0) /*Recv enable*/ && (mfp_reg[MFPR_TSR] & b00000110)!=b00000110 /*Loopback*/ && (mfp_reg[MFPR_RSR] & BIT_6)==0 /*No overrun*/){ if ((mfp_reg[MFPR_RSR] & BIT_7 /*Buffer Full*/)==0){ rs232_recv_byte=SerialPort.ReadByte(); rs232_recv_overrun=0; }else{ rs232_recv_overrun=true; } mfp_reg[MFPR_RSR]&=BYTE(~(BIT_2 /*Char in progress*/ | BIT_3 /*Break*/ | BIT_4 /*Frame Error*/ | BIT_5 /*Parity Error*/)); mfp_reg[MFPR_RSR]|=BIT_7 /*Buffer Full*/; mfp_interrupt(MFP_INT_RS232_RECEIVE_BUFFER_FULL,ABSOLUTE_CPU_TIME); } if (SerialPort.AreBytesToCome()){ mfp_reg[MFPR_RSR]|=BYTE(BIT_2); // Character in progress agenda_add(agenda_serial_replace,rs232_hbls_per_word,0); }else{ mfp_reg[MFPR_RSR]&=BYTE(~BIT_2); // Character in progress } } }
//--------------------------------------------------------------------------- void agenda_check_centronics_interrupt(int) { UpdateCentronicsBusyBit(); if (ParallelPort.AreBytesToRead() || ParallelPort.AreBytesToOutput()){ agenda_add(agenda_check_centronics_interrupt,2,0); } }
//--------------------------------------------------------------------------- // MIDI Port //--------------------------------------------------------------------------- void agenda_midi_replace(int) { if (MIDIPort.AreBytesToCome()){ MIDIPort.NextByte(); if (ACIA_MIDI.rx_not_read){ // discard data and set overrun log_to_section(LOGSECTION_MIDI,"MIDI: Overrun on ACIA! Byte lost!"); if (ACIA_MIDI.overrun!=ACIA_OVERRUN_YES) ACIA_MIDI.overrun=ACIA_OVERRUN_COMING; }else{ ACIA_MIDI.data=MIDIPort.ReadByte(); ACIA_MIDI.rx_not_read=true; } log_to_section(LOGSECTION_MIDI,EasyStr("MIDI: Fire ACIA interrupt")); if (ACIA_MIDI.rx_irq_enabled) ACIA_MIDI.irq=true; mfp_gpip_set_bit(MFP_GPIP_ACIA_BIT,!(ACIA_IKBD.irq || ACIA_MIDI.irq)); if (MIDIPort.AreBytesToCome()) agenda_add(agenda_midi_replace,ACIAClockToHBLS(ACIA_MIDI.clock_divide,true),0); } }
static inline int refine_states(int invstates) { int i, selfsplit; struct e *thise; struct p *tP, *newP = NULL; /* 1. add inverse(P,a) to table of inverses, disallowing duplicates 2. first pass on S, touch each state once, increasing P->t_count 3. for each P where counter != count, split and add to agenda */ /* Inverse to table of inverses */ selfsplit = 0; /* touch and increase P->counter */ for (i=0; i < invstates; i++) { ((E+(*(temp_move+i)))->group)->t_count++; ((E+(*(temp_move+i)))->group)->inv_t_count += ((E+(*(temp_move+i)))->inv_count); assert((E+(*(temp_move+i)))->group->t_count <= (E+(*(temp_move+i)))->group->count); } /* Split (this is the tricky part) */ for (i=0; i < invstates; i++) { thise = E+*(temp_move+i); tP = thise->group; /* Do we need to split? if we've touched as many states as there are in the partition we don't split */ if (tP->t_count == tP->count) { tP->t_count = 0; tP->inv_t_count = 0; continue; } if ((tP->t_count != tP->count) && (tP->count > 1) && (tP->t_count > 0)) { /* Check if we already split this */ newP = tP->current_split; if (newP == NULL) { /* printf("tP [%i] newP [%i]\n",tP->inv_count,tP->inv_t_count); */ /* Create new group newP */ total_states++; if (total_states == num_states) return(1); /* Abort now, machine is already minimal */ tP->current_split = Pnext++; newP = tP->current_split; newP->first_e = newP->last_e = thise; newP->count = 0; newP->inv_count = tP->inv_t_count; newP->inv_t_count = 0; newP->t_count = 0; newP->current_split = NULL; newP->agenda = NULL; /* Add to agenda */ /* If the current block (tP) is on the agenda, we add both back */ /* to the agenda */ /* In practice we need only add newP since tP stays where it is */ /* However, we mark the larger one as not starting the symloop */ /* from zero */ if (tP->agenda != NULL) { /* Is tP smaller */ if (tP->inv_count < tP->inv_t_count) { agenda_add(newP, 1); tP->agenda->index = 0; } else { agenda_add(newP, 0); } /* In the event that we're splitting the partition we're currently */ /* splitting with, we can simply add both new partitions to the agenda */ /* and break out of the entire sym loop after we're */ /* done with the current sym and move on with the agenda */ /* We process the larger one for all symbols */ /* and the smaller one for only the ones remaining in this symloop */ } else if (tP == current_w) { agenda_add(((tP->inv_count < tP->inv_t_count) ? tP : newP),0); agenda_add(((tP->inv_count >= tP->inv_t_count) ? tP : newP),1); selfsplit = 1; } else { /* If the block is not on the agenda, we add */ /* the smaller of tP, newP and start the symloop from 0 */ agenda_add((tP->inv_count < tP->inv_t_count ? tP : newP),0); } /* Add to middle of P-chain */ newP->next = P->next; P->next = newP; } thise->group = newP; newP->count++; /* need to make tP->last_e point to the last untouched e */ if (thise == tP->last_e) tP->last_e = thise->left; if (thise == tP->first_e) tP->first_e = thise->right; /* Adjust links */ if (thise->left != NULL) thise->left->right = thise->right; if (thise->right != NULL) thise->right->left = thise->left; if (newP->last_e != thise) { newP->last_e->right = thise; thise->left = newP->last_e; newP->last_e = thise; } thise->right = NULL; if (newP->first_e == thise) thise->left = NULL; /* Are we done for this block? Adjust counters */ if (newP->count == tP->t_count) { tP->count = tP->count - newP->count; tP->inv_count = tP->inv_count - tP->inv_t_count; tP->current_split = NULL; tP->t_count = 0; tP->inv_t_count = 0; } } } /* We return 1 if we just split the partition we were working with */ return (selfsplit); }
//--------------------------------------------------------------------------- void ParallelOutputNotify() { agenda_add(agenda_check_centronics_interrupt,1,0); }
//--------------------------------------------------------------------------- void MidiInBufNotEmpty() { agenda_add(agenda_midi_replace,ACIAClockToHBLS(ACIA_MIDI.clock_divide,true)+1,0); //+1 for middle of scanline }
//--------------------------------------------------------------------------- void SerialInBufNotEmpty() { mfp_reg[MFPR_RSR]|=BYTE(BIT_2); // Character in progress agenda_add(agenda_serial_replace,rs232_hbls_per_word+1,0); //+1 for middle of scanline }
/* source values: 0 -> Public from bot_channel 1 -> Private message to bot */ bool botcmd_parse(irc_session_t* session, const char* cmd, const char* sender, const char* host, int source) { char args[5][256]; if (cmd[0] != '!') { return false; } else { printf("Got command: %s from %s.\n", cmd, sender); } if (sscanf(cmd, "!vote %[^\n]s", args[1]) == 1) { voting_add(session, args[1], sender, host); return true; } else if (strcmp(cmd, "!showvotes") == 0) { printf("Showing vote list\n"); voting_report(session, sender); return true; } else if (strcmp(cmd, "!broadcastvotes") == 0 && is_op(sender)) { printf("Broadcasting vote list\n"); voting_report(session, bot_channel); return true; } else if (sscanf(cmd, "!openvote %[^\n]s", args[0]) == 1 && is_op(sender)) { printf("Opening voting: %s\n", args[0]); voting_init(session, bot_channel, args[0]); return true; } else if (strcmp(cmd, "!closevote") == 0 && is_op(sender)) { printf("Closing current voting\n"); voting_close(session, bot_channel); return true; } else if (strcmp(cmd, "!randkick") == 0 && is_op(sender)) { botcmd_randkick(session); return true; } else if (sscanf(cmd, "!greet %[^\n]s", args[0]) == 1) { if (!source) { botcmd_greet(session, args[0], bot_channel); } else { botcmd_greet(session, args[0], sender); } return true; } else if (strcmp(cmd, "!enablegreet") == 0 && is_op(sender)) { printf("Greeter is now off...\n"); greeter_on = true; return true; } else if (strcmp(cmd, "!disablegreet") == 0 && is_op(sender)) { printf("Greeter is now on...\n"); greeter_on = false; return true; } else if (strcmp(cmd, "!slots") == 0) { if (!source) { botcmd_slots(session, bot_channel, sender); } else { botcmd_slots(session, sender, sender); } return true; } else if (strcmp(cmd, "!clones") == 0) { /* botcmd_clones(session, sender, sender); */ irc_cmd_notice(session, sender, "Coming soon..."); return true; } else if (strcmp(cmd, "!agendaics") == 0) { agenda_export_ics(session, sender); return true; } else if (sscanf(cmd, "!agendaget %[^\n]s", args[0]) == 1) { if (!source) { agenda_get(session, bot_channel, args[0]); } else { agenda_get(session, sender, args[0]); } return true; } else if (sscanf(cmd, "!agendadel %[^\n]s", args[0]) == 1 && is_op(sender)) { if (!source) { agenda_del(session, bot_channel, args[0]); } else { agenda_del(session, sender, args[0]); } return true; } else if (sscanf(cmd, "!agendaadd %[^\n]s", args[0]) == 1 && is_op(sender)) { if (!source) { agenda_add(session, bot_channel, args[0]); } else { agenda_add(session, sender, args[0]); } return true; } else if (strcmp(cmd, "!agenda") == 0) { if (!source) { agenda_list(session, bot_channel, ""); } else { agenda_list(session, sender, ""); } return true; } else if (sscanf(cmd, "!agenda %[^\n]s", args[0]) == 1) { if (!source) { agenda_list(session, bot_channel, args[0]); } else { agenda_list(session, sender, args[0]); } return true; /* } else if (strcmp(cmd, "!gaem") == 0 && is_op(sender)) { botcmd_game(session); return true; */ } else if (strcmp(cmd, "!goatsex") == 0) { if (!source) { botcmd_goatsex(session, bot_channel); } else { botcmd_goatsex(session, sender); } } else if (strcmp(cmd, "!help") == 0) { irc_cmd_notice(session, sender, "Command list:"); irc_cmd_notice(session, sender, "!agenda [all | today | month | year | DD-MM-AAAA]"); irc_cmd_notice(session, sender, "!agendaics"); irc_cmd_notice(session, sender, "!agendaget <index>"); irc_cmd_notice(session, sender, "!callall"); irc_cmd_notice(session, sender, "!clones {Note: Unimplemented}"); irc_cmd_notice(session, sender, "!game"); irc_cmd_notice(session, sender, "!google <search query>"); irc_cmd_notice(session, sender, "!grep <search query>"); if (greeter_on) irc_cmd_notice(session, sender, "!greet <something>"); irc_cmd_notice(session, sender, "!help"); irc_cmd_notice(session, sender, "!ping"); irc_cmd_notice(session, sender, "!slots"); irc_cmd_notice(session, sender, "!showvotes"); irc_cmd_notice(session, sender, "!vote <option>"); if (is_op(sender)) { irc_cmd_notice(session, sender, "Op command list:"); irc_cmd_notice(session, sender, "!agendaadd"); irc_cmd_notice(session, sender, "!agendadel"); irc_cmd_notice(session, sender, "!broadcastvotes"); irc_cmd_notice(session, sender, "!closevote"); irc_cmd_notice(session, sender, "!disablegreet"); irc_cmd_notice(session, sender, "!enablegreet"); irc_cmd_notice(session, sender, "!fibonacci <n> <string>"); irc_cmd_notice(session, sender, "!openvote <question to vote>"); irc_cmd_notice(session, sender, "!randkick"); } return true; } if (!source) { return external_check(session, cmd, sender, bot_channel); } else { return external_check(session, cmd, sender, sender); } }