@@ -410,7 +410,7 @@ PUB drawChar(char) | xs, ys
410410
411411PUB drawStr(str)
412412 repeat while byte[str] <> 0
413- DrawChar (byte[str++])
413+ drawChar (byte[str++])
414414
415415PUB drawString(col,row,str)
416416' Draw a 0 terminated string at col,row
@@ -432,18 +432,38 @@ PUB drawPixel(x, y, rgb) | i
432432 setWindow(x, y, x, y) ' 1 pixel
433433 fillWindow(rgb)
434434
435+ PUB drawFastHLine(x,y,l,rgb)
436+ setWindow(x,y,x+l,y)
437+ fillWindow(rgb)
438+
439+ PUB drawFastVLine(x,y,l,rgb)
440+ setWindow(x,y,x,y+l)
441+ fillWindow(rgb)
442+
435443PUB drawLine(xs, ys, xe, ye, rgb) | i, x, y, dx, dy
436444' Draw Line - start co-ords, end co-ords, color
437445 dx:= xe - xs
438446 dy:= ye - ys
439- if ABS(dx) > ABS(dy) 'plot incrementing x axis
440- repeat i from 0 to dx
441- y := (dy*i + dx/2)/dx
442- drawPixel(xs+i, ys+y, rgb)
443- else 'plot incrementing y axis
444- repeat i from 0 to dy
445- x := (dx*i + dy/2)/dy
446- drawPixel(xs+x, ys+i, rgb)
447+
448+ if dx == 0
449+ if ys < ye
450+ drawFastVLine(xs,ys,dy,rgb)
451+ else
452+ drawFastVLine(xs,ye,ABS(dy),rgb)
453+ elseif dy == 0
454+ if xs < xe
455+ drawFastHLine(xs,ys,dx,rgb)
456+ else
457+ drawFastHLine(xe,ys,ABS(dx),rgb)
458+ else
459+ if ABS(dx) > ABS(dy) 'plot incrementing x axis
460+ repeat i from 0 to dx
461+ y := (dy*i + dx/2)/dx
462+ drawPixel(xs+i, ys+y, rgb)
463+ else 'plot incrementing y axis
464+ repeat i from 0 to dy
465+ x := (dx*i + dy/2)/dy
466+ drawPixel(xs+x, ys+i, rgb)
447467
448468PUB drawCircle(xc, yc, r, rgb) | x, y
449469' Draw Circle d^2 = x^2 + y^2; y = SQRT(d^2 - x^2) (Pythagoras theorum)
@@ -462,38 +482,17 @@ PUB drawCircle(xc, yc, r, rgb) | x, y
462482 drawPixel(xc+y, yc-x, rgb)
463483 drawPixel(xc-y, yc-x, rgb)
464484
465- {
466- PUB fillCircle(xc, yc, r, rgb)|x,y,xr,yr,d,a
467- ' Draws a filled circle using ROTXY
468- d := $80000000 / 180 'degrees unit in 32 bits
469- x := 0
470- y := r
471- a := 0
472-
473- repeat a from 0 to 45 step 2
474- xr,yr := ROTXY(x,y,a*d)
475-
476- 'Window requires start column < end column and start row < end row
477- setWindow(xc-yr,yc-xr,xc+yr,yc+xr)
478- fillWindow(rgb)
479-
480- 'Window requires start column < end column and start row < end row
481- setWindow(xc-xr,yc-yr,xc+xr,yc+yr)
482- fillWindow(rgb)
483- }
484-
485485PUB fillCircle(xc, yc, r, rgb)|x,y,xr,yr,d
486- 'Faster than above approach
487486'The most efficient algorithm for creating a filled circle is
488487'the Midpoint Circle Algorithm, also known as Bresenham's Circle Algorithm.
489488 x := 0
490489 y := r
491490 d := 1 - r
492491 repeat while x <= y
493- drawLine (xc-x, yc+y, xc+x, yc+y , rgb) 'last
494- drawLine (xc-x, yc-y, xc+x, yc-y , rgb) 'top
495- drawLine (xc-y, yc+x, xc+y, yc+x , rgb) 'third
496- drawLine (xc-y, yc-x, xc+y, yc-x , rgb) 'second
492+ drawFastHLine (xc-x, yc+y, 2*x , rgb) 'last
493+ drawFastHLine (xc-x, yc-y, 2*x , rgb) 'top
494+ drawFastHLine (xc-y, yc+x, 2*y , rgb) 'third
495+ drawFastHLine (xc-y, yc-x, 2*y , rgb) 'second
497496
498497 x++
499498 if d < 0
@@ -583,8 +582,8 @@ PUB buttonIsHit (x, y): n
583582PUB waitForButton (): n
584583' wait uintil a button is hit and returns its number
585584 repeat
586- wait_for_touch ()
587- wait_for_untouch ()
585+ Wait_for_touch ()
586+ Wait_for_untouch ()
588587 n:= buttonIsHit (Get_TS_XY ())
589588 until n > 0
590589
@@ -598,23 +597,23 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
598597
599598 clearScreen()
600599 clearButtons()
601- drawstring (xstr, ystr, string("CALIBRATE TOP LEFT"))
602- SetColRow (cal_topx, cal_topy)
603- DrawChar ("x") ' draw top left calibration X
600+ drawString (xstr, ystr, string("CALIBRATE TOP LEFT"))
601+ setColRow (cal_topx, cal_topy)
602+ drawChar ("x") ' draw top left calibration X
604603 int := 1
605604
606605 Wait_for_touch() ' wait for touch
607606 tx_topx,ty_topy:= Get_TS_XY_raw() ' calibration point top left
608607
609608' term.fstr3(string("X %d Y %d int %d %s\r\n"),tx_topx,ty_topy,int)
610- clearscreen ()
611- drawstring (xstr, ystr, string("CALIBRATE BOTTOM RIGHT"))
612- SetColRow (cal_botx, cal_boty)
609+ clearScreen ()
610+ drawString (xstr, ystr, string("CALIBRATE BOTTOM RIGHT"))
611+ setColRow (cal_botx, cal_boty)
613612
614- DrawChar ("x") ' draw bottom right calibration X
613+ drawChar ("x") ' draw bottom right calibration X
615614
616- wait_for_untouch () ' wait until not touched
617- wait_for_touch () ' wait until touched
615+ Wait_for_untouch () ' wait until not touched
616+ Wait_for_touch () ' wait until touched
618617
619618 tx_botx,ty_boty:= Get_TS_XY_raw() ' calibration point bottom right
620619' term.fstr3(string("X %d Y %d int %d %s\r\n"),tx_botx,ty_boty,spotx)
@@ -628,9 +627,9 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
628627
629628 calibrated:= true
630629
631- clearscreen ()
632- wait_for_untouch ()
633- drawstring (xstr, ystr, string("TOUCH DISPLAY TO MAKE X"))
630+ clearScreen ()
631+ Wait_for_untouch ()
632+ drawString (xstr, ystr, string("TOUCH DISPLAY TO MAKE X"))
634633 spotx:= cal_botx-(cal_edge/2)
635634 spoty:= cal_edge/2
636635 setWindow(spotx, spoty, spotx+cal_edge, spoty+cal_edge)
@@ -639,22 +638,22 @@ PUB calibrateTouch() | xstr, ystr, tx,ty,tx_topx,ty_topy,tx_botx,ty_boty,spotx,s
639638
640639 setBGcolor(white)
641640 setFGcolor(black)
642- drawstring (spotx, cal_edge, string("DONE"))
641+ drawString (spotx, cal_edge, string("DONE"))
643642 setFGcolor(green)
644643 setBGcolor(black)
645644
646645 repeat
647- wait_for_untouch () ' wait until not touched
648- wait_for_touch () ' wait until touched
646+ Wait_for_untouch () ' wait until not touched
647+ Wait_for_touch () ' wait until touched
649648
650649 spotx,spoty:= Get_TS_XY()
651650
652651 if buttonIsHit (spotx, spoty)
653652 quit ' cal_done
654- SetColRow (spotx,spoty)
655- DrawChar ("x")
653+ setColRow (spotx,spoty)
654+ drawChar ("x")
656655 clearButtons()
657- clearscreen ()
656+ clearScreen ()
658657
659658' term.fstr3(string("X %d Y %d int %d %s\r\n"),spotx,spoty,spotx)
660659'----------------------------------------------------------
724723PUB detects_valid_touch(): valid_touch_detected | pos_x, pos_y
725724 valid_touch_detected := false
726725 if Touched() AND (getms()-last_time >= DEBOUNCE_TIMER)
727- pos_x, pos_y := GET_TS_XY ()
726+ pos_x, pos_y := Get_TS_XY ()
728727 if (pos_x > 0 AND pos_x <= cal_offx) AND (pos_y > 0 AND pos_y <= cal_offy)
729728 valid_touch_detected := true
730729 last_x := pos_x
@@ -804,7 +803,7 @@ entry ' PTRA contains the poin
804803 fltl PIN_SDA '|
805804 drvh PIN_CLK '|
806805 drvh PIN_LED '/
807- wrpin modeLClk ,PIN_CLK ' smart pin transition mode
806+ wrpin modeLCLK ,PIN_CLK ' smart pin transition mode
808807 wrpin modeLTXD,PIN_SDA ' smart pin synchronous serial transmit
809808 wxpin divCLK,PIN_CLK ' clock transition every 50ns
810809 wypin #2,PIN_CLK ' dummy pulse to force IN=1 (ready flag)
@@ -1100,7 +1099,7 @@ selectLCD
11001099 if_nz jmp #.waitRdy ' wait until last CLK sequence finished
11011100 fltl PIN_SDA
11021101 drvc PIN_DC ' cmd=0 / data=1
1103- wrpin modeLClk ,PIN_CLK ' smart pin transition mode
1102+ wrpin modeLCLK ,PIN_CLK ' smart pin transition mode
11041103 wrpin modeLTXD,PIN_SDA ' smart pin synchronous serial transmit
11051104 wxpin divCLK,PIN_CLK ' clock transition every 50ns
11061105 _ret_ drvl PIN_CE ' CS=0
@@ -1136,14 +1135,14 @@ write16data shl data, #16 ' prep word to write (ms
11361135''+-----------------------------------------------------+
11371136pollTouchXY
11381137 mov data,#$91
1139- call #get_ts_adc
1138+ call #Get_ts_adc
11401139 mov data,#$91
1141- call #get_ts_adc
1140+ call #Get_ts_adc
11421141 mov ts_xy,data
11431142 mov data,#$D1
1144- call #get_ts_adc
1143+ call #Get_ts_adc
11451144 mov data,#$D0
1146- call #get_ts_adc
1145+ call #Get_ts_adc
11471146 shl data,#16
11481147 or ts_xy,data
11491148 wrlong ts_xy,ptra[6]
0 commit comments