Results 1 to 4 of 4

Thread: Direct Memory Addressing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    28

    Question

    This may seem simple, but would anyone be able to tell me how to write directly to memory in c (not c++), namely for SVGA graphics? Qbasic has it's "poke" and "peek" functions but I can't seem to find the equivalent in c.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    to write directly to a specific memory location in c, you need something like the following code. DON'T RUN THIS!!!!! IT WILL SERIOUSLY KILL YOUR COMPUTER!!!!!!

    sorry.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void main() {
        char* pcMyVariable;
        char* pcMyString = "Here is a string";
    
        pcMyVariable = 0x6552; // random memory address
        strcpy(pcMyVariable, pcMyString);
    }
    obviously, you set the memory address to whatever is needed - if you need to write to video memory, there are ways to find the base address. i assume that you know how to set up the screen mode, and just need to write something. anyway, all you do is set the pointer to your memory location and write away. and then your program dies because you messed up (it happens to me a lot!).


    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    28
    That sounds cool, but unfortunately I am still stuck in the c data segment. I don't suppose c supports segment overrides (or perhaps a way to trick it like a far external char in video segment 0xA000) ?

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    make it a big enough address that it wraps round...there is a method floating round the Internet somewhere, but I
    a) have never used it
    b) never intend to use it
    c) don't understand it
    So I think you can see my problem.
    Let's try something:

    DOES ANYONE OUT THERE KNOW HOW TO GET AT VIDEO MEMORY FROM DOS!!!!!!!

    Now to wait for the punters to 'flood in'...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width