umm... sorry for being so ignorant but
i have a really dumb question...
I know how to use pointers to operate on program data. How do you access memmory outside the program in c. (Im not talking about malloc)
eg. In basic you would use DEF SEG to set the segment address, and peek/poke.
thanks for your help.
-= Twisted Matrix =-
What environment? In Windows I don''t think it is possible since in runs in protected mode. In old 16 bit DOS mode you could just point to any ol'' address you wanted. I think it kinda depends on what you are trying to do.
yeah, I know its not possible in windows. DJGPP is still protected mode though. I think I would have to move memmory into the programs local address space before I could do anything with it. but im not sure how...
looking through libc...
-= Twisted Matrix =-
looking through libc...
-= Twisted Matrix =-
i cant find a ansi standard way to access MS-DOS'' conventional (REAL mode) memmory from pmode anywhere. It dosen''t exist I tell you!! Arghh!
-= Twisted Matrix =-
-= Twisted Matrix =-
In DJGPP, I think you can use the functions dosmemget and dosmemput.
Stold this from the libc reference inside Rhide. . .
Stold this from the libc reference inside Rhide. . .
dosmemget
=========
Syntax
------
#include <sys/movedata.h>
void dosmemget(int offset, int length, void *buffer);
Description
-----------
This function transfers data from MS-DOS''s conventional memory space to
the program''s virtual address space. The OFFSET is a physical address,
which can be computed from a real-mode segment/offset pair as follows:
offset = segment * 16 + offset;
The LENGTH is the number of bytes to transfer, and BUFFER is a pointer
to somewhere in your virtual address space (such as memory obtained
from `malloc'') where the data will go.
Return Value
------------
None.
Portability
-----------
not ANSI, not POSIX
Example
-------
unsigned short shift_state;
dosmemget(0x417, 2, &shift_state);
if (shift_state & 0x0004)
/* Ctrl key pressed */;
dosmemput
=========
Syntax
------
#include <sys/movedata.h>
void dosmemput(const void *buffer, int length, int offset);
Description
-----------
This function transfers data from the program''s virtual address space to
MS-DOS''s conventional memory space. The OFFSET is a physical address,
which can be computed from a real-mode segment/offset pair as follows:
offset = segment * 16 + offset;
The LENGTH is the number of bytes to transfer, and BUFFER is a pointer
to somewhere in your virtual address space (such as memory obtained
from `malloc'') where the data will come from.
Return Value
------------
None.
Portability
-----------
not ANSI, not POSIX
Example
-------
unsigned short save_screen[25][80];
dosmemput(save_screen, 80*2*25, 0xb8000);
TwistedMatrix:
if you just want to access VGA vidmem in djgpp you be able to do it like this
unsigned char *vidmem = 0xA0000;
vidmem[0] = 255;
sets first pixel to color index 255 :-)
long time since I last programmed for DOS32 (with a dos extender). But I remember something about the djgpp dos extender mapping all the dosmem into your programs space.. that is why the above works.. I''ve only added one zero because this is a flatmode address.. The realmode VGA framebuffer address was A000:0000.. most of the dos extenders just made one giant linear memory segment because under dos you only ran one pmode program at a time.. windows use segmented p-mode with paging which basically means that you have virtual memory addresses in the form of Segment:Address.. windows sets up a segment for every program you run.. that way it is able to protect each programs memspace.. this is why you sometime see the general protection fault.. this is a hardware interrupt triggered by the processor if a program writes outside its mem segment (mostly a loop running wild).
if you just want to access VGA vidmem in djgpp you be able to do it like this
unsigned char *vidmem = 0xA0000;
vidmem[0] = 255;
sets first pixel to color index 255 :-)
long time since I last programmed for DOS32 (with a dos extender). But I remember something about the djgpp dos extender mapping all the dosmem into your programs space.. that is why the above works.. I''ve only added one zero because this is a flatmode address.. The realmode VGA framebuffer address was A000:0000.. most of the dos extenders just made one giant linear memory segment because under dos you only ran one pmode program at a time.. windows use segmented p-mode with paging which basically means that you have virtual memory addresses in the form of Segment:Address.. windows sets up a segment for every program you run.. that way it is able to protect each programs memspace.. this is why you sometime see the general protection fault.. this is a hardware interrupt triggered by the processor if a program writes outside its mem segment (mostly a loop running wild).
Thanks. I have another question however. The following software interrupt, dosn''t work all of the time. could anyone tell me why?
inregs.w.ax = 0x1112; /* LOAD ROM 8x8 CHARS */
int86(0x10, &inregs, &outregs);
Also, apparently AX can be 1112h or 1102h. Weird???
-= Twisted Matrix =-
inregs.w.ax = 0x1112; /* LOAD ROM 8x8 CHARS */
int86(0x10, &inregs, &outregs);
Also, apparently AX can be 1112h or 1102h. Weird???
-= Twisted Matrix =-
I think mabey the interrupt was loading junk into the lower byte of BX...
-= Twisted Matrix =-
-= Twisted Matrix =-
Do not use a high level language if you''re going to write interrupt handlers. Anyone from the old skool''ll tell you that, and dude, your intentions with these little questions dont seem to be purely platonic, but if im right, and if you''re trying to write what i think you are, write if for an operating system that is still in general use *i.e. there are plenty of exploits that i know of for windows XP, but i dont make those kind of programs(anymore)*
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement