void display_board(board *b) { int x, y; if (alt_video_page) { outpage(2); } else { outpage(4); } textcolour(7); clearscr(); movecur(30, 7); os_long_int_to_string(&score, 10, conv_buffer); strout("Score: "); strout(conv_buffer); for (y = 0; y < brd_h; y++) { movecur(30, y * 2 + 8); strout(seperator); movecur(30, y * 2 + 9); for (x = 0; x < brd_w; x++) { charout('|'); if ((*b)[y][x] < 10000) charout(' '); if ((*b)[y][x] < 1000) charout(' '); if ((*b)[y][x] < 100) charout(' '); if ((*b)[y][x] < 10) charout(' '); if ((*b)[y][x] == 0) { charout(' '); } else { strout(os_int_to_string((*b)[y][x])); } } charout('|'); } movecur(30, 16); strout(seperator); if (alt_video_page) { viewpage(2); alt_video_page = 0; } else { viewpage(4); alt_video_page = 1; } }
int main() { int key; init_display(); play_again: reset_game(); display_board(&grid); play_game(); movecur(15, 9 + brd_h * 2); textcolour(12); strout("Game Over! Press ESCAPE to exit or ENTER to play again."); do { key = os_wait_for_key(); } while (key != ESC_KEY && key != ENTER_KEY); if (key == ENTER_KEY) goto play_again; end_program(); }
int mandelbrot (cl_char (*data)[200], cl_fract *job) { cl_int error; int i; #if ERROR_CHECK if (prog == NULL) { init_mandelbrot(); } #endif #if MULTI_GPUS // move to new context/cq int currentdevice = nextDevice(); cl_command_queue *cq = get_command_queue(); cl_context *context = get_cl_context(); #else int currentdevice = 0; #endif // Allocate memory for the kernel to work with cl_mem mem1, mem2; mem1 = clCreateBuffer(*context, CL_MEM_WRITE_ONLY, sizeof(cl_char)*(IMAGEHEIGHT*IMAGEWIDTH*2), 0, &error); if (mandelbrot_cl_float) { cl_float jobfloat[4]; for (i=0; i<4; i++) jobfloat[i] = (cl_float) job[i]; mem2 = clCreateBuffer(*context, CL_MEM_COPY_HOST_PTR, sizeof(cl_float)*4, jobfloat, &error); } else { mem2 = clCreateBuffer(*context, CL_MEM_COPY_HOST_PTR, sizeof(cl_fract)*4, job, &error); } // get a handle and map parameters for the kernel error = clSetKernelArg(k_mandelbrot[currentdevice], 0, sizeof(cl_mem), &mem1); error = clSetKernelArg(k_mandelbrot[currentdevice], 1, sizeof(cl_mem), &mem2); // Perform the operation (width is 100 in this example) size_t worksize[3] = {IMAGEHEIGHT, IMAGEWIDTH, 0}; error = clEnqueueNDRangeKernel(*cq, k_mandelbrot[currentdevice], 2, NULL, &worksize[0], 0, 0, 0, 0); // Read the result back into data error = clEnqueueReadBuffer(*cq, mem1, CL_TRUE, 0, sizeof(cl_char)*(IMAGEHEIGHT*IMAGEWIDTH*2), data, 0, 0, 0); // cleanup - don't perform a flush as the queue is now shared between all executions. The // blocking clEnqueueReadBuffer should be enough clReleaseMemObject(mem1); clReleaseMemObject(mem2); if (error) { fprintf (stderr, "ERROR! : %s\n", errorMessageCL(error)); exit(10); } #if C_PRINT // this will print a frame coming out of the CL kernel in a dirty but functional manner int j; int colour = -1; for (i=0; i < IMAGEHEIGHT; i++) { for (j=0; j < IMAGEWIDTH*2; j++) { if (colour != data[i][j]) { colour = data[i][j]; textcolour(colour); } j++; fprintf (stdout, "%c", data[i][j]); } fprintf(stdout, "\n"); } #endif return error; }