Subversion Repositories Kolibri OS

Rev

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

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