1 /*
2  *  This file is part of x48, an emulator of the HP-48sx Calculator.
3  *  Copyright (C) 1994  Eddie C. Dost  (ecd@dressler.de)
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 /* $Log: device.c,v $
21  * Revision 1.8  1995/01/11  18:20:01  ecd
22  * major update to support HP48 G/GX
23  *
24  * Revision 1.7  1994/11/28  02:00:51  ecd
25  * played around with sound stuff
26  *
27  * Revision 1.7  1994/11/28  02:00:51  ecd
28  * played around with sound stuff
29  *
30  * Revision 1.6  1994/11/02  14:40:38  ecd
31  * adapted to new timer 2 stuff from timer.c
32  *
33  * Revision 1.5  1994/10/05  08:36:44  ecd
34  * removed addr queue
35  *
36  * Revision 1.4  1994/09/30  12:37:09  ecd
37  * new and FASTER display handling
38  *
39  * Revision 1.3  1994/09/18  15:29:22  ecd
40  * started Real Time support
41  *
42  * Revision 1.2  1994/09/13  16:57:00  ecd
43  * changed to plain X11
44  *
45  * Revision 1.1  1994/08/26  11:09:02  ecd
46  * Initial revision
47  *
48  *
49  * $Id: device.c,v 1.8 1995/01/11 18:20:01 ecd Exp ecd $
50  */
51 
52 #include "global.h"
53 
54 #include <stdlib.h>
55 
56 #include "hp48.h"
57 #include "hp48_emu.h"
58 #include "device.h"
59 #include "timer.h"
60 #include "x48_x11.h"
61 
62 extern int device_check;
63 
64 device_t device;
65 
66 void
67 #ifdef __FunctionProto__
check_devices(void)68 check_devices(void)
69 #else
70 check_devices()
71 #endif
72 {
73   if (device.display_touched > 0 && device.display_touched-- == 1) {
74     device.display_touched = 0;
75     update_display();
76   }
77   if (device.display_touched > 0) {
78     device_check = 1;
79   }
80   if (device.contrast_touched) {
81     device.contrast_touched = 0;
82     adjust_contrast(display.contrast);
83   }
84   if (device.ann_touched) {
85     device.ann_touched = 0;
86     draw_annunc();
87   }
88   if (device.baud_touched) {
89     device.baud_touched = 0;
90     serial_baud(saturn.baud);
91   }
92   if (device.ioc_touched) {
93     device.ioc_touched = 0;
94     if ((saturn.io_ctrl & 0x02) && (saturn.rcs & 0x01)) {
95       do_interupt();
96     }
97   }
98   if (device.rbr_touched) {
99     device.rbr_touched = 0;
100     receive_char();
101   }
102   if (device.tbr_touched) {
103     device.tbr_touched = 0;
104     transmit_char();
105   }
106   if (device.t1_touched) {
107     saturn.t1_instr = 0;
108     sched_timer1 = saturn.t1_tick;
109     restart_timer(T1_TIMER);
110     set_t1 = saturn.timer1;
111     device.t1_touched = 0;
112   }
113   if (device.t2_touched) {
114     saturn.t2_instr = 0;
115     sched_timer2 = saturn.t2_tick;
116     device.t2_touched = 0;
117   }
118 #if 0
119   if (device.disp_test_touched) {
120     device.disp_test_touched = 0;
121   }
122   if (device.crc_touched) {
123     device.crc_touched = 0;
124   }
125   if (device.power_status_touched) {
126     device.power_status_touched = 0;
127   }
128   if (device.power_ctrl_touched) {
129     device.power_ctrl_touched = 0;
130   }
131   if (device.mode_touched) {
132     device.mode_touched = 0;
133   }
134   if (device.card_ctrl_touched) {
135     device.card_ctrl_touched = 0;
136   }
137   if (device.card_status_touched) {
138     device.card_status_touched = 0;
139   }
140   if (device.tcs_touched) {
141     device.tcs_touched = 0;
142   }
143   if (device.rcs_touched) {
144     device.rcs_touched = 0;
145   }
146   if (device.sreq_touched) {
147     device.sreq_touched = 0;
148   }
149   if (device.ir_ctrl_touched) {
150     device.ir_ctrl_touched = 0;
151   }
152   if (device.base_off_touched) {
153     device.base_off_touched = 0;
154   }
155   if (device.lcr_touched) {
156     device.lcr_touched = 0;
157   }
158   if (device.lbr_touched) {
159     device.lbr_touched = 0;
160   }
161   if (device.scratch_touched) {
162     device.scratch_touched = 0;
163   }
164   if (device.base_nibble_touched) {
165     device.base_nibble_touched = 0;
166   }
167   if (device.unknown_touched) {
168     device.unknown_touched = 0;
169   }
170   if (device.t1_ctrl_touched) {
171     device.t1_ctrl_touched = 0;
172   }
173   if (device.t2_ctrl_touched) {
174     device.t2_ctrl_touched = 0;
175   }
176   if (device.unknown2_touched) {
177     device.unknown2_touched = 0;
178   }
179 #endif
180 }
181 
182 #if 0
183 
184 #include <stdio.h>
185 #include <stdlib.h>
186 #include <unistd.h>
187 #include <fcntl.h>
188 
189 void
190 #ifdef __FunctionProto__
191 check_out_register(void)
192 #else
193 check_out_register()
194 #endif
195 {
196   static int au = -2;
197   unsigned char c[] = { 0xff, 0x00 };
198 
199   if (au == -2)
200     if ((au = open("/dev/audio", O_WRONLY)) < 0)
201   if (au < 0)
202     return;
203   if (saturn.OUT[2] & 0x8)
204     write(au, c, 1);
205   else
206     write(au, &c[1], 1);
207 }
208 
209 #endif
210