void check_temp_achieved() { DDA* current_movebuffer = &movebuffer[mb_tail]; if (current_movebuffer->live) { if (current_movebuffer->waitfor_temp) { // setTimer(HEATER_WAIT_TIMEOUT); reset_idle(); if (temp_achieved()) { current_movebuffer->live = current_movebuffer->waitfor_temp = 0; serial_writestr_P(PSTR("Temp achieved\n")); debug_led_set_pattern(0,0); } /*#if STEP_INTERRUPT_INTERRUPTIBLE sei(); #endif*/ } } }
int int17(void) { int timeout, val8; ioport_t addr; CARRY; if (_DX >= NUM_LPTS) return 1; addr = READ_WORD(BIOS_ADDRESS_LPT1 + _DX * 2); if (addr == 0) return 1; timeout = READ_BYTE(BIOS_LPT1_TIMEOUT + _DX) << 8; reset_idle(2); switch(_AH) { case 0: port_outb(addr, _AL); val8 = port_inb(addr + 2); port_outb(addr + 2, val8 | 0x01); // send strobe port_outb(addr + 2, val8 & ~0x01); while (((val8 = port_inb(addr + 1)) & LPT_STAT_NOT_ACK) && timeout) timeout--; break; case 1: val8 = port_inb(addr + 2); port_outb(addr + 2, val8 & ~0x04); // send init port_outb(addr + 2, val8 | 0x04); val8 = port_inb(addr + 1); break; case 2: val8 = port_inb(addr + 1); break; default: return 1; } _AH = val8 ^ (LPT_STAT_NOT_ACK | LPT_STAT_NOIOERR); if (!timeout) _AH |= LPT_STAT_TIMEOUT; NOCARRY; return 1; }
void io_select(void) { int selrtn, i; struct timeval tvptr; fd_set fds = fds_sigio; tvptr.tv_sec=0L; tvptr.tv_usec=0L; #if defined(SIG) irq_select(); #endif while ( ((selrtn = select(numselectfd, &fds, NULL, NULL, &tvptr)) == -1) && (errno == EINTR)) { tvptr.tv_sec=0L; tvptr.tv_usec=0L; g_printf("WARNING: interrupted io_select: %s\n", strerror(errno)); } switch (selrtn) { case 0: /* none ready, nothing to do :-) */ return; break; case -1: /* error (not EINTR) */ error("bad io_select: %s\n", strerror(errno)); break; default: /* has at least 1 descriptor ready */ for(i = 0; i < numselectfd; i++) { if (FD_ISSET(i, &fds) && io_callback_func[i].func) { g_printf("GEN: fd %i has data for %s\n", i, io_callback_func[i].name); io_callback_func[i].func(io_callback_func[i].arg); } } reset_idle(0); break; } }
char bios_getchar(char *hi) { com32sys_t ireg, oreg; unsigned char data; memset(&ireg, 0, sizeof(ireg)); memset(&oreg, 0, sizeof(oreg)); while (1) { __idle(); ireg.eax.b[1] = 0x11; /* Poll keyboard */ __intcall(0x16, &ireg, &oreg); if (oreg.eflags.l & EFLAGS_ZF) { if (!SerialPort) continue; cli(); if (SerialTail != SerialHead) { /* serial queued */ sti(); /* We already know we'll consume data */ data = *SerialTail++; if (SerialTail > SerialHead + serial_buf_size) SerialTail = SerialHead; } else { /* LSR */ data = inb(SerialPort + 5) & 1; if (!data) { sti(); continue; } data = inb(SerialPort + 6); data &= FlowIgnore; if (data != FlowIgnore) { sti(); continue; } data = inb(SerialPort); sti(); break; } } else { /* Keyboard input? */ ireg.eax.b[1] = 0x10; /* Get keyboard input */ __intcall(0x16, &ireg, &oreg); data = oreg.eax.b[0]; *hi = oreg.eax.b[1]; if (data == 0xE0) data = 0; if (data) { /* Convert character sets */ data = KbdMap[data]; } } break; } reset_idle(); /* Character received */ return data; }
static void dspio_process_dma(struct dspio_state *state) { int dma_cnt, nfr, in_fifo_cnt, out_fifo_cnt, i, j, tlocked; unsigned long long time_dst; double output_time_cur; sndbuf_t buf[PCM_MAX_BUF][SNDBUF_CHANS]; static int warned; dma_cnt = in_fifo_cnt = out_fifo_cnt = 0; if (state->dma.running) { state->dma.stereo = sb_dma_samp_stereo(); state->dma.rate = sb_get_dma_sampling_rate(); state->dma.samp_signed = sb_dma_samp_signed(); state->dma.dsp_fifo_enabled = sb_fifo_enabled(); dma_cnt += state->dma.input ? dspio_drain_input(state) : dspio_fill_output(state); } if (!state->output_running && !state->input_running) return; time_dst = GETusTIME(0); if (state->output_running) { output_time_cur = pcm_time_lock(state->dma_strm); tlocked = 1; nfr = calc_nframes(state, output_time_cur, time_dst); } else { nfr = 0; tlocked = 0; } for (i = 0; i < nfr; i++) { for (j = 0; j < state->dma.stereo + 1; j++) { if (state->dma.running && !dspio_output_fifo_filled(state)) { if (!dspio_run_dma(state)) break; dma_cnt++; } if (!dspio_get_output_sample(state, &buf[i][j], state->dma.is16bit)) break; #if 0 /* if speaker disabled, overwrite DMA data with silence */ /* on SB16 is not used */ if (!state->speaker) dma_get_silence(state->dma.samp_signed, state->dma.is16bit, &buf[i][j]); #endif } if (j != state->dma.stereo + 1) break; out_fifo_cnt++; } if (out_fifo_cnt && state->dma.rate) { pcm_write_interleaved(buf, out_fifo_cnt, state->dma.rate, pcm_get_format(state->dma.is16bit, state->dma.samp_signed), state->dma.stereo + 1, state->dma_strm); output_time_cur = pcm_get_stream_time(state->dma_strm); if (state->dma.running && output_time_cur > time_dst - 1) { pcm_clear_flag(state->dma_strm, PCM_FLAG_POST); warned = 0; } } if (out_fifo_cnt < nfr) { /* not enough samples, see why */ if (!sb_dma_active()) { dspio_stop_output(state); } else { if (nfr && !warned) { S_printf("SB: Output FIFO exhausted while DMA is still active (ol=%f)\n", time_dst - output_time_cur); warned = 1; } if (state->dma.running) S_printf("SB: Output FIFO exhausted while DMA is running (no DACK?)\n"); /* DMA is active but currently not running and the FIFO is * already exhausted. Normally we should flush the channel * and stop the output timing. * HACK: try to not flush the channel for as long as possible * in a hope the PCM buffers are large enough to hold till * the DMA is restarted. */ pcm_set_flag(state->dma_strm, PCM_FLAG_POST); /* awake dosemu */ reset_idle(0); } } if (tlocked) pcm_time_unlock(state->dma_strm); /* TODO: sync also input time with PCM? */ if (state->input_running) nfr = calc_nframes(state, state->input_time_cur, time_dst); else nfr = 0; if (nfr && state->i_started && sb_input_enabled()) { struct player_params params; params.rate = state->dma.rate; params.channels = state->dma.stereo + 1; params.format = pcm_get_format(state->dma.is16bit, state->dma.samp_signed); params.handle = state->i_handle; nfr = pcm_data_get_interleaved(buf, nfr, ¶ms); } if (!state->i_started) { for (i = 0; i < nfr; i++) { for (j = 0; j < state->dma.stereo + 1; j++) dma_get_silence(state->dma.samp_signed, state->dma.is16bit, &buf[i][j]); } } for (i = 0; i < nfr; i++) { for (j = 0; j < state->dma.stereo + 1; j++) { if (sb_input_enabled()) { if (!dspio_put_input_sample(state, &buf[i][j], state->dma.is16bit)) break; } } if (j == state->dma.stereo + 1) in_fifo_cnt++; for (j = 0; j < state->dma.stereo + 1; j++) { if (state->dma.running) { if (!dspio_run_dma(state)) break; dma_cnt++; } } if (!state->input_running || (j != state->dma.stereo + 1)) break; } if (in_fifo_cnt) { if (state->dma.rate) { state->input_time_cur += in_fifo_cnt * pcm_frame_period_us(state->dma.rate); } else { state->input_time_cur = time_dst; } } if (debug_level('S') >= 7 && (in_fifo_cnt || out_fifo_cnt || dma_cnt)) S_printf("SB: Processed %i %i FIFO, %i DMA, or=%i dr=%i\n", in_fifo_cnt, out_fifo_cnt, dma_cnt, state->output_running, state->dma.running); }