]> git.sur5r.net Git - cc65/blob - libsrc/atari/scroll.s
5e8428cc2146eab6cce7e879604afb15900f44ae
[cc65] / libsrc / atari / scroll.s
1 ;
2 ; Christian Groessler, June 2004
3 ;
4 ; void __fastcall__ _scroll (signed char numlines);
5 ; numlines > 0  scrolls up
6 ; numlines < 0  scrolls down
7 ;
8
9         .include        "atari.inc"
10         .importzp       tmp1,tmp4,ptr1,ptr2
11         .import         mul40,_clrscr
12         .export         __scroll
13
14 .proc   __scroll
15
16         cmp     #0
17         beq     jmpfin
18 ;       cmp     #$80
19 ;       bcc     up
20         bpl     up
21
22 ;scroll down
23         eor     #$ff
24         clc
25         adc     #1              ; make positive
26         sta     tmp1
27
28         cmp     #24             ; scroll >= the whole screen?
29         bcc     down_ok
30         jmp     _clrscr
31
32 down_ok:lda     SAVMSC
33         clc
34         adc     #<(40*23)
35         sta     ptr1
36         sta     ptr2
37         lda     SAVMSC+1
38         adc     #>(40*23)
39         sta     ptr1+1          ; point to last line on screen
40         sta     ptr2+1
41
42         lda     tmp1
43         jsr     mul40
44         sta     tmp4
45         lda     ptr2
46         sec
47         sbc     tmp4
48         sta     ptr2
49         stx     tmp4
50         lda     ptr2+1
51         sbc     tmp4
52         sta     ptr2+1
53
54         lda     #24             ; # of lines on screen
55         sec
56         sbc     tmp1            ; # of lines to move
57         tax
58
59         ;very simple, could be improved
60
61 scrold: ldy     #39             ; # of chars on a line - 1
62 copy_d: lda     (ptr2),y
63         sta     (ptr1),y
64         dey
65         bpl     copy_d
66         lda     ptr1
67         sec
68         sbc     #40
69         sta     ptr1
70         bcs     u1
71         dec     ptr1+1
72 u1:     lda     ptr2
73         sec
74         sbc     #40
75         sta     ptr2
76         bcs     u2
77         dec     ptr2+1
78 u2:     dex
79         bne     scrold
80
81         ; fill new scrolled in lines with space
82
83         ldx     tmp1            ; # of new lines
84 fild:   lda     #0
85         ldy     #39
86 fill_d: sta     (ptr1),y
87         dey
88         bpl     fill_d
89         dex
90 jmpfin: beq     finish
91         lda     ptr1
92         sec
93         sbc     #40
94         sta     ptr1
95         bcs     u3
96         dec     ptr1+1
97 u3:     jmp     fild
98
99 ;scroll up
100 up:     sta     tmp1            ; # of lines to scroll
101         cmp     #24             ; scroll >= the whole screen?
102         bcc     up_ok
103         jmp     _clrscr
104
105         ;multiply by 40 (xsize)
106 up_ok:  jsr     mul40
107         clc
108         adc     SAVMSC          ; add start of screen mem
109         sta     ptr2
110         txa
111         adc     SAVMSC+1
112         sta     ptr2+1
113         lda     SAVMSC+1
114         sta     ptr1+1
115         lda     SAVMSC
116         sta     ptr1
117         lda     #24             ; # of lines on screen
118         sec
119         sbc     tmp1            ; # of lines to move
120         tax
121
122         ;very simple, could be improved
123
124 scroll: ldy     #39             ; # of chars on a line - 1
125 copy_l: lda     (ptr2),y
126         sta     (ptr1),y
127         dey
128         bpl     copy_l
129         lda     #40
130         clc
131         adc     ptr1
132         sta     ptr1
133         bcc     l1
134         inc     ptr1+1
135 l1:     lda     #40
136         clc
137         adc     ptr2
138         sta     ptr2
139         bcc     l2
140         inc     ptr2+1
141 l2:     dex
142         bne     scroll
143
144         ; fill new scrolled in lines with space
145
146         ldx     tmp1            ; # of new lines
147 fill:   lda     #0
148         ldy     #39
149 fill_l: sta     (ptr1),y
150         dey
151         bpl     fill_l
152         dex
153         beq     finish
154         lda     #40
155         clc
156         adc     ptr1
157         sta     ptr1
158         bcc     l3
159         inc     ptr1+1
160 l3:     jmp     fill
161
162 finish: rts
163
164 .endproc