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 > Howto flickerfree and moving rasterbar ?
2009-10-19 23:18
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Howto flickerfree and moving rasterbar ?

<Post edited by moderator on 20/10-2009 01:24>

Making a perfect stable, flickerfree and moving rasterbar is harder than I thought.
Why and which changes are needed to the code below to fulfill my dream about the flickerfree rasterbar?
The code is based on http://www.ffd2.com/fridge/vic/stableraster.txt.
Acme code ready to compile:

!to "doubleirqrasterbar1.prg",cbm  

*= $0800
!byte $00,$0c,$08,$0a,$00,$9e,$33,$32,$37,$36,$38,$00,$00,$00,$00	
 
raspos    = $00
maxpos    = $7c

         *= $8000    ;Assemble to $8000       
         
         cld         ;Clear Decimal Mode
         sei         ;Disable IRQ's
         lda #$1f    ;Disable CIA IRQ's
         sta $dc0d
         sta $dd0d
 
;        lda #<nmi   ;Install NMI into
;        ldx #>nmi   ;Hardware NMI and
;        sta $fffa   ;RESET Vectors
;        sta $fffc
;        stx $fffb
;        stx $fffd
 
         lda #<irq1  ;Install RASTER IRQ
         ldx #>irq1  ;into Hardware
         sta $0314   ;Interrupt Vector
         stx $0315
 
;        lda #$35    ;Set MMU to RAM at
;        ldx #$ff    ;$a000-$bfff and
;        sta $01     ;$e000-$ffff
;        txs         ;Clear the STACK
 
         lda #$01    ;Enable RASTER IRQ
         ldx #$1b    ;High bit of RASTER
         ldy #$34    ;compare register
         sta $d01a   ;and RASTER IRQ to
         stx $d011   ;line $34
         sty $d012
                     ;NOTE double IRQ
                     ;cannot be on or
                     ;around a BAD LINE!
                     ;(Fast Line)
 
         lda #$0e    ;Set Background
         ldx #$06    ;and Border colors
         ldy #$00    ;to default and
         sta $d020   ;turn off sprites
         stx $d021
         sty $d015
 
         jsr clrscreen
         jsr clrcolor
;        jsr printtext
 
         asl $d019   ;Ack any previous
         lda $dc0d   ;IRQ's
         lda $dd0d
 
         cli         ;Renable IRQ's
 
         jmp *       ;Endless Loop
 
 
irq1
         sta reseta1 ;Preserve A,X and Y
         stx resetx1 ;Registers
         sty resety1 ;VIA self modifying
                     ;code
                     ;(Faster than the
                     ;STACK is!)
 
         lda #<irq2  ;Set IRQ Vector
         ldx #>irq2  ;to point to the
         ldy #$35    ;next part of the
         sta $0314   ;Stable IRQ
         stx $0315   ;ON NEXT LINE!
         sty $d012
         asl $d019   ;Ack RASTER IRQ
         tsx         ;We want the IRQ
         cli         ;To return to our
         nop         ;endless loop
         nop         ;NOT THE END OF
         nop         ;THIS IRQ!
         nop
         nop         ;Execute nop's
         nop         ;until next RASTER
         nop         ;IRQ Triggers
         nop
         nop         ;2 cycles per
         nop         ;instruction so
         nop         ;we will be within
         nop         ;1 cycle of RASTER
         nop         ;Register change
 
;        nop  ;<--- remove 1 NOP for PAL

irq2
         txs         ;Restore STACK
                     ;Pointer
         ldx #$08    ;Wait exactly 1
         dex         ;lines worth of
         bne *-1     ;cycles for compare
         bit $ea     ;Minus compare
         nop         ;cycles
 
;        nop  ;<--- remove 1 NOP for PAL
 
         lda #$35    ;RASTER change yet?
         cmp $d012
         beq start   ;If no waste 1 more
                     ;cycle
start

         ldx raspos
         cpx #maxpos   
         beq setrastup
         inx
         stx raspos
         cpx #maxpos   
         bne rasterbarctrl

setrastup     
         ldx #$00
         stx raspos        ;Reset raster positon to 
                           ;zero if maximum has been reached.     

rasterbarctrl
         ldx raspos
         ldy rastmov,x    ;Wait for rasterline $3D-$96 at $D012 
wait     cpy $d012 
         bne wait 
        
                              ;rasterbar
         ldx #$00 
copy11   ldy rastime,x       
         dey                    
         bne *-1 
         lda coloursr,x       
         sta $d020 
         sta $d021 
         inx 
         cpx #$10
         bne copy11


         lda #<irq3  ;Set IRQ to point
         ldx #>irq3  ;to subsequent IRQ
         ldy #$b8    ;at line $68
         sta $0314
         stx $0315
         sty $d012
         asl $d019   ;Ack RASTER IRQ
 
         lda #$00    ;Reload A,X,and Y
reseta1  = *-1       ;registers
         ldx #$00
resetx1  = *-1
         ldy #$00
