;This program moves a car under mouse control
	  mov    ax, 0     ; start mouse
	  int    33h
	  mov    ax, 1
	  int    33h            ;make certain it is not seen
car_loop: call   draw_car
	  call   pause
	  call   erase_car
	  call   mouse_pos
	  mov    ax, 3
	  int    33h
	  or     bx, bx
	  jz     car_loop       ; no mouse button pressed

	  mov   ax, 4C00H
	  int   21h
car_row   db     10
car_col   db     30
pause:    push   si
	  push   ax
	  mov    si, 50
outter:   mov    ax, 0ffffh
lp1:      sub    ax, 1
	  jnz    lp1
	  sub    si, 1
	  jnz    outter
	  pop    ax
	  pop    si
	  ret
;  input and output:  car_row and car_col

mouse_pos:  push     ax
	     push     bx
	     push     cx
	     push     dx
	     mov      ax, 3
	     int      33h
; cx = mouse position 0 - 639
; dx = mouse position vert 0 - 199
	     cmp      cx, 400
	     ja       right
	     cmp      cx, 200
	     ja       vert
	     sub      car_col, 1
	     jmp      vert
right:       add      car_col, 1
vert:        cmp      dx, 75
	     jb       up
	     cmp      dx, 125
	     jb       rand_exit
	     add      car_row, 1
	     jmp      rand_exit
up:          sub      car_row, 1
rand_exit:    pop      dx
	      pop      cx
	      pop      bx
	      pop      ax
	     ret

erase_car:       push   ax
		 push   bx
		 push   cx
		 push   dx
		 mov    al, ' '
		 mov    bl, 07h
		 mov    cx, 1
		 mov    dh, car_row
		 mov    dl, car_col
		 call   paint
		 add    dh, 1
		 sub    dl, 2
		 mov    cx, 5
		 call   paint
		 pop    dx
		 pop    cx
		 pop    bx
		 pop    ax
		 ret

;         input (dh, dl) row and col of where to paint car
draw_car: push   ax
	  push   bx
	  push   cx
	  push   dx
	  mov    dh,    car_row
	  mov    dl,    car_col
	  mov    al, 1                 ;happy face
	  mov    cx, 1
	  mov    bl, 0Eh               ;yellow on black
	  call   paint
	  add    dh, 1
	  sub    dl, 2                 ;position of first car
	  mov    al, 0C8h              ;left side of car
	  mov    bl, 01h               ;blue on black
	  call   paint
	  add    dl, 1
	  mov    cx, 3
	  mov    al, 0CDh              ;char for middle of car
	  call   paint
	  add    dl, 3
	  mov    cx, 1
	  mov    al, 0BCh              ;right side of car
	  call   paint
	  mov    dh, 25
	  mov    dl, 25
	  call  set_pos       ; get rid of cursor so we can't see it
	  pop   dx
	  pop   cx
	  pop   bx
	  pop   ax
	  ret



;      input    dh = row
;               dl = col
set_pos:  push   ax
	  push   bx
	  mov    bh, 0                 ;page 0
	  mov    ah, 2                 ;function set cursor
	  int    10h
	  pop    bx
	  pop    ax
	  ret
;  paints chars at the current cursor location
;         input  = cx num of char
;                  al = ascii char
;                  bl = attrib
;
paint:    push   ax
	  push   bx
	  cmp    cx, 0
	  je     paint_done
	  call   set_pos
	  mov    bh, 0                 ;page 0
	  mov    ah, 9                 ;function for writing a char
	  int    10h
paint_done:
	  pop    bx
	  pop    ax
	  ret
	  end