Commodore 64 (C64) Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Trying to get routines to work together

 
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene
View previous topic :: View next topic  
Author Message
lee5657
Newbie


Joined: 04 Dec 2012
Posts: 12

PostPosted: Tue Dec 04, 2012 1:45 pm    Post subject: Trying to get routines to work together Reply with quote

Hi,

Basically the problem is that I've got this routine for a scroller, and I'm trying to JSR to it after setting up an IRQ, and also trying to get some music happening at the same time. The problem is it only seems to display the scroll text, and doesn't play the music routine. I think it's got something to do with the "loop" label in the scroll routine, but when I try to get it to loop elsewhere the music slows down, or the scroller goes all jerky and the music doesn't play. Here's the code for the IRQ:

Code:

                sei
                lda #<init
                ldx #>init
                sta $0314
                stx $0315
                lda #$00
                sta $d012
                lda #$7f
                sta $dc0d
                lda #$01
                sta $d01a

                lda #$00
                tax
                tay
                jsr $1000
                cli

hold          jmp hold


init            lda #$01
                sta $d019


                jsr scroller

                 jsr $1003


                asl $d019
                pla
                tay
                pla
                tax
                pla
                rti


and here's the code for the scroller:

Code:

scroller


lda #$37
   sta $01

   ldx #0


   inx
   stx $0286
   jsr $e544

loop    ldy #$80
   ldx #7
smooth    stx $d016

   cpy $d012
   bne *-3
   dey
   dex
   bpl smooth

   ldx #218
scroll    lda $0799-218,x
   sta $0798-218,x
   inx
   bne scroll

write    ldx #0
   lda text,x
   beq wrap
   sta $07be
   inx
   txa

wrap    sta write+1


   jmp loop


text

!text "SIMPLE SCROLLER..."
!text " BLAH BLAH WRAP IT. "
!text " "
!byte 0
Back to top
View user's profile Send private message
mood_swing
Newbie


Joined: 23 Sep 2008
Posts: 42

PostPosted: Tue Dec 04, 2012 2:20 pm    Post subject: Reply with quote

How can the interrupt finish if you never return from your scroller routine Question

Set up a raster interrupt to occur on, say, line $80 by storing $80 in $d012, instead of waiting for that line within scroller. On each raster interrupt, decrement the fine scrolling in $d016 from 7 to 0. When you put it back to 7, on the 8th interrupt, then execute the scroll part of your scroller.

Make sure your scroller finishes executing before the next raster interrupt.
Back to top
View user's profile Send private message
spider-j
Über Groupie
Über Groupie


Joined: 12 Jun 2012
Posts: 310
Location: Wuppertal, FRG

PostPosted: Tue Dec 04, 2012 3:30 pm    Post subject: Reply with quote

What mood_swing said + this
Code:

   cpy $d012
   bne *-3

doesn't belong in a routine that is supposed to be called every frame.
You have to store the softscroll value somewhere and restore when the scroller routine is called.

Your routine has to do 7 frames softscroll then 1 frame hardscroll + reset softscrollreg.

You can't just copy'n'paste example code. Try to understand what you're doing!

EDIT: and of course that clear-screen part also doesn't belong in this routine.
Back to top
View user's profile Send private message
lee5657
Newbie


Joined: 04 Dec 2012
Posts: 12

PostPosted: Tue Dec 04, 2012 11:30 pm    Post subject: Reply with quote

Quote:
You can't just copy'n'paste example code. Try to understand what you're doing!

That's what I'm trying to do. The only way I know how to learn this stuff is to use the routines, and then try to work out why they don't work. And in the process hopefully learn a thing or two.

Quote:
How can the interrupt finish if you never return from your scroller routine

True. I suppose I've got to work out how to return to the main loop while preserving some of the values. Which brings me to...


Quote:
You have to store the softscroll value somewhere and restore when the scroller routine is called.

Your routine has to do 7 frames softscroll then 1 frame hardscroll + reset softscrollreg.

Which bit of the code is responsible for the soft/hard scroll? I'm assuming it's this bit:

Code:

loop         ldy #$80
               ldx #7
smooth    stx $d016
Back to top
View user's profile Send private message
THEWIZ
Forum Junkie
Forum Junkie


Joined: 17 Jun 2006
Posts: 528

PostPosted: Wed Dec 05, 2012 2:33 am    Post subject: Reply with quote

lee5657 wrote:
Your routine has to do 7 frames softscroll then 1 frame hardscroll + reset softscrollreg.

Which bit of the code is responsible for the soft/hard scroll? I'm assuming it's this bit:[/quote]
There are two parts to scrolling. The first is called the "softscroll" which ONLY shifts the screen via d016. Personally I recommend shifting it by more than 1 pixel (3 is a decent speed)
Then there is the "hardscroll" which is what happens when you need to move all 40 characters over 1.

