ctp-test.4th 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. \ ctp testing
  2. base @ decimal
  3. 20 constant box-width-small
  4. 20 constant box-height-small
  5. 40 constant box-width-large
  6. 40 constant box-height-large
  7. : box-origin-large ( u -- x y w h )
  8. case
  9. 0 of \ top left
  10. 0 0
  11. endof
  12. 1 of \ top right
  13. lcd-width-pixels box-width-large - 0
  14. endof
  15. 2 of \ bottom right
  16. lcd-width-pixels box-width-large - lcd-height-pixels box-height-large - 1-
  17. endof
  18. 3 of \ bottom left
  19. 0 lcd-height-pixels box-height-large - 1-
  20. endof
  21. 4 of \ centre
  22. lcd-width-pixels 2/ box-width-large 2/ -
  23. lcd-height-pixels 2/ box-height-large 2/ -
  24. endof
  25. endcase
  26. box-width-large box-height-large \ x y w h
  27. ;
  28. : box-origin-small ( u -- x y w h )
  29. case
  30. 0 of \ top left
  31. 0 0
  32. endof
  33. 1 of \ top right
  34. lcd-width-pixels box-width-small - 0
  35. endof
  36. 2 of \ bottom right
  37. lcd-width-pixels box-width-small - lcd-height-pixels box-height-small - 1-
  38. endof
  39. 3 of \ bottom left
  40. 0 lcd-height-pixels box-height-small - 1-
  41. endof
  42. 4 of \ centre
  43. lcd-width-pixels 2/ box-width-small 2/ -
  44. lcd-height-pixels 2/ box-height-small 2/ -
  45. endof
  46. endcase
  47. box-width-small box-height-small \ x y w h
  48. ;
  49. : left-origin-small ( u -- x y w h )
  50. case
  51. 0 of \ top left
  52. 0 box-origin-small
  53. endof
  54. 1 of \ centre
  55. 4 box-origin-small
  56. endof
  57. 2 of \ bottom right
  58. 2 box-origin-small
  59. endof
  60. endcase
  61. ;
  62. : right-origin-small ( u -- x y w h )
  63. case
  64. 0 of \ top right
  65. 1 box-origin-small
  66. endof
  67. 1 of \ centre
  68. 4 box-origin-small
  69. endof
  70. 2 of \ bottom left
  71. 3 box-origin-small
  72. endof
  73. endcase
  74. ;
  75. variable 'origin
  76. : inside-box ( x y u -- flag )
  77. 'origin @ execute \ x y x0 y0 w0 h0
  78. >r >r >r \ x y x0 R: h0 w0 y0
  79. swap r> r> \ x x0 y y0 w0 R: h0
  80. -rot r> \ x x0 w0 y y0 h0
  81. over + within >r \ x x0 w0 R: f
  82. over + within r> and
  83. ;
  84. variable check-boxes
  85. variable required-lines
  86. : draw-boxes ( u -- )
  87. case
  88. 1 of
  89. 3 check-boxes !
  90. 2 required-lines !
  91. ['] left-origin-small 'origin !
  92. endof
  93. 2 of
  94. 3 check-boxes !
  95. 2 required-lines !
  96. ['] right-origin-small 'origin !
  97. endof
  98. 4 check-boxes !
  99. 4 required-lines !
  100. ['] box-origin-large 'origin !
  101. endcase
  102. lcd-cls
  103. check-boxes @ 0
  104. ?do
  105. i 'origin @ execute \ x y w h
  106. 2>r
  107. lcd-move-to lcd-black
  108. 2r> lcd-box
  109. 8 4 lcd-move-rel
  110. i [char] 1 + lcd-emit
  111. loop
  112. ;
  113. variable down
  114. variable check-counter
  115. variable inside
  116. variable in-sequence
  117. variable flag
  118. : draw-lines ( u -- flag )
  119. draw-boxes
  120. button-flush
  121. key-flush
  122. ctp-flush
  123. false down !
  124. false inside !
  125. true in-sequence !
  126. 0 check-counter !
  127. begin
  128. ctp-pos? if
  129. ctp-pos dup 0<
  130. if
  131. 2drop
  132. down @ if
  133. check-counter @ required-lines @ =
  134. inside @ and
  135. in-sequence @ and
  136. exit
  137. then
  138. else
  139. down @
  140. if
  141. false flag !
  142. check-boxes @ 0
  143. ?do
  144. 2dup
  145. i inside-box if
  146. true flag !
  147. i check-counter @ check-boxes @ mod <>
  148. if
  149. false in-sequence !
  150. then
  151. then
  152. loop
  153. flag @ if \ into box
  154. inside @ 0= if
  155. true inside !
  156. then
  157. else \ out of box
  158. inside @ if
  159. false inside !
  160. 1 check-counter +!
  161. then
  162. then
  163. lcd-line-to
  164. else
  165. lcd-move-to
  166. true down !
  167. then
  168. then
  169. then
  170. button? if
  171. button
  172. case
  173. button-left of
  174. endof
  175. button-centre of
  176. endof
  177. button-right of
  178. false exit
  179. endof
  180. endcase
  181. then
  182. key? if
  183. key-flush
  184. then
  185. \ wait-for-event
  186. again
  187. ;
  188. variable retry-count
  189. : test-ctp-tries ( u -- flag )
  190. 3 0 ?do
  191. i 0<>
  192. if
  193. lcd-cls
  194. s" CTP Test" lcd-type
  195. lcd-text-columns 2/ lcd-text-rows 2/ lcd-at-xy
  196. s" RETRY " lcd-type i lcd-.
  197. 500000 delay-us
  198. then
  199. dup draw-lines
  200. if
  201. unloop
  202. drop
  203. true exit
  204. then
  205. loop
  206. drop false
  207. ;
  208. : test-ctp-sequence ( -- flag )
  209. true
  210. 3 0 ?do
  211. i test-ctp-tries dup
  212. if
  213. s" PASS"
  214. else
  215. s" FAIL"
  216. then
  217. type ." : CTP item " i 1+ . cr
  218. and
  219. loop
  220. ;
  221. : test-ctp-main ( -- )
  222. lcd-cls
  223. test-ctp-sequence if
  224. s" PASS"
  225. else
  226. s" FAIL"
  227. then
  228. lcd-cls
  229. s" CTP Test" lcd-type
  230. lcd-text-columns 2/ lcd-text-rows 2/ lcd-at-xy
  231. 2dup lcd-type
  232. 500000 delay-us
  233. type ." : CTP test" cr
  234. ;
  235. base !