ascii code provided in the book doesn't match the wiki page

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ascii code provided in the book doesn't match the wiki page

social_loser
the ascii codes of   "newline", "backspace" and "double quote" provided in the book are  128, 129 , and 34, however it didn't match any thing I searched on the net. according to wikipedia , the codes should be  10 , 8 , and 34.

maybe this issue doesn't affect anything, but I want to make a note here.
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

cadet1620
Administrator
You are correct, the keyboard codes for the special keys are not ASCII.

    Key pressed   Code    Key pressed   Code

    newline       128     end           135
    backspace     129     page up       136
    left arrow    130     page down     137
    up arrow      131     insert        138
    right arrow   132     delete        139
    down arrow    133     esc           140
    home          134     f1–f12        141–152

Figure 4.6 Special keyboard codes in the Hack platform.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

Sai krishna
This post was updated on .
I have some doubts regarding the implementation of the Keyboard.readChar():
1) Should these characters also echo their effect on the screen?(Does echo mean printing the characters?)
     * new line = 128 = String.newline()
     * backspace = 129 = String.backspace()
     * left arrow = 130
     * up arrow = 131
     * right arrow = 132
     * down arrow = 133
     * home = 134
     * End = 135
     * page up = 136
     * page down = 137
     * insert = 138
     * delete = 139
     * ESC = 140
     * F1 - F12 = 141 - 152
If so, what should those characters from 134 do?
2) How to display cursor? I am trying to use printChar(0) since that prints a black square but using printchar() also advances the cursor by one position. How to do withh this?
3) And why is a String.backspace() and String.newline() function there in the String class? Why use it if we have its character code?
Please reply
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

WBahn
Administrator
Except as specified, there is no requirement that pressing those keys do anything -- which means you can have them behave any way you want.

How does having a code for backspace relieve you of the need to have the backspace() function? What would you do just knowing that the current contents of the keyboard buffer is 129? If you didn't need the backspace() function, wouldn't the same reasoning apply to code 128 meaning that you don't need the newline() function?

In Jack, your string literals can't contain escape characters, so you can't embed things like newlines, tabs, or backspaces.
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

Sai krishna
I am extremely sorry for posting the same question over and over. I just needed to get the answer immediately.

How to display the cursor in Keyboard class? (which I have asked in my post)

Also I asked the need for having backspace and newline functions in String class (not the Output class) where they just return their character codes only but not perform that action?
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

WBahn
Administrator
Is there any compelling need for a visible cursor?

Isn't the cursor always at the end of the last line on the screen?

Where you would need a visible cursor would be if you had the ability to move the cursor around to different places on the screen independent of the text on the screen. There's no requirement for that capability. If you move the cursor back with the backspace key, it erases the character that was there.

If you really want a cursor, then just print something at the cursor's location every time you move the cursor (being sure to erase it before you move it). So when someone types a character, you erase the cursor at the original location, print the character at the original location, move the cursor to the new location, print the cursor at the new location.

Don't try to get a blinking cursor. Remember, the Hack has no concept of time or any form of interrupts. So the best you can do would be to have a unique-looking character represent the cursor (and many embedded systems have done exactly this over the years).
Reply | Threaded
Open this post in threaded view
|

Re: ascii code provided in the book doesn't match the wiki page

Sai krishna
Ok. Got it. Thank you for your kind response