?login_element?

Subversion Repositories NedoOS

Rev

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

  1. ; The CHK macro causes a checksum to be computed and deposited at the current location.
  2. ; The starting point of the checksum calculation is indicated as an argument.
  3. ;
  4. ; The checksum is calculated as the simple arithmetic sum of all bytes starting
  5. ; at the provided address up to but not including the address of the CHK macro instance.
  6. ; The least significant byte is all that is used.
  7. ;
  8. ; The macro requires the virtual DEVICE memory (checksum needs access to previously
  9. ; defined machine code bytes).
  10.  
  11. ; CHK macro definition
  12.     MACRO .CHK address?
  13.         OPT push listoff
  14. .SUM = 0                        ; init values for checksumming
  15. .ADR = address? : ASSERT address? < $   ; starting address must be below current
  16.         DUP $ - address?        ; do simple sum of all bytes
  17. .SUM = .SUM + {B .ADR}
  18. .ADR = .ADR + 1
  19.         EDUP
  20.         OPT pop
  21.         DB      low .SUM
  22.     ENDM
  23.  
  24.     ; similar as .CHK macro, but does use XOR to calculate checksum
  25.     MACRO .CHKXOR address?
  26.         OPT push listoff
  27. .CSUM = 0                       ; init values for checksumming
  28. .ADR = address? : ASSERT address? < $   ; starting address must be below current
  29.         DUP $ - address?        ; do simple sum of all bytes
  30. .CSUM = .CSUM ^ {B .ADR}
  31. .ADR = .ADR + 1
  32.         EDUP
  33.         OPT pop
  34.         DB      .CSUM
  35.     ENDM
  36.  
  37. ; Examples and verification (ZX Spectrum 48 virtual device is used for the test)
  38.  
  39.     DEVICE ZXSPECTRUM48 : OUTPUT "sum_checksum.bin"
  40. TEST1   DB      'A'
  41.         .CHK    TEST1           ; expected 'A'
  42.  
  43. TEST2   DS      300, 'b'
  44.         DB      'B' - ((300*'b')&$FF)   ; adjust checksum to become 'B'
  45.         .CHK    TEST2           ; expected 'B'
  46.  
  47. TEST3   inc     hl              ; $23
  48.         inc     h               ; $24
  49.         .CHK    TEST3           ; expected 'G' ($47)
  50.  
  51. TESTXOR
  52.         HEX           20 50 49 38 30 20
  53.         HEX     20 20 20 20 20 43 01 00
  54.         HEX     40 08 40 20 20 20 20 20
  55.         HEX     20 43 41
  56.         .CHKXOR TESTXOR         ; expected $79
  57.