Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
593 mikedld 14
$Revision: 2434 $
1 ha 15
 
16
 
17
paletteVGA:
18
 
19
;16 colour palette
2434 Serge 20
        mov     dx, 0x3c8
21
        mov     al, 0
22
        out     dx, al
1 ha 23
 
2434 Serge 24
        mov     ecx, 16
25
        mov     dx, 0x3c9
26
        xor     eax, eax
1 ha 27
 
28
     palvganew:
29
 
2434 Serge 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
1 ha 37
     palvgalbl1:
2434 Serge 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
1 ha 46
     palvgalbl2:
2434 Serge 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
1 ha 55
     palvgalbl3:
2434 Serge 56
        out     dx, al; green 0,31 or 63
57
        add     ah, 1
58
        loop    palvganew
117 mario79 59
;       mov    dx, 3ceh
379 serge 60
;       mov    ax, 0005h
61
;       out    dx, ax
2434 Serge 62
        ret
1 ha 63
 
117 mario79 64
palette320x200:
1 ha 65
 
2434 Serge 66
        mov     edx, 0x3c8
67
        xor     eax, eax
68
        out     dx, al
69
        mov     ecx, 256
70
        mov     edx, 0x3c9
71
        xor     eax, eax
1 ha 72
 
117 mario79 73
     palnew:
2434 Serge 74
        mov     al, 0
75
        test    ah, 64
76
        jz      pallbl1
77
        add     al, 21
117 mario79 78
     pallbl1:
2434 Serge 79
        test    ah, 128
80
        jz      pallbl2
81
        add     al, 42
117 mario79 82
     pallbl2:
2434 Serge 83
        out     dx, al
84
        mov     al, 0
85
        test    ah, 8
86
        jz      pallbl3
87
        add     al, 8
117 mario79 88
     pallbl3:
2434 Serge 89
        test    ah, 16
90
        jz      pallbl4
91
        add     al, 15
117 mario79 92
     pallbl4:
2434 Serge 93
        test    ah, 32
94
        jz      pallbl5
95
        add     al, 40
117 mario79 96
     pallbl5:
2434 Serge 97
        out     dx, al
98
        mov     al, 0
99
        test    ah, 1
100
        jz      pallbl6
101
        add     al, 8
117 mario79 102
     pallbl6:
2434 Serge 103
        test    ah, 2
104
        jz      pallbl7
105
        add     al, 15
117 mario79 106
     pallbl7:
2434 Serge 107
        test    ah, 4
108
        jz      pallbl8
109
        add     al, 40
117 mario79 110
     pallbl8:
2434 Serge 111
        out     dx, al
112
        add     ah, 1
113
        loop    palnew
1 ha 114
 
2434 Serge 115
        ret
1168 Lrz 116
align 4
117 mario79 117
uglobal
118
  novesachecksum dd 0x0
119
  EGA_counter    db  0
120
  VGA_drawing_screen db 0
379 serge 121
  VGA_8_pixels:
117 mario79 122
     rb 16
123
  temp:
124
     .cx dd 0
125
endg
1168 Lrz 126
align 4
117 mario79 127
checkVga_N13:
1 ha 128
 
2434 Serge 129
        cmp     [SCR_MODE], dword 0x13
130
        jne     @f
1 ha 131
 
117 mario79 132
;      cnvl:
133
        pushad
2434 Serge 134
        cmp     [EGA_counter], 1
135
        je      novesal
136
        mov     ecx, [MOUSE_X]
137
        cmp     ecx, [novesachecksum]
138
        jne     novesal
117 mario79 139
        popad
140
      @@:
141
        ret
1 ha 142
 
117 mario79 143
      novesal:
2434 Serge 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
117 mario79 150
      m13l3:
2434 Serge 151
        cmp     eax, 480-100
152
        jbe     m13l4
153
        mov     eax, 480-100
117 mario79 154
      m13l4:
2434 Serge 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
117 mario79 162
      m13l1:
2434 Serge 163
        cmp     eax, 640-160
164
        jbe     m13l2
165
        mov     eax, 640-160
117 mario79 166
      m13l2:
2434 Serge 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
117 mario79 175
        cld
176
     m13pix:
177
        lodsd
2434 Serge 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
117 mario79 191
     .save_pixel:
192
        stosb
2434 Serge 193
        loop    m13pix
194
        mov     ecx, 320
195
        add     esi, 4*(640-320)
196
        dec     edx
197
        jnz     m13pix
198
        mov     [EGA_counter], 0
117 mario79 199
        popad
200
        ret
1 ha 201
 
119 mario79 202
VGA_drawbackground:
379 serge 203
; draw all
2434 Serge 204
        cmp     [SCR_MODE], dword 0x12
119 mario79 205
        jne     .end
117 mario79 206
        pushad
2434 Serge 207
        mov     esi, [LFBAddress]
208
        mov     edi, VGABasePtr
209
        mov     ebx, 640/32; 640*480/(8*4)
210
        mov     edx, 480
117 mario79 211
     @@:
2434 Serge 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
117 mario79 223
        popad
119 mario79 224
    .end:
117 mario79 225
        ret
1 ha 226
 
117 mario79 227
VGA_draw_long_line:
2434 Serge 228
        mov     dx, 3ceh
229
        mov     ax, 0ff08h
117 mario79 230
        cli
2434 Serge 231
        out     dx, ax
232
        mov     ax, 0005h
233
        out     dx, ax
117 mario79 234
    m12pix:
2434 Serge 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
117 mario79 247
        sti
248
        ret
1 ha 249
 
