Home | History | Annotate | Line # | Download | only in amiga
      1 /*	$NetBSD: cc.h,v 1.19 2021/08/12 20:13:54 andvar Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Christian E. Hopps
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Christian E. Hopps.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #if ! defined (_CC_H)
     34 #define _CC_H
     35 
     36 #include <sys/queue.h>
     37 #include <amiga/amiga/cc_registers.h>
     38 
     39 #ifndef __powerpc__
     40 #include "opt_lev6_defer.h"
     41 #endif /* __powerpc__ */
     42 
     43 #if ! defined (HIADDR)
     44 #define HIADDR(x) (u_short)((((unsigned long)(x))>>16)&0xffff)
     45 #endif
     46 #if ! defined (LOADDR)
     47 #define LOADDR(x) (u_short)(((unsigned long)(x))&0xffff)
     48 #endif
     49 
     50 
     51 /*
     52  * Audio stuff
     53  */
     54 struct audio_channel {
     55 	u_short play_count;
     56 	short	isaudio;
     57 	void  (*handler)(int);
     58 };
     59 
     60 #ifdef LEV6_DEFER
     61 #define AUCC_MAXINT 3
     62 #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2)
     63 #else
     64 #define AUCC_MAXINT 4
     65 #define AUCC_ALLINTF (INTF_AUD0|INTF_AUD1|INTF_AUD2|INTF_AUD3)
     66 #endif
     67 /*
     68  * Define this one unconditionally; we may use AUD3 as slave channel
     69  * with LEV6_DEFER
     70  */
     71 #define AUCC_ALLDMAF (DMAF_AUD0|DMAF_AUD1|DMAF_AUD2|DMAF_AUD3)
     72 
     73 /*
     74  * Vertical blank interrupt server chains.
     75  */
     76 
     77 struct vbl_node {
     78 	LIST_ENTRY(vbl_node) link;
     79 	short  priority;			/* Private. */
     80 	short  flags;				/* Private. */
     81 	void  (*function)(register void *);	/* put function pointer here */
     82 	void   *data;				/* functions data. */
     83 };
     84 
     85 enum vbl_node_bits {
     86     VBLNB_OFF,		  /* don't call me right now. */
     87     VBLNB_TURNOFF,	  /* turn function off. */
     88 };
     89 
     90 enum vlb_node_flags {
     91     VBLNF_OFF = 1 << VBLNB_OFF,
     92     VBLNF_TURNOFF = 1 << VBLNB_TURNOFF,
     93 };
     94 
     95 /*
     96  * Blitter stuff.
     97  */
     98 
     99 #define BLT_SHIFT_MASK(shift) (0xf&shift)
    100 
    101 #define MAKEBOOL(val) (val ? 1 : 0)
    102 
    103 #define DMAADDR(lng) (u_long)(((0x7 & lng) << 16)|(lng & 0xffff))
    104 
    105 #define MAKE_BLTCON0(shift_a, use_a, use_b, use_c, use_d, minterm) \
    106         ((0x0000) | (BLT_SHIFT_MASK(shift_a) << 12) | \
    107 	 (use_a << 11) |  (use_b << 10) |  (use_c << 9) |  (use_d << 8) | \
    108 	 (minterm))
    109 
    110 #define MAKE_BLTCON1(shift_b, efe, ife, fc, desc)  \
    111         ((0x0000) | (BLT_SHIFT_MASK(shift_b) << 12) | (efe << 4) | \
    112 	 (ife << 3) | (fc << 2) | (desc << 1))
    113 
    114 /*
    115  * Copper stuff.
    116  */
    117 
    118 typedef struct copper_list {
    119     union j {
    120 	struct k {
    121 	    u_short opcode;
    122 	    u_short operand;
    123 	} inst;
    124 	u_long data;
    125     } cp;
    126 } cop_t;
    127 
    128 #define CI_MOVE(x)   (0x7ffe & x)
    129 #define CI_WAIT(h,v) (((0x7f&v)<<8)|(0xfe&h)|(0x0001))
    130 #define CI_SKIP(x)   (((0x7f&v)<<8)|(0xfe&h)|(0x0001))
    131 
    132 #define CD_MOVE(x) (x)
    133 #define CD_WAIT(x) (x & 0xfffe)
    134 #define CD_SKIP(x) (x|0x0001)
    135 
    136 #define CBUMP(c) (c++)
    137 
    138 #define CMOVE(c,r,v) do { \
    139 			    c->cp.data=((CI_MOVE(r)<<16)|(CD_MOVE(v))); \
    140 		            CBUMP (c); \
    141 		        } while(0)
    142 #define CWAIT(c,h,v) do { \
    143 			    c->cp.data=((CI_WAIT(h,v) << 16)|CD_WAIT(0xfffe)); \
    144 		            CBUMP (c); \
    145 		        } while(0)
    146 #define CSKIP(c,h,v) do { \
    147 			    c->cp.data=((CI_SKIP(h,v)<<16)|CD_SKIP(0xffff)); \
    148 		            CBUMP (c); \
    149 		        } while(0)
    150 #define CEND(c) do { \
    151 			    c->cp.data=0xfffffffe; \
    152 		            CBUMP (c); \
    153 		        } while(0)
    154 
    155 /*
    156  * Chipmem allocator stuff.
    157  */
    158 
    159 struct mem_node {
    160 	TAILQ_ENTRY(mem_node) link;
    161 	TAILQ_ENTRY(mem_node) free_link;
    162 	u_long size;		/* size of memory following node. */
    163 	u_char type;		/* free, used */
    164 };
    165 #define MNODE_FREE 0
    166 #define MNODE_USED 1
    167 
    168 #define CM_BLOCKSIZE 0x4
    169 #define CM_BLOCKMASK (~(CM_BLOCKSIZE - 1))
    170 #define MNODES_MEM(mn) ((u_char *)(&mn[1]))
    171 #define PREP_DMA_MEM(mem) (void *)((char*)(mem) - CHIPMEMADDR)
    172 
    173 extern vaddr_t CHIPMEMADDR;
    174 extern vaddr_t chipmem_start;
    175 extern vaddr_t chipmem_end;
    176 #define CHIPMEMBASE	(0x00000000)
    177 #define CHIPMEMTOP	(0x00200000)
    178 #define NCHIPMEMPG	btoc(CHIPMEMTOP - CHIPMEMBASE)
    179 
    180 /*
    181  * Prototypes.
    182  */
    183 void custom_chips_init(void);
    184 /* vertical blank server chain */
    185 void cc_init_vbl(void);
    186 void add_vbl_function(struct vbl_node *, short, void *);
    187 void remove_vbl_function(struct vbl_node *);
    188 void turn_vbl_function_off(struct vbl_node *);
    189 void turn_vbl_function_on(struct vbl_node *);
    190 /* blitter */
    191 void cc_init_blitter(void);
    192 int is_blitter_busy(void);
    193 void wait_blit(void);
    194 void blitter_handler(void);
    195 void do_blit(u_short);
    196 void set_blitter_control(u_short, u_short);
    197 void set_blitter_mods(u_short, u_short, u_short, u_short);
    198 void set_blitter_masks(u_short, u_short);
    199 void set_blitter_data(u_short, u_short, u_short);
    200 void set_blitter_pointers(void *, void *, void *, void *);
    201 /* copper */
    202 void install_copper_list(cop_t *);
    203 cop_t *find_copper_inst(cop_t *, u_short);
    204 void cc_init_copper(void);
    205 void copper_handler(void);
    206 /* audio */
    207 void cc_init_audio(void);
    208 void play_sample(u_short, u_short *, u_short, u_short, u_short, u_long);
    209 void audio_handler(void);
    210 /* chipmem */
    211 void cc_init_chipmem(void);
    212 void *alloc_chipmem(u_long);
    213 void free_chipmem(void *);
    214 u_long avail_chipmem(int);
    215 u_long sizeof_chipmem(void *);
    216 
    217 void wait_tof(void);
    218 void vbl_handler(void);
    219 void *chipmem_steal(long);
    220 
    221 #endif /* _CC_H */
    222