]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
Added emulation and more clipping for the BAR function.
[cc65] / libsrc / tgi / tgi-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 21.06.2002
3 ;
4 ; Common functions of the tgi graphics kernel.
5 ;
6
7         .include        "tgi-kernel.inc"
8         .include        "tgi-error.inc"
9
10         .export         _tgi_setup
11         .importzp       ptr1
12
13
14 ;----------------------------------------------------------------------------
15 ; Variables
16
17 .bss
18
19 _tgi_drv:       .res    2               ; Pointer to driver
20 _tgi_error:     .res    1               ; Last error code
21 _tgi_mode:      .res    1               ; Graphics mode or zero
22 _tgi_xres:      .res    2               ; X resolution of the current mode
23 _tgi_yres:      .res    2               ; Y resolution of the current mode
24 _tgi_colors:    .res    1               ; Number of available colors
25 _tgi_pagecount: .res    1               ; Number of available screen pages
26
27
28 .data
29
30 ; Jump table for the driver functions.
31
32 tgi_install:    jmp     $0000
33 tgi_deinstall:  jmp     $0000
34 tgi_init:       jmp     $0000
35 tgi_done:       jmp     $0000
36 tgi_control:    jmp     $0000
37 tgi_clear:      jmp     $0000
38 tgi_setviewpage:jmp     $0000
39 tgi_setdrawpage:jmp     $0000
40 tgi_setcolor:   jmp     $0000
41 tgi_setpixel:   jmp     $0000
42 tgi_getpixel:   jmp     $0000
43 tgi_line:       jmp     $0000
44 tgi_bar:        jmp     $0000
45 tgi_circle:     jmp     $0000
46
47
48 ;----------------------------------------------------------------------------
49 ; void __fastcall__ tgi_setup (void);
50 ; /* Setup the driver and graphics kernel once the driver is loaded */
51
52
53 copy:   lda     (ptr1),y
54         sta     tgi_install,x
55         iny
56         inx
57         rts
58
59
60 _tgi_setup:
61         jsr     tgi_set_ptr             ; load _tgi_drv into ptr1
62
63 ; Copy the jump vectors
64
65         ldy     #TGI_HDR_JUMPTAB
66         ldx     #0
67 @L1:    inx                             ; Skip JMP opcode
68         jsr     copy                    ; Copy one byte
69         jsr     copy                    ; Copy one byte
70         cpx     #(TGI_HDR_JUMPCOUNT*3)
71         bne     @L1
72
73 ; Check for emulation vectors needed
74
75         lda     tgi_bar+1
76         ora     tgi_bar+2               ; Do we have a BAR vector?
77         bne     @L2                     ; Jump if yes
78         lda     #<tgi_emu_bar           ; Use emulation if no
79         sta     tgi_bar+1
80         lda     #>tgi_emu_bar
81         sta     tgi_bar+2
82
83 ; Copy variables. Beware: We are using internal knowledge about variable
84 ; layout here!
85
86 @L2:    ldy     #TGI_HDR_XRES
87         ldx     #0
88 @L3:    lda     (ptr1),y
89         sta     _tgi_xres,x
90         iny
91         inx
92         cpx     #6
93         bne     @L3
94
95 ; Initialize variables
96
97         lda     #$00
98         sta     _tgi_error
99         sta     _tgi_mode
100
101         jsr     tgi_install             ; Call driver install routine
102
103 ;       jmp     tgi_fetch_error
104
105 ;----------------------------------------------------------------------------
106 ; Fetch the error code from the driver and place it into the global error
107 ; variable. The function will also return the error in A and the flags from
108 ; loading the error code are set.
109
110 tgi_fetch_error:
111         jsr     tgi_set_ptr
112         ldy     #TGI_HDR_ERROR
113         lda     (ptr1),y
114         sta     _tgi_error
115         rts
116
117 ;----------------------------------------------------------------------------
118 ; Load the pointer to the tgi driver into ptr1.
119
120 tgi_set_ptr:
121         lda     _tgi_drv
122         sta     ptr1
123         lda     _tgi_drv+1
124         sta     ptr1+1
125         rts
126
127 ;----------------------------------------------------------------------------
128 ; Set an invalid argument error
129
130 tgi_inv_arg:
131         lda     #TGI_ERR_INV_ARG
132         sta     _tgi_error
133         rts
134