resety1  = *-1
 
;        rti         ;Return from IRQ
         jmp $ea31
irq3
         sta reseta2 ;Preserve A,X,and Y
         stx resetx2 ;Registers
         sty resety2
 
         ldx #$0a    ;Waste some more
         dex         ;time so effect
         bne *-1     ;can be seen
         nop
 
;        lda #$0e    ;More colors
;        ldx #$06
;	 nop:nop 
;        sta $d021   ;Cool! subsequent
;        stx $d021   ;IRQ's are also
                     ;stable :-)
                     ;Unless you are
                     ;running realtime
                     ;code :-)
 
         ldy #$18    ;Waste time so this
         dey         ;IRQ does not try
         bne *-1     ;to reoccur on the
                     ;same line!
 
         lda #<irq1  ;Reset Vectors to
         ldx #>irq1  ;first IRQ again
         ldy #$34    ;at line $34
         sta $0314
         stx $0315
         sty $d012
         asl $d019   ;Ack RASTER IRQ
 
         lda #$00    ;Reload A,X,and Y
reseta2  = *-1       ;registers
         ldx #$00
resetx2  = *-1
         ldy #$00
resety2  = *-1
 
;        rti         ;Return from IRQ
         jmp $ea81 
                     ;Pound RESTORE to
                     ;get back to Turbo
nmi
         asl $d019   ;Ack all IRQ's
         lda $dc0d
         lda $dd0d
         lda #$81    ;reset CIA 1 IRQ
         ldx #$00    ;remove raster IRQ
         ldy #$37    ;reset MMU to roms
         sta $dc0d
         stx $d01a
         sty $01
         ldx #$ff    ;clear the stack
         txs
         cli         ;reenable IRQ's
         jmp $9000   ;back to Turbo
 
clrscreen
         lda #$20    ;Clear the screen
         ldx #$00
clrscr   sta $0400,x
         sta $0500,x
         sta $0600,x
         sta $0700,x
         dex
         bne clrscr
         rts
clrcolor
         lda #$03    ;Clear color memory
         ldx #$00
clrcol   sta $d800,x
         sta $d900,x
         sta $da00,x
         sta $db00,x
         dex
         bne clrcol
         rts
 
printtext
         lda #$16    ;C-set = lower case
         sta $d018
 
         ldx #$00
moretext lda text1,x
 
         bpl lower   ;upper case ?
         eor #$80    ;yes
 
         bne lower+2
 
lower    and #$3f    ;lower case
         sta $0450,x
         inx
         cpx #$78
         bne moretext
exit     rts
 
text1
         !scr "Stable Raster IRQ sourc"
         !scr "e (PAL/NTSC)     "
         !scr "All Code by Fungus 1996"
         !scr "                 "
         !scr "Feel free to use and mo"
         !scr "dify this code :)"
 


;------------------------------------------------------------------------------- -
;raster data
;------------------------------------------------------------------------------- -

rastime      
             !byte $08,$08,$08,$08,$08,$08,$08,$01
             !byte $08,$08,$08,$08,$08,$08,$08,$01

coloursr     
             !byte $0b,$0b,$0c,$0c,$0f,$0f,$0d,$0d
             !byte $0d,$0f,$0f,$0c,$0c,$0b,$0b,$00


rastmov      
             !byte $3D,$3D,$3E,$3E,$3F,$3F,$40,$40,$41,$42,$43,$44,$45,$46,$47,$48
             !byte $49,$4A,$4C,$4E,$50,$52,$54,$56,$58,$5A,$5C,$5E,$60,$62,$64,$66
             !byte $68,$6A,$6C,$6E,$70,$72,$74,$76,$78,$7A,$7C,$7E,$80,$82,$84,$86
             !byte $88,$8A,$8C,$8E,$8F,$90,$91,$92,$93,$94,$94,$95,$95,$96,$96,$95
             !byte $95,$94,$94,$93,$93,$92,$91,$90,$8F,$8E,$8D,$8D,$8B,$89,$87,$85
             !byte $83,$81,$7F,$7D,$7B,$79,$77,$75,$73,$71,$6F,$6D,$6B,$69,$67,$65
             !byte $63,$61,$5F,$5D,$5B,$59,$57,$55,$53,$51,$4F,$4D,$4B,$49,$48,$47
             !byte $46,$45,$44,$43,$42,$41,$40,$40,$3F,$3F,$3E,$3E



 
... 71 posts hidden. Click here to view all posts....
 
2009-10-23 22:10
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Please try to help me out with my question if you have the knowledge to explain the problem.
Yes I know what an interrupt is.
2009-10-24 00:46
GT
Account closed

Registered: Sep 2008
Posts: 308
Quote: Please try to help me out with my question if you have the knowledge to explain the problem.
Yes I know what an interrupt is.


Yeah, tell me how a interrupt works. :)
2009-10-24 07:11
MagerValp

Registered: Dec 2001
Posts: 1078
Quote: Please try to help me out with my question if you have the knowledge to explain the problem.
Yes I know what an interrupt is.


