Jump to content
IGNORED

DLI Programming....locating Display List Interrupts before display list?


Recommended Posts

Hello,

 

I spent a couple hours of trying to move working DLI's.  Originally, the DLI's were located well before the display list.  However, I need to move the DLI's, and display list, out of the bankable code region.  So, I moved the DLI's into another region and placed the Display List before the DLI's.  The problems were now many and numerous.  It was like a whack-a-mole game trying to get this to work.  Finally, thinking about how the DLI's worked when placed before the display list, I put them before the display list.  Everything now works.  Did I miss some rule, somewhere, that DLI's should be before the display list?

 

Thanks!

Brian

Edited by reifsnyderb
Link to comment
Share on other sites

1 minute ago, Wrathchild said:

What are you referring to as Dlis?

The interrupt code or the instructions in the display list to trigger an interrupt?

 

The irq code location has no bearing on the location of the display list and vice-versa, you must be doing something else wrong. Can you create a cut down example?

 

Here's the code.....

 

 

FIX $2A00
; Display List Interrupt Routines

; Initial DLI -- Loads colors for graph
DLI1 = *

                    PHA

                    LDA        #low DLI2A        ; Load DLI2A interrupt address
                    STA        VDSLST
                    LDA        #high DLI2A
                    STA        VDSLST+1

                    STA        WSYNC            ; Wait for horizontal sync.
                    JSR        CLRGA                ; Load colors for graph

                    PLA
                    RTI

DLI2A = *

                    PHA

                    LDA        #low DLI2B        ; Load DLI2B interrupt address
                    STA        VDSLST
                    LDA        #high DLI2B
                    STA        VDSLST+1

                    STA     WSYNC            ; Wait for horizontal sync.
                    JSR        CLRGB                ; Load colors for graph

                    PLA
                    RTI


; Load menu colors
DLI2B = *
                    PHA

                    LDA        #low DLI3            ; Load DLI3 interrupt address
                    STA        VDSLST
                    LDA        #high DLI3
                    STA        VDSLST+1

                    STA        WSYNC            ; Wait for horizontal sync.
                    JSR        CLRM

                    PLA
                    RTI


; Load textbox colors
DLI3 = *
                    PHA

                    LDA        #low DLI4            ; Load DLI4 interrupt address
                    STA        VDSLST
                    LDA        #high DLI4
                    STA        VDSLST+1

                    STA        WSYNC            ; Wait for horizontal sync.
                    JSR        CLRTB                ; Load colors text box

                    PLA
                    RTI


; Load copyright colors
DLI4 = *
                    PHA

                    LDA        #low DLI5            ; Load DLI4 interrupt address
                    STA        VDSLST
                    LDA        #high DLI5
                    STA        VDSLST+1

                    STA        WSYNC            ; Wait for horizontal sync.

                    JSR        CLRC                ; Load colors for copyright

                    PLA
                    RTI


; Load initial title colors
DLI5 = *
                    PHA

                    LDA        #low DLI1            ; Load DLI1 interrupt address
                    STA        VDSLST
                    LDA        #high DLI1
                    STA        VDSLST+1

                    STA        WSYNC;            ; Wait for horizontal sync.

                    JSR        CLRT                ; Load colors for title

                    PLA
                    RTI

 

 

; ****************************************************************************************************************


 

;FIX    DSTART
FIX    $2B00
;DLCODE = *
;LOC    DLIMEM
;LOC $2C00
;ORG $2B00
;DLCS = *                                            ; Start of display list related code
; Display List for Config Screen
;FIX $9E00

