void c_func_cmp (ea_t *src, ea_t *dest, int size) { char buf[256]; const char *sz = c_ssizes[size]; const char *usz = c_usizes[size]; c_fncall (); c_fnbegin (); c_readea (dest, buf); cln ("s32 dest = %s;\n", buf); c_readea (src, buf); cln ("s32 src = %s;\n", buf); cln ("s32 val = (%s)dest - (%s)src;", sz, sz); ifV cln ("s32 flgs = ((%s)src) < 0;", sz); ifV cln ("s32 flgo = ((%s)dest) < 0;", sz); ifVoN cln ("s32 flgn = ((%s)val) < 0;", sz); ifV cln ("V = ((flgs != flgo) && (flgn != flgo));"); ifC cln ("C = ((%s)src) > ((%s)dest);", usz, usz); ifN cln ("N = (flgn != 0);"); ifZ cln ("nZ = val;"); c_postea (dest); c_postea (src); c_fnend (); }
void c_func_rts () { if (gen_mode != GEN_CALL) return; cln ("jdest = rdlong (Regs[15]._u32);"); cln ("Regs[15]._s32 += 4;"); cln ("goto jumptable;"); }
void c_func_cmpa (ea_t *src, ea_t *dest, int size) { char buf[256]; const char *sz = c_ssizes[size]; c_fncall (); c_fnbegin (); cln ("s32 dest = Regs[%d]._s32;\n", dest->reg); c_readea (src, buf); cln ("%s src = %s;\n", sz, buf); cln ("s32 val = (s32)dest - (s32)src;"); ifV cln ("s32 flgs = ((s32)src) < 0;"); ifV cln ("s32 flgo = ((s32)dest) < 0;"); ifVoN cln ("s32 flgn = ((s32)val) < 0;"); ifZ cln ("nZ = val;"); ifV cln ("V = ((flgs != flgo) && (flgn != flgo));"); ifC cln ("C = ((u32)src) > ((u32)dest);"); ifN cln ("N = (flgn != 0);"); c_postea (dest); c_postea (src); c_fnend (); }
/* Check for pending exceptions also */ void c_jump_e (ea_t *ea) { char buf[256]; if (gen_mode != GEN_CALL) return; c_ea_get_address (ea, buf); cln ("{"); cln ("if ((exceptions_pending) && (rdest == 0)) {"); if (((ea->mode == 7) && (ea->reg == 1)) || ((ea->mode == 7) && (ea->reg == 2))) { cln (" rdest = __D%s;", ea->imm.label); } else { cln (" rdest = %s;", buf); } c_postea (ea); cln (" goto handle_exception;", buf); cln ("} else {"); if (((ea->mode == 7) && (ea->reg == 1)) || ((ea->mode == 7) && (ea->reg == 2))) { cln (" goto __N%s;", ea->imm.label); } else { cln (" jdest = %s;", buf); c_postea (ea); cln (" goto jumptable;"); } cln ("}}"); }
void c_func_bset (ea_t *src, ea_t *dest, int size) { int len; const char *sz; char buf[256]; c_fncall (); c_fnbegin (); sz = c_usizes[size]; if (size == BYTE) len = 8; else if (size == WORD) len = 16; else len = 32; c_readea (src, buf); cln ("%s src = %s;", sz, buf); c_readea (dest, buf); cln ("%s dest = %s;", sz, buf); cln ("src &= %d;", len-1); ifZ { cln ("nZ = !(1 ^ ((dest >> src) & 1));"); } cln ("dest |= (1 << src);"); c_writeea (dest, size, "dest"); c_postea (src); c_postea (dest); c_fnend (); }
void c_func_rte () { if (gen_mode != GEN_CALL) return; cln ("N=bN; nZ=bnZ; V=bV; C=bC; X=bX;"); cln ("jdest = rdest;"); cln ("rdest = 0;"); cln ("goto jumptable;"); }
void c_func_movem (ea_t *ea, int sz, int dr, int reg_mask) { int i, offset; char buf[256]; const char *read_func; const char *write_func; c_fncall (); c_fnbegin (); sz++; read_func = mem_read_funcs[sz]; write_func = mem_write_funcs[sz]; c_ea_get_address (ea, buf); if (dr == 0) { /* reg to memory */ cln ("s32 dest = %s;", buf); if (ea->mode == 4) { /* pre-decrement mode */ offset = 0; for (i=0; i<16; i++) { if (reg_mask & (1<<i)) { cln ("%s (dest, Regs[%d]._%s);", write_func, 15-i, c_usizes[sz]); cln ("dest -= %d;", 1<<sz); offset += 1<<sz; } } cln ("Regs[%d]._s32 -= %d;", ea->reg, offset); } else { for (i=0; i<16; i++) { if (reg_mask & (1<<i)) { cln ("%s (dest, Regs[%d]._%s);", write_func, i, c_usizes[sz]); cln ("dest += %d;", 1<<sz); } } } } else { /* mem to reg */ cln ("s32 src = %s;", buf); offset = 0; for (i=0; i<16; i++) { if (reg_mask & (1<<i)) { cln ("Regs[%d]._s32 = %s (src);", i, read_func); cln ("src += %d;", 1<<sz); offset += 1<<sz; } } /* post-inc mode */ if (ea->mode == 3) cln ("Regs[%d]._s32 += %d;", ea->reg, offset); } c_fnend (); }
void c_func_pea (ea_t *ea) { char buf[256]; if (gen_mode != GEN_CALL) return; c_ea_get_address (ea, buf); cln ("Regs[15]._u32 -= 4;"); cln ("wrlong (Regs[15]._u32, %s);", buf); }
void c_func_exg (int reg1, int reg2) { c_fncall (); c_fnbegin (); cln ("u32 temp = Regs[%d]._u32;", reg1); cln ("Regs[%d]._u32 = Regs[%d]._u32;", reg1, reg2); cln ("Regs[%d]._u32 = temp;", reg2); c_fnend (); }
void c_func_unlk (int reg) { c_fncall (); c_fnbegin (); cln ("Regs[15]._u32 = Regs[%d]._u32;", reg); cln ("Regs[%d]._u32 = rdlong (Regs[15]._u32);", reg); cln ("Regs[15]._u32 += 4;"); c_fnend (); }
void c_func_link (int reg, int val) { c_fncall (); c_fnbegin (); cln ("Regs[15]._u32 -= 4;"); cln ("wrlong (Regs[15]._u32, Regs[%d]._u32);", reg); cln ("Regs[%d]._u32 = Regs[15]._u32;", reg); cln ("Regs[15]._u32 += 0x%x;", val); c_fnend (); }
void c_addr_label (int labelled) { if (labelled || return_target || (get_bitpos () == 0x1c)) { cout ("\tcase (0x%x):\n", get_bitpos ()); } cln ("#ifdef M68K_DEBUG"); cln (" line_no = %d;", line_no); #ifdef DUMP_LOADS_OF_CRAP cln (" DumpRegsChanged ();"); #endif /* DUMP_LOADS_OF_CRAP */ cln ("#endif"); }
void c_func_clr (ea_t *dest) { c_fncall (); c_fnbegin (); c_writeea (dest, dest->op_size, "0"); c_postea (dest); ifN cln ("N = 0;"); ifZ cln ("nZ = 0;"); ifV cln ("V = 0;"); ifC cln ("C = 0;"); c_fnend (); }
void c_func_tst (ea_t *ea) { char buf[256]; c_fncall (); c_fnbegin (); c_readea (ea, buf); cln ("nZ = %s;", buf); c_postea (ea); ifN cln ("N = nZ < 0;"); ifV cln ("V = 0;"); ifC cln ("C = 0;"); c_fnend (); }
void c_func_jsr (ea_t *dest) { char buf[256]; if (gen_mode != GEN_CALL) return; snprintf (buf, sizeof (buf), "%x", get_bitpos ()); add_label (buf, C_ADDR, get_bitpos () - BASE); add_fixup (0, C_ADDR, buf); snprintf (buf, sizeof (buf), "__D%x", get_bitpos ()); cln ("Regs[15]._s32 -= 4;"); cln ("wrlong (Regs[15]._s32, %s);", buf); c_jump (dest); }
static void c_postea (ea_t *ea) { int inc; inc = 1<<ea->op_size; if ((ea->reg == 15) && (inc == 1)) inc = 2; switch (ea->mode) { /* areg postinc */ case 3: cln ("Regs[%d]._s32 += %d;", ea->reg, inc); break; /* areg predec */ case 4: cln ("Regs[%d]._s32 -= %d;", ea->reg, inc); break; default: break; } }
void c_func_scc (ea_t *dest, int cond) { c_fncall (); c_fnbegin (); cout ("\tif ("); c_eval_cond (cond); cout (") {\n"); c_writeea (dest, BYTE, "0xff"); cln ("} else {"); c_writeea (dest, BYTE, "0"); cln ("}"); c_postea (dest); c_fnend (); }
virtual void operator()(const CNetScheduleAdmin::SWorkerNodeInfo& info) { CNetScheduleAPI cln(info.host + ":" + NStr::UIntToString(info.port), "netschedule_admin", "noname"); cln.GetAdmin().ShutdownServer(m_Level); }
void c_jump (ea_t *ea) { char buf[256]; if (gen_mode != GEN_CALL) return; c_ea_get_address (ea, buf); cln ("{"); if (((ea->mode == 7) && (ea->reg == 1)) || ((ea->mode == 7) && (ea->reg == 2))) { cln (" goto __N%s;", ea->imm.label); } else { cln (" jdest = %s;", buf); c_postea (ea); cln (" goto jumptable;"); } cln ("}"); }
void c_func_suba (ea_t *src, int dest_reg, int size) { char buf[256]; if (gen_mode != GEN_CALL) return; c_readea (src, buf); cln ("Regs[%d]._u32 = Regs[%d]._s32 - (%s)%s;", dest_reg, dest_reg, c_ssizes[size], buf); c_postea (src); }
void c_func_lea (ea_t *ea, int reg) { char buf[256]; if (gen_mode != GEN_CALL) return; c_ea_get_address (ea, buf); cln ("Regs[%d]._u32 = %s;", reg, buf); }
void c_func_move (ea_t *src, ea_t *dest, int size) { char buf[256]; c_fncall (); c_fnbegin (); c_readea (src, buf); cln ("s32 val = %s;", buf); c_writeea (dest, size, "val"); c_postea (src); c_postea (dest); ifZ cln ("nZ = val;"); ifN cln ("N = val < 0;"); ifV cln ("V = 0;"); ifC cln ("C = 0;"); c_fnend (); }
void c_func_movea (ea_t *src, int reg_dest) { char buf[256]; if (gen_mode != GEN_CALL) return; assert (reg_dest > 7); c_readea (src, buf); cln ("Regs[%d]._s32 = %s;", reg_dest, buf); c_postea (src); }
/* XXX note: this does not call c_jump and therefore does not * check for pending exceptions. an infinite DBcc loop will not * allow exceptions to occur. * does it matter? */ void c_func_dbcc (const char *label, int cond, int reg) { if (gen_mode != GEN_CALL) return; if (cond == 0) { cln ("if (--Regs[%d]._s16 != -1) goto __N%s;\n", reg, label); } else { cout ("\tif ((!"); c_eval_cond (cond); cout (") && (--Regs[%d]._s16 != -1)) goto __N%s;\n", reg, label); } }
void c_func_neg (ea_t *ea, int size) { char buf[256]; c_fncall (); c_fnbegin (); c_readea (ea, buf); cln ("%s src = %s;", c_ssizes[size], buf); cln ("%s dest = ((%s)0) - ((%s)src);", c_usizes[size], c_ssizes[size], c_ssizes[size]); cln ("int flgs, flgn;"); cln ("flgs = ((%s)src) < 0;", c_ssizes[size]); cln ("flgn = ((%s)dest) < 0;", c_ssizes[size]); ifZ { cln ("nZ = dest;"); } ifV { cln ("V = (flgs & flgn);"); } cln ("X = (dest != 0);"); ifC { cln ("C = X;"); } ifN { cln ("N = (flgn != 0);"); } c_writeea (ea, size, "dest"); c_postea (ea); c_fnend (); }
void c_func_negx (ea_t *ea, int size) { char buf[256]; c_fncall (); c_fnbegin (); c_readea (ea, buf); /* XXX is nZ flag correct here? */ cln ("%s src = %s;", c_ssizes[size], buf); cln ("u32 dest = (0 - src) - (X ? 1 : 0);"); cln ("int flgs, flgn;"); cln ("flgs = ((%s)src) < 0;", c_ssizes[size]); cln ("flgn = ((%s)dest) < 0;", c_ssizes[size]); ifZ { cln ("nZ = !((!nZ) & (((%s)(dest)) == 0));", c_ssizes[size]); } ifV { cln ("V = (flgs & flgn);"); } cln ("X = flgs ^ ((flgs ^ flgn) & (flgn));"); ifC { cln ("C = X;"); } ifN { cln ("N = ((%s)dest) < 0;", c_ssizes[size]); } c_writeea (ea, size, "dest"); c_postea (ea); c_fnend (); }
static complex complex_pow(complex a, complex b) { /* a^z = e^(z * ln(a)) */ complex c, d; c = a; d = b; cln(&c); mult(&d, c); complex_exp(&d); return d; }
int main(int argc, char* argv[]) { try { char const* port = argc > 1 ? argv[1] : "10001"; server svr("127.0.0.1", std::atoi(port)); client cln("127.0.0.1", port); } catch (std::exception& ex) { std::cerr << ex.what() << std::endl; } return 0; }
void c_begin (const char *src_filename, const char *bin_filename) { char buf[128]; snprintf (buf, sizeof (buf), ".%s.c", src_filename); if ((c_out = fopen (buf, "w"))==NULL) { fprintf (stderr, "Error: Cannot open %s for writing.\n", buf); exit (-1); } snprintf (buf, sizeof (buf), ".%s.fn.c", src_filename); if ((c_out2 = fopen (buf, "w"))==NULL) { fprintf (stderr, "Error: Cannot open %s for writing.\n", buf); exit (-1); } cout ("void Init680x0 () {\n"); cln ("STRam = &m68kram[0];"); cln ("load_binfile (\"%s\");", bin_filename); cout ("}\n"); cout ("void Start680x0 ()\n{\n"); cout ("\ts32 i, jdest = 0x1c;\n"); cout ("\tRegs[15]._u32 = MEM_SIZE;\n\n"); cout ("jumptable:\n\tswitch (jdest) {\n"); }
/////////////////////////////////////////////////////////////////////////////// // Worker function for the client thread DWORD WINAPI clientThread(LPVOID lpParam) {CLIENT *pc = Clns + (int)lpParam; SOCKET sock = pc->sock; Client cln(&(pc->addr)); char szBuff[BUFFER_LEN], *rpl; int ret; // print info printf("%02d new client from %s:%d\n", pc->idx, inet_ntoa(pc->addr.sin_addr), ntohs(pc->addr.sin_port)); // main loop while(1) {// perform a blocking recv() call ret = recv(sock, szBuff, BUFFER_LEN, 0); if (ret == 0) break; // Graceful close else if (ret == SOCKET_ERROR) {printf("%02d recv() failed: %d\n", pc->idx, WSAGetLastError()); break; } // print command szBuff[ret] = '\0'; printf("%02d RECV: '%s'\n", pc->idx, szBuff); // parse command rpl = cln.ParseCommand(szBuff); // send reply send(sock, rpl, strlen(rpl), 0); printf("%02d SEND: '%s'\n", pc->idx, rpl); // is it request to quit? if (strcmp(rpl, cs_quit) == 0) break; } // print info printf("%02d connection with client %s:%d closed\n", pc->idx, inet_ntoa(pc->addr.sin_addr), ntohs(pc->addr.sin_port)); // close socket closesocket(sock); // free slot pc->sock = INVALID_SOCKET; // that's all return 0; }