That was explained in post #4 in this thread, which you apparently ignored. Stop cutting and pasting code. You need to write it yourself to understand it.
2009-10-24 08:31
8bitforever
Account closed

Registered: Oct 2009
Posts: 48
Magervalp, Parts of the rasterbar code part is written by me. I have also tried to combine it with the original hardware irq vector code also. I have the same problem making it stable and flickerfree with that code.
Please compile and review the code. I need your deep knowledge to fix this.
2009-10-24 08:46
Steppe

Registered: Jan 2002
Posts: 1510
No, you need to switch on your brain.
2009-10-24 11:16
chatGPZ

Registered: Dec 2001
Posts: 11386
the code has still the same problems that have been pointed out earlier in this thread. nothing more to say really.

"The last time I coded the c64 was some 23 years ago. For some reason I remember a lot of things."

hillarious =)


2009-10-24 11:48
Mr. SID

Registered: Jan 2003
Posts: 424
2009-10-24 16:44
Skate

Registered: Jul 2003
Posts: 494
@8bitforever: a quick dirty code for your pleasure. please don't ask any more questions (for a while at least).

	!to "rasterbars.prg",cbm

FIRST_RASTER_POSITION = $30

Y_POSITION = $f0 ; zeropage address

	* = $0801

	; SYS 2061 ($080d)
	!byte $0b, $08, $00, $00, $9e, $32, $30, $36, $31, $00, $00, $00

	* = $080d

	lda #$00
	sta Y_POSITION

	cld
	sei
	lda #$1f
	sta $dc0d
	sta $dd0d

	lda #<irq1
	ldx #>irq1
	sta $fffe
	stx $ffff

	lda #$35
	ldx #$ff
	sta $01
	txs

	lda #$01
	ldx #$1b
	ldy #FIRST_RASTER_POSITION
	sta $d01a
	stx $d011
	sty $d012

	ldy #$c8
	sty $d016

	asl $d019
	lda $dc0d
	lda $dd0d

	cli
	jmp *

irq1
	sta reseta1
	stx resetx1
	sty resety1

	lda #<irq2
	ldx #>irq2
	ldy #FIRST_RASTER_POSITION+1
	sta $fffe
	stx $ffff
	sty $d012
	asl $d019
	tsx
	cli
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop

irq2
	txs

	ldx #$08
	dex
	bne *-1
	bit $ea
	nop

	lda #FIRST_RASTER_POSITION+1
	cmp $d012
	beq start

start
!for i,12 {
	bit $eaea
}
	; draw bars
	ldx #$00
-	lda color_table,x
	sta $d020
	sta $d021
	ldy timing_table,x
	dey
	bne *-1
	inx
	cpx #200
	bne -

	; copy bar colors
	ldx #$00
	ldy Y_POSITION
-	lda color_bar,x
	sta color_table,y
	iny
	inx
	cpx #color_bar_end-color_bar
	bne -

	; move bar position between 0-156
	inc Y_POSITION : opcode1 = *-2
	lda Y_POSITION
	beq +
	cmp #156
	beq +
	jmp ++
+	lda opcode1 ; inc/dec opcode switch
	eor #$20
	sta opcode1

++	lda #<irq1
	ldx #>irq1
	ldy #FIRST_RASTER_POSITION
	sta $fffe
	stx $ffff
	sty $d012
	asl $d019

	lda #$00 : reseta1 = *-1
	ldx #$00 : resetx1 = *-1
	ldy #$00 : resety1 = *-1
	rti

!align 255,0,0

timing_table
!for i,32 {
	!byte 1,8,8,8,8,8,8,8
}

color_table
	!fill 256, 0

color_bar
	!byte $00,$02,$00,$02,$0a,$00,$02,$0a
	!byte $07,$00,$02,$0a,$07,$01,$00,$02
	!byte $0a,$07,$01,$01,$01,$01,$01,$01
	!byte $01,$01,$07,$0a,$02,$00,$01,$07
	!byte $0a,$02,$00,$07,$0a,$02,$00,$0a
	!byte $02,$00,$02,$00
color_bar_end = *
2009-10-24 17:03
Frantic

Registered: Mar 2003
Posts: 1648
Finally "2009" is really 2009, thanks to Skate! I guess, in the future, that we won't even have to surf the solutions up on Google/Forums/etc, but the machines will code the stuff for us instead. But that is for 2010 I guess... ;)
2009-10-24 17:24
Skate

Registered: Jul 2003
Posts: 494
@Frantic: see what happens when he tries to move rasterbars differently :)
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 - 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
Mike
Jazzcat/Onslaught
E$G/HF ⭐ 7
XmikeX
Freeze/Blazon
Guests online: 302
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
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 Original Suppliers
1 Derbyshire Ram  (9.7)
2 Fungus  (9.3)
3 Black Beard  (9.2)
4 Baracuda  (9.2)
5 hedning  (9.1)

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