blob: 4ea86fa8b4b5672bf8fbbcfab3608c4d44792c9d [file] [log] [blame]
adamdunkels942aabf2003-04-09 00:31:13 +00001/*
2 * Copyright (c) 2003, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the "ctk" console GUI toolkit for cc65
34 *
35 * $Id: ctk-mouse.c,v 1.1 2003/04/09 00:31:14 adamdunkels Exp $
36 *
37 */
38
39#include "ctk.h"
40#include "ctk-mouse.h"
41#include "ctk-conf.h"
42
43#if CTK_CONF_MOUSE_SUPPORT
44
45unsigned short ctk_mouse_joyy, ctk_mouse_joyx;
46unsigned char ctk_mouse_firebutton;
47
48extern void ctk_mouse_asm_irq(void);
49
50/*-----------------------------------------------------------------------------------*/
51void
52ctk_mouse_init(void)
53{
54 ctk_mouse_joyx = ctk_mouse_joyy = 0;
55
56 /* Setup and start IRQ */
57 asm("sei");
58 asm("lda #<%v", ctk_mouse_asm_irq);
59 asm("sta $0314");
60 asm("lda #>%v", ctk_mouse_asm_irq);
61 asm("sta $0315");
62 asm("cli");
63
64 /* Turn on sprite 0 */
65 asm("lda #1");
66 asm("sta $d015");
67
68 asm("lda #9");
69 asm("sta $d027");
70}
71/*-----------------------------------------------------------------------------------*/
72unsigned short
73ctk_mouse_x(void)
74{
75 return ctk_mouse_joyx;
76}
77/*-----------------------------------------------------------------------------------*/
78unsigned short
79ctk_mouse_y(void)
80{
81 return ctk_mouse_joyy;
82}
83/*-----------------------------------------------------------------------------------*/
84unsigned char
85ctk_mouse_button(void)
86{
87 return ctk_mouse_firebutton;
88}
89/*-----------------------------------------------------------------------------------*/
90unsigned char
91ctk_mouse_xtoc(unsigned short x)
92{
93 return x / 8;
94}
95/*-----------------------------------------------------------------------------------*/
96unsigned char
97ctk_mouse_ytoc(unsigned short y)
98{
99 return y / 8;
100}
101/*-----------------------------------------------------------------------------------*/
102#endif /* CTK_CONF_MOUSE_SUPPORT */