home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / spiele / quintom / quintom.exe / Quint150.txt < prev    next >
Encoding:
Text File  |  1999-07-15  |  9.6 KB  |  552 lines

  1. \ Quintominoes v1.50
  2. \ ERS 15JULY1999
  3. needs graphics 
  4. needs Events
  5. needs toolkit
  6. needs case
  7. needs resources
  8. needs ids
  9.  
  10. decimal
  11.  
  12. here constant prefs 
  13. \ Begin of data area to be saved in Prefs
  14.  
  15. \ Now defining the pieces
  16. \ and their initial locations
  17. : pentos ( n --- 10*n )    \ offset of a piece-cell
  18. 5 cells * ;
  19.  
  20. create q-all 12 pentos  allot
  21. : q-all-f
  22. q-all  
  23. 2 8 * over ! 1 cells +
  24. 1 8 * over ! 1 cells + 
  25. [ 2 base ! ]
  26. 0 over c! 1+
  27. 0 over c! 1+
  28. 11111 over c! 1+
  29. 0 over c! 1+
  30. 0 over ! 1 cells +
  31. [ decimal ]
  32.  
  33. 5 8 * over ! 1 cells +
  34. 1 8 * over ! 1 cells +
  35. [ 2 base ! ]
  36. 0 over c! 1+
  37. 01000 over c! 1+
  38. 01111 over c! 1+
  39. 0 over c! 1+
  40. 0 over ! 1 cells +
  41. [ decimal ]
  42.  
  43. 8 8 * over ! 1 cells +
  44. 1 8 * over ! 1 cells +
  45. [ 2 base ! ]
  46. 0 over c! 1+
  47. 00100 over c! 1+
  48. 01111 over c! 1+
  49. 0 over c! 1+
  50. 0 over ! 1 cells +
  51. [ decimal ]
  52.  
  53. 12 8 * over ! 1 cells +
  54. 1 8 * over ! 1 cells +
  55. [ 2 base ! ]
  56. 0 over c! 1+
  57. 01100 over c! 1+
  58. 00111 over c! 1+
  59. 0 over c! 1+
  60. 0 over ! 1 cells +
  61. [ decimal ]
  62.  
  63. 2 8 * over ! 1 cells +
  64. 6 8 * over ! 1 cells +
  65. [ 2 base ! ]
  66. 0 over c! 1+
  67. 01100 over c! 1+
  68. 01110 over c! 1+
  69. 0 over c! 1+
  70. 0 over ! 1 cells +
  71. [ decimal ]
  72.  
  73. 6 8 * over ! 1 cells +
  74. 6 8 * over ! 1 cells +
  75. [ 2 base ! ]
  76. 0 over c! 1+
  77. 01010 over c! 1+
  78. 01110 over c! 1+
  79. 0 over c! 1+
  80. 0 over ! 1 cells +
  81. [ decimal ]
  82.  
  83. 11 8 * over ! 1 cells +
  84. 6 8 * over ! 1 cells +
  85. [ 2 base ! ]
  86. 0 over c! 1+
  87. 00010  over c! 1+
  88. 00010 over c! 1+
  89. 01110 over c! 1+
  90. 0 over ! 1 cells +
  91. [ decimal ]
  92.  
  93. 6 8 * over ! 1 cells +
  94. 11 8 * over ! 1 cells +
  95. [ 2 base ! ]
  96. 0 over c! 1+
  97. 00100 over c! 1+
  98. 00100 over c! 1+
  99. 01110 over c! 1+
  100. 0 over ! 1 cells +
  101. [ decimal ]
  102.  
  103. 11 8 * over ! 1 cells +
  104. 11 8 * over ! 1 cells +
  105. [ 2 base ! ]
  106. 0 over c! 1+
  107. 00100 over c! 1+
  108. 00110 over c! 1+
  109. 01100 over c! 1+
  110. 0 over ! 1 cells +
  111. [ decimal ]
  112.  
  113. 2 8 * over ! 1 cells +
  114. 15 8 * over ! 1 cells +
  115. [ 2 base ! ]
  116. 0 over c! 1+
  117. 00110 over c! 1+
  118. 00100 over c! 1+
  119. 01100 over c! 1+
  120. 0 over ! 1 cells +
  121. [ decimal ]
  122.  
  123. 6 8 * over ! 1 cells +
  124. 15 8 * over ! 1 cells +
  125. [ 2 base ! ]
  126. 0 over c! 1+
  127. 00100 over c! 1+
  128. 01110 over c! 1+
  129. 00100 over c! 1+
  130. 0 over ! 1 cells +
  131. [ decimal ]
  132.  
  133. 12 8 * over ! 1 cells +
  134. 15 8 * over ! 1 cells +
  135. [ 2 base ! ]
  136. 0 over c! 1+
  137. 01000 over c! 1+
  138. 01100 over c! 1+
  139. 00110 over c! 1+
  140. 0 swap ! ;
  141. decimal
  142.  
  143. variable act
  144. \ status variable, selected piece
  145.  
  146. here prefs - constant prefsize
  147. \ End of data for Prefs
  148.  
  149. create q13 1 pentos allot 
  150. \ Swap/Scrap area
  151.  
  152. variable tg
  153. \ Auxilliary variable
  154.  
  155. 10 130 2constant FormBounds
  156.  
  157.  
  158. : q-unc ( y x --- )
  159. >r >r 8 8 r>  r> 
  160. erase-rectangle ;
  161. : q-c ( y x --- )
  162. >r >r 8 8 r> r>
  163. rectangle ;
  164. : q-l ( y x --- )
  165. 2dup swap 7 + swap line ;
  166. : q-r  ( y x --- )
  167. 7 + q-l ; 
  168. : q-t ( y x --- )
  169. 2dup 7 + line ;
  170. : q-b  ( y x --- )
  171. swap 7 + swap q-t ;
  172. \ Assorted drawing routines,
  173. \ Blocks for selected piece,
  174. \ Borderlines for others. All ( y x --- )
  175.  
  176.  
  177. : thisbit? ( addr col row --- bool ) 
  178. rot 2 cells + +  c@ swap rshift 1 and 
  179. ;
  180. : upperbit? ( addr col row --- bool )
  181. ?dup if 1 - thisbit? else 2drop 0 then
  182. ;
  183. : lowerbit? ( addr col row --- bool )
  184. dup 4 < if 1 + thisbit? else 2drop drop 0 then
  185. ;
  186. : rightbit? ( addr col row --- bool )
  187. swap ?dup if 1 - swap thisbit? else 2drop 0 then
  188. ;
  189. : leftbit? ( addr col row --- bool )
  190. swap dup 4 < if 1 + swap thisbit? else 2drop drop 0 then
  191. ;  
  192. \ Test for blocks and relative
  193. \ positions in pieces, needed for
  194. \ proper drawing
  195.  
  196.  
  197. : scr-pos-p1 ( addr row --- addr row absy xbasepos )
  198. over  @ over 8 * + 2 pick 1 cells +  @
  199. ;
  200.  
  201. : scr-pos-p2 ( absy xbasepos relx --- absy absx yboundsflag )  
  202. 8 * + over FormBounds within
  203. ;
  204. \ absolute screen positioning, parts one and two 
  205.  
  206. : q-unblock ( addr row --- )
  207. 5 0 do over over i  swap thisbit?  
  208.  if  
  209.  scr-pos-p1 i scr-pos-p2 if q-unc else 2drop then 
  210. then
  211. loop
  212. 2drop
  213. ;
  214. \ undraws a row of given piece
  215.  
  216. : q-block ( addr row --- )
  217. tg @ if
  218. 5 0 do over over i  swap thisbit?  
  219.  if  
  220.  scr-pos-p1 i scr-pos-p2 if q-c else 2drop then
  221. then
  222. loop
  223.  
  224. else
  225. 5 0 do over over i  swap thisbit? 
  226. if  
  227.  
  228.  over over i  swap rightbit? 0= if
  229.  scr-pos-p1 i scr-pos-p2 if q-l else 2drop then
  230.  then
  231.  
  232.  over over i  swap leftbit? 0= if
  233.  scr-pos-p1 i scr-pos-p2 if q-r else 2drop then
  234.  then
  235.  
  236.  over over i  swap upperbit? 0= if
  237.  scr-pos-p1 i scr-pos-p2 if q-t else 2drop then 
  238.  then
  239.  
  240.  over over i  swap lowerbit? 0= if
  241.  scr-pos-p1 i scr-pos-p2 if q-b else 2drop then
  242.  then
  243.  
  244. then 
  245. loop
  246.  
  247. then
  248. 2drop
  249. ;
  250. \ Draws each row of each given piece
  251.  
  252.  : q-undraw ( n --- )
  253.    dup if
  254.   1 - q-all swap pentos + 
  255.   5 0 do dup i  
  256.   q-unblock
  257.   loop
  258. then
  259. drop
  260. ;
  261. \ Entry to undraw a piece, calls row undraw
  262. \ routine
  263.  
  264.  : q-draw ( addr --- )
  265.   5 0 do dup i  
  266.   q-block
  267.   loop
  268.   drop
  269. ;
  270. \ Entry to draw a piece, calls row draw 
  271. \ routine
  272.  
  273.  
  274. : q-col ( val i --- )
  275. swap 
  276. 5 0 do dup i rshift 1 and
  277. 2 pick 
  278.  lshift q13 8 + i - dup >r 
  279. c@ or r>  c! 
  280. loop
  281. 2drop
  282. ;
  283. \ column handler for rotating 
  284. \ a piece
  285.  
  286.  
  287. : q-rot ( addr --- )
  288. q13 9 0 do dup i + 0 swap c! Loop drop
  289. 2 cells + 5 0 do dup
  290. i +   c@ i q-col
  291. loop
  292. 5 0 do dup q13 2 cells + i + c@ swap c!
  293. 1+ 
  294.  loop
  295. drop
  296. ;
  297. \ entry for piece rotation, calls
  298. \ column handler
  299.  
  300. : q-flip ( addr --- )
  301. q13 9 0 do dup i + 0 swap c! Loop drop 2 cells +
  302. 5 0 do dup i  +  c@ q13 8 + i -
  303. c! Loop 
  304. 5 0 do dup q13 2 cells + i + c@ swap c!
  305. 1+ 
  306. loop
  307.  drop
  308. ;
  309. \ routine to flip a piece
  310.  
  311. : q-paint-all ( --- )  
  312.  
  313. 12 0 do i 1+ act @ = if
  314. 1 tg ! Else 0 tg ! then
  315. q-all i pentos +  
  316. q-draw
  317. loop 
  318. ;
  319. \ name says it
  320.  
  321.  
  322. : q-rt ( --- )
  323. q-all act @ dup q-undraw 1 - pentos + 
  324. q-rot ;
  325.  
  326. : q-flp ( --- )
  327. q-all act @ dup q-undraw 1 - pentos + 
  328. q-flip ;
  329.  
  330. : q-left ( --- )
  331. q-all act @ dup q-undraw 1 - pentos +  1 cells + dup
  332. @ 8 - swap !
  333. ;
  334.  
  335. : q-right ( --- )
  336. q-all act @ dup q-undraw 1 - pentos +  1 cells + dup
  337. @ 8 + swap !
  338. ;
  339.  
  340. : q-up ( --- )
  341. q-all act @ dup q-undraw 1 - pentos +  dup
  342. @ 8 - swap !
  343. ;
  344. : q-down ( --- )
  345. q-all act @ dup q-undraw 1 - pentos +  dup
  346. @ 8 + swap !
  347. ;
  348. \ ... how to move them pieces
  349.  
  350.  
  351.  
  352. 3000 constant AboutBox
  353. 3001 constant HelpString
  354.  
  355. 2001 constant AboutMenuItem
  356. 2002 constant HelpMenuItem
  357. 2003 constant RestartMenuItem
  358. 2004 constant DeslctMenuItem
  359. 2005 constant RefreshMenuItem 
  360.  
  361. 516 constant CalendarKey
  362. 517 constant AddressKey
  363. 518 constant ToDoKey
  364. 519 constant MemoKey
  365. 11 constant UpKey
  366. 12 constant DownKey
  367.  
  368. 266 constant SilkFindKey
  369. \ 261 constant SilkMenuKey
  370.  
  371. 1001 constant FlipButton
  372. 1002 constant LeftButton
  373. 1005 constant RightButton
  374. 1006 constant RotButton
  375. 1004 constant UpButton
  376. 1003 constant DownButton
  377.  
  378. 50. 2constant timeout.
  379.  
  380.  
  381. variable match
  382. variable yp
  383. variable xp
  384.  
  385. variable ym
  386. variable xm
  387.  
  388. : q-move ( --- )
  389. match @ if
  390. ym @ 8 / yp @ 8 / 2dup > if
  391.   q-down 8 yp +!
  392. then < if
  393.  q-up -8 yp +! then 
  394. xm @ 8 / xp @ 8 / 2dup > if
  395.  q-right 8 xp +!
  396. then < if
  397.  q-left -8 xp +! then 
  398. q-paint-all
  399. then
  400. ;
  401.  
  402. : q-match ( y x --- )
  403.  xp @ swap dup 8 + within swap
  404.  yp @ swap dup 8 + within and if 1 match ! then
  405. ;
  406.  
  407. : q-find ( addr row --- )
  408. 5 0 do over over i  swap thisbit? 
  409.  if  
  410.  over  @ over 8 * + 2 pick 1 cells +  @ i 8 * + q-match 
  411. then
  412. loop
  413. 2drop
  414. ;
  415.  
  416. : q-select (  --- )
  417.  
  418. q-all
  419. 12 0 do dup i pentos + 
  420. 5 0 do dup i q-find
  421. loop drop
  422. match @ if act @ q-undraw i 1 + act ! 
  423. q-paint-all 
  424. leave
  425. then
  426. loop drop
  427. ;
  428.  
  429.  
  430. variable hard
  431.  
  432. : do-it  ( --- )
  433. case
  434. MenuEvent of
  435. event >abs itemid case
  436. AboutMenuItem of
  437.       AboutBox FrmAlert drop
  438.       endof
  439. HelpMenuItem of
  440.       HelpString FrmHelp
  441.       endof  
  442. RestartMenuItem of
  443.       q-all-f 1000 showform q-paint-all
  444.       endof
  445. DeslctMenuItem of 
  446.        act @ q-undraw
  447.       0 act ! 1000 showform 
  448.       q-paint-all
  449.       endof
  450. RefreshMenuItem of
  451.        1000 showform q-paint-all
  452.       endof
  453. endcase
  454. endof
  455. KeyDownEvent of
  456.  event >abs itemid 
  457.  case
  458.  CalendarKey of act @ if q-flp then q-paint-all 1 hard ! endof
  459.  AddressKey  of act @ if q-left then q-paint-all 1 hard ! endof
  460.  ToDoKey     of act @ if q-right then q-paint-all 1 hard ! endof
  461.  MemoKey     of act @ if q-rt then q-paint-all 1 hard ! endof
  462.  UpKey       of act @ if q-up q-paint-all then 1 hard !  endof  
  463.  DownKey     of act @ if q-down q-paint-all then 1 hard !  endof
  464.  SilkFindKey of 1 hard ! endof
  465. endcase 
  466.  
  467. endof
  468.  
  469. CtlSelectEvent of  
  470.  event >abs itemid
  471.  case
  472.  FlipButton   of act @ if q-flp q-paint-all then endof
  473.  LeftButton   of act @ if q-left q-paint-all then endof
  474.  RightButton  of act @ if q-right q-paint-all then endof
  475.  RotButton    of act @ if q-rt q-paint-all then endof
  476.  UpButton     of act @ if q-up q-paint-all then endof  
  477.  DownButton   of act @ if q-down q-paint-all then endof
  478.  endcase
  479.  
  480. endof
  481.  
  482. PenDownEvent of
  483. 0 match !
  484. coords@ xp ! yp ! q-select
  485. endof
  486.  
  487. PenMoveEvent of
  488. coords@ xm ! ym ! q-move
  489. endof
  490.  
  491.  
  492. endcase
  493. ;
  494. \ Main event handling
  495.  
  496.  
  497.  
  498. \ The next two words were taken
  499. \ from the Quartus discussion forum...
  500. (id) QES2 2constant crid
  501. : get-stored ( -- bool )
  502.   prefsize  prefs >abs  1 crid
  503.   PrefGetAppPreferencesV10 ;
  504.  
  505. : set-stored ( --- )
  506.   prefsize  prefs >abs  1 crid
  507.   PrefSetAppPreferencesV10 ;
  508.  
  509.  
  510. : q-init ( --- )
  511. get-stored 0 = if 
  512. 1 act !  0 tg ! 0 hard !
  513. Q-all-f
  514.  then
  515. 1000 showform
  516. q-paint-all
  517. ;
  518. \ Initialize things
  519.  
  520. : go ( --- )
  521. decimal
  522. q-init
  523. begin  
  524. begin timeout. event >abs EvtGetEvent event @ ?dup until 
  525.  do-it 
  526. hard @ 0= if
  527.  HandleEvent then
  528. 0 hard ! 
  529. again ;
  530. \ Main event loop
  531.  
  532. -257 constant byeThrow
  533.  
  534. : shand ( --- )
  535.   ['] go catch
  536.   \ If the application is exiting,
  537.   \  store settings:
  538.   dup byeThrow
  539.  = if 
  540. set-stored then
  541.   throw ;
  542. \ "Standard" exit handler
  543.  
  544. (id) QES2  (id) rsrc 
  545. use-resources
  546. \ ...also if you want to run it in the
  547. \ Quartus environment
  548.  
  549.  
  550. cr
  551. .s 
  552.