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


Forums > C64 Coding > Can anyone debug this terrible FLD code that isn't working
2022-05-09 14:47
Starfox

Registered: Jul 2014
Posts: 27
Can anyone debug this terrible FLD code that isn't working

Was fiddling with FLD, at work of course, but seems I've made a mistake somewhere. The FLD just flickers all over the screen.

Anyone? :)

Sorry for TERRIBLE formatting when posting the code here.


BasicUpstart2(main)

.var line = 81

main: sei // disable maskable interrupts

lda #$7f // disable timer interrupts
sta $dc0d
sta $dd0d
lda $dc0d // disable pending timer interrupts
lda $dd0d

lda #1
sta $d01a // tell VICII to generate a raster interrupt

lda #line // rasterline to generate the interrupt on
sta $d012
lda #$1b // raster lines > 256, needs bit #7 of $d011 to be set
sta $d011 // as it is the 9th bit of $d012

lda #$35 // RAM everywhere but SID/VICII etc. ($d000-dfff)
sta $01

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

cli // allow maskable interrupts again

jmp *

irq1: sta atemp+1 // preserve registers
stx xtemp+1
sty ytemp+1

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

inc $d012 // we want interrupt on next raster line

lda #1
sta $d019

tsx
cli

nop // wait for interrupt to happen
nop
nop
nop
nop
nop
nop
nop

irq2: txs

ldx #8 // tricks
dex
bne *-1
bit $00

lda $d012
cmp $d012
beq *+2

// stable raster now

lda #7
sta $d020

// FLD
ldx #10
FLD:
lda $d012
cmp $d012
beq *-3

clc // one line of FLD. *Snort* Ahh!!!
lda $d011
adc #1
and #7
ora #$18
sta $d011

dex
bne FLD

// effect over
lda #14
sta $d020

lda #<irq1
ldx #>irq1
sta $fffe
stx $ffff
lda #line
sta $d012
lda #1
sta $d019

atemp: lda #00
xtemp: ldx #00
ytemp: ldy #00

rti
2022-05-09 14:52
Groepaz

Registered: Dec 2001
Posts: 10353
This should be trivial :) Hint:
In the FLD loop remove the cmp $d012 beq *-3. Don't add one to the value from $d011, but use $d012 instead :) Now after sta $d011 put a sta $d021. Now you see the color changes once per rasterline. Next add cycles to the loop until the point where the color changes are exactly in the same cycle each line. Now if it isnt already working, add or remove some cycles before the FLD loop.
2022-05-09 15:44
TheRyk

Registered: Mar 2009
Posts: 1420
Quoting Starfox

Sorry for TERRIBLE formatting when posting the code here.

Please use BBCode opensquarebracketCODEclosesquarebracket then your code and close it with the same tag adding a slash before the "["
2022-05-09 15:47
Starfox

Registered: Jul 2014
Posts: 27
Quote: This should be trivial :) Hint:
In the FLD loop remove the cmp $d012 beq *-3. Don't add one to the value from $d011, but use $d012 instead :) Now after sta $d011 put a sta $d021. Now you see the color changes once per rasterline. Next add cycles to the loop until the point where the color changes are exactly in the same cycle each line. Now if it isnt already working, add or remove some cycles before the FLD loop.


Ahh, thanks! I knew it was something simple I had missed šŸ‘šŸ˜Ž
2022-05-09 15:50
Starfox

Registered: Jul 2014
Posts: 27
Quoting Starfox
Was fiddling with FLD, at work of course, but seems I've made a mistake somewhere. The FLD just flickers all over the screen.

Anyone? :)

Sorry for TERRIBLE formatting when posting the code here.


BasicUpstart2(main)

.var line = 81

main:		sei				// disable maskable interrupts
			
			lda #$7f		// disable timer interrupts			
			sta $dc0d			
			sta $dd0d			
			lda $dc0d		// disable pending timer interrupts		
			lda $dd0d

			lda #1
			sta $d01a		// tell VICII to generate a raster interrupt

			lda #line 		// rasterline to generate the interrupt on
			sta $d012
			lda #$1b		// raster lines > 256, needs bit #7 of $d011 to be set
			sta $d011		// as it is the 9th bit of $d012

			lda #$35		// RAM everywhere but SID/VICII etc. ($d000-dfff)
			sta $01

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

			cli 			// allow maskable interrupts again

			jmp *			

