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