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