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. |
adamdunkels | fb24dff | 2004-09-12 14:07:30 +0000 | [diff] [blame] | 14 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 15 | * products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | * |
| 30 | * This file is part of the "ctk" console GUI toolkit for cc65 |
| 31 | * |
adamdunkels | fb24dff | 2004-09-12 14:07:30 +0000 | [diff] [blame] | 32 | * $Id: ctk-mouse.c,v 1.6 2004/09/12 14:07:31 adamdunkels Exp $ |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include "ctk.h" |
| 37 | #include "ctk-mouse.h" |
| 38 | #include "ctk-conf.h" |
| 39 | |
| 40 | #if CTK_CONF_MOUSE_SUPPORT |
| 41 | |
| 42 | unsigned short ctk_mouse_joyy, ctk_mouse_joyx; |
| 43 | unsigned char ctk_mouse_firebutton; |
| 44 | |
| 45 | extern void ctk_mouse_asm_irq(void); |
| 46 | |
| 47 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 48 | #pragma optimize(push, off) |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 49 | void |
| 50 | ctk_mouse_init(void) |
| 51 | { |
adamdunkels | 9e5028e | 2003-04-09 09:02:05 +0000 | [diff] [blame] | 52 | /* Place mouse pointer at the middle of the screen. */ |
| 53 | ctk_mouse_joyx = 160; |
| 54 | ctk_mouse_joyy = 100; |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 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"); |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 63 | |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 64 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 65 | #pragma optimize(pop) |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 66 | /*-----------------------------------------------------------------------------------*/ |
| 67 | unsigned short |
| 68 | ctk_mouse_x(void) |
| 69 | { |
adamdunkels | a9b51fe | 2003-08-06 23:58:03 +0000 | [diff] [blame] | 70 | if(ctk_mouse_joyx >= 342) { |
| 71 | ctk_mouse_joyx = 0; |
| 72 | } else if(ctk_mouse_joyx >= 320) { |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 73 | ctk_mouse_joyx = 319; |
| 74 | } |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 75 | return ctk_mouse_joyx; |
| 76 | } |
| 77 | /*-----------------------------------------------------------------------------------*/ |
| 78 | unsigned short |
| 79 | ctk_mouse_y(void) |
| 80 | { |
| 81 | return ctk_mouse_joyy; |
| 82 | } |
| 83 | /*-----------------------------------------------------------------------------------*/ |
| 84 | unsigned char |
| 85 | ctk_mouse_button(void) |
| 86 | { |
| 87 | return ctk_mouse_firebutton; |
| 88 | } |
| 89 | /*-----------------------------------------------------------------------------------*/ |
| 90 | unsigned char |
| 91 | ctk_mouse_xtoc(unsigned short x) |
| 92 | { |
| 93 | return x / 8; |
| 94 | } |
| 95 | /*-----------------------------------------------------------------------------------*/ |
| 96 | unsigned char |
| 97 | ctk_mouse_ytoc(unsigned short y) |
| 98 | { |
| 99 | return y / 8; |
| 100 | } |
| 101 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 102 | #pragma optimize(push, off) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 103 | void |
| 104 | ctk_mouse_hide(void) |
| 105 | { |
| 106 | /* Turn off sprites 0 and 1 */ |
| 107 | asm("lda #0"); |
| 108 | asm("sta $d015"); |
| 109 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 110 | #pragma optimize(pop) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 111 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 112 | #pragma optimize(push, off) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 113 | void |
| 114 | ctk_mouse_show(void) |
| 115 | { |
| 116 | /* Turn on sprites 0 and 1 */ |
| 117 | asm("lda #3"); |
| 118 | asm("sta $d015"); |
| 119 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 120 | #pragma optimize(pop) |
adamdunkels | e6f14d6 | 2003-04-11 20:24:08 +0000 | [diff] [blame] | 121 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 942aabf | 2003-04-09 00:31:13 +0000 | [diff] [blame] | 122 | #endif /* CTK_CONF_MOUSE_SUPPORT */ |