Hi. I'm trying to figure out how to read what character is at a specific position and I'm not having much luck. I know how to get to the position but don't know how to read the character.

For example, lets say I printed 'abcdefg' on the first row. And, 'hijklmn' on the second. :

    0  1  2  3  4  5  6 7 8 9 <- Column
0  a  b  c  d  e  f  g
1  h  i  j  k  l  m  n


Now, I want to find how what character is at position (r0, c3). How would I go about doing this?

Sorry is this was confusing, not very good at explaining things. :)

Thank you,

- Steve
Posted on 2006-04-08 23:08:31 by ~Steve~
What methods are you using to "get" to the character???

You can read straight from video memory if you wish. This would require reading one WORD (16 bits/2 bytes) at a time. VGA video console is mapped into address 0x000B8000. The typical console mode is 80x25, so basically you would do some calculation like... Offset = (Column*80 + Row)*2

Where 80 is the length of one row of characters and 2 is the size of one display character in bytes (one byte for attribute, one byte for ASCII). With that you would do something like...

;NASM Example
;-Offset is in EBX
;-Intel is Little Endian so ignore loading the whole WORD
mov al,BYTE

The above code will help you retrieve the ASCII character at said offset. Hope this helps :)
Posted on 2006-04-08 23:24:43 by SpooK
Thanks for the quick reply. :)

I'm using HLA so it's a function that sets cursor position. (SetConsoleCursorPosition in API) There's no HLA function to read the character so I'll use the information you gave me. (Or not that I know of.)

Thank you,

- Steve
Posted on 2006-04-08 23:35:12 by ~Steve~
I'm not too up on the inner workings of HLA, but "SetConsoleCursorPosition" seems like an abstraction for setting the related video cursor ports (I/O ports 0x0E and 0x0F comprise of the total cursor address/position). Reading/Writing from/to video memory (or a command buffer) is a different process altogether, which you should be able to do based on the example above. Good luck.
Posted on 2006-04-09 00:08:41 by SpooK
Input Params :
                  Int = 21h
                  AH = 08h
                  BH = Display Page

Outputs :
                  AL = The read character
                  AH = The read character's attribute
Posted on 2006-04-10 23:59:14 by XCHG

Input Params :
                  Int = 21h
                  AH = 08h
                  BH = Display Page

Outputs :
                  AL = The read character
                  AH = The read character's attribute

... or you could use the BIOS :lol:

Your best bet is to invest in what XCHG just posted since even in DOS, direct access to memory can be messy to deal with. Ignore my OSDev-like mindset :)
Posted on 2006-04-11 00:13:25 by SpooK
Uh, it's INT 10h, my bad.

Here is an example i wrote for you
Hope it helps

Posted on 2006-04-12 22:18:08 by XCHG
Just an FYI, INT 10 is BIOS (should work on any computer running Real Mode or VM86), INT 21 is DOS specific.
Posted on 2006-04-12 22:20:06 by SpooK
Well, try this:
mov ax,0b800h
mov es,ax
mov di,0
mov ax,row
xor dx,dx
mov ecx,160
mul cx
add di,ax
add di,clm ; <- clm you want to get to.
add di,clm

mov al,es:

Posted on 2006-04-12 23:36:25 by Zcoder
SetConsoleCursorPosition is a WIN32 API call, and HLA probably has a wrapper for it. So, I'm deducing you're using HLA to do 32bit windows console mode programming. DOS/BIOS calls and direct memory access will not work on that platform.

So, what you will want is a WIN32 Console API call. Start by opening up MSDN, use SetConsoleCursorPosition as an entry point. If using the online MSDN, you will now see a list of all console related APIs to the left.

ReadConsoleOutput and ReadConsoleOutputCharacter sound interesting, don't they? :)
Posted on 2006-04-13 06:07:33 by f0dder