Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
129 mikedld 1
;
2
;   MenuetOS Driver (vmode.mdr)
3
;   Target: Vertical Refresh Rate programming and videomode changing
4
;
5
;   Author: Trans <<<<<13>>>>>
6
;   Date:   20.07.2003
7
;
8
;   Version: 1.0
9
;   OS: MenuetOS
10
;   Compiler: FASM
11
;
12
use32
13
 
14
__DEBUG__ = 1
15
 
16
;macro align value { rb (value-1) - ($ + value-1) mod value }
17
macro func name {
18
 if used name
19
  align 4
20
  name@of@func equ name
21
;  _numb `name,name
22
}
23
macro begin {
24
 align 4
25
 name@of@func:
26
}
27
endf fix end if
28
macro return _val {
29
 if ~_val eq eax
30
  mov  eax,_val
31
 end if
32
 ret
33
}
34
macro comment symb { ;s
35
 if 0=1
36
}
37
^ fix end if
38
 
39
include 'struct.inc'
40
 
41
B_HOST fix HOST_BENDIAN ; HOST_LENDIAN
42
 
43
;-----------------------------------------------------------------------------
44
 
384 mikedld 45
	org    0x760000
129 mikedld 46
 
47
headerstart=$
48
 
384 mikedld 49
mdid	db     'MDAZ'		   ; 4 byte id
50
mdhver	dd     0x00		   ; header version
51
mdcode	dd     MDSTART		   ; start of code
52
mdver	dd     0x00000001	   ; driver version (subversion*65536+version)
53
mdname	db     'Trans VideoDriver' ; 32 bytes of full driver name
129 mikedld 54
    times (32-($-mdname)) db ' '   ;
55
 
56
headerlen=$-headerstart
384 mikedld 57
    times (256-headerlen) db 0	   ; reserved area for future
129 mikedld 58
 
59
MDSTART:    ; start of driver code ( base_adr+256 bytes)
60
; ebx(=ecx in program):
61
;   1 - Get DriverInfo and Driver Initial Set
62
;   2 - Get Current Video Mode With Vertical Refresh Rate
63
;   3 - Change Video Mode
64
;   4 - Return at Start System Video Mode
65
;   5 - Change vertical and horizontal size of visible screen area
66
;   6 - Change Vert/Hor position visible area on screen (not complete yet)
67
;
68
;   MAXF - ...
69
MAXF=7
70
 
71
;-------Main Manager-------------
72
    pushad
73
    cmp ebx,1
74
    jb mdvm_00
75
    cmp ebx,MAXF
76
    ja mdvm_00
77
    call dword [mdvm_func_table+ebx*4]
78
    mov [esp+28],eax
79
    mov [esp+24],ecx
80
    mov [esp+20],edx
81
    mov [esp+16],ebx
82
    popad
83
    retn
84
mdvm_00:
85
    popad
86
    xor eax,eax
87
    dec eax
88
    retn
89
 
90
; ------Drivers Functions----------
91
 
92
; EBX=1 (in applications ECX=1)- Get DriverInfo and Driver Initial Set
93
;
94
; IN: ecx (in app. edx) - pointer to 512-bytes info area in application
95
; OUT:
96
;
97
func vm_info_init
98
begin
99
      push ecx
100
      cmp [mdrvm],dword 0
101
      jnz .vmii_00
102
      call vm_safe_reg
103
      call vm_get_initial_videomode
104
      mov eax,[initvm]
105
      mov [currvm],eax
106
;     call vm_search_sys_func_table
107
      call vm_get_cur_vert_rate
108
      mov [initrr],eax
109
      call vm_calc_pixelclock
110
      call vm_calc_refrate
111
      inc [mdrvm]
112
.vmii_00:
113
      pop ecx
114
      call vm_transfer_drv_info
115
      mov ebx,dword [refrate]
384 mikedld 116
      mov eax,dword [mdid]	;dword [systlb]
129 mikedld 117
      retn
118
endf
119
 
120
; EBX=2 (in applications ECX=2)- Get Current Video Mode
121
;
122
; OUT: eax = X_screen*65536+Y_screen
123
;      ebx = current vertical rate
124
;      ecx = current video mode (number)
125
func vm_get_cur_mode
126
begin
127
      cmp [mdrvm],dword 0
128
      jz .vmgcm_00
129
      call vm_get_cur_vert_rate
130
      mov eax,[0FE00h]
131
      mov ebx,[0FE04h]
132
      shl eax,16
133
      add eax,ebx
134
      add eax,00010001h
135
      mov ebx,[refrate]
136
      mov ecx,[currvm]
137
      retn
138
.vmgcm_00:
139
      xor eax,eax
140
      dec eax
141
      retn
142
endf
143
 
144
; EBX=3 (in applications ECX=3)- Change Video Mode
145
;
146
; IN:  ecx = VertRate*65536+VideoMode
147
; OUT: eax = 0 if no error
148
;
149
func vm_set_video_mode
150
begin
151
      cmp [mdrvm],dword 0
152
      jz .vmsvm_00
153
      call vm_set_selected_mode
154
;      xor eax,eax
155
      retn
156
.vmsvm_00:
157
      xor eax,eax
158
      dec eax
159
      retn
160
endf
161
 
162
; EBX=4 (in applications ECX=4)- Return at Start System Video Mode
163
;
164
; IN:
165
; OUT: eax = = 0 if no error
166
;
167
func vm_restore_init_video_mode
168
begin
169
      cmp [mdrvm],dword 0
170
      jz .vmrivm_00
171
      call vm_restore_reg
172
      xor eax,eax
173
      retn
174
.vmrivm_00:
175
      xor eax,eax
176
      dec eax
177
      retn
178
endf
179
 
180
; EBX=5 (in applications ECX=5)- Change vertical and horizontal size
181
;                                 of visible screen area
182
; IN:  ecx (in app. edx) = 0/1 - -/+ horizontal size on 1 position
183
;                        = 2/3 - -/+ vertical size on 1 position (8 pixels)
184
;                          ^-^----- not complete yet
185
; OUT: eax = = 0 if no error
186
;
187
func vm_change_screen_size
188
begin
189
      cmp [mdrvm],dword 0
190
      jz .vmcss_00
191
      cmp cl,1
192
      ja .vmcss_01
193
      mov eax,ecx
194
      call vm_inc_dec_width
195
      xor eax,eax
196
      retn
197
.vmcss_01:
198
      and ecx,01h
199
      mov eax,ecx
200
;     call vm_inc_dec_high   ; not complete yet
201
      xor eax,eax
202
      retn
203
.vmcss_00:
204
      xor eax,eax
205
      dec eax
206
      retn
207
endf
208
 
209
; EBX=6 (in applications ECX=6)- Change Vert/Hor position visible area on screen
210
;
211
; IN:  ecx (in app. edx) = 0/1 - -/+ horizontal position on 1 point
212
;                        = 2/3 - -/+ vertical position on 1 pixel
213
;                          ^-^----- not complete yet
214
; OUT: eax = 0 if no error
215
;
216
func vm_change_position_screen
217
begin
218
      cmp [mdrvm],dword 0
219
      jz .vmcps_00
220
  ; ...
221
      xor eax,eax
222
      retn
223
.vmcps_00:
224
      xor eax,eax
225
      dec eax
226
      retn
227
endf
228
 
229
;-----Drivers Subfunctions---------
230
 
231
;
232
; Searching i40 system functions pointer table in kernel area location
233
;
234
func vm_search_sys_func_table
235
begin
384 mikedld 236
      push eax	   ; eax - current value
237
      push ecx	   ; ecx - will be counter of equevalent value
238
      push edx	   ; edx - last value
239
      push esi	   ; esi - current address
129 mikedld 240
      xor ecx,ecx
384 mikedld 241
      mov esi,010000h		 ; Start address of kernel location
129 mikedld 242
      lodsd
243
      mov edx,eax
244
      cld
245
.vmssft_00:
246
      cmp esi,30000h
247
      ja .vmssft_03
248
      inc ecx
249
      lodsd
250
      cmp edx,eax
251
      mov edx,eax
252
      je .vmssft_00
253
      cmp ecx,128
254
      ja .vmssft_02
255
.vmssft_01:
256
      xor ecx,ecx
257
      jmp .vmssft_00
258
.vmssft_02:
259
      cmp edx,0
260
      je .vmssft_01
261
      sub esi,256*4-1
262
      mov [systlb],esi
263
      xor ecx,ecx
264
.vmssft_03_0:
265
      inc ecx
266
      lodsd
267
      cmp edx,eax
268
      mov edx,eax
269
      jne .vmssft_03_0
270
      mov esi,dword [systlb]
271
      cmp cx,60
272
      jae .vmssft_03
273
      add esi,256*4-4
274
      lodsb
275
      mov edx,eax
276
      jmp .vmssft_01
277
.vmssft_03:
278
      mov [systlb],esi
279
      pop esi
280
      pop edx
281
      pop ecx
282
      pop eax
283
      retn
284
endf
285
 
286
; IN:
287
; OUT: eax= vertical rate in Hz
288
func vm_get_cur_vert_rate
289
begin
290
      push edx
291
      push ebx
292
      xor eax,eax
293
      mov edx,eax
294
      mov ebx,eax
295
      mov dx,03DAh
296
.vmgcvt_00:
297
      in al,dx
298
      test al,8
299
      jz .vmgcvt_00
300
.vmgcvt_01:
301
      in al,dx
302
      test al,8
303
      jnz .vmgcvt_01
304
      mov ebx,edx
305
      rdtsc
306
      mov edx,ebx
307
      mov ebx,eax
308
.vmgcvt_02:
309
      in al,dx
310
      test al,8
311
      jz .vmgcvt_02
312
.vmgcvt_03:
313
      in al,dx
314
      test al,8
315
      jnz .vmgcvt_03
316
      rdtsc
317
      sub eax,ebx
318
      mov ebx,eax
319
      mov eax,[0F600h]
320
      xor edx,edx
321
      div ebx
322
      inc eax
323
      mov [refrate],eax
324
      pop ebx
325
      pop edx
326
      retn
327
endf
328
 
329
func vm_calc_pixelclock
330
begin
384 mikedld 331
	push ebx
332
	push edx
333
	xor eax,eax
334
	mov al,[_00]
335
	add ax,5
336
	shl eax,3
337
	xor ebx,ebx
338
	mov bl,[_06]
339
	mov bh,[_07]
340
	and bh,00100001b
341
	btr bx,13
342
	jnc .vmcpc_00
343
	or bh,2
129 mikedld 344
.vmcpc_00:
384 mikedld 345
	xor edx,edx
346
	mul ebx
347
	xor edx,edx
348
	mul [initrr]
349
	mov [pclock],eax
350
	pop edx
351
	pop ebx
352
	retn
129 mikedld 353
endf
354
 
355
;
356
; Safe of initial CRTC state
357
;
358
func vm_safe_reg
359
begin
360
    push edx
361
    push ebx
362
    push ecx
363
    push edi
364
    cli
365
    mov dx,3d4h  ; CRTC
366
    mov al,11h
367
    out dx,al
368
    inc dx
369
    in al,dx
370
    and al,7fh
384 mikedld 371
    out dx,al	 ; Clear protection bit
129 mikedld 372
    dec dx
373
    xor ecx,ecx
374
    mov cl,19h
375
    xor bl,bl
376
    mov edi,CRTCreg
377
.vmsr_00:
378
    mov al,bl
379
    out dx,al
380
    inc dx
381
    in al,dx
382
    dec dx
383
    stosb
384
    inc bl
385
    loop .vmsr_00
386
    sti
387
    pop edi
388
    pop ecx
389
    pop ebx
390
    pop edx
391
    retn
392
endf
393
 
394
;
395
; Restore of initial CRTC state
396
;
397
func vm_restore_reg
398
begin
399
    push eax
400
    push ebx
401
    push edx
402
    push esi
403
    mov eax,[oldX]
404
    mov [0FE00h],eax
405
    mov eax,[oldY]
406
    mov [0FE04h],eax
407
    mov dx,03dah
408
.vmrr_00:
409
    in al,dx
410
    test al,8
411
    jnz .vmrr_00
412
.vmrr_01:
413
    in al,dx
414
    test al,8
415
    jnz .vmrr_01
416
    cli
417
    mov dx,03c4h
418
    mov ax,0101h
419
    out dx,ax
420
    mov dx,3d4h  ; CRTC
421
    mov al,11h
422
    out dx,al
423
    inc dx
424
    in al,dx
384 mikedld 425
    and al,7fh	; Clear Protection bit
129 mikedld 426
    out dx,al
427
    dec dx
428
    xor ecx,ecx
429
    mov cl,19h
430
    mov esi,CRTCreg
431
    xor bl,bl
432
.vmrr_02:
433
    lodsb
434
    mov ah,al
435
    mov al,bl
436
    out dx,ax
437
    inc bl
438
    loop .vmrr_02
439
    sti
440
;    call ref_screen
441
    pop esi
442
    pop edx
443
    pop ecx
444
    pop eax
445
    retn
446
endf
447
 
448
; Calculate of possible vertical refrash rate
449
;  (light version of function)
450
func vm_calc_refrate
451
begin
384 mikedld 452
	push ebx
453
	push ecx
454
	push edx
455
	push edi
456
	push esi
457
	mov eax,[pclock]
458
	xor edx,edx
459
	mov edi,_m1
460
	mov ebx,eax
461
	mov ecx,(1696*1065)
462
	div ecx
463
	xor edx,edx
464
	stosw
465
	add edi,8
466
	mov eax,ebx
467
	mov ecx,(1344*804)
468
	div ecx
469
	xor edx,edx
470
	stosw
471
	add edi,8
472
	mov eax,ebx
473
	mov ecx,(1056*636)
474
	div ecx
475
	xor edx,edx
476
	stosw
477
	add edi,8
478
	mov eax,ebx
479
	mov ecx,(800*524)
480
	div ecx
481
	xor edx,edx
482
	stosw
483
	mov edi,_m1
484
	mov esi,edi
485
	mov ecx,5*4
129 mikedld 486
.vmcrr_00:
384 mikedld 487
	lodsw
488
	cmp ax,55
489
	jb .vmcrr_01
490
	stosw
491
	loop .vmcrr_00
492
	pop esi
493
	pop edi
494
	pop edx
495
	pop ecx
496
	pop ebx
497
	retn
129 mikedld 498
.vmcrr_01:
384 mikedld 499
	xor ax,ax
500
	stosw
501
	loop .vmcrr_00
502
	pop esi
503
	pop edi
504
	pop edx
505
	pop ecx
506
	pop ebx
507
	retn
129 mikedld 508
endf
509
 
510
func vm_get_initial_videomode
511
begin
512
    push eax
513
    mov eax,dword [0FE00h]
514
    mov [oldX],eax
515
    mov eax,dword [0FE04h]
516
    mov [oldY],eax
517
    mov eax,dword [0FE0Ch] ; initial video mode
518
    and ax,01FFh
519
    mov dword [initvm],eax
520
    pop eax
521
    retn
522
endf
523
 
524
; IN: eax = 0/1  -  -/+ 1 position of width
525
func vm_inc_dec_width
526
begin
527
    push ebx
528
    push edx
529
    mov ebx,eax
530
    mov dx,3d4h  ; CRTC
531
    mov al,11h
532
    out dx,al
533
    inc dx
534
    in al,dx
384 mikedld 535
    and al,7fh	; Clear Protection bit
129 mikedld 536
    out dx,al
537
    dec dx
538
    xor al,al
539
    out dx,al
540
    inc dx
541
    in al,dx
542
    dec al
543
    cmp bl,0
544
    jnz .vmidr_00
545
    inc al
546
    inc al
547
.vmidr_00:
548
    out dx,al
549
    pop edx
550
    pop ebx
551
    retn
552
endf
553
 
554
;
555
; Copy driver info to application area
556
;
557
; IN: ecx (in app. edx) - pointer to 512-bytes info area in application
558
; OUT:
559
func vm_transfer_drv_info
560
begin
384 mikedld 561
	push ecx
562
	push edi
563
	push esi
564
	mov eax,ecx
565
	xor ecx,ecx
566
	mov cl,32/4
567
	mov esi,mdname
568
	mov edi,drvname
569
	rep movsd
570
	mov ecx,eax
571
	mov eax,[mdver]
572
	mov [drvver],eax
573
	mov edi,[3010h]
574
	mov edi,[edi+10h]
575
	add edi,ecx
576
	mov esi,drvinfo
577
	xor ecx,ecx
578
	mov cx,512
579
	rep movsb
580
	pop esi
581
	pop edi
582
	pop ecx
583
	retn
129 mikedld 584
endf
585
 
586
;
587
; Set selected video mode
588
; (light version)
589
;
590
; IN: ecx = VertRate*65536+VideoMode
591
;
592
func vm_set_selected_mode
593
begin
594
    push edx
595
    push ecx
596
    push esi
597
    ror ecx,16
598
    cmp cx,00h
599
    je .vmssm_03
600
    rol ecx,16
601
    mov eax,ecx
602
    shl eax,16
603
    shr eax,16
604
    mov [currvm],eax
605
    cmp cx,112h
606
    jne .vmssm_00
607
    mov esi,mode0
608
    mov ecx,639
609
    mov edx,479
610
    jmp .vmssm_st00
611
.vmssm_00:
612
    cmp cx,115h
613
    jne .vmssm_01
614
    mov esi,mode1
615
    mov ecx,799
616
    mov edx,599
617
    jmp .vmssm_st00
618
.vmssm_01:
619
    cmp cx,118h
620
    jne .vmssm_02
621
    mov esi,mode2
622
    mov ecx,1023
623
    mov edx,767
624
    jmp .vmssm_st00
625
.vmssm_02:
626
    cmp cx,11Bh
627
    jne .vmssm_03
628
    mov esi,mode2
629
    mov ecx,1279
630
    mov edx,1023
631
    jmp .vmssm_st00
632
.vmssm_03:
633
    xor eax,eax
634
    dec eax
635
    pop esi
636
    pop ecx
637
    pop edx
638
    retn
639
.vmssm_st00:
640
    mov [0FE00h],ecx
641
    mov [0FE04h],edx
642
    cli
643
    mov dx,03c4h
644
    lodsw
645
    out dx,ax
646
    mov dx,03d4h
647
    mov al,11h
648
    out dx,al
649
    inc dx
650
    in al,dx
651
    and al,7fh
652
    out dx,al
653
    dec dx
654
    mov ecx,13
655
.vmssm_st01:
656
    lodsw
657
    out dx,ax
658
    loop .vmssm_st01
659
    sti
660
    xor eax,eax
661
    pop esi
662
    pop ecx
663
    pop edx
664
    retn
665
endf
666
 
667
;-[ mike.dld ]- begin ---------------
668
 
669
include 'normal.asm'
670
 
671
;-[ mike.dld ]- end -----------------
672
 
673
;------------DATA AREA---------------
674
 
675
align 4
676
 
677
mdvm_func_table:
384 mikedld 678
	dd MDSTART
679
	dd vm_info_init,	  vm_get_cur_mode
680
	dd vm_set_video_mode,	  vm_restore_init_video_mode
681
	dd vm_change_screen_size ;vm_change_position_screen
129 mikedld 682
 
683
;-[ mike.dld ]- begin ---------------
684
 
384 mikedld 685
	dd vm_mike_init
129 mikedld 686
;       dd vm_mike_cursor_pos
384 mikedld 687
	dd vm_mike_uninit
129 mikedld 688
 
689
;-[ mike.dld ]- end -----------------
690
 
691
;1280x1024 - 11Bh
692
mode3:
693
      dw 0101h
694
      dw 0d000h,9f01h,9f02h,9303h,0a904h,1905h,2806h,5a07h
695
      dw 0110h,8411h,0ff12h,0ff15h,2916h
696
 
697
;1024x768 - 118h
698
mode2:
699
      dw 0101h
700
      dw 0a400h,7f01h,7f02h,8703h,8404h,9505h,2406h,0f507h
701
      dw 0310h,8911h,0ff12h,0ff15h,2516h
702
 
703
;800x600  - 115h
704
mode1:
705
      dw 0101h
706
      dw 8000h,6301h,6302h,8303h,6a04h,1a05h,7206h,0f007h
707
      dw 5910h,8d11h,5712h,5715h,7316h
708
 
709
;640x480 - 112h, 12h
710
mode0:
711
      dw 0101h
712
      dw 6000h,4f01h,4f02h,8303h,5304h,9f05h,00b06h,3e07h
713
      dw 0ea10h,8c11h,0df12h,0df15h,0c16h
714
 
715
; 640x400
716
;mymode0:
717
; dw 0101h
718
;_0_7 dw 5f00h,4f01h,4f02h,8303h,5304h,9f05h,0BF06h,1f07h
719
; dw 9c10h,8e11h,8f12h,9615h,0B916h ;,4013h
720
 
721
; 640x800
722
;mymode1:
723
; dw 0101h
724
; dw 5f00h,4f01h,4f02h,8003h,5004h,9f05h,06006h,0FF07h
725
; dw 2d10h,8f11h,2012h,2615h,05716h ;,4013h
726
 
727
align 4
728
 
729
;-[ mike.dld ]- begin ---------------
730
;oldX      dd ?
731
;oldY      dd ?
732
;initvm    dd ?
384 mikedld 733
currvm	   dd 0
129 mikedld 734
refrate    dd 0
384 mikedld 735
initrr	   dd 0
736
systlb	   dd 0
129 mikedld 737
;pclock    dd ?
384 mikedld 738
mdrvm	   dd 0 ; 0 - not drv init yet, 1 - already drv init
129 mikedld 739
;-[ mike.dld ]- end -----------------
740
 
741
 
742
drvinfo:
743
drvname:   times 32 db ' '
384 mikedld 744
drvver	   dd 0
745
	   times (32-($-drvver))/4 dd 0
129 mikedld 746
drvmode    dw 011Bh,0118h,0115h,0112h
384 mikedld 747
	   times (64-($-drvmode))/2 dw 00h
748
_m1	   dw 0,0,0,0,0
749
_m2	   dw 0,0,0,0,0
750
_m3	   dw 0,0,0,0,0
751
_m4	   dw 0,0,0,0,0
752
_m5	   dw 0,0,0,0,0
753
	   times (512-($-drvinfo)) db 0
129 mikedld 754
drvinfoend:
755
 
756
;-[ mike.dld ]- begin ---------------
757
 
758
align 4
759
include_debug_strings
760
 
761
;-[ mike.dld ]- end -----------------
762
 
763
DRVM_END:
764
 
765
align 4
766
 
767
;-[ mike.dld ]- begin ---------------
384 mikedld 768
oldX	   dd ?
769
oldY	   dd ?
770
initvm	   dd ?
771
pclock	   dd ?
129 mikedld 772
;-[ mike.dld ]- end -----------------
773
 
774
CRTCreg:
775
_00  db ?
776
_01  db ?
777
_02  db ?
778
_03  db ?
779
_04  db ?
780
_05  db ?
781
_06  db ?
782
_07  db ?
783
_08  db ?
784
_09  db ?
785
_0a  db ?
786
_0b  db ?
787
_0c  db ?
788
_0d  db ?
789
_0e  db ?
790
_0f  db ?
791
_10  db ?
792
_11  db ?
793
_12  db ?
794
_13  db ?
795
_14  db ?
796
_15  db ?
797
_16  db ?
798
_17  db ?
799
_18  db ?
800
_19  db ?
801
 
802
;-[ mike.dld ]- begin ---------------
803
 
384 mikedld 804
 cnt	  dd ?
129 mikedld 805
align 16
384 mikedld 806
 tr	  RECT
807
 rct	  RECT
129 mikedld 808
;rb       40*sizeof.RECT
809
 
810
;-[ mike.dld ]- end -----------------