Subversion Repositories Kolibri OS

Rev

Rev 1264 | Rev 2436 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;  VGA.INC                                                     ;;
7
;;                                                              ;;
8
;;  640x480 mode 0x12 VGA functions for MenuetOS                ;;
9
;;                                                              ;;
10
;;  Paul Butcher, paul.butcher@asa.co.uk                        ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
$Revision: 2288 $
15
 
16
 
17
paletteVGA:
18
 
19
;16 colour palette
20
        mov     dx, 0x3c8
21
        mov     al, 0
22
        out     dx, al
23
 
24
        mov     ecx, 16
25
        mov     dx, 0x3c9
26
        xor     eax, eax
27
 
28
     palvganew:
29
 
30
        mov     al, 0
31
        test    ah, 4
32
        jz      palvgalbl1
33
        add     al, 31
34
        test    ah, 8
35
        jz      palvgalbl1
36
        add     al, 32
37
     palvgalbl1:
38
        out     dx, al; red 0,31 or 63
39
        mov     al, 0
40
        test    ah, 2
41
        jz      palvgalbl2
42
        add     al, 31
43
        test    ah, 8
44
        jz      palvgalbl2
45
        add     al, 32
46
     palvgalbl2:
47
        out     dx, al; blue 0,31 or 63
48
        mov     al, 0
49
        test    ah, 1
50
        jz      palvgalbl3
51
        add     al, 31
52
        test    ah, 8
53
        jz      palvgalbl3
54
        add     al, 32
55
     palvgalbl3:
56
        out     dx, al; green 0,31 or 63
57
        add     ah, 1
58
        loop    palvganew
59
;       mov    dx, 3ceh
60
;       mov    ax, 0005h
61
;       out    dx, ax
62
        ret
63
 
64
palette320x200:
65
 
66
        mov     edx, 0x3c8
67
        xor     eax, eax
68
        out     dx, al
69
        mov     ecx, 256
70
        mov     edx, 0x3c9
71
        xor     eax, eax
72
 
73
     palnew:
74
        mov     al, 0
75
        test    ah, 64
76
        jz      pallbl1
77
        add     al, 21
78
     pallbl1:
79
        test    ah, 128
80
        jz      pallbl2
81
        add     al, 42
82
     pallbl2:
83
        out     dx, al
84
        mov     al, 0
85
        test    ah, 8
86
        jz      pallbl3
87
        add     al, 8
88
     pallbl3:
89
        test    ah, 16
90
        jz      pallbl4
91
        add     al, 15
92
     pallbl4:
93
        test    ah, 32
94
        jz      pallbl5
95
        add     al, 40
96
     pallbl5:
97
        out     dx, al
98
        mov     al, 0
99
        test    ah, 1
100
        jz      pallbl6
101
        add     al, 8
102
     pallbl6:
103
        test    ah, 2
104
        jz      pallbl7
105
        add     al, 15
106
     pallbl7:
107
        test    ah, 4
108
        jz      pallbl8
109
        add     al, 40
110
     pallbl8:
111
        out     dx, al
112
        add     ah, 1
113
        loop    palnew
114
 
115
        ret
116
align 4
117
uglobal
118
  novesachecksum dd 0x0
119
  EGA_counter    db  0
120
  VGA_drawing_screen db 0
121
  VGA_8_pixels:
122
     rb 16
123
  temp:
124
     .cx dd 0
125
endg
126
align 4
127
checkVga_N13:
128
 
129
        cmp     [SCR_MODE], dword 0x13
130
        jne     @f
131
 
132
;      cnvl:
133
        pushad
134
        cmp     [EGA_counter], 1
135
        je      novesal
136
        mov     ecx, [MOUSE_X]
137
        cmp     ecx, [novesachecksum]
138
        jne     novesal
139
        popad
140
      @@:
141
        ret
142
 
143
      novesal:
144
        mov     [novesachecksum], ecx
145
        mov     ecx, 0
146
        movzx   eax, word [MOUSE_Y]
147
        cmp     eax, 100
148
        jge     m13l3
149
        mov     eax, 100
150
      m13l3:
151
        cmp     eax, 480-100
152
        jbe     m13l4
153
        mov     eax, 480-100
154
      m13l4:
155
        sub     eax, 100
156
        imul    eax, 640*4
157
        add     ecx, eax
158
        movzx   eax, word [MOUSE_X]
159
        cmp     eax, 160
160
        jge     m13l1
161
        mov     eax, 160
162
      m13l1:
163
        cmp     eax, 640-160
164
        jbe     m13l2
165
        mov     eax, 640-160
166
      m13l2:
