Shop OBEX P1 Docs P2 Docs Learn Events
DAT block questions. — Parallax Forums

DAT block questions.

RontopiaRontopia Posts: 139
edited 2008-03-13 16:14 in Propeller 1
Im at the end of the objects lab and I just keep going over and over it and im really missing something about the dat block.

heres the code if from the objects lab and works just fine. but I have questions about how it works and .. well here's the code
[noparse][[/noparse]code]

''Top File: TestMessages.spin
''sent text messages sorted in DAT block to the hyper terminal.

Con
······· _clkmode = xtal1 + pll16x
······· _xinfreq = 5_000_000

OBJ
······· Debug: "FullDuplexSerialPlus"

PUB· TestDatMessages | value, counter
· ''send messages stored in the DAT Block.

Debug.start(31, 30, 0, 57600)
waitcnt(clkfreq*3 + cnt)

··· repeat
······· Debug.Str(@MyString)
······· Debug.Dec(counter++)
······· Debug.Str(@MyOtherString)
······· Debug.Str(@CR)
······· waitcnt(clkfreq + cnt)

DAT
MyString··················byte··· 10, 13, "This is a test message number: ", 0
MyOtherString·········· byte··· ", ", 10, 13, "and this is another line of text.",0
CR··························byte··· 10, 13, 0


·[noparse][[/noparse]/code]

so my question is.. why the byte? does this code use a byte per letter? or does it put as many letters in the byte as will fit? and relaly I dont understand why i even need a byte? if its a dat block, why isnt it just stuffed into memory untill needed? or is byte = to MyString? im lost and the lab really doesnt explain this well. at least I didnt get it. also where is the byte? is it main ram? or is it in cog ram?

also.. the 10 and the 13 .. 10 means indent 10 spaces? but then there is a 13 which mean carrage return, woldnt that carrage return send the curser back to the left hand side of the text window?

why do I need a counter variable? or what ever its called.. counter space, why am i counting every time this thing loops? or is that what its doing? why do i care how many times it loops? actually now that I think about it.. what is value doing?

ok I have more questions about it but I think this is enough for now. Im starting to think that I will never get this in my head.

ok.. one more and it more of a compile question. so in this code we are using FullDuplesSerialPlus. but we are only really using the Str method in that object right? so the compiler does not "cherry pick" that method form the object or the methods it needs, it compiles the whole object right? if that is so.. wouldnt it be better to make an object with just the Str method in it to save ram space? or is that a loaded question?

thanks



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔



IC layout designer
Austin Texas

