Subversion Repositories Kolibri OS

Rev

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

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