]> 4ch.mooo.com Git - 16.git/blob - 16/xlib/XPOINT.ASM
added xlib to the project and i gotta convert the damn makefile -.-
[16.git] / 16 / xlib / XPOINT.ASM
1 ;-----------------------------------------------------------------------\r
2 ; MODULE XPOINT\r
3 ;\r
4 ; Point functions all MODE X 256 Color resolutions\r
5 ;\r
6 ; Compile with Tasm.\r
7 ; C callable.\r
8 ;\r
9 ;\r
10 ; ****** XLIB - Mode X graphics library                ****************\r
11 ; ******                                               ****************\r
12 ; ****** Written By Themie Gouthas                     ****************\r
13 ;\r
14 ; egg@dstos3.dsto.gov.au\r
15 ; teg@bart.dsto.gov.au\r
16 ;-----------------------------------------------------------------------\r
17 \r
18 \r
19 include xlib.inc\r
20 include xpoint.inc\r
21 \r
22         .code\r
23 \r
24 \r
25 ;-----------------------------------------------------------------------\r
26 ; Mode X (256 color mode) write pixel routine.\r
27 ; No clipping is performed.\r
28 ;\r
29 ; Based on code originally published in DDJ Mag by M. Abrash\r
30 ;\r
31 ; C near-callable as:\r
32 ;    void x_put_pix(int X, int Y, int PageOffset, int Color);\r
33 ;\r
34 ;\r
35 \r
36 _x_put_pix  proc    \r
37         ARG X:word,Y:word,PgOfs:word,Color:word\r
38         push bp                   ;preserve caller's stack frame\r
39         mov  bp,sp                ;point to local stack frame\r
40 \r
41         mov  ax,[_ScrnLogicalByteWidth]\r
42         mul  [Y]                  ;offset of pixel's scan line in page\r
43         mov  bx,[X]\r
44         shr  bx,2                 ;X/4 = offset of pixel in scan line\r
45         add  bx,ax                ;offset of pixel in page\r
46         add  bx,[PgOfs]           ;offset of pixel in display memory\r
47         mov  ax,SCREEN_SEG\r
48         mov  es,ax                ;point ES:BX to the pixel's address\r
49 \r
50         mov  cl,byte ptr [X]\r
51         and  cl,011b              ;CL = pixel's plane\r
52         mov  ax,0100h + MAP_MASK  ;AL = index in SC of Map Mask reg\r
53         shl  ah,cl                ;set only the bit for the pixel's\r
54                                   ; plane to 1\r
55         mov  dx,SC_INDEX          ;set the Map Mask to enable only the\r
56         out  dx,ax                ; pixel's plane\r
57 \r
58         mov  al,byte ptr [Color]\r
59         mov  es:[bx],al           ;draw the pixel in the desired color\r
60 \r
61         pop   bp                  ;restore caller's stack frame\r
62         ret\r
63 _x_put_pix   endp\r
64 \r
65 ;-------------------------------------------------------------------------\r
66 ; Mode X (320x240, 256 colors) read pixel routine. Works on all VGAs.\r
67 ; No clipping is performed.\r
68 ;\r
69 ; Based on code originally published in DDJ Mag by M. Abrash\r
70 ;\r
71 ; C near-callable as:\r
72 ;    unsigned int x_get_pix(int X, int Y, unsigned int PageBase);\r
73 \r
74 \r
75 _x_get_pix   proc\r
76         ARG x:word,y:word,PageBase:word\r
77         push bp                   ;preserve caller's stack frame\r
78         mov  bp,sp                ;point to local stack frame\r
79 \r
80         mov  ax,[_ScrnLogicalByteWidth]\r
81         mul  [Y]                  ;offset of pixel's scan line in page\r
82         mov  bx,[X]\r
83         shr  bx,1\r
84         shr  bx,1                 ;X/4 = offset of pixel in scan line\r
85         add  bx,ax                ;offset of pixel in page\r
86         add  bx,[PageBase]        ;offset of pixel in display memory\r
87         mov  ax,SCREEN_SEG\r
88         mov  es,ax                ;point ES:BX to the pixel's address\r
89 \r
90         mov  ah,byte ptr [X]\r
91         and  ah,011b              ;AH = pixel's plane\r
92         mov  al,READ_MAP          ;AL = index in GC of the Read Map reg\r
93         mov  dx,GC_INDEX          ;set the Read Map to read the pixel's\r
94         out  dx,ax                ; plane\r
95 \r
96         mov  al,es:[bx]           ;read the pixel's color\r
97         sub  ah,ah                ;convert it to an unsigned int\r
98 \r
99         pop  bp                   ;restore caller's stack frame\r
100         ret\r
101 _x_get_pix   endp\r
102         end\r
103 \r
104 \r
105         end\r
106 \r
107 \1a