1

As part of a school project I am making a game that shows everything we've learned this semester. So I made this game where you're this smiley guy and you run around a maze with obstacles that bring you back to the start of the maze and once you reach the end you go to the next level.

So I wanted to add a title screen with a "button" -- pretty much a title screen drawn in text and then:

 mov  ax, 3h
 int  33h
 mov  mouseClick, bx
 mov  mouseX, cx
 mov  mouseY, dx
 call checkMClick
 cmp  mousePos, 1h
 je   goodMPos
 jne  badMPos

 goodMPos:

 call firstLevel   
 call newMazePos
 call output

;---------------------------------------;                            

 checkMClick: cmp  mouseclick, 1h 
              je   checkMouseX
              jne  mouse  

 checkMouseX: cmp  mouseX, 7h
              jge  afterStartX
              jl   mouse

 afterStartX: cmp  mouseX, 23h
              jle  goodXPos
              jg   badMPos

 goodXPos:    mov  mousePos, 1h
              jmp  checkMouseY

 checkMouseY: cmp  mouseY, 7h
              jge  afterStartY
              jl   mouse

 afterStartY: cmp  mouseY, 11h
              jge  goodYPos
              jl   badMPos                 

 goodYPos:    mov  mousePos, 1h
              ret                 

 badMPos:     mov  mousePos, 0h
              jmp  mouse

But the coordinates for the mouse position are fucked up.

EDIT: Here's the pastebin for the entire thing

itamar reif
  • 139
  • 2
  • 9

2 Answers2

1

You have to change the order of the operands! The registers are the source.

mov  bx, mouseClick
mov  cx, mouseX
mov  dx, mouseY

Also function 3 of the mouse driver gives positions as if the screen were 640x200. You have to compensate for this.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • I am in video mode `03h` which is 640x200 and 8x8 -- doesn't that mean that the coordinates should match the ones given by `int 33h`? – itamar reif Dec 22 '14 at 00:04
0
; DATA segment
mouseClick DW ?
mouseX     DW ?
mouseY     DW ?
mousePos   DW ?

; CODE segment
mov  ax, 3h
int  33h
mov  [mouseClick], bx ; Write the value of BX to mouseClick
mov  [mouseX], cx     ; Write the value of CX to mouseX
mov  [mouseY], dx     ; Write the value of DX to mouseY

Those following instructions need to specify how many bytes we want to access.

cmp  mouseclick, 1h
mov  mousePos, 1h

cmp  WORD[mouseclick], 1h ; for to compare two bytes
mov  WORD[mousePos], 1h   ; for to write two bytes

And for to check unsigned nunbers if the value is above, or below, we can use the instructions: "ja, jna, jb, jnb". The instructions: "jg, jng, jl, jnl are for signed numbers.

In text modes, all coordinates are specified as multiples of the cell size, typically 8x16 or 8x8 pixels. http://en.wikipedia.org/wiki/Text_mode

  • In text modes, all coordinates are specified as multiples of the cell size, typically 8x16 or 8x8 pixels. http://en.wikipedia.org/wiki/Text_mode I am in video mode `03h` which is 640x200 and 8x8 -- doesn't that mean that the coordinates should match the ones given by `int 33h`? – itamar reif Dec 22 '14 at 00:01
  • The mouse coordinates are between 640x200, but the textscreen is divided into 80x25 rows, columns. – Dirk Wolfgang Glomp Dec 22 '14 at 09:57
  • Oh, I see. So I would have to multiply the X,Y accordingly? – itamar reif Dec 22 '14 at 10:03