Subversion Repositories Kolibri OS

Rev

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

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