Subversion Repositories Kolibri OS

Rev

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

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