167
        sub     eax, 160
168
        shl     eax, 2
169
        add     ecx, eax
170
        mov     esi, [LFBAddress]
171
        add     esi, ecx
172
        mov     edi, VGABasePtr
173
        mov     edx, 200
174
        mov     ecx, 320
175
        cld
176
     m13pix:
177
        lodsd
178
        test    eax, eax
179
        jz      .save_pixel
180
        push    eax
181
        mov     ebx, eax
182
        and     eax, (128+64+32)    ; blue
183
        shr     eax, 5
184
        and     ebx, (128+64+32)*256; green
185
        shr     ebx, 8+2
186
        add     eax, ebx
187
        pop     ebx
188
        and     ebx, (128+64)*256*256; red
189
        shr     ebx, 8+8
190
        add     eax, ebx
191
     .save_pixel:
192
        stosb
193
        loop    m13pix
194
        mov     ecx, 320
195
        add     esi, 4*(640-320)
196
        dec     edx
197
        jnz     m13pix
198
        mov     [EGA_counter], 0
199
        popad
200
        ret
201
 
202
VGA_drawbackground:
203
; draw all
204
        cmp     [SCR_MODE], dword 0x12
205
        jne     .end
206
        pushad
207
        mov     esi, [LFBAddress]
208
        mov     edi, VGABasePtr
209
        mov     ebx, 640/32; 640*480/(8*4)
210
        mov     edx, 480
211
     @@:
212
        push    ebx edx esi edi
213
        shl     edx, 9
214
        lea     edx, [edx+edx*4]
215
        add     esi, edx
216
        shr     edx, 5
217
        add     edi, edx
218
        call    VGA_draw_long_line
219
        pop     edi esi edx ebx
220
        dec     edx
221
        jnz     @r
222
        call    VGA_draw_long_line_1
223
        popad
224
    .end:
225
        ret
226
 
227
VGA_draw_long_line:
228
        mov     dx, 3ceh
229
        mov     ax, 0ff08h
230
        cli
231
        out     dx, ax
232
        mov     ax, 0005h
233
        out     dx, ax
234
    m12pix:
235
        call    VGA_draw_32_pixels
236
        dec     ebx
237
        jnz     m12pix
238
        mov     dx, 3c4h
239
        mov     ax, 0ff02h
240
        out     dx, ax
241
        mov     dx, 3ceh
242
        mov     ax, 0205h
243
        out     dx, ax
244
        mov     dx, 3ceh
245
        mov     al, 08h
246
        out     dx, al
247
        sti
248
        ret
249
 
250
VGA_draw_32_pixels:
251
        xor     eax, eax
252
        mov     ebp, VGA_8_pixels
253
        mov     [ebp], eax
254
        mov     [ebp+4], eax
255
        mov     [ebp+8], eax
256
        mov     [ebp+12], eax
257
        mov     ch, 4
258
    .main_loop:
259
        mov     cl, 8
260
    .convert_pixels_to_VGA:
261
        lodsd   ; eax = 24bit colour
262
        test    eax, eax
263
        jz      .end
264
        rol     eax, 8
265
        mov     al, ch
266
        ror     eax, 8
267
        mov     ch, 1
268
        dec     cl
269
        shl     ch, cl
270
        cmp     al, 85
271
        jbe     .p13green
272
        or      [ebp], ch
273
        cmp     al, 170
274
        jbe     .p13green
275
        or      [ebp+12], ch
276
    .p13green:
277
        cmp     ah, 85
278
        jbe     .p13red
279
        or      [ebp+4], ch
280
        cmp     ah, 170
281
        jbe     .p13red
282
        or      [ebp+12], ch
283
    .p13red:
284
        shr     eax, 8
285
        cmp     ah, 85
286
        jbe     .p13cont
287
        or      [ebp+8], ch
288
        cmp     ah, 170
289
        jbe     .p13cont
290
        or      [ebp+12], ch
291
    .p13cont:
292
        ror     eax, 8
293
        mov     ch, ah
294
        inc     cl
295
    .end:
296
        dec     cl
297
        jnz     .convert_pixels_to_VGA
298
        inc     ebp
299
        dec     ch
300
        jnz     .main_loop
301
        push    esi
302
        sub     ebp, 4
303
        mov     esi, ebp
304
        mov     dx, 3c4h
305
        mov     ah, 1h
306
    @@:
307
        mov     al, 02h
308
        out     dx, ax
309
        xchg    ax, bp
310
        lodsd
311
        mov     [edi], eax
312
        xchg    ax, bp
313
        shl     ah, 1
314
        cmp     ah, 10h
