]> git.sur5r.net Git - cc65/blobdiff - libsrc/tgi/tgi-kernel.s
remove superfluous ".code" line
[cc65] / libsrc / tgi / tgi-kernel.s
index 1cd44644c273119c6bc48c0372e3d1614cbdc902..a4316f8f1a5b5f920462cfc23eb1f863dcc5e649 100644 (file)
@@ -7,8 +7,8 @@
         .include        "tgi-kernel.inc"
         .include        "tgi-error.inc"
 
-        .export         tgi_clear_ptr
         .importzp       ptr1
+        .interruptor    tgi_irq         ; Export as IRQ handler
 
 
 ;----------------------------------------------------------------------------
 .bss
 
 _tgi_drv:                  .res    2           ; Pointer to driver
+; From here on, variables get cleared when a new driver is loaded
+cstart:
 _tgi_error:                .res    1           ; Last error code
 _tgi_gmode:         .res    1           ; Flag: Graphics mode active
 _tgi_curx:          .res    2           ; Current drawing cursor X
 _tgi_cury:          .res    2           ; Current drawing cursor Y
 _tgi_color:         .res    1           ; Current drawing color
+_tgi_font:          .res    1           ; Which font to use
 _tgi_textdir:       .res    1           ; Current text direction
-_tgi_textmagx:      .res    1           ; Text magnification in X dir
-_tgi_textmagy:      .res    1           ; Text magnification in Y dir
+_tgi_vectorfont:    .res    2           ; Pointer to vector font
+; The following two store an 8.8 fixed point value in the first two bytes,
+; and a rounded integer value in the third byte. The latter is passed to the
+; driver to scale the bitmap font. The variables are expected to be in
+; this order and adjacent.
+_tgi_textscalew:    .res    3           ; Text scale for the width
+_tgi_textscaleh:    .res    3           ; Text scale for the height
+
+; The following two must also be in exactly this order
+_tgi_charwidth:     .res    1           ; Char width of system font
+_tgi_charheight:    .res    1           ; Char height of system font
+
+; End of section that gets cleared when a new driver is loaded
+csize   = * - cstart
+
+; Maximum X and Y coordinate (that is, xres-1 and yres-1)
+_tgi_xmax:          .res    2
+_tgi_ymax:          .res    2
 
 ; The following variables are copied from the driver header for faster access
+; fontwidth and fontheight are expected to be in order and adjacent.
 tgi_driver_vars:
 _tgi_xres:          .res    2           ; X resolution of the current mode
 _tgi_yres:          .res    2           ; Y resolution of the current mode
 _tgi_colorcount:    .res    1           ; Number of available colors
 _tgi_pagecount:     .res    1           ; Number of available screen pages
-_tgi_fontsizex:     .res    1           ; System font X size
-_tgi_fontsizey:     .res    1           ; System font Y size
-tgi_driver_var_size     = * - tgi_driver_vars
+_tgi_fontwidth:     .res    1           ; System font width in pixels
+_tgi_fontheight:    .res    1           ; System font height in pixels
+_tgi_aspectratio:   .res    2           ; Aspect ratio in 8.8 fixed point
 
 
 .data
 
 ; Jump table for the driver functions.
 
+jumpvectors:
 tgi_install:               jmp     $0000
 tgi_uninstall:             jmp     $0000
 tgi_init:           jmp     $0000
@@ -56,19 +77,18 @@ tgi_getpalette:     jmp     $0000
 tgi_getdefpalette:  jmp     $0000
 tgi_setpixel:       jmp     $0000
 tgi_getpixel:       jmp     $0000
-tgi_horline:        jmp     $0000
 tgi_line:           jmp     $0000
 tgi_bar:            jmp     $0000
-tgi_circle:         jmp     $0000
 tgi_textstyle:      jmp     $0000
 tgi_outtext:        jmp     $0000
+tgi_irq:            .byte   $60, $00, $00       ; RTS plus two dummy bytes
 
 ; Driver header signature
 .rodata
 tgi_sig:        .byte   $74, $67, $69, TGI_API_VERSION  ; "tgi", version
