;************************************************************************** ;* ;* FILE startup.asm ;* Copyright (c) 2010 Daniel Kahlin ;* Written by Daniel Kahlin ;* ;* DESCRIPTION ;* ;****** processor 6502 seg code org $0801 ;************************************************************************** ;* ;* Basic line! ;* ;****** StartOfFile: dc.w EndLine dc.w 0 dc.b $9e,"2069 /T.L.R/",0 ; 0 SYS2069 /T.L.R/ EndLine: dc.w 0 ;************************************************************************** ;* ;* SysAddress... When run we will enter here! ;* ;****** SysAddress: sei lda #$7f sta $dc0d lda $dc0d jsr check_time sta cycles_per_line stx num_lines jsr test_present sei lda #$35 sta $01 ldx #6 sa_lp1: lda vectors-1,x sta $fffa-1,x dex bne sa_lp1 ldx cycles_per_line cpx #63 bcc sa_fl1 ;<63, fail cpx #66 ;>=66, fail bcs sa_fl1 lda time1-63,x sta is_sm1+1 ifconst HAVE_STABILITY_GUARD jsr start_guard endif jsr test_prepare jsr wait_vb lda #1 sta $d019 sta $d01a cli sa_lp2: if 0 ; be evil to timing to provoke glitches inx bpl sa_lp2 inc $4080,x dec $4080,x endif ifconst HAVE_TEST_CONTROLLER jsr test_controller endif ifconst HAVE_TEST_RESULT lda test_done beq sa_lp2 sei lda #$37 sta $01 ldx #0 stx $d01a inx stx $d019 jsr $fda3 jsr test_result sa_lp3: jmp sa_lp3 else jmp sa_lp2 endif vectors: dc.w nmi_entry,0,irq_stable sa_fl1: nmi_entry: sei lda #$37 sta $01 jmp $fe66 cycles_per_line: dc.b 0 num_lines: dc.b 0 ifconst HAVE_TEST_RESULT test_done: dc.b 0 endif time1: dc.b irq_stable2_pal, irq_stable2_ntscold, irq_stable2_ntsc ;************************************************************************** ;* ;* NAME irq_stable, irq_stable2 ;* ;****** irq_stable: sta accstore ; 4 sty ystore ; 4 stx xstore ; 4 inc $d019 ; 6 inc $d012 ; 6 is_sm1: lda # irq_stable2_ntscold: dc.b $24 ; bit irq_stable2_pal: dc.b $ea jsr twelve ; 12 jsr twelve ; 12 ;--- txs ; 2 dec $d019 ; 6 dec $d012 ; 6 lda #= cycles_per_line bcs ug_fl1 ; yes, fault! tya sta guard_last_cycle,x lda guard_mask,x and guard,y bne ug_ex1 lda guard_mask,x ora guard,y sta guard,y inc guard_count,x ug_ex1: rts ug_fl1: lda #$80 ora guard_count,x sta guard_count,x rts guard_mask: dc.b %00000001 dc.b %00000010 dc.b %00000100 dc.b %00001000 guard_count: ds.b MAX_GUARDS guard_last_cycle: ds.b MAX_GUARDS guard: ds.b MAX_GUARD_CYCLES ;************************************************************************** ;* ;* NAME check_guard ;* ;* DESCRIPTION ;* Check guard counts. ;* IN: X=guard# (0-3) ;* ;****** check_guard: lda guard_count,x rts endif ;HAVE_STABILITY_GUARD ifconst HAVE_ADJUST ;************************************************************************** ;* ;* NAME adjust_timing ;* ;****** adjust_timing: ldx cycles_per_line lda time2-63,x sta tm1_zp lda time3-63,x sta tm2_zp lda #test_start sta ptr_zp+1 ldx #>[test_end-test_start+255] at_lp1: ldy #0 lda #$d8 ; cld cmp (ptr_zp),y bne at_skp1 iny cmp (ptr_zp),y bne at_skp1 dey lda tm1_zp sta (ptr_zp),y iny lda tm2_zp sta (ptr_zp),y at_skp1: inc ptr_zp bne at_lp1 inc ptr_zp+1 dex bne at_lp1 rts ; eor #$00 (2), bit $ea (3), nop; nop (4) time2: dc.b $49, $24, $ea time3: dc.b $00, $ea, $ea ;****** ; end of line marker mac EOL ds.b 2,$d8 endm endif ;HAVE_ADJUST ; eof