Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > stable rasters (again...)
2007-08-15 13:42
Iapetus/Algarbi/Wood

Registered: Dec 2004
Posts: 71
stable rasters (again...)

I have been playing with double irq for some time and I can't put the code to work, can someone please have a look
and tell me why I can't get my raster bars stable, thanks.
I use kickassembler and the code is an adaptation of the one here: http://codebase64.org/doku.php?id=base:fli_displayer


.pc = $0801 "Basic Program"
:BasicUpstart($1000)

.pc = $1000

	jmp start
irq0:	
	dec $d019
	inc $d012
	lda #<irq1
	sta $fffe      // set up 2nd IRQ to get a stable IRQ
	
	
	cli

        // Following here: A bunch of NOPs which allow the 2nd IRQ
        // to be triggered with either 0 or 1 clock cycle delay
        // resulting in an "almost" stable IRQ.

	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
irq1:
	nop
	nop
	nop
	nop
	nop
	nop
	
	nop
	nop
	nop
	
	bit $ea
	
	
	
	
	
	lda #$2d
	sta $d012
	lda #<irq0
	sta $fffe      // switch IRQ back to first stabilizer IRQ
	
	
	lda $d012
	cmp $d012      // stabilize last jittering cycle
	beq delay2      // if equal, 2 cycles delay. else 3 cycles delay

	

delay2:

	    
       ldx #$00			  //2
v:     lda rastercols,x   //4
	   sta $d020 		  //4
//	   sta $d021		  //4
//nop
//nop
bit $ea
	   ldy delay,x		  //4
	   dey				  //2
	   bne *-1			  //2 or 3
	   inx				  //2
	   cpx #48			  //2
	   bne v			  //2  or 3  = 30
	
	   bit $ea
	   
/*	
	ldx #$10
wait:	dex
	bne wait
*/


        // Following here is the main FLI loop which forces the VIC-II to read
        // new color data each rasterline. The loop is exactly 23 clock cycles
        // long so together with 40 cycles of color DMA this will result in
        // 63 clock cycles which is exactly the length of a PAL C64 rasterline.


	asl $d019
	
nmi:
	rti

start:
	sei
	lda #$35
	sta $01        // disable all ROMs
	lda #$7f
	sta $dc0d      // no timer IRQs
	lda $dc0d      // clear timer IRQ flags
	lda #$1b
	sta $d011
	lda #$2d
	sta $d012
	   
 
     
 
         lda #$00    //Set Background
         ldx #BLACK    //and Border colors
        
         sta $d020   //turn off sprites
         stx $d021

	lda #<irq0
	sta $fffe
	lda #>irq0
	sta $ffff
	lda #<nmi
	sta $fffa
	lda #>nmi
	sta $fffb      // dummy NMI to avoid crashing due to RESTORE
	lda #$01
	sta $d01a      // enable raster IRQs



	dec $d019      // clear raster IRQ flag
	cli
	jmp *          // that's it, no more action needed

.pc = $0c00         
rastercols:			.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, ORANGE
					.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, ORANGE
					.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, BLACK
					.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, ORANGE
					.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, ORANGE
					.byte BLUE, PURPLE, GREEN, LIGHT_RED, PURPLE, BLACK, WHITE, BLACK
.pc = $0d00         					
delay:				.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
					.byte $08,$01,$08,$08,$08,$08, $08, $08
 
... 11 posts hidden. Click here to view all posts....
 
2007-08-16 15:27
Frantic

Registered: Mar 2003
Posts: 1648
hä hä hä
2007-08-16 16:53
Iapetus/Algarbi/Wood

Registered: Dec 2004
Posts: 71
very funny hehehe
2007-08-16 19:55
Slammer

Registered: Feb 2004
Posts: 416
A little tip. I find it very usefull to put the stable raster routine in a library so you dont have to rewrite it every time. In my library it looks like the code below.

