don't click here

MD shenanigans

Discussion in 'General Sega Discussion' started by Sik, May 2, 2010.

  1. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    Manual complement

    Probably the biggest WTF in the main docs is the complete lack of information on how to read the controller. No, seriously - it says how to access the I/O ports, but it completely forgets to mention how the standard controller is meant to be read. I guess Sega just assumed that developers would use the subroutine in the Logo Demo.

    That said, the "Genesis Technical Bulletin #28" makes a mention to a complement manual:
    I never saw any such doc. Am I missing something or that one hasn't been leaked yet?

    RAM disk

    In the "Genesis Technical Bulletin #4", the following code can be found:
    Code (ASM):
    1. ;*******************************************************;
    2. ;                                                       ;
    3. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
    4. ;       input   a6.l = controller port address          ;
    5. ;       output  d7.b == $00     Modem                   ;
    6. ;                       $0d     Mega Drive Joy Stick    ;
    7. ;                       $0e     Ram Disk                ;
    8. ;                       $0f     ETC. or None            ;
    9. ;       use     d0,a0                                   ;
    10. ;*******************************************************;
    RAM disk? Huh? o_O

    At first I thought it could have been a generic drive thingy. For instance, the bit in $A10001 that was meant to indicate the presence of a floppy drive later got reused to indicate the presence of a Mega CD. Now, of course, the Mega CD is not connected to any of the standard I/O ports... and in fact, I can't think on any drive-like device that does. Does anybody know anything about this?

    To make it worse, the subroutine code is incomplete, at least in the copy I have. Maybe somebody else has the full code. Here's what I have of the code (which is as useless as shit):
    Code (ASM):
    1. cont            set     $0006
    2.  
    3. con_port:
    4.                 movem.l d1-d2/a5,-(sp)          ; register push
    5.                 dis
    6.                 z80_diw
    7.                 lea     ??and_data(pc),a5       ; data table address set
    8.                 move.b  (a5),cont(a6)           ; Th bit set output
    9.                 moveq.l #0,d7                   ; rerturn register initial
    10.                 moveq.l #$08,d1                 ; counter set
    Can somebody look for that piece of code in the leaked devkits, please? (sidenote: "con_port" may be wrong, the second and third letters are unreadable...)

    Wordram at $600000?

    In the 32x runlength demo, the following piece of code is in "68K/MD.I":
    Code (ASM):
    1. wordram     equ $600000
    What the fuck?

    First I checked the 32x docs just in case, and indeed there is no memory at that address (at least, documented). I noticed that the SH2 RAM addresses are at a similar place... except it's $6000000, not $600000. Also, this file is used by the 68k code, not SH2 code. All other addresses in the file seem to be OK as well... Oh, and a last thing: the 68k code never references this label, at all.

    Was the 32x planned to have extra 68k RAM at some point, maybe?

    Sega Subor System Cartridge

    There is one ROM image floating around labeled "Sega Subor System Cartridge (Unl).bin". If you try to run it, the program will not boot. When I tried this, the first thing I thought was that the program required custom hardware, just like about every single unlicensed crap out there =/ But then I checked into the ROM image, and huh...
    Code (Text):
    1. $000100 ... 4145 4141 004D 4547 0020 4052 4056 0020   AEAA.MEG. @R@V.
    2. $000110 ... 0043 0858 5858 0020 3030 3030 0444 4143   .C.XXX. 0000.DAC
    3. $000120 ... 8081 9397 809E 8888 0020 8080 9092 8088   ......... ......
    4. $000130 ... 8486 2020 2020 2020 2020 2020 2020 2020   ..              
    5. $000140 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    6. $000150 ... 4445 4052 4849 4647 0053 4454 2020 2020   [email protected]    
    7. $000160 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    8. $000170 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    9. $000180 ... 454D 2030 3030 3030 3030 202D 3030 0000   EM 0000000 -00..
    10. $000190 ... 0020 2020 2020 2020 2020 2020 2020 2020   .              
    11. $0001A0 ... 0000 0000 0004 0000 00FF 0000 00FF FFFF   ................
    12. $0001B0 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    13. $0001C0 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    14. $0001D0 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    15. $0001E0 ... 2020 2020 2020 2020 2020 2020 2020 2020                  
    16. $0001F0 ... 4055 0020 2020 2020 2020 2020 2020 2020   @U.
    Looks like a bad dump. Does anybody know if there's a good dump of this thing?
     
  2. sasuke

    sasuke

    Member
    66
    0
    0
    I don't know much about the other stuff, but I think I can answer this question:

    I believe this is the 256K Word Ram for the Sega CD when a cartridge is running. According to a Sega CD manual I read and Mask of Destiny's Transfer Suite website, there is a pin in the cartridge, B32 to be exact, that determines whether to boot from the cartridge or the expansion port, where the Sega CD is connected. When it is high, it boots the cartridge and sets the expansion port's memory to the next 4MB. When the pin is low (used for Sega CD ram expansions), they are swapped. Since the Word Ram starts at address $200000 when the Sega CD boots, it would make sense to start at address $200000 + $400000, or $600000, when a cartridge boots.
     
  3. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    I do believe this is correct. As to the controllers, SEGA put out some sample code which isn't very good, so most devs just make their own. Here's my controller code for 3 button, 6 button, and the MegaMouse - feel free to use it as you wish.

    Code (Text):
    1. | get current pad value
    2. | entry: a0 = pad control port
    3. | exit:  d2 = pad value (0 0 0 1 M X Y Z S A C B R L D U) or (0 0 0 0 0 0 0 0 S A C B R L D U)
    4. get_pad:
    5.         bsr.b   get_input       /* - 0 s a 0 0 d u - 1 c b r l d u */
    6.         move.w  d0,d1
    7.         andi.w  #0x0C00,d0
    8.         bne.b   no_pad
    9.         bsr.b   get_input       /* - 0 s a 0 0 d u - 1 c b r l d u */
    10.         bsr.b   get_input       /* - 0 s a 0 0 0 0 - 1 c b m x y z */
    11.         move.w  d0,d2
    12.         bsr.b   get_input       /* - 0 s a 1 1 1 1 - 1 c b r l d u */
    13.         andi.w  #0x0F00,d0      /* 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 */
    14.         cmpi.w  #0x0F00,d0
    15.         beq.b   common          /* six button pad */
    16.         move.w  #0x010F,d2      /* three button pad */
    17. common:
    18.         lsl.b   #4,d2           /* - 0 s a 0 0 0 0 m x y z 0 0 0 0 */
    19.         lsl.w   #4,d2           /* 0 0 0 0 m x y z 0 0 0 0 0 0 0 0 */
    20.         andi.w  #0x303F,d1      /* 0 0 s a 0 0 0 0 0 0 c b r l d u */
    21.         move.b  d1,d2           /* 0 0 0 0 m x y z 0 0 c b r l d u */
    22.         lsr.w   #6,d1           /* 0 0 0 0 0 0 0 0 s a 0 0 0 0 0 0 */
    23.         or.w    d1,d2           /* 0 0 0 0 m x y z s a c b r l d u */
    24.         eori.w  #0x1FFF,d2      /* 0 0 0 1 M X Y Z S A C B R L D U */
    25.         rts
    26.  
    27. no_pad:
    28.         move.w  #0xF000,d2
    29.         rts
    30.  
    31. | read single phase from controller
    32. get_input:
    33.         move.b  #0x00,(a0)
    34.         nop
    35.         nop
    36.         move.b  (a0),d0
    37.         move.b  #0x40,(a0)
    38.         lsl.w   #8,d0
    39.         move.b  (a0),d0
    40.         rts
    41.  
    42. | get current mouse value
    43. | entry: a0 = mouse control port
    44. | exit:  d0 = mouse value (0  0  0  0  0  0  0  0  YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0) or -2 (timeout) or -1 (no mouse)
    45. get_mky:
    46.         move.w  sr,d2
    47.         move.w  #0x2700,sr      /* disable ints */
    48.  
    49.         move.b    #0x60,6(a0)     /* set direction bits */
    50.         nop
    51.         nop
    52.         move.b  #0x60,(a0)      /* first phase of mouse packet */
    53.         nop
    54.         nop
    55. 0:
    56.         btst    #4,(a0)
    57.         beq.b   0b              /* wait on handshake */
    58.         move.b  (a0),d0
    59.         andi.b  #15,d0
    60.         bne     mky_err         /* not 0 means not mouse */
    61.  
    62.         move.b  #0x20,(a0)      /* next phase */
    63.         move.w  #254,d1         /* number retries before timeout */
    64. 1:
    65.         btst    #4,(a0)
    66.         bne.b   2f              /* handshake */
    67.         dbra    d1,1b
    68.         bra     timeout_err
    69. 2:
    70.         move.b  (a0),d0
    71.         andi.b  #15,d0
    72.         move.b  #0,(a0)         /* next phase */
    73.         cmpi.b  #11,d0
    74.         bne     mky_err         /* not 11 means not mouse */
    75. 3:
    76.         btst    #4,(a0)
    77.         beq.b   4f              /* handshake */
    78.         dbra    d1,3b
    79.         bra     timeout_err
    80. 4:
    81.         move.b  (a0),d0         /* specs say should be 15 */
    82.         nop
    83.         nop
    84.         move.b  #0x20,(a0)      /* next phase */
    85.         nop
    86.         nop
    87. 5:
    88.         btst    #4,(a0)
    89.         bne.b   6f
    90.         dbra    d1,5b
    91.         bra     timeout_err
    92. 6:
    93.         move.b  (a0),d0         /* specs say should be 15 */
    94.         nop
    95.         nop
    96.         move.b  #0,(a0)         /* next phase */
    97.         moveq   #0,d0           /* clear reg to hold packet */
    98.         nop
    99. 7:
    100.         btst    #4,(a0)
    101.         beq.b   8f              /* handshake */
    102.         dbra    d1,7b
    103.         bra     timeout_err
    104. 8:
    105.         move.b  (a0),d0         /* YO XO YS XS */
    106.         move.b  #0x20,(a0)      /* next phase */
    107.         lsl.w   #8,d0           /* save nibble */
    108. 9:
    109.         btst    #4,(a0)
    110.         bne.b   10f             /* handshake */
    111.         dbra    d1,9b
    112.         bra     timeout_err
    113. 10:
    114.         move.b  (a0),d0         /* S  M  R  L */
    115.         move.b  #0,(a0)         /* next phase */
    116.         lsl.b   #4,d0           /* YO XO YS XS S  M  R  L  0  0  0  0 */
    117.         lsl.l   #4,d0           /* YO XO YS XS S  M  R  L  0  0  0  0  0  0  0  0 */
    118. 11:
    119.         btst    #4,(a0)
    120.         beq.b   12f             /* handshake */
    121.         dbra    d1,11b
    122.         bra     timeout_err
    123. 12:
    124.         move.b  (a0),d0         /* X7 X6 X5 X4 */
    125.         move.b  #0x20,(a0)      /* next phase */
    126.         lsl.b   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 0  0  0  0 */
    127.         lsl.l   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 0  0  0  0  0  0  0  0 */
    128. 13:
    129.         btst    #4,(a0)
    130.         bne.b   14f             /* handshake */
    131.         dbra    d1,13b
    132.         bra     timeout_err
    133. 14:
    134.         move.b  (a0),d0         /* X3 X2 X1 X0 */
    135.         move.b  #0,(a0)         /* next phase */
    136.         lsl.b   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 0  0  0  0 */
    137.         lsl.l   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 0  0  0  0  0  0  0  0 */
    138. 15:
    139.         btst    #4,(a0)
    140.         beq.b   16f             /* handshake */
    141.         dbra    d1,15b
    142.         bra     timeout_err
    143. 16:
    144.         move.b  (a0),d0         /* Y7 Y6 Y5 Y4 */
    145.         move.b  #0x20,(a0)      /* next phase */
    146.         lsl.b   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 0  0  0  0 */
    147.         lsl.l   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 0  0  0  0  0  0  0  0*/
    148. 17:
    149.         btst    #4,(a0)
    150.         beq.b   18f             /* handshake */
    151.         dbra    d1,17b
    152.         bra     timeout_err
    153. 18:
    154.         move.b  (a0),d0         /* Y3 Y2 Y1 Y0 */
    155.         move.b  #0x60,(a0)      /* first phase */
    156.         lsl.b   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 0  0  0  0 */
    157.         lsr.l   #4,d0           /* YO XO YS XS S  M  R  L  X7 X6 X5 X4 X3 X2 X1 X0 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
    158. 19:
    159.         btst    #4,(a0)
    160.         beq.b   19b             /* wait on handshake */
    161.  
    162.         move.w  d2,sr           /* restore int status */
    163.         rts
    164.  
    165. timeout_err:
    166.         move.b  #0x60,(a0)      /* first phase */
    167.         nop
    168.         nop
    169. 0:
    170.         btst    #4,(a0)
    171.         beq.b   0b              /* wait on handshake */
    172.  
    173.         move.w  d2,sr           /* restore int status */
    174.         moveq   #-2,d0
    175.         rts
    176.  
    177. mky_err:
    178.         move.b  #0x40,6(a0)     /* set direction bits */
    179.         nop
    180.         nop
    181.         move.b  #0x40,(a0)
    182.  
    183.         move.w  d2,sr           /* restore int status */
    184.         moveq   #-1,d0
    185.         rts
    If you wish to also use SMS controllers with the same code, replace the code after no_pad: above with this

    Code (Text):
    1. | no pad found, so we're going to ASSUME an SMS (compatible) pad
    2. no_pad:
    3.         lea     0xA10003,a0
    4.         move.b  (a0),d0         /* - 1 c b r l d u */
    5.         andi.w  #0x003F,d0      /* 0 0 0 0 0 0 0 0 0 0 c b r l d u */
    6.         eori.w  #0x003F,d0      /* 0 0 0 0 0 0 0 0 0 0 C B R L D U */
    7.         move.l  (sp)+,d2
    8.         rts
     
  4. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    Good catch.

    It still doesn't explain the RAM disk thing though, which seems to have been coded at some point. That's what I'm interested on right now. By the way, wasn't Sega meant to make a keyboard and a floppy drive, and then dropped the idea because the Mega Modem wasn't popular? I think we may have something there.
     
  5. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    Never seen nor heard of the "ram disk". SEGA had a number of ram carts for development, none of which were controlled via the ports.
     
  6. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    Can somebody try to localize that code on the leaked devkits, anyways?

    Also whatever happened to that complement manual? That one would be interesting too.
     
  7. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    Can you be more specific about what you want? "That code" could refer to anything. :)
     
  8. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    I've posted a piece of code, I want to see if the full code has been leaked already.
     
  9. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    That IOID code? The only version I've seen is this

    Code (Text):
    1. *----------------------------------------------------------------------------
    2. * _JSID:    does initial id checking for I/O devices attached to
    3. *        joystick id code get
    4. *        this routine figures out if some kind of controller is
    5. *        attached to the ports. Essentially distinguishes between
    6. *        regular controllers(3 but,6but,activator,optical) and
    7. *        handshaking controllers(mouse,).  This identification
    8. *        scheme is based on Addendum #1 in the Genesis Software Manual
    9. *        port 1 and 2 on the genesis.
    10. *
    11. * void _JSID( )
    12. *
    13. *    in    d1.w : port number ( 0..2 )
    14. *
    15. *    out    d0.l : ID
    16. *         equ    $0f    * ?????  unknown/nothing connected
    17. *         equ    $0d    * (MDpad,FP6B)
    18. *         equ    $03    * MOUSE
    19. *         equ    $07    * SEGA TEAM PLAYER
    20. *        equ    $ff    * input error(incorrect port number)
    21. *
    22. * author: NG (SOJ)
    23. * MODS
    24. *    name    date        comments
    25. *    ----    --------    -------------------------------------------
    26. *    UP    06/29/1993    fixed bugs
    27. *    UP     01/14/1994    (increased time between each TH transition
    28. *                based on SOJ MD TECHNICAL INFO #7 01/11/94)
    29. *
    30. * copyright SEGA OF AMERICA
    31. *---------------------------------------------------------------------------
    32.     xdef    JSID
    33.     dc.l    0
    34. JSID:
    35.     cmp.b    #3,d1
    36.     blt    _JSID_10
    37.     moveq    #-1,d0
    38.     rts
    39. _JSID_10:
    40.     movem.l    d2-d3/a0,-(sp)
    41.     Z80di        ;disable the Z80 off the bus
    42.     move.l    #$00a10003,a0
    43.     moveq    #0,d0
    44.     move.b    d1,d0
    45.     add.l    d0,d0
    46.     adda.l    d0,a0
    47.     moveq    #0,d0
    48.     move.l    d0,d1
    49.     move.b    6(a0),d3; save original status of control port
    50.     swap     d3
    51.     move.b    (a0),d3        ; original status of I/O port
    52.     move.b    #%01000000,6(a0); I/O control : TH out
    53.  
    54.     move.b    #%01000000,(a0)    ; TH - Hi
    55.     nop
    56.     nop
    57.     nop
    58.     nop
    59.     move.b    (a0),d0
    60.     move.b    #%00000000,(a0)    ; TH - Low
    61.     nop
    62.     nop
    63.     nop
    64.     nop
    65.     move.b    (a0),d1
    66.  
    67.     move.b    #%01000000,(a0)    ; TH - Hi
    68.  
    69.     move.w    d0,d2
    70.     lsr.b    #1,d0
    71.     ror.w    #1,d0
    72.     lsr.b    #1,d0
    73.     rol.w    #1,d0
    74.     ror.w    #1,d2
    75.     lsr.b    #1,d2
    76.     rol.w    #1,d2
    77.     or.b     d2,d0        ;ID2=(PD6=1)&(PD1 OR PD0)
    78.     and.w    #$03,d0
    79.     lsl.b    #2,d0
    80.     move.w    d1,d2
    81.     lsr.b    #1,d1
    82.     ror.w    #1,d1
    83.     lsr.b    #1,d1
    84.     rol.w    #1,d1
    85.     ror.w    #1,d2
    86.     lsr.b    #1,d2
    87.     rol.w    #1,d2
    88.     or.b     d2,d1        ;ID0=(PD6=0)&(PD1 OR PD0)
    89.     and.w    #$03,d1
    90.     or.b     d1,d0        ;return id value
    91.  
    92.     move.b    d3,(a0)        ; restore original status of I/O port
    93.     swap    d3
    94.     move.b    d3,6(a0)    ; restore original status of control port
    95.     Z80ei            ; Z80 bus release
    96.     movem.l    (sp)+,d2-d3/a0
    97.     rts