DECLARE SUB flop (fi$)
DECLARE SUB tg ()

 DEFINT A-Z
DECLARE SUB Mouse (cx, dx, bx)
DECLARE SUB MousePointer (SW)
DECLARE SUB drmouse (cx%, dx%)
DECLARE SUB prockey (KE$)

COMMON SHARED h1, v1, hpos, VPOS, pncl
COMMON SHARED c1, d1, bx, cc
    DEFINT A-Z
   
    DIM SHARED pn%(10, 10)
     CLS

SCREEN 13
    c1 = 1: d1 = 1
    
    DIM SHARED a(9)                 'Set up array for code
                                                          
    DEF SEG = VARSEG(a(0))          'Get array segment (nnnn:    )
                                    '    (two 8 bit)
    FOR i = 0 TO 17                 'length of DATA to
       READ r                       'read
       POKE VARPTR(a(0)) + i, r     'into array/2 (nnnn:iiii) (one 8 bit)
    NEXT i                          'until 17

'**************************** Machine Code *********************************

DATA &HB8,&H00,&H00   :   ' mov  AX,[n]       [Swap code-(L),(H)] in AX
DATA &H55             :   ' push BP           Save BP
DATA &H8B,&HEC        :   ' mov  BP,SP        Get BP to c Seg
DATA &HCD,&H33        :   ' int  33           Interrupt 33
DATA &H92             :   ' xchg AX,[reg]     [Swap code-reg] in AX
DATA &H8B,&H5E,&H06   :   ' mov  BX,[BP+6]    Point to (variable)
DATA &H89,&H07        :   ' mov  [BX],AX      Put AX in (variable)
DATA &H5D             :   ' pop  BP           Restore BP
DATA &HCA,&H02,&H00   :   ' ret  2            Far return

'*********************** P R O G R A M   S C R E E N ***********************

          
                CALL MousePointer(0)      'Reset mouse and
                CALL MousePointer(3)      'Get coordinates

 DIM SHARED BOX%(10, 10)
 
GET (0, 0)-(5, 5), pn%
CLS

 FOR V = 0 TO 400 STEP 10
 FOR h = 250 TO 300 STEP 10
 c = c + 1

  LINE (h, V)-(h + 7, V + 7), c, BF





  NEXT h
 NEXT V

GET (0, 0)-(10, 10), BOX%
V = 1

hpos = 20
VPOS = 20
 hdm = 1
DO

LOCATE 1, 1: PRINT dx; " "; cx; " "; bx; "  "

CALL tg
CALL Mouse(cx, dx, bx)
 IF bx = 1 AND hdm = 1 THEN PUT (d1, c1), pn%, PSET

 IF hdm = 1 THEN
 CALL drmouse(cx, dx)
 END IF
KE$ = INKEY$
 IF bx = 2 THEN hdm = 1: SOUND 100 + 5, 1: IF dx > 240 THEN pncl = POINT(dx, cx): LINE (230, 0)-(239, 200), pncl, BF
 IF bx = 0 THEN hdm = 1
IF bx = 1 AND dx <= 239 THEN PSET (dx, cx), pncl: hdm = 0: GET (dx, cx)-(dx + 5, cx + 5), pn%: c1 = cx: d1 = dx


  IF KE$ <> "" THEN

  CALL prockey(KE$)
 
  END IF


LOOP UNTIL KE$ = CHR$(27)
DEFINT A-Z
'

SUB drmouse (cx, dx)







    IF c1 <> (cx) OR d1 <> (dx) THEN
     IF bx <> 1 AND dx > 1 AND cx > 1 AND dx < 310 AND cx < 190 THEN
   
   
    PUT (d1, c1), pn%, PSET

    c1 = cx
    d1 = dx
   
   
    GET (dx, cx)-(dx + 5, cx + 5), pn%



    END IF
    ELSE
   
    IF bx <> 1 THEN
    LINE (dx + 1, cx + 1)-(dx + 1, cx + 3), cc
    LINE -(dx + 3, cx + 1), cc
    LINE -(dx + 1, cx + 1), cc
   
    LINE (dx + 1, cx + 1)-(dx + 4, cx + 4), 3
   
    END IF

    END IF


END SUB

SUB flop (fi$)

REM open routine



OPEN fi$ FOR INPUT AS #1



END SUB

SUB Mouse (cx, dx, bx)
      
      
     

           POKE VARPTR(a(4)), &H92           'Swap code,Get CX setup
          CALL absolute(cx, VARPTR(a(0)))     'Run Code
              cx = cx                     'Adjust 25x80
           POKE VARPTR(a(4)), &H91           'Swap code,Get DX setup
          CALL absolute(dx, VARPTR(a(0)))     'Run Code
              dx = dx                     'Adjust 25x80
           POKE VARPTR(a(4)), &H93           'Swap code,Get BX setup
          CALL absolute(bx, VARPTR(a(0)))     'Run Code
END SUB

SUB MousePointer (SW)
      
           POKE VARPTR(a(0)) + 1, SW         'Swap code,Set AX = (SW)
          CALL absolute(c, VARPTR(a(0)))     'Run Code

                                          'Note:
                                             'SW = 0-reset
                                             'SW = 1-on
                                             'SW = 2-off
                                             'SW = 3-coordinates


END SUB

SUB prockey (KE$)
   IF hpos < 250 THEN hpos = 250
  
  
   SELECT CASE KE$

   CASE IS = "J", CHR$(0) + "K"
  
    hpos = hpos - 5: IF hpos < 250 THEN hpos = 250
  
   CASE IS = "K", CHR$(0) + "M"
  
    hpos = hpos + 5: IF hpos > 300 THEN hpos = 300
  
   CASE IS = "M", CHR$(0) + "P"
    VPOS = VPOS + 5: IF VPOS > 185 THEN VPOS = 185
  
   CASE IS = "I", CHR$(0) + "H"
  
    VPOS = VPOS - 5: IF VPOS < 1 THEN VPOS = 1
  
          ' <F1>
   CASE IS = CHR$(0) + CHR$(59)

        LOCATE 22, 1
        INPUT "open file"; fi$
        CALL flop(fi$)





   CASE IS = CHR$(13)
    pncl = POINT(hpos + 5, VPOS + 5): LINE (240, 0)-(248, 200), pncl, BF



   END SELECT

  
  
    PUT (h1, v1), BOX%, PSET
  
    GET (hpos, VPOS)-(hpos + 10, VPOS + 10), BOX%

  
     CALL tg


      h1 = hpos: v1 = VPOS
    

END SUB

SUB tg


      h$ = "R" + STR$(hpos + 5)
      V$ = "D" + STR$(VPOS + 5)


      TARGET$ = "BU1U4BD10U4BU1BL5R4BR6L4"
    IF hpos >= 250 THEN
 
   DRAW "bm0,0b" + h$ + "b" + V$ + "c" + STR$(cc) + TARGET$
   END IF

     cc = cc + 1
     IF cc > 100 THEN cc = 0

END SUB

