This week we were given the task of researching into the assembly code used in old game consoles. I was in the group that was researching the code for the Sega Mega Drive. I could not find a decent disassembler to actually look at the code for a game of the Mega Drive, but I did find quite a lot of example code.
I have done some assembly code, using a program called Asm Tutor, as part of the computing course I did as one of my A levels, but not to the extent of what is used to actually create a video game.
Here is some sample code I found for reading the controller:
jsinit: moveq #$40,d0
move.b d0,$a10009
move.b d0,$a1000b
move.b d0,$a1000d
rts
porta: move.b #$40,$a10003
nop
nop
move.b $a10003,d1
andi.b #$3f,d1
move.b #$00,$a10003
nop
nop
move.b $a10003,d0
andi.b #$30,d0
lsl.b #2,d0
or.b d1,d0
not.b d0
rts
According to the notes that accompany this piece of code jsinit must be called to set up the joystick. It is only called once but if this code was not present the would be errors when reading back from the controller.
The code porta deals with the controller in the first port on the console the same can also be done with portb. This piece of code returns a boolean value at the end. It uses logic gates to check whether a button has been pressed(returns 1 bit) or not (returns 0 bits).
Also at the same site that I found the link to the above code, I found an assembler and disassembler with a small sample program. There is no documentation to help understand exactly what this program is doing but, I think, will still come in handy in understanding assembly code in the coming months.
This piece of is from the beginning of the sample program. I am not entirely sure what it is doing but I think it is declaring values in registers and adding some values. It also prints out "SEGA GENESIS (C)SEGA 1996 MAY" and "Sample Program".
dc.l $00FFFE00,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200,$200
dc.l $200,$200,$200,$200,$200,$200,$200
dc.l $200
dc.b 'SEGA GENESIS (C)SEGA 1996 MAY'
dc.b 'SAMPLE PROGRAM '
dc.b 'SAMPLE PROGRAM '
dc.b 'GM 00000000-00',$a5,$fb
dc.b 'JD ',$00,$00,$00,$00,$00,$02,$00,$00
dc.b $00,$ff,$00,$00,$ff,$ff,$ff,$ff,' '
dc.b ' '
dc.b ' '
dc.b 'JUE '
nop
nop
rte
Wednesday, October 15, 2008
Subscribe to:
Posts (Atom)