irq1:		sta atemp+1 	// preserve registers
			stx xtemp+1
			sty ytemp+1

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

			inc $d012		// we want interrupt on next raster line

			lda #1			
			sta $d019

			tsx
			cli

			nop 			// wait for interrupt to happen
			nop
			nop
			nop
			nop
			nop
			nop
			nop

irq2:		txs

			ldx #8 			// tricks
			dex
			bne *-1
			bit $00

			lda $d012
			cmp $d012
			beq *+2

			// stable raster now

			lda #7
			sta $d020

			// FLD
        	ldx #10
FLD:		
			lda $d012		
        	cmp $d012
        	beq *-3

        	clc 			// one line of FLD. *Snort* Ahh!!!
        	lda $d011
        	adc #1
        	and #7
        	ora #$18
        	sta $d011

        	dex 
        	bne FLD

			// effect over
			lda #14
			sta $d020

			lda #<irq1		
			ldx #>irq1
			sta $fffe
			stx $ffff
			lda #line
			sta $d012
			lda #1			
			sta $d019

atemp:		lda #00
xtemp:		ldx #00
ytemp:		ldy #00/


rti



I must be getting too old, lol. I tried doing what you said, but I'm not sure I did it correct, as it's still bugging out. But it might have been Malwarebytes. I just got a notification that x64sc was ransomware lol.

EDIT: I think this is what you meant, it doesn't bug out anymore:



FLD:		
			lda $d012		
        	//cmp $d012
        	//beq *-3

        	//clc 			// one line of FLD. *Snort* Ahh!!!
        	//lda $d011
        	//adc #1
        	and #7
        	ora #$18
        	sta $d011
        	sta $d021

        	nop
        	nop
        	nop 
        	nop 
        	nop 
        	nop 
        	nop 
        	nop 
        	nop 
        	nop 


        	dex 
        	bne FLD
2022-05-09 17:26
Groepaz

Registered: Dec 2001
Posts: 10353
yes. remember what you want to achive - the lower 3 bits of $d012 should never match the lower 3 bits of $d011 (which is the badline condition). so load $d012, modify it (add 1) and write it to $d011 (it can work even when not adding one, that means the timing happens to be so when you write $d011, you are already one rasterline ahead)
2022-05-09 20:27
Starfox

Registered: Jul 2014
Posts: 27
Quote: yes. remember what you want to achive - the lower 3 bits of $d012 should never match the lower 3 bits of $d011 (which is the badline condition). so load $d012, modify it (add 1) and write it to $d011 (it can work even when not adding one, that means the timing happens to be so when you write $d011, you are already one rasterline ahead)

Indeed! And thanks for the explanation! šŸ‘
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
Scooby/Gā˜…P/Light
Doc Snyder/ONS
Visage/Lethargy
A3/AFL
Endurion
Matt
Guests online: 35
Top Demos
1 Edge of Disgrace  (9.6)
2 Coma Light 13  (9.6)
3 Bromance  (9.6)
4 Memento Mori  (9.6)
5 Uncensored  (9.6)
6 Comaland 100%  (9.6)
7 Lunatico  (9.5)
8 Unboxed  (9.5)
9 Wonderland XII  (9.5)
10 Christmas Megademo  (9.5)
Top onefile Demos
1 Copper Booze  (9.6)
2 Daah, Those Acid Pil..  (9.5)
3 Cityscape 2730  (9.5)
4 Plasma Ninja  (9.5)
5 Dawnfall V1.1  (9.5)
6 Lovecats  (9.5)
7 Barry Boomer - Trapp..  (9.5)
8 Square Booze  (9.5)
9 Elite Code Mechanics  (9.5)
10 To Norah  (9.4)
Top Groups
1 Booze Design  (9.4)
2 Oxyron  (9.3)
3 Crest  (9.2)
4 Lethargy  (9.2)
5 Censor Design  (9.2)
Top Cover Designers
1 Duce  (9.8)
2 Electric  (9.8)
3 Junkie  (9.7)
4 The Elegance  (9.5)
5 Mermaid  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2022
Page generated in: 0.07 sec.