MOUSE IN THE GRAPHICAL MODE - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

MOUSE IN THE GRAPHICAL MODE

bpajkbpajk Posts: 156Member
I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.


{the cursor}
const utripac:array[0..15] of word=
($1FFF,$0FFF,$07FF,$03FF,
$01FF,$00FF,$007F,$003F,
$001F,$003F,$01FF,$01FF,
$E0FF,$F0FF,$F8FF,$F8FF);

{the procedure for showing the cursor}
procedure mprikazi; assembler;
asm
mov AX, $0009
mov BX, $0001
mov CX, $0001
mov ES, [offset utripac]
mov DX, [seg utripac]
int 33H
end;


I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.

PS: I use TP7


Comments

  • ManningManning Posts: 1,621Member
    : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    :
    :
    : {the cursor}
    : const utripac:array[0..15] of word=
    : ($1FFF,$0FFF,$07FF,$03FF,
    : $01FF,$00FF,$007F,$003F,
    : $001F,$003F,$01FF,$01FF,
    : $E0FF,$F0FF,$F8FF,$F8FF);
    :
    : {the procedure for showing the cursor}
    : procedure mprikazi; assembler;
    : asm
    : mov AX, $0009
    : mov BX, $0001
    : mov CX, $0001
    : mov ES, [offset utripac]
    : mov DX, [seg utripac]
    : int 33H
    : end;
    :
    :
    : I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.
    :
    : PS: I use TP7

    You might be using TP7, but you're asking an ASM question. Someone here may have an answer, but you're probably better off asking on the assembler message board.
  • Phat NatPhat Nat Posts: 757Member
    : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    : :
    : :
    : : {the cursor}
    : : const utripac:array[0..15] of word=
    : : ($1FFF,$0FFF,$07FF,$03FF,
    : : $01FF,$00FF,$007F,$003F,
    : : $001F,$003F,$01FF,$01FF,
    : : $E0FF,$F0FF,$F8FF,$F8FF);
    : :
    : : {the procedure for showing the cursor}
    : : procedure mprikazi; assembler;
    : : asm
    : : mov AX, $0009
    : : mov BX, $0001
    : : mov CX, $0001
    : : mov ES, [offset utripac]
    : : mov DX, [seg utripac]
    : : int 33H
    : : end;
    : :
    : :
    : : I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.
    : :
    : : PS: I use TP7
    :
    : You might be using TP7, but you're asking an ASM question. Someone here may have an answer, but you're probably better off asking on the assembler message board.
    :

    True. I have quite an extensive ASM knowledge, but I couldn't get it to work either. The only thing I can think of is that maybe the Windows mouse driver doesn't properly implement this. The Segment and Offsets are correct because using them I can do a direct screen write. I am pretty sure this is where the problem lies. If you find differently, please post the answer. I am going to start looking around as well.

    Phat Nat

  • bpajkbpajk Posts: 156Member
    : : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    : : :
    : : :
    : : : {the cursor}
    : : : const utripac:array[0..15] of word=
    : : : ($1FFF,$0FFF,$07FF,$03FF,
    : : : $01FF,$00FF,$007F,$003F,
    : : : $001F,$003F,$01FF,$01FF,
    : : : $E0FF,$F0FF,$F8FF,$F8FF);
    : : :
    : : : {the procedure for showing the cursor}
    : : : procedure mprikazi; assembler;
    : : : asm
    : : : mov AX, $0009
    : : : mov BX, $0001
    : : : mov CX, $0001
    : : : mov ES, [offset utripac]
    : : : mov DX, [seg utripac]
    : : : int 33H
    : : : end;
    : : :
    : : :
    : : : I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.
    : : :
    : : : PS: I use TP7
    : :
    : : You might be using TP7, but you're asking an ASM question. Someone here may have an answer, but you're probably better off asking on the assembler message board.
    : :
    :
    : True. I have quite an extensive ASM knowledge, but I couldn't get it to work either. The only thing I can think of is that maybe the Windows mouse driver doesn't properly implement this. The Segment and Offsets are correct because using them I can do a direct screen write. I am pretty sure this is where the problem lies. If you find differently, please post the answer. I am going to start looking around as well.
    :
    : Phat Nat
    :
    : It would be great if this could work, but there is a different way to go around this. It is actually harder than assembler but it would work. To draw a cursor on new coordinates and erase the cursor on old coordinates when the mouse coordinates change (only a draft). This was my secondary plan. Not so efficien as assembler but it will have to do.



  • Phat NatPhat Nat Posts: 757Member
    : : : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    : : : :
    : : : :
    : : : : {the cursor}
    : : : : const utripac:array[0..15] of word=
    : : : : ($1FFF,$0FFF,$07FF,$03FF,
    : : : : $01FF,$00FF,$007F,$003F,
    : : : : $001F,$003F,$01FF,$01FF,
    : : : : $E0FF,$F0FF,$F8FF,$F8FF);
    : : : :
    : : : : {the procedure for showing the cursor}
    : : : : procedure mprikazi; assembler;
    : : : : asm
    : : : : mov AX, $0009
    : : : : mov BX, $0001
    : : : : mov CX, $0001
    : : : : mov ES, [offset utripac]
    : : : : mov DX, [seg utripac]
    : : : : int 33H
    : : : : end;
    : : : :
    : : : :
    : : : : I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.
    : : : :
    : : : : PS: I use TP7
    : : :
    : : : You might be using TP7, but you're asking an ASM question. Someone here may have an answer, but you're probably better off asking on the assembler message board.
    : : :
    : :
    : : True. I have quite an extensive ASM knowledge, but I couldn't get it to work either. The only thing I can think of is that maybe the Windows mouse driver doesn't properly implement this. The Segment and Offsets are correct because using them I can do a direct screen write. I am pretty sure this is where the problem lies. If you find differently, please post the answer. I am going to start looking around as well.
    : :
    : : Phat Nat
    : :
    : : It would be great if this could work, but there is a different way to go around this. It is actually harder than assembler but it would work. To draw a cursor on new coordinates and erase the cursor on old coordinates when the mouse coordinates change (only a draft). This was my secondary plan. Not so efficien as assembler but it will have to do.

    I have done stuff this before. I was going to recommend it, but then you should use Virtual Screens to eliminate flicker while keeping speed. I have used this method for many different programs & games. If you need a hand, just leave a message and I'll explain it more.

    Phat Nat
  • bpajkbpajk Posts: 156Member
    : : : : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    : : : : :
    : : : : :
    : : : : : {the cursor}
    : : : : : const utripac:array[0..15] of word=
    : : : : : ($1FFF,$0FFF,$07FF,$03FF,
    : : : : : $01FF,$00FF,$007F,$003F,
    : : : : : $001F,$003F,$01FF,$01FF,
    : : : : : $E0FF,$F0FF,$F8FF,$F8FF);
    : : : : :
    : : : : : {the procedure for showing the cursor}
    : : : : : procedure mprikazi; assembler;
    : : : : : asm
    : : : : : mov AX, $0009
    : : : : : mov BX, $0001
    : : : : : mov CX, $0001
    : : : : : mov ES, [offset utripac]
    : : : : : mov DX, [seg utripac]
    : : : : : int 33H
    : : : : : end;
    : : : : :
    : : : : :
    : : : : : I don't know what is wrong here. It may be the offset or the seg part. I don't know. If anyone does please anwser.
    : : : : :
    : : : : : PS: I use TP7
    : : : :
    : : : : You might be using TP7, but you're asking an ASM question. Someone here may have an answer, but you're probably better off asking on the assembler message board.
    : : : :
    : : :
    : : : True. I have quite an extensive ASM knowledge, but I couldn't get it to work either. The only thing I can think of is that maybe the Windows mouse driver doesn't properly implement this. The Segment and Offsets are correct because using them I can do a direct screen write. I am pretty sure this is where the problem lies. If you find differently, please post the answer. I am going to start looking around as well.
    : : :
    : : : Phat Nat
    : : :
    : : : It would be great if this could work, but there is a different way to go around this. It is actually harder than assembler but it would work. To draw a cursor on new coordinates and erase the cursor on old coordinates when the mouse coordinates change (only a draft). This was my secondary plan. Not so efficien as assembler but it will have to do.
    :
    : I have done stuff this before. I was going to recommend it, but then you should use Virtual Screens to eliminate flicker while keeping speed. I have used this method for many different programs & games. If you need a hand, just leave a message and I'll explain it more.
    :
    : Phat Nat
    : Yes, I would be very thankfull for you're help on this subject.



  • Phat NatPhat Nat Posts: 757Member
    : : : : : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    [italic]

    [/italic]
    : : : : Phat Nat
    : : : :
    : : : : It would be great if this could work, but there is a different way to go around this. It is actually harder than assembler but it would work. To draw a cursor on new coordinates and erase the cursor on old coordinates when the mouse coordinates change (only a draft). This was my secondary plan. Not so efficien as assembler but it will have to do.
    : :
    : : I have done stuff this before. I was going to recommend it, but then you should use Virtual Screens to eliminate flicker while keeping speed. I have used this method for many different programs & games. If you need a hand, just leave a message and I'll explain it more.
    : :
    : : Phat Nat
    : Yes, I would be very thankfull for you're help on this subject.

    First off, I'm not at home, so my code may need minor adjustments. No way of testing it here.

    Okay, here goes. The easiest way I have found is to get the pointer location, then draw a pre-defined array on the screen. The nice thing about doing it this way is that it can be any size you want and also, it can be any colors you want. The disadvantage is that you need to create your own Virtual Screens so that it doesn't flicker. Well, here goes:

    First off, we need Virtual Screens. I like to decalre them like this:
    [code]
    CONST
    VGA = $A000; { This is where the screen is located in memory }
    TYPE
    VScreen = Array[0..63999] Of Byte; { Graphics 320x200 }
    VirScr = ^VScreen;

    VAR
    VScreen : Array[1..4] Of VirScr;
    VAddr : Array[1..4] Of Word;
    [/code]

    Now that we have declared the variables, we need to MAKE SURE THAT WE INITIALIZE THEM. otherwise, if you just start writing to the Virtual Screens without initialization, it will overwrite something important in memory and your computer will crash and need to be rebooted :(
    [code]
    VAR
    X : Word;
    NumScreens : Byte;
    Begin
    NumScreens := 0;
    For X := 1 to 4 Do
    If MemAvail >= SizeOf(VScreen) Then
    Begin
    New(VirScr[X]);
    VAddr[X] := Addr(VirScr[X]);
    Inc(NumScreens);
    End;
    {...}
    End.
    [/code]

    By default, this will always give us 4 virtual screens to work with as long as there is enough memory. And when we are finished, we need to dispose of the Virtual Screens to free up the memory.
    [code]
    For X := 1 to NumScreens Do
    Dispose(VirScr[X]);
    [/code]

    Okay. Now we have them, we need to be able to use them. They are drawn to just like the screen, so here's an example of an 8x8 mouse pointer:
    [code]
    PROCEDURE DrawMouse(Where : Word); { Where is the Virtual Screen we want it drawn on }
    VAR
    MouseX, MouseY : Word;
    MouseB : Byte;
    X, Y : Word;
    Begin
    ASM
    Mov Ax, $0003 { I think... This should be Get Pos/Buttons }
    Int $33
    Shr Cx, 1 { If I remember right, Cx=0-640. Div by 2 for 320 }
    Mov MouseX, Cx
    Mov MouseY, Dx
    Mov MouseB, Bl
    END;
    For Y := 0 to 7 Do
    For X := 0 to 7 Do
    If Mouse[X,Y] <> 255 Then
    If Mouse[X,Y] = 254 Then
    Mem[Where:MouseX+X + (MouseY+Y)*320] := Mem[Where:MouseX+X + (MouseY+Y)*320] XOR 255;
    ELSE
    Mem[Where:MouseX+X + (MouseY+Y)*320] := Mouse[X,Y];
    End;
    [/code]

    Sorry, I'm not going to take the time to do a demo Mouse VAR. Just make
    Mouse : Array[0..7,0..7] Of Byte;
    and then set it to any color (255 = clear, 254 = Reversed).

    The only thing left is how to use these together. Here's an example:
    *NOTE* This may not work, but gives you an idea. I have written procedures to do the FillChar() & Move() in ASM and can't remember if this works. If it doesn't and you can't get it leave another message)
    [code]
    Begin
    {... This was decalred earlier ...}
    FillChar(Mem[Vaddr[1]:0000],0); { Make sure VirScr[1] is cleared }
    {...Draw something on VAddr[1] (VirScr[1])... }
    Repeat
    { You can draw anything on VAddr[1] that you want saved }
    Move(Mem[VAddr[1]:0],Mem[VAddr[2]:0],SizeOf(VScreen));
    { You can draw anything on VAddr[2] that you want for 1 screen draw }
    DrawMouse(VAddr[1]);
    Move(Mem[VAddr[2]:0],Mem[VGA:0],SizeOf(VScreen));
    Until Keypressed;
    End.
    [/code]

    Hope this isn't too confusing. As I said, it may not work, but it gives you the basic idea. The MOVE() procedure could be replaced with the assembly STOSW command (much faster as well).

    Phat Nat
  • bpajkbpajk Posts: 156Member
    : : : : : : : I want to have a mouse in my graphical program, but I don't want any mouse units in my code. (I want to write evrything myself.) I have written everything I need except the procedure to make the cursor visible in graphical mode. This is a part of my code.
    : [italic]
    :
    : [/italic]
    : : : : : Phat Nat
    : : : : :
    : : : : : It would be great if this could work, but there is a different way to go around this. It is actually harder than assembler but it would work. To draw a cursor on new coordinates and erase the cursor on old coordinates when the mouse coordinates change (only a draft). This was my secondary plan. Not so efficien as assembler but it will have to do.
    : : :
    : : : I have done stuff this before. I was going to recommend it, but then you should use Virtual Screens to eliminate flicker while keeping speed. I have used this method for many different programs & games. If you need a hand, just leave a message and I'll explain it more.
    : : :
    : : : Phat Nat
    : : Yes, I would be very thankfull for you're help on this subject.
    :
    : First off, I'm not at home, so my code may need minor adjustments. No way of testing it here.
    :
    : Okay, here goes. The easiest way I have found is to get the pointer location, then draw a pre-defined array on the screen. The nice thing about doing it this way is that it can be any size you want and also, it can be any colors you want. The disadvantage is that you need to create your own Virtual Screens so that it doesn't flicker. Well, here goes:
    :
    : First off, we need Virtual Screens. I like to decalre them like this:
    : [code]
    : CONST
    : VGA = $A000; { This is where the screen is located in memory }
    : TYPE
    : VScreen = Array[0..63999] Of Byte; { Graphics 320x200 }
    : VirScr = ^VScreen;
    :
    : VAR
    : VScreen : Array[1..4] Of VirScr;
    : VAddr : Array[1..4] Of Word;
    : [/code]
    :
    : Now that we have declared the variables, we need to MAKE SURE THAT WE INITIALIZE THEM. otherwise, if you just start writing to the Virtual Screens without initialization, it will overwrite something important in memory and your computer will crash and need to be rebooted :(
    : [code]
    : VAR
    : X : Word;
    : NumScreens : Byte;
    : Begin
    : NumScreens := 0;
    : For X := 1 to 4 Do
    : If MemAvail >= SizeOf(VScreen) Then
    : Begin
    : New(VirScr[X]);
    : VAddr[X] := Addr(VirScr[X]);
    : Inc(NumScreens);
    : End;
    : {...}
    : End.
    : [/code]
    :
    : By default, this will always give us 4 virtual screens to work with as long as there is enough memory. And when we are finished, we need to dispose of the Virtual Screens to free up the memory.
    : [code]
    : For X := 1 to NumScreens Do
    : Dispose(VirScr[X]);
    : [/code]
    :
    : Okay. Now we have them, we need to be able to use them. They are drawn to just like the screen, so here's an example of an 8x8 mouse pointer:
    : [code]
    : PROCEDURE DrawMouse(Where : Word); { Where is the Virtual Screen we want it drawn on }
    : VAR
    : MouseX, MouseY : Word;
    : MouseB : Byte;
    : X, Y : Word;
    : Begin
    : ASM
    : Mov Ax, $0003 { I think... This should be Get Pos/Buttons }
    : Int $33
    : Shr Cx, 1 { If I remember right, Cx=0-640. Div by 2 for 320 }
    : Mov MouseX, Cx
    : Mov MouseY, Dx
    : Mov MouseB, Bl
    : END;
    : For Y := 0 to 7 Do
    : For X := 0 to 7 Do
    : If Mouse[X,Y] <> 255 Then
    : If Mouse[X,Y] = 254 Then
    : Mem[Where:MouseX+X + (MouseY+Y)*320] := Mem[Where:MouseX+X + (MouseY+Y)*320] XOR 255;
    : ELSE
    : Mem[Where:MouseX+X + (MouseY+Y)*320] := Mouse[X,Y];
    : End;
    : [/code]
    :
    : Sorry, I'm not going to take the time to do a demo Mouse VAR. Just make
    : Mouse : Array[0..7,0..7] Of Byte;
    : and then set it to any color (255 = clear, 254 = Reversed).
    :
    : The only thing left is how to use these together. Here's an example:
    : *NOTE* This may not work, but gives you an idea. I have written procedures to do the FillChar() & Move() in ASM and can't remember if this works. If it doesn't and you can't get it leave another message)
    : [code]
    : Begin
    : {... This was decalred earlier ...}
    : FillChar(Mem[Vaddr[1]:0000],0); { Make sure VirScr[1] is cleared }
    : {...Draw something on VAddr[1] (VirScr[1])... }
    : Repeat
    : { You can draw anything on VAddr[1] that you want saved }
    : Move(Mem[VAddr[1]:0],Mem[VAddr[2]:0],SizeOf(VScreen));
    : { You can draw anything on VAddr[2] that you want for 1 screen draw }
    : DrawMouse(VAddr[1]);
    : Move(Mem[VAddr[2]:0],Mem[VGA:0],SizeOf(VScreen));
    : Until Keypressed;
    : End.
    : [/code]
    :
    : Hope this isn't too confusing. As I said, it may not work, but it gives you the basic idea. The MOVE() procedure could be replaced with the assembly STOSW command (much faster as well).
    :
    : Phat Nat
    : Thanx wery much for the help, it will come in handy.



Sign In or Register to comment.