zdosio.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright (C) 1992, 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: zdosio.c,v 1.4 2002/02/21 22:24:54 giles Exp $ */
  14. /* MS-DOS direct I/O operators. */
  15. /* These should NEVER be included in a released configuration! */
  16. #include "dos_.h"
  17. #include "ghost.h"
  18. #include "oper.h"
  19. #include "store.h"
  20. /* <port> .inport <word> */
  21. private int
  22. zinport(i_ctx_t *i_ctx_p)
  23. {
  24. os_ptr op = osp;
  25. check_type(*op, t_integer);
  26. make_int(op, inport((int)op->value.intval));
  27. return 0;
  28. }
  29. /* <port> .inportb <byte> */
  30. private int
  31. zinportb(i_ctx_t *i_ctx_p)
  32. {
  33. os_ptr op = osp;
  34. check_type(*op, t_integer);
  35. make_int(op, inportb((int)op->value.intval));
  36. return 0;
  37. }
  38. /* <port> <word> .outport - */
  39. private int
  40. zoutport(i_ctx_t *i_ctx_p)
  41. {
  42. os_ptr op = osp;
  43. check_type(*op, t_integer);
  44. check_type(op[-1], t_integer);
  45. outport((int)op[-1].value.intval, (int)op->value.intval);
  46. pop(1);
  47. return 0;
  48. }
  49. /* <port> <byte> .outportb - */
  50. private int
  51. zoutportb(i_ctx_t *i_ctx_p)
  52. {
  53. os_ptr op = osp;
  54. check_type(*op, t_integer);
  55. check_int_leu(op[-1], 0xff);
  56. outportb((int)op[-1].value.intval, (byte) op->value.intval);
  57. pop(1);
  58. return 0;
  59. }
  60. /* <loc> .peek <byte> */
  61. private int
  62. zpeek(i_ctx_t *i_ctx_p)
  63. {
  64. os_ptr op = osp;
  65. check_type(*op, t_integer);
  66. make_int(op, *(byte *) (op->value.intval));
  67. return 0;
  68. }
  69. /* <loc> <byte> .poke - */
  70. private int
  71. zpoke(i_ctx_t *i_ctx_p)
  72. {
  73. os_ptr op = osp;
  74. check_type(*op, t_integer);
  75. check_int_leu(op[-1], 0xff);
  76. *(byte *) (op[-1].value.intval) = (byte) op->value.intval;
  77. pop(1);
  78. return 0;
  79. }
  80. /* ------ Operator initialization ------ */
  81. const op_def zdosio_op_defs[] =
  82. {
  83. {"1.inport", zinport},
  84. {"1.inportb", zinportb},
  85. {"2.outport", zoutport},
  86. {"2.outportb", zoutportb},
  87. {"1.peek", zpeek},
  88. {"2.poke", zpoke},
  89. op_def_end(0)
  90. };