flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Keyboard Input

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
I'm making a bootloader-ish program and need to know how to get keyboard input without int 21h.
Post 28 Nov 2009, 22:09
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
easy:
there are many examples on the board.

the simpler way is to poll the port60h
but is limited.
the best is to write a IRQ1 handler.
you can search a little on the forum, you will find.
Post 28 Nov 2009, 22:12
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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 Razz. 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]
Post 28 Nov 2009, 22:25
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
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
    
Post 29 Nov 2009, 03:02
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
Dex4u wrote:
Code:
   cmp   al,0x1c     ;scan code foe enter
    

I was just about to ask that. Very Happy
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?
Post 29 Nov 2009, 05:35
View user's profile Send private message Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman
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
Post 29 Nov 2009, 08:37
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
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?
Post 29 Nov 2009, 12:14
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
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.
Post 29 Nov 2009, 13:36
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
bitshifter wrote:

16bit
Code:
get_string:
pusha
mov di,str_array
@@:
call get_char_w_echo
stosb
jmp @b
popa
retn    

That's exactly what I wanted to do, thanks! Very Happy
btw I'm getting dangerously close to my second sector, so how do I go about loading the rest of my code?
Post 29 Nov 2009, 14:13
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
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 ( Wink ) to get the whole picture.
Post 29 Nov 2009, 14:54
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
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?
Post 29 Nov 2009, 17:39
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
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. Rolling Eyes


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.
Post 29 Nov 2009, 19:17
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
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...
Post 29 Nov 2009, 20:40
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
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.


Description:
Download
Filename: OS Calculator.ASM
Filesize: 1.28 KB
Downloaded: 74 Time(s)

Post 29 Nov 2009, 22:20
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
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.
Post 29 Nov 2009, 23:06
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
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...
Post 30 Nov 2009, 00:07
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
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/
Post 30 Nov 2009, 17:51
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
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. Smile
Post 01 Dec 2009, 01:27
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
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 Smile.
Post 03 Dec 2009, 06:18
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
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)
Post 31 Dec 2009, 03:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.