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 > Sideborder open on badline
2022-05-12 10:32
Starfox

Registered: Jul 2014
Posts: 31
Sideborder open on badline

I'm just trying to see if I can remember some vic effects, like the FLD question I asked about the other day. I made those effects myself back in the day, but couldn't remember the timings etc. (even looking over my old convoluted code didn't help, lol) but got it working (thanks).

I'm now trying to open the sideborder on the first text line (line 51), which should be a badline.

I break after the stabilizing code:
            txs
            ldx #8
            dex
            bne *-1
            bit $00
            lda $d012
            cmp $d012
            beq *+2

            ldx #0        // break here
            ldy #$c0
            lda #$c8

            sty $d016
            sta $d016
            sty $d016
            sta $d016,x

Vice tells me it is at cycle 3. After executing "ldx #0" I'm at cycle 5. Executing "ldy #$c0" and I'm at cycle 7. Executing "lda #$c8" and I'm at cycle 9, as expected.

I'm then executing "sty $d016" but I'm at cycle 51. so the instruction ends on cycle 55. One cycle short, to open the border.

Btw I have no sprites on at the moment, but I want to have one sprite in the left border, and one in the right border, and I want to have text on those lines too, so no fld.

Before I try to fix this, I just want to know if I'm on the right track or completely wrong? 😄
2022-05-12 12:57
Oswald

Registered: Apr 2002
Posts: 5017
add 1 cycle delay and you can see yourself ?
2022-05-12 12:59
Martin Piper

Registered: Nov 2007
Posts: 631
I seem to remember the side borders cannot be opened on a bad line with sprite and text/bitmap screen enabled and without FLD. The cycles aren't available at the time you need them. Unless you're using that enabled screen but disabled badline mode.
2022-05-12 13:06
chatGPZ

Registered: Dec 2001
Posts: 11100
it can be done :) You might have to play with different instructions so the store happens in the right cycle
2022-05-12 13:18
Martin Piper

Registered: Nov 2007
Posts: 631
Postpone the $d016 write with a RMW instruction?
2022-05-12 13:34
Martin Piper

Registered: Nov 2007
Posts: 631
oh yes, doh, this is probably a clean example: Sideborder 4K

$265c stx $d016 - cycle 52
$265f sta $d016 - cycle 56

Note sprites 4-7 are enabled, 0-3 are disabled.

Interesting use of HSP/DMA delay as well.
2022-05-12 14:00
chatGPZ

Registered: Dec 2001
Posts: 11100
Quote:
sprites 4-7 are enabled, 0-3 are disabled

yes, this is the key :)
2022-05-12 14:21
Martin Piper

Registered: Nov 2007
Posts: 631
Quote: Quote:
sprites 4-7 are enabled, 0-3 are disabled

yes, this is the key :)


Yeah, sprite 0 fetch starts at cycle 58 with a read pre-stall 3 cycles before.
2022-05-12 17:26
Krill

Registered: Apr 2002
Posts: 2825
The interesting point here is that the write to $d016 most likely happens just before badline DMA, and not after in cycle 56.

Any new CPU op after the badline would be to late.

So the write goes to VIC just before badline DMA, but it's only effective in that magic cycle.

Or is there a better explanation for why open sideborder on a badline is possible at all? :)

Or maybe Christian Bauer's VIC Artikel is wrong again, and badline DMA is not offset by 1 cycle/char before display, but by 5 or so, thus CPU can work again already 5 cycles before the sideborder while the badline is still being drawn?
2022-05-12 18:03
Oswald

Registered: Apr 2002
Posts: 5017
Gunnar, I cant imagine VIC would only register d016 change 40 cycle later on a badline, just because, why ? I think instruction is stopped before its write cycle, then write cycle AND VIC checking if border needs to be started might happen at the same cpu cycle (remember vic being 8mhz)
2022-05-12 18:41
chatGPZ

Registered: Dec 2001
Posts: 11100
Quote:
remember vic being 8mhz

only the graphics sequencer
2022-05-12 18:44
Krill

Registered: Apr 2002
Posts: 2825
Quoting Oswald
I think instruction is stopped before its write cycle, then write cycle AND VIC checking if border needs to be started might happen at the same cpu cycle (remember vic being 8mhz)
The instruction isn't just stopped or temporarily halted, it's aborted, retired, and then restarted after the badline. At least afaik.

Or might there be some kind of clock-stretch going on?

As for delayed internal register update, VIC-II most likely isn't 8 MHz throughout, and i'm fairly certain the bus and register access circuitry is clocked at no more than 2 Mhz (and maybe only 1 for the latter). Also why can't the register update be delayed by a higher-priority bus access like DMA? :)
2022-05-12 18:44
Starfox

Registered: Jul 2014
Posts: 31
Interesting, thanks!

Oswald: I didn't mean I couldn't add 1 cycle, but I wanted to know if it was a bad idea to continue, before doing that :) I'm a bit rusty with vic effects, since '88 or something lol.

I'll take a look at that 4k demo for sure.
2022-05-12 19:47
tlr

Registered: Sep 2003
Posts: 1703
Quoting Krill
Quoting Oswald
I think instruction is stopped before its write cycle, then write cycle AND VIC checking if border needs to be started might happen at the same cpu cycle (remember vic being 8mhz)
The instruction isn't just stopped or temporarily halted, it's aborted, retired, and then restarted after the badline. At least afaik.

