Input Characters

Thread Solved

Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Input Characters

 
0
  #1
Aug 24th, 2009
Hello,
I'm beginning in the OS development(In Assembly, Nasm as Assembler) and i need to implement a command-line on it, but i don't know how to do this, but what i want to say as command-line is like MS-DOS or UNIX:
  1. > ver
  2. BerlOS v.0.0.1
  3. > _
But i don't know how to do the input method(ver in the command). In the repetition of the > before the user input things i know, i only need to do a JMP to the section that prints the > and the input method, if it's needed, here is my code:
  1. [BITS 16] ; 16 bit code generation
  2. [ORG 0x7C00] ; ORGin location is 7C00
  3.  
  4. JMP short main ; Jump past disk description section
  5. NOP ; Pad out before disk description
  6.  
  7. ; ------------------------------------------------------------------
  8. ; Disk description table, to make it a valid floppy
  9. ; Note: some of these values are hard-coded in the source!
  10. ; Values are those used by IBM for 1.44 MB, 3.5" diskette
  11.  
  12. OEMLabel db "BERL OS" ; Disk label - 8 chars
  13. BytesPerSector dw 512 ; Bytes per sector
  14. SectorsPerCluster db 1 ; Sectors per cluster
  15. ReservedForBoot dw 1 ; Reserved sectors for boot record
  16. NumberOfFats db 2 ; Number of copies of the FAT
  17. RootDirEntries dw 224 ; Number of entries in root dir
  18. LogicalSectors dw 2880 ; Number of logical sectors
  19. MediumByte db 0F0h ; Medium descriptor byte
  20. SectorsPerFat dw 9 ; Sectors per FAT
  21. SectorsPerTrack dw 18 ; Sectors per track (36/cylinder)
  22. Sides dw 2 ; Number of sides/heads
  23. HiddenSectors dd 0 ; Number of hidden sectors
  24. LargeSectors dd 0 ; Number of LBA sectors
  25. DriveNo dw 0 ; Drive No: 0
  26. Signature db 41 ; Drive signature: 41 for floppy
  27. VolumeID dd 00000000h ; Volume ID: any number
  28. VolumeLabel db "BERL OS" ; Volume Label: any 11 chars
  29. FileSystem db "FAT12" ; File system type: don't change!
  30.  
  31. ; End of the disk description table
  32. ; ------------------------------------------------------------------
  33.  
  34. main:
  35. MOV BX, 0 ; Disable blinking.
  36. MOV BH, 00h
  37. MOV BL, 07h ; Color settings
  38. MOV AL, 1
  39. MOV BH, 0
  40. MOV BL, 02h
  41. MOV CX, osmsgend - os_msg ; Calculate message size.
  42. MOV DL, 30
  43. MOV DH, 0
  44. PUSH CS
  45. POP ES
  46. MOV BP, os_msg
  47. MOV AH, 13h
  48. INT 10h
  49. JMP wel
  50.  
  51. wel:
  52. MOV BH, 00h
  53. MOV BL, 07h
  54. MOV AL, 1
  55. MOV BH, 0
  56. MOV BL, 059
  57. MOV CX, welcome_end - welcome ; Calculate message size.
  58. MOV DL, 32
  59. MOV DH, 2
  60. PUSH CS
  61. POP ES
  62. MOV BP, welcome
  63. MOV AH, 13h
  64. INT 10h
  65. JMP osmsgend
  66.  
  67. welcome DB "Welcome !"
  68. welcome_end:
  69.  
  70. os_msg DB "BerlOS v0.0.1"
  71. osmsgend:
  72. JMP $
  73.  
  74. ; Boot things
  75. TIMES 510-($-$$) DB 0 ; Fill the rest of the sector with zeros
  76. DW 0xAA55 ; Boot signature
The only thing that i need too know how to do is the input characters method.

Thanks,
Nathan Paulino Campos
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Input Characters

 
0
  #2