It uses some small pseudo commands from other libraries so you can't compile it directly, but I guess it's pretty intuitive what they do (:nop #8 does 8 nop commands, :mov16 moves a 16 bit value like lda, sta, lda, sta etc).
//---------------------------------------------------------------
// This is how you write your stable raster irq
//---------------------------------------------------------------
irq1:
	:irqStart_stableRaster 
	// Do your rasterbars here 	
	:irqEnd	


//---------------------------------------------------------------
// Defining irq start and end
//---------------------------------------------------------------
.pseudocommand irqStart_stableRaster {
	sta _ds_irqa	
	stx _ds_irqx
	sty _ds_irqy
	lsr $d019		
	inc $d012		
	:mov16 #irq2;$fffe       
	cli				
	:nop #8
irq2:
	:nop #14
	:pla #3
	lsr $d019
	lda $d012
	cmp $d012    
	beq *+2
}


.pseudocommand irqEnd nextIrqYpos ; nextIrq {
	.if (nextIrqYpos.getType()!=AT_NONE) {
		:mov nextIrqYpos ; $d012
	}	
	.if (nextIrq.getType()!=AT_NONE) {
		:mov16 nextIrq ; $fffe
	}	
	lda _ds_irqa
	ldx _ds_irqx
	ldy _ds_irqy
	rti
}



2007-10-13 14:40
Richard

Registered: Dec 2001
Posts:
I'm using DASM for my Sub Hunter project. I'm on to the bug fixing phase, but I'm experiencing difficulties to get the rasterline $c2 to stay still when sprites go over this area. Here is my source for inside the IRQ. (Game loops are outside the IRQ as usual). Temp 1 to temp 8 are all smooth scroll values for the parallax.
 SEI
                                LDA #$35
                                STA $01
                                LDA #<STAGE1_IRQ1
                                STA $FFFE
                                LDA #>STAGE1_IRQ1
                                STA $FFFF
                                LDA #$30
                                STA $D012
                                LDA #$7F
                                STA $DC0D
                                LDA #$1B
                                STA $D011
                                LDA #$01
                                STA $D01A
                                LDA $DC0D
                                LSR $D019
                                CLI
LOOP                            LDA #0
                                STA SYNC
WAITSYNC                        CMP SYNC
                                BEQ SYNCWAIT
                                JSR GAMELOOP
                                JMP LOOP 

STAGE1_IRQ1:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$01
				STA SYNC
			;	LDA #$35
			;	STA $01
				JSR $E003

				LDA #$47
				STA $D012
				
				
				
				LDA #$18
				STA $D016
				LDA #$0f
				STA $D021
				LDA #$01
				STA $D022
				LDA #$09
				STA $D023
				LDA #$00
				STA $D015
				;LDA #$01
				;STA $D020
				LDA #<STAGE1_IRQ2
				STA $FFFE
				LDA #>STAGE1_IRQ2
				STA $FFFF
				
				
			;	LDA #$37
			;	STA $01
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				
STAGE1_IRQ2: 	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$48
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			
				
				LDA #$0f
				STA $D021
				LDA #$09
				STA $D022
				LDA #$03
				STA $D023
				LDA #$10
				STA $D016
				LDA #$FF
				STA $D015
				;LDA #$02
				;STA $D020
				LDA #<STAGE1_IRQ3
				STA $FFFE
				LDA #>STAGE1_IRQ3
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				
STAGE1_IRQ3:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$6A
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			
	
				

				LDA TEMP1
				ORA #$10
				STA $D016
				;LDA #$03
				;STA $D020
				LDA #$0E
				STA $D021
				LDA #$01
				STA $D022
				LDA #$0E
				STA $D023
				LDA #<STAGE1_IRQ4
				STA $FFFE
				LDA #>STAGE1_IRQ4
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
STAGE1_IRQ4:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$7A
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			

				
				LDA TEMP2
				ORA #$10
				STA $D016
				;LDA #$04
				;STA $D020
				LDA #$0E
				STA $D021
				LDA #<STAGE1_IRQ5
				STA $FFFE
				LDA #>STAGE1_IRQ5
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				;JMP $EA7E
STAGE1_IRQ5:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$84
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			

				LDA TEMP2
				ORA #$10
				STA $D016
				;LDA #$06
				;STA $D020
				LDA #$00
				STA $D022
				LDA #$0B
				STA $D021
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ6
				STA $FFFE
				LDA #>STAGE1_IRQ6
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				;JMP $EA7E
				;JMP $EA7E
STAGE1_IRQ6:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$98
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			

				

				LDA TEMP6
				ORA #$10
				STA $D016
				;LDA #$07
				;STA $D020
				LDA #$0B
				STA $D021
				STA $D022
				STA $D023
				LDA #<STAGE1_IRQ7
				STA $FFFE
				LDA #>STAGE1_IRQ7
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				
				;JMP $EA7E
				;JMP $EA7E
STAGE1_IRQ7:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$AA
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			

				

				;LDA #$08
				;STA $D020
				
			
				LDA TEMP6
				ORA #$10
				STA $D016
				LDA #$0B
				STA $D021
				LDA #$0B
				STA $D022
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ8
				STA $FFFE
				LDA #>STAGE1_IRQ8
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				;JMP $EA7E
STAGE1_IRQ8:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$C2
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				LDA #$0E
				STA $D021
				LDA #$0B
				STA $D023
				LDA #$01
				STA $D022
				LDA TEMP7
				ORA #$10
				STA $D016
				LDA #<STAGE1_IRQ9
				STA $FFFE
				LDA #>STAGE1_IRQ9
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI
				
STAGE1_IRQ9:	PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$E3
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			
				
				
				
				;LDA #$0B
				;STA $D020
				LDA TEMP8
				ORA #$10
				STA $D016
				LDA #<STAGE1_IRQ10
				STA $FFFE
				LDA #>STAGE1_IRQ10
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
NMI:			RTI
STAGE1_IRQ10:	
				PHA
				TXA
				PHA
				TYA
				PHA
				LSR $D019
				LDA #$F2
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
			

				LDA #$18
				STA $D016
				LDA #$09
				STA $D023
				LDA #$0F
				STA $D021
				LDA #$01
				STA $D022
				LDA #0
				STA $D015
				LDA #<STAGE1_IRQ1
				STA $FFFE
				LDA #>STAGE1_IRQ1
				STA $FFFF
				PLA
				TAY
				PLA
				TAX
				PLA
				RTI

How do I tidy this routine so that there is no line flicker for when sprites go over raster line $C0 or is very close to it?
2007-10-13 14:54
chatGPZ

Registered: Dec 2001
Posts: 11386
the most obvious (and probably easiest) way would be to write 2 different routines, one thats timed for the case when there is no sprite, one thats timed for the case when there is a sprite, and switch between them accordingly.
2007-10-13 15:04
Oswald

Registered: Apr 2002
Posts: 5094
the speedup I see is that you save X&Y to the stack even when not destroying their value. you can do only one pha at the start and only one pla rti at the end when you destroy the val of A only.

edit, its also somewhat faster:

sta atemp+1

...dostuff

atemp lda #$00
rti

make sure your irq is not on a badline, also try to time the registerchanges so, that they happen in the previous rasterline, but already in the right sideborder ASAP.
2007-10-13 15:07
chatGPZ

Registered: Dec 2001
Posts: 11386
Quote:

you can do only one pha at the start and only one pla rti at the end when you destroy the val of A only


or better yet, don't use the stack at all, but use the magic of LDA and STA =P
2007-10-13 15:28
Richard

Registered: Dec 2001
Posts:
You guys are great :)

