;
; File generated by cc65 v 2.13.2
;
	.fopt		compiler,"cc65 v 2.13.2"
	.setcpu		"6502"
	.smart		on
	.autoimport	on
	.case		on
	.debuginfo	off
	.importzp	sp, sreg, regsave, regbank, tmp1, ptr1, ptr2
	.macpack	longbranch
	.forceimport	__STARTUP__
	.import		_rNES_init
	.import		_rNES_fill_ram
	.import		_rNES_get_joy
	.import		_rNES_sound_init
	.import		_rNES_sound
	.import		_rNES_disable_graphics
	.import		_rNES_enable_graphics
	.import		_rNES_copy_tiles
	.import		_rNES_fill_vram
	.import		_rNES_sprite_dma
	.import		_rNES_copy_vram
	.import		_rNES_print
	.import		_sprite_tiles
	.import		_scenery_tiles
	.import		_font
	.import		_charset
	.export		_bkg_pal
	.export		_spr_pal
	.export		_sprites
	.export		_joy
	.export		_i
	.export		_j
	.export		_playerX
	.export		_playerY
	.export		_PPU_status
	.export		_currentFrame
	.export		_score
	.export		_kills
	.export		_level
	.export		_highscore
	.export		_invaderX
	.export		_invaderY
	.export		_invaderAlive
	.export		_rocketX
	.export		_rocketY
	.export		_rocketState
	.export		_rocketExplosionFrames
	.export		_destroy_player
	.export		_destroy_invader
	.export		_rocket_hit
	.export		_despawn_rocket
	.export		_need_to_spawn
	.export		_spawn_enemy
	.export		_animate_invaders
	.export		_Itoa
	.export		_animate_player
	.export		_animate_rocket
	.export		_move_rocket
	.export		_move_invader
	.export		_move_player
	.export		_initialize_sprites
	.export		_initializeSystem
	.export		_drawBuilding
	.export		_starrySky
	.export		_drawBackground
	.export		_game
	.export		_intro
	.export		_main

.segment	"DATA"

_bkg_pal:
	.byte	$0E
	.byte	$19
	.byte	$10
	.byte	$01
	.byte	$0E
	.byte	$28
	.byte	$18
	.byte	$06
	.byte	$0E
	.byte	$14
	.byte	$04
	.byte	$00
_spr_pal:
	.byte	$0E
	.byte	$16
	.byte	$25
	.byte	$12
	.byte	$0E
	.byte	$01
	.byte	$03
	.byte	$01
	.byte	$0E
	.byte	$14
	.byte	$15
	.byte	$01
	.byte	$0E
	.byte	$09
	.byte	$0B
	.byte	$01
_sprites:
	.word	$0200
_currentFrame:
	.dword	$00000000
_highscore:
	.word	$0000

.segment	"RODATA"

L0001:
	.byte	$57,$72,$69,$74,$74,$65,$6E,$20,$62,$79,$20,$53,$65,$62,$61,$73
	.byte	$74,$69,$61,$6E,$20,$4D,$69,$68,$61,$69,$2C,$20,$32,$30,$31,$32
	.byte	$00,$42,$59,$20,$53,$45,$42,$41,$53,$54,$49,$41,$4E,$20,$4D,$49
	.byte	$48,$41,$49,$2C,$20,$32,$30,$31,$32,$00,$20,$20,$20,$20,$20,$20
	.byte	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
	.byte	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$00,$49,$4E,$56,$41,$44
	.byte	$45,$52,$53,$20,$4D,$55,$53,$54,$20,$44,$49,$45,$21,$00,$20,$20
	.byte	$20,$20,$20,$20,$20,$20,$20,$20,$20,$00,$42,$59,$20,$53,$45,$42
	.byte	$41,$53,$54,$49,$41,$4E,$20,$4D,$49,$48,$41,$49,$2C,$20,$32,$30
	.byte	$31,$32,$00,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
	.byte	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
	.byte	$20,$20,$20,$00,$53,$43,$4F,$52,$45,$00,$48,$49,$47,$48,$53,$43
	.byte	$4F,$52,$45,$00,$50,$52,$45,$53,$53,$20,$53,$54,$41,$52,$54,$00

.segment	"BSS"

_joy:
	.res	1,$00
_i:
	.res	2,$00
_j:
	.res	2,$00
_playerX:
	.res	1,$00
_playerY:
	.res	1,$00
_PPU_status:
	.res	1,$00
_score:
	.res	2,$00
_kills:
	.res	2,$00
_level:
	.res	1,$00
_invaderX:
	.res	10,$00
_invaderY:
	.res	10,$00
_invaderAlive:
	.res	10,$00
_rocketX:
	.res	1,$00
_rocketY:
	.res	1,$00
_rocketState:
	.res	1,$00
_rocketExplosionFrames:
	.res	1,$00

