ARM application development SDK for MNT ZZ9000 graphics and coprocessor card for classic Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blur.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * MNT ZZ9000 Amiga Graphics and ARM Coprocessor SDK
  3. * Code example: "blur"
  4. *
  5. * Copyright (C) 2019, Lukas F. Hartmann <lukas@mntre.com>
  6. * MNT Research GmbH, Berlin
  7. * https://mntre.com
  8. *
  9. * More Info: https://mntre.com/zz9000
  10. *
  11. * SPDX-License-Identifier: GPL-3.0-or-later
  12. * GNU General Public License v3.0 or later
  13. *
  14. * https://spdx.org/licenses/GPL-3.0-or-later.html
  15. */
  16. #include <stdlib.h>
  17. #include <unistd.h>
  18. #include "printf/printf.h"
  19. #include "zz9k_env.h"
  20. static uint32_t* fb=0;
  21. static uint32_t fb_pitch=0;
  22. struct ZZ9K_ENV* _zz9k_env;
  23. #define ZZ9K_APP_DATASPACE 0x05000000
  24. void __aeabi_idiv0(int r) {
  25. printf("__aeabi_idiv0()!\n");
  26. while (1) {
  27. }
  28. }
  29. void __aeabi_ldiv0(int r) {
  30. printf("__aeabi_idiv0()!\n");
  31. while (1) {
  32. }
  33. }
  34. int errno_var = 0;
  35. int* __errno() {
  36. return &errno_var;
  37. }
  38. void _putchar(char c) {
  39. _zz9k_env->putchar(c);
  40. };
  41. void set_fb(uint32_t* fb_, uint32_t pitch) {
  42. fb=fb_;
  43. fb_pitch=pitch;
  44. }
  45. void blur() {
  46. for (int y=0; y<480; y++) {
  47. for (int x=0; x<640; x++) {
  48. uint32_t s1 = fb[y*fb_pitch+x-1];
  49. uint32_t s2 = fb[y*fb_pitch+x+1];
  50. uint32_t s3 = fb[(y-1)*fb_pitch+x];
  51. uint32_t s4 = fb[(y+1)*fb_pitch+x];
  52. uint32_t s1r = (s1>>16)&0xff;
  53. uint32_t s1g = (s1>>8)&0xff;
  54. uint32_t s1b = s1&0xff;
  55. uint32_t s2r = (s2>>16)&0xff;
  56. uint32_t s2g = (s2>>8)&0xff;
  57. uint32_t s2b = s2&0xff;
  58. uint32_t s3r = (s3>>16)&0xff;
  59. uint32_t s3g = (s3>>8)&0xff;
  60. uint32_t s3b = s3&0xff;
  61. uint32_t s4r = (s4>>16)&0xff;
  62. uint32_t s4g = (s4>>8)&0xff;
  63. uint32_t s4b = s4&0xff;
  64. uint32_t r = (s1r+s2r+s3r+s4r)/4;
  65. if (r>0xff) r = 0xff;
  66. uint32_t g = (s1g+s2g+s3g+s4g)/4;
  67. if (g>0xff) g = 0xff;
  68. uint32_t b = (s1b+s2b+s3b+s4b)/4;
  69. if (b>0xff) b = 0xff;
  70. fb[y*fb_pitch+x] = (r<<16)|(g<<8)|b;
  71. }
  72. }
  73. }
  74. int __attribute__ ((section (".binstart"))) main(struct ZZ9K_ENV* env) {
  75. _zz9k_env = env;
  76. if (!env) {
  77. return 1;
  78. }
  79. if (env->argc<2) {
  80. return 1;
  81. }
  82. // arg0: framebuffer pointer
  83. // arg1: screen width
  84. set_fb((uint32_t*)env->argv[0],env->argv[1]);
  85. while (1) {
  86. blur();
  87. }
  88. return 0;
  89. }