PutChar & GetChar

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

PutChar & GetChar

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:31 pm, edited 2 times in total.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:PutChar & GetChar!

Post 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
-- Stu --
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:PutChar & GetChar!

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:32 pm, edited 1 time in total.
Ozguxxx

Re:PutChar & GetChar!

Post by Ozguxxx »

Hi Perica... This link should help you about putchar.
http://my.execpc.com/~geezer/osd/cons/index.htm
Good luck...
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:PutChar & GetChar!

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:32 pm, edited 1 time in total.
DarylD

Re:PutChar & GetChar!

Post 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.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:PutChar & GetChar!

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:32 pm, edited 1 time in total.
DarylD

Re:PutChar & GetChar!

Post 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!
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:PutChar & GetChar!

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:32 pm, edited 1 time in total.
DarylD

Re:PutChar & GetChar!

Post 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.
Whatever5k

Re:PutChar & GetChar!

Post 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)...
jrfritz

Re:PutChar & GetChar!

Post by jrfritz »

I have a well tested putch in FritzOS.

It works just like the regular C lib.
Curufir

Re:PutChar & GetChar!

Post 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 ;)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:PutChar & GetChar!

Post 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?
-- Stu --
Curufir

Re:PutChar & GetChar!

Post 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
Post Reply