/** * Write callback for XML output using libxml2's I/O routines. It buffers the data it receives * into chunks of 1 tape block each and writes each chunk to the tape. */ int xml_output_tape_write_callback(void *context, const char *buffer, int len) { ssize_t ret; struct xml_output_tape *ctx = context; uint32_t copy_count; /* number of bytes of "buffer" to write immediately */ uint32_t bytes_remaining; /* number of input bytes waiting to be handled */ if (len == 0) return 0; if (ctx->buf_used + len < ctx->buf_size) { memcpy(ctx->buf + ctx->buf_used, buffer, len); ctx->buf_used += len; } else { bytes_remaining = len; do { copy_count = ctx->buf_size - ctx->buf_used; memcpy(ctx->buf + ctx->buf_used, buffer + (len - bytes_remaining), copy_count); ret = tape_write(ctx->device, ctx->buf, ctx->buf_size, true, true); if (ret < 0) { ltfsmsg(LTFS_ERR, "17060E", (int)ret); return -1; } ctx->buf_used = 0; bytes_remaining -= copy_count; } while (bytes_remaining > ctx->buf_size); if (bytes_remaining > 0) memcpy(ctx->buf, buffer + (len - bytes_remaining), bytes_remaining); ctx->buf_used = bytes_remaining; } return len; }
signed int load_script(char *filename) { FILE *fstream; signed int file_size; int i; fstream = fopen(filename, "rb"); if (fstream == NULL) { fprintf(stderr, "Error loading '%s'\n", filename); exit(-1); } /* Find the file size */ fseek(fstream, 0, SEEK_END); file_size = ftell(fstream); fseek(fstream, 0, SEEK_SET); /* Read in all data */ for (i=0; i<file_size; ++i) { unsigned char value; fread(&value, 1, 1, fstream); tape_write(i - file_size, value); } return -file_size; }
void tape_initialize(TAPE *tape, char *t){ uint64_t i; for(i = 0; i < strlen(t); i++){ tape_moveRight(tape); tape_write(tape, t[i]); } tape->actualSymbol = lista_getRaiz(tape->tape); }
void tm_run(TM *t) { char state = t->init, sym, newsym; sym = t->tape[t->tape_pos]; while (newsym = t->code[state][2*sym]) { tape_write(t, newsym); #ifdef DEBUG puts(tape_str(t)); #endif state = t->code[state][2*sym + 1]; sym = t->tape[t->tape_pos]; } }
/** * Close callback for XML output using libxml2's I/O routines. It flushes any partial buffer * which might be left after the write callback has received all XML data. */ int xml_output_tape_close_callback(void *context) { int ret; struct xml_output_tape *ctx = context; if (ctx->buf_used > 0) ret = tape_write(ctx->device, ctx->buf, ctx->buf_used, true, true); else ret = 0; if (ret < 0) ltfsmsg(LTFS_ERR, "17061E", (int)ret); free(ctx->buf); free(ctx); return (ret < 0) ? -1 : 0; }
/* * Punch Perforated Tape, Alphanumeric * ppa Address 0005 * * For each In-Out Transfer instruction one line of tape is punched. In-Out Register * Bit 17 conditions Hole 1. Bit 16 conditions Hole 2, etc. Bit 10 conditions Hole 8 */ static void iot_ppa(device_t *device, int op2, int nac, int mb, int *io, int ac) { pdp1_state *state = device->machine().driver_data<pdp1_state>(); if (LOG_IOT_EXTRA) logerror("PPA instruction: mb=0%06o, (%s)\n", (unsigned) mb, device->machine().describe_context()); tape_write(state, *io & 0377); state->m_io_status &= ~io_st_ptp; /* delay is approximately 1/63.3 second */ if (LOG_IOT_OVERLAP) { if (state->m_tape_puncher.timer->enable(0)) logerror("Error: overlapped PPA/PPB instructions: mb=0%06o, (%s)\n", (unsigned) mb, device->machine().describe_context()); } state->m_tape_puncher.timer->adjust(attotime::from_usec(15800), nac); }
int ui_tape_write( void ) { char *filename; fuse_emulation_pause(); filename = ui_get_save_filename( "Fuse - Write Tape" ); if( !filename ) { fuse_emulation_unpause(); return 1; } tape_write( filename ); libspectrum_free( filename ); fuse_emulation_unpause(); return 0; }
void interpret(signed int entrypoint) { signed int pc; signed int ptr; unsigned char cmd; int loop_level; pc = entrypoint; ptr = 0; while (pc < 0) { cmd = tape_read(pc); switch(cmd) { case ',': tape_write(ptr, getchar()); break; case '.': putchar(tape_read(ptr)); break; case '<': ptr -= 1; break; case '>': ptr += 1; break; case '-': tape_write(ptr, tape_read(ptr) - 1); break; case '+': tape_write(ptr, tape_read(ptr) + 1); break; case '[': if (tape_read(ptr) == 0) { loop_level = 1; while (loop_level > 0) { pc += 1; if (tape_read(pc) == '[') loop_level += 1; else if (tape_read(pc) == ']') loop_level -= 1; } } break; case ']': /* Rewind to the loop start */ loop_level = 1; while (loop_level > 0) { pc -= 1; if (tape_read(pc) == '[') loop_level -= 1; else if (tape_read(pc) == ']') loop_level += 1; } pc -= 1; break; default: break; } pc += 1; } }