-tgi_sig_len     = * - tgi_sig
 
 
+.code
 ;----------------------------------------------------------------------------
 ; void __fastcall__ tgi_install (void* driver);
 ; /* Install an already loaded driver. */
@@ -82,7 +102,7 @@ _tgi_install:
 
 ; Check the driver signature
 
-        ldy     #tgi_sig_len-1
+        ldy     #.sizeof(tgi_sig)-1
 @L0:    lda     (ptr1),y
         cmp     tgi_sig,y
         bne     tgi_inv_drv
@@ -91,54 +111,51 @@ _tgi_install:
 
 ; Copy the jump vectors
 
-        ldy     #TGI_HDR_JUMPTAB
+        ldy     #TGI_HDR::JUMPTAB
         ldx     #0
 @L1:    inx                             ; Skip JMP opcode
         jsr     copy                    ; Copy one byte
         jsr     copy                    ; Copy one byte
-        cpx     #(TGI_HDR_JUMPCOUNT*3)
+        cpy     #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
         bne     @L1
 
-; Check for emulation vectors needed
-
-        lda     tgi_bar+1
-        ora     tgi_bar+2               ; Do we have a BAR vector?
-        bne     @L2                     ; Jump if yes
-        lda     #<tgi_emu_bar           ; Use emulation if no
-        sta     tgi_bar+1
-        lda     #>tgi_emu_bar
-        sta     tgi_bar+2
+; Call the driver install routine. It may update header variables, so we copy
+; them after this call.
 
-@L2:    jsr     tgi_install             ; Call driver install routine, may...
-                                        ; ...update variables
-        jsr     tgi_set_ptr             ; Set ptr1 to tgi_drv
+        jsr     tgi_install
 
-; Copy variables. Beware: We are using internal knowledge about variable
-; layout here!
+; Copy variables from the driver header for faster access.
 
-        ldy     #TGI_HDR_XRES
-        ldx     #0
+        jsr     tgi_set_ptr             ; Set ptr1 to tgi_drv
+        ldy     #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
+        ldx     #.sizeof(TGI_HDR::VARS)-1
 @L3:    lda     (ptr1),y
         sta     tgi_driver_vars,x
-        iny
-        inx
-        cpx     #tgi_driver_var_size
-        bne     @L3
+        dey
+        dex
+        bpl     @L3
+
+; Install the IRQ vector if the driver needs it.
 
-; Initialize variables
+        lda     tgi_irq+2               ; Check high byte of IRQ vector
+        beq     @L4                     ; Jump if vector invalid
+       lda     #$4C                    ; Jump opcode
+               sta     tgi_irq                 ; Activate IRQ routine
+
+; Initialize some other variables
 
         lda     #$00
-        ldx     #7-1
-@L4:    sta     _tgi_error,x            ; Clear error/mode/curx/cury/textdir
+@L4:    ldx     #csize-1
+@L5:    sta     cstart,x                ; Clear error/mode/curx/cury/...
         dex
-        bpl     @L4
+        bpl     @L5
 
        rts
 
-; Copy one byte from the jump vectors
+; Copy one byte to the jump vectors
 
 copy:   lda     (ptr1),y
-        sta     tgi_install,x
+        sta     jumpvectors,x
         iny
         inx
         rts
@@ -177,11 +194,14 @@ tgi_set_ptr:
 
 _tgi_uninstall:
         jsr     _tgi_done               ; Switch off graphics
+
         jsr     tgi_uninstall           ; Allow the driver to clean up
 
+       lda     #$60                    ; RTS opcode
+       sta     tgi_irq                 ; Disable IRQ entry point
+
 ; Clear driver pointer and error code
 
-tgi_clear_ptr:                          ; External entry point
         lda     #$00
         sta     _tgi_drv
         sta     _tgi_drv+1
@@ -190,3 +210,4 @@ tgi_clear_ptr:                          ; External entry point
         rts
 
 
+