117 mario79 250
VGA_draw_32_pixels:
2434 Serge 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
117 mario79 258
    .main_loop:
2434 Serge 259
        mov     cl, 8
117 mario79 260
    .convert_pixels_to_VGA:
261
        lodsd   ; eax = 24bit colour
2434 Serge 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
119 mario79 271
        jbe     .p13green
2434 Serge 272
        or      [ebp], ch
273
        cmp     al, 170
119 mario79 274
        jbe     .p13green
2434 Serge 275
        or      [ebp+12], ch
117 mario79 276
    .p13green:
2434 Serge 277
        cmp     ah, 85
119 mario79 278
        jbe     .p13red
2434 Serge 279
        or      [ebp+4], ch
280
        cmp     ah, 170
119 mario79 281
        jbe     .p13red
2434 Serge 282
        or      [ebp+12], ch
117 mario79 283
    .p13red:
2434 Serge 284
        shr     eax, 8
285
        cmp     ah, 85
119 mario79 286
        jbe     .p13cont
2434 Serge 287
        or      [ebp+8], ch
288
        cmp     ah, 170
119 mario79 289
        jbe     .p13cont
2434 Serge 290
        or      [ebp+12], ch
117 mario79 291
    .p13cont:
2434 Serge 292
        ror     eax, 8
293
        mov     ch, ah
294
        inc     cl
117 mario79 295
    .end:
2434 Serge 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
117 mario79 306
    @@:
2434 Serge 307
        mov     al, 02h
308
        out     dx, ax
309
        xchg    ax, bp
117 mario79 310
        lodsd
2434 Serge 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
117 mario79 318
        ret
1 ha 319
 
320
VGA_putpixel:
321
 ; eax = x
322
 ; ebx = y
2434 Serge 323
        mov     ecx, eax
117 mario79 324
        mov     eax, [esp+32-8+4] ; color
2434 Serge 325
        shl     ebx, 9
326
        lea     ebx, [ebx+ebx*4]   ; умножение на 5
117 mario79 327
        lea     edx, [ebx+ecx*4]  ; + x*BytesPerPixel (Vesa2.0 32)
2434 Serge 328
        mov     edi, edx
381 serge 329
        add     edi, [LFBAddress]     ; + LFB address
117 mario79 330
        mov     [edi], eax        ; write to LFB for Vesa2.0
2434 Serge 331
        shr     edx, 5            ; change BytesPerPixel to 1/8
332
        mov     edi, edx
381 serge 333
        add     edi, VGABasePtr     ; address of pixel in VGA area
2434 Serge 334
        and     ecx, 0x07         ; bit no. (modulo 8)
117 mario79 335
        pushfd
336
        ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8)
2434 Serge 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
117 mario79 346
.p13green:
2434 Serge 347
        cmp     ah, 85
348
        jbe     .p13red
349
        or      dl, 0x02
350
        cmp     ah, 170
351
        jbe     .p13red
352
        or      dl, 0x08
379 serge 353
.p13red:
2434 Serge 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
117 mario79 361
.p13cont:
2434 Serge 362
        ror     edx, 8
363
        inc     cl
364
        xor     eax, eax
365
        inc     ah
366
        shr     ax, cl
367
        mov     dx, 3cfh
117 mario79 368
        cli
2434 Serge 369
        out     dx, al
370
        mov     al, [edi]         ; dummy read
371
        rol     edx, 8
372
        mov     [edi], dl
117 mario79 373
        popfd
374
;.end:
375
        ret
379 serge 376
 
117 mario79 377
VGA__putimage:
378
; ecx = size [x|y]
379
; edx = coordinates [x|y]
2434 Serge 380
        cmp     [SCR_MODE], dword 0x12
117 mario79 381
        jne     @f
2434 Serge 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
117 mario79 392
@@:
2434 Serge 393
        ret
1 ha 394
 
117 mario79 395
VGA_draw_bar:
396
; eax   cx
397
; ebx   cy
398
; ecx   xe
399
; edx   ye
2434 Serge 400
        cmp     [SCR_MODE], dword 0x12
117 mario79 401
        jne     @f
2434 Serge 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
117 mario79 411
@@:
2434 Serge 412
        ret
1 ha 413
 
117 mario79 414
VGA_draw_bar_1:
2434 Serge 415
        mov     [temp.cx], eax
379 serge 416
        mov     eax, [TASK_BASE]
117 mario79 417
        add     ebx, [eax-twdw + 4]
418
        mov     eax, [eax-twdw + 0]
419
        add     eax, [temp.cx]
2434 Serge 420
        and     eax, 0xfff8
421
        shl     ebx, 9
422
        lea     ebx, [ebx+ebx*4]; умножение на 5
117 mario79 423
        lea     ebx, [ebx+eax*4]  ; + x*BytesPerPixel (Vesa2.0 32)
2434 Serge 424
        mov     esi, ebx
381 serge 425
        add     esi, [LFBAddress]     ; + LFB address
2434 Serge 426
        shr     ebx, 5            ; change BytesPerPixel to 1/8
427
        mov     edi, ebx
381 serge 428
        add     edi, VGABasePtr   ; address of pixel in VGA area
2434 Serge 429
        mov     ebx, ecx
430
        shr     ebx, 5
117 mario79 431
        inc     ebx
432
.main_loop:
2434 Serge 433
        call    VGA_draw_long_line_1
434
        dec     edx
435
        jnz     .main_loop
436
        call    VGA_draw_long_line_1
117 mario79 437
        ret
1 ha 438
 
117 mario79 439
VGA_draw_long_line_1:
2434 Serge 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
117 mario79 448
        ret
1 ha 449