~ubuntu-branches/ubuntu/breezy/tiemu/breezy

« back to all changes in this revision

Viewing changes to src/core/ti_hw/keyboard.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2005-06-02 16:50:15 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050602165015-59ab24414tl2wzol
Tags: 1.99+svn1460-1
* New snapshot.
* debian/control:
  + Updated build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  gtktiemu - a TI89/92/92+ emulator
2
 
 *  (c) Copyright 2000-2001, Romain Lievin and Thomas Corvazier
3
 
 *
4
 
 *  This program is free software; you can redistribute it and/or modify
5
 
 *  it under the terms of the GNU General Public License as published by
6
 
 *  the Free Software Foundation; either version 2 of the License, or
7
 
 *  (at your option) any later version.
8
 
 *
9
 
 *  This program is distributed in the hope that it will be useful,
10
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 *  GNU General Public License for more details.
13
 
 *
14
 
 *  You should have received a copy of the GNU General Public License
15
 
 *  along with this program; if not, write to the Free Software
16
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
/*
20
 
  TI keyboard management
21
 
*/
22
 
 
23
 
#include <stdlib.h>
24
 
#include <stdio.h>
25
 
#include <ctype.h>
26
 
 
27
 
#include "uae.h"
28
 
#include "keydefs.h"
29
 
#include "memory.h"
30
 
#include "callbacks.h"
31
 
#include "consts.h"
32
 
#include "images.h"
33
 
 
34
 
int on_key = 0;
35
 
static int key_states[NB_MAX_KEYS];
36
 
 
37
 
int keyRow92[10][8] =
38
 
{
39
 
  {TIKEY_DOWN, TIKEY_RIGHT, TIKEY_UP, TIKEY_LEFT, TIKEY_HAND, 
40
 
   TIKEY_SHIFT, TIKEY_DIAMOND, TIKEY_2ND},
41
 
  {TIKEY_3, TIKEY_2, TIKEY_1, TIKEY_F8, TIKEY_W, TIKEY_S, TIKEY_Z, TIKEY_NU},
42
 
  {TIKEY_6, TIKEY_5, TIKEY_4, TIKEY_F3, TIKEY_E, TIKEY_D, TIKEY_X, TIKEY_NU},
43
 
  {TIKEY_9, TIKEY_8, TIKEY_7, TIKEY_F7, TIKEY_R, TIKEY_F, TIKEY_C, 
44
 
   TIKEY_STORE},
45
 
  {TIKEY_COMMA, TIKEY_PARIGHT, TIKEY_PALEFT, TIKEY_F2, TIKEY_T, TIKEY_G, 
46
 
   TIKEY_V, TIKEY_SPACE},
47
 
  {TIKEY_TAN, TIKEY_COS, TIKEY_SIN, TIKEY_F6, TIKEY_Y, TIKEY_H, TIKEY_B, 
48
 
   TIKEY_DIVIDE},
49
 
  {TIKEY_P, TIKEY_ENTER2, TIKEY_LN, TIKEY_F1, TIKEY_U, TIKEY_J, TIKEY_N, 
50
 
   TIKEY_POWER},
51
 
  {TIKEY_MULTIPLY, TIKEY_APPS, TIKEY_CLEAR, TIKEY_F5, TIKEY_I, TIKEY_K, 
52
 
   TIKEY_M, TIKEY_EQUALS},
53
 
  {TIKEY_NU, TIKEY_ESCAPE, TIKEY_MODE, TIKEY_PLUS, TIKEY_O, TIKEY_L, 
54
 
   TIKEY_THETA, TIKEY_BACKSPACE},
55
 
  {TIKEY_NEGATE, TIKEY_PERIOD, TIKEY_0, TIKEY_F4, TIKEY_Q, TIKEY_A, 
56
 
   TIKEY_ENTER1, TIKEY_MINUS}
57
 
};
58
 
 
59
 
int keyRow89[10][8] =
60
 
