Byte Processor::execInstruction() { #ifdef R_UM_OPT_ENABLE_LOGGING #ifdef R_UM_OPT_PRC_DEBUG ic_ ++; #endif #endif Word instr = (*mm_)(0, pc_ ++); switch (decodeInstruction(instr)) { case IC_CNDMOV: return CNDMOV(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_ARRIDX: return ARRIDX(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_ARRAMD: return ARRAMD(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_ADD: return ADD(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_MUL: return MUL(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_DIV: return DIV(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_NOTAND: return NOTAND(decodeAreg(instr), decodeBreg(instr), decodeCreg(instr)); case IC_HLT: return HLT(); case IC_ALLOC: return ALLOC(decodeBreg(instr), decodeCreg(instr)); case IC_ABAND: return ABAND(decodeCreg(instr)); case IC_OUTP: return OUTP(decodeCreg(instr)); case IC_INP: return INP(decodeCreg(instr)); case IC_LDPRG: return LDPRG(decodeBreg(instr), decodeCreg(instr)); case IC_ORTHO: return ORTHO(decodeOreg(instr), decodeVal(instr)); default: assert(false); return HLT(); } }
void play(Play *play) { /* put the pieces on the board, * adjust the board data structures. */ int j; Pos p; char c; firstmove = false; /* describe the play */ if(1) { print("(%d,%d,%c) %d ", play->pos.x, play->pos.y, play->o ? 'V' : 'H', play->score); wordprint(&play->word); print("\n"); if(DBG) score(&play->word, play->pos, play->o); } assert(isword(root, &play->word)); /* place the letters */ p = play->pos; for (j= play->word.n -1; j>= 0; j--) { if(!HASLETTER(p)){ /* place the letter on the board */ LETTER(p) = play->word.c[j]; HASLETTER(p)=true; SPECIAL(p) = Not; /* not needed */ ISANCHOR(p) = false; SCORE(p) = play->word.blank[j] ? 0 : points[play->word.c[j]]; adjust(p,ORTHO(play->o)); } p = PREV(p,play->o); } p = NEXT(p,play->o); adjust(p, play->o); /* squares to the sides */ }
char* valid(Play *play) { /* Return NULL if play is valid, or a reason if the play is invalid. */ Pos p; Pos p2; int j; char c; static char buf[LLEN]; int n; Bool newletter; /* uses at least one new letter */ Bool crosscentre; /* crosses the centre square */ Bool hasanchor; /* crosses at least one anchor */ if(DBG) { print("assert (%d,%d,%c)", play->pos.x, play->pos.y, play->o == LR ? 'H' : 'V'); wordprint(&play->word); } p = play->pos; p2 = NEXT(play->pos,play->o); if (HASLETTER(p2)){ return "abuts another word\n"; } if(!isword(root, &play->word)){ return "not a word"; } newletter = crosscentre = hasanchor = false; /* For each letter of the word. */ for(j= play->word.n - 1; j>=0; j--) { if (p.x < 0 || p.y < 0 || p.x > BLEN || p.y > BLEN) return "off the edge"; c = play->word.c[j]; if (ISANCHOR(p)){ hasanchor = true; } if (HASLETTER(p)) { if (LETTER(p) != c){ sprintf(buf,"wanted %c, got %c at (%d,%d)", c+'a', LETTER(p)+'a', p.x, p.y); return buf; } } else { newletter = true; if(!firstmove){ if(!(CROSS(p,ORTHO(play->o)) & 1 << c)) { sprintf(buf,"invalid cross word at (%d,%d)",p.x,p.y); return buf; } } } if (p.x == 8 && p.y ==8){ crosscentre = true; } p = PREV(p,play->o); } if (firstmove){ DPRINT("FIRSTMOVE\n"); if (!crosscentre) return ("first move doesn't touch centre square"); } if (!(hasanchor|| firstmove)){ return ("not attached to another word"); } if(HASLETTER(p)) return "abutting another word"; if (! newletter) return "adds no letters"; return (char*)0; }