![]() |
![]() |
Sega Megadrive Assembly Programming BasicsCopyright, Lewis Bassett, December 2005
Section 3 - TMSS Security Code Back in the day, a few companies started to produce unlicienced software for the Megadrive, which didn't make Sega very happy. To get around this, Sega implemented a Trade Mark Security System (TMSS). The TMSS expects a Megadrive program to write the string 'SEGA' to a certain register very soon after starting. If this is not done, the program will stop running, since the Megadrive's BIOS system would refuse it. There's an offcial code segment that Sega released to it's developers, which is inserted at the beginning of the program, straight after the header. We'll insert this into our header file ('Header.asm', in the 'lib\' directory) after the 'START' label. Here's the official routine, taken from disassemblies of some of the mainstream games, such as Sonic the Hedgehog: START: move.b $A10001, d0 andi.b #$0F, d0 beq WrongVersion move.l #'SEGA', $A14000 WrongVersion:Insert this at the end of the header file. Notice that the routine follows the 'START' label, which is defined in the interrupt vector. This label is where the program starts running, after the BIOS has accepted it. Address $a10001 contains the version number of the Megadrive. This is copied into register d0 and compared to the number for version 0, the first Megadrive distribution, which doesn't require the TMSS code. If address $a10001 contains another version number, the string 'SEGA' is copied to address $a14000, which is the TMSS register. After you've modified it with this TMSS code segment, you're header file should now look like this: ;******************************************* ;* SEGA Megadrive ROM Header * ;******************************************* InterruptVector: dc.l $00FFE000; Slot #1 : The address of the stack dc.l START; Slot #2 : The start of our program dc.l Interrupt; Slot #3 dc.l Interrupt; Slot #4 dc.l Interrupt; Slot #5 dc.l Interrupt; Slot #6 dc.l Interrupt; Slot #7 dc.l Interrupt; Slot #8 dc.l Interrupt; Slot #9 dc.l Interrupt; Slot #10 dc.l Interrupt; Slot #11 dc.l Interrupt; Slot #12 dc.l Interrupt; Slot #13 dc.l Interrupt; Slot #14 dc.l Interrupt; Slot #15 dc.l Interrupt; Slot #16 dc.l Interrupt; Slot #17 dc.l Interrupt; Slot #18 dc.l Interrupt; Slot #19 dc.l Interrupt; Slot #20 dc.l Interrupt; Slot #21 dc.l Interrupt; Slot #22 dc.l Interrupt; Slot #23 dc.l Interrupt; Slot #24 dc.l Interrupt; Slot #25 dc.l Interrupt; Slot #26 dc.l Interrupt; Slot #27 dc.l Interrupt; Slot #28 dc.l HBL; Slot #29 : VDP Horizontal Interrupt dc.l Interrupt; Slot #30 dc.l VBL; Slot #31 : VDP Vertical Interrupt dc.l Interrupt; Slot #32 dc.l Interrupt; Slot #33 dc.l Interrupt; Slot #34 dc.l Interrupt; Slot #35 dc.l Interrupt; Slot #36 dc.l Interrupt; Slot #37 dc.l Interrupt; Slot #38 dc.l Interrupt; Slot #39 dc.l Interrupt; Slot #40 dc.l Interrupt; Slot #41 dc.l Interrupt; Slot #42 dc.l Interrupt; Slot #43 dc.l Interrupt; Slot #44 dc.l Interrupt; Slot #45 dc.l Interrupt; Slot #46 dc.l Interrupt; Slot #47 dc.l Interrupt; Slot #48 dc.l Interrupt; Slot #49 dc.l Interrupt; Slot #50 dc.l Interrupt; Slot #51 dc.l Interrupt; Slot #52 dc.l Interrupt; Slot #53 dc.l Interrupt; Slot #54 dc.l Interrupt; Slot #55 dc.l Interrupt; Slot #56 dc.l Interrupt; Slot #57 dc.l Interrupt; Slot #58 dc.l Interrupt; Slot #59 dc.l Interrupt; Slot #60 dc.l Interrupt; Slot #61 dc.l Interrupt; Slot #62 dc.l Interrupt; Slot #63 dc.l Interrupt; Slot #64 GameInformation: dc.b "SEGA MEGA DRIVE "; Europe and Japan Console Name dc.b "(C)SEGA 2006.JAN"; Copyright date dc.b "SAMPLE PROGRAM "; Domestic Name dc.b "SAMPLE PROGRAM "; Overseas Name dc.b "GM 00000000-00"; Serial Number dc.w $a148; Checksum dc.b "J " I/O Support dc.l $00000000; ROM Start Address dc.l ROMEnd; ROM End Address dc.l $00ff0000; RAM Start Address dc.l $00ffffff; RAM End Address dc.b " "; No Modem or SRAM Support dc.b "DEMONSTRATION PROGRAM "; Memo dc.b "JUE "; Can be released in Japan, Europe and the US. START: move.b $A10001, d0 andi.b #$0F, d0 beq WrongVersion move.l #'SEGA', $A14000 WrongVersion:Save the modified file into the 'lib\' directory as 'Header.asm'. We can now insert the complete header and TMSS code into every program we write. In the next section, I'll explain how to pad out the ROM to a vallid size. |