galaxian commented disassembly

dj_yt

Active member
Feedback
3 (100%)
Credits
787CR
stunstall said:
As an aside, I feel Aaron Giles is an absolute genius and I think, "how the Hell did he figure THAT out?"

I'm surprised back in the 1990s the authors of the System 16 emulator figured this hardware out, way before MAME got there, and got the games running on low-spec DOS Pentium machines. They were the first to emulate this era of Sega hardware. And I think the public information was non-existent at this time. I didn't see the schematics surface until much later on.

Not to discount all the great things Aaron Giles and the MAME team have done of course - without which, my projects wouldn't have been possible!

dj_yt2018-08-16 14:12:01
 

stunstall

Newbie
Credits
32CR
Hello, have updated the disassembly twice in a week.

It's coming along quite nicely
smiley4.gif


Regarding the question re the architecture, it's interesting.

Looks like the entire game - from attract mode to the game itself - is driven by the Non Maskable Interrupt handler. This is the first game I've seen written this way.

The developer was streets ahead of me in Z80 so he must have had his reasons using the NMI to drive the game - I'm thinking he wanted to ensure the game ran at ~60Hz. I don't know if the NMI is synced to vertical retrace of the monitor.

I'm really interested to know how you develop a game for a monitor that's on its side. Apart from swapping the X/Y axis, it must have been a real PITA to debug given that cocktail mode had to be catered for as well.
 

philmurr

Active member
vacBacker
Feedback
48 (100%)
Credits
2,385CR
Great update Scott.

Yes the NMI is generated when the scan is at the bottom of the screen (so the game can make changes to things on-screen without causing flicker)

As Galaxian was the first arcade game I started to disassemble when I did my first high score save, I just presumed all games were driven by the NMI (which now I know isn't the case). A lot of games from this era (and the ones I've seen that run on Galaxian-derived hardware, including Scramble etc.) look to use this method.

Writing code for the monitor on its side isn't too difficult as the clever stuff is done in hardware. You just need to remember the next character on the screen isn't 1 byte but actually 32 bytes along! It's an awful lot easier than writing for the Sinclair Spectrum with its 3 separate "zones" on the screen.
 

stunstall

Newbie
Credits
32CR
Hi Phil, I would disagree with you saying writing code for monitor on its side not being difficult, could you imagine messing with pixel adjustment code to handle special cocktail cases & sprite issues back in 1978?
smiley18.gif
(love these smileys.) - for example, take the sprite code @ $0BBE which I have labelled HANDLE_INFLIGHT_ALIEN_SPRITE_UPDATE : it appears the first 3 sprites have to be positioned at different pixel offsets from the other 5. That's without factoring in cocktail mode - aaagh!
smiley4.gif


If I didn't design the hardware (I am unsure if the developer did?) and these artefacts presented themselves I'd probably think it was my code to blame and not the hardware
smiley9.gif


Love discussing this stuff with you guys btw.
 

Macro

Active member
vacBacker
Feedback
4 (100%)
Credits
2,016CR
Screen rotation is done totally in hardware, so you only have to get it working one way up

you just write a '1' to two addresses to 'flip-x' and 'flip-y' (addresses 0x7006 and 0x7007)
 

stunstall

Newbie
Credits
32CR
Macro said:
Screen rotation is done totally in hardware, so you only have to get it working one way up

you just write a '1' to two addresses to 'flip-x' and 'flip-y' (addresses 0x7006 and 0x7007)

Hi Macro, I've seen code that writes to the 2 ports:

Code:
0204: 32 06 70      ld   ($7006),a           ; set regen hflip
	0207: 32 07 70      ld   ($7007),a           ; set regen vflip
	020A: 32 18 40      ld   ($4018),a           ; set DISPLAY_IS_COCKTAIL_P2

But I can definitely say in the code I've disassembled there's code dedicated to handling cocktail setups, adjusting coordinates for player bullet & sprites, such as:

Code:
HANDLE_PLAYER_BULLET:
	0898: CD BC 08      call $08BC               ; call MOVE_PLAYER_BULLET
	089B: 2A 09 42      ld   hl,($4209)          ; load value of PLAYER_BULLET_X into H, PLAYER_BULLET_Y into L
	089E: 3A 18 40      ld   a,($4018)           ; read DISPLAY_IS_COCKTAIL_P2
	08A1: 0F            rrca                     ; move bit 0 into carry.
	08A2: 38 0D         jr   c,$08B1             ; If carry is set, then player 2 is playing and its a cocktail cab: goto $08B1.
	
	; This comment is wrong in the actual disassembly so ignore it
	08A4: 7D            ld   a,l                 ; load A with PLAYER_BULLET_Y
	08A5: 2F            cpl
	08A6: C6 FC         add  a,-4                ; subtract 4
	08A8: 32 9F 40      ld   ($409F),a           ; update Y coordinate of player bullet
	08AB: 7C            ld   a,h                 ; load A with PLAYER_BULLET_X
	08AC: 2F            cpl
	08AD: 32 9D 40      ld   ($409D),a           ; update X coordinate of player bullet
	08B0: C9            ret
	
	; this code only runs when the game is in cocktail mode and it's player 2 playing.
	; It takes into account the screen is upside down and positions the player bullet properly.
	08B1: 7D            ld   a,l
	08B2: 3D            dec  a
	08B3: 32 9F 40      ld   ($409F),a           ; update Y coordinate of player bullet
	08B6: 7C            ld   a,h
	08B7: 2F            cpl
	08B8: 32 9D 40      ld   ($409D),a           ; update X coordinate of player bullet
	08BB: C9            ret
Code:

Personally speaking, given the dev tools in 1978, it must have been really time-consuming
smiley18.gif
 

Macro

Active member
vacBacker
Feedback
4 (100%)
Credits
2,016CR
I guess bullets and missiles are not affected by the hardware switch over - thinking about it they use a different set of chips and just mix the video output in with that from the characters/sprites circuit.

The only games I wrote on galaxian hardware didn't require the bullets or missiles so I just had to alter the flip registers for player two (and read the correct set of controls of course!)
 

John Bennett

Senior Member
vacBacker
Feedback
10 (100%)
Credits
5,336CR
Perhaps everything other than the ‘bullet’ layer is inverted in hardware?
You can see the XORs for video counter inversion for the majority of the hardware.

A little while ago I made a huge landscape printout of the galaxIan schematics to help understand sprite hardware. I learnt a litte bit, but it seemed overly complex to overcome the RAM/ROM limitations of the day (stuff from the mid 80s like Double Dragon was easier to understand - to me anyway). I ran out of colours quickly trying to highlight every bus on the schematics
smiley36.gif
 

stunstall

Newbie
Credits
32CR
OK, I've covered most of Galaxian's code in the disassembly. It's up on Sean's. Anything I change in it will be to tidy up the comments or clarify things. Or indeed, correct mistakes
smiley9.gif


I can say that, in the main, I think Galaxian's written well, and there's a lot to it.

For example when your laser gets too close to the swarm, the aliens will stand still and let the laser pass them by. Or that after an alien flies by you for the 4th time it will get REALLY aggressive and start hunting you down. The loop the loop is split into 2 different routines - the first routine makes the alien fly in a table-driven 270 degree arc and the second routine that completes the final 90 degrees is the exact same that executes when the alien leave the swarm.

It was an absolute pleasure to work on it.

I'm now working on Scramble, and I might have a disassembly of that ready for Sean Riddle's site by end of play today - depends on how much beer I have tonight
smiley17.gif


Scramble has a LOT of shared code with Galaxian.

stunstall2018-12-27 18:46:24
 

stunstall

Newbie
Credits
32CR
Should mention I'm thinking of writing a doc on how to edit Galaxian sprites. PhilMurr's help in understanding the graphics ROMs has been very useful, so thanks again!
 
Top