Comments

  • tpw_mantpw_man Posts: 276
    edited 2008-03-08 22:16
    Rontopia, here are the answers as best as I can answer them:

    1. In standard ASCII codes, a byte is used to store a letter. In the ASCII code set, that byte can also hold various control and special characters. It is stuffed by the byte/word/long prefix. MyString is just a label for easy referencing later on. More info on ASCII here. The data is located in main ram.

    2. 10 and 13 are the decimal equivalent of ASCII control characters. 10 is a Line Feed, which moves the cursor down one line at the place it is currently located. 13 is a Carriage Return, which moves the cursor to the start of the line it is on.

    3. The value variable does not appear to be doing anything. The counter variable is to hold the number to output to the screen. It loops indefinitely. Every time it loops, it outputs the first message, outputs the counter variable, increments it (counter++), displays the second message, and outputs a carriage return sequence.

    4. The reason for not creating an object with only what one needs is because it would probably be very time-consuming to do. Methods inside objects are usually highly dependent on each other to function, and if methods are missing, it would fail to compile. Also, making a custom object to save space rather than standard objects probably would not save much space, and it would be hard to find the modified version if it is not included.

    I hope I could help. Feel free to ask me anymore questions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1010, so be surprised!
  • RontopiaRontopia Posts: 139
    edited 2008-03-08 23:27
    1 so what your saying is each letter in the text needs it own byte.. ie. byte = T = 101 0101 or byte = 101 0101

    2 thats cool only in my mind this line:

    MyString··················byte··· 10, 13, "This is a test message number: ", 0

    would look like this:

    MyString··················byte··· 10, "This is a test message number: ", 13, 0

    or why do i need the CR at all if im asking for a new line with the "10".. does new line not mean what I think it does.." give me a new line to do something with" or is the CR telling the compiler where the new line is to start, which is below this one?

    3.... oh duh.. ok i get it.·I think i get it.

    so how do you use a variable in a DAT block? or can you I will give you an example of what I mean tho I know it would not work ..
    [color=blue]''Top File: TestMessages.spin
    ''sent text messages sorted in DAT block to the hyper terminal. [/color]
    [color=blue]Con
            _clkmode = xtal1 + pll16x
            _xinfreq = 5_000_000[/color]
    [color=blue]OBJ
            Debug: "FullDuplexSerialPlus"[/color]
    [color=blue]PUB  TestDatMessages | value, counter
      ''send messages stored in the DAT Block.[/color]
    [color=blue]Debug.start(31, 30, 0, 57600)
    waitcnt(clkfreq*3 + cnt)[/color]
    [color=blue]    repeat
            Debug.Str(@MyString)
            Debug.Dec(counter++)[/color]
    [color=#0000ff]        [color=red]counter = x
    [/color]        Debug.Str(@MyOtherString)
            Debug.Str(@CR)
            waitcnt(clkfreq + cnt)[/color]
    [color=blue]DAT[/color]
    [color=blue]MyString                  byte    10, 13, "This is a test message number: ","[color=#0]x[/color]" , 0
    MyOtherString             byte    10, 13, "and this is another line of text.",0
    CR                        byte    10, 13, 0[/color]
    
    


    this sort of thing would avoid confustion in my head as to where what CR and NL is and whats being displayed where... ikes I get lost easy and if everthing· was on its own line in code and then gets displayed that way.. you see what I mean? so I know what I wrote would not work but there should be a way for the variable counter to be included in the same line of code that it is to be displayed with. you know what Im saying? err writing?, getting at?

    thanks for your help

    and and if a byte is 8 bits.. and 101 0101 = T.. what happens to the blank? 101~0101..~ = blank .. its a memory cell and it has no blank state.. its either 1 or 0. is that 4th 1 or 0 just not read?





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔



    IC layout designer
    Austin Texas

    Post Edited (Rontopia) : 3/8/2008 11:33:40 PM GMT
  • Chuck McManisChuck McManis Posts: 65
    edited 2008-03-08 23:37
    Ron,

    You pretty much have it. So different ASCII control codes are treated differently. 10 (newline), moves the cursor straight down one line. The code 13 (carraige return) moves the cursor all the way to the left but does not change which line it is on. So to position the cursor at the start of the next lower line, the sequence 10,13 will move the cursor down and then left. (or 13,10) which will move it left and then down, both put it in the same spot. If you have a string 10,"string", 13 then the cursor is left at the beginning of the line where the string is and if another string is printed it might over write the current string.

    So in the code example the line:
    MyString                  byte    10, 13, "This is a test message number: ","x" , 0
    
    


    Has a string which first moves the cursor down and left, then it prints the message, then it *leaves* the cursor just after the "x" (which is replaced by a number I suspect)

    Clear?
    --Chuck
  • RontopiaRontopia Posts: 139
    edited 2008-03-08 23:48
    yes clear chuck.. thanks..

    so CR does not really mean CR like on a keyboard.. it just means "go all the way to the left from here"
    I get it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔



    IC layout designer
    Austin Texas
  • Chuck McManisChuck McManis Posts: 65
    edited 2008-03-09 00:17
    Exactly. The original definition of ASCII defines a number of "control code" (the first 32 values) and the interesting ones for sending to a terminal or a printer are generally control-J (also known as 10 decimal) for "line feed" (move down one line), control-M (also 13 decimal) for "Carraige Return" (send the carraige to the left column), control-I (also known as 9 decimal) send the carraige to the next tab stop (if one is set), control-g or 7 decimal, ring the bell, and control-L or 18 decimal which tells the printer or terminal to go to a new page.

    Those all have "responses" by a printing/display device that are defined by ASCII. When you send them to a program (because you are typing on a keyboard) the program can choose to do whatever it wants with them.

    --Chuck
  • portblockportblock Posts: 9
    edited 2008-03-10 00:42
    Think of the old teletype machines (serial drivin printers) or a type writter.

    on a typewriter, we can return the carriage, without going to a new line, hence chr 13 (0x0D)
    now once the carriage is returned, we need to advance the paper up, or a new line, hence chr 10 (0xA)

    hope the little history back in time thing shows where it came from.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2008-03-12 10:00
    I think what you have is another example of the curse of the two-fingered. The label CR is both terse and misleading. Carriage Return (plus line feed) should be viewed as a blank line.

    CR byte 10, 13, 0 'use for a blank line.

    This is a problem if you really want a Carriage Return without a line feed, say, to add underscores. (Which worked with printers)
  • RontopiaRontopia Posts: 139
    edited 2008-03-13 16:14
    thanks guys.. I think I got now. or at least I "get" as much as I need to know for now

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔



    IC layout designer
    Austin Texas
Sign In or Register to comment.