Shop OBEX P1 Docs P2 Docs Learn Events
concatenate a string — Parallax Forums

concatenate a string

laser-vectorlaser-vector Posts: 118
edited 2010-07-30 08:14 in Propeller 1
RESOLVED!!

FIXED and working:

pin connections:



CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  cols = 80
  rows = 64
  tiles = cols * rows

  spacetile = $220
  mousespeed = 10
  scale = 10

OBJ

  vga     : "VGA_1280x1024_Tile_Driver_With_Cursor"
  mouse   : "mouse"
  num     : "numbers"
  
VAR

  long  col, row, color
  long  boxcolor, boxptr

  long  array[noparse][[/noparse]tiles/2]
  long  cursor[noparse][[/noparse]1+32]

  long  cursor_x, cursor_y, cursor_col, cursor_def
  long  changeme
  long  var1
  long  var2
  byte  temp[noparse][[/noparse]80]

PUB start | i, j, k

  'start mouse and set bound parameters
  mouse.start(24, 25)
  mouse.bound_limits(0, 0, 0, 1279 / mousespeed, 1023 / mousespeed, 0)
  mouse.bound_scales(1, 1, 0)
  mouse.bound_preset(640 / mousespeed, 512 / mousespeed, 0)
  
  'start vga tile driver
  vga.start(16, @array, @vgacolors, @cursor_x, 0, 0)
  menu4

