fl { PropForth 5.5 Simple Game P0-P7 --- CharliePlexing 8x8DotMatrix P8 ------ buzzar P9 ------ SW 3.3V ---- 3.3V GND ----- GND 2015/01/31 17:21:54 } \ =========================================================================== \ Constants \ =========================================================================== \ ----- on-data for 8x8Matrix-dot ----- \ ----- upperbyte:index of matrix-array \ ----- lowerbyte:bit-data wvariable dot -2 allot h0001 w, h0002 w, h0004 w, h0008 w, h0010 w, h0020 w, h0040 w, h0080 w, h0180 w, h0280 w, h0380 w, h0480 w, h0580 w, h0680 w, h0780 w, h0740 w, h0720 w, h0710 w, h0708 w, h0704 w, h0702 w, h0701 w, h0601 w, h0501 w, h0403 w, h0301 w, h0201 w, h0101 w, h1F8 wconstant ctra \ h1F9 wconstant ctrb h1FA wconstant frqa { h1FB wconstant frqb h1FC wconstant phsa h1FD wconstant phsb } 8 wconstant buzzar 9 wconstant sw sw >m constant swm d1600000 constant 20msec dot d56 + wconstant dotend d800000 constant 10msec \ =========================================================================== \ Variables \ =========================================================================== \ Buffer for 8x8 LED-Matrix variable matrix 4 allot wvariable sw_value wvariable snd_value wvariable n \ =========================================================================== \ Main \ =========================================================================== \ Drive 8x8-LED-Matrix curcuit for Charlieplexing by assembler-word \ It takes about 16msec displaying 8-lines. \ ( n1 -- ) n1:address of 8x8-Matrix buffer lockdict create _matrix_Charlie_asm forthentry $C_a_lxasm w, h12E h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyPW8 l, z2WiPfg l, z2WiPmB l, z2Wyxj0 l, z2WyxW0 l, z1Sy\Ka l, z2WixZD l, z2Wyxmy l, z2WiPve l, z20iPyk l, z3ryPr0 l, ziPuE l, z2[iQ3F l, z24yQ01 l, z2WixZG l, z1Sy\Ka l, zfyPb1 l, z20yPj1 l, z3[yP[M l, z1SV04J l, z2WiPvf l, z20iPyk l, z3ryPr0 l, z1SV000 l, z38 l, zJY0 l, z1 l, freedict \ Clear matrix buffer \ ( -- ) : clr_matrix 0 matrix L! 0 matrix 4+ L! ; \ Seperate index and erase-bit-data \ ( n1 -- n2 n3 ) n1:word n2:erase-bit-data n3:index : seperate dup \ ( n1 n1 ) hFF and swap \ ( n2 n1 ) 8 rshift \ ( n2 n3 ) ; \ Check switch-status \ ( -- ) : sw begin \ Check if buttom is pushed(P9 is 0 when sw is pushed) swm ina COG@ and 0= if \ Wait 10msec d10 delms swm ina and if 0 else 1 then if \ Set flag when bottun pushed 1 sw_value W! \ Wait until buttom is release begin swm ina COG@ and if \ Wait 10msec d10 delms swm ina COG@ and if 1 else 0 then else 0 then until then then 0 until ; \ Clear sw flag \ ( -- ) : clr_sw 0 sw_value W! ; \ Buzzar \ ( n1 n2 -- ) n1:time n2:FRQA value : tone \ Set NCO/PWM single-ended mode h10000000 buzzar or ctra COG! frqa COG! delms 0 frqa COG! ; \ Game"rouretto" \ Only pushing bottun (When pushing bottun, one dot is off) \ Time erasing all dots is score. \ ( -- ) : roulette \ initialization clr_sw buzzar pinout clr_matrix c" matrix _matrix_Charlie_asm" 0 cogx c" sw" 1 cogx d40 n W! 2 matrix 4 + C! dot begin dup 2 d107374 tone \ f=2000Hz duration=2msec W@ seperate 2dup matrix + C! \ Dot on \ Wait cnt COG@ 20msec + \ Check if sw is pushed sw_value W@ if n W@ d20 > if 10msec + n W@ 1- n W! else 10msec 5 u* + n W@ 1- n W! then then 0 waitcnt drop n W@ 0 = if 2drop d500 delms \ Check if ok matrix 4+ W@ 1 and if h80844020 matrix L! h20408480 matrix 4+ L! \ smile face else h404A040A matrix L! h0A404A40 matrix 4+ L! \ sad face then clr_sw begin sw_value W@ until clr_sw d40 n W! clr_matrix else 2 matrix 4 + C! swap drop 0 swap matrix + C! \ Dot off 2+ \ Check if dot is end dup dotend = if drop dot then then fkey? swap drop until drop 0 cogreset 1 cogreset 2 cogreset ;