DISLST                                            ; Display List
    DB    $70,$70,$70                            ; 24 SL

    DB    $47                                        ; 16 SL
    DW    CSTTL                                    ; Title "MEGA 4 XL"

    DB    $70                                        ; 8 SL

    DB    $42                                        ; 8 SL
    DW    STXRAM                                ; "0...RAM...4096"

    DB    $CE                                        ; 1 SL, 40 bytes for upper line on graph        ; DLI1
    DW    SCGRLN
    
    DB    $4D                                        ; 8 SL, Gr 7    Graph, 40 byes/line - use center 32 bytes or 128 pixels
    DW    SCGRPH
    DB    $8D,$0D,$8D                            ;                                                                 DLI2A, DLI2B

    DB    $4E                                        ; 1 SL, 40 bytes for lower line on graph
    DW    SCGRLN

    DB    $42                                        ; 8 SL
    DW    SCGRL                                    ; Graph Labels
    
    DB    $30                                        ; 4 SL

    DB    $46                                        ; 8 SL
    DW    SCDRIV                                ; Drive Settings
    DB    $06,$06,$06,$06,$06,$06,$06    ; 56 SL

    DB    $06                                        ; 8 SL, Printer Spooler
    
    DB    $46                                        ; 8 SL
    DW    SCOPT                                    ; Option Key

    DB    $B0                                        ; 4 SL                                                        DLI3

    DB    $42                                        ; 8 SL
    DW    SCMB1                                    ; Message Box 1

    DB    $10                                        ; 2 SL

    DB    $42                                        ; 8 SL
    DW    SCMB2                                    ; Message Box 2

    DB    $90                                        ; 2 SL                                                    DL14
    
    DB    $42                                        ; 8 SL
    DW    SCCPR

    DB    $80                                        ; 1 SL                                                    DLI5

    DB    $41
    DB    low DISLST
    DB    high DISLST

; NOTE:  0 SL still available

 

Link to comment
Share on other sites

Here's the functions called from the DLI's....

 

 

FIX $2E00

; Setup copyright colors
CLRC = *
                    LDA        #$44
;                    STA        COLOR0        ;Large upper case characters
                    STA        COLPF0
                    LDA        #$0C
;                    STA        COLOR1        ;Gr.0 Text
                    STA        COLPF1
                    LDA        #$0A            ; Light grey
;                    STA        COLOR2        ;Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A            ; Light grey
;                    STA        COLOR4        ;Background/Border color
                    STA        COLBK

                    RTS


; Setup title colors
CLRT = *
                    ;LDA        #$44                ; Red
                    LDA        #$84                ; Blue
                    STA        COLOR0        ; Large upper case characters
                    STA        COLPF0
                    LDA        #$00
                    STA        COLOR1        ; Gr.0 Text
                    STA        COLPF1
                    LDA        #$0A            ; Light grey
                    STA        COLOR2        ; Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A            ; Light grey
                    STA        COLOR4        ; Background/Border color
                    STA        COLBK

                    RTS


; Setup text box
CLRTB = *
                    LDA        #$48
;                    STA        COLOR0        ;Large upper case characters
                    STA        COLPF0
                    ;LDA        #$C9
                    LDA        #$00                ; Black
                    ;STA        COLOR1        ;Gr.0 Text
                    STA        COLPF1
                    LDA        #$0A        ; Light grey
                    ;LDA        #$94            ;
;                    STA        COLOR2        ;Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A            ; Light grey
;                    STA        COLOR4        ;Background/Border color
                    STA        COLBK

                    RTS


; Setup graph colors -- upper 1/2
CLRGA
                    LDA        #$2F                ; Light yellow
;                    STA        COLOR0        ;Gr 7 graph background
                    STA        COLPF0
;                    LDA        #$84                ; Blue
                    LDA        #$A6            ; Torquoise
;                    STA        COLOR1        ;Gr.7 bank color
                    STA        COLPF1
                    LDA        #$0A
;                    STA        COLOR2        ;Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A
;                    STA        COLOR4        ;Background/Border color
                    STA        COLBK

                    RTS


; Setup graph colors -- lower 1/2
CLRGB
;                    LDA        #$2F                ; Light yellow
                    LDA        GRLC1
;                    STA        COLOR0        ;Gr 7 graph background
                    STA        COLPF0