I tried fixing the IRQ by putting the multiple irqs into good raster positions and the routine works successfully :)

Thanks for your help :)


2007-10-20 19:15
Richard

Registered: Dec 2001
Posts:
Damn I spoke too soon. At $C2 there is still a flicker when a sprite goes over it. :( I tried this for Sub Hunter, but it seems to cause me problems :(

STAGE1_IRQ1: STA I1+1
				LSR $D019
				
				
				LDA #$42
				STA $D012
				;TSX
				
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				;TSX
				LDA #$00
				STA $D015
				LDA #$18
				STA $D016
				LDA #$0F
				STA $D021
				LDA #$01
				STA $D022
				LDA #$09
				STA $D023
				LDA #<STAGE1_IRQ2
				STA $FFFE
				LDA #>STAGE1_IRQ2
				STA $FFFF
				
I1 				LDA #0
NMI 			RTI
STAGE1_IRQ2 	STA I2+1
				LSR $D019
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				LDA #$4A
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				LDA #$FF
				STA $D015
				LDA #$10
				STA $D016
				LDA #$0F
				STA $D021
				LDA #$09
				STA $D022
				LDA #$03
				STA $D023
				LDA #<STAGE1_IRQ3
				STA $FFFE
				LDA #>STAGE1_IRQ3
				STA $FFFF
I2				LDA #0
				RTI
STAGE1_IRQ3 	STA I3+1
				LSR $D019
				CLI

				LDA #$6A
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
								LDA TEMP1
				ORA #$10
				STA $D016
				LDA #$0E
				STA $D021
				LDA #$01
				STA $D022
				LDA #$0E
				STA $D023
				LDA #<STAGE1_IRQ4
				STA $FFFE
				LDA #>STAGE1_IRQ4
				STA $FFFF
			
I3 				LDA #0
				RTI
STAGE1_IRQ4 	STA I4+1
				LSR $D019
				CLI

				LDA #$82
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
								LDA TEMP2
				ORA #$10
				STA $D016
				LDA #$0E
				STA $D021
				LDA #$01
				STA $D022
				LDA #$0b
				STA $D023
				LDA #<STAGE1_IRQ5
				STA $FFFE
				LDA #>STAGE1_IRQ5
				STA $FFFF
			
I4 				LDA #0
				RTI
STAGE1_IRQ5 	STA I5+1
				LSR $D019

				LDA #$8a
				STA $D012
NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
								

				LDA TEMP3
				ORA #$10
				STA $D016
				LDA #$0B
				STA $D021
				LDA #$00
				STA $D022
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ6
				STA $FFFE
				LDA #>STAGE1_IRQ6
				STA $FFFF
			
				
I5 				LDA #0
				RTI
STAGE1_IRQ6 	STA I6+1
				LSR $D019
				CLI

				LDA #$98
				STA $D012
						NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				

				LDA TEMP6
				ORA #$10
				STA $D016
				LDA #$0B
				STA $D021
				LDA #$0B
				STA $D022
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ7
				STA $FFFE
				LDA #>STAGE1_IRQ7
				STA $FFFF
			
I6				LDA #0
				RTI
STAGE1_IRQ7 	STA I7+1
				LSR $D019
				CLI

				LDA #$aa
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				LDA TEMP6
				ORA #$10
				STA $D016
				LDA #$0B
				STA $D021
				LDA #$0B
				STA $D022
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ8
				STA $FFFE
				LDA #>STAGE1_IRQ8
				STA $FFFF
						
I7 				LDA #0
				RTI
STAGE1_IRQ8 	STA I8+1
				STX I8X+1
				STY I8X+1
				
				DEC $D019			
				
				;DEC $D011
				LDA #$C2
				STA $D012		
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				LDA	TEMP7
				ORA #$10
				STA $D016
				LDA #$0E
				STA $D021
				LDA #$01
				STA $D022
				LDA #$0B
				STA $D023
				
				LDA #<STAGE1_IRQ9
				STA $FFFE
				LDA #>STAGE1_IRQ9
				STA $FFFF
				 				
I8 				LDA #0
I8X				LDX #0
I8Y				LDY #0
				RTI
STAGE1_IRQ9 	STA I9+1
				LSR $D019
				
				LDA #$E2
				STA $D012
			
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				
				LDA TEMP8
				ORA #$10
				STA $D016
				LDA #$0E
				STA $D021
				LDA #$01
				STA $D022
				LDA #$0B
				STA $D023
				LDA #<STAGE1_IRQ10
				STA $FFFE
				LDA #>STAGE1_IRQ10
				STA $FFFF
								
I9 				LDA #0
				RTI
STAGE1_IRQ10 	STA I10+1
				LSR $D019
				

				LDA #$F2
				STA $D012
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
				NOP
								
				LDA #$00
				STA $D015
				LDA #$18
				STA $D016
				LDA #$0F
				STA $D021
				LDA #$01
				STA $D022
				LDA #$09
				STA $D023
				LDA #<STAGE1_IRQ1
				STA $FFFE
				LDA #>STAGE1_IRQ1
				STA $FFFF
				
				LDA #$01
				STA SYNC
				JSR $E003
				
I10 			LDA #0
				RTI


If a certain sprite hits raster line $C2 what code should I use to stop the flicker from happening on the next raster line (bad line $c3) so that the parallax scrolling like the previous rasters are stable enough ?

2007-10-21 17:37
Oswald

Registered: Apr 2002
Posts: 5094
LDA TEMP8
LDX #$0E
LDY #$01
STA $D016
STX $D021
STY $D022
LDA #$0B
STA $D023

you can make it tighter with some preloading. also I see no point of lda temp8 ora #$10.. make temp8 outside the irq having pre-ora-ed already.
Previous - 1 | 2 | 3 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
MCM/ONSLAUGHT
Jammer
danikAdmiral
Guests online: 106
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.