File: graphics.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (108 lines) | stat: -rw-r--r-- 2,599 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;
; Christian Groessler, June 2004
;
; this file provides an equivalent to the BASIC GRAPHICS function
;
; int __fastcall__ _graphics(unsigned char mode);
;
;

        .export __graphics

        .import findfreeiocb
        .import __oserror
        .import fddecusage
        .import clriocb
        .import fdtoiocb
        .import newfd
        .import scrdev
        .importzp tmp1,tmp2,tmp3

        .include        "atari.inc"
        .include        "errno.inc"

        .code

; set new grapics mode
; gets new mode in A
; returns handle or -1 on error
; uses tmp1, tmp2, tmp3, tmp4 (in subroutines)

.proc   __graphics

;       tax
;       and     #15             ; get required graphics mode
;       cmp     #12
;       bcs     invmode         ; invalid mode
;       txa
;       and     #$c0            ; invalid bits set?
;       bne     invmode

;       stx     tmp1
        sta     tmp1            ; remember graphics mode

parmok: jsr     findfreeiocb
        beq     iocbok          ; we found one

        lda     #<EMFILE        ; "too many open files"
seterr: jsr     __mappederrno   ; @@@ probably not correct to set errno here @@@
        rts                     ; return -1

;invmode:ldx    #>EINVAL
;       lda     #<EINVAL
;       bne     seterr

iocbok: txa
        tay                     ; move iocb # into Y
        lda     #3
        sta     tmp3            ; name length + 1
        lda     #<scrdev
        ldx     #>scrdev
        jsr     newfd
        tya
        tax
        bcs     doopen          ; C set: open needed

        ldx     #0
        lda     tmp2            ; get fd used
        jsr     fdtoiocb
        tax

doopen: txa
        ;brk
        pha
        jsr     clriocb
        pla
        tax
        lda     #<scrdev
        sta     ICBAL,x
        lda     #>scrdev
        sta     ICBAH,x
        lda     #OPEN
        sta     ICCOM,x
        lda     tmp1            ; get requested graphics mode
        and     #15
        sta     ICAX2,x
        lda     tmp1
        and     #$30
        eor     #$10
        ora     #12
        sta     ICAX1,x

        jsr     CIOV
        bmi     cioerr

        lda     tmp2            ; get fd
        ldx     #0
        stx     __oserror
        rts

cioerr: sty     tmp3            ; remember error code
        lda     #CLOSE
        sta     ICCOM,x
        jsr     CIOV            ; close IOCB again since open failed
        jsr     fddecusage      ; and decrement usage counter of fd
        lda     tmp3            ; put error code into A
        jmp     __mappederrno

.endproc        ; __graphics