;                    LDA        #$84                ; Blue
;                    LDA        #$A6            ; Torquoise
                    LDA        GRLC2
;                    STA        COLOR1        ;Gr.7 bank color
                    STA        COLPF1
                    LDA        #$0A
;                    STA        COLOR2        ;Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A
;                    STA        COLOR4        ;Background/Border color
                    STA        COLBK

                    RTS


; Setup menu colors
CLRM
                    LDA        #$04                ; Dark grey
;                    STA        COLOR0        ;Large upper case characters
                    STA        COLPF0
                    LDA        #$00
;                    STA        COLOR1        ;Gr.0 Text
                    STA        COLPF1
                    LDA        #$0A            ; Light grey
;                    STA        COLOR2        ;Gr.0 Background
                    STA        COLPF2
                    LDA        #$0A            ; Light grey
;                    STA        COLOR4        ;Background/Border color
                    STA        COLBK

                    RTS

 

Link to comment
Share on other sites

Some not so good practices in there:

 

1) DLIs trigger after the line they are on, so the last $80 followed by a $41 is not such a good idea?

What is shown after this point which needs DLI to set it right?

 

2) What your code is depending upon is the first DLI fires the right (first) routine.

Better would be to use a VBI to set the first DLI. Then the last DLI does not need to chain back to the first.

 

3) DLIs are quite time critical. So the chaining of the next DLI does not need to be the first thing done, it it usually the last.

Also, JSR and RTS are expensive in terms of clock cycles. These routines aren't reused, so inline them.

 

 

Link to comment
Share on other sites

27 minutes ago, Wrathchild said:

Some not so good practices in there:

lol    No surprise there.   🙂    This is the first time I've done this.   🙂

 

27 minutes ago, Wrathchild said:

Some not so good practices in there:

 

1) DLIs trigger after the line they are on, so the last $80 followed by a $41 is not such a good idea?

What is shown after this point which needs DLI to set it right?

Are you referring to this?

 

    DB    $80                                        ; 1 SL                                                    DLI5

    DB    $41
    DB    low DISLST
    DB    high DISLST

 

I did this to reset the colors for the top of the screen.  Adding a VBI, like you mention in #2, would take care of this.  I did find out the hard way that trying to add a DLI to the $41 results in a nasty stack overflow.   lol

 

31 minutes ago, Wrathchild said:

2) What your code is depending upon is the first DLI fires the right (first) routine.

Better would be to use a VBI to set the first DLI. Then the last DLI does not need to chain back to the first.

Good idea.  I have VBI enabling code already in the program but commented out.  I was trying to avoid VBI's to avoid yet another complexity.  (In addition to DLI's, I have PMG's so as to add more colors.)  This would also save wasting that last scan line....which I suspected wasn't a good idea but didn't think of anything else.

33 minutes ago, Wrathchild said:

3) DLIs are quite time critical. So the chaining of the next DLI does not need to be the first thing done, it it usually the last.

Also, JSR and RTS are expensive in terms of clock cycles. These routines aren't reused, so inline them.

Good point on putting the DLI chaining last and I'll also inline the subroutines.  (All they do is change the colors anyhow.)

 

Some experimentation here makes me wonder if it's possible to reliably change colors in the middle of a scan line with some constructive delays.

 

Thanks for the pointers!  I've spent a lot of time screwing around with the Display List and the DLI's.

 

 

 

 

Link to comment
Share on other sites

1 hour ago, Wrathchild said:

The OS routines are doing this for you already. 

 

I was pondering your statement about this and realized the trick is to set the shadow color addresses so that the OS sets the colors every VBLANK.  Then, no VBI is needed.   🙂

 

All the DLI's then call the color changes directly to the registers.

 

With the exception of not creating a VBI, all changes are implemented as I am letting the OS handle the first color settings via it's normal OS VBI whereby it sets the colors based on the shadow color addresses.  Works great!  Thanks again!

 

 

 

 

 

Link to comment
Share on other sites

Cleaned up code:

 

