adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 35 | * $Id: ctk-mouse.c,v 1.5 2004/07/18 13:19:47 oliverschmidt Exp $ |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 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 | |
| 45 | unsigned short ctk_mouse_joyy, ctk_mouse_joyx; |
| 46 | unsigned char ctk_mouse_firebutton; |
| 47 | |
| 48 | extern void ctk_mouse_asm_irq(void); |
| 49 | |
| 50 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 51 | #pragma optimize(push, off) |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 52 | void |
| 53 | ctk_mouse_init(void) |
| 54 | { |
adamdunkels | 9e5028e | 2003-04-09 09:02:05 +0000 | [diff] [blame] | 55 | /* Place mouse pointer at the middle of the screen. */ |
| 56 | ctk_mouse_joyx = 160; |
| 57 | ctk_mouse_joyy = 100; |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 58 | |
| 59 | /* Setup and start IRQ */ |
| 60 | asm("sei"); |
| 61 | asm("lda #<%v", ctk_mouse_asm_irq); |
| 62 | asm("sta $0314"); |
| 63 | asm("lda #>%v", ctk_mouse_asm_irq); |
| 64 | asm("sta $0315"); |
| 65 | asm("cli"); |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 66 | |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 67 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 68 | #pragma optimize(pop) |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 69 | /*-----------------------------------------------------------------------------------*/ |
| 70 | unsigned short |
| 71 | ctk_mouse_x(void) |
| 72 | { |
adamdunkels | a9b51fe | 2003-08-06 23:58:03 +0000 | [diff] [blame] | 73 | if(ctk_mouse_joyx >= 342) { |
| 74 | ctk_mouse_joyx = 0; |
| 75 | } else if(ctk_mouse_joyx >= 320) { |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 76 | ctk_mouse_joyx = 319; |
| 77 | } |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 78 | return ctk_mouse_joyx; |
| 79 | } |
| 80 | /*-----------------------------------------------------------------------------------*/ |
| 81 | unsigned short |
| 82 | ctk_mouse_y(void) |
| 83 | { |
| 84 | return ctk_mouse_joyy; |
| 85 | } |
| 86 | /*-----------------------------------------------------------------------------------*/ |
| 87 | unsigned char |
| 88 | ctk_mouse_button(void) |
| 89 | { |
| 90 | return ctk_mouse_firebutton; |
| 91 | } |
| 92 | /*-----------------------------------------------------------------------------------*/ |
| 93 | unsigned char |
| 94 | ctk_mouse_xtoc(unsigned short x) |
| 95 | { |
| 96 | return x / 8; |
| 97 | } |
| 98 | /*-----------------------------------------------------------------------------------*/ |
| 99 | unsigned char |
| 100 | ctk_mouse_ytoc(unsigned short y) |
| 101 | { |
| 102 | return y / 8; |
| 103 | } |
| 104 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 105 | #pragma optimize(push, off) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 106 | void |
| 107 | ctk_mouse_hide(void) |
| 108 | { |
| 109 | /* Turn off sprites 0 and 1 */ |
| 110 | asm("lda #0"); |
| 111 | asm("sta $d015"); |
| 112 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 113 | #pragma optimize(pop) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 114 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 115 | #pragma optimize(push, off) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 116 | void |
| 117 | ctk_mouse_show(void) |
| 118 | { |
| 119 | /* Turn on sprites 0 and 1 */ |
| 120 | asm("lda #3"); |
| 121 | asm("sta $d015"); |
| 122 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame^] | 123 | #pragma optimize(pop) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 124 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 125 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |