?login_element?

Subversion Repositories NedoOS

Rev

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

  1. ;Z80 depacker for megalz V4 packed files   (C) fyrex^mhm
  2.  
  3. ; DESCRIPTION:
  4. ;
  5. ; Depacker is fully relocatable, not self-modifying,
  6. ;it's length is 110 bytes starting from DEC40.
  7. ;Register usage: AF,AF',BC,DE,HL. Must be CALL'ed, return is done by RET.
  8. ;Provide extra stack location for store 2 bytes (1 word). Depacker does not
  9. ;disable or enable interrupts, as well as could be interrupted at any time
  10. ;(no f*cking wicked stack usage :).
  11.  
  12. ; USAGE:
  13. ;
  14. ; - put depacker anywhere you want,
  15. ; - put starting address of packed block in HL,
  16. ; - put location where you want data to be depacked in DE,
  17. ;   (much like LDIR command, but without BC)
  18. ; - make CALL to depacker (DEC40).
  19. ; - enjoy! ;)
  20.  
  21. ; PRECAUTIONS:
  22. ;
  23. ; Be very careful if packed and depacked blocks coincide somewhere in memory.
  24. ;Here are some advices:
  25. ;
  26. ; 1. put packed block to the highest addresses possible.
  27. ;     Best if last byte of packed block has address 0xFFFF.
  28. ;
  29. ; 2. Leave some gap between ends of packed and depacked block.
  30. ;     For example, last byte of depacked block at 0xFF00,
  31. ;     last byte of packed block at 0xFFFF.
  32. ;
  33. ; 3. Place nonpackable data to the end of block.
  34. ;
  35. ; 4. Always check whether depacking occurs OK and neither corrupts depacked data
  36. ;     nor hangs computer.
  37. ;
  38.  
  39. DEC40
  40.         LD      A,0x80
  41.         EX      AF,AF'
  42. MS      LDI
  43. M0      LD      BC,0x2FF
  44. M1      EX      AF,AF'
  45. M1X     ADD     A,A
  46.         JR      NZ,M2
  47.         LD      A,(HL)
  48.         INC     HL
  49.         RLA
  50. M2      RL      C
  51.         JR      NC,M1X
  52.         EX      AF,AF'
  53.        DJNZ    X2
  54.        LD      A,2
  55.        SRA     C
  56.        JR      C,N1
  57.        INC     A
  58.        INC     C
  59.        JR      Z,N2
  60.        LD      BC,0x33F
  61.        JR      M1
  62.  
  63. X2      DJNZ    X3
  64.        SRL     C
  65.        JR      C,MS
  66.        INC     B
  67.        JR      M1
  68. X6
  69.        ADD     A,C
  70. N2
  71.        LD      BC,0x4FF
  72.        JR      M1
  73. N1
  74.        INC     C
  75.        JR      NZ,M4
  76.        EX      AF,AF'
  77.         INC     B
  78. N5      RR      C
  79.         RET     C
  80.         RL      B
  81.         ADD     A,A
  82.         JR      NZ,N6
  83.         LD      A,(HL)
  84.         INC     HL
  85.         RLA
  86. N6      JR      NC,N5
  87.         EX      AF,AF'
  88.        ADD     A,B
  89.        LD      B,6
  90.        JR      M1
  91. X3
  92.        DJNZ    X4
  93.        LD      A,1
  94.        JR      M3
  95. X4      DJNZ    X5
  96.        INC     C
  97.        JR      NZ,M4
  98.        LD      BC,0x51F
  99.        JR      M1
  100. X5
  101.        DJNZ    X6
  102.        LD      B,C
  103. M4      LD      C,(HL)
  104.        INC     HL
  105. M3      DEC     B
  106.        PUSH    HL
  107.        LD      L,C
  108.        LD      H,B
  109.        ADD     HL,DE
  110.        LD      C,A
  111.        LD      B,0
  112.        LDIR
  113.        POP     HL
  114.        JR      M0
  115. END_DEC40
  116.  
  117.