concatenate a string
laser-vector
Posts: 118
RESOLVED!!
FIXED and working:
pin connections:
THANKS
Post Edited (laser-vector) : 7/30/2010 8:20:00 AM GMT
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
strings are BYTE-sequences not long-sequences
Post Edited (laser-vector) : 7/30/2010 8:20:58 AM GMT
propeller.wikispaces.com/Strings
Massimo
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
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
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.
Edit:· Fixed spelling and added additional comments in code.
Post Edited (Duane Degn) : 7/30/2010 6:52:30 AM GMT
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