void Space::load_motor(uint8_t m, int32_t &addr) { // {{{ loaddebug("loading motor %d", m); uint16_t enable = motor[m]->enable_pin.write(); double old_home_pos = motor[m]->home_pos; double old_steps_per_unit = motor[m]->steps_per_unit; motor[m]->step_pin.read(read_16(addr)); motor[m]->dir_pin.read(read_16(addr)); motor[m]->enable_pin.read(read_16(addr)); motor[m]->limit_min_pin.read(read_16(addr)); motor[m]->limit_max_pin.read(read_16(addr)); motor[m]->sense_pin.read(read_16(addr)); motor[m]->steps_per_unit = read_float(addr); motor[m]->max_steps = read_8(addr); motor[m]->home_pos = read_float(addr); motor[m]->limit_v = read_float(addr); motor[m]->limit_a = read_float(addr); motor[m]->home_order = read_8(addr); arch_motors_change(); SET_OUTPUT(motor[m]->enable_pin); if (enable != motor[m]->enable_pin.write()) { if (motors_busy) SET(motor[m]->enable_pin); else { RESET(motor[m]->enable_pin); } } RESET(motor[m]->step_pin); SET_INPUT(motor[m]->limit_min_pin); SET_INPUT(motor[m]->limit_max_pin); SET_INPUT(motor[m]->sense_pin); bool must_move = false; if (!isnan(motor[m]->home_pos)) { // Axes with a limit switch. if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) { int32_t hp = motor[m]->home_pos * motor[m]->steps_per_unit + (motor[m]->home_pos > 0 ? .49 : -.49); int32_t ohp = old_home_pos * old_steps_per_unit + (old_home_pos > 0 ? .49 : -.49); int32_t diff = hp - ohp; motor[m]->settings.current_pos += diff; cpdebug(id, m, "load motor new home add %d", diff); arch_addpos(id, m, diff); must_move = true; } } else { // Axes without a limit switch, including extruders. if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) { int32_t cp = motor[m]->settings.current_pos; double pos = cp / old_steps_per_unit; cpdebug(id, m, "load motor new steps no home"); motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit; int diff = motor[m]->settings.current_pos - cp; arch_addpos(id, m, diff); } } if (must_move) move_to_current(); } // }}}
static BOOLEAN LoadSummary (SUMMARY_DESC *SummPtr, void *fp) { if (!LoadSisState (&SummPtr->SS, fp)) return FALSE; if ( read_8 (fp, &SummPtr->Activity) != 1 || read_8 (fp, &SummPtr->Flags) != 1 || read_8 (fp, &SummPtr->day_index) != 1 || read_8 (fp, &SummPtr->month_index) != 1 || read_16 (fp, &SummPtr->year_index) != 1 || read_8 (fp, &SummPtr->MCreditLo) != 1 || read_8 (fp, &SummPtr->MCreditHi) != 1 || read_8 (fp, &SummPtr->NumShips) != 1 || read_8 (fp, &SummPtr->NumDevices) != 1 || read_a8 (fp, SummPtr->ShipList, MAX_BUILT_SHIPS) != 1 || read_a8 (fp, SummPtr->DeviceList, MAX_EXCLUSIVE_DEVICES) != 1 || read_8 (fp, &SummPtr->res_factor) != 1 || // JMS: This'll help making saves between different resolutions compatible. read_16 (fp, NULL) != 1 /* padding */ ) return FALSE; else return TRUE; }
static void SampleHeader_read(SampleHeader *self, Reader *stream) { Reader_read(stream, self->mName, sizeof(self->mName)); self->mStart = read_le32(stream); self->mEnd = read_le32(stream); self->mStartloop = read_le32(stream); self->mEndloop = read_le32(stream); self->mSampleRate = read_le32(stream); self->mOriginalKey = read_8(stream); self->mCorrection = read_8(stream); self->mSampleLink = read_le16(stream); self->mSampleType = read_le16(stream); }
static void load(Space *s, uint8_t old_type, int32_t &addr) { uint8_t num = read_8(addr); if (!s->setup_nums(num, num)) { debug("Failed to set up cartesian axes"); s->cancel_update(); } }
/* Reads in a value from the constant pool. */ void skip_constant(FILE *classfile, u_int16_t *cur) { u_int16_t len; int seekerr = 1; pool[*cur] = ftell(classfile); switch(read_8(classfile)) { case CP_UTF8: len = read_16(classfile); seekerr = fseek(classfile, len, SEEK_CUR); break; case CP_CLASS: case CP_STRING: seekerr = fseek(classfile, 2, SEEK_CUR); break; case CP_INTEGER: case CP_FLOAT: case CP_FIELDREF: case CP_METHODREF: case CP_INTERFACEMETHODREF: case CP_NAMEANDTYPE: seekerr = fseek(classfile, 4, SEEK_CUR); break; case CP_LONG: case CP_DOUBLE: seekerr = fseek(classfile, 8, SEEK_CUR); ++(*cur); break; default: corrupt_error(); } if(seekerr) seek_error(); }
void Space::load_axis(uint8_t a, int32_t &addr) { // {{{ loaddebug("loading axis %d", a); axis[a]->park = read_float(addr); axis[a]->park_order = read_8(addr); axis[a]->min_pos = read_float(addr); axis[a]->max_pos = read_float(addr); } // }}}
static BOOLEAN LoadSisState (SIS_STATE *SSPtr, void *fp) { if ( read_32s (fp, &SSPtr->log_x) != 1 || read_32s (fp, &SSPtr->log_y) != 1 || read_32 (fp, &SSPtr->ResUnits) != 1 || read_32 (fp, &SSPtr->FuelOnBoard) != 1 || read_16 (fp, &SSPtr->CrewEnlisted) != 1 || read_16 (fp, &SSPtr->TotalElementMass) != 1 || read_16 (fp, &SSPtr->TotalBioMass) != 1 || read_a8 (fp, SSPtr->ModuleSlots, NUM_MODULE_SLOTS) != 1 || read_a8 (fp, SSPtr->DriveSlots, NUM_DRIVE_SLOTS) != 1 || read_a8 (fp, SSPtr->JetSlots, NUM_JET_SLOTS) != 1 || read_8 (fp, &SSPtr->NumLanders) != 1 || read_a16 (fp, SSPtr->ElementAmounts, NUM_ELEMENT_CATEGORIES) != 1 || read_str (fp, SSPtr->ShipName, SIS_NAME_SIZE) != 1 || read_str (fp, SSPtr->CommanderName, SIS_NAME_SIZE) != 1 || read_str (fp, SSPtr->PlanetName, SIS_NAME_SIZE) != 1 || read_16 (fp, NULL) != 1 /* padding */ ) return FALSE; else { // JMS: Let's make savegames work even between different resolution modes. SSPtr->log_x <<= RESOLUTION_FACTOR; SSPtr->log_y <<= RESOLUTION_FACTOR; return TRUE; } }
double read_float(int32_t &address) { ReadFloat ret; for (uint8_t t = 0; t < sizeof(double); ++t) ret.b[t] = read_8(address); return ret.f; }
void Space::load_motor(int m, int32_t &addr) { // {{{ loaddebug("loading motor %d", m); uint16_t enable = motor[m]->enable_pin.write(); double old_home_pos = motor[m]->home_pos; double old_steps_per_unit = motor[m]->steps_per_unit; motor[m]->step_pin.read(read_16(addr)); motor[m]->dir_pin.read(read_16(addr)); motor[m]->enable_pin.read(read_16(addr)); motor[m]->limit_min_pin.read(read_16(addr)); motor[m]->limit_max_pin.read(read_16(addr)); motor[m]->steps_per_unit = read_float(addr); motor[m]->home_pos = read_float(addr); motor[m]->limit_v = read_float(addr); motor[m]->limit_a = read_float(addr); motor[m]->home_order = read_8(addr); arch_motors_change(); SET_OUTPUT(motor[m]->enable_pin); if (enable != motor[m]->enable_pin.write()) { if (motors_busy) SET(motor[m]->enable_pin); else { RESET(motor[m]->enable_pin); } } RESET(motor[m]->step_pin); SET_INPUT(motor[m]->limit_min_pin); SET_INPUT(motor[m]->limit_max_pin); bool must_move = false; if (!isnan(motor[m]->home_pos)) { // Axes with a limit switch. if (motors_busy && (old_home_pos != motor[m]->home_pos || old_steps_per_unit != motor[m]->steps_per_unit) && !isnan(old_home_pos)) { double ohp = old_home_pos * old_steps_per_unit; double hp = motor[m]->home_pos * motor[m]->steps_per_unit; double diff = hp - ohp; motor[m]->settings.current_pos += diff; //debug("load motor %d %d new home %f add %f", id, m, motor[m]->home_pos, diff); arch_addpos(id, m, diff); must_move = true; } } else { // Axes without a limit switch, including extruders. if (motors_busy && old_steps_per_unit != motor[m]->steps_per_unit) { debug("load motor %d %d new steps no home", id, m); double oldpos = motor[m]->settings.current_pos; double pos = oldpos / old_steps_per_unit; motor[m]->settings.current_pos = pos * motor[m]->steps_per_unit; arch_addpos(id, m, motor[m]->settings.current_pos - oldpos); // Adjust current_pos in all history. for (int h = 0; h < FRAGMENTS_PER_BUFFER; ++h) { oldpos = motor[m]->history[h].current_pos; pos = oldpos / old_steps_per_unit; motor[m]->history[h].current_pos = pos * motor[m]->steps_per_unit; } } } if (must_move) move_to_current(); } // }}}
uint8_t OSD_EEPROM::_read(uint16_t addr){ for(uint8_t i=PAGE_SIZE/EEPROM_SIZE; i!=0;){ // look most recent value from last stage i--; uint32_t ea = EEPROM_PAGE + i*EEPROM_SIZE + addr; uint8_t val = read_8(ea); if(val != 0xFF) { ee_ptr=ea; // remember last read address return val; // first non-FF is a value } } ee_ptr = EEPROM_PAGE + addr; return 0xff; // got to begin and still FF - really FF }
static void eload(Space *s, uint8_t old_type, int32_t &addr) { uint8_t num = read_8(addr); if (!s->setup_nums(num, num)) { debug("Failed to set up extruder axes"); uint8_t n = min(s->num_axes, s->num_motors); if (!s->setup_nums(n, n)) { debug("Trouble! Failed to abort. Cancelling."); s->cancel_update(); } } for (int a = EDATA(s).num_axes; a < s->num_axes; ++a) { s->axis[a]->type_data = new ExtruderAxisData; for (int i = 0; i < 3; ++i) EADATA(s, a).offset[i] = 0; } EDATA(s).num_axes = s->num_axes; bool move = false; if (motors_busy && !computing_move && settings.queue_start == settings.queue_end && !settings.queue_full) { move = true; queue[settings.queue_end].probe = false; queue[settings.queue_end].cb = false; queue[settings.queue_end].f[0] = INFINITY; queue[settings.queue_end].f[1] = INFINITY; for (int i = 0; i < spaces[0].num_axes; ++i) { queue[settings.queue_end].data[i] = spaces[0].axis[i]->settings.current; for (int ss = 0; ss < 2; ++ss) queue[settings.queue_end].data[i] = space_types[spaces[ss].type].unchange0(&spaces[ss], i, queue[settings.queue_end].data[i]); if (i == 2) queue[settings.queue_end].data[i] -= zoffset; } for (int i = spaces[0].num_axes; i < QUEUE_LENGTH; ++i) { queue[settings.queue_end].data[i] = NAN; } cpdebug(0, 0, "eload end"); settings.queue_end = (settings.queue_end + 1) % QUEUE_LENGTH; // This shouldn't happen and causes communication problems, but if you have a 1-item buffer it is correct. if (settings.queue_end == settings.queue_start) settings.queue_full = true; } for (int a = 0; a < s->num_axes; ++a) { for (int o = 0; o < 3; ++o) EADATA(s, a).offset[o] = read_float(addr); } if (move) { next_move(); buffer_refill(); } }
void Space::load_info(int32_t &addr) { // {{{ loaddebug("loading space %d", id); uint8_t t = type; if (t >= NUM_SPACE_TYPES) t = DEFAULT_TYPE; type = read_8(addr); if (type >= NUM_SPACE_TYPES || (id == 1 && type != EXTRUDER_TYPE)) { debug("request for type %d ignored", type); type = t; } bool ok; if (t != type) { loaddebug("setting type to %d", type); space_types[t].free(this); if (!space_types[type].init(this)) { type = DEFAULT_TYPE; space_types[type].reset_pos(this); for (uint8_t a = 0; a < num_axes; ++a) axis[a]->settings.current = axis[a]->settings.source; return; // The rest of the package is not meant for DEFAULT_TYPE, so ignore it. } ok = false; } else { if (computing_move || !motors_busy) ok = false; else ok = true; } space_types[type].load(this, t, addr); if (t != type) { space_types[type].reset_pos(this); loaddebug("resetting current for load space %d", id); for (uint8_t a = 0; a < num_axes; ++a) axis[a]->settings.current = axis[a]->settings.source; } if (ok) move_to_current(); loaddebug("done loading space"); } // }}}
void OSD_EEPROM::_write(uint16_t addr, uint8_t val){ uint8_t cv = _read(addr); if(cv == val) return; // already is if( /* we can write - there is no '0' where we need '1' */ (~cv & val)==0 ){ FLASH_Unlock_dis(); write_8(ee_ptr, val); // just overwrite last value goto done; } if(val != 0xFF){ // the only way to write FF is to clear all - but OSD don't writes it for(uint8_t i=0; i<PAGE_SIZE/EEPROM_SIZE; i++){ // look 0xFF uint32_t ea = EEPROM_PAGE + i*EEPROM_SIZE + addr; cv = read_8(ea); if(cv == 0xFF) { // empty FLASH_Unlock_dis(); write_8(ea, val); goto done; } } } // no empty slots - so need to erase page // 1st - erase page. power loss here cause data loss! In execution time CPU is frozen! printf("\nEEprom_OSD erase page %d\n ", (uint16_t)((EEPROM_PAGE & 0x00ffffff) / 0x4000) ); // clear high byte of address and count 16K blocks FLASH_Unlock_dis(); erasePageByAddress(EEPROM_PAGE); // 2rd write data back to the beginning of Flash page for(uint16_t i=0;i<EEPROM_SIZE; i++){ write_8(EEPROM_PAGE+i, data[i]); } done: FLASH_Lock_check(); }
static inline unsigned int read_24(const UINT8 *oprom, unsigned int offset) { unsigned int val = read_8(oprom, offset); val |= (read_8(oprom, offset+1)<<8); return val | (read_8(oprom, offset+2)<<16); }
int main(int argc, char **argv) { FILE *classfile; u_int16_t cp_count, i, this_class, classinfo_ptr; u_int8_t length; program = argv[0]; if(!argv[1]) error("%s: Missing input file\n", program); classfile = fopen(argv[1], "rb"); if(!classfile) error("%s: Error opening %s\n", program, argv[1]); if(fseek(classfile, 8, SEEK_SET)) /* skip magic and version numbers */ seek_error(); cp_count = read_16(classfile); pool = calloc(cp_count, sizeof(long)); if(!pool) error("%s: Out of memory for constant pool\n", program); for(i = 1; i < cp_count; ++i) skip_constant(classfile, &i); if(fseek(classfile, 2, SEEK_CUR)) /* skip access flags */ seek_error(); this_class = read_16(classfile); if(this_class < 1 || this_class >= cp_count) corrupt_error(); if(!pool[this_class] || pool[this_class] == -1) corrupt_error(); if(fseek(classfile, pool[this_class] + 1, SEEK_SET)) seek_error(); classinfo_ptr = read_16(classfile); if(classinfo_ptr < 1 || classinfo_ptr >= cp_count) corrupt_error(); if(!pool[classinfo_ptr] || pool[classinfo_ptr] == -1) corrupt_error(); if(fseek(classfile, pool[classinfo_ptr] + 1, SEEK_SET)) seek_error(); length = read_16(classfile); for(i = 0; i < length; ++i) { u_int8_t x = read_8(classfile); if((x & 0x80) || !x) { if((x & 0xE0) == 0xC0) { u_int8_t y = read_8(classfile); if((y & 0xC0) == 0x80) { int c = ((x & 0x1f) << 6) + (y & 0x3f); if(c) putchar(c); else utf8_error(); } else utf8_error(); } else utf8_error(); } else if(x == '/') putchar('.'); else putchar(x); } putchar('\n'); free(pool); fclose(classfile); return 0; }
unsigned g65816_disassemble(char* buff, unsigned int pc, unsigned int pb, const UINT8 *oprom, int m_flag, int x_flag) { unsigned int instruction; const opcode_struct* opcode; char* ptr; int var; int length = 1; unsigned int address; unsigned dasm_flags; pb <<= 16; address = pc | pb; base_oprom = oprom; base_pc = address; instruction = read_8(address); opcode = g_opcodes + instruction; strcpy(buff, g_opnames[opcode->name]); ptr = buff + strlen(buff); switch(opcode->name) { case JSR: case JSL: dasm_flags = DASMFLAG_STEP_OVER; break; case RTI: case RTL: case RTS: dasm_flags = DASMFLAG_STEP_OUT; break; default: dasm_flags = 0; break; } switch(opcode->ea) { case IMP : break; case ACC : sprintf(ptr, "A"); break; case RELB: var = (INT8) read_8(address+1); length++; sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_8_str(var)); break; case RELW: case PER : var = read_16(address+1); sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var)); length += 2; break; case IMM : if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x", read_16(address+1)); length += 2; } else { sprintf(ptr, " #$%02x", read_8(address+1)); length++; } break; case A : case PEA : sprintf(ptr, " $%04x", read_16(address+1)); length += 2; break; case AI : sprintf(ptr, " ($%04x)", read_16(address+1)); length += 2; break; case AL : sprintf(ptr, " $%06x", read_24(address+1)); length += 3; break; case ALX : sprintf(ptr, " $%06x,X", read_24(address+1)); length += 3; break; case AX : sprintf(ptr, " $%04x,X", read_16(address+1)); length += 2; break; case AXI : sprintf(ptr, " ($%04x,X)", read_16(address+1)); length += 2; break; case AY : sprintf(ptr, " $%04x,Y", read_16(address+1)); length += 2; break; case D : sprintf(ptr, " $%02x", read_8(address+1)); length++; break; case DI : case PEI : sprintf(ptr, " ($%02x)", read_8(address+1)); length++; break; case DIY : sprintf(ptr, " ($%02x),Y", read_8(address+1)); length++; break; case DLI : sprintf(ptr, " [$%02x]", read_8(address+1)); length++; break; case DLIY: sprintf(ptr, " [$%02x],Y", read_8(address+1)); length++; break; case DX : sprintf(ptr, " $%02x,X", read_8(address+1)); length++; break; case DXI : sprintf(ptr, " ($%02x,X)", read_8(address+1)); length++; break; case DY : sprintf(ptr, " $%02x,Y", read_8(address+1)); length++; break; case S : sprintf(ptr, " %s,S", int_8_str(read_8(address+1))); length++; break; case SIY : sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1))); length++; break; case SIG : sprintf(ptr, " #$%02x", read_8(address+1)); length++; break; case MVN : case MVP : sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1)); length += 2; break; } return length | DASMFLAG_SUPPORTED | dasm_flags; }
int16_t read_16(int32_t &address) { uint8_t l = read_8(address); uint8_t h = read_8(address); return ((uint16_t(h) & 0xff) << 8) | (uint16_t(l) & 0xff); }
INLINE unsigned int read_16(const UINT8 *oprom, unsigned int offset) { unsigned int val = read_8(oprom, offset); return val | (read_8(oprom, offset+1)<<8); }
Buffer::ConstPointer Buffer::read(uint8_t &out_value) const throw(KafkaError) { out_value = *reinterpret_cast<const uint8_t *>(read_8()); return shared_from_this(); }
INLINE unsigned int read_24(unsigned int address) { unsigned int val = read_8(address); val |= (read_8(address+1)<<8); return val | (read_8(address+2)<<16); }
int m7700_disassemble(char* buff, unsigned int pc, unsigned int pb, const UINT8 *oprom, int m_flag, int x_flag) { unsigned int instruction; const m7700_opcode_struct *opcode; char* ptr; int var; signed char varS; int length = 1; unsigned int address; //unsigned int start; UINT32 flags = 0; pb <<= 16; address = pc | pb; //start = address; instruction = read_8(oprom,0); // check for prefixes switch (instruction) { case 0x42: address++; length++; oprom++; instruction = read_8(oprom,0); opcode = &m7700_opcode_struct::get_prefix42(instruction); break; case 0x89: address++; length++; oprom++; instruction = read_8(oprom,0); opcode = &m7700_opcode_struct::get_prefix89(instruction); break; default: opcode = &m7700_opcode_struct::get(instruction); break; } if (opcode->is_call()) flags = DASMFLAG_STEP_OVER; else if (opcode->is_return()) flags = DASMFLAG_STEP_OUT; sprintf(buff, "%s", opcode->name()); ptr = buff + strlen(buff); switch(opcode->ea) { case IMP : break; case ACC : sprintf(ptr, " A"); break; case ACCB : sprintf(ptr, " B"); break; case RELB: varS = read_8(oprom,1); length++; sprintf(ptr, " %06x (%s)", pb | ((pc + length + varS)&0xffff), int_8_str(varS)); break; case RELW: case PER : var = read_16(oprom,1); length += 2; sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_16_str(var)); break; case IMM : if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x", read_16(oprom,1)); length += 2; } else { sprintf(ptr, " #$%02x", read_8(oprom,1)); length++; } break; case BBCD: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { varS = read_8(oprom,4); length += 4; sprintf(ptr, " #$%04x, $%02x, %06x (%s)", read_16(oprom,2), read_8(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } else { varS = read_8(oprom,3); length += 3; sprintf(ptr, " #$%02x, $%02x, %06x (%s)", read_8(oprom,2), read_8(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } break; case BBCA: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { length += 5; varS = read_8(oprom,5); sprintf(ptr, " #$%04x, $%04x, %06x (%s)", read_16(oprom,3), read_16(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } else { length += 4; varS = read_8(oprom,4); sprintf(ptr, " #$%02x, $%04x, %06x (%s)", read_8(oprom,3), read_16(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } break; case LDM4: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%02x", read_16(oprom,2), read_8(oprom,1)); length += 3; } else { sprintf(ptr, " #$%02x, $%02x", read_8(oprom,2), read_8(oprom,1)); length += 2; } break; case LDM5: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%04x", read_16(oprom,3), read_16(oprom,1)); length += 4; } else { sprintf(ptr, " #$%02x, $%04x", read_8(oprom,3), read_16(oprom,1)); length += 3; } break; case LDM4X: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%02x, X", read_16(oprom,2), read_8(oprom,1)); length += 3; } else { sprintf(ptr, " #$%02x, $%02x, X", read_8(oprom,2), read_8(oprom,1)); length += 2; } break; case LDM5X: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%04x, X", read_16(oprom,3), read_16(oprom,1)); length += 4; } else { sprintf(ptr, " #$%02x, $%04x, X", read_8(oprom,3), read_16(oprom,1)); length += 3; } break; case A : case PEA : sprintf(ptr, " $%04x", read_16(oprom,1)); length += 2; break; case AI : sprintf(ptr, " ($%04x)", read_16(oprom,1)); length += 2; break; case AL : sprintf(ptr, " $%06x", read_24(oprom,1)); length += 3; break; case ALX : sprintf(ptr, " $%06x,X", read_24(oprom,1)); length += 3; break; case AX : sprintf(ptr, " $%04x,X", read_16(oprom,1)); length += 2; break; case AXI : sprintf(ptr, " ($%04x,X)", read_16(oprom,1)); length += 2; break; case AY : sprintf(ptr, " $%04x,Y", read_16(oprom,1)); length += 2; break; case D : sprintf(ptr, " $%02x", read_8(oprom,1)); length++; break; case DI : case PEI : sprintf(ptr, " ($%02x)", read_8(oprom,1)); length++; break; case DIY : sprintf(ptr, " ($%02x),Y", read_8(oprom,1)); length++; break; case DLI : sprintf(ptr, " [$%02x]", read_8(oprom,1)); length++; break; case DLIY: sprintf(ptr, " [$%02x],Y", read_8(oprom,1)); length++; break; case DX : sprintf(ptr, " $%02x,X", read_8(oprom,1)); length++; break; case DXI : sprintf(ptr, " ($%02x,X)", read_8(oprom,1)); length++; break; case DY : sprintf(ptr, " $%02x,Y", read_8(oprom,1)); length++; break; case S : sprintf(ptr, " %s,S", int_8_str(read_8(oprom,1))); length++; break; case SIY : sprintf(ptr, " (%s,S),Y", int_8_str(read_8(oprom,1))); length++; break; case SIG : sprintf(ptr, " #$%02x", read_8(oprom,1)); length++; break; case MVN : case MVP : sprintf(ptr, " $%02x, $%02x", read_8(oprom,2), read_8(oprom,1)); length += 2; break; } return length | flags | DASMFLAG_SUPPORTED; }
INLINE unsigned int read_16(unsigned int address) { unsigned int val = read_8(address); return val | (read_8(address+1)<<8); }
int g65816_disassemble(char* buff, unsigned int pc, unsigned int pb, int m_flag, int x_flag) { unsigned int instruction; opcode_struct* opcode; char* ptr; int var; int length = 1; unsigned int address; pb <<= 16; address = pc | pb; instruction = read_8(address); opcode = g_opcodes + instruction; strcpy(buff, g_opnames[opcode->name]); ptr = buff + strlen(buff); switch(opcode->ea) { case IMP : break; case ACC : sprintf(ptr, "A"); break; case RELB: var = read_8(address+1); length++; sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_8_str(var)); break; case RELW: case PER : var = read_16(address+1); sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var)); length += 2; break; case IMM : if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x", read_16(address+1)); length += 2; } else { sprintf(ptr, " #$%02x", read_8(address+1)); length++; } break; case A : case PEA : sprintf(ptr, " $%04x", read_16(address+1)); length += 2; break; case AI : sprintf(ptr, " ($%04x)", read_16(address+1)); length += 2; break; case AL : sprintf(ptr, " $%06x", read_24(address+1)); length += 3; break; case ALX : sprintf(ptr, " $%06x,X", read_24(address+1)); length += 3; break; case AX : sprintf(ptr, " $%04x,X", read_16(address+1)); length += 2; break; case AXI : sprintf(ptr, " ($%04x,X)", read_16(address+1)); length += 2; break; case AY : sprintf(ptr, " $%04x,Y", read_16(address+1)); length += 2; break; case D : sprintf(ptr, " $%02x", read_8(address+1)); length++; break; case DI : case PEI : sprintf(ptr, " ($%02x)", read_8(address+1)); length++; break; case DIY : sprintf(ptr, " ($%02x),Y", read_8(address+1)); length++; break; case DLI : sprintf(ptr, " [$%02x]", read_8(address+1)); length++; break; case DLIY: sprintf(ptr, " [$%02x],Y", read_8(address+1)); length++; break; case DX : sprintf(ptr, " $%02x,X", read_8(address+1)); length++; break; case DXI : sprintf(ptr, " ($%02x,X)", read_8(address+1)); length++; break; case DY : sprintf(ptr, " $%02x,Y", read_8(address+1)); length++; break; case S : sprintf(ptr, " %s,S", int_8_str(read_8(address+1))); length++; break; case SIY : sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1))); length++; break; case SIG : sprintf(ptr, " #$%02x", read_8(address+1)); length++; break; case MVN : case MVP : sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1)); length += 2; break; } return length; }
int m7700_disassemble(char* buff, unsigned int pc, unsigned int pb, int m_flag, int x_flag) { unsigned int instruction; opcode_struct *opcode; char* ptr; int var; signed char varS; int length = 1; unsigned int address; pb <<= 16; address = pc | pb; instruction = read_8(address); // check for prefixes switch (instruction) { case 0x42: address++; length++; instruction = read_8(address); opcode = g_opcodes_prefix42 + instruction; break; case 0x89: address++; length++; instruction = read_8(address); opcode = g_opcodes_prefix89 + instruction; break; default: opcode = g_opcodes + instruction; break; } sprintf(buff, "%s", g_opnames[opcode->name]); ptr = buff + strlen(buff); switch(opcode->ea) { case IMP : break; case ACC : sprintf(ptr, " A"); break; case ACCB : sprintf(ptr, " B"); break; case RELB: varS = read_8(address+1); length++; sprintf(ptr, " %06x (%s)", pb | ((pc + length + varS)&0xffff), int_8_str(varS)); break; case RELW: case PER : var = read_16(address+1); sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var)); length += 2; break; case IMM : if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x", read_16(address+1)); length += 2; } else { sprintf(ptr, " #$%02x", read_8(address+1)); length++; } break; case BBCD: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { varS = read_8(address+4); length += 4; sprintf(ptr, " #$%04x, $%02x, %06x (%s)", read_16(address+2), read_8(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } else { varS = read_8(address+3); length += 3; sprintf(ptr, " #$%02x, $%02x, %06x (%s)", read_8(address+2), read_8(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } break; case BBCA: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { length += 5; varS = read_8(address+5); sprintf(ptr, " #$%04x, $%04x, %06x (%s)", read_16(address+3), read_16(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } else { length += 4; varS = read_8(address+4); sprintf(ptr, " #$%02x, $%04x, %06x (%s)", read_8(address+3), read_16(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS)); } break; case LDM4: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%02x", read_16(address+2), read_8(address+1)); length += 3; } else { sprintf(ptr, " #$%02x, $%02x", read_8(address+2), read_8(address+1)); length += 2; } break; case LDM5: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%04x", read_16(address+3), read_16(address+1)); length += 4; } else { sprintf(ptr, " #$%02x, $%04x", read_8(address+3), read_16(address+1)); length += 3; } break; case LDM4X: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%02x, X", read_16(address+2), read_8(address+1)); length += 3; } else { sprintf(ptr, " #$%02x, $%02x, X", read_8(address+2), read_8(address+1)); length += 2; } break; case LDM5X: if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag)) { sprintf(ptr, " #$%04x, $%04x, X", read_16(address+3), read_16(address+1)); length += 4; } else { sprintf(ptr, " #$%02x, $%04x, X", read_8(address+3), read_16(address+1)); length += 3; } break; case A : case PEA : sprintf(ptr, " $%04x", read_16(address+1)); length += 2; break; case AI : sprintf(ptr, " ($%04x)", read_16(address+1)); length += 2; break; case AL : sprintf(ptr, " $%06x", read_24(address+1)); length += 3; break; case ALX : sprintf(ptr, " $%06x,X", read_24(address+1)); length += 3; break; case AX : sprintf(ptr, " $%04x,X", read_16(address+1)); length += 2; break; case AXI : sprintf(ptr, " ($%04x,X)", read_16(address+1)); length += 2; break; case AY : sprintf(ptr, " $%04x,Y", read_16(address+1)); length += 2; break; case D : sprintf(ptr, " $%02x", read_8(address+1)); length++; break; case DI : case PEI : sprintf(ptr, " ($%02x)", read_8(address+1)); length++; break; case DIY : sprintf(ptr, " ($%02x),Y", read_8(address+1)); length++; break; case DLI : sprintf(ptr, " [$%02x]", read_8(address+1)); length++; break; case DLIY: sprintf(ptr, " [$%02x],Y", read_8(address+1)); length++; break; case DX : sprintf(ptr, " $%02x,X", read_8(address+1)); length++; break; case DXI : sprintf(ptr, " ($%02x,X)", read_8(address+1)); length++; break; case DY : sprintf(ptr, " $%02x,Y", read_8(address+1)); length++; break; case S : sprintf(ptr, " %s,S", int_8_str(read_8(address+1))); length++; break; case SIY : sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1))); length++; break; case SIG : sprintf(ptr, " #$%02x", read_8(address+1)); length++; break; case MVN : case MVP : sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1)); length += 2; break; } return length; }
bool globals_load(int32_t &addr) { bool change_hw = false; uint8_t nt = read_8(addr); uint8_t ng = read_8(addr); // Free the old memory and initialize the new memory. if (nt != num_temps) { ldebug("new temp"); for (uint8_t t = nt; t < num_temps; ++t) temps[t].free(); Temp *new_temps = new Temp[nt]; for (uint8_t t = 0; t < min(nt, num_temps); ++t) temps[t].copy(new_temps[t]); for (uint8_t t = num_temps; t < nt; ++t) new_temps[t].init(); delete[] temps; temps = new_temps; num_temps = nt; } if (ng != num_gpios) { for (uint8_t g = ng; g < num_gpios; ++g) gpios[g].free(); Gpio *new_gpios = new Gpio[ng]; for (uint8_t g = 0; g < min(ng, num_gpios); ++g) gpios[g].copy(new_gpios[g]); for (uint8_t g = num_gpios; g < ng; ++g) new_gpios[g].init(); delete[] gpios; gpios = new_gpios; num_gpios = ng; } ldebug("new done"); int p = led_pin.write(); led_pin.read(read_16(addr)); if (p != led_pin.write()) change_hw = true; p = stop_pin.write(); stop_pin.read(read_16(addr)); if (p != stop_pin.write()) change_hw = true; p = probe_pin.write(); probe_pin.read(read_16(addr)); if (p != probe_pin.write()) change_hw = true; p = spiss_pin.write(); spiss_pin.read(read_16(addr)); if (p != spiss_pin.write()) change_hw = true; int t = timeout; timeout = read_16(addr); if (t != timeout) change_hw = true; bed_id = read_16(addr); fan_id = read_16(addr); spindle_id = read_16(addr); feedrate = read_float(addr); if (isnan(feedrate) || isinf(feedrate) || feedrate <= 0) feedrate = 1; max_deviation = read_float(addr); max_v = read_float(addr); int ce = read_8(addr); targetx = read_float(addr); targety = read_float(addr); double zo = read_float(addr); if (motors_busy && (current_extruder != ce || zoffset != zo) && settings.queue_start == settings.queue_end && !settings.queue_full && !computing_move) { queue[settings.queue_end].probe = false; queue[settings.queue_end].cb = false; queue[settings.queue_end].f[0] = INFINITY; queue[settings.queue_end].f[1] = INFINITY; for (int i = 0; i < spaces[0].num_axes; ++i) { queue[settings.queue_end].data[i] = spaces[0].axis[i]->settings.current - (i == 2 ? zoffset : 0); for (int s = 0; s < NUM_SPACES; ++s) queue[settings.queue_end].data[i] = space_types[spaces[s].type].unchange0(&spaces[s], i, queue[settings.queue_end].data[i]); } for (int i = spaces[0].num_axes; i < QUEUE_LENGTH; ++i) { queue[settings.queue_end].data[i] = NAN; } settings.queue_end = (settings.queue_end + 1) % QUEUE_LENGTH; // This shouldn't happen and causes communication problems, but if you have a 1-item buffer it is correct. if (settings.queue_end == settings.queue_start) settings.queue_full = true; current_extruder = ce; zoffset = zo; next_move(); buffer_refill(); } else { current_extruder = ce; zoffset = zo; } bool store = read_8(addr); if (store && !store_adc) { store_adc = fopen("/tmp/franklin-adc-dump", "a"); } else if (!store && store_adc) { fclose(store_adc); store_adc = NULL; } ldebug("all done"); if (change_hw) arch_motors_change(); return true; }