; Display List Interrupt Routines

; Initial DLI -- Loads colors for upper part of graph.
DLI1 = *

                    PHA

                    STA        WSYNC            ; Wait for horizontal sync.

                    LDA        #$2F                    ; Light yellow background for Gr7 graph
                    STA        COLPF0
                    LDA        #$A6                ; Torquoise color for Gr. 7 banks.
                    STA        COLPF1

                    LDA        #low DLI2A        ; Load DLI2A interrupt address
                    STA        VDSLST
                    LDA        #high DLI2A
                    STA        VDSLST+1

 

                    PLA
                    RTI

DLI2A = *

                    PHA

                    STA     WSYNC            ; Wait for horizontal sync.

                    LDA        GRLC1                ; Get first graph color color
                    STA        COLPF0
                    LDA        GRLC2                ; Get second graph color color
                    STA        COLPF1

                    LDA        #low DLI2B        ; Load DLI2B interrupt address
                    STA        VDSLST
                    LDA        #high DLI2B
                    STA        VDSLST+1

 

                    PLA
                    RTI


; Load menu colors
DLI2B = *
                    PHA

                    STA        WSYNC            ; Wait for horizontal sync.

                    LDA        #$04                ; Dark grey
                    STA        COLPF0        ; Large upper case characters.
                    LDA        #$00
                    STA        COLPF1        ;
                    LDA        #$0A            ; Light grey

                    LDA        #low DLI3            ; Load DLI3 interrupt address
                    STA        VDSLST
                    LDA        #high DLI3
                    STA        VDSLST+1

                    PLA
                    RTI


; Load textbox colors
DLI3 = *
                    PHA

                    STA        WSYNC            ; Wait for horizontal sync.

                    LDA        #$48
                    STA        COLPF0        ; Large upper case characters.
                    LDA        #$00                ; Black
                    STA        COLPF1

                    LDA        #low DLI4            ; Load DLI4 interrupt address
                    STA        VDSLST
                    LDA        #high DLI4
                    STA        VDSLST+1

                    PLA
                    RTI


; Load copyright colors
DLI4 = *
                    PHA

                    STA        WSYNC            ; Wait for horizontal sync.

                    LDA        #$44                    ; Large upper case characters
                    STA        COLPF0
                    LDA        #$0C                ; Light gray
                    STA        COLPF1            ; Gr.0 Text

                    LDA        #low DLI1            ; Load DLI1 interrupt address
                    STA        VDSLST
                    LDA        #high DLI1
                    STA        VDSLST+1

                    PLA
                    RTI

 

Link to comment
Share on other sites

1 hour ago, reifsnyderb said:

Some experimentation here makes me wonder if it's possible to reliably change colors in the middle of a scan line with some constructive delays.

Like this :) ,not the best example as it's a graphics 0 screen, but I'm changing the colour about 1/2 way across the screen, then resetting

back to the original colour until the next dli (so 8 scan lines later for GR.0)

 

image.thumb.png.c2692f395cfd2b8764fea8d987d29d35.png

dli.asm

  • Like 1
Link to comment
Share on other sites

46 minutes ago, Wrathchild said:

The DLI vector at $200 is not a shadow value, it IS the indirect JMP address used by the OS to jump to when a display list interrupt occurs.

I didn't do anything with $200, instead, I went to $2C4 and provided the color values....

 

 

                    LDA        #$84                ; Blue
                    STA        COLOR0        ; Large upper case characters
                    LDA        #$00
                    STA        COLOR1        ; Gr.0 Text
                    LDA        #$0A            ; Light grey
                    STA        COLOR2        ; Gr.0 Background
                    LDA        #$0A            ; Light grey
                    STA        COLOR4        ; Background/Border color

 

 

Then, the OS will reset them every VBLANK.

 

 

Edited by reifsnyderb
Link to comment
Share on other sites