Aug 25th, 2009
You're using the 0x10 VIDEO BIOS services handler for your video handling so use the 0x16 KEYBOARD BIOS services handler for your keyboard handling!

  1. ; Get Keyboard value (and wait for press)
  2. mov ah,0
  3. int 16h ; KEYBOARD
  4. ;ah=scan code al=ASCII character
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Re: Input Characters

 
0
  #3
Aug 25th, 2009
Hello wildgoose,
Thanks for your help, now i know that INT 16h is for keyboard, but if i want to improve like, the user types: ver , then when he press enter the OS shows a message, like: ver DB "ver. 0.0.1" .

Thanks,
Nathan Paulino Campos
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Input Characters

 
0
  #4
Aug 25th, 2009
After data entry, remove carriage return and set a terminator!

Create a master list of commands! A table lookup of string addresses and scan through the list one at a time and do a caseless string to data entered. When you find a caseless match you have your command. Then jump to the code to handle that command!

You could use a structure table that contains the pointer to the string, and address of the function.


Initially just write a string compare function and do a series of if-then's to find your matching string!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Re: Input Characters

 
0
  #5
Aug 25th, 2009
But how i can do this?
Sorry about this simple questions, but i'm learning Assembly for OS's.

Thanks for you attention!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Input Characters

 
0
  #6
Aug 25th, 2009
One step at a time

  1. xVer db 'Ver',0
  2. Key db dup(128)
  3. Kscan db dup(128)
  4.  
  5.  
  6. xor bx,bx
  7.  
  8. KeyIn:
  9. mov ah,0
  10. int 16h ; KEYBOARD
  11. ;ah=scan code al=ASCII character
  12.  
  13. mov Key[ bx ],al
  14. mov KScan[ bx ],ah
  15. inc bx
  16. cmp al,0dh ; Carriage return
  17. jne KeyIn
  18.  
  19. ; bx = buffer Length
  20. mov Key[ bx - 1 ],0 ; Overwrite with terminator
  21.  
  22. ; String now in buffer

Visually inspect buffer to make sure the string is there intact!

Then work on a string compare function
  1. mov ax,offset KeyBuf
  2. mov dx,offset xVer
  3. call StrICmp
  4. jnc next
  5.  
  6. ;;; Have a match!
  7. jmp done
  8.  
  9. next:
  10.  
  11. done:
Last edited by wildgoose; Aug 25th, 2009 at 3:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Re: Input Characters

 
0
  #7
Aug 25th, 2009
Ok, i'm going to try, any thing i will post, but i know that i will not have problems, thanks!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Re: Input Characters

 
0
  #8
Aug 25th, 2009
Hello wildgoose,
Now i'm getting this errors:
http://img253.imageshack.us/img253/3381/errorb.png
Why?

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 179
Reputation: Nathan Campos is an unknown quantity at this point 
Solved Threads: 6
Nathan Campos's Avatar
Nathan Campos Nathan Campos is offline Offline
Junior Poster

Re: Input Characters

 
0
  #9
