cpu 6502
nam Bouncer
	int_lo = $0314
	int_hi = $0315
	chrin  = $FFCF
	chrout = $FFD2
	getin  = $FFE4
	plot   = $FFF0
	spenbl = $D015
	sp1clr = $D027
	sp1x   = $D000
	sp1y   = $D001
	sp2clr = $D028
	sp3clr = $D029
	sp4clr = $D02A
	sp5clr = $D02B
	sp6clr = $D02C
	sp7clr = $D02D
	sp8clr = $D02E

* = $0900  ; assemble at $900
code

	lda int_lo		; load a with the lo order byte of old int
	sta new_vec_lo		; store it in memory
	lda int_hi		; load a with the hi order byte of old int
	sta new_vec_hi		; store it in memory
	sei			; freeze interrupts

	
	lda #$10		; put the new routine into the old vector
	sta int_lo
	lda #$0A
	sta int_hi
	cli			; unfreeze interrupts
	lda #$20		; put locations of sprites in sprite vecotors
	sta $07F8
	lda #$21
	sta $07F9
	lda #$22
	sta $07FA

.lddta	lda sprite1,x		; copy sprite data
	sta $0800,x
	lda sprite2,x
	sta $0840,x
	lda sprite3,x
	sta $0880,x
	inx			; increment index (x)
	cpy #$3F		; compare it (x) with 63 decimal
	bne .lddta		; <= 63 do it again
	
	lda #$80		; locations of sprites
	sta sp1x
	sta sp1y
	
	lda #$07		; colours of sprites
	sta sp1clr
	
	lda #$01		; turn on sprite1
	sta spenbl
	rts

	;; SPRITE DATA
sprite1 db $0E, $00, $00, $11, $00, $00, $11, $00
	db $00, $0E, $00, $00, $04, $00, $00, $3F
	db $80, $00, $2E, $80, $00, $2E, $80, $00
	db $2E, $80, $00, $2E, $40, $00, $2E, $40
	db $00, $2A, $30, $00, $0A, $00, $00, $0A
	db $30, $00, $0A, $78, $00, $0A, $78, $00
	db $0A, $30, $00, $0A, $00, $00, $0A, $00
	db $00, $3B, $80, $00, $00, $00, $00

sprite2 db $0E, $00, $00, $11, $00, $00, $11, $00
	db $00, $0E, $00, $00, $04, $00, $00, $3F
	db $80, $00, $2E, $80, $00, $2E, $80, $00
	db $2E, $80, $00, $2E, $40, $00, $2E, $40
	db $00, $2A, $30, $00, $0A, $00, $00, $0A
	db $00, $00, $0A, $30, $00, $0A, $78, $00
	db $0A, $78, $00, $0A, $30, $00, $0A, $00
	db $00, $3B, $80, $00, $00, $00, $00

sprite3 db $0E, $00, $00, $11, $00, $00, $11, $00
	db $00, $0E, $00, $00, $04, $00, $00, $3F
	db $80, $00, $2E, $80, $00, $2E, $80, $00
	db $2E, $80, $00, $2E, $40, $00, $2E, $40
	db $00, $2A, $30, $00, $0A, $00, $00, $0A
	db $00, $00, $0A, $00, $00, $0A, $00, $00
	db $0A, $30, $00, $0A, $78, $00, $0A, $78
	db $00, $3B, $B0, $00, $00, $00, $00

	;; PLACE TO STORE NEW INTERRUPT VECTORS
	new_vec_lo db $FF
	new_vec_hi db $FF

	;; DRIBBLE
.newrtn	ldx sprite_ptr
	lda which_sprite, x
	inx
	stx sprite_ptr
	sta $07F8
	cpy #$0F
	bne .skip
	lda #$00
	sta sprite_ptr
.skip 	jmp (new_vec_lo)
	lda #$1F
	sta $07F8
	rts
	sprite_ptr	db $00		      ;the sprite index
	which_sprite 	db $20, $20, $20, $20, $20 ;the order of the sprites
	                db $21, $21, $21, $21, $21
	                db $22, $22, $22, $22, $22
                        db $21, $21, $21, $21, $21
	
	;; UNINSTALL (stop dribbling)
.uninst	sei
	lda new_vec_lo
	sta int_lo
	lda new_vec_hi
	sta int_hi
	cli
	rts

.mright ldx sp1x 		; move right
	inx
	inx
	stx sp1x
	rts

.mleft  ldx sp1x		; move left
	dex
	dex
	stx sp1x
	rts

.mup	ldy sp1y		; move up
	dey
	dey
	sty sp1y
	rts

.mdown  ldy sp1y		; move down
	iny
	iny
	sty sp1y
	rts

.shoot	nop			; shoot (not yet implemented)
	nop
	nop
	rts

	;; GAME
.game	lda $028B		; save and set kbd state
	sta kbd1		; so that all keys repeat quickly
	lda $028C
	sta kbd1
	lda $028A
	sta kbd3
	lda #$01
	sta $028B
	lda #$01
	sta $028C
	lda #$FF
	sta $028A
	
	
.tenmvs	jsr getin
	sta keypress		; Store the key pressed in memory
	cmp #$51		;Q
	beq .quit
	cmp #$91		;cursor up
	bne .notup
	jsr .mup
	jmp .tenmvs
.notup 	cmp #$11		;cursor down
	bne .notdown
	jsr .mdown
	jmp .tenmvs
.notdown cmp #$1D		;cursor right
	bne .notright
	jsr .mright
	jmp .tenmvs
.notright cmp #$9D		;cursor left
	bne .notleft
	jsr .mleft
.notleft cmp #$20		; space bar
	bne .notspace
	jsr .shoot
.notspace jmp .tenmvs		; nothing, so check again
	
.quit	lda kbd1		; restore kbd state
	sta $028B
	lda kbd2
	sta $028C
	lda kbd3
	sta $028A
	rts
	
	;; storage for keyboard stuff
	kbd1 db $00
	kbd2 db $00
	kbd3 db $00
	keypress db $00
	nop
	nop
	nop
code
