?login_element?

Subversion Repositories NedoOS

Rev

Rev 1850 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //TCRC=0x4000 ;size 0x400, divisible by 0x100
  2.  
  3. CS_SYMLEN       equ     8 ;length of checksum in ascii: 8 for CRC32
  4.  
  5. CS_NAME
  6.         db      "CRC-32 (0xEDB88320)",0
  7.  
  8. CS_PREPARE:     ; precalculate CRC table
  9.  
  10.         ;bcde - rotating value
  11.         ;hl - table pointer & counter
  12.  
  13.         ld      l,0
  14. .tbloop
  15.         ld      bc,8*256
  16.         ld      d,c
  17.         ld      e,c
  18.         ld      a,l     ;shift/xor value in CDEA
  19. .bitloop
  20.         srl     c
  21.         rr      d
  22.         rr      e
  23.         rra
  24.         jr      nc,.skipxor
  25.         exa
  26.         ld      a,c
  27.         xor     0xED
  28.         ld      c,a
  29.         ld      a,d
  30.         xor     0xB8
  31.         ld      d,a
  32.         ld      a,e
  33.         xor     0x83
  34.         ld      e,a
  35.         exa
  36.         xor     0x20
  37. .skipxor
  38.         djnz    .bitloop
  39.  
  40.         ld      h,TCRC/256
  41.         ld      [hl],a
  42.         inc     h
  43.         ld      [hl],e
  44.         inc     h
  45.         ld      [hl],d
  46.         inc     h
  47.         ld      [hl],c
  48.         inc     l
  49.         jr      nz,.tbloop
  50.        
  51.         ret
  52.  
  53.  
  54.  
  55.  
  56. CS_START:       ;start/init calculation anew
  57.                
  58.                 ld      hl,0xFFFF
  59.                 ld      [CRCArea+0],hl
  60.                 ld      [CRCArea+2],hl
  61.                 ret
  62.  
  63.  
  64. CS_APPEND:      ;append chunk of data to calculation
  65.                 ;in: bc - size
  66.                 ;in: hl - ptr
  67.        
  68.                 ;kills: everything
  69.  
  70.                 exx
  71.                 ld      bc,[CRCArea+0]
  72.                 ld      de,[CRCArea+2]
  73.                 exx
  74. .crc_loop
  75.         ld      a,[hl]          ;7
  76.         exx                     ;4
  77.  
  78.         xor     c               ;4
  79.         ld      l,a             ;4
  80.  
  81.         ld      h,TCRC/256      ;7
  82.         ld      a,[hl]          ;7
  83.         xor     b               ;4
  84.         ld      c,a             ;4
  85.  
  86.         inc     h               ;4
  87.         ld      a,[hl]          ;7
  88.         xor     e               ;4
  89.         ld      b,a             ;4
  90.  
  91.         inc     h               ;4
  92.         ld      a,[hl]          ;7
  93.         xor     d               ;4
  94.         ld      e,a             ;4
  95.  
  96.         inc     h               ;4
  97.         ld      d,[hl]          ;7
  98.  
  99.         exx                     ;4
  100.         cpi                     ;16
  101.         jp      pe,.crc_loop    ;10
  102.                                 ; == 120 tc/byte
  103.                
  104.                 exx
  105.                 ld      [CRCArea+0],bc
  106.                 ld      [CRCArea+2],de
  107.                 ret
  108.  
  109.  
  110. CS_FINALIZE:    ;finish calculation, generate asciiz string with checksum
  111.  
  112.                 ;in: HL - place of CS_SYMLEN+1 bytes to place asciiz string of checksum
  113.  
  114.                 ;kills: everything
  115.  
  116.                 push    hl
  117.  
  118.                 ld      hl,CRCArea+1
  119.                 ld      de,CRCArea+2
  120.  
  121.                  DUP    2
  122.                 ld      a,[hl]
  123.                 cpl
  124.                 ld      b,a
  125.                 ld      a,[de]
  126.                 cpl
  127.                 ld      [hl],a
  128.                 ld      a,b
  129.                 ld      [de],a
  130.                 dec     hl
  131.                 inc     de
  132.                  EDUP
  133.                 org     $-2
  134.  
  135.                 pop     de
  136.                 call    hexconv4
  137.                 xor     a
  138.                 ld      [de],a
  139.                 ret
  140.  
  141. hexconv4
  142.         call    hexconv2
  143. hexconv2
  144.         call    hexconv
  145. hexconv
  146.         ld      a,(hl)
  147.         rrca
  148.         rrca
  149.         rrca
  150.         rrca
  151.         call    .digit
  152.         ld      a,(hl)
  153.         inc     hl
  154. .digit
  155.         or      0xf0
  156.         daa
  157.         add     a,0xa0
  158.         adc     a,0x40
  159.         ld      [de],a
  160.         inc     de
  161.         ret
  162.  
  163.  
  164. CRCArea
  165.         ds 4,0xff
  166.  
  167.  
  168.         org     ($+255)&0xFF00
  169. TCRC    ds      0x400
  170.  
  171.