PutChar & GetChar
Re:PutChar & GetChar!
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
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 --
-
Ozguxxx
Re:PutChar & GetChar!
Hi Perica... This link should help you about putchar.
http://my.execpc.com/~geezer/osd/cons/index.htm
Good luck...
http://my.execpc.com/~geezer/osd/cons/index.htm
Good luck...
-
DarylD
Re:PutChar & GetChar!
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.
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.
-
DarylD
Re:PutChar & GetChar!
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 * 80)+x) << 1
Two less multiply's and a super fast bit shift.
Then again, maybe I should stop complicating things unnecessarily!
-
DarylD
Re:PutChar & GetChar!
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.
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!
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)...
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!
I have a well tested putch in FritzOS.
It works just like the regular C lib.
It works just like the regular C lib.
-
Curufir
Re:PutChar & GetChar!
((y<<6 + y<<4) + x) << 1DarylD 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!
Why bother with a mul if you don't have to
Re:PutChar & GetChar!
when your not dealing with 80x25Curufir wrote:
((y<<6 + y<<4) + x) << 1
Why bother with a mul if you don't have to![]()
-- Stu --
-
Curufir
Re:PutChar & GetChar!
Doh! ;Ddf wrote:when your not dealing with 80x25Curufir wrote:
((y<<6 + y<<4) + x) << 1
Why bother with a mul if you don't have to![]()
say 132x44 or 132x25?

