]> git.sur5r.net Git - cc65/blob - libsrc/atari/xlmemchk.inc
Changed most "backticks" (grave accents) into apostrophes.
[cc65] / libsrc / atari / xlmemchk.inc
1 ;
2 ; Christian Groessler, Jun-2013
3 ;
4 ; This routine is used in preparation to move the screen memory
5 ; in front of the program.
6 ;
7 ; It calculates the value to put into RAMTOP for a subsequent
8 ; "GRAPHICS 0" call, and the lowest address which will be used
9 ; by the screen memory afterwards.
10
11 ; inputs:
12 ;       __STARTADDRESS__        -       load address of the program
13 ; outputs:
14 ;       lodadr                  -       (high byte only) value to
15 ;                                       write into RAMTOP
16 ;       lowadr                  -       lowest address occupied by
17 ;                                       screen data
18 ;
19
20
21 ; When setting a display mode, the ROM takes the RAMTOP value
22 ; and subtracts the size of the screen memory from it. This will
23 ; become the new screen memory address.
24 ; From this address it subtracts the size of the display list.
25 ; This will become the new display list address.
26 ; Screen memory cannot cross 4K boundaries and a display list
27 ; cannot cross a 1K boundary.
28 ;
29 ; Work out a sane value for RAMTOP to prevent boundary crossing.
30 ; RAMTOP is only one byte, it counts in memory pages.
31 ;
32 ; The ROM doesn't do this boundary checking, since it doesn't
33 ; expect RAMTOP to have (rather) arbitrary values. For a
34 ; "GRAPHICS 0" call and RAMTOP representing the possible physically
35 ; available memory, boundary crossing cannot happen.
36
37
38 SCRBUFSZ =      (40 * 24)               ; size of mode 0 screen buffer
39 DLSZ    =       32                      ; size of mode 0 display list
40
41
42 scrmemtst:
43
44 ; subtract screen memory size from our load address
45
46         lda     lodadr
47         sec
48         sbc     #<SCRBUFSZ
49         sta     tstadr
50         lda     lodadr+1
51         sbc     #>SCRBUFSZ
52         sta     tstadr+1
53
54 ; check if a 4K boundary is crossed
55
56         lda     lodadr+1
57         and     #$f0
58         sta     tmp
59         lda     tstadr+1
60         and     #$f0
61         cmp     tmp
62         beq     scrmemok
63
64 ; if lodadr is at an exact 4K boundary, it's still ok
65
66         lda     lodadr+1
67         and     #$0f
68         beq     scrmemok
69
70 ; 4K boundary will be crossed, use this 4K boundary address as lodadr
71
72 al4k:   lda     lodadr+1
73         and     #$f0
74         sta     lodadr+1
75         bne     scrmemtst
76 ; not reached
77
78 .ifdef DEBUG
79 .byte "XLMEMCHK:>"
80 .endif
81 lodadr: .word   __STARTADDRESS__ & $FF00                ; our program's load address, rounded down to page boundary
82 tstadr: .res    2
83 lowadr: .res    2
84 tmp:    .res    1
85
86
87 ; subtract display list size from calculated screen address
88
89 scrmemok:
90         lda     tstadr
91         sec
92         sbc     #<DLSZ
93         sta     lowadr
94         lda     tstadr+1
95         sbc     #>DLSZ
96         sta     lowadr+1
97
98 .if 0   ; this cannot happen
99 ; check if a 1K boundary is crossed
100
101         lda     tstadr+1
102         and     #$fc
103         sta     tmp
104         lda     lowadr+1
105         and     #$fc
106         cmp     tmp
107         bne     al4k            ; 1K boundary will be crossed, decrease lodadr
108 .endif
109
110 ; address of display list is ok
111 ; decrease lowadr by two
112
113         lda     lowadr
114         sec
115         sbc     #2
116         sta     lowadr
117         bcs     dec_cont
118         dec     lowadr+1
119 dec_cont: