fl hex { PropForth5.5 Graphic command for Graphic LCD 2013/03/18 16:20:45 This is used by each Graphic LCD using HUB-ram as v-ram. } \ charcter position wvariable vidX wvariable vidY wvariable column wvariable row wvariable fontType wvariable row_line wvariable odd \ Set LCD screen-value for 8X8font : 8X8Font pixel_X 8 u/ column W! pixel_Y 8 u/ row W! 1 fontType W! ; \ Set LCD screen-value for prop_font : propFont pixel_X d16 u/ column W! pixel_Y d32 u/ row W! 0 fontType W! ; \ Display character(8X8dots) to graphicLCD ( n1 n2 n3 -- ) \ n1:character n2:x-pos n3:y-pos : grlcd_char column W@ 8 u* u* + vidMem + \ Get vidMem's address for (x,y) swap h20 - 8 u* Font + \ Get Font-address \ Copy character to vidMem 8 0 do 2dup C@ swap i column W@ u* + C! 1+ \ Font-address + 1 loop 2drop ; \ Calculate column and row \ ( -- ) : calc_XY vidX W@ 1+ dup column W@ = \ Check if vixX = column if drop 0 vidX W! \ next line vidY W@ 1+ dup row W@ = \ Check if vixY = row if drop 0 vidY W! \ first line else vidY W! then else vidX W! then ; \ Display character(16X32dots) to graphicLCD ( n1 n2 n3 -- ) \ n1:character n2:x-pos n3:y-pos : grlcd_char_prop pixel_X 8 u/ d32 u* u* \ y * (column/16) * d32(ROM-font:16X32) vidMem + swap 2 u* + \ X * 2 swap \ (vidMem-addr character --) h40 u* h8000 + \ Get ROM-address dup h40 and 0= \ Check if character is even or odd if 1 else 2 then odd W! \ 1:Even 2:Odd \ (vidMem-addr ROM-addr -- ) odd W@ 2 = if h40 - then \ Subtract 1 from address when odd d32 0 do dup L@ odd W@ d16 0 do \ Get 1-row (16bits) 2dup and if 1 else 0 then row_line W@ 1 lshift or row_line W! \ (vidMem-addr ROM-font odd_mask_data -- ) { \ ---- Display ROM-Font to terminal 2dup and if h2A else bl then emit \ ------------------------------------ } 2 lshift loop 2drop \ (vidMem-addr ROM-font -- ) \ ------------------------------------ \ cr \ ------------------------------------ swap dup column W@ 2 u* i u* \ each row for ROM-font + \ Calculate address of vidMem row_line W@ dup 8 lshift swap hFF00 and 8 rshift or swap W! \ Save 16bit-data to vidMem swap 4 + \ Add 4 to Font-addres loop 2drop ; \ display string to graphicLCD ( cstr -- ) \ Set charcter-type by 8X8Font/propFont before call : grlcd_str C@++ dup if bounds do i C@ vidX W@ vidY W@ fontType W@ 1 = if grlcd_char else grlcd_char_prop then \ Update (vidX,vidY) calc_XY loop else 2drop then ; \ Clear vidMem \ ( n1 n2 -- ) n1:start address n2:number of word (2byte) : clear_vram 0 do dup 0 swap W! 2+ loop drop ; \ vidMem ---------------------------------------- \ pixel_Y - 1 |(0,pixel_Y-1) (pixel_X-1, pixel_Y-1)| \ | | | pixel_X/8[bytes] X pixel_Y[Lines] \ | | (x,y) | \ | | | \ | |(0,0) (pixel_X-1, 0)| \ 0 ---------------------------------------- \ \ y 0 ---------------------------------- pixel_X - 1 \ x \ Calculate GraphicMemory address from (x,y) \ ( n1 n2 -- n3 ) n1:x n2:y n3:address : GetAddr vidMem swap pixel_Y 1- swap - pixel_X 8 u/ u* + \ vertical direction swap 8 u/ \ horizontal direction + \ Get address ; \ Set/Clear dot at (x,y) \ ( n1 n2 n3 -- ) n1:1=putPixel 0=clearPixel n2:x n3:y : setPixel over >r \ Push x GetAddr dup >r \ Get address and push C@ \ Get byte r> r> swap >r \ pop x 8 u/mod drop h80 swap rshift \ Get bit data rot if or \ Set bit to 1 else hFF xor and \ Set bit to 0 then r> C! \ Save byte ; \ copy top 3 items on the stack \ ( n1 n2 n3 -- n1 n2 n3 n1 n2 n3 ) : 3dup dup >r over >r rot dup >r rot2 r> r> r> ; { wvariable difx wvariable dify variable dx variable dy variable sx variable sy wvariable ds \ Draw straight line from (x0,y0) to (x1,y1) \ It takes 131msec from (0,0) to (239,63) \ ( n1 n2 n3 n4 n5 -- ) n1:1=putPixel 0=clearPixel n2:y0 n3:y1 n4:x0 n5:x1 : DrawLine \ X 2dup over >r \ Push x0 < if 1 else -1 then dx L! \ 1 or -1 for X-direction - abs dup 1 rshift sy L! \ error in Y-direction difx W! \ pixels in X-direction \ Y 2dup over >r \ Push y0 < if 1 else -1 then dy L! \ 1 or -1 for Y-direction - abs dup 1 rshift sx L! \ error in X-direction dify W! \ pixels in Y-direction difx W@ dify W@ min ds W! r> r> swap 3dup \ ( 1/0 x0 y0 1/0 x0 y0 -- ) difx W@ dify W@ max 1+ 0 do setPixel \ Plot current position \ X sx L@ ds W@ - dup sx L! 0 <= \ Check sx if sx L@ dify W@ + sx L! \ Increment sx by dify swap dx L@ + swap \ Move X in X-direction then \ Y sy L@ ds W@ - dup sy L! 0 <= \ Check sy if sy L@ difx W@ + sy L! \ Increment sy by difx dy L@ + \ Move Y in Y-direction then 3dup loop 3drop 3drop ; } wvariable X0 wvariable X1 wvariable Y0 wvariable Y1 wvariable steep wvariable deltax wvariable deltay variable error variable ystep \ Draw straight line from (x0,y0) to (x1,y1) \ It takes 133msec from (0,0) to (239,63) \ ( n1 n2 n3 n4 n5 -- ) n1:1=putPixel 0=clearPixel n2:y0 n3:y1 n4:x0 n5:x1 : DrawLine 2dup X1 W! X0 W! - >r \ Push difference (X0 - X1) 2dup Y1 W! Y0 W! - \ difference (Y0 - Y1) abs r> abs > \ Compare abs(Y1 - Y0) and abs(X1 - X0) if 1 else 0 then steep W! steep W@ 1 = if \ Swap X and Y X0 W@ Y0 W@ X0 W! Y0 W! X1 W@ Y1 W@ X1 W! Y1 W! then X0 W@ X1 W@ > if \ Swap X0 and X1 X0 W@ X1 W@ X0 W! X1 W! Y0 W@ Y1 W@ Y0 W! Y1 W! then X1 W@ X0 W@ - deltax W! Y1 W@ Y0 W@ - abs deltay W! deltax W@ 1 rshift error L! Y0 W@ Y1 W@ < if 1 else -1 then ystep L! X0 W@ Y0 W@ \ ( 1/0 X Y -- ) begin 3dup steep W@ 1 = if swap then setPixel \ Plot pixel error L@ deltay W@ - error L! error L@ 0< if ystep L@ + \ Y = Y + ystep error L@ deltax W@ + error L! \ error = error + deltax then swap 1+ dup X1 W@ = if 1 else swap 0 then until 3drop ; wvariable tmp 6 allot \ Draw box between (x0,y0) and (x1,y1) \ It takes 131msec between (0,0) ando (239,63) \ ( n1 n2 n3 n4 n5 -- ) n1:1=putPixel 0=clearPixel n2:y0 n3:y1 n4:x0 n5:x1 : Box tmp W! tmp 2+ W! tmp 4+ W! tmp 6 + W! dup tmp 6 + W@ tmp 6 + W@ tmp 2+ W@ tmp W@ DrawLine dup tmp 6 + W@ tmp 4+ W@ tmp W@ tmp W@ DrawLine dup tmp 4+ W@ tmp 4+ W@ tmp W@ tmp 2+ W@ DrawLine tmp 4+ W@ tmp 6 + W@ tmp 2+ W@ tmp 2+ W@ DrawLine ; variable f variable ddF_x variable ddF_y wvariable x wvariable y wvariable R \ Draw hisigata e with center on (x0,y0) radius=R \ ( n1 n2 n3 n4 -- ) n1:1=putPixel 0=clearPixel n2:x0 n3:y0 n4;radius : hisi dup dup dup 1 swap - f L! 0 ddF_x L! -2 * ddF_y L! 0 x W! y W! R W! 3dup R W@ + setPixel 3dup R W@ - setPixel 3dup swap R W@ + swap setPixel 3dup swap R W@ - swap setPixel begin f L@ 0 >= if y W@ 1- y W! ddF_y L@ 2+ ddF_y L! f L@ ddF_y L@ + f L! then x W@ 1+ x W! f L@ ddF_x 1+ + f L! 3dup swap x W@ + swap y W@ + setPixel 3dup swap x W@ - swap y W@ + setPixel 3dup swap x W@ + swap y W@ - setPixel 3dup swap x W@ - swap y W@ - setPixel 3dup swap y W@ + swap x W@ + setPixel 3dup swap y W@ - swap x W@ + setPixel 3dup swap y W@ + swap x W@ - setPixel 3dup swap y W@ - swap x W@ - setPixel x W@ y W@ < if 0 else 1 then until 3drop ; variable xx variable yy wvariable X wvariable Y \ Draw circle with center on (x0,y0) radius=R \ ( n1 n2 n3 n4 -- ) n1:1=putPixel 0=clearPixel n2:x0 n3:y0 n4;radius : circle d128 u* xx L! 0 yy L! 0 X W! 0 Y W! begin xx L@ 7 rshift X W! yy L@ 7 rshift Y W! 3dup swap X W@ + swap Y W@ + setPixel 3dup swap X W@ - swap Y W@ - setPixel 3dup swap X W@ - swap Y W@ + setPixel 3dup swap X W@ + swap Y W@ - setPixel 3dup swap Y W@ + swap X W@ + setPixel 3dup swap Y W@ - swap X W@ - setPixel 3dup swap Y W@ - swap X W@ + setPixel 3dup swap Y W@ + swap X W@ - setPixel yy L@ xx L@ 7 rshift + yy L! xx L@ yy L@ 7 rshift - xx L! yy L@ xx L@ >= if 1 else 0 then until 3drop ; \ ----------------------------------------------------------------------------- \ DEMO \ ----------------------------------------------------------------------------- \ ***** Display 8X8 Font ***** : demo1 BASE DISP_OFF + pinout \ Disable graphicLCD BASE Vee + pinout \ Disable Vee c" vidMem BASE GraphicLCD" 0 cogx \ Drive graphicLCD vidMem pixel_X pixel_Y u* d16 u/ clear_vram BASE Vee + pinhi \ Enable Vee 1 delms BASE DISP_OFF + pinhi \ Enable graphicLCD 8X8Font \ Select 8X8font 0 vidX W! 0 vidY W! h20 \ start character ." Hit any key, when finished" cr begin d96 0 do dup i + \ Get Font character vidX W@ vidY W@ grlcd_char \ Print character calc_XY \ Update (x,y) d50 delms loop fkey? swap drop until drop BASE DISP_OFF + pinlo \ Enable graphicLCD \ LCD-off BASE Vee + pinlo \ Disable Vee 0 cogreset ; \ ***** Display ROM-Font(16X32dots) ***** : demo2 BASE DISP_OFF + pinout \ Disable graphicLCD BASE Vee + pinout \ Disable Vee c" vidMem BASE GraphicLCD" 0 cogx \ Drive graphicLCD vidMem pixel_X pixel_Y u* d16 u/ clear_vram BASE Vee + pinhi \ Enable Vee 1 delms BASE DISP_OFF + pinhi \ Enable graphicLCD propFont \ Select ROM-font 0 vidX W! 0 vidY W! ." Hit any key, when finished" cr 0 \ start character begin d256 0 do dup i + \ Get Font character vidX W@ vidY W@ grlcd_char_prop \ Print character calc_XY \ Update (x,y) d50 delms loop fkey? swap drop until drop \ LCD-off BASE DISP_OFF + pinlo \ Disable graphicLCD BASE Vee + pinlo \ Disable -9V 0 cogreset ; : demo3 BASE DISP_OFF + pinout \ Disable graphicLCD BASE Vee + pinout \ Disable Vee c" vidMem BASE GraphicLCD" 0 cogx \ Drive graphicLCD vidMem pixel_X pixel_Y u* d16 u/ clear_vram BASE Vee + pinhi \ Enable Vee 1 delms BASE DISP_OFF + pinhi \ Enable graphicLCD 8X8Font \ Select 8X8font 0 vidX W! 0 vidY W! c" WD-G2406B" grlcd_str 0 vidX W! 1 vidY W! c" May the Forth be with you." grlcd_str d2000 delms vidMem d240 clear_vram propFont 0 vidX W! 0 vidY W! c" May the Forth be with you." grlcd_str d2000 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram \ Line pixel_Y 5 u/ 1+ 0 do 1 0 i 5 u* 0 pixel_X 1- DrawLine loop pixel_X 5 u/ 0 do 1 0 pixel_Y 1- 0 pixel_X 1- i 5 u* - DrawLine loop d500 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram pixel_Y 5 u/ 1+ 0 do 1 0 i 5 u* pixel_X 1- 0 DrawLine loop pixel_X 5 u/ 0 do 1 0 pixel_Y 1- pixel_X 1- i 5 u* DrawLine loop d500 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram pixel_Y 5 u/ 1+ 0 do 1 pixel_Y 1- pixel_Y 1- i 5 u* - 0 pixel_X DrawLine loop pixel_X 5 u/ 0 do 1 pixel_Y 1- 0 0 pixel_X 1- i 5 u* - DrawLine loop d500 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram pixel_Y 5 u/ 1+ 0 do 1 pixel_Y 1- pixel_Y 1- i 5 u* - pixel_X 0 DrawLine loop pixel_X 5 u/ 0 do 1 pixel_Y 1- 0 pixel_X 1- i 5 u* DrawLine loop d1000 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram \ Box 1 0 8 0 d30 Box 9 2 do 1 0 i d8 u* 1- 0 i d30 u* 1- Box d100 delms loop d500 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram 5 0 do 1 i 5 u* pixel_Y 1- i 5 u* - i 20 u* pixel_X 1- i 20 u* - Box loop d500 delms 5 0 do 0 i 5 u* pixel_Y 1- i 5 u* - i 20 u* pixel_X 1- i 20 u* - Box loop d1000 delms vidMem pixel_X pixel_Y u* d16 u/ clear_vram \ Circle 7 1 do 1 d50 d30 i 5 u* circle loop \ LCD-off BASE DISP_OFF + pinlo \ Disable graphicLCD \ BASE Vee + pinlo \ Disable Vee 0 cogreset ; decimal