Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) You are not logged in - nap
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: 31
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
chatGPZ

Registered: Dec 2001
Posts: 11100
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: 2053
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: 31
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: 31
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
chatGPZ

Registered: Dec 2001
Posts: 11100
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: 31
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
rikib80
St0rmfr0nt/Quantum
Guests online: 84
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 Wafer Demo  (9.5)
7 TRSAC, Gabber & Pebe..  (9.5)
8 Onscreen 5k  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

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