1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied, modified
8 or distributed except as expressly authorized under the terms of that
9 license. Refer to licensing information at http://www.artifex.com/
10 or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11 San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
12 */
13
14 /* $Id: zdosio.c 9043 2008-08-28 22:48:19Z giles $ */
15 /* MS-DOS direct I/O operators. */
16 /* These should NEVER be included in a released configuration! */
17 #include "dos_.h"
18 #include "ghost.h"
19 #include "oper.h"
20 #include "store.h"
21
22 /* <port> .inport <word> */
23 static int
zinport(i_ctx_t * i_ctx_p)24 zinport(i_ctx_t *i_ctx_p)
25 {
26 os_ptr op = osp;
27
28 check_type(*op, t_integer);
29 make_int(op, inport((int)op->value.intval));
30 return 0;
31 }
32
33 /* <port> .inportb <byte> */
34 static int
zinportb(i_ctx_t * i_ctx_p)35 zinportb(i_ctx_t *i_ctx_p)
36 {
37 os_ptr op = osp;
38
39 check_type(*op, t_integer);
40 make_int(op, inportb((int)op->value.intval));
41 return 0;
42 }
43
44 /* <port> <word> .outport - */
45 static int
zoutport(i_ctx_t * i_ctx_p)46 zoutport(i_ctx_t *i_ctx_p)
47 {
48 os_ptr op = osp;
49
50 check_type(*op, t_integer);
51 check_type(op[-1], t_integer);
52 outport((int)op[-1].value.intval, (int)op->value.intval);
53 pop(1);
54 return 0;
55 }
56
57 /* <port> <byte> .outportb - */
58 static int
zoutportb(i_ctx_t * i_ctx_p)59 zoutportb(i_ctx_t *i_ctx_p)
60 {
61 os_ptr op = osp;
62
63 check_type(*op, t_integer);
64 check_int_leu(op[-1], 0xff);
65 outportb((int)op[-1].value.intval, (byte) op->value.intval);
66 pop(1);
67 return 0;
68 }
69
70 /* <loc> .peek <byte> */
71 static int
zpeek(i_ctx_t * i_ctx_p)72 zpeek(i_ctx_t *i_ctx_p)
73 {
74 os_ptr op = osp;
75
76 check_type(*op, t_integer);
77 make_int(op, *(byte *) (op->value.intval));
78 return 0;
79 }
80
81 /* <loc> <byte> .poke - */
82 static int
zpoke(i_ctx_t * i_ctx_p)83 zpoke(i_ctx_t *i_ctx_p)
84 {
85 os_ptr op = osp;
86
87 check_type(*op, t_integer);
88 check_int_leu(op[-1], 0xff);
89 *(byte *) (op[-1].value.intval) = (byte) op->value.intval;
90 pop(1);
91 return 0;
92 }
93
94 /* ------ Operator initialization ------ */
95
96 const op_def zdosio_op_defs[] =
97 {
98 {"1.inport", zinport},
99 {"1.inportb", zinportb},
100 {"2.outport", zoutport},
101 {"2.outportb", zoutportb},
102 {"1.peek", zpeek},
103 {"2.poke", zpoke},
104 op_def_end(0)
105 };
106