if ( help == buffer ) is the same as:
if help[0] == buffer[0]
so you compare the first character of the "strings" (they are not valid strings without an ending zero). As long as each command has a different first letter this works accidentally.
You really need to follow the suggestions of Kuroneko. A string library from the OBEX may also help.
I set this up to use the strcomp, but it is not working for me, and I do not see what the problem is. When I type in 'help', 'dir', or 'cls' the program does not respond to the command. The key is, that when I hit enter, I want it to check the buffer, and respond accordingly. I would like somebody else to look at this, and tell me what I am missing.
Thanks
Ray
'' PropOS_C3.spin
'' Version 0.0.1
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("This is the PropOS_C3 program!"))
vga.out($0D)
vga.str(string("Type 'help' for help!"))
kbd.start(PS2_DATA, PS2_CLK)
kbd.clearkeys
vga.out($0D) '' Newline
vga.out(">") '' Special char
repeat
get_keystring '' The command line interface
vga.blink(100)
PUB get_keystring | c
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 '' Newline
if strcomp(@help,@buffer{0})
vga.str(string(" Help"))
vga.out($0D)
vga.str(string("dir - Directory Listing"))
vga.out($0D)
vga.str(string("cls - Clear the screen"))
vga.out($0D)
if strcomp(@dir, @buffer{0}) '' dir
vga.str(string("Future 'DIR' listing."))
vga.out($0D)
if strcomp( @cls, @buffer{0} ) '' cls
vga.cls
vga.gotoxy(0,0)
''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.str(string("No such command"))
vga.out($0D)
vga.out(">")
DAT
help byte "help",0
dir byte "dir",0
cls byte "cls",0
The zip file below contains, what I am referring to as version 0.0.1. It responds to three commands: help, dir, and cls. I just added the dir command for the heck of it, I am not sure if I am ready to tackle the SD stuff, just yet. I could not get "No such command" to work correctly, so I will have to give it some more thought. Maybe I should try adding some color to CLI, not sure if color is implemented in the VGA64 driver. I am open for reasonable suggestions as to what PropOS_C3 should contain.
Back to version 0.0.1, this time using the new VGA80 driver(s). In the VGA80 driver I have tested out the new functions that are in there, so far they work. The program is just a test of keyboard/VGA screen functionality, so it's just a simple program. So far the VGA80 driver(s) are holding up, no problems.
Attached is version 0.0.2, added some more functions to VGA80 driver(s). Added a few "commands" to the program, it all seems to behave as expected. This is using a 6.25MHz crystal, so it probably will not work on a different setup.
I can't seem to find a good source for the keyboard key codes, especially the function keys (F1 - F12), Ctrl, and Alt. I found some key codes, but they do not seem to work. In the C3 source I found the code for the Esc key, and some others, but none of the function keys. I have a chart that lists, for example, the F1 as $3B, but that does not work. So I am at loss here.
Attached below is version 0.0.3. This version I have implemented a concept of a very crude version of an editor. Basically you type some stuff in, and then you use the '@' to display the contents of the buffer. The next step is to create a name for the file, and store the file. For this concept I will be using the upper part of the EEPROM. Has anybody created an EEPROM disk? I will be referring to this as dira, and the SD will be referred to as dirc. Now comes the hard part, getting the name of the file to EEPROM, storing the file to EEPROM, and then being able to access the file, by name, off of the EEPROM.
As for the keyboard key codes, I think the keyboard driver sets the keyboard up as an XT model, meaning no function keys, keypad, or other special keys. I guess I need a keyboard expert to figure this one out.
You find all keycodes described at the end of the Keyboard object source code.
Generally the documentation of an object is integrated in the source with special comments. If you click on "Documentation" in the PropellerTool under the Tabs, you get this description comments extracted as an own file.
I created a quick and dirty utility program for obtaining the keycodes. The program below, you just press a key on the keyboard, and the program will display the decimal and hex codes. This resolves my issue with finding the keycodes. Of course this is for a C3 setup.
I decided to create the editor as a stand alone object, which is pedit.spin. Hopefully I will be able to call it from within the PropOS program, and have it function the way I want to.
Pedit .spin is a concept program, so it lacks a lot of stuff. I have not provided a way of naming and storing the file, so for the time being, all it does is capture the input, and at quit time displays what is in the buffer before it quits.
The program is still not complicated, code wise, so I think the beginners can still pretty much follow as to what is going on. That is why I am posting it.
Some prelim concerns:
I still cannot get the backspace to work correctly, as it concerns the buffer, some guidance would be appreciated.
When the buffer gets dumped, it is not displaying within pedit framework.
Next I will be implementing the SD portion , so I can start working on naming and storing the file.
Comments
You really need to follow the suggestions of Kuroneko. A string library from the OBEX may also help.
Andy
Thanks
Ray
Either you add the $0D also at he end of the keywords: or you delete the $0D character before comparing starts: And you need to indent the whole "if c == $0D " block, so that the test is only done when you got a key.
Andy
Edit: You know that all these {0} statements are only comments?
The zip file below contains, what I am referring to as version 0.0.1. It responds to three commands: help, dir, and cls. I just added the dir command for the heck of it, I am not sure if I am ready to tackle the SD stuff, just yet. I could not get "No such command" to work correctly, so I will have to give it some more thought. Maybe I should try adding some color to CLI, not sure if color is implemented in the VGA64 driver. I am open for reasonable suggestions as to what PropOS_C3 should contain.
Thanks
Ray
Ray
Ray
Thanks
Ray
As for the keyboard key codes, I think the keyboard driver sets the keyboard up as an XT model, meaning no function keys, keypad, or other special keys. I guess I need a keyboard expert to figure this one out.
Ray
You find all keycodes described at the end of the Keyboard object source code.
Generally the documentation of an object is integrated in the source with special comments. If you click on "Documentation" in the PropellerTool under the Tabs, you get this description comments extracted as an own file.
Andy
Ray
Pedit .spin is a concept program, so it lacks a lot of stuff. I have not provided a way of naming and storing the file, so for the time being, all it does is capture the input, and at quit time displays what is in the buffer before it quits.
The program is still not complicated, code wise, so I think the beginners can still pretty much follow as to what is going on. That is why I am posting it.
Some prelim concerns:
I still cannot get the backspace to work correctly, as it concerns the buffer, some guidance would be appreciated.
When the buffer gets dumped, it is not displaying within pedit framework.
Next I will be implementing the SD portion , so I can start working on naming and storing the file.
Ray