void _3dfx_DrawFlatShadedPoly( g3ds_tmap *Tmap1, unsigned long argb ) { GrVertex a, b, c; int i; float lowest_y = 10000, highest_y = 0; float lowest_x = 10000, highest_x = 0; for ( i = 0; i < Tmap1->nv; i++ ) { float x = SNAP( Tmap1->verts[i].x2d ) * fix_to_float; float y = SNAP( Tmap1->verts[i].y2d ) * fix_to_float; if ( x < lowest_x ) lowest_x = x; if ( x > highest_x ) highest_x = x; if ( y < lowest_y ) lowest_y = y; if ( y > highest_y ) highest_y = y; } if ( highest_x < 0 || highest_y < 0 || lowest_x > 639 || lowest_y > 479 ) { mprintf( ( 0, "3dfx - rejecting fspoly way off screen\n" ) ); return; } guColorCombineFunction( GR_COLORCOMBINE_CCRGB ); grConstantColorValue( argb ); a.x = SNAP( Tmap1->verts[0].x2d ) * fix_to_float; a.y = SNAP( Tmap1->verts[0].y2d ) * fix_to_float; for ( i = 1; i < Tmap1->nv - 1; i++ ) { b.x = SNAP( Tmap1->verts[i].x2d ) * fix_to_float; b.y = SNAP( Tmap1->verts[i].y2d ) * fix_to_float; c.x = SNAP( Tmap1->verts[i+1].x2d ) * fix_to_float; c.y = SNAP( Tmap1->verts[i+1].y2d ) * fix_to_float; grDrawTriangle( &a, &b, &c ); } }
int main( int argc, char *argv[] ) { int nQs,nAs,verbose; printf(VERSION); /* The following (compile time) calculations of the number of questions * (nQs) and the number of possible answers (nAs) allows the program to * adjust itself automatically to the size of the data set. * Note: the -1 allows for the fact that as a defensive measure the 0th * array elements aren't counted thus allowing the indices into arrays to * be in the range 1 to nQs and 1 to nAs respectively. I.e. we consider * the arrays to have a lower bound of 1 rather than a lower bound of 0. * I.e. this give a more intuitive mapping of the question answers, for * example, where A -> 1, B -> 2, etc. */ nQs = (int)(sizeof(questions)/sizeof(questions[0]))-1; nAs = (int)(sizeof(questions[0].pAnswers)/sizeof(questions[0].pAnswers[0]))-1; #if DEBUG printf("Number of questions is: %d\n",nQs); printf("Number of answers is: %d\n",nAs); #endif printf("%s",questions[0].pQuestion); /* 0th 'question' is the preamble */ GetAnswer("Y"); /* Wait for a response - any, in fact, will do! */ printf("\nThere are %d questions in this test. Good luck!\n\n",nQs); Countdown(3); /* Output some typical Brain Trainer eye candy! */ puts(""); questions[0].aTime = SNAP(); /* Record the start time of the test */ AskQuestions(questions,nQs,nAs); /* Self-explanatory I trust! */ SHOT(); /* Record the end time of the test */ printf("\nThanks for taking Darren's LLP Brain Trainer Test!\n" "You completed the test in %d seconds\n",(int)ELAPSED()); printf("Would you like the verbose version of your results? [Y/N]: "); verbose = (GetAnswer("NY") == 1); /* Wait for a response */ MarkAnswers(questions,nQs,options,verbose); /* Report the test results */ return(0); }
/* Unroll loop. */ static void loop_unroll(jit_State *J) { IRRef1 phi[LJ_MAX_PHI]; uint32_t nphi = 0; IRRef1 *subst; SnapNo onsnap; SnapShot *osnap, *loopsnap; SnapEntry *loopmap, *psentinel; IRRef ins, invar; /* Use temp buffer for substitution table. ** Only non-constant refs in [REF_BIAS,invar) are valid indexes. ** Caveat: don't call into the VM or run the GC or the buffer may be gone. */ invar = J->cur.nins; subst = (IRRef1 *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, (invar-REF_BIAS)*sizeof(IRRef1)) - REF_BIAS; subst[REF_BASE] = REF_BASE; /* LOOP separates the pre-roll from the loop body. */ emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0); /* Grow snapshot buffer and map for copy-substituted snapshots. ** Need up to twice the number of snapshots minus #0 and loop snapshot. ** Need up to twice the number of entries plus fallback substitutions ** from the loop snapshot entries for each new snapshot. ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap! */ onsnap = J->cur.nsnap; lj_snap_grow_buf(J, 2*onsnap-2); lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent); /* The loop snapshot is used for fallback substitutions. */ loopsnap = &J->cur.snap[onsnap-1]; loopmap = &J->cur.snapmap[loopsnap->mapofs]; /* The PC of snapshot #0 and the loop snapshot must match. */ psentinel = &loopmap[loopsnap->nent]; lua_assert(*psentinel == J->cur.snapmap[J->cur.snap[0].nent]); *psentinel = SNAP(255, 0, 0); /* Replace PC with temporary sentinel. */ /* Start substitution with snapshot #1 (#0 is empty for root traces). */ osnap = &J->cur.snap[1]; /* Copy and substitute all recorded instructions and snapshots. */ for (ins = REF_FIRST; ins < invar; ins++) { IRIns *ir; IRRef op1, op2; if (ins >= osnap->ref) /* Instruction belongs to next snapshot? */ loop_subst_snap(J, osnap++, loopmap, subst); /* Copy-substitute it. */ /* Substitute instruction operands. */ ir = IR(ins); op1 = ir->op1; if (!irref_isk(op1)) op1 = subst[op1]; op2 = ir->op2; if (!irref_isk(op2)) op2 = subst[op2]; if (irm_kind(lj_ir_mode[ir->o]) == IRM_N && op1 == ir->op1 && op2 == ir->op2) { /* Regular invariant ins? */ subst[ins] = (IRRef1)ins; /* Shortcut. */ } else { /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */ IRType1 t = ir->t; /* Get this first, since emitir may invalidate ir. */ IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2)); subst[ins] = (IRRef1)ref; if (ref != ins) { IRIns *irr = IR(ref); if (ref < invar) { /* Loop-carried dependency? */ /* Potential PHI? */ if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) { irt_setphi(irr->t); if (nphi >= LJ_MAX_PHI) lj_trace_err(J, LJ_TRERR_PHIOV); phi[nphi++] = (IRRef1)ref; } /* Check all loop-carried dependencies for type instability. */ if (!irt_sametype(t, irr->t)) { if (irt_isinteger(t) && irt_isinteger(irr->t)) continue; else if (irt_isnum(t) && irt_isinteger(irr->t)) /* Fix int->num. */ ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT)); else if (irt_isnum(irr->t) && irt_isinteger(t)) /* Fix num->int. */ ref = tref_ref(emitir(IRTGI(IR_CONV), ref, IRCONV_INT_NUM|IRCONV_CHECK)); else lj_trace_err(J, LJ_TRERR_TYPEINS); subst[ins] = (IRRef1)ref; irr = IR(ref); goto phiconv; } } else if (ref != REF_DROP && irr->o == IR_CONV && ref > invar && irr->op1 < invar) { /* May need an extra PHI for a CONV. */ ref = irr->op1; irr = IR(ref); phiconv: if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) { irt_setphi(irr->t); if (nphi >= LJ_MAX_PHI) lj_trace_err(J, LJ_TRERR_PHIOV); phi[nphi++] = (IRRef1)ref; } } } } } if (!irt_isguard(J->guardemit)) /* Drop redundant snapshot. */ J->cur.nsnapmap = (uint16_t)J->cur.snap[--J->cur.nsnap].mapofs; lua_assert(J->cur.nsnapmap <= J->sizesnapmap); *psentinel = J->cur.snapmap[J->cur.snap[0].nent]; /* Restore PC. */ loop_emit_phi(J, subst, phi, nphi, onsnap); }