Aug 25th, 2009
If it's needed, here is the code:
  1. [BITS 16] ; 16 bit code generation
  2. [ORG 0x7C00] ; ORGin location is 7C00
  3.  
  4. JMP short main ; Jump past disk description section
  5. NOP ; Pad out before disk description
  6.  
  7. ; ------------------------------------------------------------------
  8. ; Disk description table, to make it a valid floppy
  9. ; Note: some of these values are hard-coded in the source!
  10. ; Values are those used by IBM for 1.44 MB, 3.5" diskette
  11.  
  12. OEMLabel db "BERL OS" ; Disk label - 8 chars
  13. BytesPerSector dw 512 ; Bytes per sector
  14. SectorsPerCluster db 1 ; Sectors per cluster
  15. ReservedForBoot dw 1 ; Reserved sectors for boot record
  16. NumberOfFats db 2 ; Number of copies of the FAT
  17. RootDirEntries dw 224 ; Number of entries in root dir
  18. LogicalSectors dw 2880 ; Number of logical sectors
  19. MediumByte db 0F0h ; Medium descriptor byte
  20. SectorsPerFat dw 9 ; Sectors per FAT
  21. SectorsPerTrack dw 18 ; Sectors per track (36/cylinder)
  22. Sides dw 2 ; Number of sides/heads
  23. HiddenSectors dd 0 ; Number of hidden sectors
  24. LargeSectors dd 0 ; Number of LBA sectors
  25. DriveNo dw 0 ; Drive No: 0
  26. Signature db 41 ; Drive signature: 41 for floppy
  27. VolumeID dd 00000000h ; Volume ID: any number
  28. VolumeLabel db "BERL OS" ; Volume Label: any 11 chars
  29. FileSystem db "FAT12" ; File system type: don't change!
  30.  
  31. ; End of the disk description table
  32. ; ------------------------------------------------------------------
  33.  
  34. main:
  35. MOV BX, 0 ; Disable blinking.
  36. MOV BH, 00h
  37. MOV BL, 07h ; Color settings
  38. MOV AL, 1
  39. MOV BH, 0
  40. MOV BL, 02h
  41. MOV CX, osmsgend - os_msg ; Calculate message size.
  42. MOV DL, 30
  43. MOV DH, 0
  44. PUSH CS
  45. POP ES
  46. MOV BP, os_msg
  47. MOV AH, 13h
  48. INT 10h
  49. JMP wel
  50.  
  51. wel:
  52. MOV BH, 00h
  53. MOV BL, 07h
  54. MOV AL, 1
  55. MOV BH, 0
  56. MOV BL, 059
  57. MOV CX, welcome_end - welcome ; Calculate message size.
  58. MOV DL, 32
  59. MOV DH, 2
  60. PUSH CS
  61. POP ES
  62. MOV BP, welcome
  63. MOV AH, 13h
  64. INT 10h
  65. JMP KeyIn
  66.  
  67. ; ------------------------------------------
  68. ; Keyboard input method
  69. xVer db 'Ver', 0
  70. Key db dup(128)
  71. Kscan db dup(128)
  72.  
  73.  
  74. xor bx,bx
  75.  
  76. KeyIn:
  77. mov ah,0
  78. int 16h ; KEYBOARD
  79. ;ah=scan code al=ASCII character
  80.  
  81. mov Key[ bx ],al
  82. mov KScan[ bx ],ah
  83. inc bx
  84. cmp al,0dh ; Carriage return
  85. jne KeyIn
  86.  
  87. ; bx = buffer Length
  88. mov Key[ bx - 1 ],0 ; Overwrite with terminator
  89.  
  90. ; String now in buffer
  91. mov ax,offset KeyBuf
  92. mov dx,offset xVer
  93. call StrICmp
  94. JMP osmsgend
  95.  
  96. ; End of input characters method
  97. ; ------------------------------------------
  98.  
  99.  
  100. welcome DB "Welcome !"
  101. welcome_end:
  102.  
  103. os_msg DB "BerlOS v0.0.1"
  104. osmsgend:
  105. JMP $
  106.  
  107. ; Boot things
  108. TIMES 510-($-$$) DB 0 ; Fill the rest of the sector with zeros
  109. DW 0xAA55 ; Boot signature

Thanks!
Last edited by Nathan Campos; Aug 25th, 2009 at 5:19 pm. Reason: ...
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Input Characters

 
0
  #10
Aug 26th, 2009
Look at the line number that contains the error and look for things.


Line#35
You may need the label on the same line as instruction. Some assemblers require this, some don't!

main: MOV BX, 0 ; Disable blinking.

Line#70 and #71
;Key db dup(128)
;Kscan db dup(128)
Key db 128 dup(?)
Kscan db 128 dup(?)

Line#81,82 should then be fixed.

Line#88 mov byte ptr Key[ bx - 1 ],0 ; Overwrite with
terminator

Wrong label name
mov ax,offset Key

Don't know about 92
mov dx,offset xVer
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC