Shop OBEX P1 Docs P2 Docs Learn Events
C3+MikronautsVGA80+keyboard test program — Parallax Forums

C3+MikronautsVGA80+keyboard test program

RsadeikaRsadeika Posts: 3,837
edited 2011-04-27 05:36 in Propeller 1
I am probably being a little optimistic by calling this PropOS_C3, but what the heck. Below is the program that is basically testing out the C3, MikronautsVGA80, and the keyboard program.

Some observations:
C3: I started out using a USB keyboard with a USB to PS/2 converter, for whatever reason the C3 does not recognize it. As soon as I plugged in a PS/2 plug keyboard, it started to work. I still wish the new boards would use the available 2011 technology.

I plugged in 6.250 MHz crystal, and I tried the program below. I am getting a hit and miss situation when I try to start the program up. Sometimes program starts up, and sometimes it does not start, so I am not sure what the problem is. I did notice that there is a greater chance for the program to start when the power plug is in.

MikronautsVGA80: This program gets me the 80 char screen that I wanted to play around with, I guess I can live with the 30 rows, I was looking for 24. I would like to see a flashing underline cursor, but I do not have any idea as to how to do that. Is that something in the program itself that I am missing?

keyboard: Where do I program the keyboard control, meaning it should do the function, and not just display the key press to the screen. A good example is the backspace key, when I press that, all I get is a character on the screen, and not the actual backspace.

The program below is a very simple test to see how the keyboard, and the VGA screen interact. I am looking for a command line type of scenario, not sure if the VGA program is capable of doing graphics, and if it is, not sure how you could use a mouse and a keyboard at the same time. So, I guess I need some guidance on the problems mentioned above. As I improve this program I will post it; I will try to do this in stages so the beginners will have a chance to see how everything evolves, instead of trying to decipher 20 objects with 50 pages of code. That its for now.

Thanks

Ray

'' PropOS_C3.spin


CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 6_250_000



CLOCKS_PER_MICROSECOND = 5*16
CLOCKS_PER_MILLISECOND = 5000*16

STATUS_LED_BUS_MUX = 15

PS2_DATA  = 26
PS2_CLK   = 27

VAR

long x, y, k


OBJ

  vga        : "MikronautsVGA80.spin"  '' Program by Wlliam Henning
  kbd        : "keyboard_010.spin"


PUB Main

'' This is needed for the C3 init '''''
  vga.start(%10110)   '' 16           '
                                      '
  Delay_US(1*1_000_000)               '
                                      '
  DIRA[STATUS_LED_BUS_MUX] := 1       '
  OUTA[STATUS_LED_BUS_MUX] := 0       '
'''''''''''''''''''''''''''''''''''''''

  vga.cls    '' Clear the screen

  vga.str(string("Hello World"))

  kbd.start(PS2_DATA, PS2_CLK)

  kbd.clearkeys
  vga.out($0D)            '' Newline
  vga.out(">")            '' Special char
  
  repeat
    if (kbd.gotkey == TRUE)  '' Checks to see if there is a keypress
      k:= kbd.key            '' If there is, grab it

      vga.out(k)
        if (k == $0D)      '' If enter key
          vga.out(">")     '' goto newline
        



PUB Delay_MS(time)
  waitcnt (cnt + time*CLOCKS_PER_MILLISECOND)


PUB Delay_US(time)
  waitcnt (cnt + time*CLOCKS_PER_MICROSECOND)

«1

Comments

  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-04-16 09:43
    As for the backspace you would have to interpret it, and space out the previous char (by repositioning the cursor), and make sure that the char is in the correct place. Similar goes for the flashing cursor (draw and erase an underscore).
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-16 13:43
    Hi Ray,

    The reason the C3 does not recognize your keyboard is that the converters are passive; the keyboard must support the PS2 protocol.

    I am glad you like the driver. The "hit-and-miss" sync you notice is a known problem, that Kuroneko's patch has already fixed with the 64 and 50 column drivers (that use 80Mhz), and I have incorporated the fix into the 80 column version I have here - but I am having some issues. I should be able to work on it next week, right now I am working on getting a few more of my PCB's into production in time for UPEW :-)

    To get 24 rows, select the 8x10 font by uncommenting the correct object line, and set scalex=2 in its CON section.

    I will attach the lates, hacked to pieces, untested, with incorrect comments on top, not cleaned up, version of the driver. It might blow up your LCD and fry your Prop or it just might work :)

    The driver only provides basic tvtext style output, it does not implement cursors or line/screen editing.

    It is relatively easy to keep track of the cursor and provide such capabilities; and it should be easy to modify existing text editors written in Spin to use my driver to provide 80x24 output.

    You can make a blinking underline cursor by getting the character at the cursor position, and alternating the character at that location with the original character and the underscore character.

    Here are a few helper functions, including a new version of CLS, that I will later add to the next version of the drivers that will make writing editors and blinking cursors easier:
    PUB get(xc,yc)
      return tilemap[yc*chars + xc]
    
    PUB getx
      return col
    
    PUB gety
      retun row
    
    PUB blink(t)|ch ' time to display cursor/character specified in ms
       ch:=get(col,row)
       wait(cnt+_clkfreq/1000)
       put(col,row,95) ' I think thats underscore
       wait(cnt+_clkfreq/1000)
       put(col,row,ch) ' put back original character
    
    PUB cls|yn
      'init colors to cyan on blue
      repeat yn from 0 to lines-1
        colors[yn]:=$2804
      ' fill the screen with space character
      bytefill(@tilemap,32,lines*chars)
      row:=0
      col:=0
    

    Rsadeika wrote: »
    I am probably being a little optimistic by calling this PropOS_C3, but what the heck. Below is the program that is basically testing out the C3, MikronautsVGA80, and the keyboard program.

    Some observations:
    C3: I started out using a USB keyboard with a USB to PS/2 converter, for whatever reason the C3 does not recognize it. As soon as I plugged in a PS/2 plug keyboard, it started to work. I still wish the new boards would use the available 2011 technology.

    I plugged in 6.250 MHz crystal, and I tried the program below. I am getting a hit and miss situation when I try to start the program up. Sometimes program starts up, and sometimes it does not start, so I am not sure what the problem is. I did notice that there is a greater chance for the program to start when the power plug is in.

    MikronautsVGA80: This program gets me the 80 char screen that I wanted to play around with, I guess I can live with the 30 rows, I was looking for 24. I would like to see a flashing underline cursor, but I do not have any idea as to how to do that. Is that something in the program itself that I am missing?

    keyboard: Where do I program the keyboard control, meaning it should do the function, and not just display the key press to the screen. A good example is the backspace key, when I press that, all I get is a character on the screen, and not the actual backspace.

    The program below is a very simple test to see how the keyboard, and the VGA screen interact. I am looking for a command line type of scenario, not sure if the VGA program is capable of doing graphics, and if it is, not sure how you could use a mouse and a keyboard at the same time. So, I guess I need some guidance on the problems mentioned above. As I improve this program I will post it; I will try to do this in stages so the beginners will have a chance to see how everything evolves, instead of trying to decipher 20 objects with 50 pages of code. That its for now.

    Thanks

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-16 14:11
    Strangely enough, I changed the xtal1 to xtal2, and that looks like it made it work in a more consistent manner. But, according to the manual it should not work at all. The getx, and gety methods that you provided, I have already tried, and it did not get me what I was expecting. Instead of a location number I just got a gibberish character. Maybe you could provide a simple example for proper use of the two PUBs.

    Ray
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-16 14:15
    That is interesting news about xtal2.

    I will certainly due so after my current time crunch is over - I am afraid getting ready for UPEW product launches is higher priority :)

    I only posted the above to point you in the approximately correct direction.

    FYI, the sync issue is due to lack fo synchronization between hub access cycles and WAITVID behaviour; kuroneko figured out how to force synchronization, but I could not get it running in the 80 column driver quickly. Fixing this driver is on my "TODO" list, and I will try - but cannot promise - to have it running before UPEW.

    The new methods I added above were untested, and have to be placed into the driver source, not the application source.

    For now, I suggest you go back to 80MHz, and use the 64 column driver. Using the 8x10 font with scalex=2 it will give you a nice steady 64x24 screen, which will let you work on getting line/screen editing going until such time as the 80 column driver is fully qualified.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-17 04:50
    I just tested out the MikronautsVGA64.spin, it started out OK, but the sync issue raised its ugly head. When I was working with MikronautsVGA80.spin, even using the xtal2 setting, eventually the sync issue showed up. I hate to say this, but I do not think that I have the patience to keep doing a reset/reload until the program kicks in. I even tried using the blink and get PUBs with no success. So, now I do not have the slightest idea as to what the next step should be. Maybe I should go back to embedded x86? Anybody have any suggestions?

    Thanks

    Ray
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-17 05:01
    Can you attach the driver(s) you are using? I never had issues with the 50 column driver (after the adjustment) neither with the 80 column driver which I picked up this morning from the forum (despite having to use a 6.5MHz crystal).
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-17 05:18
    In my first post, I have a zip file attached that contains the driver(s) that I am using. Just to qualify, I did try this with two different working monitors, just to make sure.

    Ray
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-17 05:28
    Rsadeika wrote: »
    In my first post, I have a zip file attached that contains the driver(s) that I am using.
    The first post of this thread has a single (top level) SPIN file as an attachment. How do I get hold of the ZIP archive you mention? I'd also like to see the 64 column driver you're using.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-17 06:12
    Sorry, I grabbed the wrong file for upload, I could sworn I had uploaded the zip file. Anyway, attached is the zip file which contains the driver(s).

    Ray
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-17 06:52
    Hi Ray,

    Did you go back to 80Mhz for the 64 column driver?

    I've never had it not sync with kuroneko's patch applied.

    For inexpensive embedded x86, I've had great success using Intel Atom 330 mini-ITX boards - inexpensive, and small.
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-17 06:57
    FWIW, the 64 column driver from the archive works out of the box (demoboard adaption). Can't be bothered right now to switch crystals, the included 80 column driver is broken anyway (or rather not fixed yet). Do you have any other platform where you can verify the drivers? I don't assume that my monitor is in any way special (LCD 1280x1024). Personally I don't have a C3 so unless someone else jumps in and runs your test I'm out of options.

    The get method does work. You have to assign its result to something or print it directly e.g. vga.out(vga.get(xx, yy)). Calling vga.out(xx) is equivalent to CLS (xx is a global and therefore initially 0). As for the blink() implementation, try this instead:
    PUB blink(t{ms}) | ch
    
      ch := get(col, row)
      waitcnt(cnt+clkfreq/1000*t)
      put(col, row, 95)
      waitcnt(cnt+clkfreq/1000*t)
      put(col, row, ch)
    
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-17 07:09
    kuroneko, thanks for catching my blink() error - I wrote it on the fly while testing pcbs...

    the 64 and 50 column drivers work perfectly for me, every time, with your fix!
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-17 07:46
    I seemed to have misplaced my demo board, as soon as I find it, I will give the 64 column driver another try. If every thing works, meaning no problem with the monitor, then I will have to assume that there is something wrong with the C3 board. Hopefully there is somebody else out there with a C3 that can verify that the Mikronauts VGA driver(s) do work on the C3.

    The Intel mini-itx boards are a little under powered for my purposes, although the D510 is 1.8GHz, which is still not good enough. But, when you compare it to 100MHz, then the mini-itx stuff is a speed demon.

    Ray
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-17 19:14
    Rsadeika wrote: »
    Hopefully there is somebody else out there with a C3 that can verify that the Mikronauts VGA driver(s) do work on the C3.
    New thread [thread=131104]Attention C3 owners: VGA test request[/thread].
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-18 19:19
    I posted the C3 fix in the new thread referenced above; the VGA output is not enabled by default on the C3, takes two lines of spin in the demo program.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-19 12:38
    The code below now works as expected. I am very surprised that Andre did not put in his opinion on this, this probably could have been resolved a couple of days ago.

    Now, does this mean that the 80 x 24 driver will work?

    Thanks

    Ray
    '' PropOS_C3.spin
    
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    
    CLOCKS_PER_MICROSECOND = 5*16
    CLOCKS_PER_MILLISECOND = 5000*16
    
    STATUS_LED_BUS_MUX = 15
    
    PS2_DATA  = 26
    PS2_CLK   = 27
    
    VAR
    
    long x, y, k, xx, yy
    long Xpos, Ypos
    
    
    OBJ
    
    
      vga        : "MikronautsVGA64.spin"   '' Program by William Henning
      kbd        : "keyboard_010.spin"
    
    
    PUB Main
    
    '' This is needed for the C3 init '''''
                                          '
      DIRA[STATUS_LED_BUS_MUX]:=1         '
      vga.start(16)                       '
    '''''''''''''''''''''''''''''''''''''''
    
      vga.cls    '' Clear the screen
    
      vga.str(string("Hello World"))
    
      kbd.start(PS2_DATA, PS2_CLK)
    
      kbd.clearkeys
      vga.out($0D)            '' Newline
      vga.out(">")            '' Special char
      
      repeat
        if (kbd.gotkey == TRUE)  '' Checks to see if there is a keypress
          k:= kbd.key            '' If there is, grab it
    
          vga.out(k)
        
            if (k == $0D)      '' If enter key
              vga.out(">")     '' goto newline
              
    
    
    ''PUB backspace
    
    ''  vga.out($08)
      
    
    PUB Delay_MS(time)
      waitcnt (cnt + time*CLOCKS_PER_MILLISECOND)
    
    
    PUB Delay_US(time)
      waitcnt (cnt + time*CLOCKS_PER_MICROSECOND)
    
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-19 17:15
    Originally you used:
    '' This is needed for the C3 init '''''
      [COLOR="blue"]vga.start(%10[/COLOR]110[COLOR="blue"])[/COLOR]   '' 16           '
                                          '
      Delay_US(1*1_000_000)               '
                                          '
      [COLOR="red"]DIRA[STATUS_LED_BUS_MUX] := 1[/COLOR]       '
      OUTA[STATUS_LED_BUS_MUX] := 0       '
    '''''''''''''''''''''''''''''''''''''''
    
    This is equivalent to what you use now:
    '' This is needed for the C3 init '''''
                                          '
      [COLOR="red"]DIRA[STATUS_LED_BUS_MUX]:=1[/COLOR]         '
      [COLOR="blue"]vga.start(16)[/COLOR]                       '
    '''''''''''''''''''''''''''''''''''''''
    
    So why would the C3 behave differently? The VGA driver ignores the lower 3 bits of the basepin parameter so it still is 16 (but is started before the buffer is enabled). And the delay shouldn't make any difference at all.

    As for the 80 column driver, don't use the one posted in this thread and AFAIK the one from its introductory thread is not fixed yet. Just wait for Bill.

    I'm curious, when it goes wrong, does the LED stay on (it seems it's hard-wired to the buffer enable line)?
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-20 02:45
    First off, Thanks kuroneko and Bill for taking the time to figure this out. I do not have the slightest idea as to why it is working now, I used the same monitor, and keyboard this time around. The only speculation that I have, and I will be nice, I have an "ultra-sensitive" board. Having said that, I will continue testing some of the other features of the board, with my command line approach.

    I tried out the 'blink' PUB, it works as expected, but I did notice the program is starting to show some lag time between the keypress, and the char showing up on the screen. I guess maybe I need to step up to a 100MHz crystal?

    The other problem now seems to be the control of the keyboard, I am still getting garbage characters on the screen after a keypress like 'backspace'. I guess I have to change something in the VGA driver object, but it seems like $08 is addressed in the out(c) PUB. Every time that I try to use it from an out() perspective, it still throws up some garbage to the screen, and does not do the actual backspace. I guess all this should keep me busy.

    Thanks

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-20 06:38
    I think I got the backspace, ->, and <- keys to work the way I think that it should work. Now if you hit the Insert key or something, you can just use the backspace key the get rid of the garbage character. Small steps in the beginning. Now, I will try to get keypress input capture to work, this should be a little more difficult, but it should be a good concept to master. Once that is done, I can either go the menu route, or keyed command route, or maybe both, not sure at this point.

    The zip file with the changes to VGA64 driver file is attached below. I guess i need some feedback as to what could be done better.

    Thanks

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-21 06:55
    I really need some help on the concept of capturing a keypress. Below is my attempt to do it, all I am getting is a garbage key displayed. So, I am not even sure if anything got put into the Bkeystring[] array. The ultimate goal is to capture a typed in command, which might be up to twenty characters in length. Any help will be appreciated.

    Thanks

    Ray
    '' PropOS_C3.spin
    
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    
    STATUS_LED_BUS_MUX = 15
    
    PS2_DATA  = 26
    PS2_CLK   = 27
    
    VAR
    
    long  temp1
    
    OBJ
    
    
      vga        : "MikronautsVGA64.spin"   '' Program by William Henning
      kbd        : "keyboard_010.spin"
    
    
    PUB Main
    
    '' This is needed for the C3 init '''''
                                          '
      DIRA[STATUS_LED_BUS_MUX]:=1         '
      vga.start(16)                       '
    '''''''''''''''''''''''''''''''''''''''
    
      
      vga.cls    '' Clear the screen
    
      vga.str(string("Hello World"))
      
    
      kbd.start(PS2_DATA, PS2_CLK)
    
      kbd.clearkeys
      vga.out($0D)            '' Newline
      vga.out(">")            '' Special char
      
      repeat
        get_keystring
               
        vga.blink(200)
      
    
    PUB get_keystring | k, Bkeystring[1]
    
    
      
      if(kbd.gotkey == TRUE)  '' Checks to see if there is a keypress
        
          k:= kbd.key            '' If there is, grab it
          vga.out(k)
          temp1:=k
          temp1:= byte[@Bkeystring][1] 
    
            if (k == $0D)      '' If enter key
              vga.out(">")     '' goto newline
              vga.out(@Bkeystring[0])  
       ''vga.blink(200)
    
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-21 12:37
    Well, I tried a bunch of different things today, and it looks like vga.(out), or any form of it, can not handle array elements. I tried a simple:
    Bkeystring[0]:= "X"
    vga.out(Bkeystring[1])
    and all I get is a garbage character on the screen. So, I am not sure if this is a problem with the VGA64 driver, or my "ultra sensitive" C3 board. The worst part is I do not know how to get around this problem. It is probably some simple explanation that I am not seeing at the moment. Any help would be appreciated.

    Thanks

    Ray
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-21 12:44
    Sorry Ray,

    The problem appears to be that you are not initializing Bkeystring anywhere in the code above, so it has random garbage in it.

    It has nothing to do with your C3, or the driver, it is simply a programming error.

    Bill
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-21 12:51
    I am not sure what you mean by "initializing", so here is the complete code.

    '' PropOS_C3.spin
    
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    
    STATUS_LED_BUS_MUX = 15
    
    PS2_DATA  = 26
    PS2_CLK   = 27
    
    VAR
    
    byte  temp1
    
    OBJ
    
    
      vga        : "MikronautsVGA64.spin"   '' Program by William Henning
      kbd        : "keyboard_010.spin"
    
    
    PUB Main
    
    '' This is needed for the C3 init '''''
                                          '
      DIRA[STATUS_LED_BUS_MUX]:=1         '
      vga.start(16)                       '
    '''''''''''''''''''''''''''''''''''''''
    
      
      vga.cls    '' Clear the screen
    
      vga.str(string("Hello World"))
      
    
      kbd.start(PS2_DATA, PS2_CLK)
    
      kbd.clearkeys
      vga.out($0D)            '' Newline
      vga.out(">")            '' Special char
      
      repeat
        get_keystring
               
        vga.blink(200)
      
    
    PUB get_keystring | k, Bkeystring[1]
    
    
      
      if(kbd.gotkey == TRUE)  '' Checks to see if there is a keypress
        
          k:= kbd.key            '' If there is, grab it
          temp1:=k
          vga.out(k)
          
          ''temp1:=k
         '' byte[@Bkeystring][0] := $41
          Bkeystring[0]:= "X" 
           vga.out(Bkeystring[1])
          if (k == $0D)      '' If enter key
              vga.out(">")     '' goto newline
     
       ''vga.blink(200)
    
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-21 13:09
    Rsadeika wrote: »
    I am not sure what you mean by "initializing", so here is the complete code.

          Bkeystring[0]:= "X" 
           vga.out(Bkeystring[1])
    

    You are puttin "X" into array element Bkeystring[0], but trying to print array element Bkeystring [1] - whose value was never initialized (set), and as such will have garbage in it
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-21 16:34
    Apart from that, using Bkeystring[1] is invalid. The array is only defined to have one element which translates to index 0.
  • Bill HenningBill Henning Posts: 6,445
    edited 2011-04-21 17:23
    Absolutely true...

    Hmm...

    If the stack frame is:

    agument
    return address
    local valriables

    then Bkeystring[1] would not clobber anything if it was the last local declared... i think.

    Ray should declare a global line buffer, and implement a line editor based on that.
    kuroneko wrote: »
    Apart from that, using Bkeystring[1] is invalid. The array is only defined to have one element which translates to index 0.
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-21 17:31
    then Bkeystring[1] would not clobber anything if it was the last local declared... i think.
    Yes, it's only read but it's still undefined. Anyway, just throwing out hints here:
    CON
      ccnt = 32                                             ' buffer size
      
    VAR
      byte  buffer[ccnt]                                    ' (ccnt-1) characters + terminator
      long  index
      
    PUB get_keystring | c
      
      if kbd.gotkey
        c := kbd.key
        vga.out(c)                                          ' local echo
    
        if index < constant(ccnt -1)                        ' place key code into buffer
          buffer[index++] := c                              ' as long as we have space
    
        if c == $0D                                         ' EOL
          vga.str(string("local buffer: "))                 ' |
          vga.str(@buffer{0})                               ' display string buffer
          index~                                            ' reset index
          bytefill(@buffer{0}, 0, ccnt)                     ' reset buffer
    
          vga.out(">")                                      ' prompt
    
    DAT
    
    @Ray: As for the sluggishness, try reducing the blink() parameter in your main loop. It's eating way too much time.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-22 07:01
    Below is version that captures the keypress, Thanks kuroneko. Now I am trying to process the contents of the buffer[]. I added a simple 'if' to compare the buffer[] contents to a string "dir", the program compiles, but when I type in dir, nothing is happening. My thoughts, the contents of @buffer are 32 bytes long, and "dir" is 3 bytes long, so it is not '=='? Does that mean I have to trim @buffer to eliminate all the excess zeros? But, when the @buffer gets printed to the screen, it does not show all of the zeros in the @buffer contents. Their must be something else that is going on?

    Thanks

    Ray
    '' PropOS_C3.spin
    
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    
    STATUS_LED_BUS_MUX = 15
    
    PS2_DATA  = 26
    PS2_CLK   = 27
    
    ccnt = 32      '' Size of buffer[]
    
    VAR
    
    byte buffer[ccnt]
    long index
    
    OBJ
    
    
      vga        : "MikronautsVGA64.spin"   '' Program by William Henning
      kbd        : "keyboard_010.spin"
    
    
    PUB Main
    
    '' This is needed for the C3 init '''''
                                          '
      DIRA[STATUS_LED_BUS_MUX]:=1         '
      vga.start(16)                       '
    '''''''''''''''''''''''''''''''''''''''
    
      
      vga.cls    '' Clear the screen
    
      vga.str(string("Hello World"))
      
    
      kbd.start(PS2_DATA, PS2_CLK)
    
      kbd.clearkeys
      vga.out($0D)            '' Newline
      vga.out(">")            '' Special char
      
      repeat
        get_keystring
               
        vga.blink(100)
        
    
    PUB get_keystring | c{keypress}
    
      if (kbd.gotkey == TRUE)
         c:=kbd.key
         vga.out(c)
    
         if index < constant(ccnt-1)     '' This controls placement of char 
           buffer[index++]:=c            '' in the buffer array
    
      if c == $0D
        if ( dir  == @buffer )
          vga.str(string("Did I get anything usefull"))  
        vga.str(string("Local Buffer: "))
        vga.str(@buffer{0})                '' This prints the buffer contents
        index~                             '' Reset the index
        bytefill(@buffer{0}, 0, ccnt)      '' This zeros out @buffer
    
       vga.out(">")
      
    
    DAT
    
    dir byte "dir"  
    
  • kuronekokuroneko Posts: 3,623
    edited 2011-04-22 07:14
    You can't compare strings by using ==, try strcomp(addr1, addr2) instead. To be able to use this you should terminate your dir string with 0:
    dir byte "dir", 0
    
    and then use
    strcomp(@dir, @buffer{0})
    
    or (no DAT definition required)
    strcomp(string("dir"), @buffer{0})
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-04-22 07:23
    The code below works as expected when I type in 'dir', and 'help'. In the '==' compare I changed @buffer to 'buffer'. So, I am not sure why this program works, and what the difference is when using @buffer, and 'buffer' in this context? As soon as I figure that one out, then I can move on to a more complex program.

    Ray
    '' PropOS_C3.spin
    
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    
    STATUS_LED_BUS_MUX = 15
    
    PS2_DATA  = 26
    PS2_CLK   = 27
    
    ccnt = 32      '' Size of buffer[]
    
    VAR
    
    byte buffer[ccnt]
    long index
    
    OBJ
    
    
      vga        : "MikronautsVGA64.spin"   '' Program by William Henning
      kbd        : "keyboard_010.spin"
    
    
    PUB Main
    
    '' This is needed for the C3 init '''''
                                          '
      DIRA[STATUS_LED_BUS_MUX]:=1         '
      vga.start(16)                       '
    '''''''''''''''''''''''''''''''''''''''
    
      
      vga.cls    '' Clear the screen
    
      vga.str(string("Hello World"))
      
    
      kbd.start(PS2_DATA, PS2_CLK)
    
      kbd.clearkeys
      vga.out($0D)            '' Newline
      vga.out(">")            '' Special char
      
      repeat
        get_keystring
               
        vga.blink(100)
        
    
    PUB get_keystring | c{keypress}
    
      if (kbd.gotkey == TRUE)
         c:=kbd.key
         vga.out(c)
    
         if index < constant(ccnt-1)     '' This controls placement of char 
           buffer[index++]:=c            '' in the buffer array
    
      if c == $0D
        if ( help  == buffer )
          vga.str(string("Future 'Help' listing."))
          vga.out($0D)
        if ( dir == buffer )
          vga.str(string("Future 'DIR' listing."))
          vga.out($0D)  
        ''vga.str(string("Local Buffer: "))
        ''vga.str(@buffer{0})                '' This prints the buffer contents
        index~                             '' Reset the index
        bytefill(@buffer{0}, 0, ccnt)      '' This zeros out @buffer
    
       vga.out(">")
      
    
    DAT
    
    help byte "help"
    dir byte "dir" 
    
Sign In or Register to comment.