]> git.sur5r.net Git - cc65/blob - libsrc/atari/graphics.s
181aeed645c0ea8fde2258995a6f48072cbc7b8f
[cc65] / libsrc / atari / graphics.s
1 ;
2 ; Christian Groessler, October 2001
3 ;
4 ; this file provides an equivalent to the BASIC GRAPHICS function
5 ;
6 ; int __fastcall__ graphics(unsigned char mode);
7 ;
8 ;
9
10         .export _graphics
11         .constructor    initscrmem,28
12
13         .import findfreeiocb
14         .import __do_oserror,__oserror
15         .import fddecusage
16         .import clriocb
17         .import fdtoiocb
18         .import newfd
19         .import __graphmode_used
20         .importzp tmp1,tmp2,tmp3
21
22         .include        "atari.inc"
23         .include        "errno.inc"
24
25         .code
26
27 ; set new grapics mode
28 ; gets new mode in A
29 ; returns handle or -1 on error
30 ; uses tmp1, tmp2, tmp3, tmp4 (in subroutines)
31
32 .proc   _graphics
33
34 ;       tax
35 ;       and     #15             ; get required graphics mode
36 ;       cmp     #12
37 ;       bcs     invmode         ; invalid mode
38 ;       txa
39 ;       and     #$c0            ; invalid bits set?
40 ;       bne     invmode
41
42 ;       stx     tmp1
43         sta     tmp1            ; remember graphics mode
44
45 parmok: jsr     findfreeiocb
46         beq     iocbok          ; we found one
47
48         lda     #<EMFILE        ; "too many open files"
49 seterr: jsr     __seterrno
50         lda     #$FF
51         tax
52         rts                     ; return -1
53
54 ;invmode:ldx    #>EINVAL
55 ;       lda     #<EINVAL
56 ;       bne     seterr
57
58 iocbok: txa
59         tay                     ; move iocb # into Y
60         lda     #3
61         sta     tmp3            ; name length + 1
62         lda     #<scrdev
63         ldx     #>scrdev
64         jsr     newfd
65         tya
66         tax
67         bcs     doopen          ; C set: open needed
68
69         ldx     #0
70         lda     tmp2            ; get fd used
71         jsr     fdtoiocb
72         tax
73
74 doopen: txa
75         ;brk
76         pha
77         jsr     clriocb
78         pla
79         tax
80         lda     #<scrdev
81         sta     ICBAL,x
82         lda     #>scrdev
83         sta     ICBAH,x
84         lda     #OPEN
85         sta     ICCOM,x
86         lda     tmp1            ; get requested graphics mode
87         and     #15
88         sta     ICAX2,x
89         lda     tmp1
90         and     #$30
91         eor     #$10
92         ora     #12
93         sta     ICAX1,x
94
95         jsr     CIOV
96         bmi     cioerr
97
98         lda     tmp2            ; get fd
99         ldx     #0
100         stx     __oserror
101         rts
102
103 cioerr: jsr     fddecusage      ; decrement usage counter of fd as open failed
104         jmp     __do_oserror
105
106 .endproc        ; _graphics
107
108
109 ; calc. upper memory limit to use
110
111 .proc   initscrmem
112
113         lda     __graphmode_used
114         beq     ignore          ; mode 0 doesn't need adjustment
115         cmp     #32
116         bcs     ignore          ; invalid value
117
118         asl     a
119         tay
120         lda     APPMHI
121         sec
122         sbc     grmemusage,y
123         sta     APPMHI
124         lda     APPMHI+1
125         sbc     grmemusage+1,y
126         sta     APPMHI+1
127 ignore: rts
128
129 .endproc        ; initscrmem
130
131         .rodata
132
133 scrdev: .byte   "S:", 0
134
135
136 ; memory usage of the different graphics modes (0-31)
137 ; values < 0 of "bytes needed" are mappped to 0
138 ;               bytes needed    ; mode  ; val. of MEMTOP
139 grmemusage:
140         .word   0               ; 0     ; 39967
141         .word   0 ;-318         ; 1     ; 40285
142         .word   0 ;-568         ; 2     ; 40535
143         .word   0 ;-558         ; 3     ; 40525
144         .word   0 ;-298         ; 4     ; 40265
145         .word   182             ; 5     ; 39785
146         .word   1182            ; 6     ; 38785
147         .word   3198            ; 7     ; 36769
148         .word   7120            ; 8     ; 32847
149         .word   7146            ; 9     ; 32821
150         .word   7146            ; 10    ; 32821
151         .word   7146            ; 11    ; 32821
152         .word   162             ; 12    ; 39805
153         .word   0 ;-328         ; 13    ; 40295
154         .word   3278            ; 14    ; 36689
155         .word   7120            ; 15    ; 32847
156         .word   0               ; 16    ; 39967
157         .word   0 ;-320         ; 17    ; 40287
158         .word   0 ;-572         ; 18    ; 40539
159         .word   0 ;-560         ; 19    ; 40527
160         .word   0 ;-296         ; 20    ; 40263
161         .word   184             ; 21    ; 39783
162         .word   1192            ; 22    ; 38775
163         .word   3208            ; 23    ; 36759
164         .word   7146            ; 24    ; 32821
165         .word   7146            ; 25    ; 32821
166         .word   7146            ; 26    ; 32821
167         .word   7146            ; 27    ; 32821
168         .word   160             ; 28    ; 39807
169         .word   0 ;-332         ; 29    ; 40299
170         .word   3304            ; 30    ; 36663
171         .word   7146            ; 31    ; 32821
172
173 ; the program used to get these values (Atari BASIC):
174 ;  100 FILE=0
175 ;  110 IF FILE=1 THEN OPEN #1,8,0,"D:FREEMEM.OUT"
176 ;  120 IF FILE<>1 THEN OPEN #1,8,0,"E:"
177 ;  200 DIM G(32)
178 ;  210 FOR I=0 TO 32:GRAPHICS I:GOSUB 1000:G(I)=VAL:NEXT I
179 ;  220 GRAPHICS 0
180 ;  230 FOR I=0 TO 31:PRINT #1;I;":",G(I);" - ";G(0)-G(I):NEXT I
181 ;  240 CLOSE #1
182 ;  999 END
183 ;  1000 VAL=PEEK(741)+256*PEEK(742)
184 ;  1010 RETURN
185