This is a discussion on How can I access memory in C? within the C and C++ Programming forums, part of the Software Development category; How can I access memory (a memory-mapped device, or graphics memory) located at a certain address? How can I ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| How can I access memory (a memory-mapped device, or graphics memory) located at a certain address? How can I do PEEK and POKE in C?
__________________ Thanks & Regards Sabari... |
| Sponsored Links |
| |||
| hi, Set a pointer, of the appropriate type, to the right number (using an explicit cast to assure the compiler that you really do intend this nonportable conversion): unsigned int *magicloc = (unsigned int *)0x12345678; Then, *magicloc refers to the location you want. [footnote] If the location is a memory-mapped I/O register, you will probably also want to use the volatile qualifier: ``volatile unsigned int *magicloc''. (If you want to refer to a byte at a certain address rather than a word, use unsigned char *.) Under MS-DOS, you may find a macro like MK_FP() handy for working with segments and offsets. As suggested by Gary Blaine, you can also declare tricky array pointers which allow you to access screen memory using array notation. For example, on an MS-DOS machine in an 80x25 text mode, given the declaration unsigned short (far * videomem)[80] = (unsigned short (far *)[80])0xb8000000; you can access the character and attribute byte at row i, column j with videomem[i][j]. Many operating systems execute user-mode programs in a protected mode where direct access to I/O devices (or to any address outside the running process) is simply not possible. In such cases you will have to ask the operating system to carry out I/O operations for you. PEEK and POKE POKE and PEEK are memory write and read statments USING in C ----------WAY 1------------ SCREEN 13 DEF SEG = &HA000 'then to plot a pixel with coordinates of x and y and color c POKE (y * 320 + x), c 'to read a pixel you c = PEEK(y * 320 + x) 'then c will be the color of that pixel Thanks, Prasath.K Last edited by prasath : 07-17-2007 at 03:51 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Efficient memory allocation | vigneshgets | Operating Systems | 1 | 08-18-2007 12:18 AM |
| Memory alignment | prasath | C and C++ Programming | 1 | 07-30-2007 06:46 AM |
| Access e-mail using Outlook Web Access | gattuso | Server Management | 0 | 07-19-2007 07:20 AM |
| How to get the available and used memory in mobile using J2ME ? | oxygen | J2ME | 1 | 07-19-2007 12:51 AM |
| Memory Sticks?? | WiccanSpirit | The Lounge | 10 | 03-15-2007 08:59 PM |