; ---------------------------------------------------------------
; void __near__ destroy_player (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_destroy_player: near

.segment	"CODE"

	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ destroy_invader (unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_destroy_invader: near

.segment	"CODE"

	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L004D
	inx
L004D:	ldy     #$00
	jsr     ldauidx
	sta     _rocketX
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L0051
	inx
L0051:	ldy     #$00
	jsr     ldauidx
	jsr     incax2
	sta     _rocketY
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L0060
	inx
L0060:	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L0064
	inx
L0064:	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L0068
	inx
L0068:	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	jsr     incsp1
	rts

.endproc

; ---------------------------------------------------------------
; int __near__ rocket_hit (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_rocket_hit: near

.segment	"CODE"

	jsr     decsp5
	ldx     #$00
	lda     #$00
	ldy     #$04
	sta     (sp),y
L006B:	ldy     #$04
	ldx     #$00
	lda     (sp),y
	cmp     #$0A
	jsr     boolult
	jne     L006E
	jmp     L006C
L006E:	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$04
	clc
	adc     (sp),y
	bcc     L0076
	inx
L0076:	ldy     #$00
	jsr     ldauidx
	jeq     L0077
	ldx     #$00
	lda     _rocketY
	jsr     pushax
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	ldy     #$06
	clc
	adc     (sp),y
	bcc     L0079
	inx
L0079:	ldy     #$00
	jsr     ldauidx
	jsr     incax8
	jsr     tosuleax
	jne     L0074
L0077:	ldx     #$00
	lda     #$00
	jeq     L007A
L0074:	ldx     #$00
	lda     #$01
L007A:	jeq     L006D
	ldx     #$00
	lda     _rocketX
	jsr     pushax
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$06
	clc
	adc     (sp),y
	bcc     L007E
	inx
L007E:	ldy     #$00
	jsr     ldauidx
	jsr     tossubax
	ldy     #$02
	jsr     staxysp
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$04
	clc
	adc     (sp),y
	bcc     L0082
	inx
L0082:	ldy     #$00
	jsr     ldauidx
	jsr     pushax
	ldx     #$00
	lda     _rocketX
	jsr     tossubax
	ldy     #$00
	jsr     staxysp
	ldx     #$00
	lda     _rocketX
	jsr     pushax
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$06
	clc
	adc     (sp),y
	bcc     L0087
	inx
L0087:	ldy     #$00
	jsr     ldauidx
	jsr     tosugtax
	jeq     L0088
	ldy     #$03
	jsr     ldaxysp
	cmp     #$08
	txa
	sbc     #$00
	bvc     L0089
	eor     #$80
L0089:	asl     a
	lda     #$00
	ldx     #$00
	rol     a
	jne     L0085
L0088:	ldx     #$00
	lda     #$00
	jeq     L008A
L0085:	ldx     #$00
	lda     #$01
L008A:	jne     L0084
	ldx     #$00
	lda     _rocketX
	jsr     pushax
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$06
	clc
	adc     (sp),y
	bcc     L008D
	inx
L008D:	ldy     #$00
	jsr     ldauidx
	jsr     tosuleax
	jeq     L008E
	ldy     #$01
	jsr     ldaxysp
	cmp     #$08
	txa
	sbc     #$00
	bvc     L008F
	eor     #$80
L008F:	asl     a
	lda     #$00
	ldx     #$00
	rol     a
	jne     L008B
L008E:	ldx     #$00
	lda     #$00
	jeq     L0090
L008B:	ldx     #$00
	lda     #$01
L0090:	jne     L0084
	ldx     #$00
	lda     #$00
	jeq     L0091
L0084:	ldx     #$00
	lda     #$01
L0091:	jeq     L006D
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	ldx     #$00
	jmp     L006A
L006D:	ldy     #$04
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	ldy     #$04
	sta     (sp),y
	pla
	jmp     L006B
L006C:	ldx     #$FF
	lda     #$FF
	jmp     L006A
L006A:	jsr     incsp5
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ despawn_rocket (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_despawn_rocket: near

.segment	"CODE"

	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	rts

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ need_to_spawn (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_need_to_spawn: near

.segment	"CODE"

	jsr     decsp1
	ldx     #$00
	lda     #$00
	ldy     #$00
	sta     (sp),y
L00A2:	ldy     #$00
	ldx     #$00
	lda     (sp),y
	cmp     #$0A
	jsr     boolult
	jne     L00A5
	jmp     L00A3
L00A5:	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L00AD
	inx
L00AD:	ldy     #$00
	jsr     ldauidx
	cmp     #$00
	jsr     booleq
	jeq     L00A4
	ldx     #$00
	lda     #$01
	jmp     L00A1
L00A4:	ldy     #$00
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	ldy     #$00
	sta     (sp),y
	pla
	jmp     L00A2
L00A3:	ldx     #$00
	lda     #$00
	jmp     L00A1
L00A1:	jsr     incsp1
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ spawn_enemy (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_spawn_enemy: near

.segment	"CODE"

	lda     #$FF
	jsr     pusha
	jsr     decsp1
	lda     #$20
	jsr     pusha
	lda     _currentFrame+3
	sta     sreg+1
	lda     _currentFrame+2
	sta     sreg
	ldx     _currentFrame+1
	lda     _currentFrame
	jsr     pusheax
	ldx     #$38
	lda     #$00
	sta     sreg
	lda     #$00
	sta     sreg+1
	lda     #$F1
	jsr     tosumuleax
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$BE
	jsr     tosumodeax
	ldy     #$19
	jsr     inceaxy
	jsr     pusha
	ldx     #$00
	lda     #$00
	ldy     #$02
	sta     (sp),y
L00B6:	ldy     #$02
	ldx     #$00
	lda     (sp),y
	cmp     #$0A
	jsr     boolult
	jne     L00B9
	jmp     L00B7
L00B9:	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$02
	clc
	adc     (sp),y
	bcc     L00C1
	inx
L00C1:	ldy     #$00
	jsr     ldauidx
	cmp     #$00
	jsr     booleq
	jeq     L00B8
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	sta     (sp),y
	jmp     L00B7
L00B8:	ldy     #$02
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	ldy     #$02
	sta     (sp),y
	pla
	jmp     L00B6
L00B7:	ldy     #$03
	ldx     #$00
	lda     (sp),y
	cmp     #$FF
	jsr     booleq
	jeq     L00C4
	jmp     L00B0
L00C4:	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$09
	ldy     #$01
	jsr     staspidx
	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$03
	clc
	adc     (sp),y
	bcc     L00D4
	inx
L00D4:	jsr     pushax
	ldx     #$00
	lda     #$01
	ldy     #$00
	jsr     staspidx
	lda     #<(_invaderX)
	ldx     #>(_invaderX)
	ldy     #$03
	clc
	adc     (sp),y
	bcc     L00D8
	inx
L00D8:	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	ldy     #$03
	clc
	adc     (sp),y
	bcc     L00DC
	inx
L00DC:	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
L00B0:	jsr     incsp4
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ animate_invaders (unsigned int)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_animate_invaders: near

.segment	"CODE"

	jsr     decsp1
	ldx     #$00
	lda     #$00
	ldy     #$00
	sta     (sp),y
L00DF:	ldy     #$00
	ldx     #$00
	lda     (sp),y
	cmp     #$0A
	jsr     boolult
	jne     L00E2
	jmp     L00E0
L00E2:	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L00EA
	inx
L00EA:	ldy     #$00
	jsr     ldauidx
	jeq     L00E1
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	ldy     #$02
	clc
	adc     (sp),y
	bcc     L00F2
	inx
L00F2:	ldy     #$00
	jsr     ldauidx
	ldy     #$00
	jsr     staspidx
	ldy     #$02
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$14
	jsr     tosumodax
	cpx     #$00
	bne     L00F5
	cmp     #$0A
L00F5:	jsr     boolult
	jeq     L00F3
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$09
	ldy     #$01
	jsr     staspidx
	jmp     L00E1
L00F3:	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$0A
	ldy     #$01
	jsr     staspidx
L00E1:	ldy     #$00
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	ldy     #$00
	sta     (sp),y
	pla
	jmp     L00DF
L00E0:	jsr     incsp3
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ Itoa (__near__ unsigned char*, unsigned int)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_Itoa: near

.segment	"RODATA"

L00FE:
	.byte	$54,$65,$6D,$70,$6F,$72,$61,$72,$79,$20,$73,$74,$6F,$72,$61,$67
	.byte	$65,$21,$00

.segment	"CODE"

	ldy     #$13
	jsr     subysp
	ldy     #$12
L00FF:	lda     L00FE,y
	sta     (sp),y
	dey
	bpl     L00FF
	lda     #$00
	jsr     pusha
	ldy     #$15
	jsr     ldaxysp
	jsr     pushax
L0102:	ldy     #$01
	jsr     ldaxysp
	cmp     #$0A
	txa
	sbc     #$00
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L0103
	lda     #$03
	jsr     leaa0sp
	ldy     #$02
	clc
	adc     (sp),y
	bcc     L0108
	inx
L0108:	jsr     pushax
	ldy     #$03
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$0A
	jsr     tosumodax
	ldy     #$30
	jsr     incaxy
	ldy     #$00
	jsr     staspidx
	ldy     #$01
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$0A
	jsr     tosudivax
	ldy     #$00
	jsr     staxysp
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	bpl     L010D
	dex
L010D:	pha
	clc
	adc     #$01
	ldy     #$02
	sta     (sp),y
	pla
	jmp     L0102
L0103:	lda     #$03
	jsr     leaa0sp
	ldy     #$02
	clc
	adc     (sp),y
	bcc     L0111
	inx
L0111:	jsr     pushax
	ldy     #$03
	jsr     ldaxysp
	ldy     #$30
	jsr     incaxy
	ldy     #$00
	jsr     staspidx
L0113:	ldy     #$02
	ldx     #$00
	lda     (sp),y
	bpl     L0116
	dex
L0116:	tax
	jsr     boolge
	jeq     L0114
	ldy     #$19
	jsr     ldaxysp
	sta     regsave
	stx     regsave+1
	jsr     incax1
	ldy     #$18
	jsr     staxysp
	lda     regsave
	ldx     regsave+1
	jsr     pushax
	lda     #$05
	jsr     leaa0sp
	ldy     #$04
	clc
	adc     (sp),y
	bcc     L011B
	inx
L011B:	ldy     #$00
	jsr     ldauidx
	ldy     #$00
	jsr     staspidx
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	bpl     L011D
	dex
L011D:	pha
	sec
	sbc     #$01
	ldy     #$02
	sta     (sp),y
	pla
	jmp     L0113
L0114:	ldy     #$19
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	ldy     #$1A
	jsr     addysp
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ animate_player (unsigned int)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_animate_player: near

.segment	"CODE"

	ldy     #$01
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$0A
	jsr     tosumodax
	cpx     #$00
	bne     L0123
	cmp     #$05
L0123:	jsr     boolult
	jeq     L0121
	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$01
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$02
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$03
	ldy     #$01
	jsr     staspidx
	jmp     L012D
L0121:	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$04
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$05
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$06
	ldy     #$01
	jsr     staspidx
L012D:	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$0D
	ldy     #$01
	jsr     staspidx
	jsr     incsp2
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ animate_rocket (unsigned int)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_animate_rocket: near

.segment	"CODE"

	ldx     #$00
	lda     _rocketState
	cmp     #$02
	jsr     booleq
	jeq     L013B
	ldx     #$00
	lda     _rocketExplosionFrames
	cmp     #$09
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L013D
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$0B
	ldy     #$01
	jsr     staspidx
	jmp     L0148
L013D:	ldx     #$00
	lda     _rocketExplosionFrames
	cmp     #$05
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L0143
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$0C
	ldy     #$01
	jsr     staspidx
	jmp     L0148
L0143:	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$0B
	ldy     #$01
	jsr     staspidx
L0148:	jmp     L0153
L013B:	ldy     #$01
	jsr     ldaxysp
	jsr     pushax
	ldx     #$00
	lda     #$0A
	jsr     tosumodax
	cpx     #$00
	bne     L014F
	cmp     #$05
L014F:	jsr     boolult
	jeq     L014D
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$07
	ldy     #$01
	jsr     staspidx
	jmp     L0153
L014D:	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$08
	ldy     #$01
	jsr     staspidx
L0153:	jsr     incsp2
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ move_rocket (unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_move_rocket: near

.segment	"CODE"

	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$10
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	jsr     incsp2
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ move_invader (unsigned char, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_move_invader: near

.segment	"CODE"

	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	jsr     incsp3
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ move_player (unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_move_player: near

.segment	"CODE"

	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	jsr     decax8
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax4
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     incax8
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	jsr     incax8
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$0C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldy     #$03
	ldx     #$00
	lda     (sp),y
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     decax7
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$3C
	jsr     incaxy
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	jsr     incsp2
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ initialize_sprites (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_initialize_sprites: near

.segment	"CODE"

	jsr     decsp1
	ldx     #$00
	lda     #$00
	ldy     #$00
	sta     (sp),y
L0191:	ldy     #$00
	ldx     #$00
	lda     (sp),y
	cmp     #$0A
	jsr     boolult
	jne     L0194
	jmp     L0192
L0194:	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	ldy     #$14
	jsr     incaxy
	jsr     pushax
	ldy     #$02
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	jsr     tosaddax
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	ldy     #$00
	clc
	adc     (sp),y
	bcc     L01A7
	inx
L01A7:	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$00
	jsr     staspidx
	ldy     #$00
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	ldy     #$00
	sta     (sp),y
	pla
	jmp     L0191
L0192:	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$01
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldx     #$00
	lda     #$20
	ldy     #$02
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldx     #$00
	lda     #$00
	ldy     #$03
	jsr     staspidx
	lda     _sprites
	ldx     _sprites+1
	jsr     pushax
	ldx     #$00
	lda     #$1E
	ldy     #$00
	jsr     staspidx
	ldx     #$00
	lda     #$00
	jsr     pushax
	jsr     _animate_player
	jsr     incsp1
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ initializeSystem (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_initializeSystem: near

.segment	"CODE"

	lda     #<(L0001)
	ldx     #>(L0001)
	jsr     pushax
	ldy     #$00
	jsr     _rNES_init
	lda     #$03
	jsr     pusha
	jsr     _rNES_sound_init
	ldy     #$00
	jsr     _rNES_disable_graphics
	lda     #<(_bkg_pal)
	ldx     #>(_bkg_pal)
	jsr     pushax
	ldx     #$00
	lda     #$0C
	jsr     pushax
	ldx     #$3F
	lda     #$00
	jsr     pushax
	jsr     _rNES_copy_vram
	lda     #<(_spr_pal)
	ldx     #>(_spr_pal)
	jsr     pushax
	ldx     #$00
	lda     #$10
	jsr     pushax
	ldx     #$3F
	lda     #$10
	jsr     pushax
	jsr     _rNES_copy_vram
	lda     #<(_font)
	ldx     #>(_font)
	jsr     pushax
	ldx     #$00
	lda     #$00
	jsr     pushax
	ldx     #$00
	lda     #$00
	jsr     pushax
	ldx     #$00
	lda     #$40
	jsr     pushax
	jsr     _rNES_copy_tiles
	lda     #<(_scenery_tiles)
	ldx     #>(_scenery_tiles)
	jsr     pushax
	ldx     #$00
	lda     #$00
	jsr     pushax
	ldx     #$00
	lda     #$40
	jsr     pushax
	ldx     #$00
	lda     #$05
	jsr     pushax
	jsr     _rNES_copy_tiles
	lda     #<(_sprite_tiles)
	ldx     #>(_sprite_tiles)
	jsr     pushax
	ldx     #$00
	lda     #$00
	jsr     pushax
	ldx     #$01
	lda     #$00
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     pushax
	jsr     _rNES_copy_tiles
	jsr     incsp2
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ drawBuilding (unsigned char, unsigned char, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_drawBuilding: near

.segment	"CODE"

	jsr     decsp2
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	ldx     #$00
	sta     _j
	stx     _j+1
L01D6:	lda     _j
	ldx     _j+1
	jsr     pushax
	ldy     #$06
	ldx     #$00
	lda     (sp),y
	jsr     pushax
	ldy     #$07
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     tosneax
	jne     L01D9
	jmp     L01D7
L01D9:	ldy     #$05
	ldx     #$00
	lda     (sp),y
	ldx     #$00
	sta     _i
	stx     _i+1
L01DF:	lda     _i
	ldx     _i+1
	jsr     pushax
	ldy     #$07
	ldx     #$00
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     tosneax
	jne     L01E2
	jmp     L01D8
L01E2:	lda     _j
	ldx     _j+1
	jsr     pushax
	lda     _i
	ldx     _i+1
	jsr     tosumulax
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	ldy     #$00
	jsr     staxysp
	ldy     #$01
	jsr     ldaxysp
	ldx     #$00
	and     #$01
	cpx     #$00
	bne     L01EC
	cmp     #$00
L01EC:	jsr     booleq
	jeq     L01EA
	lda     _j
	ldx     _j+1
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldx     #$20
	lda     #$00
	jsr     tosaddax
	jsr     pushax
	lda     _i
	ldx     _i+1
	jsr     tosaddax
	txa
	ldx     #$00
	sta     $2006
	lda     _j
	ldx     _j+1
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	lda     _i
	ldx     _i+1
	jsr     tosaddax
	sta     $2006
	ldx     #$00
	lda     #$40
	sta     $2007
	jmp     L01E1
L01EA:	lda     _j
	ldx     _j+1
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldx     #$20
	lda     #$00
	jsr     tosaddax
	jsr     pushax
	lda     _i
	ldx     _i+1
	jsr     tosaddax
	txa
	ldx     #$00
	sta     $2006
	lda     _j
	ldx     _j+1
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	lda     _i
	ldx     _i+1
	jsr     tosaddax
	sta     $2006
	ldx     #$00
	lda     #$41
	sta     $2007
L01E1:	inc     _i
	bne     L01E7
	inc     _i+1
L01E7:	lda     _i
	ldx     _i+1
	jmp     L01DF
L01D8:	inc     _j
	bne     L01DE
	inc     _j+1
L01DE:	lda     _j
	ldx     _j+1
	jmp     L01D6
L01D7:	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     incax4
	jsr     decax1
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldx     #$20
	lda     #$00
	jsr     tosaddax
	jsr     pushax
	ldy     #$07
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     shrax1
	jsr     tosaddax
	txa
	ldx     #$00
	sta     $2006
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     pushax
	ldy     #$05
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     incax4
	jsr     decax1
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldy     #$07
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     shrax1
	jsr     tosaddax
	sta     $2006
	ldx     #$00
	lda     #$42
	sta     $2007
	jsr     incsp6
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ starrySky (unsigned char, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_starrySky: near

.segment	"CODE"

	ldy     #$01
	ldx     #$00
	lda     (sp),y
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldx     #$20
	lda     #$00
	jsr     tosaddax
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	txa
	ldx     #$00
	sta     $2006
	ldy     #$01
	ldx     #$00
	lda     (sp),y
	jsr     incax4
	jsr     shlax4
	jsr     shlax1
	jsr     pushax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     tosaddax
	sta     $2006
	ldy     #$00
	ldx     #$00
	lda     (sp),y
	sta     $2007
	jsr     incsp3
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ drawBackground (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_drawBackground: near

.segment	"CODE"

	lda     #$00
	jsr     pusha
	lda     #$10
	jsr     pusha
	lda     #$04
	jsr     pusha
	lda     #$03
	jsr     pusha
	jsr     _drawBuilding
	lda     #$04
	jsr     pusha
	lda     #$0D
	jsr     pusha
	lda     #$07
	jsr     pusha
	lda     #$05
	jsr     pusha
	jsr     _drawBuilding
	lda     #$0A
	jsr     pusha
	lda     #$12
	jsr     pusha
	lda     #$02
	jsr     pusha
	lda     #$09
	jsr     pusha
	jsr     _drawBuilding
	lda     #$14
	jsr     pusha
	lda     #$0B
	jsr     pusha
	lda     #$09
	jsr     pusha
	lda     #$03
	jsr     pusha
	jsr     _drawBuilding
	lda     #$18
	jsr     pusha
	lda     #$0E
	jsr     pusha
	lda     #$06
	jsr     pusha
	lda     #$07
	jsr     pusha
	jsr     _drawBuilding
	lda     #$1A
	jsr     pusha
	lda     #$02
	jsr     pusha
	lda     #$44
	jsr     pusha
	jsr     _starrySky
	lda     #$10
	jsr     pusha
	lda     #$0F
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$00
	jsr     pusha
	lda     #$09
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$07
	jsr     pusha
	lda     #$07
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$14
	jsr     pusha
	lda     #$0A
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$1D
	jsr     pusha
	lda     #$0D
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$0C
	jsr     pusha
	lda     #$01
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$0F
	jsr     pusha
	lda     #$02
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$01
	jsr     pusha
	lda     #$05
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$12
	jsr     pusha
	lda     #$09
	jsr     pusha
	lda     #$43
	jsr     pusha
	jsr     _starrySky
	lda     #$0D
	jsr     pusha
	lda     #$0D
	jsr     pusha
	lda     #$44
	jsr     pusha
	jsr     _starrySky
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ game (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_game: near

.segment	"CODE"

	lda     #$00
	jsr     pusha
	jsr     _initializeSystem
	jsr     _drawBackground
	ldx     #$23
	lda     #$C0
	jsr     pushax
	ldx     #$00
	lda     #$08
	jsr     pushax
	lda     #$55
	jsr     pusha
	jsr     _rNES_fill_vram
	ldx     #$23
	lda     #$F0
	jsr     pushax
	ldx     #$00
	lda     #$10
	jsr     pushax
	lda     #$AA
	jsr     pusha
	jsr     _rNES_fill_vram
	lda     #<(L0001+33)
	ldx     #>(L0001+33)
	jsr     pushax
	lda     #$04
	jsr     pusha
	lda     #$19
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     #<(L0001+58)
	ldx     #>(L0001+58)
	jsr     pushax
	lda     #$00
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     #<(L0001+91)
	ldx     #>(L0001+91)
	jsr     pushax
	lda     #$07
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     #<(L0001+110)
	ldx     #>(L0001+110)
	jsr     pushax
	lda     #$09
	jsr     pusha
	lda     #$03
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	ldx     #$00
	lda     #$00
	sta     _score
	stx     _score+1
	ldx     #$00
	lda     #$00
	sta     _level
	ldx     #$00
	lda     #$00
	sta     _kills
	stx     _kills+1
	ldx     #$00
	lda     #$00
	sta     _rocketState
	ldx     #$02
	lda     #$00
	jsr     pushax
	ldx     #$01
	lda     #$00
	jsr     pushax
	lda     #$00
	jsr     pusha
	jsr     _rNES_fill_ram
	ldx     #$00
	lda     #$80
	sta     _playerX
	ldx     #$00
	lda     #$B9
	sta     _playerY
	lda     _playerX
	jsr     pusha
	lda     _playerY
	jsr     pusha
	jsr     _move_player
	jsr     _initialize_sprites
	ldy     #$00
	jsr     _rNES_enable_graphics
L02B6:	ldx     #$00
	lda     $2002
	ldx     #$00
	and     #$80
	jsr     bnegax
	jeq     L02B7
	jmp     L02B6
L02B7:	lda     #$02
	jsr     pusha
	lda     #$00
	jsr     pusha
	jsr     _rNES_sprite_dma
L02C0:	lda     _kills
	ldx     _kills+1
	jsr     pushax
	ldx     #$00
	lda     #$05
	jsr     tosudivax
	sta     _level
	ldx     #$00
	lda     _level
	cmp     #$0A
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L02C5
	ldx     #$00
	lda     #$09
	sta     _level
L02C5:	lda     _currentFrame+3
	sta     sreg+1
	lda     _currentFrame+2
	sta     sreg
	ldx     _currentFrame+1
	lda     _currentFrame
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	sta     _currentFrame
	stx     _currentFrame+1
	ldy     sreg
	sty     _currentFrame+2
	ldy     sreg+1
	sty     _currentFrame+3
	jsr     resteax
	ldx     #$40
	lda     #$16
	jsr     pushax
	jsr     _rNES_get_joy
	sta     _joy
	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$01
	stx     tmp1
	ora     tmp1
	jeq     L02CD
	ldx     #$00
	lda     _level
	jsr     pushax
	ldx     #$00
	lda     #$03
	jsr     tosudivax
	jsr     incax1
	ldx     #$00
	clc
	adc     _playerX
	sta     _playerX
	ldx     #$00
	lda     _playerX
	cmp     #$F1
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L02D2
	ldx     #$00
	lda     #$F0
	sta     _playerX
L02D2:	jmp     L02DC
L02CD:	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$02
	stx     tmp1
	ora     tmp1
	jeq     L02DC
	ldx     #$00
	lda     _level
	jsr     pushax
	ldx     #$00
	lda     #$03
	jsr     tosudivax
	jsr     incax1
	ldx     #$00
	eor     #$FF
	sec
	adc     _playerX
	sta     _playerX
	ldx     #$00
	lda     _playerX
	cmp     #$08
	jsr     boolult
	jeq     L02DC
	ldx     #$00
	lda     #$08
	sta     _playerX
L02DC:	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$01
	stx     tmp1
	ora     tmp1
	jne     L02E1
	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$02
	stx     tmp1
	ora     tmp1
	jne     L02E1
	ldx     #$00
	lda     #$00
	jeq     L02E4
L02E1:	ldx     #$00
	lda     #$01
L02E4:	jeq     L02E0
	lda     #$01
	jsr     pusha
	lda     #$A8
	jsr     pusha
	lda     #$03
	jsr     pusha
	ldx     #$06
	lda     #$A4
	jsr     pushax
	jsr     _rNES_sound
	lda     _playerX
	jsr     pusha
	lda     _playerY
	jsr     pusha
	jsr     _move_player
	lda     _currentFrame
	ldx     _currentFrame+1
	jsr     pushax
	jsr     _animate_player
	jmp     L02F0
L02E0:	ldx     #$00
	lda     #$00
	jsr     pushax
	jsr     _animate_player
L02F0:	ldx     #$00
	lda     _rocketState
	cmp     #$01
	jsr     booleq
	jeq     L02F3
	jsr     _rocket_hit
	cpx     #$FF
	bne     L02F7
	cmp     #$FF
L02F7:	jsr     boolne
	jeq     L02F5
	lda     _kills
	ldx     _kills+1
	sta     regsave
	stx     regsave+1
	jsr     incax1
	sta     _kills
	stx     _kills+1
	lda     regsave
	ldx     regsave+1
	lda     _score
	ldx     _score+1
	jsr     pushax
	ldx     #$00
	lda     _level
	jsr     tosaddax
	jsr     incax1
	sta     _score
	stx     _score+1
	lda     #$02
	jsr     pusha
	lda     #$A8
	jsr     pusha
	lda     #$0A
	jsr     pusha
	ldx     #$07
	lda     #$D0
	jsr     pushax
	jsr     _rNES_sound
	jsr     _rocket_hit
	jsr     pusha
	jsr     _destroy_invader
	ldx     #$00
	lda     #$02
	sta     _rocketState
	jmp     L030B
L02F5:	ldx     #$00
	lda     _rocketY
	cmp     #$29
	jsr     boolult
	jeq     L0306
	ldx     #$00
	lda     #$00
	sta     _rocketState
	jsr     _despawn_rocket
	jmp     L030B
L0306:	ldx     #$00
	lda     _rocketY
	sec
	sbc     #$07
	sta     _rocketY
	lda     _rocketX
	jsr     pusha
	lda     _rocketY
	jsr     pusha
	jsr     _move_rocket
	lda     _currentFrame
	ldx     _currentFrame+1
	jsr     pushax
	jsr     _animate_rocket
L030B:	jmp     L032A
L02F3:	ldx     #$00
	lda     _rocketState
	cmp     #$00
	jsr     booleq
	jeq     L0314
	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$80
	stx     tmp1
	ora     tmp1
	jeq     L0316
	ldx     #$00
	lda     #$01
	sta     _rocketState
	ldx     #$00
	lda     _playerX
	sta     _rocketX
	ldx     #$00
	lda     _playerY
	jsr     decax8
	sta     _rocketY
	ldx     #$00
	lda     #$0C
	sta     _rocketExplosionFrames
L0316:	jmp     L032A
L0314:	ldx     #$00
	lda     _rocketState
	cmp     #$02
	jsr     booleq
	jeq     L032A
	ldx     #$00
	lda     _rocketExplosionFrames
	pha
	sec
	sbc     #$01
	sta     _rocketExplosionFrames
	pla
	ldx     #$00
	lda     _rocketExplosionFrames
	cmp     #$00
	jsr     booleq
	jeq     L0325
	ldx     #$00
	lda     #$00
	sta     _rocketState
	jsr     _despawn_rocket
	jmp     L032A
L0325:	lda     _rocketX
	jsr     pusha
	lda     _rocketY
	jsr     pusha
	jsr     _move_rocket
	lda     _currentFrame
	ldx     _currentFrame+1
	jsr     pushax
	jsr     _animate_rocket
L032A:	lda     _currentFrame+3
	sta     sreg+1
	lda     _currentFrame+2
	sta     sreg
	ldx     _currentFrame+1
	lda     _currentFrame
	jsr     pusheax
	ldx     #$00
	lda     #$0A
	jsr     pushax
	ldx     #$00
	lda     _level
	jsr     tossubax
	jsr     axulong
	jsr     tosumodeax
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$00
	jsr     toseqeax
	jeq     L0348
	ldx     #$00
	lda     #$00
	sta     _i
	stx     _i+1
L0333:	lda     _i
	ldx     _i+1
	cpx     #$00
	bne     L033A
	cmp     #$0A
L033A:	jsr     boolult
	jne     L0336
	jmp     L0334
L0336:	lda     #<(_invaderAlive)
	ldx     #>(_invaderAlive)
	clc
	adc     _i
	tay
	txa
	adc     _i+1
	tax
	tya
	ldy     #$00
	jsr     ldauidx
	jeq     L0335
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	clc
	adc     _i
	tay
	txa
	adc     _i+1
	tax
	tya
	jsr     pushax
	ldy     #$00
	jsr     ldauidx
	pha
	clc
	adc     #$01
	ldy     #$00
	jsr     staspidx
	pla
	lda     #<(_invaderY)
	ldx     #>(_invaderY)
	clc
	adc     _i
	tay
	txa
	adc     _i+1
	tax
	tya
	ldy     #$00
	jsr     ldauidx
	cmp     #$B5
	lda     #$00
	ldx     #$00
	rol     a
	jeq     L0335
	ldx     #$00
	lda     #$01
	ldy     #$00
	sta     (sp),y
L0335:	lda     _i
	ldx     _i+1
	sta     regsave
	stx     regsave+1
	jsr     incax1
	sta     _i
	stx     _i+1
	lda     regsave
	ldx     regsave+1
	jmp     L0333
L0334:	lda     _currentFrame
	ldx     _currentFrame+1
	jsr     pushax
	jsr     _animate_invaders
	jsr     _need_to_spawn
	tax
	jeq     L0348
	jsr     _spawn_enemy
L0348:	ldy     #$00
	lda     (sp),y
	jeq     L034B
	ldx     #$00
	lda     #$00
	sta     _j
	stx     _j+1
L034D:	lda     _j
	ldx     _j+1
	cpx     #$00
	bne     L0354
	cmp     #$0A
L0354:	jsr     boolult
	jne     L0350
	jmp     L034E
L0350:	lda     _j
	jsr     pusha
	jsr     _destroy_invader
	lda     _j
	ldx     _j+1
	sta     regsave
	stx     regsave+1
	jsr     incax1
	sta     _j
	stx     _j+1
	lda     regsave
	ldx     regsave+1
	jmp     L034D
L034E:	jsr     _despawn_rocket
	jsr     _destroy_player
L034B:	ldx     #$00
	lda     $2002
	sta     _PPU_status
	ldx     #$00
	lda     _PPU_status
	ldx     #$00
	and     #$80
	stx     tmp1
	ora     tmp1
	jeq     L0361
	jmp     L035B
L0361:	jmp     L034B
L035B:	lda     #$02
	jsr     pusha
	lda     #$00
	jsr     pusha
	jsr     _rNES_sprite_dma
	ldy     #$00
	lda     (sp),y
	jeq     L0368
	lda     #$01
	jsr     pusha
	lda     #$C0
	jsr     pusha
	lda     #$08
	jsr     pusha
	ldx     #$03
	lda     #$E8
	jsr     pushax
	jsr     _rNES_sound
	ldx     #$00
	lda     #$00
	sta     _i
	stx     _i+1
L0370:	lda     _i
	ldx     _i+1
	cpx     #$4E
	bne     L0377
	cmp     #$20
L0377:	jsr     boolult
	jne     L0373
	jmp     L0371
L0373:	lda     _i
	ldx     _i+1
	sta     _j
	stx     _j+1
	lda     _i
	ldx     _i+1
	sta     regsave
	stx     regsave+1
	jsr     incax1
	sta     _i
	stx     _i+1
	lda     regsave
	ldx     regsave+1
	jmp     L0370
L0371:	jmp     L02C1
L0368:	jmp     L02C0
L02C1:	jsr     incsp1
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ intro (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_intro: near

.segment	"RODATA"

L037C:
	.byte	$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$00

.segment	"CODE"

	ldy     #$0C
	jsr     subysp
	ldy     #$0B
L037D:	lda     L037C,y
	sta     (sp),y
	dey
	bpl     L037D
	jsr     _initializeSystem
	jsr     _drawBackground
	ldx     #$23
	lda     #$C0
	jsr     pushax
	ldx     #$00
	lda     #$08
	jsr     pushax
	lda     #$55
	jsr     pusha
	jsr     _rNES_fill_vram
	ldx     #$23
	lda     #$F0
	jsr     pushax
	ldx     #$00
	lda     #$10
	jsr     pushax
	lda     #$AA
	jsr     pusha
	jsr     _rNES_fill_vram
	lda     #<(L0001+122)
	ldx     #>(L0001+122)
	jsr     pushax
	lda     #$04
	jsr     pusha
	lda     #$19
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     #<(L0001+147)
	ldx     #>(L0001+147)
	jsr     pushax
	lda     #$00
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     sp
	ldx     sp+1
	jsr     pushax
	lda     _score
	ldx     _score+1
	jsr     pushax
	jsr     _Itoa
	lda     #<(L0001+180)
	ldx     #>(L0001+180)
	jsr     pushax
	lda     #$00
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     sp
	ldx     sp+1
	jsr     pushax
	lda     #$06
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     sp
	ldx     sp+1
	jsr     pushax
	lda     _highscore
	ldx     _highscore+1
	jsr     pushax
	jsr     _Itoa
	lda     #<(L0001+186)
	ldx     #>(L0001+186)
	jsr     pushax
	lda     #$0D
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     sp
	ldx     sp+1
	jsr     pushax
	lda     #$17
	jsr     pusha
	lda     #$02
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	lda     #<(L0001+196)
	ldx     #>(L0001+196)
	jsr     pushax
	lda     #$09
	jsr     pusha
	lda     #$03
	jsr     pusha
	ldx     #$20
	lda     #$00
	jsr     pushax
	lda     #<(_charset)
	ldx     #>(_charset)
	jsr     pushax
	jsr     _rNES_print
	ldy     #$00
	jsr     _rNES_enable_graphics
L03BB:	ldx     #$00
	lda     $2002
	ldx     #$00
	and     #$80
	jsr     bnegax
	jeq     L03BC
	jmp     L03BB
L03BC:	lda     _currentFrame+3
	sta     sreg+1
	lda     _currentFrame+2
	sta     sreg
	ldx     _currentFrame+1
	lda     _currentFrame
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	sta     _currentFrame
	stx     _currentFrame+1
	ldy     sreg
	sty     _currentFrame+2
	ldy     sreg+1
	sty     _currentFrame+3
	jsr     resteax
	ldx     #$40
	lda     #$16
	jsr     pushax
	jsr     _rNES_get_joy
	sta     _joy
	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$10
	stx     tmp1
	ora     tmp1
	jeq     L03C9
L03CC:	ldx     #$00
	lda     _joy
	ldx     #$00
	and     #$10
	stx     tmp1
	ora     tmp1
	jeq     L03CD
	ldx     #$40
	lda     #$16
	jsr     pushax
	jsr     _rNES_get_joy
	sta     _joy
	jmp     L03CC
L03CD:	jmp     L03C3
L03C9:	ldx     #$00
	lda     $2002
	sta     _PPU_status
	ldx     #$00
	lda     _PPU_status
	ldx     #$00
	and     #$80
	stx     tmp1
	ora     tmp1
	jeq     L03DA
	jmp     L03D4
L03DA:	jmp     L03C9
L03D4:	jmp     L03BC
L03C3:	ldy     #$0C
	jsr     addysp
	rts

.endproc

; ---------------------------------------------------------------
; void __near__ main (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_main: near

.segment	"CODE"

L03DF:	jsr     _intro
	jsr     _game
	lda     _score
	ldx     _score+1
	jsr     pushax
	lda     _highscore
	ldx     _highscore+1
	jsr     tosugtax
	jeq     L03E4
	lda     _score
	ldx     _score+1
	sta     _highscore
	stx     _highscore+1
L03E4:	jmp     L03DF
	rts

.endproc

