]> 4ch.mooo.com Git - 16.git/blob - src/lib/modex16/rn.c
I DID IT PLANAR BUFFERING IS RENDERED! IT JUST NEEDS POLISHING~
[16.git] / src / lib / modex16 / rn.c
1 void\r
2 modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {\r
3     /* draw the region (the entire freakin bitmap) */\r
4     modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
5 }\r
6 \r
7 void\r
8 modexDrawBmpRegion(page_t *page, int x, int y,\r
9                    int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
10         word poffset = (word) page->data  + y*(page->width/4) + x/4;\r
11         byte *data = bmp->data;//+bmp->offset;\r
12         word bmpOffset = (word) data + ry * bmp->width + rx;\r
13         word width = rw;\r
14         word height = rh;\r
15         byte plane = 1 << ((byte) x & 0x03);\r
16         word scanCount = width/4 + (width%4 ? 1 :0);\r
17         word nextPageRow = page->width/4 - scanCount;\r
18         word nextBmpRow = (word) bmp->width - width;\r
19         word rowCounter;\r
20         byte planeCounter = 4;\r
21 \r
22     __asm {\r
23                 MOV AX, SCREEN_SEG      ; go to the VGA memory\r
24                 MOV ES, AX\r
25 \r
26                 MOV DX, SC_INDEX        ; point at the map mask register\r
27                 MOV AL, MAP_MASK        ;\r
28                 OUT DX, AL            ;\r
29 \r
30         PLANE_LOOP:\r
31                 MOV DX, SC_DATA  ; select the current plane\r
32                 MOV AL, plane      ;\r
33                 OUT DX, AL            ;\r
34 \r
35                 ;-- begin plane painting\r
36                 MOV AX, height    ; start the row counter\r
37                 MOV rowCounter, AX      ;\r
38                 MOV DI, poffset  ; go to the first pixel\r
39                 MOV SI, bmpOffset       ; go to the bmp pixel\r
40         ROW_LOOP:\r
41                 MOV CX, width      ; count the columns\r
42         SCAN_LOOP:\r
43                 MOVSB              ; copy the pixel\r
44                 SUB CX, 3              ; we skip the next 3\r
45                 ADD SI, 3              ; skip the bmp pixels\r
46                 LOOP SCAN_LOOP    ; finish the scan\r
47 \r
48                 MOV AX, nextPageRow\r
49                 ADD DI, AX            ; go to the next row on screen\r
50                 MOV AX, nextBmpRow\r
51                 ADD SI, AX            ; go to the next row on bmp\r
52 \r
53                 DEC rowCounter\r
54                 JNZ ROW_LOOP        ; do all the rows\r
55                 ;-- end plane painting\r
56                 MOV AL, plane      ; advance to the next plane\r
57                 SHL AL, 1              ;\r
58                 AND AL, 0x0f        ; mask the plane properly\r
59                 MOV plane, AL      ; store the plane\r
60 \r
61                 INC bmpOffset      ; start bmp at the right spot\r
62 \r
63                 DEC planeCounter\r
64                 JNZ PLANE_LOOP    ; do all 4 planes\r
65     }\r
66 }\r
67 \r
68 void\r
69 modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {\r
70     /* draw the whole sprite */\r
71     modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
72 }\r
73 \r
74 void\r
75 modexDrawSpriteRegion(page_t *page, int x, int y,\r
76                       int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
77         word poffset = (word)page->data + y*(page->width/4) + x/4;\r
78         byte *data = bmp->data;//+bmp->offset;\r
79         word bmpOffset = (word) data + ry * bmp->width + rx;\r
80         word width = rw;\r
81         word height = rh;\r
82         byte plane = 1 << ((byte) x & 0x03);\r
83         word scanCount = width/4 + (width%4 ? 1 :0);\r
84         word nextPageRow = page->width/4 - scanCount;\r
85         word nextBmpRow = (word) bmp->width - width;\r
86         word rowCounter;\r
87         byte planeCounter = 4;\r
88 \r
89     __asm {\r
90                 MOV AX, SCREEN_SEG      ; go to the VGA memory\r
91                 MOV ES, AX\r
92 \r
93                 MOV DX, SC_INDEX        ; point at the map mask register\r
94                 MOV AL, MAP_MASK        ;\r
95                 OUT DX, AL            ;\r
96 \r
97         PLANE_LOOP:\r
98                 MOV DX, SC_DATA  ; select the current plane\r
99                 MOV AL, plane      ;\r
100                 OUT DX, AL            ;\r
101 \r
102                 ;-- begin plane painting\r
103                 MOV AX, height    ; start the row counter\r
104                 MOV rowCounter, AX      ;\r
105                 MOV DI, poffset  ; go to the first pixel\r
106                 MOV SI, bmpOffset       ; go to the bmp pixel\r
107         ROW_LOOP:\r
108                 MOV CX, width      ; count the columns\r
109         SCAN_LOOP:\r
110                 LODSB\r
111                 DEC SI\r
112                 CMP AL, 0\r
113                 JNE DRAW_PIXEL    ; draw non-zero pixels\r
114 \r
115                 INC DI            ; skip the transparent pixel\r
116                 ADD SI, 1\r
117                 JMP NEXT_PIXEL\r
118         DRAW_PIXEL:\r
119                 MOVSB              ; copy the pixel\r
120         NEXT_PIXEL:\r
121                 SUB CX, 3              ; we skip the next 3\r
122                 ADD SI, 3              ; skip the bmp pixels\r
123                 LOOP SCAN_LOOP    ; finish the scan\r
124 \r
125                 MOV AX, nextPageRow\r
126                 ADD DI, AX            ; go to the next row on screen\r
127                 MOV AX, nextBmpRow\r
128                 ADD SI, AX            ; go to the next row on bmp\r
129 \r
130                 DEC rowCounter\r
131                 JNZ ROW_LOOP        ; do all the rows\r
132                 ;-- end plane painting\r
133 \r
134                 MOV AL, plane      ; advance to the next plane\r
135                 SHL AL, 1              ;\r
136                 AND AL, 0x0f        ; mask the plane properly\r
137                 MOV plane, AL      ; store the plane\r
138 \r
139                 INC bmpOffset      ; start bmp at the right spot\r
140 \r
141                 DEC planeCounter\r
142                 JNZ PLANE_LOOP    ; do all 4 planes\r
143     }\r
144 }\r