home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / BBS_UTIL / BM0406_A.ZIP / BMASM.ZIP / XMODEM.ASM < prev    next >
Assembly Source File  |  1993-02-06  |  5KB  |  125 lines

  1. ; Modified 8/24/85 for use with QuickBasic Compiler
  2.  
  3. ; Heavy modifications 8/31/86 by Jim King
  4. ; Changed CRC_CALC from the awfulness it was to an algorithm suggested
  5. ; by Philip Burns.  In a test program, this algorithm is over 3 times as
  6. ; fast as the one previously used by RBBS-PC.
  7. ; Changed the loop that calculates checksum and calls the CRC to be more
  8. ; efficient (just about halved the number of instructions).
  9. ; Note that RBBS-PC.BAS was also modified so that it no longer tacks on
  10. ; two null bytes to the input string (they were necessary for the old CRC
  11. ; routine to work correctly).
  12. ; Once again, thanks to Philip Burns for suggesting the CRC algorithm.
  13. ; Many thanks also to John Souvestre, who helped me tweak the assembly
  14. ; routine to run even faster.
  15.  
  16. ; Modified 02/06/93 by Richie Molinelli
  17. ; Modified for use with BASIC v7.x /Fs (far string) compile option.
  18. ; Original mod for far strings done by Scott McNay.  Scott eliminated
  19. ; the 1K buffer for the string.  I reinstituted the buffer and retained
  20. ; the original code and logic for reference.  Many thanks to Scott McNay
  21. ; for the original breakthrough in adapting the .ASM routine for far string
  22. ; compatibility.
  23.  
  24.           EXTRN   StringAddress:FAR     ;FS020601
  25.  
  26. XM_CALC   SEGMENT PUBLIC 'CODE'
  27.           ASSUME CS:XM_CALC
  28.           PUBLIC XMODEM
  29. ;
  30. CHK_SUM           DB 0
  31. STRG_LEN          DW 0                  ;CHANGED TO LENGTH OF STRING PASSED
  32. STRG_LOC          DW 0
  33. STRG_MSG          DB 1026 DUP (' ')     ;COMMAND CHARS (+CR) GO INTO HERE
  34. ;
  35. ;
  36. ;
  37. XMODEM    PROC    FAR
  38.           PUSH    BP
  39.           MOV     BP,SP
  40.           MOV     CHK_SUM,0         ;INITIALIZE
  41. ;
  42. ;FS020601 MOV     SI,[BP+14]        ;GET STRING DESCRIPTOR
  43. ;FS020601 MOV     BL,[SI+ 2]        ;REARRANGE LOW/HIGH BYTES
  44. ;FS020601 MOV     BH,[SI+ 3]        ;NOW BX HOLDS THE ADDRESS OF THE STRING
  45. ;FS020601 MOV     STRG_LOC,BX       ;STORE IT
  46. ;FS020601 MOV     AX,[SI]           ;GET STRING LENGTH
  47. ;FS020601 MOV     STRG_LEN,AX       ;STORE IT
  48. ;
  49.           PUSH    [BP+14]           ;FS020601
  50.           CALL    StringAddress     ;FS020601
  51.           MOV     STRG_LOC,AX       ;FS020601 Save string address
  52.           MOV     STRG_LEN,CX       ;FS020601 Save string length
  53.           PUSH    DS                ;FS020601 Save DS
  54.           PUSH    DX                ;FS020601
  55.           POP     DS                ;FS020601 Set segment address
  56.           MOV     CX,CS:STRG_LEN        ;STORE LENGTH IN CX
  57.           MOV     SI,CS:STRG_LOC        ;STORE OFFSET TO STRING IN SI
  58.           PUSH    CS
  59.           POP     ES
  60.           MOV     DI,OFFSET STRG_MSG    ;ES:DI = LOCATION OF VARIABLE
  61.           REP     MOVSB                 ;FILL STRG_MSG WITH STRING
  62. ;
  63. ;FS020601 PUSH    DS                    ;SAVE DS
  64.           PUSH    CS
  65.           POP     DS
  66.  
  67.           MOV     CX,CS:STRG_LEN        ;INITIALIZE COUNTER
  68.       MOV      SI,OFFSET STRG_MSG    ;get address of input string
  69.           XOR     DX,DX            ;initialize CRC value to 0
  70. LOOP1:
  71.       LODSB                ;get character into AL
  72.           MOV     DI,CX                 ;SAVE CX
  73.           ADD     CHK_SUM,AL            ;ADD AL TO CHK_SUM
  74.  
  75. ; this used to be:
  76. ;CRC_CALC   PROC NEAR
  77. ; this is the CRC calculation routine.  It's placed here instead of in
  78. ; a separate procedure for additional speed.
  79. ; DX contains the CRC value, AL has the new character.  Other registers
  80. ; are used for temporary storage and scratch work.
  81.     XCHG    DH,DL            ; CRC := Swap(CRC) XOR Ord(Ch);
  82.     XOR    DL,AL
  83.  
  84.     MOV    AL,DL            ; CRC := CRC XOR ( Lo(CRC) SHR 4 );
  85.     MOV    CL,4
  86.     SHR    AL,CL
  87.     XOR    DL,AL
  88.  
  89.                     ; CRC := CRC XOR ( Swap(Lo(CRC)) SHL 4 )
  90.                     ;        XOR ( Lo(CRC) SHL 5 );
  91.     MOV    BL,DL
  92.     MOV    AH,DL
  93.     SHL    AH,CL
  94.     XOR    DH,AH
  95.     XOR    BH,BH
  96.     INC    CL
  97.     SHL    BX,CL
  98.     XOR    DX,BX
  99. ; end of the CRC calculation routine
  100.     
  101.           MOV     CX,DI                 ;RESTORE CX
  102.       LOOP      LOOP1            ;do it again
  103.  
  104.  
  105.           POP     DS                   ;RESTORE DS
  106.           MOV     BX,DX                ;PASS BACK THE CRC VALUE
  107.           MOV     SI,[BP+ 6]           ;AND CRC HIGH AND LOW BYTES
  108.           MOV     [SI],BL
  109.           MOV     SI,[BP+ 8]
  110.           MOV     [SI],BH
  111.           MOV     SI,[BP+10]
  112.           MOV     [SI],BX
  113.           MOV     BL,CS:CHK_SUM        ;PASS BACK THE CHECK SUM
  114.           MOV     SI,[BP+12]
  115.           MOV     [SI],BL
  116. ;
  117.           PUSH    CS                ;CLEAN UP WORK TO RETURN TO BASIC
  118.           POP     ES
  119.           POP     BP
  120.           RET     10
  121. XMODEM    ENDP
  122. XM_CALC   ENDS
  123.           END
  124. 
  125.