compile_gfx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #define compile_int_arg(); args = cdr(args);\
  2. if (!car(args)) { printf("error: missing arguments.\n"); return 0; }\
  3. compile_arg(JIT_R0, car(args), TAG_PURE_INT);\
  4. stack_push(JIT_R0, &stack_ptr);
  5. #define push_stack_arg(); stack_pop(JIT_R0, &stack_ptr);\
  6. jit_pushargr(JIT_R0);
  7. int compile_rect_fill(int retreg, Cell* args) {
  8. Cell* arg_x = car(args);
  9. if (!arg_x) return argnum_error("(rectfill x y w h color)");
  10. args = cdr(args);
  11. Cell* arg_y = car(args);
  12. if (!arg_y) return argnum_error("(rectfill x y w h color)");
  13. args = cdr(args);
  14. Cell* arg_w = car(args);
  15. if (!arg_w) return argnum_error("(rectfill x y w h color)");
  16. args = cdr(args);
  17. Cell* arg_h = car(args);
  18. if (!arg_h) return argnum_error("(rectfill x y w h color)");
  19. args = cdr(args);
  20. Cell* arg_c = car(args);
  21. if (!arg_c) return argnum_error("(rectfill x y w h color)");
  22. compile_arg(JIT_R0, arg_c, TAG_PURE_INT);
  23. stack_push(JIT_R0, &stack_ptr);
  24. compile_arg(JIT_R0, arg_h, TAG_PURE_INT);
  25. stack_push(JIT_R0, &stack_ptr);
  26. compile_arg(JIT_R0, arg_w, TAG_PURE_INT);
  27. stack_push(JIT_R0, &stack_ptr);
  28. compile_arg(JIT_R0, arg_y, TAG_PURE_INT);
  29. stack_push(JIT_R0, &stack_ptr);
  30. compile_arg(JIT_R0, arg_x, TAG_PURE_INT);
  31. stack_push(JIT_R0, &stack_ptr);
  32. jit_prepare();
  33. stack_pop(JIT_R0, &stack_ptr);
  34. jit_pushargr(JIT_R0);
  35. stack_pop(JIT_R0, &stack_ptr);
  36. jit_pushargr(JIT_R0);
  37. stack_pop(JIT_R0, &stack_ptr);
  38. jit_pushargr(JIT_R0);
  39. stack_pop(JIT_R0, &stack_ptr);
  40. jit_pushargr(JIT_R0);
  41. stack_pop(JIT_R0, &stack_ptr);
  42. jit_pushargr(JIT_R0);
  43. jit_finishi(machine_video_rect);
  44. jit_movi(retreg, 0);
  45. return 1;
  46. }
  47. int compile_pixel(int retreg, Cell* args) {
  48. Cell* arg_x = car(args);
  49. if (!arg_x) return argnum_error("(pixel x y color)");
  50. args = cdr(args);
  51. Cell* arg_y = car(args);
  52. if (!arg_y) return argnum_error("(pixel x y color)");
  53. args = cdr(args);
  54. Cell* arg_c = car(args);
  55. if (!arg_c) return argnum_error("(pixel x y color)");
  56. compile_arg(JIT_R0, arg_c, TAG_PURE_INT);
  57. stack_push(JIT_R0, &stack_ptr);
  58. compile_arg(JIT_R0, arg_y, TAG_PURE_INT);
  59. stack_push(JIT_R0, &stack_ptr);
  60. compile_arg(JIT_R0, arg_x, TAG_PURE_INT);
  61. stack_push(JIT_R0, &stack_ptr);
  62. jit_prepare();
  63. stack_pop(JIT_R0, &stack_ptr);
  64. jit_pushargr(JIT_R0);
  65. stack_pop(JIT_R0, &stack_ptr);
  66. jit_pushargr(JIT_R0);
  67. stack_pop(JIT_R0, &stack_ptr);
  68. jit_pushargr(JIT_R0);
  69. jit_finishi(machine_video_set_pixel);
  70. jit_movi(retreg, 0);
  71. return 1;
  72. }
  73. int compile_flip(int retreg) {
  74. jit_prepare();
  75. jit_finishi(machine_video_flip);
  76. jit_movi(retreg, 0);
  77. return 1;
  78. }
  79. int compile_blit(int retreg, Cell* args) {
  80. compile_arg(JIT_R0, car(args), TAG_BYTES);
  81. //jit_ldr(JIT_R0, JIT_R0); // load bytes addr
  82. stack_push(JIT_R0, &stack_ptr);
  83. compile_int_arg();
  84. compile_int_arg();
  85. compile_int_arg();
  86. compile_int_arg();
  87. jit_prepare();
  88. push_stack_arg();
  89. push_stack_arg();
  90. push_stack_arg();
  91. push_stack_arg();
  92. push_stack_arg(); // pop bytes addr
  93. jit_finishi(blit_vector32);
  94. jit_movi(retreg, 0);
  95. return 1;
  96. }
  97. int compile_blit_mono(int retreg, Cell* args) {
  98. compile_arg(JIT_R0, car(args), TAG_BYTES);
  99. jit_ldr(JIT_R0, JIT_R0); // load bytes addr
  100. stack_push(JIT_R0, &stack_ptr);
  101. compile_int_arg();
  102. compile_int_arg();
  103. compile_int_arg();
  104. compile_int_arg();
  105. compile_int_arg();
  106. compile_int_arg();
  107. compile_int_arg();
  108. compile_int_arg();
  109. jit_prepare();
  110. push_stack_arg();
  111. push_stack_arg();
  112. push_stack_arg();
  113. push_stack_arg();
  114. push_stack_arg();
  115. push_stack_arg();
  116. push_stack_arg();
  117. push_stack_arg();
  118. push_stack_arg(); // pop bytes addr
  119. jit_finishi(blit_vector1);
  120. jit_movi(retreg, 0);
  121. return 1;
  122. }
  123. int compile_blit_mono_inv(int retreg, Cell* args) {
  124. compile_arg(JIT_R0, car(args), TAG_BYTES);
  125. jit_ldr(JIT_R0, JIT_R0); // load bytes addr
  126. stack_push(JIT_R0, &stack_ptr);
  127. compile_int_arg();
  128. compile_int_arg();
  129. compile_int_arg();
  130. compile_int_arg();
  131. compile_int_arg();
  132. compile_int_arg();
  133. compile_int_arg();
  134. compile_int_arg();
  135. jit_prepare();
  136. push_stack_arg();
  137. push_stack_arg();
  138. push_stack_arg();
  139. push_stack_arg();
  140. push_stack_arg();
  141. push_stack_arg();
  142. push_stack_arg();
  143. push_stack_arg();
  144. push_stack_arg(); // pop bytes addr
  145. jit_finishi(blit_vector1_invert);
  146. jit_movi(retreg, 0);
  147. return 1;
  148. }
  149. int compile_blit_string(int retreg, Cell* args, int requires) {
  150. compile_arg(JIT_R0, car(args), TAG_BYTES); // font
  151. stack_push(JIT_R0, &stack_ptr);
  152. args = cdr(args);
  153. compile_arg(JIT_R0, car(args), TAG_ANY); // string
  154. stack_push(JIT_R0, &stack_ptr);
  155. compile_int_arg();
  156. compile_int_arg();
  157. compile_int_arg();
  158. compile_int_arg();
  159. compile_int_arg();
  160. compile_int_arg();
  161. jit_prepare();
  162. push_stack_arg(); // color
  163. push_stack_arg(); // h
  164. push_stack_arg(); // w
  165. push_stack_arg(); // y
  166. push_stack_arg(); // x
  167. push_stack_arg(); // cursor_pos (or -1)
  168. push_stack_arg(); // string
  169. push_stack_arg(); // font
  170. jit_finishi(blit_string1);
  171. jit_retval(retreg);
  172. box_int(retreg, requires);
  173. return 1;
  174. }