low   = $fb
high  = $fc
low2  = $fd
high2 = $fe


* = $0801
        ;-----------------
        ; basic run line -
        ;-----------------

        .byte $0b,$08,$00,$00,$9e,$32,$30,$36,$34,$00,$00,$00,$00,$00,$00

        ;---------------
        ;display stuff -
        ;---------------

        lda #0
        sta $d020
        sta $d021
        lda #$17
        sta $d018

        jsr $e544

        lda #$05
        ldx #0
loop
        sta $d800,x
        sta $d900,x
        sta $da00,x
        sta $db00,x
        inx
        bne loop

        lda #<$0400
        sta low
        lda #>$0400
        sta high
        lda #<text
        sta low2
        lda #>text
        sta high2
puttext
        ldy #0
        lda (low2),y
        beq nextline
        cmp #$ff
        beq endtext
        sta (low),y
        iny
        bne puttext+2
nextline
        lda low
        clc
        adc #40
        sta low
        bcc *+4
        inc high
        tya
        sec
        adc low2
        sta low2
        bcc *+4
        inc high2
        jmp puttext
endtext
        ;-----------------
        ; wait for space -
        ;-----------------

        lda $dc01
        and #$10
        bne *-5

        ;-----------------
        ; game init code -
        ;-----------------

;---------------------------------------------------------------------------------------------------------------------------

        ;----------------------
        ; disable restore key -
        ;----------------------

restoreprotect
         sei

         lda #<nmi+1
         sta $0318
         lda #>nmi+1
         sta $0319
         lda #$81
         sta $dd0d
         ldx #$00
         stx $dd05
         inx
         stx $dd04
         lda #$dd
         sta $dd0e
nmi
         lda #$40   ;$40=rti!

         bit $d011           ;wait until nmi to trigger
         bpl *-3
         bit $d011
         bmi *-3

;------------------------------------------------------------------------------------------

         ;------------------
         ; init cia timers -
         ;------------------
timerinit
	; Disable all interferences
	lda #$00
	sta $d015
         lda #$35
	sta $01
	;lda #$01
	;sta $d01a
	lda #$7f
	sta $dc0d
	bit $dc0d

	; Wait for raster line 0 twice to make sure there are no sprites
	ldx #1
	bit $d011
	bpl *-3
	bit $d011
	bmi *-3
         dex
         bpl *-11

	; Achieve an initial stable raster point using halve invariance method
	ldx $d012
	inx
	cpx $d012
	bne *-3
	ldy #$0a
	dey
	bne *-1
	inx
	cpx $d012
	nop
	beq *+5
	nop
	bit $24
	ldy #$09
	dey
	bne *-1
	nop
	nop
	inx
	cpx $d012
	nop
	beq *+4
	bit $24
	ldy #$0a
	dey
	bne *-1
	inx
	cpx $d012
	bne *+2
	nop
	nop
	nop
	nop
	nop
	; Raster is stable here

	nop
	nop
	bit $ff

         ; Start a continious timer with 63 ticks each loop
	lda #$3e
	sta $dc04
	sty $dc05
	lda #%00010001
	sta $dc0e

;------------------------------------------------------------------------------------------

        ;----------------------
        ; copy game to memory -
        ;----------------------

        lda #<startoftable+2
        sta low
        lda #>startoftable+2
        sta high

        lda #<$0801
        sta low2
        lda #>$0801
        sta high2

        ldy #0
        lda copyroutine,y
        sta $0400,y
        iny
        bne *-7
        jmp $0400

copyroutine

        lda #$35
        sta $01

        ldy #0
copy
        lda (low),y
        sta (low2),y
        iny
        bne *-5

        inc high
        inc high2
        lda high2
        cmp #>endoftable
        beq copy
        bcc copy

        lda #$0b
        sta $d011
        lda #6
        sta $d021
        lda #0
        sta $d020

        ;if using exomizer, set $01 to $37
        ;if using pucrunch, comment these lines away!

        ;lda #$37
        ;sta $01

        jmp $080d     ;pucrunch : $080d   exo2beta 080b

text          ;1234567890123456789012345678901234567890
        .text "-pinball dreams c64  version 06-02-2006-"
        .byte 0,0
        .text "some instructions :",0,0
        .text "- left-shift to operate left flipper",0
        .text "- / to operate right flipper",0
        .text "- pound sign (",28,") (ins key on winvice)",0
        .text "  to operate spring",0
        .text "- joystick in port 2 to move ball around",0
        .text "  (press and hold fire)",0
        .text "- use flipper-keys to 'scroll' die/warp",0
        .text "  lights",0,0
        .text "        press space to start :)!        ",0,0
        .text "   (be patient during heavy decrunch)   "
        .byte $ff

startoftable
        .binary .\temp\table.prg
endoftable


