cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

rand.c (1702B)


      1/***************************************************************************
      2 *                                                                         *
      3 * Module  : rand.c                                                        *
      4 *                                                                         *
      5 * Purpose : A test for the rand() function, for the GBDK                  *
      6 *                                                                         *
      7 * Version : 1, Januari 6 1998                                             *
      8 *                                                                         *
      9 * Author  : Luc Van den Borre ( Homepage : NOC.BASE.ORG )                 *
     10 *                                                                         *
     11 **************************************************************************/
     12
     13#include <gb/gb.h>
     14#include <stdint.h>
     15#include <rand.h>
     16#include <gb/drawing.h>
     17#include <stdio.h>
     18#include <string.h>
     19
     20uint8_t accu[80];
     21uint8_t accua[80];
     22
     23void main(void)
     24{
     25  uint8_t r, s, t = 0, u = 0;
     26  uint16_t seed;
     27
     28  memset(accu, 0, sizeof(accu));
     29  memset(accua, 0, sizeof(accua));
     30
     31  /* We use the DIV register to get a random initial seed */
     32  puts("Getting seed");
     33  puts("Push any key (1)");
     34  waitpad(0xFF);
     35  waitpadup();
     36  seed = DIV_REG;
     37  puts("Push any key (2)");
     38  waitpad(0xFF);
     39  waitpadup();
     40  seed |= (uint16_t)DIV_REG << 8;
     41
     42  /* initarand() calls initrand() */
     43  initarand(seed);
     44
     45  do {
     46    r = rand();
     47    s = arand();
     48
     49    if(r < 80) {
     50      t = ++accu[r];
     51      plot(r, 144-t, LTGREY, SOLID);
     52    }
     53    if(s < 80) {
     54      u = ++accua[s];
     55      plot(s+80, 144-u, DKGREY, SOLID);
     56    }
     57  }
     58  while(t != 144 && u != 144); 
     59}