Subversion Repositories Kolibri OS

Rev

Rev 9941 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
9606 Doczom 3
;; Copyright (C) KolibriOS team 2004-2022. 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: 9977 $
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
9977 rgimad 171
        xor     ecx, ecx
2288 clevermous 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
9715 Doczom 253
        lea     edx, [edx + edx*4]
2288 clevermous 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
9715 Doczom 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
2448 mario79 385
        jne     .no_mouseunder
386
;--------------------------------------
387
align 4
2436 mario79 388
        push    ecx
389
        shl     ecx, 16
390
        mov     cx, bx
391
; check mouse area for putpixel
392
        test    eax, 0x04000000
393
        jnz     @f
9941 Doczom 394
 
2436 mario79 395
        call    [_display.check_mouse]
396
;--------------------------------------
397
align 4
398
@@:
399
        pop     ecx
2448 mario79 400
;--------------------------------------
401
align 4
402
.no_mouseunder:
2288 clevermous 403
        shl     ebx, 9
9715 Doczom 404
        lea     ebx, [ebx + ebx*4]  ; multiply by 5
405
        lea     edx, [ebx + ecx*4]  ; + x*BytesPerPixel (Vesa2.0 32)
2288 clevermous 406
        mov     edi, edx
8053 rgimad 407
        add     edi, [LFBAddress] ; + LFB address
2288 clevermous 408
        mov     [edi], eax        ; write to LFB for Vesa2.0
409
        shr     edx, 5            ; change BytesPerPixel to 1/8
410
        mov     edi, edx
8053 rgimad 411
        add     edi, VGABasePtr   ; address of pixel in VGA area
2288 clevermous 412
        and     ecx, 0x07         ; bit no. (modulo 8)
413
        pushfd
414
        ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8)
415
        xor     edx, edx
416
        test    eax, eax
417
        jz      .p13cont
418
        cmp     al, 85
419
        jbe     .p13green
420
        or      dl, 0x01
421
        cmp     al, 170
422
        jbe     .p13green
423
        or      dl, 0x08
2436 mario79 424
;--------------------------------------
425
align 4
2288 clevermous 426
.p13green:
427
        cmp     ah, 85
428
        jbe     .p13red
429
        or      dl, 0x02
430
        cmp     ah, 170
431
        jbe     .p13red
432
        or      dl, 0x08
2436 mario79 433
;--------------------------------------
434
align 4
2288 clevermous 435
.p13red:
436
        shr     eax, 8
437
        cmp     ah, 85
438
        jbe     .p13cont
439
        or      dl, 0x04
440
        cmp     ah, 170
441
        jbe     .p13cont
442
        or      dl, 0x08
2436 mario79 443
;--------------------------------------
444
align 4
2288 clevermous 445
.p13cont:
446
        ror     edx, 8
447
        inc     cl
448
        xor     eax, eax
449
        inc     ah
450
        shr     ax, cl
451
        mov     dx, 3cfh
452
        cli
453
        out     dx, al
454
        mov     al, [edi]         ; dummy read
455
        rol     edx, 8
456
        mov     [edi], dl
457
        popfd
458
        ret
2436 mario79 459
;------------------------------------------------------------------------------
460
align 4
2288 clevermous 461
VGA__putimage:
462
; ecx = size [x|y]
463
; edx = coordinates [x|y]
464
        pushad
465
        rol     edx, 16
466
        movzx   eax, dx
467
        rol     edx, 16
468
        movzx   ebx, dx
469
        movzx   edx, cx
470
        rol     ecx, 16
471
        movzx   ecx, cx
472
        call    VGA_draw_bar_1
473
        popad
474
        ret
2436 mario79 475
;------------------------------------------------------------------------------
476
align 4
2288 clevermous 477
VGA_draw_bar:
478
; eax   cx
479
; ebx   cy
480
; ecx   xe
481
; edx   ye
482
        pushad
483
        sub     ecx, eax
484
        sub     edx, ebx
485
        and     eax, 0xffff
486
        and     ebx, 0xffff
487
        and     ecx, 0xffff
488
        and     edx, 0xffff
489
        call    VGA_draw_bar_1
490
        popad
491
        ret
2436 mario79 492
;------------------------------------------------------------------------------
493
align 4
2288 clevermous 494
VGA_draw_bar_1:
495
        mov     [temp.cx], eax
9941 Doczom 496
        mov     eax, [current_slot]
497
        mov     eax, [eax + APPDATA.window]
498
        add     ebx, [eax + WDATA.box.top]
499
        mov     eax, [eax + WDATA.box.left]
2288 clevermous 500
        add     eax, [temp.cx]
501
        and     eax, 0xfff8
502
        shl     ebx, 9
9715 Doczom 503
        lea     ebx, [ebx + ebx*4]  ; multiply by 5
504
        lea     ebx, [ebx + eax*4]  ; + x*BytesPerPixel (Vesa2.0 32)
2288 clevermous 505
        mov     esi, ebx
8053 rgimad 506
        add     esi, [LFBAddress] ; + LFB address
2288 clevermous 507
        shr     ebx, 5            ; change BytesPerPixel to 1/8
508
        mov     edi, ebx
509
        add     edi, VGABasePtr   ; address of pixel in VGA area
510
        mov     ebx, ecx
511
        shr     ebx, 5
512
        inc     ebx
2436 mario79 513
;--------------------------------------
514
align 4
2288 clevermous 515
.main_loop:
516
        call    VGA_draw_long_line_1
517
        dec     edx
518
        jnz     .main_loop
519
        call    VGA_draw_long_line_1
520
        ret
2436 mario79 521
;------------------------------------------------------------------------------
522
align 4
2288 clevermous 523
VGA_draw_long_line_1:
524
        push    ebx edx esi edi
525
        shl     edx, 9
9715 Doczom 526
        lea     edx, [edx + edx*4]
2288 clevermous 527
        add     esi, edx
528
        shr     edx, 5
529
        add     edi, edx
530
        call    VGA_draw_long_line
531
        pop     edi esi edx ebx
532
        ret
2436 mario79 533
;------------------------------------------------------------------------------