User Tools

Site Tools


supercross_2000:ovln

This is an old revision of the document!


Table of Contents

OVLN

This is a compression format used by EA Games


The header takes up the first 0x15 bytes of the compressed file

Offset#BytesDescription
0x004“OVLN”
0x044Compressed size (including the header)
0x084RAM location to decompress
0x0C4RAM location to JAL to when done
0x102Magic Number. If it is 0x10FB then decompress, otherwise directly DMA with uncompressed size.
0x123Uncompressed size

Decompression Code

Python

ovln_parse.py
  1. def bytes_to_int24(arr, offset):
  2. return int.from_bytes(arr[offset:offset+4], byteorder='big') >> 8
  3.  
  4. def bytes_to_int_reversed(arr, offset):
  5. return int.from_bytes(arr[offset:offset+4], byteorder='little')
  6.  
  7. def ovln_memset(dst, dst_offset, value, amount):
  8. for i in range(amount):
  9. dst[dst_offset + i] = value
  10.  
  11. def ovln_memcpy(dst, dst_offset, dst_backwards_offset, amount):
  12. src_offset = dst_offset - dst_backwards_offset
  13. for i in range(amount):
  14. dst[dst_offset + i] = dst[src_offset + i]
  15.  
  16. def ovln_fetch_bytes(dst, dst_offset, dst_backwards_offset, amount):
  17. if dst_backwards_offset > 1:
  18. ovln_memcpy(dst, dst_offset, dst_backwards_offset, amount)
  19. else:
  20. ovln_memset(dst, dst_offset, dst[dst_offset - dst_backwards_offset], amount)
  21. return dst_offset + amount
  22.  
  23. def ovln_copy_literal(dst, dst_offset, src, src_offset, amount):
  24. for i in range(amount):
  25. dst[dst_offset + i] = src[src_offset + i]
  26.  
  27. # Input: src = compressed data list
  28. # Output: returns decompressed data list
  29. def ovln_parse(src):
  30. decompressed_size = bytes_to_int24(src, 0x12)
  31. dst = [0] * decompressed_size # Decompressed data list
  32. src_offset = 0x15
  33. dst_offset = 0
  34. while True:
  35. cmd = bytes_to_int_reversed(src, src_offset)
  36. if cmd & 0x80 == 0: # Covers commands 00 to 7F
  37. src_offset += 2
  38. # Copy bytes from the compressed data array
  39. amount_to_copy = cmd & 0x3
  40. ovln_copy_literal(dst, dst_offset, src, src_offset, amount_to_copy)
  41. src_offset += amount_to_copy
  42. dst_offset += amount_to_copy
  43. # Fetch bytes from previous decompressed data
  44. backward_fetch_offset = ((cmd << 3) & 0x300) + ((cmd >> 8) & 0xFF) + 1
  45. amount_of_bytes_to_fetch = ((cmd >> 2) & 0x7) + 3
  46. dst_offset = ovln_fetch_bytes(dst, dst_offset, backward_fetch_offset, amount_of_bytes_to_fetch)
  47. continue
  48. if cmd & 0x40 == 0: # Covers commands 0x80 to 0xBF
  49. # Copy bytes from the compressed data array
  50. src_offset += 3
  51. amount_to_copy = ((cmd >> 8) >> 6) & 0x3
  52. ovln_copy_literal(dst, dst_offset, src, src_offset, amount_to_copy)
  53. src_offset += amount_to_copy
  54. dst_offset += amount_to_copy
  55. # Fetch bytes from previous decompressed data
  56. backward_fetch_offset = (((cmd >> 8) << 8) & 0x3F00) + ((cmd >> 16) & 0xFF) + 1
  57. amount_of_bytes_to_fetch = (cmd & 0x3F) + 4
  58. dst_offset = ovln_fetch_bytes(dst, dst_offset, backward_fetch_offset, amount_of_bytes_to_fetch)
  59. continue
  60. if cmd & 0x20 == 0: # Covers commands 0xC0 to 0xDF
  61. src_offset += 4
  62. amount_to_copy = cmd & 0x3
  63. ovln_copy_literal(dst, dst_offset, src, src_offset, amount_to_copy)
  64. src_offset += amount_to_copy
  65. dst_offset += amount_to_copy
  66. # Fetch bytes from previous decompressed data
  67. backward_fetch_offset = ((cmd << 12) & 0x10000) + (((cmd >> 8) << 8) & 0xFF00) + 1 + ((cmd >> 16) & 0xFF)
  68. amount_of_bytes_to_fetch = ((cmd << 6) & 0x300) + ((cmd >> 24) & 0xFF) + 5
  69. dst_offset = ovln_fetch_bytes(dst, dst_offset, backward_fetch_offset, amount_of_bytes_to_fetch)
  70. continue
  71. src_offset += 1
  72. if (cmd & 0xFF) < 0xFC: # Covers commands 0xE0 to 0xFB
  73. # Copy bytes from the compressed data array
  74. amount_to_copy = ((cmd & 0x1F) + 1) * 4
  75. ovln_copy_literal(dst, dst_offset, src, src_offset, amount_to_copy)
  76. src_offset += amount_to_copy
  77. dst_offset += amount_to_copy
  78. continue
  79. if cmd & 3 != 0: # Copy any left-over bytes
  80. # Copy bytes from the compressed data array
  81. amount_to_copy = cmd & 0x3
  82. ovln_copy_literal(dst, dst_offset, src, src_offset, amount_to_copy)
  83. src_offset += amount_to_copy
  84. dst_offset += amount_to_copy
  85. break # A command of 0xFC, 0xFD, 0xFE, or 0xFF will end the decompression routine.
  86. return dst

supercross_2000/ovln.1562269516.txt.gz · Last modified: 2019/07/04 19:45 by David