Page 1 of 3

PutChar & GetChar

Posted: Sun Dec 29, 2002 1:03 am
by Perica
..

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 4:15 am
by df
they are two totally unrelated things!

putchar is writing to the screeen, getchar is reading from the input stream, which has nothing to do with the screen, which needs a keyboard driver, irq interface, idt, etc

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 4:24 am
by Perica
..

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 5:07 am
by Ozguxxx
Hi Perica... This link should help you about putchar.
http://my.execpc.com/~geezer/osd/cons/index.htm
Good luck...

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 5:48 am
by Perica
..

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 5:50 am
by DarylD
Okay, you said you know you can put a single character with VideoMemory[MemoryAddress].

Using x and y in this is simple of course.

There are 80 characters across by 25 lines. Each character cell on screen is composed of an ascii character and attribute (which defines how it will look).

Each cell is linear in memory, i.e. top left is 0, going across and down through all screen positions until you hit the bottom right corner.

So it will just be a simple mathematical equation to calculate the position!

I do hope you can work that out for yourself though.

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 5:59 am
by Perica
..

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 6:26 am
by DarylD
Or if you wan't an equation that will be a touch faster

((y * 80)+x) << 1

Two less multiply's and a super fast bit shift.

Then again, maybe I should stop complicating things unnecessarily!

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 6:45 am
by Perica
..

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 6:55 am
by DarylD
You are hitting tricky stuff now.

The keyboard will trigger an interrupt (IRQ 1) when a key is either pressed or released.

For getchar, you will need to wait until this interrupt occurs.

If you are in protected mode, you will need an IDT setup.

Nobody on here can tell you how to code it, but we can give you pointers.

To recap:

You need an IDT
You need to write an ISR for IRQ 1
Your code will need to loop until some flag is set in the IRQ 1 ISR code you write.

Simple.

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 8:06 am
by Whatever5k
Of course, you can implement your getchar() function to wait for a keyboard interrupt and read from the appropriate port - but that's not a proper/clean solution - would be too easy ;)
Your keyboard handler (called on every keyboard interrupt) should get the scancode, map it to ASCII and put it in an array. Now if there is a user, it will make a system call READ from the terminal, and the terminal driver will look for the first entry in the array and return it to the user (depends if you are in cooked mode or not)...

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 9:06 am
by jrfritz
I have a well tested putch in FritzOS.

It works just like the regular C lib.

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 10:27 am
by Curufir
DarylD wrote: Or if you wan't an equation that will be a touch faster

((y * 80)+x) << 1

Two less multiply's and a super fast bit shift.

Then again, maybe I should stop complicating things unnecessarily!
((y<<6 + y<<4) + x) << 1

Why bother with a mul if you don't have to ;)

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 11:10 am
by df
Curufir wrote:
((y<<6 + y<<4) + x) << 1
Why bother with a mul if you don't have to ;)
when your not dealing with 80x25 :) say 132x44 or 132x25?

Re:PutChar & GetChar!

Posted: Sun Dec 29, 2002 11:14 am
by Curufir
df wrote:
Curufir wrote:
((y<<6 + y<<4) + x) << 1
Why bother with a mul if you don't have to ;)
when your not dealing with 80x25 :) say 132x44 or 132x25?
Doh! ;D