ARM application development SDK for MNT ZZ9000 graphics and coprocessor card for classic Amiga computers.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

107 Zeilen
2.2KB

  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include "printf/printf.h"
  4. #include "zz9k_env.h"
  5. // matrix width and height
  6. #define CONW_W 320
  7. #define CONW_H (240-16)
  8. unsigned char univ[CONW_H][CONW_W];
  9. unsigned char new[CONW_H][CONW_W];
  10. void __aeabi_idiv0(int r) {
  11. printf("__aeabi_idiv0()!\n");
  12. while (1) {
  13. }
  14. }
  15. void __aeabi_ldiv0(int r) {
  16. printf("__aeabi_idiv0()!\n");
  17. while (1) {
  18. }
  19. }
  20. unsigned int lfsr113 (void)
  21. {
  22. static unsigned int z1 = 12345, z2 = 12345, z3 = 12345, z4 = 12345;
  23. unsigned int b;
  24. b = ((z1 << 6) ^ z1) >> 13;
  25. z1 = ((z1 & 4294967294U) << 18) ^ b;
  26. b = ((z2 << 2) ^ z2) >> 27;
  27. z2 = ((z2 & 4294967288U) << 2) ^ b;
  28. b = ((z3 << 13) ^ z3) >> 21;
  29. z3 = ((z3 & 4294967280U) << 7) ^ b;
  30. b = ((z4 << 3) ^ z4) >> 12;
  31. z4 = ((z4 & 4294967168U) << 13) ^ b;
  32. return (z1 ^ z2 ^ z3 ^ z4);
  33. }
  34. // Lifted from https://rosettacode.org/wiki/Conway%27s_Game_of_Life#C
  35. void show(uint32_t* fb, int fbw, int w, int h)
  36. {
  37. for (int y = 0; y < h; y++) {
  38. for (int x = 0; x < w; x++) {
  39. fb[y*fbw+x] = (univ[y][x] ? 0xffffff : 0x000000);
  40. }
  41. }
  42. }
  43. void evolve(int w, int h)
  44. {
  45. for (int y = 0; y < h; y++) {
  46. for (int x = 0; x < w; x++) {
  47. int n = 0;
  48. for (int y1 = y - 1; y1 <= y + 1; y1++) {
  49. for (int x1 = x - 1; x1 <= x + 1; x1++) {
  50. if (univ[(y1 + h) % h][(x1 + w) % w])
  51. n++;
  52. }
  53. }
  54. if (univ[y][x]) n--;
  55. new[y][x] = (n == 3 || (n == 2 && univ[y][x]));
  56. }
  57. }
  58. for (int y = 0; y < h; y++) {
  59. for (int x = 0; x < w; x++) {
  60. univ[y][x] = new[y][x];
  61. }
  62. }
  63. }
  64. void init(int w, int h) {
  65. for (int x = 0; x < w; x++) {
  66. for (int y = 0; y < h; y++) {
  67. univ[y][x] = lfsr113() < RAND_MAX / 10 ? 1 : 0;
  68. }
  69. }
  70. }
  71. struct ZZ9K_ENV* _zz9k_env;
  72. void _putchar(char c) {
  73. _zz9k_env->putchar(c);
  74. };
  75. void __attribute__ ((section (".binstart"))) main(struct ZZ9K_ENV* env) {
  76. _zz9k_env = env;
  77. if (!env) {
  78. return;
  79. }
  80. if (env->argc<2) {
  81. return;
  82. }
  83. init(CONW_W, CONW_H);
  84. while (1) {
  85. evolve(CONW_W, CONW_H);
  86. // arg0: framebuffer pointer (32bpp)
  87. // arg1: framebuffer width in pixels
  88. show((uint32_t*)env->argv[0], (uint32_t)env->argv[1], CONW_W, CONW_H);
  89. }
  90. }