BBC BASIC for Windows
« A new type of text tool (array ASCII) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:59pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: A new type of text tool (array ASCII)  (Read 385 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx A new type of text tool (array ASCII)
« Thread started on: Dec 15th, 2017, 05:01am »

A promising new way of editing a text line on graphics screen.
Array storage of each character value (ascii)

Right now its only one line, but it seems to work well and I should be able to move the cursor between arrays easily.

(uses: cross platform interface and promising new text editing tools)



Code:
      VDU 23,22,1000;500;8,15,16,1
      VDU 5
      OFF
      LET h%=100:LET v%=100:k%=0:cov%=0:t%=0
      l%=0:cp%=0:REM line # and cursor position
      DIM a%(100)
      REPEAT
        h%=100
        REPEAT
          k$=INKEY$(4)
          GCOL 15
    
          MOVE cp%*16+h%,v%:PRINT"_"
          WAIT 15
          GCOL 0: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%=100:v%=100:REM test
          MOVE h%,v%:GCOL 0
    
          REPEAT
            IF a%(t%)>0 THEN PRINT CHR$(a%(t%)): t%+=1:h%+=16:MOVE h%,v%
          UNTIL a%(t%)=0
          t%=0
          h%=100:v%=100:REM test
          MOVE h%,v%:GCOL 15
          REPEAT
            IF a%(t%)>0 THEN PRINT CHR$(a%(t%)):t%+=1:h%+=16:MOVE h%,v%
          UNTIL a%(t%)=0
          t%=0
        ENDIF
        IF ASC(k$)=8 AND cp%>0 THEN
          t%=cp%-1
          REPEAT
            a%(t%)=a%(t%+1)
            t%+=1
          UNTIL t%=100
          t%=0
          CLG
          t%=0
          h%=100:v%=100:REM test
          MOVE h%,v%:GCOL 15
          REPEAT
            IF a%(t%)>0 THEN PRINT CHR$(a%(t%)):t%+=1:h%+=16:MOVE h%,v%
          UNTIL a%(t%)=0
          t%=0
          cp%-=1
        ENDIF
      UNTIL FALSE
      END

 
User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: A new type of text tool (array ASCII)
« Reply #1 on: Dec 16th, 2017, 4:10pm »

I was wondering how you would use that?

How do you propose to get the text that you typed in assuming that you typed it in with some purpose?

I find your continued use of LET amusing. Takes me back to the 1970's, LET the fun begin but don't GOTO far.

Update.
Here is some code that does the same thing Except the flashing cursor but returns the input.
Code:
      REM Write text characters to graphics screen.
      MODE 10
      h%=100
      v%=100
      Ret$= FNgstring(h%,v%)
      END


      DEF FNgstring(h%,v%)
      LOCAL K%, a$
      VDU5
      GCOL 4,0    REM Inverts color
      MOVE h%, v% : PRINT "_";
      REPEAT :                           REM Loop getting input until a CR
        K%=INKEY(10)
        REM Build up String
        IF K% >31 AND K% <128 OR K%=8 THEN
          MOVE h%, v% : PRINT a$; "_";                :REM Erase old string
          IF K%=8 THEN a$=LEFT$(a$) ELSE a$+=CHR$(K%) :REM Build new string
          MOVE h%, v% : PRINT a$; "_";                :REM Print new string.
        ENDIF
      UNTIL K%=13
      MOVE h%, v% : PRINT a$; "_";  :REM Cursor off.
      MOVE h%, v% : PRINT a$;
      VDU4
      =a$
 
« Last Edit: Dec 16th, 2017, 8:28pm by Zaphod » User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: A new type of text tool (array ASCII)
« Reply #2 on: Dec 17th, 2017, 05:01am »

Quote:
I was wondering how you would use that?

How do you propose to get the text that you typed in assuming that you typed it in with some purpose?


Well, using this method, a person could set up a whole page at a time and create a graphics editor. It would be simpler to edit each array, and it would be easy to navigate from one line to another, or within a line if you just add another dimension.

Getting the text back is simple. Just add all the ascii values together with chr$ and you can recreate the info.

This method also eliminates the need for commands like MID$, LEFT$, RIGHT$,INSTR$

With improvement it can become quite versatile.
User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: A new type of text tool (array ASCII)
« Reply #3 on: Dec 17th, 2017, 11:04pm »

You don't like the string handling functions so I'll apologize now for using them to show how you can get this text editing done. Of course there are hundreds of ways of coding this and to me this looks easier than your approach.

You can make an 'editor' for text in a graphics screen, with all the usual editing functions with very few string manipulations. Here is an example that extends the previous code to allow the text color to be specified and has that flashing cursor. It flashes faster when in overwrite mode.
Code:
         REM Write text characters to graphics screen.
      MODE 10
      h%=100
      v%=600
      f%=11         : REM Foreground color
      GCOL 12+128   : REM Optionaly set background color
      CLG
      Ret$= FNgstring(h%,v%,f%)  :REM put string in place

      END


      DEF FNgstring(h%,v%,f%)  : REM x, y coordinates, foreground logical color.
      LOCAL K%, a$, c$, cp%, ins%, t%, oldf%, b% :REM f% foreground b%, background colors
      VDU5
      oldf%=@vdu.g.b&           : REM May be BB4W specific
      b%=@vdu.g.d&
      GCOL f%                   : REM Types in color specified.
      cp%=1                     : REM Cursor position initially 1 'cos that is how strings posns are numbered.
      ins%=TRUE                 : REM Start with insert mode
      c$="_"
      t%=15                     :REM initial timing delay for cursor.
      REPEAT :                    REM Loop getting input until a CR
        GCOL b%: MOVE h%, v% :PRINT SPC(cp%-1);c$;  :REM Remove cursor while we wait for keystrokes
        K%=INKEY(t%)
        IF K%=-1
        REM Build up String
        IF K% > 31 OR K%=8 THEN
          GCOL b%: MOVE h%, v% : PRINT a$; :REM Erase old string things are about to change (maybe).
          CASE TRUE OF
            WHEN K% >31 AND K% <128
              CASE TRUE OF
                WHEN cp%=>LEN(a$): a$+=CHR$(K%)
                WHEN cp%< LEN(a$) AND ins%=TRUE : a$=LEFT$(a$,cp%-1)+CHR$(K%)+MID$(a$,cp%)
                WHEN cp%< LEN(a$) AND ins%=FALSE: MID$(a$,cp%)=CHR$(K%)
              ENDCASE
              cp%+=1
            WHEN K%=130: cp%=1      :REM Home
            WHEN K%=131: cp%=LEN(a$):REM End
            WHEN K%=132: REM PgUp
            WHEN K%=133: REM PgDn
            WHEN K%=134: REM Ins
              REM Change modes and change cursor flash time.
              ins%=NOT ins%
              IF ins% t%=15 ELSE t%=8
            WHEN K%=8 : REM BackSp
              IF cp%>0: a$=LEFT$(a$,cp%-1)+MID$(a$,cp%+1) : cp%-=1
            WHEN K%=135 : REM Del
              a$=LEFT$(a$,cp%)+MID$(a$,cp%+2)
            WHEN K%=136: REM Left
              IF cp%>1 cp%-=1
            WHEN K%=137: REM Right
              IF cp% < LEN(a$) cp%+=1
            WHEN K%=138, 139:REM Up or down
          ENDCASE
          REM  PRINT the new string.
          GCOL f% MOVE h%, v% : PRINT a$;
        ENDIF
        REPEAT UNTIL INKEY(0)=-1  : REM Mainly flushingexcessive repeat keys if you hold them down.
        GCOL f%: MOVE h%, v% :PRINT SPC(cp%-1);c$;  :REM Now write the cursor in the new position if needed.
        WAIT t%                                     :REM Do nothing for a while.
      UNTIL K%=13
      GCOL b%: MOVE h%, v% :PRINT SPC(cp%-1);c$;
      GCOL oldf%             :REM Change Mode back to original plot color.
      VDU4
      =a$

 


You will note that the code passes the Cross Reference utility without warnings. Has no assumptions about position or graphics colors within the function and leaves the graphics modes and colors in the same state as it found it. It probes the colors with built in BB4W variables that may not be applicable to the cross platform versions.

Well that was something to play with on a wet Sunday afternoon!

Z
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: A new type of text tool (array ASCII)
« Reply #4 on: Dec 18th, 2017, 01:01am »

Quote:
You don't like the string handling functions so I'll apologize now for using them to show how you can get this text editing done


Thanks for the contribution..
I don't mind using the string commands, I just want to explore more ways of doing this.

User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: A new type of text tool (array ASCII)
« Reply #5 on: Dec 18th, 2017, 9:11pm »

Quote:
I just want to explore more ways of doing this.

Thinking more about this (and it's still raining outside) it seemed to me that byte-array structures might also fit the bill and still avoid the string functions.
I had not played with these before and found the syntax a little tricky as a usage like this is not directly mentioned in the Manual. It is implied, once you get the hang of it, but I was perhaps being a little thick. Anyhow it all seems to work out. Now even if the application isn't very useful to some the handling of the structures might be interesting. I did not put much time into testing everything so there might be some rough edges. So here it is... byte-array structures in action.
Code:
 
      REM Write text characters to graphics screen.
      REM Now for something completely different, byte arrays structures.
      MODE 10
      h%=100
      v%=600
      f%=11         : REM Foreground color
      GCOL 12+128   : REM Optionaly set background color
      CLG
      Ret$= FNgstring(h%,v%,f%)  :REM put string in place

      END


      DEF FNgstring(h%,v%,f%)  : REM x, y coordinates, foreground logical color.
      LOCAL K%,  c$, cp%, ins%, t%, oldf%, b% , L% :REM f% foreground b%, background colors
      LOCAL text{}
      DIM text{a&(100)}
      VDU5
      oldf%=@vdu.g.b&           : REM May be BB4W specific
      b%=@vdu.g.d&
      GCOL f%                   : REM Types in color specified.
      ins%=TRUE                 : REM Start with insert mode
      c$="_"
      t%=15                     :REM initial timing delay for cursor.

      REPEAT :                    REM Loop getting input until a CR
        GCOL b%: MOVE h%, v% :PRINT SPC(cp%);c$;  :REM Remove cursor while we wait for keystrokes
        K%=INKEY(t%)
        IF K%=-1
        REM Build up String
        IF K% > 31 OR K%=8 THEN
          GCOL b%: MOVE h%, v% : PRINT text.a&(); :REM Erase old string things are about to change (maybe).
          CASE TRUE OF
            WHEN K% >31 AND K% <128
              CASE TRUE OF
                WHEN cp%=>L% : text.a&(L%)=K%: L%+=1
                WHEN cp%< L% AND ins%=TRUE : PROCgap(text{},L%,cp%) : L%+=1: text.a&(cp%)=K%
                WHEN cp%< L% AND ins%=FALSE: text.a&(cp%)=K%  :REM do we need to change cp%?
              ENDCASE
              cp%+=1
            WHEN K%=130: cp%=0      :REM Home
            WHEN K%=131: cp%=L%     :REM End
            WHEN K%=132: REM PgUp
            WHEN K%=133: REM PgDn
            WHEN K%=134: REM Ins
              REM Change modes and change cursor flash time.
              ins%=NOT ins%
              IF ins% t%=15 ELSE t%=8
            WHEN K%=8 : REM BackSp
              IF cp%>0: PROCdel(text{},L%,cp%-1) : L%-=1 : cp%-=1
            WHEN K%=135 : REM Del
              PROCdel(text{},L%,cp%): L%-=1
            WHEN K%=136: REM Left
              IF cp%>1 cp%-=1
            WHEN K%=137: REM Right
              IF cp% < L% cp%+=1
            WHEN K%=138, 139:REM Up or down
          ENDCASE
          REM  PRINT the new string.
          GCOL f% MOVE h%, v% : PRINT text.a&();
        ENDIF
        REPEAT UNTIL INKEY(0)=-1  : REM Mainly flushing excessive repeat keys if you hold them down.
        GCOL f%: MOVE h%, v% :PRINT SPC(cp%);c$;  :REM Now write the cursor in the new position if needed.
        WAIT t%                                     :REM Do nothing for a while.
      UNTIL K%=13
      GCOL b%: MOVE h%, v% :PRINT SPC(cp%);c$;
      GCOL oldf%             :REM Change Mode back to original plot color.
      VDU4
      =text.a&()

      DEF PROCgap(a{},l%,p%)
      REM Make a gap in the 'string' a{()} of length l% at position p% so we can insert
      LOCAL I%
      FOR I%=l%+1 TO p% STEP -1
        a.a&(I%)=a.a&(I%-1)
      NEXT
      ENDPROC

      DEF PROCdel(a{},l%,p%)
      REM Delete the item at p% from a 'string' a{()} of length l%
      LOCAL I%
      FOR I%=p% TO l%
        a.a&(I%)=a.a&(I%+1)
      NEXT
      ENDPROC
 
« Last Edit: Dec 18th, 2017, 9:21pm by Zaphod » User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: A new type of text tool (array ASCII)
« Reply #6 on: Dec 19th, 2017, 12:33pm »

Hi Zaphod,

It's not clear to me why it is useful to put the byte array inside a structure? Why not just use the array directly?

For wider readers, if you are only handling ASCII characters, it only takes up 1/4 the space if you store them in byte variables (&) rather than integers (%), which are 32 bits = 4 bytes each.

Best wishes,

D
User IP Logged

Zaphod
Guest
xx Re: A new type of text tool (array ASCII)
« Reply #7 on: Dec 19th, 2017, 1:45pm »

Quote:
It's not clear to me why it is useful to put the byte array inside a structure? Why not just use the array directly?


Well it saves you having to use indirection to locate the address of the parameter block and print out the contents of the array memory space, or take byte at a time and reconstruct the string as Michael suggested.
Messing around with indirection is a great way of crashing the program if you don't know what you are doing, and at the moment I can't remember how to do either.
So text.a&() returns the string contained in that array directly which seemed the easier option.
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: A new type of text tool (array ASCII)
« Reply #8 on: Dec 19th, 2017, 2:43pm »

Ooh, cute! I missed that. I see it is actually specified in the manual. It's vaguely interesting that PRINT is happy with nul-terminated strings.

So you could just use a simple array, but then to get the string you'd need to use

$$^ArrayName&(0)

Best wishes,

D
User IP Logged

Zaphod
Guest
xx Re: A new type of text tool (array ASCII)
« Reply #9 on: Dec 19th, 2017, 3:23pm »


Ah, yes, that $$^ArrayName&(0) was what I was missing. And so you don't need the structure part, you are right. I just have bad experiences of crashing programs or sending reams to the printer inadvertently when using indirection incorrectly, so I avoid it whenever possible. It's a bit like the old POKE command. User beware.

I'll leave that to Michael if he wants to explore that option.

Z

User IP Logged

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

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls