BBC BASIC
« A new type of text tool (array ASCII) Mod Jan 7 »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:12pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: A new type of text tool (array ASCII) Mod Jan 7  (Read 64 times)
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx A new type of text tool (array ASCII) Mod Jan 7
« Thread started on: Dec 31st, 2017, 07:16am »

NOTE: This has been modified. I have implemented the recommended changes.

This works nicely and the method Richard offered is very interesting. I looked closely at the documentation on Indirection. Very interesting.


ahh, yes... another text tool. This is for 1 line, but with another dimension, a person could create a functional text editor on any platform.
Code:
      VDU 23,22,1000;500;8,15,16,1
      VDU 5:OFF
      PROCcolor("b","200,200,200"):CLG:REM light grey background
      REM allow user to type a message at 100,100 on the graphics screen
      s$=FNtype(100,100):VDU 7:REM BEEP!!!! he he he
      REM if you type hello then it will respond because it returns only hello
      IF s$="hello" THEN MOVE 300,300:PRINT "you said hello"
      MOVE 200,200:PRINT s$
      END
      REM It appears that this will work for future text graphics based applications
      DEF FNtype(x%,y%)
      REM first define a efficient array a&() and retstr$- case of empty returned string
      LOCAL a&(),retstr$,h%,v%,t&,k$,cp&,l%,bc$,fc$
      h%=x%:v%=y%
      fc$="000,000,000":bc$="200,200,200":REM text color is black
      REM l%,cp% line # and cursor position.l%- future(not used yet)
      REM bc$-(text overwrite-background) fc$-foreground text colors-
      REM now give a&() a dimension of 100
      DIM a&(100)
      REPEAT
        h%=x%
        REPEAT
          k$=INKEY$(4)
          REM Cursor
          PROCcolor("f",fc$):MOVE cp&*16+h%,v%:PRINT"_"
          WAIT 10:REM seems pretty smooth
          PROCcolor("f",bc$):MOVE cp&*16+h%,v%:PRINT"_"
        UNTIL k$<>""
        IF k$<>"" THEN
          IF ASC(k$)>31 AND ASC(k$)<127 AND cp&<100 THEN
            a&(cp&)=ASC(k$):cp&=cp&+1
          ENDIF
          h%=x%:v%=y%:REM test
          MOVE h%,v%:PROCcolor("f",bc$)
          REM print every ascii value in a&() array except 0 -cool stuff
          PRINT $$^a&(0)
          t&=0
          h%=x%:v%=y%:REM test
          MOVE h%,v%:PROCcolor("f",fc$)
          PRINT $$^a&(0)
          t&=0
        ENDIF
        IF ASC(k$)=8 AND cp&>0 THEN
          t&=0
          h%=x%:v%=y%:REM test
          MOVE h%,v%:PROCcolor("f",bc$)
          PRINT $$^a&(0)
          t&=0
          t&=cp&-1
          REPEAT
            a&(t&)=a&(t&+1)
            t&+=1
          UNTIL t&=100
          t&=0
          h%=x%:v%=y%:REM test
          MOVE h%,v%:PROCcolor("f",fc$)
          PRINT $$^a&(0)
          t&=0
          cp&-=1
        ENDIF
      UNTIL ASC(k$)=13
      REM assemble string for final return string using cool method
      retstr$ = $$^a&(0)
      t&=0:PROCresetrgb:REM make sure colors are reset to normal
      =retstr$
      REM restore default color palettes
      DEFPROCresetrgb
      COLOUR 0,0,0,0 :COLOUR 1,200,0,0 :COLOUR 2,000,200,000
      COLOUR 3,200,200,000:COLOUR 4,000,000,200:COLOUR 5,200,000,200
      COLOUR 6,000,200,200:COLOUR 7,200,200,200:COLOUR 8,056,056,056
      COLOUR 9,248,056,056:COLOUR 10,056,248,056:COLOUR 11,248,248,056
      COLOUR 12,056,056,248:COLOUR 13,248,056,248:COLOUR 14,056,248,248
      COLOUR 15,248,248,248
      ENDPROC
      REM I just love controlling color with this
      DEF PROCcolor(fb$,rgb$)
      PRIVATE assemble$,br%,bg%,bb%
      IF rgb$="0" OR rgb$="black" THEN rgb$="000,000,000"
      IF rgb$="1" OR rgb$="red" THEN rgb$="200,000,000"
      IF rgb$="2" OR rgb$="green" THEN rgb$="000,200,000"
      IF rgb$="3" OR rgb$="yellow" THEN rgb$="200,200,000"
      IF rgb$="4" OR rgb$="blue" THEN rgb$="000,000,200"
      IF rgb$="5" OR rgb$="magenta" THEN rgb$="200,000,200"
      IF rgb$="6" OR rgb$="cyan" THEN rgb$="000,200,200"
      IF rgb$="7" OR rgb$="white" THEN rgb$="200,200,200"
      IF rgb$="8" OR rgb$="grey" THEN rgb$="056,056,056"
      IF rgb$="9" OR rgb$="light red" THEN rgb$="248,056,056"
      IF rgb$="10" OR rgb$="light green" THEN rgb$="056,248,056"
      IF rgb$="11" OR rgb$="light yellow" THEN rgb$="248,248,056"
      IF rgb$="12" OR rgb$="light blue" THEN rgb$="056,056,248"
      IF rgb$="13" OR rgb$="light magenta" THEN rgb$="248,056,248"
      IF rgb$="14" OR rgb$="light cyan" THEN rgb$="056,248,248"
      IF rgb$="15" OR rgb$="light white" THEN rgb$="248,248,248"
      assemble$=rgb$
      br%=VAL(MID$(assemble$,1,3)):bg%=VAL(MID$(assemble$,5,3)):bb%=VAL(MID$(assemble$,9,3))
      IF fb$="f" OR fb$="F" THEN COLOUR 0,br%,bg%,bb% : GCOL 0
      IF fb$="b" OR fb$="B" THEN COLOUR 1,br%,bg%,bb% : GCOL 128+1
      ENDPROC
 

« Last Edit: Jan 8th, 2018, 05:07am by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: A new type of text tool (array ASCII) v2
« Reply #1 on: Dec 31st, 2017, 9:44pm »

on Dec 31st, 2017, 07:16am, michael wrote:
yes... another text tool.

I'm confused by this code, which appears twice in your program:

Code:
      REPEAT
        IF a&(t&)>0 THEN PRINT CHR$(a&(t&)): t&+=1:h%+=16:MOVE h%,v%
      UNTIL a&(t&)=0 

Can't it be replaced, in both places, with the much shorter and faster:

Code:
      PRINT $$^a&(0) 

Or am I missing something?

Similarly, can't this:

Code:
      REPEAT
        IF a&(t&)>0 THEN retstr$+= CHR$(a&(t&)):t&+=1:h%+=16:MOVE h%,v%
      UNTIL a&(t&)=0 

be replaced by this:

Code:
      retstr$ = $$^a&(0) 

Richard.
« Last Edit: Dec 31st, 2017, 9:48pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls