home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / CDOR0811.ZIP / SOURCE.ZIP / XMODEM.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-01-23  |  3.3 KB  |  105 lines

  1. ;
  2. ; Changes made by Scott McNay (1:395/11) July 26, 1992, to allow routine to be
  3. ; used with code compiled with BC's /Fs option.  (Most) changes marked with
  4. ; ;BCFS0726.  May have optimized some code also.  This is a plug-in replacement
  5. ; for the original code.
  6.  
  7. ;BCFS0801: Standardized code format.  Made sure that DI, SI, BP, and DS are
  8. ;  saved to meet requirements of BC 7.x.
  9. ;  Why bother having a temp buffer??  Got rid of it.  Will save the 1K overhead
  10. ;  of the buffer and the time overhead of copying 1K of data.  Got rid of all
  11. ;  variables.
  12.  
  13. ; Modified 8/24/85 for use with QuickBasic Compiler
  14.  
  15. ; Heavy modifications 8/31/86 by Jim King
  16. ; Changed CRC_CALC from the awfulness it was to an algorithm suggested
  17. ; by Philip Burns.  In a test program, this algorithm is over 3 times as
  18. ; fast as the one previously used by RBBS-PC.
  19. ; Changed the loop that calculates checksum and calls the CRC to be more
  20. ; efficient (just about halved the number of instructions).
  21. ; Note that RBBS-PC.BAS was also modified so that it no longer tacks on
  22. ; two null bytes to the input string (they were necessary for the old CRC
  23. ; routine to work correctly).
  24. ; Once again, thanks to Philip Burns for suggesting the CRC algorithm.
  25. ; Many thanks also to John Souvestre, who helped me tweak the assembly
  26. ; routine to run even faster.
  27.  
  28.     Extrn    StringAddress:far                          ;BCFS0726
  29.  
  30. XM_CALC    SEGMENT PUBLIC 'CODE'
  31.     ASSUME    CS:XM_CALC
  32.     PUBLIC    XMODEM
  33.  
  34. XMODEM    PROC    FAR
  35. INT    3    ;For debugging.  Remove when operation verified
  36.     PUSH    BP
  37.     MOV    BP,SP
  38. ;
  39.     PUSH    DI                                  ;BCFS0801
  40.     PUSH    SI                                  ;BCFS0801
  41.     PUSH    DS                                      ;BCFS0726
  42.     PUSH    [BP+14]        ;GET A$ STRING DESCRIPTOR ADDRESS          ;BCFS0726
  43.     CALL    StringAddress                              ;BCFS0726
  44.     MOV    SI,AX                                  ;BCFS0726
  45.     MOV    DS,DX                                  ;BCFS0726
  46.     XOR    BP,BP        ;INITIALIZE CHECKSUM                  ;BCFS0801
  47. ;
  48.     XOR    DX,DX        ;initialize CRC value to 0
  49. LOOP1:
  50.     LODSB            ;get character into AL
  51.     MOV    DI,CX        ;SAVE CX
  52.     ADD    BP,AX        ;ADD AL TO CHECKSUM                  ;BCFS0801
  53.  
  54. ; this used to be:
  55. ;CRC_CALC   PROC NEAR
  56. ; this is the CRC calculation routine.  It's placed here instead of in
  57. ; a separate procedure for additional speed.
  58. ; DX contains the CRC value, AL has the new character.  Other registers
  59. ; are used for temporary storage and scratch work.
  60.     XCHG    DH,DL        ; CRC := Swap(CRC) XOR Ord(Ch);
  61.     XOR    DL,AL
  62.  
  63.     MOV    AL,DL        ; CRC := CRC XOR ( Lo(CRC) SHR 4 );
  64.     MOV    CL,4
  65.     SHR    AL,CL
  66.     XOR    DL,AL
  67.  
  68.                 ; CRC := CRC XOR ( Swap(Lo(CRC)) SHL 4 )
  69.                 ;    XOR ( Lo(CRC) SHL 5 );
  70.     MOV    BL,DL
  71.     MOV    AH,DL
  72.     SHL    AH,CL
  73.     XOR    DH,AH
  74.     XOR    BH,BH
  75.     INC    CL
  76.     SHL    BX,CL
  77.     XOR    DX,BX
  78. ; end of the CRC calculation routine
  79.     
  80.     MOV    CX,DI        ;RESTORE CX
  81.     LOOP    LOOP1        ;do it again
  82.  
  83.  
  84.     POP    DS        ;RESTORE DS
  85.     POP    SI                                  ;BCFS0801
  86.     POP    DI                                  ;BCFS0801
  87.     MOV    CX,BP                                  ;BCFS0801
  88.     MOV    BP,SP                                  ;BCFS0801
  89.     MOV    AX,DX        ;PASS BACK THE CRC VALUE              ;BCFS0801
  90.     MOV    BX,[BP+ 6]    ;AND CRC HIGH AND LOW BYTES              ;BCFS0801
  91.     MOV    [BX],AL                                  ;BCFS0801
  92.     MOV    BX,[BP+ 8]                              ;BCFS0801
  93.     MOV    [BX],AH                                  ;BCFS0801
  94.     MOV    BX,[BP+10]                              ;BCFS0801
  95.     MOV    [BX],AX                                  ;BCFS0801
  96.     MOV    AL,CL        ;PASS BACK THE CHECK SUM              ;BCFS0801
  97.     MOV    BX,[BP+12]                              ;BCFS0801
  98.     MOV    [BX],AL                                  ;BCFS0801
  99. ;
  100.     POP    BP
  101.     RET    10
  102. XMODEM    ENDP
  103. XM_CALC    ENDS
  104.     END
  105.