{
61
 
  {TIKEY_ALPHA, TIKEY_DIAMOND, TIKEY_SHIFT, TIKEY_2ND, TIKEY_RIGHT, 
62
 
   TIKEY_DOWN, TIKEY_LEFT, TIKEY_UP},
63
 
  {TIKEY_F5, TIKEY_CLEAR, TIKEY_POWER, TIKEY_DIVIDE, TIKEY_MULTIPLY, 
64
 
   TIKEY_MINUS, TIKEY_PLUS, TIKEY_ENTER1},
65
 
  {TIKEY_F4, TIKEY_BACKSPACE, TIKEY_T, TIKEY_COMMA, TIKEY_9, TIKEY_6, 
66
 
   TIKEY_3, TIKEY_NEGATE},
67
 
  {TIKEY_F3, TIKEY_CATALOG, TIKEY_Z, TIKEY_PARIGHT, TIKEY_8, TIKEY_5, 
68
 
   TIKEY_2, TIKEY_PERIOD},
69
 
  {TIKEY_F2, TIKEY_MODE, TIKEY_Y, TIKEY_PALEFT, TIKEY_7, TIKEY_4, TIKEY_1, 
70
 
   TIKEY_0},
71
 
  {TIKEY_F1, TIKEY_HOME, TIKEY_X, TIKEY_EQUALS, TIKEY_PIPE, TIKEY_EE, 
72
 
   TIKEY_STORE, TIKEY_APPS},
73
 
  {TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, 
74
 
   TIKEY_VOID, TIKEY_ESCAPE},
75
 
  {TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, 
76
 
   TIKEY_VOID, TIKEY_VOID},
77
 
  {TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, 
78
 
   TIKEY_VOID, TIKEY_VOID},
79
 
  {TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, TIKEY_VOID, 
80
 
   TIKEY_VOID, TIKEY_VOID}
81
 
};
82
 
 
83
 
int *key_row;
84
 
 
85
 
/* Press a key */
86
 
void ti68k_setActiveKey(int key, int active)
87
 
{
88
 
  key_states[key] = active;
89
 
}
90
 
 
91
 
/* Returns true if the corresponding key was pressed */
92
 
int ti68k_isKeyPressed(int key)
93
 
{
94
 
  return key_states[key];
95
 
}
96
 
 
97
 
int hw_update_kbd(void) 
98
 
{
99
 
  int rc = cb_update_keys();
100
 
 
101
 
  if( (on_key = ti68k_isKeyPressed(TIKEY_ON)) ) 
102
 
    {
103
 
      if(specialflags & SPCFLAG_STOP)
104
 
        specialflags &= ~SPCFLAG_STOP;
105
 
      if(specialflags < 6) // no ints: ON works but FARGO do not
106
 
        //if(currIntLev < 6)
107
 
        {
108
 
          specialflags |= SPCFLAG_INT;
109
 
          currIntLev = 6;
110
 
        }
111
 
      key_states[TIKEY_ON] = 0;
112
 
    }
113
 
  else if(rc)
114
 
    {
115
 
      if(currIntLev < 2)
116
 
        {
117
 
          specialflags |= SPCFLAG_INT;
118
 
          currIntLev = 2;
119
 
        }
120
 
    }
121
 
  
122
 
  return rc;
123
 
}
124
 
 
125
 
 
126
 
UBYTE get_rowmask(UBYTE r) 
127
 
{
128
 
  UBYTE rc = 0;
129
 
  int i;
130
 
  int *row = key_row+(r<<3);
131
 
  
132
 
  for(i=0; i<8; i++)
133
 
    {
134
 
      rc |= key_states[row[i]]<<(7-i);
135
 
    }
136
 
  
137
 
  return rc;
138
 
}
139
 
 
140
 
UBYTE read_keyboard_mask(void)
141
 
{
142
 
  static int i;
143
 
  static UBYTE arg;
144
 
  static UWORD mask;
145
 
 
146
 
  arg=0;
147
 
  mask = (((UWORD)ti_io[0x18])<<8)|ti_io[0x19];
148
 
  for(i=0; i<10; i++)
149
 
    {
150
 
      if(!(mask & (1<<i)))
151
 
        arg |= get_rowmask(i);
152
 
    }
153
 
 
154
 
  return (UBYTE)(~arg);
155
 
}
156
 
 
157
 
void hw_init_kbd()
158
 
{
159
 
  if(current_rom_info.calc_type & TI92)
160
 
    key_row = (int*)keyRow92;
161
 
  else
162
 
    key_row = (int*)keyRow89;
163
 
}
164
 
 
165
 
void hw_exit_kbd()
166
 
{
167
 
  key_row = NULL;
168
 
}