PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/kaa-metadata-0.7.7/src/games/gameboy.py

#
Python | 99 lines | 33 code | 21 blank | 45 comment | 6 complexity | 70a6422d2f20786f367d40e916766f50 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- coding: iso-8859-1 -*-
  2. # -----------------------------------------------------------------------------
  3. # gameboy.py - Gameboy ROM parsing
  4. # -----------------------------------------------------------------------------
  5. # $Id: gameboy.py 3647 2008-10-25 19:52:16Z hmeine $
  6. #
  7. # -----------------------------------------------------------------------------
  8. # kaa-Metadata - Media Metadata for Python
  9. # Copyright (C) 2003-2006 Thomas Schueppel, Dirk Meyer
  10. #
  11. # First Edition: Richard Mottershead <richard.mottershead@v21net.co.uk>
  12. # Maintainer: Richard Mottershead <richard.mottershead@v21net.co.uk>
  13. #
  14. # Please see the file AUTHORS for a complete list of authors.
  15. #
  16. # This program is free software; you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation; either version 2 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful, but
  22. # WITHOUT ANY WARRANTY; without even the implied warranty of MER-
  23. # CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  24. # Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License along
  27. # with this program; if not, write to the Free Software Foundation, Inc.,
  28. # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. #
  30. # -----------------------------------------------------------------------------
  31. __all__ = ['Parser']
  32. # python imports
  33. import logging
  34. # kaa.metadata.games core import
  35. import core
  36. # get logging object
  37. log = logging.getLogger('metadata')
  38. # interesting file format info:
  39. # GameBoy Advance http://www.forums.emuita.it/index.php?showtopic=67255
  40. GBA_LOGOCODE = '\x24\xff\xae\x51\x69\x9a\xa2\x21\x3d\x84\x82\x0a\x84\xe4\x09\xad\x11\x24\x8b\x98\xc0\x81\x7f\x21\xa3\x52\xbe\x19\x93\x09\xce\x20\x10\x46\x4a\x4a\xf8\x27\x31\xec\x58\xc7\xe8\x33\x82\xe3\xce\xbf\x85\xf4\xdf\x94\xce\x4b\x09\xc1\x94\x56\x8a\xc0\x13\x72\xa7\xfc\x9f\x84\x4d\x73\xa3\xca\x9a\x61\x58\x97\xa3\x27\xfc\x03\x98\x76\x23\x1d\xc7\x61\x03\x04\xae\x56\xbf\x38\x84\x00\x40\xa7\x0e\xfd\xff\x52\xfe\x03\x6f\x95\x30\xf1\x97\xfb\xc0\x85\x60\xd6\x80\x25\xa9\x63\xbe\x03\x01\x4e\x38\xe2\xf9\xa2\x34\xff\xbb\x3e\x03\x44\x78\x00\x90\xcb\x88\x11\x3a\x94\x65\xc0\x7c\x63\x87\xf0\x3c\xaf\xd6\x25\xe4\x8b\x38\x0a\xac\x72\x21\xd4\xf8\x07'
  41. GB_LOGOCODE = '\xCE\xED\x66\x66\xCC\x0D\x00\x0B\x03\x73\x00\x83\x00\x0C\x00\x0D\x00\x08\x11\x1F\x88\x89\x00\x0E\xDC\xCC\x6E\xE6\xDD\xDD\xD9\x99\xBB\xBB\x67\x63\x6E\x0E\xEC\xCC\xDD\xDC\x99\x9F\xBB\xB9\x33\x3E'
  42. class Gameboy(core.Game):
  43. def __init__(self,file):
  44. core.Game.__init__(self)
  45. # Determine if the ROM is a Gameboy Advance ROM.
  46. # Compare the Logo Code. All GBA Roms have this code.
  47. file.seek(4)
  48. if file.read(156) != GBA_LOGOCODE:
  49. # Determine if the ROM is a Standard Gameboy ROM
  50. # Compare the Logo Code. All GB Roms have this code.
  51. file.seek (260)
  52. if file.read(len(GB_LOGOCODE)) != GB_LOGOCODE:
  53. raise core.ParseError()
  54. # Retrieve the ROM Title
  55. game_title = file.read(15)
  56. self.title = game_title
  57. # Retrieve the Rom Type (GB Colour or GB)j
  58. if file.read(1) == '\x80':
  59. self.mime = 'games/gbc'
  60. self.type = 'GameBoyColour game'
  61. else:
  62. self.mime = 'games/gb'
  63. self.type = 'GameBoy game'
  64. else:
  65. self.mime = 'games/gba'
  66. self.type = 'GameBoyAdvance game'
  67. # Retrieve the ROM Title
  68. game_title = file.read(12)
  69. self.title = game_title
  70. # Retrieve the Game Code
  71. game_code = file.read(4)
  72. # Retrieve the Manufacturer Code
  73. maker_code = file.read(2)
  74. log.debug("MAKER CODE: %s" % maker_code)
  75. # Check that the Fized Value is 0x96, if not then error.
  76. if file.read(1) != '\x96':
  77. raise core.ParseError()
  78. Parser = Gameboy