flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Keyboard Input Goto page 1, 2 Next |
Author |
|
Tyler 28 Nov 2009, 22:09
I'm making a bootloader-ish program and need to know how to get keyboard input without int 21h.
|
|||
28 Nov 2009, 22:09 |
|
LocoDelAssembly 28 Nov 2009, 22:25
http://www.ctyme.com/intr/int-16.htm
Int 16/AH=00h and maybe Int 16/AH=01h are the ones you may want. You could also do what edfed says, but if you don't plan switching to protected mode or taking control over interrupts I think you are better off just using Int 16h. [edit]If looking for a minimal boot code check http://board.flatassembler.net/topic.php?p=86707#86707 . Perhaps not the best you can find in this forum but is the only one that comes to my mind now . The xor ax, ax/int $16 in the code is a call to Int16/AH=0 and what is doing is waiting for keyboard input to pause execution before calling the bootstrap loader (Int19h)[/edit] |
|||
28 Nov 2009, 22:25 |
|
Dex4u 29 Nov 2009, 03:02
The simplest direct way is use 60h ( as pointed to by edfed ) and the scan codes like this
Code: ;********************************* ; Main keyboard loop. ;********************************* NoKey: xor eax,eax in al,60h cmp al,0x50 ; scan code for down arrow je DownArrowPressed cmp al,0x48 ;scan code for up arrow je UpArrowPressed cmp al,0x1c ;scan code foe enter je EnterPressed jmp NoKey DownArrowPressed: ; some code here UpArrowPressed: ;some code here EnterPressed: ;code here |
|||
29 Nov 2009, 03:02 |
|
Tyler 29 Nov 2009, 05:35
Dex4u wrote:
I was just about to ask that. That, and how to scan for delete because it also doesn't cause the desired effect(deleting). Also, is there a way to get input(when inputting 1-9) as the actual numbers(not their ascii)? And I guess the logical companion to inputting numbers direct is outputting them, so is that possible? |
|||
29 Nov 2009, 05:35 |
|
roboman 29 Nov 2009, 08:37
If al = an ascii number
sub al, '0' you now have a number in al that is 0-9 To go the other way: add al, '0' If you want to do more then one digit check out http://home.comcast.net/~dexos/FBasDx01.zip You'll have to dig around a bit, but the input statement will convert a multi digit ascii number and the print will display a number in base 10 ascii |
|||
29 Nov 2009, 08:37 |
|
Tyler 29 Nov 2009, 12:14
This is what I got so far(unrelated stuff omitted), I got my keyboard functions working(get_chr_w_echo) but what I need to do now is store the individual chars in an array. I'm assuming "str_array rb 100" = "str_array[100]."
Code: get_string: pusha sub dx, dx @@: call get_char_w_echo mov byte [str_array + dx], al ;char is stored in al inc dx jmp @b popa retn It doesn't work because dx is a reserved word, is there a way around this? |
|||
29 Nov 2009, 12:14 |
|
bitshifter 29 Nov 2009, 13:36
32bit
Code: get_string: pusha sub edx, edx @@: call get_char_w_echo mov byte [str_array + edx], al ;char is stored in al inc edx jmp @b popa retn 16bit Code: get_string: pusha mov di,str_array @@: call get_char_w_echo stosb jmp @b popa retn Are you in 16 or 32 bit land? _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
29 Nov 2009, 13:36 |
|
Tyler 29 Nov 2009, 14:13
bitshifter wrote:
That's exactly what I wanted to do, thanks! btw I'm getting dangerously close to my second sector, so how do I go about loading the rest of my code? |
|||
29 Nov 2009, 14:13 |
|
ManOfSteel 29 Nov 2009, 14:54
In your boot sector you load sector 2 using the BIOS. E.g.:
Code: mov ax,second_stage_address mov es,ax xor bx,bx mov ah,2 ; function mov al,1 ; second stage = 1 sector xor ch,ch ; track 0 mov cl,2 ; sector 2 mov dh,0 ; head 0 mov dl,the_drive_being_read int 0x13 And you put your get_string in that second stage. Check another code by bitshifter ( ) to get the whole picture. |
|||
29 Nov 2009, 14:54 |
|
Tyler 29 Nov 2009, 17:39
Yeah, I looked at bitshifter's, it kinda scared me to think I was going to have to do all that. It is really complex lookin'. I don't really know enough yet to say it's good though(not that I'm saying it's not). After I've loaded the second sector can I still use "functions" that are in the boot sector? Or does that question itself say that I am not making correct use of the boot sector?
|
|||
29 Nov 2009, 17:39 |
|
ManOfSteel 29 Nov 2009, 19:17
Tyler wrote: it kinda scared me to think I was going to have to do all that. It is really complex lookin' OK, I'll reassure you. It may look scary at first, but it's not all that complex when you study it bit by bit. Plus, what awaits you *after* this is way more complex. Hmm, didn't really come out as planned. Tyler wrote: After I've loaded the second sector can I still use "functions" that are in the boot sector Set your own interrupts up in the boot sector. Or better, don't do anything in the boot sector other than loading more sectors. In the second stage set the interrupts up. Of course, move get_string to the second stage. Interrupt example: Code: ; set "int 0x20" up push es xor ax,ax mov es,ax cli mov [es:0x20*4],int20 mov [es:0x20*4+2],cs sti pop es [...] ; "int 0x20" handler int20: cmp ah,1 je get_string cmp ah,2 je func2 cmp ah,3 je func3 [...] ; one of "int 0x20" functions get_string: [your code] iret [...] ; use get_string function mov ah,1 int 0x20 I can't test it right now, but it should work. Read about the Interrupt Vector Table. |
|||
29 Nov 2009, 19:17 |
|
bitshifter 29 Nov 2009, 20:40
LOL
Yep, the further you look, the more scary it gets. But once you identify with something it is not scary anymore. Then you go look deeper for more scary stuff to learn. This is the life of a programmer... |
|||
29 Nov 2009, 20:40 |
|
Tyler 29 Nov 2009, 22:20
I guess since yall basically gave me all the answers I needed to get as far as I have(not far) I might as well show you what I'm doing.
It's a Calculator that can be booted, all I got left to do is to parse the string from "get_string." and make the backspace erase the char in "str_array." I only have one problem, when "get_string" gets a backspace it turns it into a weird character I've never seen before. Before you judge, keep in mind I'm 15 and have been learning asm for about a week.
|
|||||||||||
29 Nov 2009, 22:20 |
|
ManOfSteel 29 Nov 2009, 23:06
Tyler wrote: I only have one problem, when "get_string" gets a backspace it turns it into a weird character I've never seen before. That weird char you're seeing is most probably backspace itself. You remember Dex's example? Right after using the input instruction it compares scancodes. When you get a backspace ( 0xe ), move the cursor back one char (int 0x10, func 2) and write a space (int 0x10, func 9). That'll do. |
|||
29 Nov 2009, 23:06 |
|
Tyler 30 Nov 2009, 00:07
Yeah, I had already made a function to do that, I just didn't use it in the right place. I've started on the parsing part now, is it reasonable to concatenate strings in asm (to get the #s in order counting them while concatenating)x=# y=count(y decrements every time) x*10^y + x*10^y...
|
|||
30 Nov 2009, 00:07 |
|
Dex4u 30 Nov 2009, 17:51
Take a look at MiniDos or MikeOS for examples of how to code such things
http://board.flatassembler.net/topic.php?t=5275 http://mikeos.berlios.de/ |
|||
30 Nov 2009, 17:51 |
|
Tyler 01 Dec 2009, 01:27
Thanks.
I dled the one from the first post, did you write all that? That's awesome. I've also learned from your organization, I've since split my project into 4 files to make it more readable. |
|||
01 Dec 2009, 01:27 |
|
Dex4u 03 Dec 2009, 06:18
Thanks, yes i written all of it in about week, i was hoping someone would take it on as a project to add more int 21h to make it more Dos compatable.
I even have a fasm port that runs on it somewhere . |
|||
03 Dec 2009, 06:18 |
|
edfed 31 Dec 2009, 03:56
what about a multikeyboard driver?
something like 4 or 8 kb of asm code, easy useable in any code Code:
include 'keyboard.inc'
...
call new_int9
...
, but with a particularity, have a very large set of ascii codes, and fashioned for hobby code using asm (and other languages?). something like a multi shift lock, using F1 to F4 as a virtual shift combinaison for a multitude of keymaps or charsets. and maybe a little utility to show the keyboard setup.(inside the 4 or 8 kb) |
|||
31 Dec 2009, 03:56 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.