315
        jnz     @r
316
        add     edi, 4
317
        pop     esi
318
        ret
319
 
320
VGA_putpixel:
321
 ; eax = x
322
 ; ebx = y
323
        mov     ecx, eax
324
        mov     eax, [esp+32-8+4] ; color
325
        shl     ebx, 9
326
        lea     ebx, [ebx+ebx*4]   ; умножение на 5
327
        lea     edx, [ebx+ecx*4]  ; + x*BytesPerPixel (Vesa2.0 32)
328
        mov     edi, edx
329
        add     edi, [LFBAddress]     ; + LFB address
330
        mov     [edi], eax        ; write to LFB for Vesa2.0
331
        shr     edx, 5            ; change BytesPerPixel to 1/8
332
        mov     edi, edx
333
        add     edi, VGABasePtr     ; address of pixel in VGA area
334
        and     ecx, 0x07         ; bit no. (modulo 8)
335
        pushfd
336
        ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8)
337
        xor     edx, edx
338
        test    eax, eax
339
        jz      .p13cont
340
        cmp     al, 85
341
        jbe     .p13green
342
        or      dl, 0x01
343
        cmp     al, 170
344
        jbe     .p13green
345
        or      dl, 0x08
346
.p13green:
347
        cmp     ah, 85
348
        jbe     .p13red
349
        or      dl, 0x02
350
        cmp     ah, 170
351
        jbe     .p13red
352
        or      dl, 0x08
353
.p13red:
354
        shr     eax, 8
355
        cmp     ah, 85
356
        jbe     .p13cont
357
        or      dl, 0x04
358
        cmp     ah, 170
359
        jbe     .p13cont
360
        or      dl, 0x08
361
.p13cont:
362
        ror     edx, 8
363
        inc     cl
364
        xor     eax, eax
365
        inc     ah
366
        shr     ax, cl
367
        mov     dx, 3cfh
368
        cli
369
        out     dx, al
370
        mov     al, [edi]         ; dummy read
371
        rol     edx, 8
372
        mov     [edi], dl
373
        popfd
374
;.end:
375
        ret
376
 
377
VGA__putimage:
378
; ecx = size [x|y]
379
; edx = coordinates [x|y]
380
        cmp     [SCR_MODE], dword 0x12
381
        jne     @f
382
        pushad
383
        rol     edx, 16
384
        movzx   eax, dx
385
        rol     edx, 16
386
        movzx   ebx, dx
387
        movzx   edx, cx
388
        rol     ecx, 16
389
        movzx   ecx, cx
390
        call    VGA_draw_bar_1
391
        popad
392
@@:
393
        ret
394
 
395
VGA_draw_bar:
396
; eax   cx
397
; ebx   cy
398
; ecx   xe
399
; edx   ye
400
        cmp     [SCR_MODE], dword 0x12
401
        jne     @f
402
        pushad
403
        sub     ecx, eax
404
        sub     edx, ebx
405
        and     eax, 0xffff
406
        and     ebx, 0xffff
407
        and     ecx, 0xffff
408
        and     edx, 0xffff
409
        call    VGA_draw_bar_1
410
        popad
411
@@:
412
        ret
413
 
414
VGA_draw_bar_1:
415
        mov     [temp.cx], eax
416
        mov     eax, [TASK_BASE]
417
        add     ebx, [eax-twdw + 4]
418
        mov     eax, [eax-twdw + 0]
419
        add     eax, [temp.cx]
420
        and     eax, 0xfff8
421
        shl     ebx, 9
422
        lea     ebx, [ebx+ebx*4]; умножение на 5
423
        lea     ebx, [ebx+eax*4]  ; + x*BytesPerPixel (Vesa2.0 32)
424
        mov     esi, ebx
425
        add     esi, [LFBAddress]     ; + LFB address
426
        shr     ebx, 5            ; change BytesPerPixel to 1/8
427
        mov     edi, ebx
428
        add     edi, VGABasePtr   ; address of pixel in VGA area
429
        mov     ebx, ecx
430
        shr     ebx, 5
431
        inc     ebx
432
.main_loop:
433
        call    VGA_draw_long_line_1
434
        dec     edx
435
        jnz     .main_loop
436
        call    VGA_draw_long_line_1
437
        ret
438
 
439
VGA_draw_long_line_1:
440
        push    ebx edx esi edi
441
        shl     edx, 9
442
        lea     edx, [edx+edx*4]
443
        add     esi, edx
444
        shr     edx, 5
445
        add     edi, edx
446
        call    VGA_draw_long_line
447
        pop     edi esi edx ebx
448
        ret
449