Do something like this (with some handwaving)

IRQ1:
;do stuff
jsr scroll
jsr music
rti

scroll:
lda savedvalue
and #7; you can do this in different places
clc
adc #3 (or whatever)
sta savedvalue
if a > 7
;call rough scroll
rts

Notice how we DON'T set D016 here!

Later:
IRQ2:
lda savedvalue
and #7
sta $d016
rti

You want to separate the two pieces of code. Change d016 immediately at the top of the IRQ, and then do nothing else related to the scroll during that interrupt. Do the rest of the scroll code on the other interrupt.

One thing you don't want to do, is change the screen at the exact same time it is being displayed. This can cause "tearing"
_________________
Back to top
View user's profile Send private message
hbhzth
Master of C64
Master of C64


Joined: 10 Nov 2007
Age: 41
Posts: 1026
Location: Norway

PostPosted: Wed Dec 26, 2012 1:00 am    Post subject: Re: Trying to get routines to work together Reply with quote

lee5657 wrote:
Hi,

Code:
;fine - except watch out for the IRQ settings made in scroller part.... they could easily been moved up to this main code part, leaving just the scroll routine intact in the scroller part.


Here's the code for the scroller:

Code:

scroller

<<<-   lda #$37
       sta $01
       ldx #0
       inx
       stx $0286
       jsr $e544     ->>>
;move all this to the very top - only needs to be run one time to set screen color and clear screen. NEVER put inside a IRQ!!!

ldy #$28     ;make rastersplit before scroll is to start

cpy $d012
bne *-3

lda #$06
sta $d021

lda variable
clc
adc #$c0     ;will give values from #$c0-c7 in scroll register (masking out 2 chars, by expanding border on each side, leaving 38 chars visible).

sta $d016

ldy #$50     ;make a new rastersplit to stable screen (from wobbling from 0-7 every rasterline under scroll)

cpy $d012
bne *-3

lda #$00     ;put in new screen color to easier adjust raster split to fit the scroll more precise - just change the numbers and see - it's fun :)

sta $d021

lda #$c8
sta $d016

dec variable
bne pass

lda #$07
sta variable     ;we set the smooth scroll register back to 7

ldx #00     ;move top screen row to the left

scroll
lda $0401,x
sta $0400,x
inx
cpx #$27
bne scroll

write lda text               ;fetch text from memory
beq endscr            ;if that char is zero then end scroll
sta $0427             ;store  to the last char on top row

inc write+1           ;increase memory location from which text is read lowbit
bne pass              ;if we cross 255 then increase hibit
inc write+2

pass
rts

endscr

lda <text
sta write+1
lda >text
sta write+2
rts

variable .byte $01

!text "SIMPLE SCROLLER..."
!text " BLAH BLAH WRAP IT. "
!text " "
!byte 0

I hope this may be of inspiration. Run it and see if you can make it work. If it don't work right away it's just a small adjustment - debugging is how one learn.

BTW: I changed the scroll to be on the top row of the screen - but with training you can make it scroll which part of the screen you will.
Back to top
View user's profile Send private message
hbhzth
Master of C64
Master of C64


Joined: 10 Nov 2007
Age: 41
Posts: 1026
Location: Norway

PostPosted: Wed Dec 26, 2012 1:20 am    Post subject: Reply with quote

init
lda #$01
sta $d019
jsr scroller
jsr $1003

asl $d019
pla
tay
pla
tax
pla
rti

Replace this with:
jmp $ea31 - And end the main prog with RTS rather than JMP *

That would enable you to still be able to move cursor around after starting the program. Can be fun to play around with.

IF you end the main program with JMP * rather than RTS then use JMP $ea81 to end the IRQ. Saves some lines by doing so. Plus some music routines are not too happy with the JMP $ea31 since it uses some zero page addys by the kernal.

There is no need to use the pla, tay, pla, tax, pla, rti - the kernal is your friend. Check kernal listing from $ea7e and viola - you got the whole thing there as well. Wink

---------
As I mentioned in prev. post:

Remove from SCROLLER routine and start with this from the very start of the program - it's only needed to be run once - definitely not every IRQ call. I think the $EA31 would waste A LOT of clock cycles better used by other programming. Save up on the rastertime where you can. You'll need it eventually as you add more routines.

Code:
lda #$37
sta $01

ldx #0
inx
stx $0286
jsr $e544

...and continue with IRQ setup, etc...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Scene All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Tip: Get C64 Forever for super-comfy C64 emulation with pre-installed games, demos and other goodies!


Powered by phpBB © 2001, 2005 phpBB Group