3 hours ago, reifsnyderb said:

                    LDA        #low DLI1            ; Load DLI1 interrupt address
                    STA        VDSLST
                    LDA        #high DLI1
                    STA        VDSLST+1

Hi Brian, yes you have misunderstood. You were already OK by setting the COLORx shadow registers as these are copied during the VBI.

 

All you needed to do was to take the code above OUT of DLI4 and put this in your deferred VBI (immediate would be better but you'll be OK).

  • Like 1
Link to comment
Share on other sites

The deferred VBI can be randomly skipped due to IRQ processing, so it is best to avoid it for anything that must run every frame, including resetting the DLI vector.

 

Additionally, the deferred VBI runs after the system VBI has already copied shadow registers to hardware registers. This happens in either stage 1 or stage 2 VBI depending on the specific register, and both of these are before deferred VBI processing. If you try changing variables like COLOR4 or SDMCTL from deferred VBI, there will be a one-frame lag in the changes taking effect.

 

For these reasons, I generally find it hard to recommend using deferred VBI for anything at all.

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, phaeron said:

The deferred VBI can be randomly skipped due to IRQ processing, so it is best to avoid it for anything that must run every frame, including resetting the DLI vector.

 

Additionally, the deferred VBI runs after the system VBI has already copied shadow registers to hardware registers. This happens in either stage 1 or stage 2 VBI depending on the specific register, and both of these are before deferred VBI processing. If you try changing variables like COLOR4 or SDMCTL from deferred VBI, there will be a one-frame lag in the changes taking effect.

 

For these reasons, I generally find it hard to recommend using deferred VBI for anything at all.

 

Thanks for pointing this out.   I just looked at the OS source code.  It appears the shadow color registers are also non-critical code and, therefore can be skipped just like a deferred VBI.  I'll change it to an immediate VBI.

Edited by reifsnyderb
Link to comment
Share on other sites

Then you have the immediate VB problems -

Too long running code can cause shadow register copies to be delayed, in extreme cases the DList pointer could be stored after the display has started which can make the screen jump.

Too long running code will disrupt SIO operations.

 

But in general for game/demo purposes immediate mode is often best.

You can prevent deferred mode from being skipped but at the cost of turning off the keyboard IRQ which can be inconvenient.

Link to comment
Share on other sites

5 minutes ago, Rybags said:

Then you have the immediate VB problems -

Too long running code can cause shadow register copies to be delayed, in extreme cases the DList pointer could be stored after the display has started which can make the screen jump.

Too long running code will disrupt SIO operations.

 

But in general for game/demo purposes immediate mode is often best.

You can prevent deferred mode from being skipped but at the cost of turning off the keyboard IRQ which can be inconvenient.

In this case, I am just setting the colors at the top of the screen.  Initial testing appears fine.  This is for a configuration screen for a 1090 card.  🙂

Edited by reifsnyderb
Link to comment
Share on other sites

2 hours ago, reifsnyderb said:

In this case, I am just setting the colors at the top of the screen.  Initial testing appears fine.  This is for a configuration screen for a 1090 card.  🙂

 

You can still use a VBI, as Avery pointed out "But in general for game/demo purposes immediate mode is often best." the setting of VDSLST is small and won't affect things.
The danger of the deferred VBI is that the CRITIC flag will cause it to be skipped and so something important like resetting the VDSLST isn't something you can go without.

 

With the approach of a) first setting VDSLST as part of your initialisation and then b) using DLI4 to re-point it to DLI1, you run the risk of something many of us would have seen when using DLIs and that is 'roll', which happens when say the number of DLI flags in the DLIST don't match the interrupts being used, or loop counters are used and you remove a flag but forget to adjust the counter limit. So at the end of the display the VDSLST is left pointing to the wrong routine and when the screen is next drawn and the first DLI is requested, it calls that wrong routine and things are out-of-kilt.

 

By resetting the DLI vector to the first interrupt routine within the VBI this can help avoid that scenario and you tend to then only need to worry about under running, which generally looks like the lower area not being setup as you'd expect.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...