megadrive_test2

annotate tools/tunnel.c @ 10:ca7108a82867

fixed gamepad input on real megadrive
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 24 Jun 2017 02:33:52 +0300
parents 72ab63f262bf
children
rev   line source
nuclear@4 1 #include <stdio.h>
nuclear@4 2 #include <stdlib.h>
nuclear@4 3 #include <math.h>
nuclear@4 4
nuclear@5 5 #define XSZ 320
nuclear@5 6 #define YSZ 240
nuclear@4 7
nuclear@4 8 int main(void)
nuclear@4 9 {
nuclear@4 10 int i, j;
nuclear@4 11 unsigned char *pixels, *pptr;
nuclear@5 12 float aspect = (float)XSZ / (float)YSZ;
nuclear@4 13
nuclear@4 14 pixels = malloc(XSZ * YSZ);
nuclear@4 15 pptr = pixels;
nuclear@4 16
nuclear@4 17 for(i=0; i<YSZ; i++) {
nuclear@4 18 float y = 2.0 * (float)i / (float)YSZ - 1.0;
nuclear@4 19 for(j=0; j<XSZ; j++) {
nuclear@5 20 float x = aspect * (2.0 * (float)j / (float)XSZ - 1.0);
nuclear@4 21 float tu = atan2(y, x) / M_PI * 0.5 + 0.5;
nuclear@4 22 float d = sqrt(x * x + y * y);
nuclear@5 23 float tv = d == 0.0 ? 0.0 : 0.5 / d;
nuclear@4 24
nuclear@5 25 int ty = (int)(tv * 64.0) % 14 + 1;
nuclear@4 26 int tx = (int)(tu * 256.0) & 0xf;
nuclear@4 27
nuclear@5 28 if(d < 0.2) {
nuclear@5 29 *pptr++ = 0;
nuclear@5 30 } else {
nuclear@5 31 *pptr++ = tx ? ty : 0xf;
nuclear@5 32 }
nuclear@4 33 }
nuclear@4 34 }
nuclear@4 35
nuclear@4 36 pptr = pixels;
nuclear@4 37 printf("P6\n%d %d\n15\n", XSZ, YSZ);
nuclear@4 38
nuclear@4 39 for(i=0; i<YSZ; i++) {
nuclear@4 40 for(j=0; j<XSZ; j++) {
nuclear@4 41 unsigned char c = *pptr++;
nuclear@4 42 putchar(c);
nuclear@4 43 putchar(c);
nuclear@4 44 putchar(c);
nuclear@4 45 }
nuclear@4 46 }
nuclear@4 47 fflush(stdout);
nuclear@4 48
nuclear@4 49 return 0;
nuclear@4 50 }