Results 1 to 18 of 18

Thread: Draw line and randomize

  1. #1

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381

    Draw line and randomize

    How do i draw a line on graphic mode from register bx to register cx.
    If you could please write a function that does such a thing I will be greatly thankful.

    Also, how do I randomize in assembler.

    Thank you

  2. #2

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    help me please

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For randomizing, you just need a function that does some stupid calculations with an inner state (the "seed") and returns the result, while at the same time updating the seed.

    As for the line, what do you mean "from bx to cx"? How can a 16-bit register hold a set of coordinates even in 320x240 mode?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    if you could please post the commands which randomize it'll help alot:P

    Also, I don't see what's the problem with "from bx to cx"
    bx=y*320+x
    ;i know you can't write like this in assembler, it's only the
    ;algorithm
    ;al-color of the dot
    mov es:[bx],al

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok, I see.
    So
    x1 = bx % 320
    y1 = bx / 320
    x2 = cx % 320
    y2 = cx / 320

    So you have a line, you need to rasterize it. I'm sure you can find a good rasterizing algorithm on the internet. If it is C (it probably is) just feed it to an optimizing C compiler and convert the resulting assembly to 16-bit code. It should be easier than translating the code yourself.

    Then you just put values at the appropriate memory addresses.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    As for randomizing, get any open source C runtime library (e.g. the GNU CRT) and look at the rand function. It should be simple enough to translate to assembly.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    how?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Download the GNU CRT source from
    www.gnu.org
    and search for the source file that implements rand and srand. It really can't be that hard.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    As for the line, what do you mean "from bx to cx"? How can a 16-bit register hold a set of coordinates even in 320x240 mode?
    He is not talking about one register he is talking
    about two registers: bx and cx. Those two together
    should be able to two coordinates ranging from 0 to 65535
    which should be enough for any resolution that is used
    on the pc I know of.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    He's talking of a line so he needs two coordinate set, so what you say is wrong.

    Anyway, that was cleared up already.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    I was talking about ONE set of coordinates not TWO
    but yes I forgot we were talking about a line where you need two sets of coordinates and that would mean you need all four available registers.

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But he said he had TWO coordinate sets in TWO registers. Not ONE in TWO, not TWO in FOUR, but TWO in TWO.
    A thing possible only in 320*240.

    Three should be the number to count to.
    Not four, neither two, except inorder to count on to three.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    yes I forgot we were talking about a line where you need two sets of coordinates and that would mean you need all four available registers.

  14. #14

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    Never mind the line... i have almost finished making it.
    If you could just post here a code which randomizes.... that would be great!:P
    Thanks

  15. #15

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    anyone?
    please(:

  16. #16
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    Perhaps you could use the timer or part of it for a random value.
    The timer is a dword value stored at address 40:6C.


    Try looking for it on the internet using Google (http://www.google.com) it will be some work but I think
    you can find something useful.

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    To give you an idea: that's the code of rand() in the VC++ CRT:
    Code:
    return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
    Of course this is a quite poor algorithm since it only gives you a 15-bit number.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  18. #18
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Random number algorithm

    Interesting lecture that has some pretty good stuff for random number generation.

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