PUB menu4 | update
  update := -1
  dira[noparse][[/noparse]3..0]~                                           {sets pins 3..0 to inputs}
  print($100)                                           {clears the screen from the last menu} 
  var1 := string("Temperature:")
  var2 := string("°C")
  repeat
    box(2, 58, 0, string("MAIN MENU"))
   bytemove(@temp, var1, strsize(var1) + 1)
   bytemove(@temp + strsize(@temp), num.tostr(changeme*100, num#dec) , strsize(num.tostr(changeme*100, num#dec))+ 1)
   bytemove(@temp + strsize(@temp), var2, strsize(var2) + 1)
                                                           

   box(28, 30, 0, (@temp))

   cursor_x := mouse.bound_x * mousespeed                
   cursor_y := mouse.bound_y * mousespeed
    if cursor_y => 30 and not cursor_y => 100 and cursor_x => 25 and not cursor_x => 210
      cursor_def := 0
      cursor_col := $ff
    else
      cursor_def := 1
      cursor_col := $ff
    if mouse.button(0) and cursor_y => 30 and not cursor_y => 100 and cursor_x => 25 and not cursor_x => 210
      menu1
      quit
    changeme := ina[noparse][[/noparse]3..0]                                {changeme now = the value of pins 3..0}
    repeat while not update == changeme                 {loop only executes if changeme is updated/changes}                                         
      print($100)
      print($110)
      print_string(string("BINARY ="))
      print_string(num.tostr(changeme, num#bin))
      print_string(string(" ... HEX ="))
      print_string(num.tostr(changeme, num#hex))
      print_string(string(" ... DEC="))
      print_string(num.tostr(changeme, num#dec))
      update := changeme                                {update is set to the value of changeme so the loop waits untill their values differ}
 PRI box(left, top, clr, str) | width, height, x, y, i

' Draw a box

  boxcolor := $10 + clr
  color := clr + 5

  width := strsize(str)
  height := 2

  boxptr := top * cols + left
  boxchr($0)
  repeat i from 1 to width
    boxchr($C)
  boxchr($8)
  repeat i from 1 to height
    boxptr := (top + i) * cols + left
    boxchr($A)
    boxptr += width
    boxchr($B)
  boxptr := (top + height + 1) * cols + left
  boxchr($1)
  repeat i from 1 to width
    boxchr($D)
  boxchr($9)

  col := left + 1
  row := top + 1
  print_string(str)
  

PRI boxchr(c): i

  array.word[noparse][[/noparse]boxptr++] := $200 + c + boxcolor << 10


PRI print_string(ptr)

  repeat while byte[noparse][[/noparse]ptr]
    print(byte[noparse][[/noparse]ptr++])
    

PRI print(c) | i, k

'' Print a character
''
''       $0D = new line
''  $20..$FF = character
''      $100 = clear screen
''      $101 = home
''      $108 = backspace
''$110..$11F = select color

  case c
    $0D:                'return?
      newline

    $20..$FF:           'character?
      k := color << 1 + c & 1
      i := $200 + (c & $FE) + k << 10
      array.word[noparse][[/noparse]row * cols + col] := i
      array.word[noparse][[/noparse](row + 1) * cols + col] := i | 1
      if ++col == cols
        newline

    $100:               'clear screen?
      wordfill(@array, spacetile, tiles)
      col := row := 0

    $101:               'home?
      col := row := 0

    $108:               'backspace?
      if col
        col--

    $110..$11F:         'select color?
      color := c & $F


PRI newline | i

  col := 0
  if (row += 2) == rows
    row -= 2
    'scroll lines
    repeat i from 0 to rows-3
      wordmove(@array.word[noparse][[/noparse]i*cols], @array.word[noparse][[/noparse](i+2)*cols], cols)
    'clear new line
    wordfill(@array.word[noparse][[/noparse](rows-2)*cols], spacetile, cols<<1)
      

DAT
  
vgacolors long

  long $3C043C04       'lt grey on dk grey
  long $3C3C0404
  long $C000C000       'red
  long $C0C00000
  long $30003000       'green
  long $30300000
  long $0C000C00       'blue
  long $0C0C0000
  long $FC00FC00       'white
  long $FCFC0000
  long $FF80FF80       'red/white
  long $FFFF8080
  long $FF20FF20       'green/white
  long $FFFF2020
  long $FF28FF28       'cyan/white
  long $FFFF2828
  long $C0408080       'redbox
  long $3010F020       'greenbox
  long $3C142828       'cyanbox
  long $FC54A8A8       'greybox
  long $3C14FF28       'cyanbox+underscore
  long $F030C050       'graphics colors
  long $881430FC
  long $8008FCA4

     byte 0

{{     




THANKS

Post Edited (laser-vector) : 7/30/2010 8:20:00 AM GMT

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2010-07-30 05:57
    without seeing the definitions of the method print and print_string it's not possible to say something
    strings are BYTE-sequences not long-sequences
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-30 06:07
    sorry bout that, i have also tried BYTEMOVE with no success.. heres all of the code:

    
    {removed this code because it was junk...}
    
    
    

    Post Edited (laser-vector) : 7/30/2010 8:20:58 AM GMT
  • max72max72 Posts: 1,155
    edited 2010-07-30 06:09
  • TimmooreTimmoore Posts: 1,031
    edited 2010-07-30 06:13
    Some comments
    you are creating a string which is bytes - why is temp where yo are putting the string longs?
    You are putting the temperature of 100 is TEMP but this is where you are putting the string so overwriting the 100
    longmove - you are moving a string which is bytes so you are moving 4x the bytes
    the longmove of TEMP into he string doesnt' convert a number which is a number of 100 into a string which is '1', '0', '0' you get a character which is a value of 100 - look at the routine you are calling with num.tostr that is convrting a number to its string
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-30 06:21
    laser-vector,

    This is hard one to explain.·

    var1·:=·string("Temperature:·")

    var1 now contains the location where the string of bytes "Temperature:·" is stored.· Hense the @var1 in the bytemove commands.· The @ means "location of."

    One of your first problems is you fill the first 32 longs of your array TEMP with zero with the longfill command after you set Temp[noparse][[/noparse]0] to 100.

    StefanL38 is correct, strings are sequences of bytes and it would be a lot easier to keep track of your strings if you used arrays of bytes.· You do want to continue to use longs for memory location addresses.

    I recognize print and print_string commands from some of your other posts, but again StefanL38 is again correct, you want to at least inform us what methods you are using.· I assume you're modifying one of the VGA objects.

    Read through some of the objects in the library and demos to find examples of dealing with strings.· It takes some getting used to.

    Duane

    Note: Timmoore posted as I was writting this.· Amen to what he says.
    Edit:· I only saw Timmoore's post.· I started writting after StefanL38 comments.· laser-vector, thanks for adding you full code.· Your longfill (or is it bytefill now, I can't see the thread while editing) is still setting Temp to zero (which is actually a minor part of what is wrong here).

    Post Edited (Duane Degn) : 7/30/2010 6:27:55 AM GMT
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-30 06:45
    ·laser-vector,

    I just looked through Numbers.spin.· I found if rather difficult to understand.· I copied a method I use to check the a string from a balance to·pull out the weight.· Hopefully you can follow some of it and gain a better understanding of string.· I don't think the method calls any other methods but there are a couple of global variable so the rest of the program has access to the weight.· This method checks for the letter "g" (upper or lowercase) because any characters after the "g" are not part of the weight.

    PUB StrToPseudonumber(rawBufferPointer, bufferPointer) | character, afterDecimalFlag, localNumber, size, endFlag
      leftDecimalMass := 0
      rightDecimalMass := 0
      positiveMassFlag := 1
      afterDecimalFlag := 0
      endFlag := 0
      
      size := strsize(rawBufferPointer)
      repeat size
        character := byte[noparse][[/noparse]rawBufferPointer++]
        localNumber := 999          ' if localNumber is still 999 I know the character read wasn't a numeral.
        case character
          43: positiveMassFlag := 1 ' +
          45: positiveMassFlag := 0 ' -
          46: afterDecimalFlag := 1 ' .
            byte[noparse][[/noparse]bufferPointer++] := character
          48..57:  localNumber := character - 48   ' 48 is the ASCII value for zero (see character chart in help menu)
            byte[noparse][[/noparse]bufferPointer++] := character
          71, 103: endFlag := 1         ' g
        if localNumber < 10 and endFlag == 0       ' localNumber will be 999 still if no numeral was found this loop
          if afterDecimalFlag
            rightDecimalMass := (rightDecimalMass * 10) + localNumber    ' I want the weight in both a string and in decimal form in a variable.
          else
            leftSize++
            leftDecimalMass := (leftDecimalMass * 10) + localNumber   
      byte[noparse][[/noparse]bufferPointer] := 0                    ' Strings are supposed to end in zero, so I add on to make sure it does.
      
    

    Edit:· Fixed spelling and added additional comments in code.

    Post Edited (Duane Degn) : 7/30/2010 6:52:30 AM GMT
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-30 07:01
    I edited the first post's code, when i copied it over the first time i guess it was from a different stage (maybe i hit undo a few times or something and didnt check it). either way, thanks so far, im still trying to learn how to manipulate things in memory with MOVEs, so please be patient [noparse]:D[/noparse]
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-07-30 07:48
    laser-vector,

    Answering questions on this forum is just for the person asking the orignial question.· Many people search these forums for thread relating to a topic they are having trouble with.· Having old posts online serve as a resource for others in the future.· I myself have not asked many questions here.· I've used Google advanced search to find treads that discussed the problem I'm having and, more often than not can find the answer I'm looking for.· What I'm getting at is . . .

    I don't think it is helpful to others to remove the original post where the question is asked.· You could have better served the community buy posting your thanks as a reply to previous posts.

    Duane

    Edit: removed "<!-- Edit -->."· How'd that get there?· I think it's a tag from part of a comment I was quoating but decided to remove and it left behind invisible text.

    Post Edited (Duane Degn) : 7/30/2010 7:53:40 AM GMT
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-30 08:14
    sorry Duane, i was a little embarrassed with the sloppyness of my code (as Timmoore pointed out a few things. and it wasnt very clear) so i figured it would be best to just remove it, Ill post the Fixed code on the first post.
Sign In or Register to comment.