home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / BBS_UTIL / BM0406_A.ZIP / BMASM.ZIP / MOVCSTR.ASM < prev    next >
Assembly Source File  |  1992-08-02  |  6KB  |  184 lines

  1. comment @
  2.  
  3.   Changes made by Scott McNay (1:395/11) July 26, 1992, to allow routine to be
  4.   used with code compiled with BC's /Fs option.  (Most) changes marked with
  5.   ;BCFS0726.  May have optimized some code also.  This is a plug-in replacement
  6.   for the original code.
  7.  
  8.   BCFS0801: Standardized code format.  Made sure that DI, SI, BP, and DS are
  9.   saved to meet requirements of BC 7.x.  Replace usage of BL with DL and SI
  10.   with BX to keep from having to save SI (getting nitpicky, huh?)
  11.  
  12.  *  MOVECURSTR
  13.  *----------------------------------------------------------------------------
  14.  *
  15.  *  Routine to generate an ANSI move cursor string
  16.  *
  17.  *  Author: Tom Collins
  18.  *        09-20-90
  19.  *
  20.  *  Calling Sequence:
  21.  *
  22.  *    A$ = SPACE$(8)
  23.  *    CALL MoveCurStr(OldY, OldX, NewY, NewX, A$, ALen)
  24.  *    A$ = LEFT$(A$, ALen)
  25.  *    Call QuickTput(A$, 0)
  26.  *
  27.  *  Returns:
  28.  *    ANSI string in A$
  29.  *    Length of string in ALen
  30.  *    OldX = NewX
  31.  *    OldY = NewY
  32.  *
  33.  *  Assemble with: TASM movcstr.asm [/Zi]   or,
  34.  *           MASM movcstr.asm [/Zi]
  35.  *  (Zi = Debug info for CV)
  36.  *
  37.     @
  38.  
  39.     extrn    StringAddress:far
  40.  
  41.     .MODEL   MEDIUM, BASIC
  42.  
  43.     .CODE
  44.  
  45.     PUBLIC   MOVECURSTR
  46.     PUBLIC   ITOA
  47.  
  48. ITOA   proc
  49.  
  50. ; Optimized (i.e., rewritten) by Scott McNay to shorten code and speed up.
  51.  
  52.     aam            ; Divide by 10, AH=quotient, AL=remainder     ;BCFS0726
  53.     add    ax,'00'        ; Convert to ASCII                  ;BCFS0726
  54.     cmp    ah,'0'        ; If first digit is 0, don't send it          ;BCFS0726
  55.     je    IT01                                  ;BCFS0726
  56.     mov    es:[di],ah    ; Send first digit                  ;BCFS0726
  57.     inc    di                                  ;BCFS0726
  58.     inc    cx        ; Increment count                  ;BCFS0726
  59. IT01:    stosb                                      ;BCFS0726
  60.     inc    cx                                  ;BCFS0726
  61.     ret            ; Done                          ;BCFS0726
  62.  
  63. ITOA    endp
  64.  
  65.  
  66. MOVECURSTR    proc USES es di, OLDY:ptr, OLDX:ptr, NEWY:ptr, NEWX:ptr, A:ptr, ALEN:ptr ;BCFS0801
  67.  
  68.     push    A                                  ;BCFS0726
  69.     call    StringAddress                              ;BCFS0726
  70.     mov    di,ax                                  ;BCFS0726
  71.     mov    es,dx                                  ;BCFS0726
  72.  
  73. ; Build the ANSI header = ESC [
  74.  
  75.     mov    al, 01Bh    ; AL = ESC
  76.     stosb            ; Save it to A$
  77.     mov    al, '['        ; AL = '['
  78.     stosb            ; Save it to A$
  79.     mov    cx, 3        ; CX = New ALEN                      ;BCFS0726
  80.  
  81. ; Get NEWX and NEWY in AL and AH
  82.  
  83.     mov    bx, NEWX    ; DS:BX -> NEWX                      ;BCFS0801
  84.     mov    al, [bx]    ; AL = NEWX                      ;BCFS0801
  85.     mov    bx, NEWY    ; DS:BX -> NEWY                      ;BCFS0801
  86.     mov    ah, [bx]    ; AH = NEWY                      ;BCFS0801
  87.  
  88. ; See if NEWX = NEWY = 0
  89.  
  90.     and    ax, ax        ; Set the flags
  91.     jz    MC15        ; NEWX = NEWY = 0.  Return.
  92.  
  93.     cmp    ax, 0101h    ; See if NEWX = NEWY = 1
  94.     jnz    MC02        ; No
  95.  
  96. ; NEWX = NEWY = 1.  Set string to ESC [f
  97.  
  98.     mov    byte ptr es:[di], 'H' ; Set up the A$ string              ;BCFS0726
  99.     jmp    short MC16    ; Return
  100.  
  101. ; Get the differences between the OLD and NEW strings in AX
  102.  
  103. MC02:    mov    bx, OLDX    ; DS:BX -> OLDX                      ;BCFS0801
  104.     sub    al, [bx]    ; AL = NEWX - OLDX                  ;BCFS0801
  105.     mov    bx, OLDY    ; DS:BX -> OLDY                      ;BCFS0801
  106.     sub    ah, [bx]    ; AH = NEWY - OLDY                  ;BCFS0801
  107.  
  108. ; See whether the X or Y or both changed.
  109.  
  110.     and    ax, ax        ; Set the flags
  111.     jz    MC15        ; Neither changed
  112.  
  113.     and    al, al        ; Set the flags
  114.     jz    MC03        ; X didn't change.  Just Y.
  115.  
  116.     and    ah, ah        ; X changed.  See if Y did.
  117.     jz    MC05        ; No
  118.  
  119. ; Both X and Y changed.  Build a string containing ESC [ NEWY ; NEWX f
  120.  
  121.     mov    bx, NEWY    ; DS:BX -> NEWY                      ;BCFS0801
  122.     mov    ax, [bx]    ; AX = NEWY                      ;BCFS0801
  123.     call    ITOA        ; Convert NEWY to a string
  124.     mov    al, ';'        ; Add the semicolon
  125.     stosb
  126.     inc    cx        ; Correct the string length
  127.     mov    bx, NEWX    ; DS:BX -> NEWX                      ;BCFS0801
  128.     mov    ax, [bx]    ; AX = NEWX                      ;BCFS0801
  129.     call    ITOA        ; Convert NEWX to a string
  130.     mov    byte ptr es:[di], 'H' ; Add the trailing character          ;BCFS0726
  131.     jmp    short MC16    ; Done
  132.  
  133. ; Just the Y coordinate changed.  Build ESC [ nn B (or A)
  134.  
  135. MC03:    mov    bx, OLDY    ; DS:BX -> OLDY                      ;BCFS0801
  136.     mov    ax, [bx]    ; AX = OLDY                      ;BCFS0801
  137.     mov    bx, NEWY    ; DS:BX -> NEWY                      ;BCFS0801
  138.     sub    ax, [bx]    ; AX = OLDY - NEWY                  ;BCFS0801
  139.     mov    dl, 'A'        ; Trailing character is 'A' (move up)          ;BCFS0801
  140.     jmp    short MC06    ; Do the string
  141.  
  142. ; Just the X coordinate changed.  Build ESC [ nn C (or D)
  143.  
  144. MC05:    mov    bx, NEWX    ; DS:BX -> NEWX                      ;BCFS0801
  145.     mov    ax, [bx]    ; AX = NEWX                      ;BCFS0801
  146.     mov    bx, OLDX    ; DS:BX -> OLDX                      ;BCFS0801
  147.     sub    ax, [bx]    ; AX = NEWX - OLDX                  ;BCFS0801
  148.     mov    dl, 'C'        ; Trailing character is 'C' (move right)      ;BCFS0801
  149.  
  150. MC06:    cmp    ax, 0        ; See if AX is positive
  151.     jg    MC07        ; Yes
  152.     neg    ax        ; No.  Make it positive
  153.     inc    dl        ; Increment trailing character              ;BCFS0801
  154. MC07:    call    ITOA        ; Convert AX to a string
  155.     mov    es:[di], dl    ; Add the trailing character              ;BCFS0801
  156.     jmp    short MC16    ; Return
  157.  
  158. ; One of the coordinates is zero (illegal), or no change is required.
  159.  
  160. MC15:    mov    bx, ALEN    ; DS:BX -> ALEN                      ;BCFS0801
  161.     mov    BYTE PTR[bx], 0 ; New ALEN is zero                  ;BCFS0801
  162.     ret            ; Return
  163.  
  164. ; Normal return
  165.  
  166. MC16:    mov    bx, ALEN    ; DS:BX -> ALEN                      ;BCFS0801
  167.     mov    [bx], cx    ; Save CX to ALEN                  ;BCFS0801
  168.  
  169.     mov    bx, NEWX    ; DS:BX -> NEWX                      ;BCFS0801
  170.     mov    al, [bx]    ; AL = NEWX                      ;BCFS0801
  171.     mov    bx, OLDX    ; DS:BX -> OLDX                      ;BCFS0801
  172.     mov    [bx], al    ; OLDX = NEWX                      ;BCFS0801
  173.  
  174.     mov    bx, NEWY    ; DS:BX -> NEWY                      ;BCFS0801
  175.     mov    al, [bx]    ; AL = NEWY                      ;BCFS0801
  176.     mov    bx, OLDY    ; DS:BX -> OLDY                      ;BCFS0801
  177.     mov    [bx], al    ; OLDY = NEWY                      ;BCFS0801
  178.  
  179.     ret            ; Return
  180.  
  181. MOVECURSTR endp
  182.  
  183.     end
  184.