Huh? IIRC it works like Oswald states.
Restarting instructions is a complicated thing, not really within the goals for a space optimized design like the 6502 and friends.

Quoting Krill
As for delayed internal register update, VIC-II most likely isn't 8 MHz throughout, and i'm fairly certain the bus and register access circuitry is clocked at no more than 2 Mhz (and maybe only 1 for the latter). Also why can't the register update be delayed by a higher-priority bus access like DMA? :)

Delaying a register update: that would also be complicated as there is only one data bus within the VIC-II. That would require an extra pipeline reg for data + addr + a DMA arbiter of some sort. Also not really working towards the space optimized goal.
2022-05-12 20:04
Oswald

Registered: Apr 2002
Posts: 5017
Krill, after VICII flags it needs the bus, the CPU will stop on its first write cycle, at the middle of the instruction if you will - clock stretch, you should know this hence some border openings(sprite 0?) only possible with RMW (inc d016) only, and because of this mechanism. In other words you can delay the VICII stopping the cpu with inserting an instruction that has a write cycle later. Or in other words you can execute more cpu cycles if you manage to make em read cycles where they count.
2022-05-12 20:55
chatGPZ

Registered: Dec 2001
Posts: 11100
If in doubt, just ask visual6502: http://visual6502.org/JSSim/expert.html?graphics=f&a=0&steps=30..
2022-05-12 22:03
Krill

Registered: Apr 2002
Posts: 2825
Quoting Oswald
Krill, after VICII flags it needs the bus, the CPU will stop on its first write cycle, at the middle of the instruction if you will - clock stretch, you should know this hence some border openings(sprite 0?) only possible with RMW (inc d016) only, and because of this mechanism. In other words you can delay the VICII stopping the cpu with inserting an instruction that has a write cycle later. Or in other words you can execute more cpu cycles if you manage to make em read cycles where they count.
No. VIC pulling the CPU's RDY input low is more like kindly asking the CPU to please stop what it's doing within the next 3 cycles.
The CPU then aborts the current instruction if it's still in a read cycle, or finishes it if it's writing.
RMW instructions finish on 2 write cycles, which will give you that extra cycle.

This is entirely different than the HALT mechanism implemented in 6502 variants used, e.g., on Atari 8-bit computers.
2022-05-12 22:16
Krill

Registered: Apr 2002
Posts: 2825
Quoting Groepaz
If in doubt, just ask visual6502: http://visual6502.org/JSSim/expert.html?graphics=f&a=0&steps=30..
Okay, really looks like the instruction is paused between reading and writing. :)

I stand corrected.
2022-05-13 09:34
Oswald

Registered: Apr 2002
Posts: 5017
Quote: Quoting Oswald
Krill, after VICII flags it needs the bus, the CPU will stop on its first write cycle, at the middle of the instruction if you will - clock stretch, you should know this hence some border openings(sprite 0?) only possible with RMW (inc d016) only, and because of this mechanism. In other words you can delay the VICII stopping the cpu with inserting an instruction that has a write cycle later. Or in other words you can execute more cpu cycles if you manage to make em read cycles where they count.
No. VIC pulling the CPU's RDY input low is more like kindly asking the CPU to please stop what it's doing within the next 3 cycles.
The CPU then aborts the current instruction if it's still in a read cycle, or finishes it if it's writing.
RMW instructions finish on 2 write cycles, which will give you that extra cycle.

This is entirely different than the HALT mechanism implemented in 6502 variants used, e.g., on Atari 8-bit computers.


I'm still happy to disagree

"The instruction isn't just stopped or temporarily halted, it's aborted, retired, and then restarted after the badline. At least afaik."

what do you think the difference is betweeen instr temprarily halted, and retired/restarted ?

IMHO HALT and what happens on c64 is the same at the point the CPU is stopped to only difference is how and when it stops.

"The CPU then aborts the current instruction if it's still in a read cycle, or finishes it if it's writing."

the cpu doesnt abort the instruction, but stops executing it in whatever (readD) cycle it happens to be.


also if it is a write cycle it doesnt mean finishing the instruction it means finishing the write cycles. atleast so I know :)
2022-05-13 10:16
Martin Piper

Registered: Nov 2007
Posts: 631
Looking at the Atari 2600 schematic: https://www.atariage.com/2600/archives/schematics/Schematic_260..

The 6507 "HALT" is wired to pin 3 RDY, which comes from the TIA. Used for video synchronisation.
2022-05-13 11:10
Krill

Registered: Apr 2002
Posts: 2825
Quoting Oswald
I'm still happy to disagree
I repeat:
Quoting Krill
I stand corrected.

Quoting Oswald
IMHO HALT and what happens on c64 is the same at the point the CPU is stopped to only difference is how and when it stops.
Yes, the difference appears to be a 3-cycle grace period (RDY) to finish write accesses vs immediate halt.
Both variants may pause an instruction and resume later.
2022-05-17 20:59
Monte Carlos

Registered: Jun 2004
Posts: 350
Use sta $d016-x,x
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
Durandal
Dave/SIDNIFY
Shake/Role
megasoftargentina
LHS/Padua
Guests online: 129
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.8)
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.066 sec.