1 /**
2  ** mempeek.h ---- (far) memory read/write operations
3  **                Borland-C code
4  **
5  ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
6  ** [e-mail: csaba@vuse.vanderbilt.edu]
7  **
8  ** This file is part of the GRX graphics library.
9  **
10  ** The GRX graphics library is free software; you can redistribute it
11  ** and/or modify it under some conditions; see the "copying.grx" file
12  ** for details.
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  **
18  ** Basic memory peek and poke operations in byte, word and long sizes.
19  ** The poke operations are available in WRITE, XOR, OR and AND versions.
20  **
21  **/
22 
23 /* There's actually nothing special except of far pointer usage */
24 #define __INLINE_STD_PEEK__(P,S,T)        (*(unsigned T far *)(P))
25 #define __INLINE_STD_POKE__(P,V,OP,I,S,T) (*(unsigned T far *)(P) OP (V))
26 
27 #define __INLINE_FAR_PEEK__(P,S,T)        (*(volatile unsigned T far *)(P))
28 #define __INLINE_FAR_POKE__(P,V,OP,I,S,T) (*(volatile unsigned T far *)(P) OP (V))
29 
30 
31 /* optimized 24bpp access */
32 
33 #include "access24.h"
34 
35 #define __INLINE_24_PEEK__(P) (                                              \
36    _ES = (unsigned)(void _seg *)(void far *)(P),                             \
37    _DI = (unsigned)(void near *)(P),                                         \
38    (__emit__(0x26),__emit__(0x8b),__emit__(0x05), /* mov ax,es:[di]   */     \
39     __emit__(0x26),__emit__(0x8a),                /* mov dl,es:[di+2] */     \
40       __emit__(0x55), __emit__(0x02),                                        \
41     __emit__(0x30), __emit__(0xf6)   ),           /* xor dh,dh        */     \
42    (long)((void _seg *)_DX + (void near *)_AX)                               \
43 )
44 #define __INLINE_24_FAR_PEEK__ __INLINE_24_PEEK__
45 
46 
47 #define __INLINE_24_BCC_POKE__(P,C,OPC_w,OPC_b)  do {                        \
48    _AX = (unsigned)(C);                                                      \
49    _ES = (unsigned)(void _seg *)(void far *)(P);                             \
50    _DI = (unsigned)(void near *)(P);                                         \
51    __emit__((char)(0x26));          /* es:                       */          \
52    __emit__((char)(OPC_w));         /*    xor/or/and/mov [..],ax */          \
53    __emit__((char)(0x05));          /*                    di     */          \
54    __emit__((char)(0x47));          /*    inc di                 */          \
55    __emit__((char)(0x47));          /*    inc di                 */          \
56    _AL = RD24BYTE((C),2);                                                    \
57    __emit__((char)(0x26));          /* es:                       */          \
58    __emit__((char)(OPC_b));         /*    xor/or/and/mov [..],al */          \
59    __emit__((char)(0x05));          /*                    di     */          \
60 } while (0)
61 
62 
63 #define __INLINE_24_POKE__(P,C,OP,INS) \
64 	__INLINE_24_TMP1_POKE__(P,C,INS)
65 #define __INLINE_24_TMP1_POKE__(P,C,INS) \
66 	__INLINE_24_TMP2_POKE__(P,C,OPCODE_##INS##_mem_w,OPCODE_##INS##_mem_b)
67 #define __INLINE_24_TMP2_POKE__(P,C,OPCw,OPCb) \
68 	__INLINE_24_BCC_POKE__(P,C,OPCw,OPCb)
69 
70 #define __INLINE_24_FAR_POKE__ __INLINE_24_POKE__
71