Subversion Repositories Kolibri OS

Rev

Rev 393 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 393 Rev 394
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
2
;;
3
;; Kolibri OS - based on source code Menuet OS, but not 100% compatible.
3
;; Kolibri OS - based on source code Menuet OS, but not 100% compatible.
4
;;
4
;;
5
;; See file COPYING or GNU.TXT for details with these additional details:
5
;; See file COPYING or GNU.TXT for details with these additional details:
6
;;     - All code written in 32 bit x86 assembly language
6
;;     - All code written in 32 bit x86 assembly language
7
;;     - No external code (eg. bios) at process execution time
7
;;     - No external code (eg. bios) at process execution time
8
;;
8
;;
9
;;
9
;;
10
;;   Compile with last version FASM
10
;;   Compile with last version FASM
11
;;
11
;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
include "proc32.inc"
13
include "proc32.inc"
14
include "kglobals.inc"
14
include "kglobals.inc"
15
include "lang.inc"
15
include "lang.inc"
16
 
16
 
17
include "const.inc"
17
include "const.inc"
18
max_processes    equ   255
18
max_processes    equ   255
19
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
19
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
20
 
20
 
21
 
21
 
22
os_data        equ  os_data_l-gdts    ; GDTs
22
os_data        equ  os_data_l-gdts    ; GDTs
23
os_code        equ  os_code_l-gdts
23
os_code        equ  os_code_l-gdts
24
graph_data     equ  3+graph_data_l-gdts
24
graph_data     equ  3+graph_data_l-gdts
25
tss0           equ  tss0_l-gdts
25
tss0           equ  tss0_l-gdts
26
app_code       equ  3+app_code_l-gdts
26
app_code       equ  3+app_code_l-gdts
27
app_data       equ  3+app_data_l-gdts
27
app_data       equ  3+app_data_l-gdts
28
 
28
 
29
 
29
 
30
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31
;;
31
;;
32
;;   Included files:
32
;;   Included files:
33
;;
33
;;
34
;;   Kernel16.inc
34
;;   Kernel16.inc
35
;;    - Booteng.inc   English text for bootup
35
;;    - Booteng.inc   English text for bootup
36
;;    - Bootcode.inc  Hardware setup
36
;;    - Bootcode.inc  Hardware setup
37
;;    - Pci16.inc     PCI functions
37
;;    - Pci16.inc     PCI functions
38
;;
38
;;
39
;;   Kernel32.inc
39
;;   Kernel32.inc
40
;;    - Sys32.inc     Process management
40
;;    - Sys32.inc     Process management
41
;;    - Shutdown.inc  Shutdown and restart
41
;;    - Shutdown.inc  Shutdown and restart
42
;;    - Fat32.inc     Read / write hd
42
;;    - Fat32.inc     Read / write hd
43
;;    - Vesa12.inc    Vesa 1.2 driver
43
;;    - Vesa12.inc    Vesa 1.2 driver
44
;;    - Vesa20.inc    Vesa 2.0 driver
44
;;    - Vesa20.inc    Vesa 2.0 driver
45
;;    - Vga.inc       VGA driver
45
;;    - Vga.inc       VGA driver
46
;;    - Stack.inc     Network interface
46
;;    - Stack.inc     Network interface
47
;;    - Mouse.inc     Mouse pointer
47
;;    - Mouse.inc     Mouse pointer
48
;;    - Scincode.inc  Window skinning
48
;;    - Scincode.inc  Window skinning
49
;;    - Pci32.inc     PCI functions
49
;;    - Pci32.inc     PCI functions
50
;;
50
;;
51
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52
 
52
 
53
 
53
 
54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55
;;                                                                      ;;
55
;;                                                                      ;;
56
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
56
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
57
;;                                                                      ;;
57
;;                                                                      ;;
58
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
 
59
 
60
use16
60
use16
61
                  org   0x0
61
                  org   0x0
62
                  jmp   start_of_code
62
                  jmp   start_of_code
63
 
63
 
64
version db    'Kolibri OS  version 0.6.5.0      ',13,10,13,10,0
64
version db    'Kolibri OS  version 0.6.5.0      ',13,10,13,10,0
65
 
65
 
66
include "boot/preboot.inc"
66
include "boot/preboot.inc"
67
 
67
 
68
if lang eq en
68
if lang eq en
69
include "boot/booteng.inc"     ; english system boot messages
69
include "boot/booteng.inc"     ; english system boot messages
70
else if lang eq ru
70
else if lang eq ru
71
include "boot/bootru.inc"      ; russian system boot messages
71
include "boot/bootru.inc"      ; russian system boot messages
72
include "boot/ru.inc"          ; Russian font
72
include "boot/ru.inc"          ; Russian font
73
else if lang eq et
73
else if lang eq et
74
include "boot/bootet.inc"      ; estonian system boot messages
74
include "boot/bootet.inc"      ; estonian system boot messages
75
include "boot/et.inc"          ; Estonian font
75
include "boot/et.inc"          ; Estonian font
76
else
76
else
77
include "boot/bootge.inc"      ; german system boot messages
77
include "boot/bootge.inc"      ; german system boot messages
78
end if
78
end if
79
 
79
 
80
include "boot/bootcode.inc"    ; 16 bit system boot code
80
include "boot/bootcode.inc"    ; 16 bit system boot code
81
include "bus/pci/pci16.inc"
81
include "bus/pci/pci16.inc"
82
 
82
 
83
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84
;;                                                                      ;;
84
;;                                                                      ;;
85
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
85
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
86
;;                                                                      ;;
86
;;                                                                      ;;
87
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88
 
88
 
89
 
89
 
90
; CR0 Flags - Protected mode and Paging
90
; CR0 Flags - Protected mode and Paging
91
 
91
 
92
        mov ecx, CR0_PE
92
        mov ecx, CR0_PE
93
 
93
 
94
; Enabling 32 bit protected mode
94
; Enabling 32 bit protected mode
95
 
95
 
96
        sidt    [cs:old_ints_h]
96
        sidt    [cs:old_ints_h]
97
 
97
 
98
        cli                             ; disable all irqs
98
        cli                             ; disable all irqs
99
        cld
99
        cld
100
        mov     al,255                  ; mask all irqs
100
        mov     al,255                  ; mask all irqs
101
        out     0xa1,al
101
        out     0xa1,al
102
        out     0x21,al
102
        out     0x21,al
103
   l.5: in      al, 0x64                ; Enable A20
103
   l.5: in      al, 0x64                ; Enable A20
104
        test    al, 2
104
        test    al, 2
105
        jnz     l.5
105
        jnz     l.5
106
        mov     al, 0xD1
106
        mov     al, 0xD1
107
        out     0x64, al
107
        out     0x64, al
108
   l.6: in      al, 0x64
108
   l.6: in      al, 0x64
109
        test    al, 2
109
        test    al, 2
110
        jnz     l.6
110
        jnz     l.6
111
        mov     al, 0xDF
111
        mov     al, 0xDF
112
        out     0x60, al
112
        out     0x60, al
113
   l.7: in      al, 0x64
113
   l.7: in      al, 0x64
114
        test    al, 2
114
        test    al, 2
115
        jnz     l.7
115
        jnz     l.7
116
        mov     al, 0xFF
116
        mov     al, 0xFF
117
        out     0x64, al
117
        out     0x64, al
118
 
118
 
119
        lgdt    [cs:tmp_gdt]            ; Load GDT
119
        lgdt    [cs:tmp_gdt]            ; Load GDT
120
        mov     eax, cr0                ; protected mode
120
        mov     eax, cr0                ; protected mode
121
        or      eax, ecx
121
        or      eax, ecx
122
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
122
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
123
        mov     cr0, eax
123
        mov     cr0, eax
124
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
124
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
125
 
125
 
126
include "boot/shutdown.inc" ; shutdown or restart
126
include "boot/shutdown.inc" ; shutdown or restart
127
 
127
 
128
align 8
128
align 8
129
tmp_gdt:
129
tmp_gdt:
130
 
130
 
131
        dw     23
131
        dw     23
132
        dd     tmp_gdt+0x10000
132
        dd     tmp_gdt+0x10000
133
        dw     0
133
        dw     0
134
 
134
 
135
        dw     0xffff
135
        dw     0xffff
136
        dw     0x0000
136
        dw     0x0000
137
        db     0x00
137
        db     0x00
138
        dw     11011111b *256 +10011010b
138
        dw     11011111b *256 +10011010b
139
        db     0x00
139
        db     0x00
140
 
140
 
141
        dw     0xffff
141
        dw     0xffff
142
        dw     0x0000
142
        dw     0x0000
143
        db     0x00
143
        db     0x00
144
        dw     11011111b *256 +10010010b
144
        dw     11011111b *256 +10010010b
145
        db     0x00
145
        db     0x00
146
 
146
 
147
include "data16.inc"
147
include "data16.inc"
148
 
148
 
149
use32
149
use32
150
org $+0x10000
150
org $+0x10000
151
 
151
 
152
align 4
152
align 4
153
B32:
153
B32:
154
           mov   ax,os_data        ; Selector for os
154
           mov   ax,os_data        ; Selector for os
155
           mov   ds,ax
155
           mov   ds,ax
156
           mov   es,ax
156
           mov   es,ax
157
           mov   fs,ax
157
           mov   fs,ax
158
           mov   gs,ax
158
           mov   gs,ax
159
           mov   ss,ax
159
           mov   ss,ax
160
           mov   esp,0x3ec00       ; Set stack
160
           mov   esp,0x3ec00       ; Set stack
161
 
161
 
162
; CLEAR 0x280000 - HEAP_BASE
162
; CLEAR 0x280000 - HEAP_BASE
163
 
163
 
164
           xor   eax,eax
164
           xor   eax,eax
165
           mov   edi,0x280000
165
           mov   edi,0x280000
166
           mov   ecx,(HEAP_BASE-0x280000) / 4
166
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
167
           cld
167
           cld
168
           rep   stosd
168
           rep   stosd
169
 
169
 
170
           mov   edi,0x40000
170
           mov   edi,0x40000
171
           mov   ecx,(0x90000-0x40000)/4
171
           mov   ecx,(0x90000-0x40000)/4
172
           rep   stosd
172
           rep   stosd
173
 
173
 
174
; CLEAR KERNEL UNDEFINED GLOBALS
174
; CLEAR KERNEL UNDEFINED GLOBALS
175
           mov   edi, endofcode-OS_BASE
175
           mov   edi, endofcode-OS_BASE
176
           mov   ecx, (uglobals_size/4)+4
176
           mov   ecx, (uglobals_size/4)+4
177
           rep   stosd
177
           rep   stosd
178
 
178
 
179
; SAVE & CLEAR 0-0xffff
179
; SAVE & CLEAR 0-0xffff
180
 
180
 
181
           xor esi, esi
181
           xor esi, esi
182
           mov   edi,0x2F0000
182
           mov   edi,0x2F0000
183
           mov   ecx,0x10000 / 4
183
           mov   ecx,0x10000 / 4
184
           rep   movsd
184
           rep   movsd
185
           xor edi, edi
185
           xor edi, edi
186
           mov   ecx,0x10000 / 4
186
           mov   ecx,0x10000 / 4
187
           rep   stosd
187
           rep   stosd
188
 
188
 
189
           call test_cpu
189
           call test_cpu
190
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
190
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
191
 
191
 
192
; MEMORY MODEL
192
; MEMORY MODEL
193
           call mem_test
193
           call mem_test
194
           call init_mem
194
           call init_mem
195
           call init_page_map
195
           call init_page_map
196
 
196
 
197
; ENABLE PAGING
197
; ENABLE PAGING
198
 
198
 
199
           mov eax, sys_pgdir-OS_BASE
199
           mov eax, sys_pgdir-OS_BASE
200
           mov cr3, eax
200
           mov cr3, eax
201
 
201
 
202
           mov eax,cr0
202
           mov eax,cr0
203
           or eax,CR0_PG
203
           or eax,CR0_PG
204
           mov cr0,eax
204
           mov cr0,eax
-
 
205
 
205
           lgdt [gdts]
206
           lgdt [gdts]
206
           jmp pword os_code:high_code
207
           jmp pword os_code:high_code
207
 
208
 
208
__DEBUG__ fix 1
209
__DEBUG__ fix 1
209
__DEBUG_LEVEL__ fix 1
210
__DEBUG_LEVEL__ fix 1
210
include 'init.inc'
211
include 'init.inc'
211
 
212
 
212
org OS_BASE+$
213
org OS_BASE+$
213
include 'fdo.inc'
-
 
214
 
214
 
215
align 4
215
align 4
216
high_code:
216
high_code:
217
           mov   ax,os_data
217
           mov   ax,os_data
218
           mov   ds,ax
218
           mov   ds,ax
219
           mov   es,ax
219
           mov   es,ax
220
           mov   fs,ax
220
           mov   fs,ax
221
           mov   gs,ax
221
           mov   gs,ax
222
           mov   ss,ax
222
           mov   ss,ax
223
           add esp, OS_BASE
223
           add esp, OS_BASE
224
 
224
 
225
           mov dword [sys_pgdir], 0
225
           mov dword [sys_pgdir], 0
226
           mov dword [sys_pgdir+4], 0
226
           mov dword [sys_pgdir+4], 0
227
           mov dword [sys_pgdir+8], 0
227
           mov dword [sys_pgdir+8], 0
228
           mov dword [sys_pgdir+12], 0
228
           mov dword [sys_pgdir+12], 0
229
 
229
 
230
           mov eax, sys_pgdir-OS_BASE
230
           mov eax, sys_pgdir-OS_BASE
231
           mov cr3, eax
231
           mov cr3, eax
232
 
232
 
233
; SAVE REAL MODE VARIABLES
233
; SAVE REAL MODE VARIABLES
234
        mov     ax, [BOOT_VAR + 0x9031]
234
        mov     ax, [BOOT_VAR + 0x9031]
235
        mov     [IDEContrRegsBaseAddr], ax
235
        mov     [IDEContrRegsBaseAddr], ax
236
; --------------- APM ---------------------
236
; --------------- APM ---------------------
237
;    mov    eax, [BOOT_VAR + 0x9040]    ; entry point
237
;    mov    eax, [BOOT_VAR + 0x9040]    ; entry point
238
;    mov    dword[apm_entry], eax
238
;    mov    dword[apm_entry], eax
239
;    mov    word [apm_entry + 4], apm_code_32 - gdts
239
;    mov    word [apm_entry + 4], apm_code_32 - gdts
240
 
240
 
241
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
241
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
242
    mov    [apm_vf], eax
242
    mov    [apm_vf], eax
243
; -----------------------------------------
243
; -----------------------------------------
244
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
244
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
245
;        mov   [0xF604],byte 1  ;al
245
;        mov   [0xF604],byte 1  ;al
246
        mov     al, [BOOT_VAR+0x901F]   ; DMA writing
246
        mov     al, [BOOT_VAR+0x901F]   ; DMA writing
247
        mov     [allow_dma_write], al
247
        mov     [allow_dma_write], al
248
        mov   al,[BOOT_VAR+0x9000]        ; bpp
248
        mov   al,[BOOT_VAR+0x9000]        ; bpp
249
        mov   [ScreenBPP],al
249
        mov   [ScreenBPP],al
250
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
250
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
251
        dec   eax
251
        dec   eax
252
        mov   [ScreenWidth],eax
252
        mov   [ScreenWidth],eax
253
        mov   [screen_workarea.right],eax
253
        mov   [screen_workarea.right],eax
254
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
254
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
255
        dec   eax
255
        dec   eax
256
        mov   [ScreenHeight],eax
256
        mov   [ScreenHeight],eax
257
        mov   [screen_workarea.bottom],eax
257
        mov   [screen_workarea.bottom],eax
258
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
258
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
259
        mov   [SCR_MODE],eax
259
        mov   [SCR_MODE],eax
260
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
260
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
261
        mov   [BANK_SWITCH],eax
261
        mov   [BANK_SWITCH],eax
262
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
262
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
263
        cmp   [SCR_MODE],word 0x13          ; 320x200
263
        cmp   [SCR_MODE],word 0x13          ; 320x200
264
        je    @f
264
        je    @f
265
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
265
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
266
        je    @f
266
        je    @f
267
        mov   ax,[BOOT_VAR+0x9001]        ; for other modes
267
        mov   ax,[BOOT_VAR+0x9001]        ; for other modes
268
        mov   [BytesPerScanLine],ax
268
        mov   [BytesPerScanLine],ax
269
@@:
269
@@:
270
 
270
 
271
; GRAPHICS ADDRESSES
271
; GRAPHICS ADDRESSES
272
 
272
 
273
        mov     byte [BOOT_VAR+0x901e],0x0
273
        mov     byte [BOOT_VAR+0x901e],0x0
274
        mov     eax,[BOOT_VAR+0x9018]
274
        mov     eax,[BOOT_VAR+0x9018]
275
        mov     [LFBAddress],eax
275
        mov     [LFBAddress],eax
276
 
276
 
277
        cmp     [SCR_MODE],word 0100000000000000b
277
        cmp     [SCR_MODE],word 0100000000000000b
278
        jge     setvesa20
278
        jge     setvesa20
279
        cmp     [SCR_MODE],word 0x13
279
        cmp     [SCR_MODE],word 0x13
280
        je      v20ga32
280
        je      v20ga32
281
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
281
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
282
        mov     [GETPIXEL],dword Vesa12_getpixel24
282
        mov     [GETPIXEL],dword Vesa12_getpixel24
283
        cmp     [ScreenBPP],byte 24
283
        cmp     [ScreenBPP],byte 24
284
        jz      ga24
284
        jz      ga24
285
        mov     [PUTPIXEL],dword Vesa12_putpixel32
285
        mov     [PUTPIXEL],dword Vesa12_putpixel32
286
        mov     [GETPIXEL],dword Vesa12_getpixel32
286
        mov     [GETPIXEL],dword Vesa12_getpixel32
287
      ga24:
287
      ga24:
288
        jmp     v20ga24
288
        jmp     v20ga24
289
      setvesa20:
289
      setvesa20:
290
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
290
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
291
        mov     [GETPIXEL],dword Vesa20_getpixel24
291
        mov     [GETPIXEL],dword Vesa20_getpixel24
292
        cmp     [ScreenBPP],byte 24
292
        cmp     [ScreenBPP],byte 24
293
        jz      v20ga24
293
        jz      v20ga24
294
      v20ga32:
294
      v20ga32:
295
        mov     [PUTPIXEL],dword Vesa20_putpixel32
295
        mov     [PUTPIXEL],dword Vesa20_putpixel32
296
        mov     [GETPIXEL],dword Vesa20_getpixel32
296
        mov     [GETPIXEL],dword Vesa20_getpixel32
297
      v20ga24:
297
      v20ga24:
298
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
298
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
299
        jne     no_mode_0x12
299
        jne     no_mode_0x12
300
        mov     [PUTPIXEL],dword VGA_putpixel
300
        mov     [PUTPIXEL],dword VGA_putpixel
301
        mov     [GETPIXEL],dword Vesa20_getpixel32
301
        mov     [GETPIXEL],dword Vesa20_getpixel32
302
      no_mode_0x12:
302
      no_mode_0x12:
303
 
303
 
304
; -------- Fast System Call init ----------
304
; -------- Fast System Call init ----------
305
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
305
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
306
           bt [cpu_caps], CAPS_SEP
306
           bt [cpu_caps], CAPS_SEP
307
           jnc .SEnP   ; SysEnter not Present
307
           jnc .SEnP   ; SysEnter not Present
308
           xor edx, edx
308
           xor edx, edx
309
           mov ecx, MSR_SYSENTER_CS
309
           mov ecx, MSR_SYSENTER_CS
310
           mov eax, os_code
310
           mov eax, os_code
311
           wrmsr
311
           wrmsr
312
           mov ecx, MSR_SYSENTER_ESP
312
           mov ecx, MSR_SYSENTER_ESP
313
           mov eax, sysenter_stack ; Check it
313
           mov eax, sysenter_stack ; Check it
314
           wrmsr
314
           wrmsr
315
           mov ecx, MSR_SYSENTER_EIP
315
           mov ecx, MSR_SYSENTER_EIP
316
           mov eax, sysenter_entry
316
           mov eax, sysenter_entry
317
           wrmsr
317
           wrmsr
318
.SEnP:
318
.SEnP:
319
; AMD SYSCALL/SYSRET
319
; AMD SYSCALL/SYSRET
320
           cmp byte[cpu_vendor], 'A'
320
           cmp byte[cpu_vendor], 'A'
321
           jne .noSYSCALL
321
           jne .noSYSCALL
322
           mov eax, 0x80000001
322
           mov eax, 0x80000001
323
           cpuid
323
           cpuid
324
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
324
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
325
           jz .noSYSCALL
325
           jz .noSYSCALL
326
           mov ecx, MSR_AMD_EFER
326
           mov ecx, MSR_AMD_EFER
327
           rdmsr
327
           rdmsr
328
           or eax, 1   ; bit_0 - System Call Extension (SCE)
328
           or eax, 1   ; bit_0 - System Call Extension (SCE)
329
           wrmsr
329
           wrmsr
330
 
330
 
331
	; !!!! It`s dirty hack, fix it !!!
331
	; !!!! It`s dirty hack, fix it !!!
332
	; Bits of EDX :
332
	; Bits of EDX :
333
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
333
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
334
	;  and the contents of this field, plus 8, are copied into the SS register.
334
	;  and the contents of this field, plus 8, are copied into the SS register.
335
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
335
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
336
	;  and the contents of this field, plus 8, are copied into the SS register.
336
	;  and the contents of this field, plus 8, are copied into the SS register.
337
 
337
 
338
	; mov	edx, (os_code + 16) * 65536 + os_code
338
	; mov	edx, (os_code + 16) * 65536 + os_code
339
           mov edx, 0x1B0013
339
           mov edx, 0x1B0013
340
 
340
 
341
           mov eax, syscall_entry
341
           mov eax, syscall_entry
342
           mov ecx, MSR_AMD_STAR
342
           mov ecx, MSR_AMD_STAR
343
           wrmsr
343
           wrmsr
344
.noSYSCALL:
344
.noSYSCALL:
345
; -----------------------------------------
345
; -----------------------------------------
346
 
346
 
347
           call init_kernel_heap
347
           call init_kernel_heap
348
           stdcall kernel_alloc, 0x2000
348
           stdcall kernel_alloc, 0x2000
349
           mov [os_stack], eax
349
           mov [os_stack], eax
350
 
350
 
351
           mov [LFBSize], 0x800000
351
           mov [LFBSize], 0x800000
352
           call init_mtrr
352
           call init_mtrr
353
 
353
 
354
           call init_LFB
354
           call init_LFB
355
           call init_fpu
355
           call init_fpu
356
 
-
 
357
           call init_malloc
356
           call init_malloc
358
 
357
 
359
           stdcall alloc_kernel_space, 0x4F000
358
           stdcall alloc_kernel_space, 0x4F000
360
           mov [ipc_tmp], eax
359
           mov [ipc_tmp], eax
361
           mov ebx, 0x1000
360
           mov ebx, 0x1000
362
 
361
 
363
           add eax, 0x40000
362
           add eax, 0x40000
364
           mov [proc_mem_map], eax
363
           mov [proc_mem_map], eax
365
 
364
 
366
           add eax, 0x8000
365
           add eax, 0x8000
367
           mov [proc_mem_pdir], eax
366
           mov [proc_mem_pdir], eax
368
 
367
 
369
           add eax, ebx
368
           add eax, ebx
370
           mov [proc_mem_tab], eax
369
           mov [proc_mem_tab], eax
371
 
370
 
372
           add eax, ebx
371
           add eax, ebx
373
           mov [tmp_task_pdir], eax
372
           mov [tmp_task_pdir], eax
374
 
373
 
375
           add eax, ebx
374
           add eax, ebx
376
           mov [tmp_task_ptab], eax
375
           mov [tmp_task_ptab], eax
377
 
376
 
378
           add eax, ebx
377
           add eax, ebx
379
           mov [ipc_pdir], eax
378
           mov [ipc_pdir], eax
380
 
379
 
381
           add eax, ebx
380
           add eax, ebx
382
           mov [ipc_ptab], eax
381
           mov [ipc_ptab], eax
383
 
382
 
384
           call init_events
383
           call init_events
385
 
-
 
386
           mov eax, srv.fd-SRV_FD_OFFSET
384
           mov eax, srv.fd-SRV_FD_OFFSET
387
           mov [srv.fd], eax
385
           mov [srv.fd], eax
388
           mov [srv.bk], eax
386
           mov [srv.bk], eax
389
 
387
 
390
           mov edi, irq_tab
388
           mov edi, irq_tab
391
           xor eax, eax
389
           xor eax, eax
392
           mov ecx, 16
390
           mov ecx, 16
393
           rep stosd
391
           rep stosd
394
 
392
 
395
;Set base of graphic segment to linear address of LFB
393
;Set base of graphic segment to linear address of LFB
396
        mov     eax,[LFBAddress]          ; set for gs
394
        mov     eax,[LFBAddress]          ; set for gs
397
        mov     [graph_data_l+2],ax
395
        mov     [graph_data_l+2],ax
398
        shr     eax,16
396
        shr     eax,16
399
        mov     [graph_data_l+4],al
397
        mov     [graph_data_l+4],al
400
        mov     [graph_data_l+7],ah
398
        mov     [graph_data_l+7],ah
401
 
399
 
402
;!!!!!!!!!!!!!!!!!!!!!!!!!!
400
;!!!!!!!!!!!!!!!!!!!!!!!!!!
403
include 'detect/disks.inc'
401
include 'detect/disks.inc'
404
;!!!!!!!!!!!!!!!!!!!!!!!!!!
402
;!!!!!!!!!!!!!!!!!!!!!!!!!!
405
 
403
 
406
; READ RAMDISK IMAGE FROM HD
404
; READ RAMDISK IMAGE FROM HD
407
 
405
 
408
;!!!!!!!!!!!!!!!!!!!!!!!
406
;!!!!!!!!!!!!!!!!!!!!!!!
409
include 'boot/rdload.inc'
407
include 'boot/rdload.inc'
410
;!!!!!!!!!!!!!!!!!!!!!!!
408
;!!!!!!!!!!!!!!!!!!!!!!!
411
;    mov    [dma_hdd],1
409
;    mov    [dma_hdd],1
412
; CALCULATE FAT CHAIN FOR RAMDISK
410
; CALCULATE FAT CHAIN FOR RAMDISK
413
 
411
 
414
        call  calculatefatchain
412
        call  calculatefatchain
415
 
413
 
416
; LOAD VMODE DRIVER
414
; LOAD VMODE DRIVER
417
 
415
 
418
;!!!!!!!!!!!!!!!!!!!!!!!
416
;!!!!!!!!!!!!!!!!!!!!!!!
419
include 'vmodeld.inc'
417
include 'vmodeld.inc'
420
;!!!!!!!!!!!!!!!!!!!!!!!
418
;!!!!!!!!!!!!!!!!!!!!!!!
421
 
419
 
422
; LOAD FONTS I and II
420
; LOAD FONTS I and II
423
 
421
 
424
        mov   [CURRENT_TASK],dword 1
422
        mov   [CURRENT_TASK],dword 1
425
        mov   [TASK_COUNT],dword 1
423
        mov   [TASK_COUNT],dword 1
426
        mov   [TASK_BASE],dword TASK_DATA
424
        mov   [TASK_BASE],dword TASK_DATA
427
 
425
 
428
        mov   esi,char
426
        mov   esi,char
429
        xor   ebx,ebx
427
        xor   ebx,ebx
430
        mov   ecx,2560
428
        mov   ecx,2560
431
        mov   edx,FONT_I
429
        mov   edx,FONT_I
432
        call  fs_RamdiskRead
430
        call  fs_RamdiskRead
433
 
431
 
434
        mov   esi,char2
432
        mov   esi,char2
435
        xor   ebx,ebx
433
        xor   ebx,ebx
436
        mov   ecx,2560;26000
434
        mov   ecx,2560;26000
437
        mov   edx,FONT_II
435
        mov   edx,FONT_II
438
        call  fs_RamdiskRead
436
        call  fs_RamdiskRead
439
 
437
 
440
        mov   esi,boot_fonts
438
        mov   esi,boot_fonts
441
        call  boot_log
439
        call  boot_log
442
 
440
 
443
; PRINT AMOUNT OF MEMORY
441
; PRINT AMOUNT OF MEMORY
444
        mov     esi, boot_memdetect
442
        mov     esi, boot_memdetect
445
        call    boot_log
443
        call    boot_log
446
 
444
 
447
        movzx   ecx, word [boot_y]
445
        movzx   ecx, word [boot_y]
448
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
446
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
449
        sub     ecx, 10
447
        sub     ecx, 10
450
        mov     edx, 0xFFFFFF
448
        mov     edx, 0xFFFFFF
451
        mov     ebx, [MEM_AMOUNT]
449
        mov     ebx, [MEM_AMOUNT]
452
        shr     ebx, 20
450
        shr     ebx, 20
453
        mov     edi, 1
451
        mov     edi, 1
454
        mov     eax, 0x00040000
452
        mov     eax, 0x00040000
455
        call    display_number_force
453
        call    display_number_force
456
 
454
 
457
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
455
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
458
 
456
 
459
        mov   esi,boot_irqs
457
        mov   esi,boot_irqs
460
        call  boot_log
458
        call  boot_log
461
        call  rerouteirqs
459
        call  rerouteirqs
462
 
460
 
463
        mov    esi,boot_tss
461
        mov    esi,boot_tss
464
        call   boot_log
462
        call   boot_log
465
 
463
 
466
; BUILD SCHEDULER
464
; BUILD SCHEDULER
467
 
465
 
468
        call   build_scheduler ; sys32.inc
466
        call   build_scheduler ; sys32.inc
469
 
467
 
470
; LOAD IDT
468
; LOAD IDT
471
        lidt   [idtreg]
469
        lidt   [idtreg]
472
 
470
 
473
        mov    esi,boot_devices
471
        mov    esi,boot_devices
474
        call   boot_log
472
        call   boot_log
475
        call   detect_devices
473
        call   detect_devices
476
 
474
 
477
; TIMER SET TO 1/100 S
475
; TIMER SET TO 1/100 S
478
 
476
 
479
        mov   esi,boot_timer
477
        mov   esi,boot_timer
480
        call  boot_log
478
        call  boot_log
481
        mov   al,0x34              ; set to 100Hz
479
        mov   al,0x34              ; set to 100Hz
482
        out   0x43,al
480
        out   0x43,al
483
        mov   al,0x9b              ; lsb    1193180 / 1193
481
        mov   al,0x9b              ; lsb    1193180 / 1193
484
        out   0x40,al
482
        out   0x40,al
485
        mov   al,0x2e              ; msb
483
        mov   al,0x2e              ; msb
486
        out   0x40,al
484
        out   0x40,al
487
 
485
 
488
; SET MOUSE
486
; SET MOUSE
489
 
487
 
490
        mov   esi,boot_setmouse
488
        mov   esi,boot_setmouse
491
        call  boot_log
489
        call  boot_log
492
        call  setmouse
490
        call  setmouse
493
 
491
 
494
        mov  [pci_access_enabled],1
492
        mov  [pci_access_enabled],1
495
 
493
 
496
; SET PRELIMINARY WINDOW STACK AND POSITIONS
494
; SET PRELIMINARY WINDOW STACK AND POSITIONS
497
 
495
 
498
        mov   esi,boot_windefs
496
        mov   esi,boot_windefs
499
        call  boot_log
497
        call  boot_log
500
        call  setwindowdefaults
498
        call  setwindowdefaults
501
 
499
 
502
; SET BACKGROUND DEFAULTS
500
; SET BACKGROUND DEFAULTS
503
 
501
 
504
        mov   esi,boot_bgr
502
        mov   esi,boot_bgr
505
        call  boot_log
503
        call  boot_log
506
        call  calculatebackground
504
        call  calculatebackground
507
 
505
 
508
; RESERVE SYSTEM IRQ'S JA PORT'S
506
; RESERVE SYSTEM IRQ'S JA PORT'S
509
 
507
 
510
        mov   esi,boot_resirqports
508
        mov   esi,boot_resirqports
511
        call  boot_log
509
        call  boot_log
512
        call  reserve_irqs_ports
510
        call  reserve_irqs_ports
513
 
511
 
514
; SET PORTS FOR IRQ HANDLERS
512
; SET PORTS FOR IRQ HANDLERS
515
 
513
 
516
        mov  esi,boot_setrports
514
        mov  esi,boot_setrports
517
        call boot_log
515
        call boot_log
518
        call setirqreadports
516
        call setirqreadports
519
 
517
 
520
; SET UP OS TASK
518
; SET UP OS TASK
521
 
519
 
522
        mov  esi,boot_setostask
520
        mov  esi,boot_setostask
523
        call boot_log
521
        call boot_log
524
 
522
 
525
        mov eax, fpu_data
523
        mov eax, fpu_data
526
        mov  dword [SLOT_BASE+APPDATA.fpu_state], eax
524
        mov  dword [SLOT_BASE+APPDATA.fpu_state], eax
527
        mov  dword [SLOT_BASE+APPDATA.fpu_handler], 0
525
        mov  dword [SLOT_BASE+APPDATA.fpu_handler], 0
528
        mov  dword [SLOT_BASE+APPDATA.sse_handler], 0
526
        mov  dword [SLOT_BASE+APPDATA.sse_handler], 0
529
 
527
 
530
        ; name for OS/IDLE process
528
        ; name for OS/IDLE process
531
 
529
 
532
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
530
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
533
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
531
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
534
        mov edi, [os_stack]
532
        mov edi, [os_stack]
535
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
533
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
536
        add edi, 0x2000-512
534
        add edi, 0x2000-512
537
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
535
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
538
 
536
 
539
        mov esi, fpu_data
537
        mov esi, fpu_data
540
        mov ecx, 512/4
538
        mov ecx, 512/4
541
        cld
539
        cld
542
        rep movsd
540
        rep movsd
543
 
541
 
544
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], 0
542
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], 0
545
        mov dword [SLOT_BASE+256+APPDATA.sse_handler], 0
543
        mov dword [SLOT_BASE+256+APPDATA.sse_handler], 0
546
        mov dword [SLOT_BASE+256+APPDATA.cursor], ebx
544
        mov dword [SLOT_BASE+256+APPDATA.cursor], ebx
547
 
545
 
548
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
546
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
549
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
547
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
550
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
548
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
551
 
549
 
552
        ; task list
550
        ; task list
553
        mov   [CURRENT_TASK],dword 1
551
        mov   [CURRENT_TASK],dword 1
554
        mov   [TASK_COUNT],dword 1
552
        mov   [TASK_COUNT],dword 1
555
        mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
553
        mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
556
        mov  [TASK_DATA+TASKDATA.pid], 1        ; process id number
554
        mov  [TASK_DATA+TASKDATA.pid], 1        ; process id number
557
        mov  [TASK_DATA+TASKDATA.mem_start], 0  ; process base address
555
        mov  [TASK_DATA+TASKDATA.mem_start], 0  ; process base address
558
 
556
 
559
        mov  edi,tss_data+tss_step
557
        mov  edi,tss_data+tss_step
560
        mov ecx, (tss_step)/4
558
        mov ecx, (tss_step)/4
561
        xor eax, eax
559
        xor eax, eax
562
        cld
560
        cld
563
        rep stosd
561
        rep stosd
564
 
562
 
565
        mov  edi,tss_data+tss_step
563
        mov  edi,tss_data+tss_step
566
        mov  [edi+TSS._ss0], os_data
564
        mov  [edi+TSS._ss0], os_data
567
        mov  eax,cr3
565
        mov  eax,cr3
568
        mov  [edi+TSS._cr3],eax
566
        mov  [edi+TSS._cr3],eax
569
        mov  [edi+TSS._eip],osloop
567
        mov  [edi+TSS._eip],osloop
570
        mov  [edi+TSS._eflags],dword 0x11202 ; sti and resume
568
        mov  [edi+TSS._eflags],dword 0x11202 ; sti and resume
571
        mov eax, [os_stack]
569
        mov eax, [os_stack]
572
        add eax, 0x2000-512
570
        add eax, 0x2000-512
573
        mov  [edi+TSS._esp], eax
571
        mov  [edi+TSS._esp], eax
574
        mov  [edi+TSS._cs],os_code
572
        mov  [edi+TSS._cs],os_code
575
        mov  [edi+TSS._ss],os_data
573
        mov  [edi+TSS._ss],os_data
576
        mov  [edi+TSS._ds],os_data
574
        mov  [edi+TSS._ds],os_data
577
        mov  [edi+TSS._es],os_data
575
        mov  [edi+TSS._es],os_data
578
        mov  [edi+TSS._fs],os_data
576
        mov  [edi+TSS._fs],os_data
579
        mov  [edi+TSS._gs],os_data
577
        mov  [edi+TSS._gs],os_data
580
 
578
 
581
        mov  ax,tss0
579
        mov  ax,tss0
582
        ltr  ax
580
        ltr  ax
583
 
581
 
584
        call init_cursors
582
        call init_cursors
585
        mov eax, [def_cursor]
583
        mov eax, [def_cursor]
586
        mov [SLOT_BASE+APPDATA.cursor],eax
584
        mov [SLOT_BASE+APPDATA.cursor],eax
587
        mov [SLOT_BASE+APPDATA.cursor+256],eax
585
        mov [SLOT_BASE+APPDATA.cursor+256],eax
588
 
586
 
589
  ; READ TSC / SECOND
587
  ; READ TSC / SECOND
590
 
588
 
591
        mov   esi,boot_tsc
589
        mov   esi,boot_tsc
592
        call  boot_log
590
        call  boot_log
593
        call  _rdtsc
591
        call  _rdtsc
594
        mov   ecx,eax
592
        mov   ecx,eax
595
        mov   esi,250               ; wait 1/4 a second
593
        mov   esi,250               ; wait 1/4 a second
596
        call  delay_ms
594
        call  delay_ms
597
        call  _rdtsc
595
        call  _rdtsc
598
        sub   eax,ecx
596
        sub   eax,ecx
599
        shl   eax,2
597
        shl   eax,2
600
        mov   [CPU_FREQ],eax          ; save tsc / sec
598
        mov   [CPU_FREQ],eax          ; save tsc / sec
601
        mov ebx, 1000000
599
        mov ebx, 1000000
602
        div ebx
600
        div ebx
603
        mov [stall_mcs], eax
601
        mov [stall_mcs], eax
604
 
602
 
605
; SET VARIABLES
603
; SET VARIABLES
606
 
604
 
607
        call  set_variables
605
        call  set_variables
608
 
606
 
609
; STACK AND FDC
607
; STACK AND FDC
610
 
608
 
611
        call  stack_init
609
        call  stack_init
612
        call  fdc_init
610
        call  fdc_init
613
 
611
 
614
; PALETTE FOR 320x200 and 640x480 16 col
612
; PALETTE FOR 320x200 and 640x480 16 col
615
 
613
 
616
        cmp   [SCR_MODE],word 0x12
614
        cmp   [SCR_MODE],word 0x12
617
        jne   no_pal_vga
615
        jne   no_pal_vga
618
        mov   esi,boot_pal_vga
616
        mov   esi,boot_pal_vga
619
        call  boot_log
617
        call  boot_log
620
        call  paletteVGA
618
        call  paletteVGA
621
      no_pal_vga:
619
      no_pal_vga:
622
 
620
 
623
        cmp   [SCR_MODE],word 0x13
621
        cmp   [SCR_MODE],word 0x13
624
        jne   no_pal_ega
622
        jne   no_pal_ega
625
        mov   esi,boot_pal_ega
623
        mov   esi,boot_pal_ega
626
        call  boot_log
624
        call  boot_log
627
        call  palette320x200
625
        call  palette320x200
628
      no_pal_ega:
626
      no_pal_ega:
629
 
627
 
630
; LOAD DEFAULT SKIN
628
; LOAD DEFAULT SKIN
631
 
629
 
632
        mov     esi,_skin_file_default
630
        mov     esi,_skin_file_default
633
        mov     edi,_skin_file
631
        mov     edi,_skin_file
634
        movsd
632
        movsd
635
        movsd
633
        movsd
636
        movsd
634
        movsd
637
        call    load_skin
635
        call    load_skin
638
 
636
 
639
; LOAD FIRST APPLICATION
637
; LOAD FIRST APPLICATION
640
        cli
638
        cli
641
        cmp   byte [BOOT_VAR+0x9030],1
639
        cmp   byte [BOOT_VAR+0x9030],1
642
        jne   no_load_vrr_m
640
        jne   no_load_vrr_m
643
 
641
 
644
        mov ebp, vrr_m
642
        mov ebp, vrr_m
645
        xor ebx, ebx
643
        xor ebx, ebx
646
        xor edx, edx
644
        xor edx, edx
647
        call fs_execute
645
        call fs_execute
648
        cmp   eax,2                  ; if vrr_m app found (PID=2)
646
        cmp   eax,2                  ; if vrr_m app found (PID=2)
649
        je    first_app_found
647
        je    first_app_found
650
 
648
 
651
no_load_vrr_m:
649
no_load_vrr_m:
652
        mov ebp, firstapp
650
        mov ebp, firstapp
653
        xor ebx, ebx
651
        xor ebx, ebx
654
        xor edx, edx
652
        xor edx, edx
655
        call fs_execute
653
        call fs_execute
656
        cmp   eax,2                  ; continue if a process has been loaded
654
        cmp   eax,2                  ; continue if a process has been loaded
657
        je    first_app_found
655
        je    first_app_found
658
        mov   eax, 0xDEADBEEF        ; otherwise halt
656
        mov   eax, 0xDEADBEEF        ; otherwise halt
659
        hlt
657
        hlt
660
first_app_found:
658
first_app_found:
661
        cli
659
        cli
662
 
660
 
663
        ;mov   [TASK_COUNT],dword 2
661
        ;mov   [TASK_COUNT],dword 2
664
        mov   [CURRENT_TASK],dword 1       ; set OS task fisrt
662
        mov   [CURRENT_TASK],dword 1       ; set OS task fisrt
665
 
663
 
666
; SET KEYBOARD PARAMETERS
664
; SET KEYBOARD PARAMETERS
667
        mov   al, 0xf6         ; reset keyboard, scan enabled
665
        mov   al, 0xf6         ; reset keyboard, scan enabled
668
        call  kb_write
666
        call  kb_write
669
 
667
 
670
        ; wait until 8042 is ready
668
        ; wait until 8042 is ready
671
        xor ecx,ecx
669
        xor ecx,ecx
672
      @@:
670
      @@:
673
        in     al,64h
671
        in     al,64h
674
        and    al,00000010b
672
        and    al,00000010b
675
        loopnz @b
673
        loopnz @b
676
 
674
 
677
       ; mov   al, 0xED       ; svetodiody - only for testing!
675
       ; mov   al, 0xED       ; svetodiody - only for testing!
678
       ; call  kb_write
676
       ; call  kb_write
679
       ; call  kb_read
677
       ; call  kb_read
680
       ; mov   al, 111b
678
       ; mov   al, 111b
681
       ; call  kb_write
679
       ; call  kb_write
682
       ; call  kb_read
680
       ; call  kb_read
683
 
681
 
684
        mov   al, 0xF3       ; set repeat rate & delay
682
        mov   al, 0xF3       ; set repeat rate & delay
685
        call  kb_write
683
        call  kb_write
686
;        call  kb_read
684
;        call  kb_read
687
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
685
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
688
        call  kb_write
686
        call  kb_write
689
;        call  kb_read
687
;        call  kb_read
690
     ;// mike.dld [
688
     ;// mike.dld [
691
        call  set_lights
689
        call  set_lights
692
     ;// mike.dld ]
690
     ;// mike.dld ]
693
 
691
 
694
; START MULTITASKING
692
; START MULTITASKING
695
 
693
 
696
        mov   esi,boot_tasking
694
        mov   esi,boot_tasking
697
        call  boot_log
695
        call  boot_log
698
 
696
 
699
 ;      mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
697
 ;      mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
700
 
698
 
701
; UNMASK ALL IRQ'S
699
; UNMASK ALL IRQ'S
702
 
700
 
703
        mov   esi,boot_allirqs
701
        mov   esi,boot_allirqs
704
        call  boot_log
702
        call  boot_log
705
 
703
 
706
        cli                          ;guarantee forbidance of interrupts.
704
        cli                          ;guarantee forbidance of interrupts.
707
        mov   al,0                   ; unmask all irq's
705
        mov   al,0                   ; unmask all irq's
708
        out   0xA1,al
706
        out   0xA1,al
709
        out   0x21,al
707
        out   0x21,al
710
 
708
 
711
        mov   ecx,32
709
        mov   ecx,32
712
 
710
 
713
     ready_for_irqs:
711
     ready_for_irqs:
714
 
712
 
715
        mov   al,0x20                ; ready for irqs
713
        mov   al,0x20                ; ready for irqs
716
        out   0x20,al
714
        out   0x20,al
717
        out   0xa0,al
715
        out   0xa0,al
718
 
716
 
719
        loop  ready_for_irqs         ; flush the queue
717
        loop  ready_for_irqs         ; flush the queue
720
 
718
 
721
        stdcall attach_int_handler, dword 1, irq1
719
        stdcall attach_int_handler, dword 1, irq1
722
 
720
 
723
;        mov    [dma_hdd],1
721
;        mov    [dma_hdd],1
724
        cmp     [IDEContrRegsBaseAddr], 0
722
        cmp     [IDEContrRegsBaseAddr], 0
725
        setnz   [dma_hdd]
723
        setnz   [dma_hdd]
726
 
724
 
727
        sti
725
        sti
728
        jmp   $                      ; wait here for timer to take control
726
        jmp   $                      ; wait here for timer to take control
729
 
727
 
730
        ; Fly :)
728
        ; Fly :)
731
 
729
 
732
 
730
 
733
include 'unpacker.inc'
731
include 'unpacker.inc'
-
 
732
include 'fdo.inc'
734
 
733
 
735
align 4
734
align 4
736
boot_log:
735
boot_log:
737
         pushad
736
         pushad
738
 
737
 
739
         mov   eax,10*65536
738
         mov   eax,10*65536
740
         mov   ax,word [boot_y]
739
         mov   ax,word [boot_y]
741
         add   [boot_y],dword 10
740
         add   [boot_y],dword 10
742
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
741
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
743
         mov   ecx,esi
742
         mov   ecx,esi
744
         mov   edi,1
743
         mov   edi,1
745
         call  dtext
744
         call  dtext
746
 
745
 
747
         mov   [novesachecksum],1000
746
         mov   [novesachecksum],1000
748
         call  checkVga_N13
747
         call  checkVga_N13
749
 
748
 
750
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
749
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
751
         je    .bll2
750
         je    .bll2
752
 
751
 
753
         cmp   esi,boot_tasking
752
         cmp   esi,boot_tasking
754
         jne   .bll2
753
         jne   .bll2
755
         ; begin ealex 04.08.05
754
         ; begin ealex 04.08.05
756
;         in    al,0x61
755
;         in    al,0x61
757
;         and   al,01111111b
756
;         and   al,01111111b
758
;         out   0x61,al
757
;         out   0x61,al
759
         ; end ealex 04.08.05
758
         ; end ealex 04.08.05
760
.bll1:   in    al,0x60    ; wait for ESC key press
759
.bll1:   in    al,0x60    ; wait for ESC key press
761
         cmp   al,129
760
         cmp   al,129
762
         jne   .bll1
761
         jne   .bll1
763
 
762
 
764
.bll2:   popad
763
.bll2:   popad
765
 
764
 
766
         ret
765
         ret
767
 
766
 
768
 
767
 
769
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
768
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
770
;                                                                    ;
769
;                                                                    ;
771
;                    MAIN OS LOOP START                              ;
770
;                    MAIN OS LOOP START                              ;
772
;                                                                    ;
771
;                                                                    ;
773
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
772
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
774
align 32
773
align 32
775
osloop:
774
osloop:
776
        call   [draw_pointer]
775
        call   [draw_pointer]
777
        call   checkbuttons
776
        call   checkbuttons
778
        call   checkwindows
777
        call   checkwindows
779
;       call   check_window_move_request
778
;       call   check_window_move_request
780
        call   checkmisc
779
        call   checkmisc
781
        call   checkVga_N13
780
        call   checkVga_N13
782
        call   stack_handler
781
        call   stack_handler
783
        call   checkidle
782
        call   checkidle
784
        call   check_fdd_motor_status
783
        call   check_fdd_motor_status
785
        jmp    osloop
784
        jmp    osloop
786
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
785
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
787
;                                                                    ;
786
;                                                                    ;
788
;                      MAIN OS LOOP END                              ;
787
;                      MAIN OS LOOP END                              ;
789
;                                                                    ;
788
;                                                                    ;
790
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
789
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
791
 
790
 
792
checkidle:
791
checkidle:
793
        pushad
792
        pushad
794
 
793
 
795
        cmp  [check_idle_semaphore],0
794
        cmp  [check_idle_semaphore],0
796
        jne  no_idle_state
795
        jne  no_idle_state
797
 
796
 
798
        call change_task
797
        call change_task
799
        mov  eax,[idlemem]
798
        mov  eax,[idlemem]
800
        mov  ebx,[timer_ticks] ;[0xfdf0]
799
        mov  ebx,[timer_ticks] ;[0xfdf0]
801
        cmp  eax,ebx
800
        cmp  eax,ebx
802
        jnz  idle_exit
801
        jnz  idle_exit
803
        call _rdtsc
802
        call _rdtsc
804
        mov  ecx,eax
803
        mov  ecx,eax
805
      idle_loop:
804
      idle_loop:
806
        hlt
805
        hlt
807
        cmp  [check_idle_semaphore],0
806
        cmp  [check_idle_semaphore],0
808
        jne  idle_loop_exit
807
        jne  idle_loop_exit
809
        mov  eax,[timer_ticks] ;[0xfdf0]
808
        mov  eax,[timer_ticks] ;[0xfdf0]
810
        cmp  ebx,eax
809
        cmp  ebx,eax
811
        jz   idle_loop
810
        jz   idle_loop
812
      idle_loop_exit:
811
      idle_loop_exit:
813
        mov  [idlemem],eax
812
        mov  [idlemem],eax
814
        call _rdtsc
813
        call _rdtsc
815
        sub  eax,ecx
814
        sub  eax,ecx
816
        mov  ebx,[idleuse]
815
        mov  ebx,[idleuse]
817
        add  ebx,eax
816
        add  ebx,eax
818
        mov  [idleuse],ebx
817
        mov  [idleuse],ebx
819
 
818
 
820
        popad
819
        popad
821
        ret
820
        ret
822
 
821
 
823
      idle_exit:
822
      idle_exit:
824
 
823
 
825
        mov  ebx,[timer_ticks] ;[0xfdf0]
824
        mov  ebx,[timer_ticks] ;[0xfdf0]
826
        mov  [idlemem],ebx
825
        mov  [idlemem],ebx
827
        call change_task
826
        call change_task
828
 
827
 
829
        popad
828
        popad
830
        ret
829
        ret
831
 
830
 
832
      no_idle_state:
831
      no_idle_state:
833
 
832
 
834
        dec  [check_idle_semaphore]
833
        dec  [check_idle_semaphore]
835
 
834
 
836
        mov  ebx,[timer_ticks] ;[0xfdf0]
835
        mov  ebx,[timer_ticks] ;[0xfdf0]
837
        mov  [idlemem],ebx
836
        mov  [idlemem],ebx
838
        call change_task
837
        call change_task
839
 
838
 
840
        popad
839
        popad
841
        ret
840
        ret
842
 
841
 
843
uglobal
842
uglobal
844
  idlemem               dd   0x0
843
  idlemem               dd   0x0
845
  idleuse               dd   0x0
844
  idleuse               dd   0x0
846
  idleusesec            dd   0x0
845
  idleusesec            dd   0x0
847
  check_idle_semaphore  dd   0x0
846
  check_idle_semaphore  dd   0x0
848
endg
847
endg
849
 
848
 
850
 
849
 
851
 
850
 
852
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
851
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
853
;                                                                      ;
852
;                                                                      ;
854
;                   INCLUDED SYSTEM FILES                              ;
853
;                   INCLUDED SYSTEM FILES                              ;
855
;                                                                      ;
854
;                                                                      ;
856
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
855
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
857
 
856
 
858
 
857
 
859
include "kernel32.inc"
858
include "kernel32.inc"
860
 
859
 
861
 
860
 
862
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
861
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
863
;                                                                      ;
862
;                                                                      ;
864
;                       KERNEL FUNCTIONS                               ;
863
;                       KERNEL FUNCTIONS                               ;
865
;                                                                      ;
864
;                                                                      ;
866
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
865
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
867
 
866
 
868
reserve_irqs_ports:
867
reserve_irqs_ports:
869
 
868
 
870
        pushad
869
        pushad
871
 
870
 
872
        mov  [irq_owner+4*0], 1    ; timer
871
        mov  [irq_owner+4*0], 1    ; timer
873
        mov  [irq_owner+4*1], 1    ; keyboard
872
        mov  [irq_owner+4*1], 1    ; keyboard
874
        mov  [irq_owner+4*5], 1    ; sound blaster
873
        mov  [irq_owner+4*5], 1    ; sound blaster
875
        mov  [irq_owner+4*6], 1    ; floppy diskette
874
        mov  [irq_owner+4*6], 1    ; floppy diskette
876
        mov  [irq_owner+4*13], 1   ; math co-pros
875
        mov  [irq_owner+4*13], 1   ; math co-pros
877
        mov  [irq_owner+4*14], 1   ; ide I
876
        mov  [irq_owner+4*14], 1   ; ide I
878
        mov  [irq_owner+4*15], 1   ; ide II
877
        mov  [irq_owner+4*15], 1   ; ide II
879
 
878
 
880
;        movzx eax,byte [0xf604]        ; mouse irq
879
;        movzx eax,byte [0xf604]        ; mouse irq
881
;        dec   eax
880
;        dec   eax
882
;        add   eax,mouseirqtable
881
;        add   eax,mouseirqtable
883
;        movzx eax,byte [eax]
882
;        movzx eax,byte [eax]
884
;        shl   eax,2
883
;        shl   eax,2
885
;        mov   [irq_owner+eax],byte 1
884
;        mov   [irq_owner+eax],byte 1
886
 
885
 
887
 
886
 
888
                                       ; RESERVE PORTS
887
                                       ; RESERVE PORTS
889
        mov   edi,1                    ; 0x00-0x2d
888
        mov   edi,1                    ; 0x00-0x2d
890
        mov   [RESERVED_PORTS],edi
889
        mov   [RESERVED_PORTS],edi
891
        shl   edi,4
890
        shl   edi,4
892
        mov   [RESERVED_PORTS+edi+0],dword 1
891
        mov   [RESERVED_PORTS+edi+0],dword 1
893
        mov   [RESERVED_PORTS+edi+4],dword 0x0
892
        mov   [RESERVED_PORTS+edi+4],dword 0x0
894
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
893
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
895
 
894
 
896
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
895
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
897
        mov   edi,[RESERVED_PORTS]
896
        mov   edi,[RESERVED_PORTS]
898
        shl   edi,4
897
        shl   edi,4
899
        mov   [RESERVED_PORTS+edi+0],dword 1
898
        mov   [RESERVED_PORTS+edi+0],dword 1
900
        mov   [RESERVED_PORTS+edi+4],dword 0x30
899
        mov   [RESERVED_PORTS+edi+4],dword 0x30
901
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
900
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
902
 
901
 
903
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
902
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
904
        mov   edi,[RESERVED_PORTS]
903
        mov   edi,[RESERVED_PORTS]
905
        shl   edi,4
904
        shl   edi,4
906
        mov   [RESERVED_PORTS+edi+0],dword 1
905
        mov   [RESERVED_PORTS+edi+0],dword 1
907
        mov   [RESERVED_PORTS+edi+4],dword 0x50
906
        mov   [RESERVED_PORTS+edi+4],dword 0x50
908
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
907
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
909
 
908
 
910
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
909
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
911
        mov   edi,[RESERVED_PORTS]
910
        mov   edi,[RESERVED_PORTS]
912
        shl   edi,4
911
        shl   edi,4
913
        mov   [RESERVED_PORTS+edi+0],dword 1
912
        mov   [RESERVED_PORTS+edi+0],dword 1
914
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
913
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
915
        mov   [RESERVED_PORTS+edi+8],dword 0xff
914
        mov   [RESERVED_PORTS+edi+8],dword 0xff
916
 
915
 
917
 
916
 
918
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
917
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
919
;        jne   ripl1
918
;        jne   ripl1
920
;        inc   dword [0x2d0000]
919
;        inc   dword [0x2d0000]
921
;        mov   edi,[0x2d0000]
920
;        mov   edi,[0x2d0000]
922
;        shl   edi,4
921
;        shl   edi,4
923
;        mov   [0x2d0000+edi+0],dword 1
922
;        mov   [0x2d0000+edi+0],dword 1
924
;        mov   [0x2d0000+edi+4],dword 0x3f0
923
;        mov   [0x2d0000+edi+4],dword 0x3f0
925
;        mov   [0x2d0000+edi+8],dword 0x3ff
924
;        mov   [0x2d0000+edi+8],dword 0x3ff
926
;      ripl1:
925
;      ripl1:
927
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
926
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
928
;        jne   ripl2
927
;        jne   ripl2
929
;        inc   dword [0x2d0000]
928
;        inc   dword [0x2d0000]
930
;        mov   edi,[0x2d0000]
929
;        mov   edi,[0x2d0000]
931
;        shl   edi,4
930
;        shl   edi,4
932
;        mov   [0x2d0000+edi+0],dword 1
931
;        mov   [0x2d0000+edi+0],dword 1
933
;        mov   [0x2d0000+edi+4],dword 0x2f0
932
;        mov   [0x2d0000+edi+4],dword 0x2f0
934
;        mov   [0x2d0000+edi+8],dword 0x2ff
933
;        mov   [0x2d0000+edi+8],dword 0x2ff
935
;      ripl2:
934
;      ripl2:
936
 
935
 
937
        popad
936
        popad
938
        ret
937
        ret
939
 
938
 
940
iglobal
939
iglobal
941
mouseirqtable   db  12    ; ps2
940
mouseirqtable   db  12    ; ps2
942
                db  4     ; com1
941
                db  4     ; com1
943
                db  3     ; com2
942
                db  3     ; com2
944
endg
943
endg
945
 
944
 
946
setirqreadports:
945
setirqreadports:
947
 
946
 
948
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
947
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
949
        mov   [irq12read+4],dword 0                  ; end of port list
948
        mov   [irq12read+4],dword 0                  ; end of port list
950
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
949
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
951
        mov   [irq04read+4],dword 0                  ; end of port list
950
        mov   [irq04read+4],dword 0                  ; end of port list
952
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
951
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
953
        mov   [irq03read+4],dword 0                  ; end of port list
952
        mov   [irq03read+4],dword 0                  ; end of port list
954
 
953
 
955
        ret
954
        ret
956
 
955
 
957
iglobal
956
iglobal
958
  process_number dd 0x1
957
  process_number dd 0x1
959
endg
958
endg
960
 
959
 
961
set_variables:
960
set_variables:
962
 
961
 
963
        mov   ecx,0x100                       ; flush port 0x60
962
        mov   ecx,0x100                       ; flush port 0x60
964
.fl60:  in    al,0x60
963
.fl60:  in    al,0x60
965
        loop  .fl60
964
        loop  .fl60
966
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
965
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
967
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
966
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
968
        mov   [BTN_COUNT],byte 0                 ; button buffer
967
        mov   [BTN_COUNT],byte 0                 ; button buffer
969
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
968
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
970
 
969
 
971
        push  eax
970
        push  eax
972
        mov   ax,[BOOT_VAR+0x900c]
971
        mov   ax,[BOOT_VAR+0x900c]
973
        shr   ax,1
972
        shr   ax,1
974
        shl   eax,16
973
        shl   eax,16
975
        mov   ax,[BOOT_VAR+0x900A]
974
        mov   ax,[BOOT_VAR+0x900A]
976
        shr   ax,1
975
        shr   ax,1
977
        mov   [MOUSE_X],eax
976
        mov   [MOUSE_X],eax
978
        pop   eax
977
        pop   eax
979
 
978
 
980
        mov   byte [SB16_Status],0            ; Minazzi Paolo
979
        mov   byte [SB16_Status],0            ; Minazzi Paolo
981
        mov   [display_data-12],dword 1       ; tiled background
980
        mov   [display_data-12],dword 1       ; tiled background
982
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
981
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
983
 
982
 
984
     ;!! IP 04.02.2005:
983
     ;!! IP 04.02.2005:
985
        mov   [next_usage_update], 100
984
        mov   [next_usage_update], 100
986
        mov   byte [DONT_SWITCH], 0 ; change task if possible
985
        mov   byte [DONT_SWITCH], 0 ; change task if possible
987
 
986
 
988
        ret
987
        ret
989
 
988
 
990
;* mouse centered - start code- Mario79
989
;* mouse centered - start code- Mario79
991
mouse_centered:
990
mouse_centered:
992
        push  eax
991
        push  eax
993
        mov   eax,[ScreenWidth]
992
        mov   eax,[ScreenWidth]
994
        shr   eax,1
993
        shr   eax,1
995
        mov   [MOUSE_X],ax
994
        mov   [MOUSE_X],ax
996
        mov   eax,[ScreenHeight]
995
        mov   eax,[ScreenHeight]
997
        shr   eax,1
996
        shr   eax,1
998
        mov   [MOUSE_Y],ax
997
        mov   [MOUSE_Y],ax
999
        pop   eax
998
        pop   eax
1000
        ret
999
        ret
1001
;* mouse centered - end code- Mario79
1000
;* mouse centered - end code- Mario79
1002
 
1001
 
1003
align 4
1002
align 4
1004
 
1003
 
1005
sys_outport:
1004
sys_outport:
1006
 
1005
 
1007
    mov   edi,ebx          ; separate flag for read / write
1006
    mov   edi,ebx          ; separate flag for read / write
1008
    and   ebx,65535
1007
    and   ebx,65535
1009
 
1008
 
1010
    mov   ecx,[RESERVED_PORTS]
1009
    mov   ecx,[RESERVED_PORTS]
1011
    test  ecx,ecx
1010
    test  ecx,ecx
1012
    jne   sopl8
1011
    jne   sopl8
1013
    mov   [esp+36],dword 1
1012
    mov   [esp+36],dword 1
1014
    ret
1013
    ret
1015
 
1014
 
1016
  sopl8:
1015
  sopl8:
1017
    mov   edx,[TASK_BASE]
1016
    mov   edx,[TASK_BASE]
1018
    mov   edx,[edx+0x4]
1017
    mov   edx,[edx+0x4]
1019
    and   ebx,65535
1018
    and   ebx,65535
1020
    cld
1019
    cld
1021
  sopl1:
1020
  sopl1:
1022
 
1021
 
1023
    mov   esi,ecx
1022
    mov   esi,ecx
1024
    shl   esi,4
1023
    shl   esi,4
1025
    add   esi,RESERVED_PORTS
1024
    add   esi,RESERVED_PORTS
1026
    cmp   edx,[esi+0]
1025
    cmp   edx,[esi+0]
1027
    jne   sopl2
1026
    jne   sopl2
1028
    cmp   ebx,[esi+4]
1027
    cmp   ebx,[esi+4]
1029
    jb    sopl2
1028
    jb    sopl2
1030
    cmp   ebx,[esi+8]
1029
    cmp   ebx,[esi+8]
1031
    jg    sopl2
1030
    jg    sopl2
1032
    jmp   sopl3
1031
    jmp   sopl3
1033
 
1032
 
1034
  sopl2:
1033
  sopl2:
1035
 
1034
 
1036
    dec   ecx
1035
    dec   ecx
1037
    jnz   sopl1
1036
    jnz   sopl1
1038
    mov   [esp+36],dword 1
1037
    mov   [esp+36],dword 1
1039
    ret
1038
    ret
1040
 
1039
 
1041
  sopl3:
1040
  sopl3:
1042
 
1041
 
1043
    test  edi,0x80000000 ; read ?
1042
    test  edi,0x80000000 ; read ?
1044
    jnz   sopl4
1043
    jnz   sopl4
1045
 
1044
 
1046
    mov   dx,bx          ; write
1045
    mov   dx,bx          ; write
1047
    out   dx,al
1046
    out   dx,al
1048
    mov   [esp+36],dword 0
1047
    mov   [esp+36],dword 0
1049
    ret
1048
    ret
1050
 
1049
 
1051
  sopl4:
1050
  sopl4:
1052
 
1051
 
1053
    mov   dx,bx          ; read
1052
    mov   dx,bx          ; read
1054
    in    al,dx
1053
    in    al,dx
1055
    and   eax,0xff
1054
    and   eax,0xff
1056
    mov   [esp+36],dword 0
1055
    mov   [esp+36],dword 0
1057
    mov   [esp+24],eax
1056
    mov   [esp+24],eax
1058
    ret
1057
    ret
1059
 
1058
 
1060
 
1059
 
1061
 
1060
 
1062
align 4
1061
align 4
1063
sys_sb16:
1062
sys_sb16:
1064
 
1063
 
1065
     cmp  word [sb16],word 0
1064
     cmp  word [sb16],word 0
1066
     jnz  sb16l1
1065
     jnz  sb16l1
1067
     mov  [esp+36],dword 1
1066
     mov  [esp+36],dword 1
1068
     ret
1067
     ret
1069
   sb16l1:
1068
   sb16l1:
1070
     mov  [esp+36],dword 0
1069
     mov  [esp+36],dword 0
1071
     cmp  eax,1    ; set volume - main
1070
     cmp  eax,1    ; set volume - main
1072
     jnz  sb16l2
1071
     jnz  sb16l2
1073
     mov  dx,word [sb16]
1072
     mov  dx,word [sb16]
1074
     add  dx,4
1073
     add  dx,4
1075
     mov  al,0x22
1074
     mov  al,0x22
1076
     out  dx,al
1075
     out  dx,al
1077
     mov  esi,1
1076
     mov  esi,1
1078
     call delay_ms
1077
     call delay_ms
1079
     mov  eax,ebx
1078
     mov  eax,ebx
1080
     inc  edx
1079
     inc  edx
1081
     out  dx,al
1080
     out  dx,al
1082
     ret
1081
     ret
1083
   sb16l2:
1082
   sb16l2:
1084
 
1083
 
1085
     cmp  eax,2    ; set volume - cd
1084
     cmp  eax,2    ; set volume - cd
1086
     jnz  sb16l3
1085
     jnz  sb16l3
1087
     mov  dx,word [sb16]
1086
     mov  dx,word [sb16]
1088
     add  dx,4
1087
     add  dx,4
1089
     mov  al,0x28
1088
     mov  al,0x28
1090
     out  dx,al
1089
     out  dx,al
1091
     mov  esi,1
1090
     mov  esi,1
1092
     call delay_ms
1091
     call delay_ms
1093
     mov  eax,ebx
1092
     mov  eax,ebx
1094
     add  edx,1
1093
     add  edx,1
1095
     out  dx,al
1094
     out  dx,al
1096
     ret
1095
     ret
1097
   sb16l3:
1096
   sb16l3:
1098
      mov  [esp+36],dword 2
1097
      mov  [esp+36],dword 2
1099
      ret
1098
      ret
1100
 
1099
 
1101
 
1100
 
1102
align 4
1101
align 4
1103
 
1102
 
1104
sys_sb16II:
1103
sys_sb16II:
1105
 
1104
 
1106
     cmp  word [sb16],word 0
1105
     cmp  word [sb16],word 0
1107
     jnz  IIsb16l1
1106
     jnz  IIsb16l1
1108
     mov  [esp+36],dword 1
1107
     mov  [esp+36],dword 1
1109
     ret
1108
     ret
1110
   IIsb16l1:
1109
   IIsb16l1:
1111
 
1110
 
1112
     cmp  eax,1    ; set volume - main
1111
     cmp  eax,1    ; set volume - main
1113
     jnz  IIsb16l2
1112
     jnz  IIsb16l2
1114
     ; L
1113
     ; L
1115
     mov  dx,word [sb16]
1114
     mov  dx,word [sb16]
1116
     add  dx,4
1115
     add  dx,4
1117
     mov  al,0x30
1116
     mov  al,0x30
1118
     out  dx,al
1117
     out  dx,al
1119
     mov  eax,ebx
1118
     mov  eax,ebx
1120
     inc  edx
1119
     inc  edx
1121
     out  dx,al
1120
     out  dx,al
1122
     ; R
1121
     ; R
1123
     mov  dx,word [sb16]
1122
     mov  dx,word [sb16]
1124
     add  dx,4
1123
     add  dx,4
1125
     mov  al,0x31
1124
     mov  al,0x31
1126
     out  dx,al
1125
     out  dx,al
1127
     mov  eax,ebx
1126
     mov  eax,ebx
1128
     inc  edx
1127
     inc  edx
1129
     out  dx,al
1128
     out  dx,al
1130
     mov  [esp+36],dword 0
1129
     mov  [esp+36],dword 0
1131
     ret
1130
     ret
1132
   IIsb16l2:
1131
   IIsb16l2:
1133
 
1132
 
1134
     cmp  eax,2    ; set volume - cd
1133
     cmp  eax,2    ; set volume - cd
1135
     jnz  IIsb16l3
1134
     jnz  IIsb16l3
1136
     ; L
1135
     ; L
1137
     mov  dx,word [sb16]
1136
     mov  dx,word [sb16]
1138
     add  dx,4
1137
     add  dx,4
1139
     mov  al,0x36
1138
     mov  al,0x36
1140
     out  dx,al
1139
     out  dx,al
1141
     mov  eax,ebx
1140
     mov  eax,ebx
1142
     inc  edx
1141
     inc  edx
1143
     out  dx,al
1142
     out  dx,al
1144
     ; R
1143
     ; R
1145
     mov  dx,word [sb16]
1144
     mov  dx,word [sb16]
1146
     add  dx,4
1145
     add  dx,4
1147
     mov  al,0x37
1146
     mov  al,0x37
1148
     out  dx,al
1147
     out  dx,al
1149
     mov  eax,ebx
1148
     mov  eax,ebx
1150
     inc  edx
1149
     inc  edx
1151
     out  dx,al
1150
     out  dx,al
1152
     mov  [esp+36],dword 0
1151
     mov  [esp+36],dword 0
1153
     ret
1152
     ret
1154
   IIsb16l3:
1153
   IIsb16l3:
1155
 
1154
 
1156
     mov  [esp+36],dword 2
1155
     mov  [esp+36],dword 2
1157
     ret
1156
     ret
1158
 
1157
 
1159
 
1158
 
1160
display_number:
1159
display_number:
1161
 
1160
 
1162
; eax = print type, al=0 -> ebx is number
1161
; eax = print type, al=0 -> ebx is number
1163
;                   al=1 -> ebx is pointer
1162
;                   al=1 -> ebx is pointer
1164
;                   ah=0 -> display decimal
1163
;                   ah=0 -> display decimal
1165
;                   ah=1 -> display hexadecimal
1164
;                   ah=1 -> display hexadecimal
1166
;                   ah=2 -> display binary
1165
;                   ah=2 -> display binary
1167
;                   eax bits 16-21 = number of digits to display (0-32)
1166
;                   eax bits 16-21 = number of digits to display (0-32)
1168
;                   eax bits 22-31 = reserved
1167
;                   eax bits 22-31 = reserved
1169
;
1168
;
1170
; ebx = number or pointer
1169
; ebx = number or pointer
1171
; ecx = x shl 16 + y
1170
; ecx = x shl 16 + y
1172
; edx = color
1171
; edx = color
1173
        xor     edi, edi
1172
        xor     edi, edi
1174
display_number_force:
1173
display_number_force:
1175
 
1174
 
1176
     cmp   eax,0xffff            ; length > 0 ?
1175
     cmp   eax,0xffff            ; length > 0 ?
1177
     jge   cont_displ
1176
     jge   cont_displ
1178
     ret
1177
     ret
1179
   cont_displ:
1178
   cont_displ:
1180
 
1179
 
1181
     cmp   eax,61*0x10000        ; length <= 60 ?
1180
     cmp   eax,61*0x10000        ; length <= 60 ?
1182
     jb    cont_displ2
1181
     jb    cont_displ2
1183
     ret
1182
     ret
1184
   cont_displ2:
1183
   cont_displ2:
1185
 
1184
 
1186
     pushad
1185
     pushad
1187
 
1186
 
1188
     cmp   al,1                  ; ecx is a pointer ?
1187
     cmp   al,1                  ; ecx is a pointer ?
1189
     jne   displnl1
1188
     jne   displnl1
1190
     mov   ebx,[ebx+std_application_base_address]
1189
     mov   ebx,[ebx+std_application_base_address]
1191
   displnl1:
1190
   displnl1:
1192
     sub   esp,64
1191
     sub   esp,64
1193
 
1192
 
1194
     cmp   ah,0                  ; DECIMAL
1193
     cmp   ah,0                  ; DECIMAL
1195
     jne   no_display_desnum
1194
     jne   no_display_desnum
1196
     shr   eax,16
1195
     shr   eax,16
1197
     and   eax,0x3f
1196
     and   eax,0x3f
1198
     push  eax
1197
     push  eax
1199
     mov   edi,esp
1198
     mov   edi,esp
1200
     add   edi,4+64-1
1199
     add   edi,4+64-1
1201
     mov   ecx,eax
1200
     mov   ecx,eax
1202
     mov   eax,ebx
1201
     mov   eax,ebx
1203
     mov   ebx,10
1202
     mov   ebx,10
1204
   d_desnum:
1203
   d_desnum:
1205
     xor   edx,edx
1204
     xor   edx,edx
1206
     div   ebx
1205
     div   ebx
1207
     add   dl,48
1206
     add   dl,48
1208
     mov   [edi],dl
1207
     mov   [edi],dl
1209
     dec   edi
1208
     dec   edi
1210
     loop  d_desnum
1209
     loop  d_desnum
1211
     pop   eax
1210
     pop   eax
1212
     call  draw_num_text
1211
     call  draw_num_text
1213
     add   esp,64
1212
     add   esp,64
1214
     popad
1213
     popad
1215
     ret
1214
     ret
1216
   no_display_desnum:
1215
   no_display_desnum:
1217
 
1216
 
1218
     cmp   ah,0x01               ; HEXADECIMAL
1217
     cmp   ah,0x01               ; HEXADECIMAL
1219
     jne   no_display_hexnum
1218
     jne   no_display_hexnum
1220
     shr   eax,16
1219
     shr   eax,16
1221
     and   eax,0x3f
1220
     and   eax,0x3f
1222
     push  eax
1221
     push  eax
1223
     mov   edi,esp
1222
     mov   edi,esp
1224
     add   edi,4+64-1
1223
     add   edi,4+64-1
1225
     mov   ecx,eax
1224
     mov   ecx,eax
1226
     mov   eax,ebx
1225
     mov   eax,ebx
1227
     mov   ebx,16
1226
     mov   ebx,16
1228
   d_hexnum:
1227
   d_hexnum:
1229
     xor   edx,edx
1228
     xor   edx,edx
1230
     div   ebx
1229
     div   ebx
1231
     add   edx,hexletters
1230
     add   edx,hexletters
1232
     mov   dl,[edx]
1231
     mov   dl,[edx]
1233
     mov   [edi],dl
1232
     mov   [edi],dl
1234
     dec   edi
1233
     dec   edi
1235
     loop  d_hexnum
1234
     loop  d_hexnum
1236
     pop   eax
1235
     pop   eax
1237
     call  draw_num_text
1236
     call  draw_num_text
1238
     add   esp,64
1237
     add   esp,64
1239
     popad
1238
     popad
1240
     ret
1239
     ret
1241
   no_display_hexnum:
1240
   no_display_hexnum:
1242
 
1241
 
1243
     cmp   ah,0x02               ; BINARY
1242
     cmp   ah,0x02               ; BINARY
1244
     jne   no_display_binnum
1243
     jne   no_display_binnum
1245
     shr   eax,16
1244
     shr   eax,16
1246
     and   eax,0x3f
1245
     and   eax,0x3f
1247
     push  eax
1246
     push  eax
1248
     mov   edi,esp
1247
     mov   edi,esp
1249
     add   edi,4+64-1
1248
     add   edi,4+64-1
1250
     mov   ecx,eax
1249
     mov   ecx,eax
1251
     mov   eax,ebx
1250
     mov   eax,ebx
1252
     mov   ebx,2
1251
     mov   ebx,2
1253
   d_binnum:
1252
   d_binnum:
1254
     xor   edx,edx
1253
     xor   edx,edx
1255
     div   ebx
1254
     div   ebx
1256
     add   dl,48
1255
     add   dl,48
1257
     mov   [edi],dl
1256
     mov   [edi],dl
1258
     dec   edi
1257
     dec   edi
1259
     loop  d_binnum
1258
     loop  d_binnum
1260
     pop   eax
1259
     pop   eax
1261
     call  draw_num_text
1260
     call  draw_num_text
1262
     add   esp,64
1261
     add   esp,64
1263
     popad
1262
     popad
1264
     ret
1263
     ret
1265
   no_display_binnum:
1264
   no_display_binnum:
1266
 
1265
 
1267
     add   esp,64
1266
     add   esp,64
1268
     popad
1267
     popad
1269
     ret
1268
     ret
1270
 
1269
 
1271
 
1270
 
1272
draw_num_text:
1271
draw_num_text:
1273
 
1272
 
1274
     ; dtext
1273
     ; dtext
1275
     ;
1274
     ;
1276
     ; eax x & y
1275
     ; eax x & y
1277
     ; ebx color
1276
     ; ebx color
1278
     ; ecx start of text
1277
     ; ecx start of text
1279
     ; edx length
1278
     ; edx length
1280
     ; edi 1 force
1279
     ; edi 1 force
1281
 
1280
 
1282
;        mov     edi,[CURRENT_TASK]
1281
;        mov     edi,[CURRENT_TASK]
1283
;        shl     edi,8
1282
;        shl     edi,8
1284
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1283
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1285
;        rol     eax,16
1284
;        rol     eax,16
1286
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1285
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1287
;        rol     eax,16
1286
;        rol     eax,16
1288
 
1287
 
1289
     mov   edx,eax
1288
     mov   edx,eax
1290
     mov   ecx,64+4
1289
     mov   ecx,64+4
1291
     sub   ecx,eax
1290
     sub   ecx,eax
1292
     add   ecx,esp
1291
     add   ecx,esp
1293
     mov   eax,[esp+64+32-8+4]
1292
     mov   eax,[esp+64+32-8+4]
1294
     push  edx                       ; add window start x & y
1293
     push  edx                       ; add window start x & y
1295
     mov   edx,[TASK_BASE]
1294
     mov   edx,[TASK_BASE]
-
 
1295
 
-
 
1296
     mov   edi,[CURRENT_TASK]
-
 
1297
     shl   edi,8
-
 
1298
 
1296
     mov   ebx,[edx-twdw+WDATA.box.left]
1299
     mov   ebx,[edx-twdw+WDATA.box.left]
1297
     add   ebx, [(edx-CURRENT_TASK)*8+SLOT_BASE+APPDATA.wnd_clientbox.left]
1300
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1298
     shl   ebx,16
1301
     shl   ebx,16
1299
     add   ebx,[edx-twdw+WDATA.box.top]
1302
     add   ebx,[edx-twdw+WDATA.box.top]
1300
     add   ebx, [(edx-CURRENT_TASK)*8+SLOT_BASE+APPDATA.wnd_clientbox.top]
1303
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1301
     add   eax,ebx
1304
     add   eax,ebx
1302
     pop   edx
1305
     pop   edx
1303
     mov   ebx,[esp+64+32-12+4]
1306
     mov   ebx,[esp+64+32-12+4]
1304
        and     ebx, not 0x80000000     ; force counted string
1307
        and     ebx, not 0x80000000     ; force counted string
1305
        mov     esi, [esp+64+4+4]
1308
        mov     esi, [esp+64+4+4]
1306
        mov     edi, [esp+64+4]
1309
        mov     edi, [esp+64+4]
1307
     jmp   dtext
1310
     jmp   dtext
1308
 
1311
 
1309
read_string:
1312
read_string:
1310
 
1313
 
1311
    ; eax  read_area
1314
    ; eax  read_area
1312
    ; ebx  color of letter
1315
    ; ebx  color of letter
1313
    ; ecx  color of background
1316
    ; ecx  color of background
1314
    ; edx  number of letters to read
1317
    ; edx  number of letters to read
1315
    ; esi  [x start]*65536 + [y_start]
1318
    ; esi  [x start]*65536 + [y_start]
1316
 
1319
 
1317
    ret
1320
    ret
1318
 
1321
 
1319
 
1322
 
1320
align 4
1323
align 4
1321
 
1324
 
1322
sys_setup:
1325
sys_setup:
1323
 
1326
 
1324
; 1=roland mpu midi base , base io address
1327
; 1=roland mpu midi base , base io address
1325
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1328
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1326
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1329
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1327
; 4=sb16 base , base io address
1330
; 4=sb16 base , base io address
1328
; 5=system language, 1eng 2fi 3ger 4rus
1331
; 5=system language, 1eng 2fi 3ger 4rus
1329
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1332
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1330
; 8=fat32 partition in hd
1333
; 8=fat32 partition in hd
1331
; 9
1334
; 9
1332
; 10 = sound dma channel
1335
; 10 = sound dma channel
1333
; 11 = enable lba read
1336
; 11 = enable lba read
1334
; 12 = enable pci access
1337
; 12 = enable pci access
1335
 
1338
 
1336
 
1339
 
1337
     mov  [esp+36],dword 0
1340
     mov  [esp+36],dword 0
1338
     cmp  eax,1                      ; MIDI
1341
     cmp  eax,1                      ; MIDI
1339
     jnz  nsyse1
1342
     jnz  nsyse1
1340
     cmp  ebx,0x100
1343
     cmp  ebx,0x100
1341
     jb   nsyse1
1344
     jb   nsyse1
1342
     mov  edx,65535
1345
     mov  edx,65535
1343
     cmp  edx,ebx
1346
     cmp  edx,ebx
1344
     jb   nsyse1
1347
     jb   nsyse1
1345
     mov  [midi_base],bx
1348
     mov  [midi_base],bx
1346
     mov  word [mididp],bx
1349
     mov  word [mididp],bx
1347
     inc  bx
1350
     inc  bx
1348
     mov  word [midisp],bx
1351
     mov  word [midisp],bx
1349
     ret
1352
     ret
1350
 
1353
 
1351
iglobal
1354
iglobal
1352
midi_base dw 0
1355
midi_base dw 0
1353
endg
1356
endg
1354
 
1357
 
1355
   nsyse1:
1358
   nsyse1:
1356
 
1359
 
1357
     cmp  eax,2                      ; KEYBOARD
1360
     cmp  eax,2                      ; KEYBOARD
1358
     jnz  nsyse2
1361
     jnz  nsyse2
1359
     cmp  ebx,1
1362
     cmp  ebx,1
1360
     jnz  kbnobase
1363
     jnz  kbnobase
1361
     mov  edi,[TASK_BASE]
1364
     mov  edi,[TASK_BASE]
1362
     add  ecx,[edi+TASKDATA.mem_start]
1365
     add  ecx,[edi+TASKDATA.mem_start]
1363
     mov  eax,ecx
1366
     mov  eax,ecx
1364
     mov  ebx,keymap
1367
     mov  ebx,keymap
1365
     mov  ecx,128
1368
     mov  ecx,128
1366
     call memmove
1369
     call memmove
1367
     ret
1370
     ret
1368
   kbnobase:
1371
   kbnobase:
1369
     cmp  ebx,2
1372
     cmp  ebx,2
1370
     jnz  kbnoshift
1373
     jnz  kbnoshift
1371
     mov  edi,[TASK_BASE]
1374
     mov  edi,[TASK_BASE]
1372
     add  ecx,[edi+TASKDATA.mem_start]
1375
     add  ecx,[edi+TASKDATA.mem_start]
1373
     mov  eax,ecx
1376
     mov  eax,ecx
1374
     mov  ebx,keymap_shift
1377
     mov  ebx,keymap_shift
1375
     mov  ecx,128
1378
     mov  ecx,128
1376
     call memmove
1379
     call memmove
1377
     ret
1380
     ret
1378
   kbnoshift:
1381
   kbnoshift:
1379
     cmp  ebx,3
1382
     cmp  ebx,3
1380
     jne  kbnoalt
1383
     jne  kbnoalt
1381
     mov  edi,[TASK_BASE]
1384
     mov  edi,[TASK_BASE]
1382
     add  ecx,[edi+TASKDATA.mem_start]
1385
     add  ecx,[edi+TASKDATA.mem_start]
1383
     mov  eax,ecx
1386
     mov  eax,ecx
1384
     mov  ebx,keymap_alt
1387
     mov  ebx,keymap_alt
1385
     mov  ecx,128
1388
     mov  ecx,128
1386
     call memmove
1389
     call memmove
1387
     ret
1390
     ret
1388
   kbnoalt:
1391
   kbnoalt:
1389
     cmp  ebx,9
1392
     cmp  ebx,9
1390
     jnz  kbnocountry
1393
     jnz  kbnocountry
1391
     mov  word [keyboard],cx
1394
     mov  word [keyboard],cx
1392
     ret
1395
     ret
1393
   kbnocountry:
1396
   kbnocountry:
1394
     mov  [esp+36],dword 1
1397
     mov  [esp+36],dword 1
1395
     ret
1398
     ret
1396
   nsyse2:
1399
   nsyse2:
1397
     cmp  eax,3                      ; CD
1400
     cmp  eax,3                      ; CD
1398
     jnz  nsyse3
1401
     jnz  nsyse3
1399
     test ebx,ebx
1402
     test ebx,ebx
1400
     jz   nosesl
1403
     jz   nosesl
1401
     cmp  ebx, 4
1404
     cmp  ebx, 4
1402
     ja   nosesl
1405
     ja   nosesl
1403
     mov  [cd_base],bl
1406
     mov  [cd_base],bl
1404
     cmp  ebx,1
1407
     cmp  ebx,1
1405
     jnz  noprma
1408
     jnz  noprma
1406
     mov  [cdbase],0x1f0
1409
     mov  [cdbase],0x1f0
1407
     mov  [cdid],0xa0
1410
     mov  [cdid],0xa0
1408
   noprma:
1411
   noprma:
1409
     cmp  ebx,2
1412
     cmp  ebx,2
1410
     jnz  noprsl
1413
     jnz  noprsl
1411
     mov  [cdbase],0x1f0
1414
     mov  [cdbase],0x1f0
1412
     mov  [cdid],0xb0
1415
     mov  [cdid],0xb0
1413
   noprsl:
1416
   noprsl:
1414
     cmp  ebx,3
1417
     cmp  ebx,3
1415
     jnz  nosema
1418
     jnz  nosema
1416
     mov  [cdbase],0x170
1419
     mov  [cdbase],0x170
1417
     mov  [cdid],0xa0
1420
     mov  [cdid],0xa0
1418
   nosema:
1421
   nosema:
1419
     cmp  ebx,4
1422
     cmp  ebx,4
1420
     jnz  nosesl
1423
     jnz  nosesl
1421
     mov  [cdbase],0x170
1424
     mov  [cdbase],0x170
1422
     mov  [cdid],0xb0
1425
     mov  [cdid],0xb0
1423
   nosesl:
1426
   nosesl:
1424
     ret
1427
     ret
1425
 
1428
 
1426
cd_base db 0
1429
cd_base db 0
1427
 
1430
 
1428
   nsyse3:
1431
   nsyse3:
1429
 
1432
 
1430
     cmp  eax,4                      ; SB
1433
     cmp  eax,4                      ; SB
1431
     jnz  nsyse4
1434
     jnz  nsyse4
1432
     cmp  ebx,0x100
1435
     cmp  ebx,0x100
1433
     jb   nsyse4
1436
     jb   nsyse4
1434
     mov  edx,65535
1437
     mov  edx,65535
1435
     cmp  edx,ebx
1438
     cmp  edx,ebx
1436
     jb   nsyse4
1439
     jb   nsyse4
1437
     mov  word [sb16],bx
1440
     mov  word [sb16],bx
1438
     ret
1441
     ret
1439
   nsyse4:
1442
   nsyse4:
1440
 
1443
 
1441
     cmp  eax,5                      ; SYSTEM LANGUAGE
1444
     cmp  eax,5                      ; SYSTEM LANGUAGE
1442
     jnz  nsyse5
1445
     jnz  nsyse5
1443
     mov  [syslang],ebx
1446
     mov  [syslang],ebx
1444
     ret
1447
     ret
1445
   nsyse5:
1448
   nsyse5:
1446
 
1449
 
1447
     cmp  eax,7                      ; HD BASE
1450
     cmp  eax,7                      ; HD BASE
1448
     jne  nsyse7
1451
     jne  nsyse7
1449
     test ebx,ebx
1452
     test ebx,ebx
1450
     jz   nosethd
1453
     jz   nosethd
1451
     cmp  ebx,4
1454
     cmp  ebx,4
1452
     ja   nosethd
1455
     ja   nosethd
1453
     mov  [hd_base],bl
1456
     mov  [hd_base],bl
1454
     cmp  ebx,1
1457
     cmp  ebx,1
1455
     jnz  noprmahd
1458
     jnz  noprmahd
1456
     mov  [hdbase],0x1f0
1459
     mov  [hdbase],0x1f0
1457
     mov  [hdid],0x0
1460
     mov  [hdid],0x0
1458
     mov  [hdpos],1
1461
     mov  [hdpos],1
1459
;     call set_FAT32_variables
1462
;     call set_FAT32_variables
1460
   noprmahd:
1463
   noprmahd:
1461
     cmp  ebx,2
1464
     cmp  ebx,2
1462
     jnz  noprslhd
1465
     jnz  noprslhd
1463
     mov  [hdbase],0x1f0
1466
     mov  [hdbase],0x1f0
1464
     mov  [hdid],0x10
1467
     mov  [hdid],0x10
1465
     mov  [hdpos],2
1468
     mov  [hdpos],2
1466
;     call set_FAT32_variables
1469
;     call set_FAT32_variables
1467
   noprslhd:
1470
   noprslhd:
1468
     cmp  ebx,3
1471
     cmp  ebx,3
1469
     jnz  nosemahd
1472
     jnz  nosemahd
1470
     mov  [hdbase],0x170
1473
     mov  [hdbase],0x170
1471
     mov  [hdid],0x0
1474
     mov  [hdid],0x0
1472
     mov  [hdpos],3
1475
     mov  [hdpos],3
1473
;     call set_FAT32_variables
1476
;     call set_FAT32_variables
1474
   nosemahd:
1477
   nosemahd:
1475
     cmp  ebx,4
1478
     cmp  ebx,4
1476
     jnz  noseslhd
1479
     jnz  noseslhd
1477
     mov  [hdbase],0x170
1480
     mov  [hdbase],0x170
1478
     mov  [hdid],0x10
1481
     mov  [hdid],0x10
1479
     mov  [hdpos],4
1482
     mov  [hdpos],4
1480
;     call set_FAT32_variables
1483
;     call set_FAT32_variables
1481
   noseslhd:
1484
   noseslhd:
1482
    call  reserve_hd1
1485
    call  reserve_hd1
1483
    call  reserve_hd_channel
1486
    call  reserve_hd_channel
1484
    call  free_hd_channel
1487
    call  free_hd_channel
1485
    mov   [hd1_status],0        ; free
1488
    mov   [hd1_status],0        ; free
1486
   nosethd:
1489
   nosethd:
1487
     ret
1490
     ret
1488
 
1491
 
1489
iglobal
1492
iglobal
1490
hd_base db 0
1493
hd_base db 0
1491
endg
1494
endg
1492
 
1495
 
1493
   nsyse7:
1496
   nsyse7:
1494
 
1497
 
1495
     cmp  eax,8                      ; HD PARTITION
1498
     cmp  eax,8                      ; HD PARTITION
1496
     jne  nsyse8
1499
     jne  nsyse8
1497
     mov  [fat32part],ebx
1500
     mov  [fat32part],ebx
1498
;     call set_FAT32_variables
1501
;     call set_FAT32_variables
1499
    call  reserve_hd1
1502
    call  reserve_hd1
1500
    call  reserve_hd_channel
1503
    call  reserve_hd_channel
1501
    call  free_hd_channel
1504
    call  free_hd_channel
1502
     pusha
1505
     pusha
1503
     call  choice_necessity_partition_1
1506
     call  choice_necessity_partition_1
1504
     popa
1507
     popa
1505
    mov   [hd1_status],0        ; free
1508
    mov   [hd1_status],0        ; free
1506
     ret
1509
     ret
1507
   nsyse8:
1510
   nsyse8:
1508
 
1511
 
1509
     cmp  eax,10                     ; SOUND DMA CHANNEL
1512
     cmp  eax,10                     ; SOUND DMA CHANNEL
1510
     jne  no_set_sound_dma
1513
     jne  no_set_sound_dma
1511
     cmp  ebx,3
1514
     cmp  ebx,3
1512
     ja   sys_setup_err
1515
     ja   sys_setup_err
1513
     mov  [sound_dma],ebx
1516
     mov  [sound_dma],ebx
1514
     ret
1517
     ret
1515
   no_set_sound_dma:
1518
   no_set_sound_dma:
1516
 
1519
 
1517
     cmp  eax,11                     ; ENABLE LBA READ
1520
     cmp  eax,11                     ; ENABLE LBA READ
1518
     jne  no_set_lba_read
1521
     jne  no_set_lba_read
1519
     and  ebx,1
1522
     and  ebx,1
1520
     mov  [lba_read_enabled],ebx
1523
     mov  [lba_read_enabled],ebx
1521
     ret
1524
     ret
1522
   no_set_lba_read:
1525
   no_set_lba_read:
1523
 
1526
 
1524
     cmp  eax,12                     ; ENABLE PCI ACCESS
1527
     cmp  eax,12                     ; ENABLE PCI ACCESS
1525
     jne  no_set_pci_access
1528
     jne  no_set_pci_access
1526
     and  ebx,1
1529
     and  ebx,1
1527
     mov  [pci_access_enabled],ebx
1530
     mov  [pci_access_enabled],ebx
1528
     ret
1531
     ret
1529
   no_set_pci_access:
1532
   no_set_pci_access:
1530
 
1533
 
1531
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1534
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1532
include 'vmodeint.inc'
1535
include 'vmodeint.inc'
1533
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1536
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1534
 
1537
 
1535
sys_setup_err:
1538
sys_setup_err:
1536
     mov  [esp+36],dword -1
1539
     mov  [esp+36],dword -1
1537
     ret
1540
     ret
1538
 
1541
 
1539
 
1542
 
1540
align 4
1543
align 4
1541
 
1544
 
1542
sys_getsetup:
1545
sys_getsetup:
1543
 
1546
 
1544
; 1=roland mpu midi base , base io address
1547
; 1=roland mpu midi base , base io address
1545
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1548
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1546
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1549
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1547
; 4=sb16 base , base io address
1550
; 4=sb16 base , base io address
1548
; 5=system language, 1eng 2fi 3ger 4rus
1551
; 5=system language, 1eng 2fi 3ger 4rus
1549
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1552
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1550
; 8=fat32 partition in hd
1553
; 8=fat32 partition in hd
1551
; 9=get hs timer tic
1554
; 9=get hs timer tic
1552
 
1555
 
1553
     cmp  eax,1
1556
     cmp  eax,1
1554
     jne  ngsyse1
1557
     jne  ngsyse1
1555
     movzx eax,[midi_base]
1558
     movzx eax,[midi_base]
1556
     mov  [esp+36],eax
1559
     mov  [esp+36],eax
1557
     ret
1560
     ret
1558
   ngsyse1:
1561
   ngsyse1:
1559
 
1562
 
1560
     cmp  eax,2
1563
     cmp  eax,2
1561
     jne  ngsyse2
1564
     jne  ngsyse2
1562
     cmp  ebx,1
1565
     cmp  ebx,1
1563
     jnz  kbnobaseret
1566
     jnz  kbnobaseret
1564
     mov  edi,[TASK_BASE]
1567
     mov  edi,[TASK_BASE]
1565
     add  ecx,[edi+TASKDATA.mem_start]
1568
     add  ecx,[edi+TASKDATA.mem_start]
1566
     mov  ebx,ecx
1569
     mov  ebx,ecx
1567
     mov  eax,keymap
1570
     mov  eax,keymap
1568
     mov  ecx,128
1571
     mov  ecx,128
1569
     call memmove
1572
     call memmove
1570
     ret
1573
     ret
1571
   kbnobaseret:
1574
   kbnobaseret:
1572
     cmp  ebx,2
1575
     cmp  ebx,2
1573
     jnz  kbnoshiftret
1576
     jnz  kbnoshiftret
1574
     mov  edi,[TASK_BASE]
1577
     mov  edi,[TASK_BASE]
1575
     add  ecx,[edi+TASKDATA.mem_start]
1578
     add  ecx,[edi+TASKDATA.mem_start]
1576
     mov  ebx,ecx
1579
     mov  ebx,ecx
1577
     mov  eax,keymap_shift
1580
     mov  eax,keymap_shift
1578
     mov  ecx,128
1581
     mov  ecx,128
1579
     call memmove
1582
     call memmove
1580
     ret
1583
     ret
1581
   kbnoshiftret:
1584
   kbnoshiftret:
1582
     cmp  ebx,3
1585
     cmp  ebx,3
1583
     jne  kbnoaltret
1586
     jne  kbnoaltret
1584
     mov  edi,[TASK_BASE]
1587
     mov  edi,[TASK_BASE]
1585
     add  ecx,[edi+TASKDATA.mem_start]
1588
     add  ecx,[edi+TASKDATA.mem_start]
1586
     mov  ebx,ecx
1589
     mov  ebx,ecx
1587
     mov  eax,keymap_alt
1590
     mov  eax,keymap_alt
1588
     mov  ecx,128
1591
     mov  ecx,128
1589
     call memmove
1592
     call memmove
1590
     ret
1593
     ret
1591
   kbnoaltret:
1594
   kbnoaltret:
1592
     cmp  ebx,9
1595
     cmp  ebx,9
1593
     jnz  ngsyse2
1596
     jnz  ngsyse2
1594
     movzx eax,word [keyboard]
1597
     movzx eax,word [keyboard]
1595
     mov  [esp+36],eax
1598
     mov  [esp+36],eax
1596
     ret
1599
     ret
1597
   ngsyse2:
1600
   ngsyse2:
1598
 
1601
 
1599
     cmp  eax,3
1602
     cmp  eax,3
1600
     jnz  ngsyse3
1603
     jnz  ngsyse3
1601
     movzx eax,[cd_base]
1604
     movzx eax,[cd_base]
1602
     mov  [esp+36],eax
1605
     mov  [esp+36],eax
1603
     ret
1606
     ret
1604
   ngsyse3:
1607
   ngsyse3:
1605
 
1608
 
1606
     cmp  eax,4
1609
     cmp  eax,4
1607
     jne  ngsyse4
1610
     jne  ngsyse4
1608
     mov  eax,[sb16]
1611
     mov  eax,[sb16]
1609
     mov  [esp+36],eax
1612
     mov  [esp+36],eax
1610
     ret
1613
     ret
1611
   ngsyse4:
1614
   ngsyse4:
1612
 
1615
 
1613
     cmp  eax,5
1616
     cmp  eax,5
1614
     jnz  ngsyse5
1617
     jnz  ngsyse5
1615
     mov  eax,[syslang]
1618
     mov  eax,[syslang]
1616
     mov  [esp+36],eax
1619
     mov  [esp+36],eax
1617
     ret
1620
     ret
1618
   ngsyse5:
1621
   ngsyse5:
1619
     cmp  eax,7
1622
     cmp  eax,7
1620
     jnz  ngsyse7
1623
     jnz  ngsyse7
1621
     movzx eax,[hd_base]
1624
     movzx eax,[hd_base]
1622
     mov  [esp+36],eax
1625
     mov  [esp+36],eax
1623
     ret
1626
     ret
1624
   ngsyse7:
1627
   ngsyse7:
1625
     cmp  eax,8
1628
     cmp  eax,8
1626
     jnz  ngsyse8
1629
     jnz  ngsyse8
1627
     mov eax,[fat32part]
1630
     mov eax,[fat32part]
1628
     mov  [esp+36],eax
1631
     mov  [esp+36],eax
1629
     ret
1632
     ret
1630
   ngsyse8:
1633
   ngsyse8:
1631
     cmp  eax,9
1634
     cmp  eax,9
1632
     jne  ngsyse9
1635
     jne  ngsyse9
1633
     mov  eax,[timer_ticks] ;[0xfdf0]
1636
     mov  eax,[timer_ticks] ;[0xfdf0]
1634
     mov  [esp+36],eax
1637
     mov  [esp+36],eax
1635
     ret
1638
     ret
1636
   ngsyse9:
1639
   ngsyse9:
1637
     cmp  eax,10
1640
     cmp  eax,10
1638
     jnz  ngsyse10
1641
     jnz  ngsyse10
1639
     mov eax,[sound_dma]
1642
     mov eax,[sound_dma]
1640
     mov  [esp+36],eax
1643
     mov  [esp+36],eax
1641
     ret
1644
     ret
1642
   ngsyse10:
1645
   ngsyse10:
1643
     cmp  eax,11
1646
     cmp  eax,11
1644
     jnz  ngsyse11
1647
     jnz  ngsyse11
1645
     mov eax,[lba_read_enabled]
1648
     mov eax,[lba_read_enabled]
1646
     mov  [esp+36],eax
1649
     mov  [esp+36],eax
1647
     ret
1650
     ret
1648
   ngsyse11:
1651
   ngsyse11:
1649
     cmp  eax,12
1652
     cmp  eax,12
1650
     jnz  ngsyse12
1653
     jnz  ngsyse12
1651
     mov eax,[pci_access_enabled]
1654
     mov eax,[pci_access_enabled]
1652
     mov  [esp+36],eax
1655
     mov  [esp+36],eax
1653
     ret
1656
     ret
1654
   ngsyse12:
1657
   ngsyse12:
1655
     mov  [esp+36],dword 1
1658
     mov  [esp+36],dword 1
1656
     ret
1659
     ret
1657
 
1660
 
1658
iglobal
1661
iglobal
1659
align 4
1662
align 4
1660
mousefn dd msscreen, mswin, msbutton, msset
1663
mousefn dd msscreen, mswin, msbutton, msset
1661
        dd app_load_cursor
1664
        dd app_load_cursor
1662
        dd app_set_cursor
1665
        dd app_set_cursor
1663
        dd app_delete_cursor
1666
        dd app_delete_cursor
1664
endg
1667
endg
1665
 
1668
 
1666
readmousepos:
1669
readmousepos:
1667
 
1670
 
1668
; eax=0 screen relative
1671
; eax=0 screen relative
1669
; eax=1 window relative
1672
; eax=1 window relative
1670
; eax=2 buttons pressed
1673
; eax=2 buttons pressed
1671
; eax=3 set mouse pos   ; reserved
1674
; eax=3 set mouse pos   ; reserved
1672
; eax=4 load cursor
1675
; eax=4 load cursor
1673
; eax=5 set cursor
1676
; eax=5 set cursor
1674
; eax=6 delete cursor   ; reserved
1677
; eax=6 delete cursor   ; reserved
1675
 
1678
 
1676
           cmp eax, 6
1679
           cmp eax, 6
1677
           ja msset
1680
           ja msset
1678
           jmp [mousefn+eax*4]
1681
           jmp [mousefn+eax*4]
1679
msscreen:
1682
msscreen:
1680
           mov  eax,[MOUSE_X]
1683
           mov  eax,[MOUSE_X]
1681
           shl  eax,16
1684
           shl  eax,16
1682
           mov  ax,[MOUSE_Y]
1685
           mov  ax,[MOUSE_Y]
1683
           mov  [esp+36],eax
1686
           mov  [esp+36],eax
1684
           ret
1687
           ret
1685
mswin:
1688
mswin:
1686
           mov  eax,[MOUSE_X]
1689
           mov  eax,[MOUSE_X]
1687
           shl  eax,16
1690
           shl  eax,16
1688
           mov  ax,[MOUSE_Y]
1691
           mov  ax,[MOUSE_Y]
1689
           mov  esi,[TASK_BASE]
1692
           mov  esi,[TASK_BASE]
1690
           mov  bx, word [esi-twdw+WDATA.box.left]
1693
           mov  bx, word [esi-twdw+WDATA.box.left]
1691
           shl  ebx,16
1694
           shl  ebx,16
1692
           mov  bx, word [esi-twdw+WDATA.box.top]
1695
           mov  bx, word [esi-twdw+WDATA.box.top]
1693
           sub  eax,ebx
1696
           sub  eax,ebx
1694
 
1697
 
1695
           mov  edi,[CURRENT_TASK]
1698
           mov  edi,[CURRENT_TASK]
1696
           shl  edi,8
1699
           shl  edi,8
1697
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1700
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1698
           rol  eax,16
1701
           rol  eax,16
1699
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1702
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1700
           rol  eax,16
1703
           rol  eax,16
1701
           mov  [esp+36],eax
1704
           mov  [esp+36],eax
1702
           ret
1705
           ret
1703
msbutton:
1706
msbutton:
1704
           movzx eax,byte [BTN_DOWN]
1707
           movzx eax,byte [BTN_DOWN]
1705
           mov  [esp+36],eax
1708
           mov  [esp+36],eax
1706
           ret
1709
           ret
1707
msset:
1710
msset:
1708
           ret
1711
           ret
1709
 
1712
 
1710
app_load_cursor:
1713
app_load_cursor:
1711
           add ebx, new_app_base
1714
           add ebx, new_app_base
1712
           cmp ebx, new_app_base
1715
           cmp ebx, new_app_base
1713
           jb msset
1716
           jb msset
1714
           stdcall load_cursor, ebx, ecx
1717
           stdcall load_cursor, ebx, ecx
1715
           mov [esp+36], eax
1718
           mov [esp+36], eax
1716
           ret
1719
           ret
1717
 
1720
 
1718
app_set_cursor:
1721
app_set_cursor:
1719
           stdcall set_cursor, ebx
1722
           stdcall set_cursor, ebx
1720
           mov [esp+36], eax
1723
           mov [esp+36], eax
1721
           ret
1724
           ret
1722
 
1725
 
1723
app_delete_cursor:
1726
app_delete_cursor:
1724
           stdcall delete_cursor, ebx
1727
           stdcall delete_cursor, ebx
1725
           mov [esp+36], eax
1728
           mov [esp+36], eax
1726
           ret
1729
           ret
1727
 
1730
 
1728
is_input:
1731
is_input:
1729
 
1732
 
1730
   push edx
1733
   push edx
1731
   mov  dx,word [midisp]
1734
   mov  dx,word [midisp]
1732
   in   al,dx
1735
   in   al,dx
1733
   and  al,0x80
1736
   and  al,0x80
1734
   pop  edx
1737
   pop  edx
1735
   ret
1738
   ret
1736
 
1739
 
1737
is_output:
1740
is_output:
1738
 
1741
 
1739
   push edx
1742
   push edx
1740
   mov  dx,word [midisp]
1743
   mov  dx,word [midisp]
1741
   in   al,dx
1744
   in   al,dx
1742
   and  al,0x40
1745
   and  al,0x40
1743
   pop  edx
1746
   pop  edx
1744
   ret
1747
   ret
1745
 
1748
 
1746
 
1749
 
1747
get_mpu_in:
1750
get_mpu_in:
1748
 
1751
 
1749
   push edx
1752
   push edx
1750
   mov  dx,word [mididp]
1753
   mov  dx,word [mididp]
1751
   in   al,dx
1754
   in   al,dx
1752
   pop  edx
1755
   pop  edx
1753
   ret
1756
   ret
1754
 
1757
 
1755
 
1758
 
1756
put_mpu_out:
1759
put_mpu_out:
1757
 
1760
 
1758
   push edx
1761
   push edx
1759
   mov  dx,word [mididp]
1762
   mov  dx,word [mididp]
1760
   out  dx,al
1763
   out  dx,al
1761
   pop  edx
1764
   pop  edx
1762
   ret
1765
   ret
1763
 
1766
 
1764
 
1767
 
1765
setuart:
1768
setuart:
1766
 
1769
 
1767
 su1:
1770
 su1:
1768
   call is_output
1771
   call is_output
1769
   cmp  al,0
1772
   cmp  al,0
1770
   jnz  su1
1773
   jnz  su1
1771
   mov  dx,word [midisp]
1774
   mov  dx,word [midisp]
1772
   mov  al,0xff
1775
   mov  al,0xff
1773
   out  dx,al
1776
   out  dx,al
1774
 su2:
1777
 su2:
1775
   mov  dx,word [midisp]
1778
   mov  dx,word [midisp]
1776
   mov  al,0xff
1779
   mov  al,0xff
1777
   out  dx,al
1780
   out  dx,al
1778
   call is_input
1781
   call is_input
1779
   cmp  al,0
1782
   cmp  al,0
1780
   jnz  su2
1783
   jnz  su2
1781
   call get_mpu_in
1784
   call get_mpu_in
1782
   cmp  al,0xfe
1785
   cmp  al,0xfe
1783
   jnz  su2
1786
   jnz  su2
1784
 su3:
1787
 su3:
1785
   call is_output
1788
   call is_output
1786
   cmp  al,0
1789
   cmp  al,0
1787
   jnz  su3
1790
   jnz  su3
1788
   mov  dx,word [midisp]
1791
   mov  dx,word [midisp]
1789
   mov  al,0x3f
1792
   mov  al,0x3f
1790
   out  dx,al
1793
   out  dx,al
1791
 
1794
 
1792
   ret
1795
   ret
1793
 
1796
 
1794
 
1797
 
1795
align 4
1798
align 4
1796
 
1799
 
1797
sys_midi:
1800
sys_midi:
1798
 
1801
 
1799
     cmp  [mididp],0
1802
     cmp  [mididp],0
1800
     jnz  sm0
1803
     jnz  sm0
1801
     mov  [esp+36],dword 1
1804
     mov  [esp+36],dword 1
1802
     ret
1805
     ret
1803
   sm0:
1806
   sm0:
1804
 
1807
 
1805
     cmp  eax,1
1808
     cmp  eax,1
1806
     mov  [esp+36],dword 0
1809
     mov  [esp+36],dword 0
1807
     jnz  smn1
1810
     jnz  smn1
1808
     call setuart
1811
     call setuart
1809
     ret
1812
     ret
1810
   smn1:
1813
   smn1:
1811
 
1814
 
1812
     cmp  eax,2
1815
     cmp  eax,2
1813
     jnz  smn2
1816
     jnz  smn2
1814
   sm10:
1817
   sm10:
1815
     call get_mpu_in
1818
     call get_mpu_in
1816
     call is_output
1819
     call is_output
1817
     test al,al
1820
     test al,al
1818
     jnz  sm10
1821
     jnz  sm10
1819
     mov  al,bl
1822
     mov  al,bl
1820
     call put_mpu_out
1823
     call put_mpu_out
1821
     ret
1824
     ret
1822
   smn2:
1825
   smn2:
1823
 
1826
 
1824
     ret
1827
     ret
1825
 
1828
 
1826
 
1829
 
1827
detect_devices:
1830
detect_devices:
1828
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1831
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1829
include 'detect/commouse.inc'
1832
include 'detect/commouse.inc'
1830
include 'detect/ps2mouse.inc'
1833
include 'detect/ps2mouse.inc'
1831
;include 'detect/dev_fd.inc'
1834
;include 'detect/dev_fd.inc'
1832
;include 'detect/dev_hdcd.inc'
1835
;include 'detect/dev_hdcd.inc'
1833
;include 'detect/sear_par.inc'
1836
;include 'detect/sear_par.inc'
1834
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1837
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1835
    ret
1838
    ret
1836
 
1839
 
1837
 
1840
 
1838
sys_end:
1841
sys_end:
1839
 
1842
 
1840
     mov   eax,[TASK_BASE]
1843
     mov   eax,[TASK_BASE]
1841
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1844
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1842
 
1845
 
1843
    waitterm:            ; wait here for termination
1846
    waitterm:            ; wait here for termination
1844
     mov   eax,5
1847
     mov   eax,5
1845
     call  delay_hs
1848
     call  delay_hs
1846
     jmp   waitterm
1849
     jmp   waitterm
1847
 
1850
 
1848
iglobal
1851
iglobal
1849
align 4
1852
align 4
1850
sys_system_table:
1853
sys_system_table:
1851
        dd      sysfn_shutdown          ; 1 = system shutdown
1854
        dd      sysfn_shutdown          ; 1 = system shutdown
1852
        dd      sysfn_terminate         ; 2 = terminate thread
1855
        dd      sysfn_terminate         ; 2 = terminate thread
1853
        dd      sysfn_activate          ; 3 = activate window
1856
        dd      sysfn_activate          ; 3 = activate window
1854
        dd      sysfn_getidletime       ; 4 = get idle time
1857
        dd      sysfn_getidletime       ; 4 = get idle time
1855
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1858
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1856
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1859
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1857
        dd      sysfn_getactive         ; 7 = get active window
1860
        dd      sysfn_getactive         ; 7 = get active window
1858
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1861
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1859
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
1862
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
1860
        dd      sysfn_minimize          ; 10 = minimize window
1863
        dd      sysfn_minimize          ; 10 = minimize window
1861
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1864
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1862
        dd      sysfn_lastkey           ; 12 = get last pressed key
1865
        dd      sysfn_lastkey           ; 12 = get last pressed key
1863
        dd      sysfn_getversion        ; 13 = get kernel version
1866
        dd      sysfn_getversion        ; 13 = get kernel version
1864
        dd      sysfn_waitretrace       ; 14 = wait retrace
1867
        dd      sysfn_waitretrace       ; 14 = wait retrace
1865
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1868
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1866
        dd      sysfn_getfreemem        ; 16 = get free memory size
1869
        dd      sysfn_getfreemem        ; 16 = get free memory size
1867
        dd      sysfn_getallmem         ; 17 = get total memory size
1870
        dd      sysfn_getallmem         ; 17 = get total memory size
1868
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1871
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1869
                                        ;                 instead of slot
1872
                                        ;                 instead of slot
1870
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1873
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1871
        dd      sysfn_meminfo           ; 20 = get extended memory info
1874
        dd      sysfn_meminfo           ; 20 = get extended memory info
1872
sysfn_num = ($ - sys_system_table)/4
1875
sysfn_num = ($ - sys_system_table)/4
1873
endg
1876
endg
1874
 
1877
 
1875
sys_system:
1878
sys_system:
1876
        dec     eax
1879
        dec     eax
1877
        cmp     eax, sysfn_num
1880
        cmp     eax, sysfn_num
1878
        jae     @f
1881
        jae     @f
1879
        jmp     dword [sys_system_table + eax*4]
1882
        jmp     dword [sys_system_table + eax*4]
1880
@@:
1883
@@:
1881
        ret
1884
        ret
1882
 
1885
 
1883
sysfn_shutdown:         ; 18.1 = BOOT
1886
sysfn_shutdown:         ; 18.1 = BOOT
1884
     mov  [BOOT_VAR+0x9030],byte 0
1887
     mov  [BOOT_VAR+0x9030],byte 0
1885
  for_shutdown_parameter:
1888
  for_shutdown_parameter:
1886
 
1889
 
1887
     mov  eax,[TASK_COUNT]
1890
     mov  eax,[TASK_COUNT]
1888
     add  eax,2
1891
     add  eax,2
1889
     mov  [shutdown_processes],eax
1892
     mov  [shutdown_processes],eax
1890
     mov  [SYS_SHUTDOWN],al
1893
     mov  [SYS_SHUTDOWN],al
1891
     and  dword [esp+36], 0
1894
     and  dword [esp+36], 0
1892
     ret
1895
     ret
1893
  uglobal
1896
  uglobal
1894
   shutdown_processes: dd 0x0
1897
   shutdown_processes: dd 0x0
1895
  endg
1898
  endg
1896
 
1899
 
1897
sysfn_terminate:        ; 18.2 = TERMINATE
1900
sysfn_terminate:        ; 18.2 = TERMINATE
1898
     cmp  ebx,2
1901
     cmp  ebx,2
1899
     jb   noprocessterminate
1902
     jb   noprocessterminate
1900
     mov  edx,[TASK_COUNT]
1903
     mov  edx,[TASK_COUNT]
1901
     cmp  ebx,edx
1904
     cmp  ebx,edx
1902
     ja   noprocessterminate
1905
     ja   noprocessterminate
1903
     mov  eax,[TASK_COUNT]
1906
     mov  eax,[TASK_COUNT]
1904
     shl  ebx,5
1907
     shl  ebx,5
1905
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
1908
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
1906
     add  ebx,CURRENT_TASK+TASKDATA.state
1909
     add  ebx,CURRENT_TASK+TASKDATA.state
1907
     cmp  byte [ebx], 9
1910
     cmp  byte [ebx], 9
1908
     jz   noprocessterminate
1911
     jz   noprocessterminate
1909
 
1912
 
1910
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1913
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1911
     mov  [ebx],byte 3       ; clear possible i40's
1914
     mov  [ebx],byte 3       ; clear possible i40's
1912
     ;call MEM_Heap_UnLock
1915
     ;call MEM_Heap_UnLock
1913
 
1916
 
1914
     cmp  edx,[application_table_status]    ; clear app table stat
1917
     cmp  edx,[application_table_status]    ; clear app table stat
1915
     jne  noatsc
1918
     jne  noatsc
1916
     mov  [application_table_status],0
1919
     mov  [application_table_status],0
1917
   noatsc:
1920
   noatsc:
1918
   noprocessterminate:
1921
   noprocessterminate:
1919
     ret
1922
     ret
1920
 
1923
 
1921
sysfn_terminate2:
1924
sysfn_terminate2:
1922
;lock application_table_status mutex
1925
;lock application_table_status mutex
1923
.table_status:
1926
.table_status:
1924
    cli
1927
    cli
1925
    cmp    [application_table_status],0
1928
    cmp    [application_table_status],0
1926
    je     .stf
1929
    je     .stf
1927
    sti
1930
    sti
1928
    call   change_task
1931
    call   change_task
1929
    jmp    .table_status
1932
    jmp    .table_status
1930
.stf:
1933
.stf:
1931
    call   set_application_table_status
1934
    call   set_application_table_status
1932
    mov    eax,ebx
1935
    mov    eax,ebx
1933
    call   pid_to_slot
1936
    call   pid_to_slot
1934
    test   eax,eax
1937
    test   eax,eax
1935
    jz     .not_found
1938
    jz     .not_found
1936
    mov    ebx,eax
1939
    mov    ebx,eax
1937
    cli
1940
    cli
1938
    call   sysfn_terminate
1941
    call   sysfn_terminate
1939
    mov    [application_table_status],0
1942
    mov    [application_table_status],0
1940
    sti
1943
    sti
1941
    and    dword [esp+36],0
1944
    and    dword [esp+36],0
1942
    ret
1945
    ret
1943
.not_found:
1946
.not_found:
1944
    mov    [application_table_status],0
1947
    mov    [application_table_status],0
1945
    or     dword [esp+36],-1
1948
    or     dword [esp+36],-1
1946
    ret
1949
    ret
1947
 
1950
 
1948
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
1951
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
1949
     cmp  ebx,2
1952
     cmp  ebx,2
1950
     jb   .nowindowactivate
1953
     jb   .nowindowactivate
1951
     cmp  ebx,[TASK_COUNT]
1954
     cmp  ebx,[TASK_COUNT]
1952
     ja   .nowindowactivate
1955
     ja   .nowindowactivate
1953
 
1956
 
1954
     mov   [window_minimize], 2   ; restore window if minimized
1957
     mov   [window_minimize], 2   ; restore window if minimized
1955
 
1958
 
1956
     movzx esi, word [WIN_STACK + ebx*2]
1959
     movzx esi, word [WIN_STACK + ebx*2]
1957
     cmp   esi, [TASK_COUNT]
1960
     cmp   esi, [TASK_COUNT]
1958
     je    .nowindowactivate ; already active
1961
     je    .nowindowactivate ; already active
1959
 
1962
 
1960
     mov   edi, ebx
1963
     mov   edi, ebx
1961
     shl   edi, 5
1964
     shl   edi, 5
1962
     add   edi, window_data
1965
     add   edi, window_data
1963
     movzx esi, word [WIN_STACK + ebx * 2]
1966
     movzx esi, word [WIN_STACK + ebx * 2]
1964
     lea   esi, [WIN_POS + esi * 2]
1967
     lea   esi, [WIN_POS + esi * 2]
1965
     call  waredraw
1968
     call  waredraw
1966
.nowindowactivate:
1969
.nowindowactivate:
1967
     ret
1970
     ret
1968
 
1971
 
1969
sysfn_getidletime:              ; 18.4 = GET IDLETIME
1972
sysfn_getidletime:              ; 18.4 = GET IDLETIME
1970
     mov  eax,[idleusesec]
1973
     mov  eax,[idleusesec]
1971
     mov  [esp+36], eax
1974
     mov  [esp+36], eax
1972
     ret
1975
     ret
1973
 
1976
 
1974
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
1977
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
1975
     mov  eax,[CPU_FREQ]
1978
     mov  eax,[CPU_FREQ]
1976
     mov  [esp+36], eax
1979
     mov  [esp+36], eax
1977
     ret
1980
     ret
1978
 
1981
 
1979
;  SAVE ramdisk to /hd/1/menuet.img
1982
;  SAVE ramdisk to /hd/1/menuet.img
1980
;!!!!!!!!!!!!!!!!!!!!!!!!
1983
;!!!!!!!!!!!!!!!!!!!!!!!!
1981
   include 'blkdev/rdsave.inc'
1984
   include 'blkdev/rdsave.inc'
1982
;!!!!!!!!!!!!!!!!!!!!!!!!
1985
;!!!!!!!!!!!!!!!!!!!!!!!!
1983
 
1986
 
1984
sysfn_getactive:        ; 18.7 = get active window
1987
sysfn_getactive:        ; 18.7 = get active window
1985
     mov  eax, [TASK_COUNT]
1988
     mov  eax, [TASK_COUNT]
1986
   movzx  eax, word [WIN_POS + eax*2]
1989
   movzx  eax, word [WIN_POS + eax*2]
1987
     mov  [esp+36],eax
1990
     mov  [esp+36],eax
1988
     ret
1991
     ret
1989
 
1992
 
1990
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1993
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1991
     cmp  ebx,1
1994
     cmp  ebx,1
1992
     jne  nogetsoundflag
1995
     jne  nogetsoundflag
1993
     movzx  eax,byte [sound_flag] ; get sound_flag
1996
     movzx  eax,byte [sound_flag] ; get sound_flag
1994
     mov  [esp+36],eax
1997
     mov  [esp+36],eax
1995
     ret
1998
     ret
1996
 nogetsoundflag:
1999
 nogetsoundflag:
1997
     cmp  ebx,2
2000
     cmp  ebx,2
1998
     jnz  nosoundflag
2001
     jnz  nosoundflag
1999
     xor  byte [sound_flag], 1
2002
     xor  byte [sound_flag], 1
2000
 nosoundflag:
2003
 nosoundflag:
2001
     ret
2004
     ret
2002
 
2005
 
2003
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2006
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2004
     cmp  ebx,1
2007
     cmp  ebx,1
2005
     jl   exit_for_anyone
2008
     jl   exit_for_anyone
2006
     cmp  ebx,4
2009
     cmp  ebx,4
2007
     jg   exit_for_anyone
2010
     jg   exit_for_anyone
2008
     mov  [BOOT_VAR+0x9030],bl
2011
     mov  [BOOT_VAR+0x9030],bl
2009
     jmp  for_shutdown_parameter
2012
     jmp  for_shutdown_parameter
2010
 
2013
 
2011
sysfn_minimize:         ; 18.10 = minimize window
2014
sysfn_minimize:         ; 18.10 = minimize window
2012
     mov   [window_minimize],1
2015
     mov   [window_minimize],1
2013
 exit_for_anyone:
2016
 exit_for_anyone:
2014
     ret
2017
     ret
2015
 
2018
 
2016
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2019
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2017
     cmp  ebx,1
2020
     cmp  ebx,1
2018
     jnz  full_table
2021
     jnz  full_table
2019
  small_table:
2022
  small_table:
2020
     call for_all_tables
2023
     call for_all_tables
2021
     mov ecx,10
2024
     mov ecx,10
2022
     cld
2025
     cld
2023
     rep movsb
2026
     rep movsb
2024
     ret
2027
     ret
2025
   for_all_tables:
2028
   for_all_tables:
2026
     mov edi,[TASK_BASE]
2029
     mov edi,[TASK_BASE]
2027
     mov edi,[edi+TASKDATA.mem_start]
2030
     mov edi,[edi+TASKDATA.mem_start]
2028
     add edi,ecx
2031
     add edi,ecx
2029
     mov esi,DRIVE_DATA
2032
     mov esi,DRIVE_DATA
2030
     ret
2033
     ret
2031
  full_table:
2034
  full_table:
2032
     cmp  ebx,2
2035
     cmp  ebx,2
2033
     jnz  exit_for_anyone
2036
     jnz  exit_for_anyone
2034
     call for_all_tables
2037
     call for_all_tables
2035
     mov ecx,16384
2038
     mov ecx,16384
2036
     cld
2039
     cld
2037
     rep movsd
2040
     rep movsd
2038
     ret
2041
     ret
2039
 
2042
 
2040
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2043
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2041
        and     dword [esp+36], 0
2044
        and     dword [esp+36], 0
2042
        ret
2045
        ret
2043
 
2046
 
2044
sysfn_getversion:       ; 18.13 = get kernel ID and version
2047
sysfn_getversion:       ; 18.13 = get kernel ID and version
2045
     mov edi,[TASK_BASE]
2048
     mov edi,[TASK_BASE]
2046
     mov edi,[edi+TASKDATA.mem_start]
2049
     mov edi,[edi+TASKDATA.mem_start]
2047
     add edi,ebx
2050
     add edi,ebx
2048
     mov esi,version_inf
2051
     mov esi,version_inf
2049
     mov ecx,version_end-version_inf
2052
     mov ecx,version_end-version_inf
2050
     cld
2053
     cld
2051
     rep movsb
2054
     rep movsb
2052
     ret
2055
     ret
2053
 
2056
 
2054
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2057
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2055
     ;wait retrace functions
2058
     ;wait retrace functions
2056
 sys_wait_retrace:
2059
 sys_wait_retrace:
2057
     mov edx,0x3da
2060
     mov edx,0x3da
2058
 WaitRetrace_loop:
2061
 WaitRetrace_loop:
2059
     in al,dx
2062
     in al,dx
2060
     test al,1000b
2063
     test al,1000b
2061
     jz WaitRetrace_loop
2064
     jz WaitRetrace_loop
2062
     mov [esp+36],dword 0
2065
     mov [esp+36],dword 0
2063
     ret
2066
     ret
2064
 
2067
 
2065
sysfn_centermouse:      ; 18.15 = mouse centered
2068
sysfn_centermouse:      ; 18.15 = mouse centered
2066
     call  mouse_centered
2069
     call  mouse_centered
2067
     mov [esp+36],dword 0
2070
     mov [esp+36],dword 0
2068
     ret
2071
     ret
2069
 
2072
 
2070
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2073
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2071
     cmp  ebx,0  ; get mouse speed factor
2074
     cmp  ebx,0  ; get mouse speed factor
2072
     jnz  .set_mouse_acceleration
2075
     jnz  .set_mouse_acceleration
2073
     xor  eax,eax
2076
     xor  eax,eax
2074
     mov  ax,[mouse_speed_factor]
2077
     mov  ax,[mouse_speed_factor]
2075
     mov  [esp+36],eax
2078
     mov  [esp+36],eax
2076
     ret
2079
     ret
2077
 .set_mouse_acceleration:
2080
 .set_mouse_acceleration:
2078
     cmp  ebx,1  ; set mouse speed factor
2081
     cmp  ebx,1  ; set mouse speed factor
2079
     jnz  .get_mouse_delay
2082
     jnz  .get_mouse_delay
2080
     mov  [mouse_speed_factor],cx
2083
     mov  [mouse_speed_factor],cx
2081
     ret
2084
     ret
2082
 .get_mouse_delay:
2085
 .get_mouse_delay:
2083
     cmp  ebx,2  ; get mouse delay
2086
     cmp  ebx,2  ; get mouse delay
2084
     jnz  .set_mouse_delay
2087
     jnz  .set_mouse_delay
2085
     mov  eax,[mouse_delay]
2088
     mov  eax,[mouse_delay]
2086
     mov  [esp+36],eax
2089
     mov  [esp+36],eax
2087
     ret
2090
     ret
2088
 .set_mouse_delay:
2091
 .set_mouse_delay:
2089
     cmp  ebx,3  ; set mouse delay
2092
     cmp  ebx,3  ; set mouse delay
2090
     jnz  .set_pointer_position
2093
     jnz  .set_pointer_position
2091
     mov  [mouse_delay],ecx
2094
     mov  [mouse_delay],ecx
2092
     ret
2095
     ret
2093
 .set_pointer_position:
2096
 .set_pointer_position:
2094
     cmp  ebx,4  ; set mouse pointer position
2097
     cmp  ebx,4  ; set mouse pointer position
2095
     jnz  .end
2098
     jnz  .end
2096
     mov   [MOUSE_Y],cx    ;y
2099
     mov   [MOUSE_Y],cx    ;y
2097
     ror   ecx,16
2100
     ror   ecx,16
2098
     mov   [MOUSE_X],cx    ;x
2101
     mov   [MOUSE_X],cx    ;x
2099
     rol   ecx,16
2102
     rol   ecx,16
2100
 .end:
2103
 .end:
2101
     ret
2104
     ret
2102
 
2105
 
2103
sysfn_getfreemem:
2106
sysfn_getfreemem:
2104
     mov eax, [pg_data.pages_free]
2107
     mov eax, [pg_data.pages_free]
2105
     shl eax, 2
2108
     shl eax, 2
2106
     mov [esp+36],eax
2109
     mov [esp+36],eax
2107
     ret
2110
     ret
2108
 
2111
 
2109
sysfn_getallmem:
2112
sysfn_getallmem:
2110
     mov  eax,[MEM_AMOUNT]
2113
     mov  eax,[MEM_AMOUNT]
2111
     shr eax, 10
2114
     shr eax, 10
2112
     mov  [esp+36],eax
2115
     mov  [esp+36],eax
2113
     ret
2116
     ret
2114
 
2117
 
2115
uglobal
2118
uglobal
2116
;// mike.dld, 2006-29-01 [
2119
;// mike.dld, 2006-29-01 [
2117
screen_workarea RECT
2120
screen_workarea RECT
2118
;// mike.dld, 2006-29-01 ]
2121
;// mike.dld, 2006-29-01 ]
2119
window_minimize db 0
2122
window_minimize db 0
2120
sound_flag      db 0
2123
sound_flag      db 0
2121
endg
2124
endg
2122
 
2125
 
2123
iglobal
2126
iglobal
2124
version_inf:
2127
version_inf:
2125
  db 0,6,5,0  ; version 0.6.5.0
2128
  db 0,6,5,0  ; version 0.6.5.0
2126
  db UID_KOLIBRI
2129
  db UID_KOLIBRI
2127
  db 'Kolibri',0
2130
  db 'Kolibri',0
2128
version_end:
2131
version_end:
2129
endg
2132
endg
2130
 
2133
 
2131
UID_NONE=0
2134
UID_NONE=0
2132
UID_MENUETOS=1   ;official
2135
UID_MENUETOS=1   ;official
2133
UID_KOLIBRI=2    ;russian
2136
UID_KOLIBRI=2    ;russian
2134
 
2137
 
2135
sys_cachetodiskette:
2138
sys_cachetodiskette:
2136
;    pushad
2139
;    pushad
2137
;    cmp  eax,1
2140
;    cmp  eax,1
2138
;    jne  no_write_all_of_ramdisk
2141
;    jne  no_write_all_of_ramdisk
2139
;    call fdc_writeramdisk
2142
;    call fdc_writeramdisk
2140
;    popad
2143
;    popad
2141
;    ret
2144
;    ret
2142
;  no_write_all_of_ramdisk:
2145
;  no_write_all_of_ramdisk:
2143
;    cmp eax,2
2146
;    cmp eax,2
2144
;    jne no_write_part_of_ramdisk
2147
;    jne no_write_part_of_ramdisk
2145
;    call fdc_commitflush
2148
;    call fdc_commitflush
2146
;    popad
2149
;    popad
2147
;    ret
2150
;    ret
2148
;  no_write_part_of_ramdisk:
2151
;  no_write_part_of_ramdisk:
2149
;    cmp  eax,3
2152
;    cmp  eax,3
2150
;    jne  no_set_fdc
2153
;    jne  no_set_fdc
2151
;    call fdc_set
2154
;    call fdc_set
2152
;    popad
2155
;    popad
2153
;    ret
2156
;    ret
2154
;  no_set_fdc:
2157
;  no_set_fdc:
2155
;    cmp  eax,4
2158
;    cmp  eax,4
2156
;    jne  no_get_fdc
2159
;    jne  no_get_fdc
2157
;    popad
2160
;    popad
2158
;    call fdc_get
2161
;    call fdc_get
2159
;    mov    [esp+36],ecx
2162
;    mov    [esp+36],ecx
2160
;    ret
2163
;    ret
2161
;  no_get_fdc:
2164
;  no_get_fdc:
2162
;    popad
2165
;    popad
2163
;    ret
2166
;    ret
2164
    cmp eax,1
2167
    cmp eax,1
2165
    jne no_floppy_a_save
2168
    jne no_floppy_a_save
2166
    mov   [flp_number],1
2169
    mov   [flp_number],1
2167
    jmp save_image_on_floppy
2170
    jmp save_image_on_floppy
2168
  no_floppy_a_save:
2171
  no_floppy_a_save:
2169
    cmp eax,2
2172
    cmp eax,2
2170
    jne no_floppy_b_save
2173
    jne no_floppy_b_save
2171
    mov   [flp_number],2
2174
    mov   [flp_number],2
2172
  save_image_on_floppy:
2175
  save_image_on_floppy:
2173
    call save_image
2176
    call save_image
2174
    mov  [esp+36],dword 0
2177
    mov  [esp+36],dword 0
2175
    cmp  [FDC_Status],0
2178
    cmp  [FDC_Status],0
2176
    je   yes_floppy_save
2179
    je   yes_floppy_save
2177
  no_floppy_b_save:
2180
  no_floppy_b_save:
2178
    mov [esp+36],dword 1
2181
    mov [esp+36],dword 1
2179
  yes_floppy_save:
2182
  yes_floppy_save:
2180
    ret
2183
    ret
2181
 
2184
 
2182
uglobal
2185
uglobal
2183
;  bgrchanged  dd  0x0
2186
;  bgrchanged  dd  0x0
2184
endg
2187
endg
2185
 
2188
 
2186
sys_background:
2189
sys_background:
2187
 
2190
 
2188
    cmp   eax,1                            ; BACKGROUND SIZE
2191
    cmp   eax,1                            ; BACKGROUND SIZE
2189
    jnz   nosb1
2192
    jnz   nosb1
2190
    cmp   ebx,0
2193
    cmp   ebx,0
2191
    je    sbgrr
2194
    je    sbgrr
2192
    cmp   ecx,0
2195
    cmp   ecx,0
2193
    je    sbgrr
2196
    je    sbgrr
2194
    mov   [display_data-8],ebx
2197
    mov   [display_data-8],ebx
2195
    mov   [display_data-4],ecx
2198
    mov   [display_data-4],ecx
2196
;    mov   [bgrchanged],1
2199
;    mov   [bgrchanged],1
2197
  sbgrr:
2200
  sbgrr:
2198
    ret
2201
    ret
2199
  nosb1:
2202
  nosb1:
2200
 
2203
 
2201
    cmp   eax,2                            ; SET PIXEL
2204
    cmp   eax,2                            ; SET PIXEL
2202
    jnz   nosb2
2205
    jnz   nosb2
2203
    mov   edx,0x160000-16
2206
    mov   edx,0x160000-16
2204
    cmp   edx,ebx
2207
    cmp   edx,ebx
2205
    jbe   nosb2
2208
    jbe   nosb2
2206
    mov   edx,[ebx]
2209
    mov   edx,[ebx]
2207
    and   edx,0xFF000000 ;255*256*256*256
2210
    and   edx,0xFF000000 ;255*256*256*256
2208
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2211
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2209
    add   edx,ecx
2212
    add   edx,ecx
2210
    mov   [ebx+IMG_BACKGROUND],edx
2213
    mov   [ebx+IMG_BACKGROUND],edx
2211
;    mov   [bgrchanged],1
2214
;    mov   [bgrchanged],1
2212
    ret
2215
    ret
2213
  nosb2:
2216
  nosb2:
2214
 
2217
 
2215
    cmp   eax,3                            ; DRAW BACKGROUND
2218
    cmp   eax,3                            ; DRAW BACKGROUND
2216
    jnz   nosb3
2219
    jnz   nosb3
2217
draw_background_temp:
2220
draw_background_temp:
2218
;    cmp   [bgrchanged],1 ;0
2221
;    cmp   [bgrchanged],1 ;0
2219
;    je    nosb31
2222
;    je    nosb31
2220
;draw_background_temp:
2223
;draw_background_temp:
2221
;    mov   [bgrchanged],1 ;0
2224
;    mov   [bgrchanged],1 ;0
2222
    mov   [REDRAW_BACKGROUND],byte 1
2225
    mov   [REDRAW_BACKGROUND],byte 1
2223
    mov    [background_defined], 1
2226
    mov    [background_defined], 1
2224
   nosb31:
2227
   nosb31:
2225
    ret
2228
    ret
2226
  nosb3:
2229
  nosb3:
2227
 
2230
 
2228
    cmp   eax,4                            ; TILED / STRETCHED
2231
    cmp   eax,4                            ; TILED / STRETCHED
2229
    jnz   nosb4
2232
    jnz   nosb4
2230
    cmp   ebx,[display_data-12]
2233
    cmp   ebx,[display_data-12]
2231
    je    nosb41
2234
    je    nosb41
2232
    mov   [display_data-12],ebx
2235
    mov   [display_data-12],ebx
2233
;    mov   [bgrchanged],1
2236
;    mov   [bgrchanged],1
2234
   nosb41:
2237
   nosb41:
2235
    ret
2238
    ret
2236
  nosb4:
2239
  nosb4:
2237
 
2240
 
2238
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2241
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2239
    jnz   nosb5
2242
    jnz   nosb5
2240
  ; bughere
2243
  ; bughere
2241
    mov   edi, [TASK_BASE]
2244
    mov   edi, [TASK_BASE]
2242
    add   ebx, [edi+TASKDATA.mem_start]
2245
    add   ebx, [edi+TASKDATA.mem_start]
2243
 ;   mov   esi, ebx
2246
 ;   mov   esi, ebx
2244
 ;   mov   edi, ecx
2247
 ;   mov   edi, ecx
2245
    mov   eax, ebx
2248
    mov   eax, ebx
2246
    mov   ebx, ecx
2249
    mov   ebx, ecx
2247
    add   ecx, edx
2250
    add   ecx, edx
2248
    cmp   ecx, 0x160000-16
2251
    cmp   ecx, 0x160000-16
2249
    ja    .fin
2252
    ja    .fin
2250
 ;   add   edi, 0x300000
2253
 ;   add   edi, 0x300000
2251
    add   ebx, IMG_BACKGROUND
2254
    add   ebx, IMG_BACKGROUND
2252
    mov   ecx, edx
2255
    mov   ecx, edx
2253
    cmp   ecx, 0x160000-16
2256
    cmp   ecx, 0x160000-16
2254
    ja    .fin
2257
    ja    .fin
2255
;    mov   [bgrchanged],1
2258
;    mov   [bgrchanged],1
2256
  ;  cld
2259
  ;  cld
2257
  ;  rep   movsb
2260
  ;  rep   movsb
2258
    call  memmove
2261
    call  memmove
2259
  .fin:
2262
  .fin:
2260
    ret
2263
    ret
2261
  nosb5:
2264
  nosb5:
2262
 
2265
 
2263
    ret
2266
    ret
2264
 
2267
 
2265
 
2268
 
2266
align 4
2269
align 4
2267
 
2270
 
2268
sys_getbackground:
2271
sys_getbackground:
2269
 
2272
 
2270
    cmp   eax,1                                  ; SIZE
2273
    cmp   eax,1                                  ; SIZE
2271
    jnz   nogb1
2274
    jnz   nogb1
2272
    mov   eax,[display_data-8]
2275
    mov   eax,[display_data-8]
2273
    shl   eax,16
2276
    shl   eax,16
2274
    mov   ax,[display_data-4]
2277
    mov   ax,[display_data-4]
2275
    mov   [esp+36],eax
2278
    mov   [esp+36],eax
2276
    ret
2279
    ret
2277
  nogb1:
2280
  nogb1:
2278
 
2281
 
2279
    cmp   eax,2                                  ; PIXEL
2282
    cmp   eax,2                                  ; PIXEL
2280
    jnz   nogb2
2283
    jnz   nogb2
2281
    mov   edx,0x160000-16
2284
    mov   edx,0x160000-16
2282
    cmp   edx,ebx
2285
    cmp   edx,ebx
2283
    jbe   nogb2
2286
    jbe   nogb2
2284
    mov   eax, [ebx+IMG_BACKGROUND]
2287
    mov   eax, [ebx+IMG_BACKGROUND]
2285
    and   eax, 0xFFFFFF
2288
    and   eax, 0xFFFFFF
2286
    mov   [esp+36],eax
2289
    mov   [esp+36],eax
2287
    ret
2290
    ret
2288
  nogb2:
2291
  nogb2:
2289
 
2292
 
2290
    cmp   eax,4                                  ; TILED / STRETCHED
2293
    cmp   eax,4                                  ; TILED / STRETCHED
2291
    jnz   nogb4
2294
    jnz   nogb4
2292
    mov   eax,[display_data-12]
2295
    mov   eax,[display_data-12]
2293
  nogb4:
2296
  nogb4:
2294
    mov   [esp+36],eax
2297
    mov   [esp+36],eax
2295
    ret
2298
    ret
2296
 
2299
 
2297
 
2300
 
2298
align 4
2301
align 4
2299
 
2302
 
2300
sys_getkey:
2303
sys_getkey:
2301
    mov   [esp+36],dword 1
2304
    mov   [esp+36],dword 1
2302
; test main buffer
2305
; test main buffer
2303
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2306
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2304
    movzx ecx,word [WIN_STACK + ebx * 2]
2307
    movzx ecx,word [WIN_STACK + ebx * 2]
2305
    mov   edx,[TASK_COUNT]
2308
    mov   edx,[TASK_COUNT]
2306
    cmp   ecx,edx
2309
    cmp   ecx,edx
2307
    jne   .finish
2310
    jne   .finish
2308
    cmp   [KEY_COUNT],byte 0
2311
    cmp   [KEY_COUNT],byte 0
2309
    je    .finish
2312
    je    .finish
2310
    movzx eax,byte [KEY_BUFF]
2313
    movzx eax,byte [KEY_BUFF]
2311
    shl   eax,8
2314
    shl   eax,8
2312
    push  eax
2315
    push  eax
2313
    dec   byte [KEY_COUNT]
2316
    dec   byte [KEY_COUNT]
2314
    and   byte [KEY_COUNT],127
2317
    and   byte [KEY_COUNT],127
2315
    movzx ecx,byte [KEY_COUNT]
2318
    movzx ecx,byte [KEY_COUNT]
2316
    add   ecx,2
2319
    add   ecx,2
2317
 ;   mov   esi,0xf402
2320
 ;   mov   esi,0xf402
2318
 ;   mov   edi,0xf401
2321
 ;   mov   edi,0xf401
2319
 ;   cld
2322
 ;   cld
2320
 ;  rep   movsb
2323
 ;  rep   movsb
2321
    mov   eax, KEY_BUFF+1
2324
    mov   eax, KEY_BUFF+1
2322
    mov   ebx, KEY_BUFF
2325
    mov   ebx, KEY_BUFF
2323
    call  memmove
2326
    call  memmove
2324
    pop   eax
2327
    pop   eax
2325
.ret_eax:
2328
.ret_eax:
2326
    mov   [esp+36],eax
2329
    mov   [esp+36],eax
2327
    ret
2330
    ret
2328
 .finish:
2331
 .finish:
2329
; test hotkeys buffer
2332
; test hotkeys buffer
2330
        mov     ecx, hotkey_buffer
2333
        mov     ecx, hotkey_buffer
2331
@@:
2334
@@:
2332
        cmp     [ecx], ebx
2335
        cmp     [ecx], ebx
2333
        jz      .found
2336
        jz      .found
2334
        add     ecx, 8
2337
        add     ecx, 8
2335
        cmp     ecx, hotkey_buffer+120*8
2338
        cmp     ecx, hotkey_buffer+120*8
2336
        jb      @b
2339
        jb      @b
2337
        ret
2340
        ret
2338
.found:
2341
.found:
2339
        mov     ax, [ecx+6]
2342
        mov     ax, [ecx+6]
2340
        shl     eax, 16
2343
        shl     eax, 16
2341
        mov     ah, [ecx+4]
2344
        mov     ah, [ecx+4]
2342
        mov     al, 2
2345
        mov     al, 2
2343
        and     dword [ecx+4], 0
2346
        and     dword [ecx+4], 0
2344
        and     dword [ecx], 0
2347
        and     dword [ecx], 0
2345
        jmp     .ret_eax
2348
        jmp     .ret_eax
2346
 
2349
 
2347
align 4
2350
align 4
2348
 
2351
 
2349
sys_getbutton:
2352
sys_getbutton:
2350
 
2353
 
2351
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2354
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2352
    mov   [esp+36],dword 1
2355
    mov   [esp+36],dword 1
2353
    movzx ecx, word [WIN_STACK + ebx * 2]
2356
    movzx ecx, word [WIN_STACK + ebx * 2]
2354
    mov   edx, [TASK_COUNT] ; less than 256 processes
2357
    mov   edx, [TASK_COUNT] ; less than 256 processes
2355
    cmp   ecx,edx
2358
    cmp   ecx,edx
2356
    jne   .exit
2359
    jne   .exit
2357
    movzx eax,byte [BTN_COUNT]
2360
    movzx eax,byte [BTN_COUNT]
2358
    test  eax,eax
2361
    test  eax,eax
2359
    jz    .exit
2362
    jz    .exit
2360
    mov   eax,[BTN_BUFF]
2363
    mov   eax,[BTN_BUFF]
2361
    shl   eax,8
2364
    shl   eax,8
2362
    mov   [BTN_COUNT],byte 0
2365
    mov   [BTN_COUNT],byte 0
2363
    mov   [esp+36],eax
2366
    mov   [esp+36],eax
2364
 .exit:
2367
 .exit:
2365
    ret
2368
    ret
2366
 
2369
 
2367
 
2370
 
2368
align 4
2371
align 4
2369
 
2372
 
2370
sys_cpuusage:
2373
sys_cpuusage:
2371
 
2374
 
2372
;  RETURN:
2375
;  RETURN:
2373
;
2376
;
2374
;  +00 dword     process cpu usage
2377
;  +00 dword     process cpu usage
2375
;  +04  word     position in windowing stack
2378
;  +04  word     position in windowing stack
2376
;  +06  word     windowing stack value at current position (cpu nro)
2379
;  +06  word     windowing stack value at current position (cpu nro)
2377
;  +10 12 bytes  name
2380
;  +10 12 bytes  name
2378
;  +22 dword     start in mem
2381
;  +22 dword     start in mem
2379
;  +26 dword     used mem
2382
;  +26 dword     used mem
2380
;  +30 dword     PID , process idenfification number
2383
;  +30 dword     PID , process idenfification number
2381
;
2384
;
2382
 
2385
 
2383
    mov  edi,[TASK_BASE]   ; eax = return area
2386
    mov  edi,[TASK_BASE]   ; eax = return area
2384
    add  eax,[edi + TASKDATA.mem_start]
2387
    add  eax,[edi + TASKDATA.mem_start]
2385
 
2388
 
2386
    cmp  ebx,-1         ; who am I ?
2389
    cmp  ebx,-1         ; who am I ?
2387
    jne  no_who_am_i
2390
    jne  no_who_am_i
2388
    mov  ebx,[CURRENT_TASK]
2391
    mov  ebx,[CURRENT_TASK]
2389
  no_who_am_i:
2392
  no_who_am_i:
2390
 
2393
 
2391
    push eax            ; return area
2394
    push eax            ; return area
2392
    push ebx            ; process number
2395
    push ebx            ; process number
2393
 
2396
 
2394
    push ebx
2397
    push ebx
2395
    push ebx
2398
    push ebx
2396
    push eax
2399
    push eax
2397
 
2400
 
2398
    ; return memory usage
2401
    ; return memory usage
2399
 
2402
 
2400
    xor  edx,edx
2403
    xor  edx,edx
2401
    mov  eax,0x20
2404
    mov  eax,0x20
2402
    mul  ebx
2405
    mul  ebx
2403
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2406
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2404
    mov  ebx,eax
2407
    mov  ebx,eax
2405
    pop  eax
2408
    pop  eax
2406
    mov  ecx,[ebx]
2409
    mov  ecx,[ebx]
2407
    mov  [eax],ecx
2410
    mov  [eax],ecx
2408
    pop  ebx
2411
    pop  ebx
2409
    mov  cx, [WIN_STACK + ebx * 2]
2412
    mov  cx, [WIN_STACK + ebx * 2]
2410
    mov  [eax+4],cx
2413
    mov  [eax+4],cx
2411
    mov  cx, [WIN_POS + ebx * 2]
2414
    mov  cx, [WIN_POS + ebx * 2]
2412
    mov  [eax+6],cx
2415
    mov  [eax+6],cx
2413
    push eax
2416
    push eax
2414
    mov  eax,ebx
2417
    mov  eax,ebx
2415
    shl  eax,8
2418
    shl  eax,8
2416
    add  eax,SLOT_BASE+APPDATA.app_name
2419
    add  eax,SLOT_BASE+APPDATA.app_name
2417
    pop  ebx
2420
    pop  ebx
2418
    add  ebx,10
2421
    add  ebx,10
2419
    mov  ecx,11
2422
    mov  ecx,11
2420
    call memmove
2423
    call memmove
2421
 
2424
 
2422
    ; memory usage
2425
    ; memory usage
2423
 
2426
 
2424
    xor    eax,eax
2427
    xor    eax,eax
2425
    mov    edx,0x100000*16
2428
    mov    edx,0x100000*16
2426
    pop    ecx                                   ; get gdt of tss
2429
    pop    ecx                                   ; get gdt of tss
2427
    cmp    ecx,1
2430
    cmp    ecx,1
2428
    je     os_mem
2431
    je     os_mem
2429
    shl    ecx,8
2432
    shl    ecx,8
2430
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2433
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2431
    mov    eax,std_application_base_address
2434
    mov    eax,std_application_base_address
2432
    ; eax run base -> edx used memory
2435
    ; eax run base -> edx used memory
2433
  os_mem:
2436
  os_mem:
2434
    dec    edx
2437
    dec    edx
2435
    mov    [ebx+12],eax
2438
    mov    [ebx+12],eax
2436
    mov    [ebx+16],edx
2439
    mov    [ebx+16],edx
2437
 
2440
 
2438
    ; PID (+30)
2441
    ; PID (+30)
2439
 
2442
 
2440
    mov    eax,[esp]
2443
    mov    eax,[esp]
2441
    shl    eax,5
2444
    shl    eax,5
2442
    add    eax,CURRENT_TASK+TASKDATA.pid
2445
    add    eax,CURRENT_TASK+TASKDATA.pid
2443
    mov    eax,[eax]
2446
    mov    eax,[eax]
2444
    mov    [ebx+20],eax
2447
    mov    [ebx+20],eax
2445
 
2448
 
2446
    ; window position and size
2449
    ; window position and size
2447
 
2450
 
2448
    mov    esi,[esp]
2451
    mov    esi,[esp]
2449
    shl    esi,5
2452
    shl    esi,5
2450
    add    esi,window_data + WDATA.box
2453
    add    esi,window_data + WDATA.box
2451
    mov    edi,[esp+4]
2454
    mov    edi,[esp+4]
2452
    add    edi,34
2455
    add    edi,34
2453
    mov    ecx,4
2456
    mov    ecx,4
2454
    cld
2457
    cld
2455
    rep    movsd
2458
    rep    movsd
2456
 
2459
 
2457
    ; Process state (+50)
2460
    ; Process state (+50)
2458
 
2461
 
2459
    mov    eax,[esp]
2462
    mov    eax,[esp]
2460
    shl    eax,5
2463
    shl    eax,5
2461
    add    eax,CURRENT_TASK+TASKDATA.state
2464
    add    eax,CURRENT_TASK+TASKDATA.state
2462
    mov    eax,[eax]
2465
    mov    eax,[eax]
2463
    mov    [ebx+40],ax
2466
    mov    [ebx+40],ax
2464
 
2467
 
2465
    ; Window client area box
2468
    ; Window client area box
2466
 
2469
 
2467
    mov    esi,[esp]
2470
    mov    esi,[esp]
2468
    shl    esi,8
2471
    shl    esi,8
2469
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2472
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2470
    lea    edi,[ebx+44]
2473
    lea    edi,[ebx+44]
2471
    mov    ecx,4
2474
    mov    ecx,4
2472
    rep    movsd
2475
    rep    movsd
2473
 
2476
 
2474
    ; Window state
2477
    ; Window state
2475
 
2478
 
2476
    mov    esi,[esp]
2479
    mov    esi,[esp]
2477
    shl    esi,5
2480
    shl    esi,5
2478
    add    esi,window_data + WDATA.box
2481
    add    esi,window_data + WDATA.box
2479
    mov    al,[esi+window_data+WDATA.fl_wstate]
2482
    mov    al,[esi+WDATA.fl_wstate]
2480
    mov    [edi],al
2483
    mov    [edi],al
2481
 
2484
 
2482
    pop    ebx
2485
    pop    ebx
2483
    pop    eax
2486
    pop    eax
2484
 
2487
 
2485
    ; return number of processes
2488
    ; return number of processes
2486
 
2489
 
2487
    mov    eax,[TASK_COUNT]
2490
    mov    eax,[TASK_COUNT]
2488
    mov    [esp+36],eax
2491
    mov    [esp+36],eax
2489
    ret
2492
    ret
2490
 
-
 
2491
 
-
 
2492
 
-
 
2493
 
2493
 
2494
align 4
2494
align 4
2495
sys_clock:
2495
sys_clock:
2496
        cli
2496
        cli
2497
  ; Mikhail Lisovin  xx Jan 2005
2497
  ; Mikhail Lisovin  xx Jan 2005
2498
  @@:   mov   al, 10
2498
  @@:   mov   al, 10
2499
        out   0x70, al
2499
        out   0x70, al
2500
        in    al, 0x71
2500
        in    al, 0x71
2501
        test  al, al
2501
        test  al, al
2502
        jns   @f
2502
        jns   @f
2503
        mov   esi, 1
2503
        mov   esi, 1
2504
        call  delay_ms
2504
        call  delay_ms
2505
        jmp   @b
2505
        jmp   @b
2506
  @@:
2506
  @@:
2507
  ; end Lisovin's fix
2507
  ; end Lisovin's fix
2508
 
2508
 
2509
        xor   al,al           ; seconds
2509
        xor   al,al           ; seconds
2510
        out   0x70,al
2510
        out   0x70,al
2511
        in    al,0x71
2511
        in    al,0x71
2512
        movzx ecx,al
2512
        movzx ecx,al
2513
        mov   al,02           ; minutes
2513
        mov   al,02           ; minutes
2514
        shl   ecx,16
2514
        shl   ecx,16
2515
        out   0x70,al
2515
        out   0x70,al
2516
        in    al,0x71
2516
        in    al,0x71
2517
        movzx edx,al
2517
        movzx edx,al
2518
        mov   al,04           ; hours
2518
        mov   al,04           ; hours
2519
        shl   edx,8
2519
        shl   edx,8
2520
        out   0x70,al
2520
        out   0x70,al
2521
        in    al,0x71
2521
        in    al,0x71
2522
        add   ecx,edx
2522
        add   ecx,edx
2523
        movzx edx,al
2523
        movzx edx,al
2524
        add   ecx,edx
2524
        add   ecx,edx
2525
        sti
2525
        sti
2526
        mov   [esp+36],ecx
2526
        mov   [esp+36],ecx
2527
        ret
2527
        ret
2528
 
2528
 
2529
 
2529
 
2530
align 4
2530
align 4
2531
 
2531
 
2532
sys_date:
2532
sys_date:
2533
 
2533
 
2534
        cli
2534
        cli
2535
 
2535
 
2536
  @@:   mov   al, 10
2536
  @@:   mov   al, 10
2537
        out   0x70, al
2537
        out   0x70, al
2538
        in    al, 0x71
2538
        in    al, 0x71
2539
        test  al, al
2539
        test  al, al
2540
        jns   @f
2540
        jns   @f
2541
        mov   esi, 1
2541
        mov   esi, 1
2542
        call  delay_ms
2542
        call  delay_ms
2543
        jmp   @b
2543
        jmp   @b
2544
  @@:
2544
  @@:
2545
 
2545
 
2546
        mov     ch,0
2546
        mov     ch,0
2547
        mov     al,7            ; date
2547
        mov     al,7            ; date
2548
        out     0x70,al
2548
        out     0x70,al
2549
        in      al,0x71
2549
        in      al,0x71
2550
        mov     cl,al
2550
        mov     cl,al
2551
        mov     al,8            ; month
2551
        mov     al,8            ; month
2552
        shl     ecx,16
2552
        shl     ecx,16
2553
        out     0x70,al
2553
        out     0x70,al
2554
        in      al,0x71
2554
        in      al,0x71
2555
        mov     ch,al
2555
        mov     ch,al
2556
        mov     al,9            ; year
2556
        mov     al,9            ; year
2557
        out     0x70,al
2557
        out     0x70,al
2558
        in      al,0x71
2558
        in      al,0x71
2559
        mov     cl,al
2559
        mov     cl,al
2560
        sti
2560
        sti
2561
        mov     [esp+36],ecx
2561
        mov     [esp+36],ecx
2562
        ret
2562
        ret
2563
 
2563
 
2564
 
2564
 
2565
; redraw status
2565
; redraw status
2566
 
2566
 
2567
sys_redrawstat:
2567
sys_redrawstat:
2568
 
2568
 
2569
    cmp  eax,1
2569
    cmp  eax,1
2570
    jne  no_widgets_away
2570
    jne  no_widgets_away
2571
 
2571
 
2572
    ; buttons away
2572
    ; buttons away
2573
 
2573
 
2574
    mov   ecx,[CURRENT_TASK]
2574
    mov   ecx,[CURRENT_TASK]
2575
 
2575
 
2576
  sys_newba2:
2576
  sys_newba2:
2577
 
2577
 
2578
    mov   edi,[BTN_ADDR]
2578
    mov   edi,[BTN_ADDR]
2579
    cmp   [edi],dword 0  ; empty button list ?
2579
    cmp   [edi],dword 0  ; empty button list ?
2580
    je    end_of_buttons_away
2580
    je    end_of_buttons_away
2581
 
2581
 
2582
    movzx ebx,word [edi]
2582
    movzx ebx,word [edi]
2583
    inc   ebx
2583
    inc   ebx
2584
 
2584
 
2585
    mov   eax,edi
2585
    mov   eax,edi
2586
 
2586
 
2587
  sys_newba:
2587
  sys_newba:
2588
 
2588
 
2589
    dec   ebx
2589
    dec   ebx
2590
    jz    end_of_buttons_away
2590
    jz    end_of_buttons_away
2591
 
2591
 
2592
    add   eax,0x10
2592
    add   eax,0x10
2593
    cmp   cx,[eax]
2593
    cmp   cx,[eax]
2594
    jnz   sys_newba
2594
    jnz   sys_newba
2595
 
2595
 
2596
    push  eax ebx ecx
2596
    push  eax ebx ecx
2597
    mov   ecx,ebx
2597
    mov   ecx,ebx
2598
    inc   ecx
2598
    inc   ecx
2599
    shl   ecx,4
2599
    shl   ecx,4
2600
    mov   ebx,eax
2600
    mov   ebx,eax
2601
    add   eax,0x10
2601
    add   eax,0x10
2602
    call  memmove
2602
    call  memmove
2603
    dec   dword [edi]
2603
    dec   dword [edi]
2604
    pop   ecx ebx eax
2604
    pop   ecx ebx eax
2605
 
2605
 
2606
    jmp   sys_newba2
2606
    jmp   sys_newba2
2607
 
2607
 
2608
  end_of_buttons_away:
2608
  end_of_buttons_away:
2609
 
2609
 
2610
    ret
2610
    ret
2611
 
2611
 
2612
  no_widgets_away:
2612
  no_widgets_away:
2613
 
2613
 
2614
    cmp   eax,2
2614
    cmp   eax,2
2615
    jnz   srl1
2615
    jnz   srl1
2616
 
2616
 
2617
    mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
2617
    mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
2618
    add   edx,draw_data-CURRENT_TASK
2618
    add   edx,draw_data-CURRENT_TASK
2619
    mov   [edx+RECT.left], 0
2619
    mov   [edx+RECT.left], 0
2620
    mov   [edx+RECT.top], 0
2620
    mov   [edx+RECT.top], 0
2621
    mov   eax,[ScreenWidth]
2621
    mov   eax,[ScreenWidth]
2622
    mov   [edx+RECT.right],eax
2622
    mov   [edx+RECT.right],eax
2623
    mov   eax,[ScreenHeight]
2623
    mov   eax,[ScreenHeight]
2624
    mov   [edx+RECT.bottom],eax
2624
    mov   [edx+RECT.bottom],eax
2625
 
2625
 
2626
    mov   edi,[TASK_BASE]
2626
    mov   edi,[TASK_BASE]
2627
    or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2627
    or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2628
 
2628
 
2629
    call  sys_window_mouse
2629
    call  sys_window_mouse
2630
 
2630
 
2631
    ret
2631
    ret
2632
 
2632
 
2633
  srl1:
2633
  srl1:
2634
 
2634
 
2635
    ret
2635
    ret
2636
 
2636
 
2637
 
2637
 
2638
sys_drawwindow:
2638
sys_drawwindow:
2639
 
2639
 
2640
    mov   edi,ecx
2640
    mov   edi,ecx
2641
    shr   edi,16+8
2641
    shr   edi,16+8
2642
    and   edi,15
2642
    and   edi,15
2643
 
2643
 
2644
    cmp   edi,0   ; type I    - original style
2644
    cmp   edi,0   ; type I    - original style
2645
    jne   nosyswI
2645
    jne   nosyswI
2646
    inc   [mouse_pause]
2646
    inc   [mouse_pause]
2647
    call  [disable_mouse]
2647
    call  [disable_mouse]
2648
    call  sys_set_window
2648
    call  sys_set_window
2649
    call  [disable_mouse]
2649
    call  [disable_mouse]
2650
    call  drawwindow_I
2650
    call  drawwindow_I
2651
    ;dec   [mouse_pause]
2651
    ;dec   [mouse_pause]
2652
    ;call   [draw_pointer]
2652
    ;call   [draw_pointer]
2653
    ;ret
2653
    ;ret
2654
    jmp   draw_window_caption.2
2654
    jmp   draw_window_caption.2
2655
  nosyswI:
2655
  nosyswI:
2656
 
2656
 
2657
    cmp   edi,1   ; type II   - only reserve area, no draw
2657
    cmp   edi,1   ; type II   - only reserve area, no draw
2658
    jne   nosyswII
2658
    jne   nosyswII
2659
    inc   [mouse_pause]
2659
    inc   [mouse_pause]
2660
    call  [disable_mouse]
2660
    call  [disable_mouse]
2661
    call  sys_set_window
2661
    call  sys_set_window
2662
    call  [disable_mouse]
2662
    call  [disable_mouse]
2663
    call  sys_window_mouse
2663
    call  sys_window_mouse
2664
    dec   [mouse_pause]
2664
    dec   [mouse_pause]
2665
    call   [draw_pointer]
2665
    call   [draw_pointer]
2666
    ret
2666
    ret
2667
  nosyswII:
2667
  nosyswII:
2668
 
2668
 
2669
    cmp   edi,2   ; type III  - new style
2669
    cmp   edi,2   ; type III  - new style
2670
    jne   nosyswIII
2670
    jne   nosyswIII
2671
    inc   [mouse_pause]
2671
    inc   [mouse_pause]
2672
    call  [disable_mouse]
2672
    call  [disable_mouse]
2673
    call  sys_set_window
2673
    call  sys_set_window
2674
    call  [disable_mouse]
2674
    call  [disable_mouse]
2675
    call  drawwindow_III
2675
    call  drawwindow_III
2676
    ;dec   [mouse_pause]
2676
    ;dec   [mouse_pause]
2677
    ;call   [draw_pointer]
2677
    ;call   [draw_pointer]
2678
    ;ret
2678
    ;ret
2679
    jmp   draw_window_caption.2
2679
    jmp   draw_window_caption.2
2680
  nosyswIII:
2680
  nosyswIII:
2681
 
2681
 
2682
    cmp   edi,3   ; type IV - skinned window
2682
    cmp   edi,3   ; type IV - skinned window
2683
    jne   nosyswIV
2683
    jne   nosyswIV
2684
 
2684
 
2685
    ; parameter for drawwindow_IV
2685
    ; parameter for drawwindow_IV
2686
    push  0
2686
    push  0
2687
    mov   edi, [TASK_COUNT]
2687
    mov   edi, [TASK_COUNT]
2688
    movzx edi, word [WIN_POS + edi*2]
2688
    movzx edi, word [WIN_POS + edi*2]
2689
    cmp   edi, [CURRENT_TASK]
2689
    cmp   edi, [CURRENT_TASK]
2690
    jne   @f
2690
    jne   @f
2691
    inc   dword [esp]
2691
    inc   dword [esp]
2692
 @@:
2692
 @@:
2693
 
2693
 
2694
    inc   [mouse_pause]
2694
    inc   [mouse_pause]
2695
    call  [disable_mouse]
2695
    call  [disable_mouse]
2696
    call  sys_set_window
2696
    call  sys_set_window
2697
    call  [disable_mouse]
2697
    call  [disable_mouse]
2698
    call  drawwindow_IV
2698
    call  drawwindow_IV
2699
    ;dec   [mouse_pause]
2699
    ;dec   [mouse_pause]
2700
    ;call   [draw_pointer]
2700
    ;call   [draw_pointer]
2701
    ;ret
2701
    ;ret
2702
    jmp   draw_window_caption.2
2702
    jmp   draw_window_caption.2
2703
  nosyswIV:
2703
  nosyswIV:
2704
 
2704
 
2705
    ret
2705
    ret
2706
 
2706
 
2707
 
2707
 
2708
draw_window_caption:
2708
draw_window_caption:
2709
        inc     [mouse_pause]
2709
        inc     [mouse_pause]
2710
        call    [disable_mouse]
2710
        call    [disable_mouse]
2711
 
2711
 
2712
        xor     eax,eax
2712
        xor     eax,eax
2713
        mov     edx,[TASK_COUNT]
2713
        mov     edx,[TASK_COUNT]
2714
        movzx   edx,word[WIN_POS+edx*2]
2714
        movzx   edx,word[WIN_POS+edx*2]
2715
        cmp     edx,[CURRENT_TASK]
2715
        cmp     edx,[CURRENT_TASK]
2716
        jne     @f
2716
        jne     @f
2717
        inc     eax
2717
        inc     eax
2718
    @@: mov     edx,[CURRENT_TASK]
2718
    @@: mov     edx,[CURRENT_TASK]
2719
        shl     edx,5
2719
        shl     edx,5
2720
        add     edx,window_data
2720
        add     edx,window_data
2721
        movzx   ebx,[edx+WDATA.fl_wstyle]
2721
        movzx   ebx,[edx+WDATA.fl_wstyle]
2722
        and     bl,0x0F
2722
        and     bl,0x0F
2723
        cmp     bl,3
2723
        cmp     bl,3
2724
        jne     .not_style_3
2724
        jne     .not_style_3
2725
 
2725
 
2726
        push    edx
2726
        push    edx
2727
        call    drawwindow_IV_caption
2727
        call    drawwindow_IV_caption
2728
        add     esp,4
2728
        add     esp,4
2729
        jmp     .2
2729
        jmp     .2
2730
 
2730
 
2731
  .not_style_3:
2731
  .not_style_3:
2732
        cmp     bl,2
2732
        cmp     bl,2
2733
        jne     .not_style_2
2733
        jne     .not_style_2
2734
 
2734
 
2735
        call    drawwindow_III_caption
2735
        call    drawwindow_III_caption
2736
        jmp     .2
2736
        jmp     .2
2737
 
2737
 
2738
  .not_style_2:
2738
  .not_style_2:
2739
        cmp     bl,0
2739
        cmp     bl,0
2740
        jne     .2
2740
        jne     .2
2741
 
2741
 
2742
        call    drawwindow_I_caption
2742
        call    drawwindow_I_caption
2743
 
2743
 
2744
;--------------------------------------------------------------
2744
;--------------------------------------------------------------
2745
  .2:   ;jmp     @f
2745
  .2:   ;jmp     @f
2746
        mov     edi,[CURRENT_TASK]
2746
        mov     edi,[CURRENT_TASK]
2747
        shl     edi,5
2747
        shl     edi,5
2748
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2748
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2749
        jz      @f
2749
        jz      @f
2750
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2750
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2751
        or      ecx,ecx
2751
        or      ecx,ecx
2752
        jz      @f
2752
        jz      @f
2753
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2753
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2754
 
2754
 
2755
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2755
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2756
        and     al,0x0F
2756
        and     al,0x0F
2757
        cmp     al,3
2757
        cmp     al,3
2758
        jne     .not_skinned
2758
        jne     .not_skinned
2759
 
2759
 
2760
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2760
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2761
        mov     bp,word[edi+window_data+WDATA.box.top]
2761
        mov     bp,word[edi+window_data+WDATA.box.top]
2762
        movzx   eax,word[edi+window_data+WDATA.box.width]
2762
        movzx   eax,word[edi+window_data+WDATA.box.width]
2763
        sub     ax,[_skinmargins.left]
2763
        sub     ax,[_skinmargins.left]
2764
        sub     ax,[_skinmargins.right]
2764
        sub     ax,[_skinmargins.right]
2765
        cwde
2765
        cwde
2766
        cdq
2766
        cdq
2767
        mov     ebx,6
2767
        mov     ebx,6
2768
        idiv    ebx
2768
        idiv    ebx
2769
        or      eax,eax
2769
        or      eax,eax
2770
        js      @f
2770
        js      @f
2771
        mov     edx,eax
2771
        mov     edx,eax
2772
        mov     eax,dword[_skinmargins.left-2]
2772
        mov     eax,dword[_skinmargins.left-2]
2773
        mov     ax,word[_skinh]
2773
        mov     ax,word[_skinh]
2774
        sub     ax,[_skinmargins.bottom]
2774
        sub     ax,[_skinmargins.bottom]
2775
        sub     ax,[_skinmargins.top]
2775
        sub     ax,[_skinmargins.top]
2776
        sar     ax,1
2776
        sar     ax,1
2777
        adc     ax,0
2777
        adc     ax,0
2778
        add     ax,[_skinmargins.top]
2778
        add     ax,[_skinmargins.top]
2779
        add     ax,-3
2779
        add     ax,-3
2780
        add     eax,ebp
2780
        add     eax,ebp
2781
        jmp     .dodraw
2781
        jmp     .dodraw
2782
 
2782
 
2783
  .not_skinned:
2783
  .not_skinned:
2784
        cmp     al,1
2784
        cmp     al,1
2785
        je      @f
2785
        je      @f
2786
 
2786
 
2787
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2787
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2788
        mov     bp,word[edi+window_data+WDATA.box.top]
2788
        mov     bp,word[edi+window_data+WDATA.box.top]
2789
        movzx   eax,word[edi+window_data+WDATA.box.width]
2789
        movzx   eax,word[edi+window_data+WDATA.box.width]
2790
        sub     eax,16
2790
        sub     eax,16
2791
        cwde
2791
        cwde
2792
        cdq
2792
        cdq
2793
        mov     ebx,6
2793
        mov     ebx,6
2794
        idiv    ebx
2794
        idiv    ebx
2795
        or      eax,eax
2795
        or      eax,eax
2796
        js      @f
2796
        js      @f
2797
        mov     edx,eax
2797
        mov     edx,eax
2798
        mov     eax,0x00080007
2798
        mov     eax,0x00080007
2799
        add     eax,ebp
2799
        add     eax,ebp
2800
.dodraw:
2800
.dodraw:
2801
        mov     ebx,[common_colours+16];0x00FFFFFF
2801
        mov     ebx,[common_colours+16];0x00FFFFFF
2802
        or      ebx, 0x80000000
2802
        or      ebx, 0x80000000
2803
        xor     edi,edi
2803
        xor     edi,edi
2804
        call    dtext
2804
        call    dtext
2805
 
2805
 
2806
    @@:
2806
    @@:
2807
;--------------------------------------------------------------
2807
;--------------------------------------------------------------
2808
        dec     [mouse_pause]
2808
        dec     [mouse_pause]
2809
        call    [draw_pointer]
2809
        call    [draw_pointer]
2810
        ret
2810
        ret
2811
 
2811
 
2812
iglobal
2812
iglobal
2813
align 4
2813
align 4
2814
window_topleft dd \
2814
window_topleft dd \
2815
  1, 21,\
2815
  1, 21,\
2816
  0,  0,\
2816
  0,  0,\
2817
  5, 20,\
2817
  5, 20,\
2818
  5,  ?
2818
  5,  ?
2819
endg
2819
endg
2820
 
2820
 
2821
set_window_clientbox:
2821
set_window_clientbox:
2822
        push    eax ecx edi
2822
        push    eax ecx edi
2823
 
2823
 
2824
        mov     eax,[_skinh]
2824
        mov     eax,[_skinh]
2825
        mov     [window_topleft+4*7],eax
2825
        mov     [window_topleft+4*7],eax
2826
 
2826
 
2827
        mov     ecx,edi
2827
        mov     ecx,edi
2828
        sub     edi,window_data
2828
        sub     edi,window_data
2829
        shl     edi,3
2829
        shl     edi,3
2830
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
2830
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
2831
        jz      @f
2831
        jz      @f
2832
 
2832
 
2833
        movzx   eax,[ecx+WDATA.fl_wstyle]
2833
        movzx   eax,[ecx+WDATA.fl_wstyle]
2834
        and     eax,0x0F
2834
        and     eax,0x0F
2835
        mov     eax,[eax*8+window_topleft+0]
2835
        mov     eax,[eax*8+window_topleft+0]
2836
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2836
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2837
        shl     eax,1
2837
        shl     eax,1
2838
        neg     eax
2838
        neg     eax
2839
        add     eax,[ecx+WDATA.box.width]
2839
        add     eax,[ecx+WDATA.box.width]
2840
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2840
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2841
 
2841
 
2842
        movzx   eax,[ecx+WDATA.fl_wstyle]
2842
        movzx   eax,[ecx+WDATA.fl_wstyle]
2843
        and     eax,0x0F
2843
        and     eax,0x0F
2844
        push    [eax*8+window_topleft+0]
2844
        push    [eax*8+window_topleft+0]
2845
        mov     eax,[eax*8+window_topleft+4]
2845
        mov     eax,[eax*8+window_topleft+4]
2846
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2846
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2847
        neg     eax
2847
        neg     eax
2848
        sub     eax,[esp]
2848
        sub     eax,[esp]
2849
        add     eax,[ecx+WDATA.box.height]
2849
        add     eax,[ecx+WDATA.box.height]
2850
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2850
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2851
        add     esp,4
2851
        add     esp,4
2852
 
2852
 
2853
        pop     edi ecx eax
2853
        pop     edi ecx eax
2854
        ret
2854
        ret
2855
    @@:
2855
    @@:
2856
        xor     eax,eax
2856
        xor     eax,eax
2857
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2857
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2858
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2858
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2859
        mov     eax,[ecx+WDATA.box.width]
2859
        mov     eax,[ecx+WDATA.box.width]
2860
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2860
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2861
        mov     eax,[ecx+WDATA.box.height]
2861
        mov     eax,[ecx+WDATA.box.height]
2862
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2862
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2863
 
2863
 
2864
        pop     edi ecx eax
2864
        pop     edi ecx eax
2865
        ret
2865
        ret
2866
 
2866
 
2867
sys_set_window:
2867
sys_set_window:
2868
 
2868
 
2869
    mov   edi,[CURRENT_TASK]
2869
    mov   edi,[CURRENT_TASK]
2870
    shl   edi,5
2870
    shl   edi,5
2871
    add   edi,window_data
2871
    add   edi,window_data
2872
 
2872
 
2873
    ; colors
2873
    ; colors
2874
    mov   [edi+WDATA.cl_workarea],ecx
2874
    mov   [edi+WDATA.cl_workarea],ecx
2875
    mov   [edi+WDATA.cl_titlebar],edx
2875
    mov   [edi+WDATA.cl_titlebar],edx
2876
    mov   [edi+WDATA.cl_frames],esi
2876
    mov   [edi+WDATA.cl_frames],esi
2877
 
2877
 
2878
    ; check flag (?)
2878
    ; check flag (?)
2879
    test  [edi+WDATA.fl_wdrawn],1
2879
    test  [edi+WDATA.fl_wdrawn],1
2880
    jnz   newd
2880
    jnz   newd
2881
 
2881
 
2882
    push  eax
2882
    push  eax
2883
    mov   eax,[timer_ticks] ;[0xfdf0]
2883
    mov   eax,[timer_ticks] ;[0xfdf0]
2884
    add   eax,100
2884
    add   eax,100
2885
    mov   [new_window_starting],eax
2885
    mov   [new_window_starting],eax
2886
    pop   eax
2886
    pop   eax
2887
 
2887
 
2888
    mov   word[edi+WDATA.box.width],ax
2888
    mov   word[edi+WDATA.box.width],ax
2889
    mov   word[edi+WDATA.box.height],bx
2889
    mov   word[edi+WDATA.box.height],bx
2890
    sar   eax,16
2890
    sar   eax,16
2891
    sar   ebx,16
2891
    sar   ebx,16
2892
    mov   word[edi+WDATA.box.left],ax
2892
    mov   word[edi+WDATA.box.left],ax
2893
    mov   word[edi+WDATA.box.top],bx
2893
    mov   word[edi+WDATA.box.top],bx
2894
 
2894
 
2895
    call  check_window_position
2895
    call  check_window_position
2896
 
2896
 
2897
    call  set_window_clientbox
2897
    call  set_window_clientbox
2898
 
2898
 
2899
    push  ecx esi edi               ; save for window fullscreen/resize
2899
    push  ecx esi edi               ; save for window fullscreen/resize
2900
    ;mov   esi,edi
2900
    ;mov   esi,edi
2901
 
2901
 
2902
        mov     cl,[edi+WDATA.fl_wstyle]
2902
        mov     cl,[edi+WDATA.fl_wstyle]
2903
 
2903
 
2904
    sub   edi,window_data
2904
    sub   edi,window_data
2905
    shl   edi,3
2905
    shl   edi,3
2906
    add   edi,SLOT_BASE
2906
    add   edi,SLOT_BASE
2907
 
2907
 
2908
        and     cl,0x0F
2908
        and     cl,0x0F
2909
        mov     [edi+APPDATA.wnd_caption],0
2909
        mov     [edi+APPDATA.wnd_caption],0
2910
        cmp     cl,3
2910
        cmp     cl,3
2911
        jne     @f
2911
        jne     @f
2912
        mov     [edi+APPDATA.wnd_caption],esi
2912
        mov     [edi+APPDATA.wnd_caption],esi
2913
    @@: mov     esi,[esp+0]
2913
    @@: mov     esi,[esp+0]
2914
 
2914
 
2915
    add   edi, APPDATA.saved_box
2915
    add   edi, APPDATA.saved_box
2916
        movsd
2916
        movsd
2917
        movsd
2917
        movsd
2918
        movsd
2918
        movsd
2919
        movsd
2919
        movsd
2920
    pop   edi esi ecx
2920
    pop   edi esi ecx
2921
 
2921
 
2922
    push  eax ebx ecx edx
2922
    push  eax ebx ecx edx
2923
;;;    mov   eax, 1
2923
;;;    mov   eax, 1
2924
;;;    call  delay_hs
2924
;;;    call  delay_hs
2925
    mov   eax, [edi+WDATA.box.left]
2925
    mov   eax, [edi+WDATA.box.left]
2926
    mov   ebx, [edi+WDATA.box.top]
2926
    mov   ebx, [edi+WDATA.box.top]
2927
    mov   ecx, [edi+WDATA.box.width]
2927
    mov   ecx, [edi+WDATA.box.width]
2928
    mov   edx, [edi+WDATA.box.height]
2928
    mov   edx, [edi+WDATA.box.height]
2929
    add   ecx, eax
2929
    add   ecx, eax
2930
    add   edx, ebx
2930
    add   edx, ebx
2931
    call  calculatescreen
2931
    call  calculatescreen
2932
    pop   edx ecx ebx eax
2932
    pop   edx ecx ebx eax
2933
 
2933
 
2934
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
2934
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
2935
    mov   [BTN_COUNT],byte 0           ; empty button buffer
2935
    mov   [BTN_COUNT],byte 0           ; empty button buffer
2936
 
2936
 
2937
  newd:
2937
  newd:
2938
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
2938
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
2939
    mov   edx,edi
2939
    mov   edx,edi
2940
 
2940
 
2941
    ret
2941
    ret
2942
 
2942
 
2943
syscall_windowsettings:
2943
syscall_windowsettings:
2944
 
2944
 
2945
  .set_window_caption:
2945
  .set_window_caption:
2946
        dec     eax     ; subfunction #1 - set window caption
2946
        dec     eax     ; subfunction #1 - set window caption
2947
        jnz     .get_window_caption
2947
        jnz     .get_window_caption
2948
 
2948
 
2949
        ; NOTE: only window owner thread can set its caption,
2949
        ; NOTE: only window owner thread can set its caption,
2950
        ;       so there's no parameter for PID/TID
2950
        ;       so there's no parameter for PID/TID
2951
 
2951
 
2952
        mov     edi,[CURRENT_TASK]
2952
        mov     edi,[CURRENT_TASK]
2953
        shl     edi,5
2953
        shl     edi,5
2954
 
2954
 
2955
        ; have to check if caption is within application memory limit
2955
        ; have to check if caption is within application memory limit
2956
        ; check is trivial, and if application resizes its memory,
2956
        ; check is trivial, and if application resizes its memory,
2957
        ;   caption still can become over bounds
2957
        ;   caption still can become over bounds
2958
; diamond, 31.10.2006: check removed because with new memory manager
2958
; diamond, 31.10.2006: check removed because with new memory manager
2959
; there can be valid data after APPDATA.mem_size bound
2959
; there can be valid data after APPDATA.mem_size bound
2960
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
2960
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
2961
;        add     ecx,255 ; max caption length
2961
;        add     ecx,255 ; max caption length
2962
;        cmp     ebx,ecx
2962
;        cmp     ebx,ecx
2963
;        ja      .exit_fail
2963
;        ja      .exit_fail
2964
 
2964
 
2965
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
2965
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
2966
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2966
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2967
 
2967
 
2968
        call    draw_window_caption
2968
        call    draw_window_caption
2969
 
2969
 
2970
        xor     eax,eax ; eax = 0 (success)
2970
        xor     eax,eax ; eax = 0 (success)
2971
        ret
2971
        ret
2972
 
2972
 
2973
  .get_window_caption:
2973
  .get_window_caption:
2974
        dec     eax     ; subfunction #2 - get window caption
2974
        dec     eax     ; subfunction #2 - get window caption
2975
        jnz     .exit_fail
2975
        jnz     .exit_fail
2976
 
2976
 
2977
        ; not implemented yet
2977
        ; not implemented yet
2978
 
2978
 
2979
  .exit_fail:
2979
  .exit_fail:
2980
        xor     eax,eax
2980
        xor     eax,eax
2981
        inc     eax     ; eax = 1 (fail)
2981
        inc     eax     ; eax = 1 (fail)
2982
        ret
2982
        ret
2983
 
2983
 
2984
 
2984
 
2985
sys_window_move:
2985
sys_window_move:
2986
 
2986
 
2987
        mov     edi,[CURRENT_TASK]
2987
        mov     edi,[CURRENT_TASK]
2988
        shl     edi,5
2988
        shl     edi,5
2989
        add     edi,window_data
2989
        add     edi,window_data
2990
 
2990
 
2991
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
2991
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
2992
        jnz     .window_move_return
2992
        jnz     .window_move_return
2993
 
2993
 
2994
        push    dword [edi + WDATA.box.left]  ; save old coordinates
2994
        push    dword [edi + WDATA.box.left]  ; save old coordinates
2995
        push    dword [edi + WDATA.box.top]
2995
        push    dword [edi + WDATA.box.top]
2996
        push    dword [edi + WDATA.box.width]
2996
        push    dword [edi + WDATA.box.width]
2997
        push    dword [edi + WDATA.box.height]
2997
        push    dword [edi + WDATA.box.height]
2998
 
2998
 
2999
        cmp   eax,-1                  ; set new position and size
2999
        cmp   eax,-1                  ; set new position and size
3000
        je    .no_x_reposition
3000
        je    .no_x_reposition
3001
        mov     [edi + WDATA.box.left], eax
3001
        mov     [edi + WDATA.box.left], eax
3002
      .no_x_reposition:
3002
      .no_x_reposition:
3003
        cmp   ebx,-1
3003
        cmp   ebx,-1
3004
        je    .no_y_reposition
3004
        je    .no_y_reposition
3005
        mov     [edi + WDATA.box.top], ebx
3005
        mov     [edi + WDATA.box.top], ebx
3006
      .no_y_reposition:
3006
      .no_y_reposition:
3007
 
3007
 
3008
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3008
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3009
        jnz     .no_y_resizing
3009
        jnz     .no_y_resizing
3010
 
3010
 
3011
        cmp   ecx,-1
3011
        cmp   ecx,-1
3012
        je    .no_x_resizing
3012
        je    .no_x_resizing
3013
        mov     [edi + WDATA.box.width], ecx
3013
        mov     [edi + WDATA.box.width], ecx
3014
      .no_x_resizing:
3014
      .no_x_resizing:
3015
        cmp   edx,-1
3015
        cmp   edx,-1
3016
        je    .no_y_resizing
3016
        je    .no_y_resizing
3017
        mov     [edi + WDATA.box.height], edx
3017
        mov     [edi + WDATA.box.height], edx
3018
      .no_y_resizing:
3018
      .no_y_resizing:
3019
 
3019
 
3020
        call  check_window_position
3020
        call  check_window_position
3021
        call  set_window_clientbox
3021
        call  set_window_clientbox
3022
 
3022
 
3023
        pushad                       ; save for window fullscreen/resize
3023
        pushad                       ; save for window fullscreen/resize
3024
        mov   esi,edi
3024
        mov   esi,edi
3025
        sub   edi,window_data
3025
        sub   edi,window_data
3026
        shr   edi,5
3026
        shr   edi,5
3027
        shl   edi,8
3027
        shl   edi,8
3028
        add   edi, SLOT_BASE + APPDATA.saved_box
3028
        add   edi, SLOT_BASE + APPDATA.saved_box
3029
        mov   ecx,4
3029
        mov   ecx,4
3030
        cld
3030
        cld
3031
        rep   movsd
3031
        rep   movsd
3032
        popad
3032
        popad
3033
 
3033
 
3034
        pushad                       ; calculcate screen at new position
3034
        pushad                       ; calculcate screen at new position
3035
        mov   eax, [edi + WDATA.box.left]
3035
        mov   eax, [edi + WDATA.box.left]
3036
        mov   ebx, [edi + WDATA.box.top]
3036
        mov   ebx, [edi + WDATA.box.top]
3037
        mov   ecx, [edi + WDATA.box.width]
3037
        mov   ecx, [edi + WDATA.box.width]
3038
        mov   edx, [edi + WDATA.box.height]
3038
        mov   edx, [edi + WDATA.box.height]
3039
        add   ecx,eax
3039
        add   ecx,eax
3040
        add   edx,ebx
3040
        add   edx,ebx
3041
 
3041
 
3042
        call  calculatescreen
3042
        call  calculatescreen
3043
        popad
3043
        popad
3044
 
3044
 
3045
        pop   edx                   ; calculcate screen at old position
3045
        pop   edx                   ; calculcate screen at old position
3046
        pop   ecx
3046
        pop   ecx
3047
        pop   ebx
3047
        pop   ebx
3048
        pop   eax
3048
        pop   eax
3049
        add   ecx,eax
3049
        add   ecx,eax
3050
        add   edx,ebx
3050
        add   edx,ebx
3051
        mov   [dlx],eax             ; save for drawlimits
3051
        mov   [dlx],eax             ; save for drawlimits
3052
        mov   [dly],ebx
3052
        mov   [dly],ebx
3053
        mov   [dlxe],ecx
3053
        mov   [dlxe],ecx
3054
        mov   [dlye],edx
3054
        mov   [dlye],edx
3055
        call  calculatescreen
3055
        call  calculatescreen
3056
 
3056
 
3057
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3057
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3058
 
3058
 
3059
        mov   eax,edi               ; redraw screen at old position
3059
        mov   eax,edi               ; redraw screen at old position
3060
        xor   esi,esi
3060
        xor   esi,esi
3061
        call  redrawscreen
3061
        call  redrawscreen
3062
 
3062
 
3063
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3063
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3064
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3064
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3065
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3065
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3066
 
3066
 
3067
        mov   ecx,10          ; wait 1/10 second
3067
        mov   ecx,10          ; wait 1/10 second
3068
      .wmrl3:
3068
      .wmrl3:
3069
        call  [draw_pointer]
3069
        call  [draw_pointer]
3070
        mov   eax,1
3070
        mov   eax,1
3071
        call  delay_hs
3071
        call  delay_hs
3072
        loop  .wmrl3
3072
        loop  .wmrl3
3073
 
3073
 
3074
        mov   [window_move_pr],0
3074
        mov   [window_move_pr],0
3075
 
3075
 
3076
      .window_move_return:
3076
      .window_move_return:
3077
 
3077
 
3078
        ret
3078
        ret
3079
 
3079
 
3080
;type_background_1:
3080
;type_background_1:
3081
;    cmp   [0xfff0],byte 0               ; background update ?
3081
;    cmp   [0xfff0],byte 0               ; background update ?
3082
;    jz    temp_nobackgr
3082
;    jz    temp_nobackgr
3083
;    mov   [0xfff0],byte 2
3083
;    mov   [0xfff0],byte 2
3084
;    call  change_task
3084
;    call  change_task
3085
;    mov   [draw_data+32+0],dword 0
3085
;    mov   [draw_data+32+0],dword 0
3086
;    mov   [draw_data+32+4],dword 0
3086
;    mov   [draw_data+32+4],dword 0
3087
;    mov   eax,[ScreenWidth
3087
;    mov   eax,[ScreenWidth
3088
;    mov   ebx,[0xfe04]
3088
;    mov   ebx,[0xfe04]
3089
;    mov   [draw_data+32+8],eax
3089
;    mov   [draw_data+32+8],eax
3090
;    mov   [draw_data+32+12],ebx
3090
;    mov   [draw_data+32+12],ebx
3091
;    call  drawbackground
3091
;    call  drawbackground
3092
;    mov   [0xfff0],byte 0
3092
;    mov   [0xfff0],byte 0
3093
;    mov   [MOUSE_BACKGROUND],byte 0
3093
;    mov   [MOUSE_BACKGROUND],byte 0
3094
;temp_nobackgr:
3094
;temp_nobackgr:
3095
;    ret
3095
;    ret
3096
 
3096
 
3097
uglobal
3097
uglobal
3098
  window_move_pr   dd  0x0
3098
  window_move_pr   dd  0x0
3099
  window_move_eax  dd  0x0
3099
  window_move_eax  dd  0x0
3100
  window_move_ebx  dd  0x0
3100
  window_move_ebx  dd  0x0
3101
  window_move_ecx  dd  0x0
3101
  window_move_ecx  dd  0x0
3102
  window_move_edx  dd  0x0
3102
  window_move_edx  dd  0x0
3103
endg
3103
endg
3104
 
3104
 
3105
;ok - 100% work
3105
;ok - 100% work
3106
;nt - not tested
3106
;nt - not tested
3107
;---------------------------------------------------------------------------------------------
3107
;---------------------------------------------------------------------------------------------
3108
;eax
3108
;eax
3109
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3109
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3110
;1 - change task. Ret nothing. Block. ok.
3110
;1 - change task. Ret nothing. Block. ok.
3111
;2 - performance control
3111
;2 - performance control
3112
; ebx
3112
; ebx
3113
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3113
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3114
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3114
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3115
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3115
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3116
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3116
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3117
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3117
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3118
;eax
3118
;eax
3119
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3119
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3120
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3120
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3121
;---------------------------------------------------------------------------------------------
3121
;---------------------------------------------------------------------------------------------
3122
sys_sheduler: ;noname & halyavin
3122
sys_sheduler: ;noname & halyavin
3123
    cmp eax,0
3123
    cmp eax,0
3124
    je shed_counter
3124
    je shed_counter
3125
    cmp eax,2
3125
    cmp eax,2
3126
    je perf_control
3126
    je perf_control
3127
    cmp eax,3
3127
    cmp eax,3
3128
    je rdmsr_instr
3128
    je rdmsr_instr
3129
    cmp eax,4
3129
    cmp eax,4
3130
    je wrmsr_instr
3130
    je wrmsr_instr
3131
    cmp eax,1
3131
    cmp eax,1
3132
    jne not_supported
3132
    jne not_supported
3133
    call change_task ;delay,0
3133
    call change_task ;delay,0
3134
ret
3134
ret
3135
shed_counter:
3135
shed_counter:
3136
    mov eax,[context_counter]
3136
    mov eax,[context_counter]
3137
    mov [esp+36],eax
3137
    mov [esp+36],eax
3138
not_supported:
3138
not_supported:
3139
ret
3139
ret
3140
perf_control:
3140
perf_control:
3141
    inc eax ;now eax=3
3141
    inc eax ;now eax=3
3142
    cmp ebx,eax
3142
    cmp ebx,eax
3143
    je cache_disable
3143
    je cache_disable
3144
    dec eax
3144
    dec eax
3145
    cmp ebx,eax
3145
    cmp ebx,eax
3146
    je cache_enable
3146
    je cache_enable
3147
    dec eax
3147
    dec eax
3148
    cmp ebx,eax
3148
    cmp ebx,eax
3149
    je is_cache_enabled
3149
    je is_cache_enabled
3150
    dec eax
3150
    dec eax
3151
    cmp ebx,eax
3151
    cmp ebx,eax
3152
    je modify_pce
3152
    je modify_pce
3153
ret
3153
ret
3154
 
3154
 
3155
rdmsr_instr:
3155
rdmsr_instr:
3156
;now counter in ecx
3156
;now counter in ecx
3157
;(edx:eax) esi:edi => edx:esi
3157
;(edx:eax) esi:edi => edx:esi
3158
mov eax,esi
3158
mov eax,esi
3159
rdmsr
3159
rdmsr
3160
mov [esp+36],eax
3160
mov [esp+36],eax
3161
mov [esp+24],edx ;ret in ebx?
3161
mov [esp+24],edx ;ret in ebx?
3162
ret
3162
ret
3163
 
3163
 
3164
wrmsr_instr:
3164
wrmsr_instr:
3165
;now counter in ecx
3165
;now counter in ecx
3166
;(edx:eax) esi:edi => edx:esi
3166
;(edx:eax) esi:edi => edx:esi
3167
mov eax,esi
3167
mov eax,esi
3168
wrmsr
3168
wrmsr
3169
mov [esp+36],eax
3169
mov [esp+36],eax
3170
mov [esp+24],edx ;ret in ebx?
3170
mov [esp+24],edx ;ret in ebx?
3171
ret
3171
ret
3172
 
3172
 
3173
cache_disable:
3173
cache_disable:
3174
       mov eax,cr0
3174
       mov eax,cr0
3175
       or  eax,01100000000000000000000000000000b
3175
       or  eax,01100000000000000000000000000000b
3176
       mov cr0,eax
3176
       mov cr0,eax
3177
       wbinvd ;set MESI
3177
       wbinvd ;set MESI
3178
ret
3178
ret
3179
 
3179
 
3180
cache_enable:
3180
cache_enable:
3181
       mov eax,cr0
3181
       mov eax,cr0
3182
       and eax,10011111111111111111111111111111b
3182
       and eax,10011111111111111111111111111111b
3183
       mov cr0,eax
3183
       mov cr0,eax
3184
ret
3184
ret
3185
 
3185
 
3186
is_cache_enabled:
3186
is_cache_enabled:
3187
       mov eax,cr0
3187
       mov eax,cr0
3188
       mov ebx,eax
3188
       mov ebx,eax
3189
       and eax,01100000000000000000000000000000b
3189
       and eax,01100000000000000000000000000000b
3190
       jz cache_disabled
3190
       jz cache_disabled
3191
       mov [esp+36],ebx
3191
       mov [esp+36],ebx
3192
cache_disabled:
3192
cache_disabled:
3193
       mov dword [esp+36],eax ;0
3193
       mov dword [esp+36],eax ;0
3194
ret
3194
ret
3195
 
3195
 
3196
modify_pce:
3196
modify_pce:
3197
       mov eax,cr4
3197
       mov eax,cr4
3198
;       mov ebx,0
3198
;       mov ebx,0
3199
;       or  bx,100000000b ;pce
3199
;       or  bx,100000000b ;pce
3200
;       xor eax,ebx ;invert pce
3200
;       xor eax,ebx ;invert pce
3201
       bts eax,8 ;pce=cr4[8]
3201
       bts eax,8 ;pce=cr4[8]
3202
       mov cr4,eax
3202
       mov cr4,eax
3203
       mov [esp+36],eax
3203
       mov [esp+36],eax
3204
ret
3204
ret
3205
;---------------------------------------------------------------------------------------------
3205
;---------------------------------------------------------------------------------------------
3206
 
3206
 
3207
 
3207
 
3208
; check if pixel is allowed to be drawn
3208
; check if pixel is allowed to be drawn
3209
 
3209
 
3210
checkpixel:
3210
checkpixel:
3211
        push eax edx
3211
        push eax edx
3212
 
3212
 
3213
        mov  edx,[ScreenWidth]     ; screen x size
3213
        mov  edx,[ScreenWidth]     ; screen x size
3214
        inc  edx
3214
        inc  edx
3215
        imul edx, ebx
3215
        imul edx, ebx
3216
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3216
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3217
 
3217
 
3218
        xor  ecx, ecx
3218
        xor  ecx, ecx
3219
        mov  eax, [CURRENT_TASK]
3219
        mov  eax, [CURRENT_TASK]
3220
        cmp  al, dl
3220
        cmp  al, dl
3221
        setne cl
3221
        setne cl
3222
 
3222
 
3223
        pop  edx eax
3223
        pop  edx eax
3224
        ret
3224
        ret
3225
 
3225
 
3226
uglobal
3226
uglobal
3227
  mouse_active  db  0
3227
  mouse_active  db  0
3228
endg
3228
endg
3229
iglobal
3229
iglobal
3230
  cpustring db '/RD/1/CPU',0
3230
  cpustring db '/RD/1/CPU',0
3231
endg
3231
endg
3232
 
3232
 
3233
uglobal
3233
uglobal
3234
background_defined    db    0    ; diamond, 11.04.2006
3234
background_defined    db    0    ; diamond, 11.04.2006
3235
endg
3235
endg
3236
 
3236
 
3237
align 4
3237
align 4
3238
; check misc
3238
; check misc
3239
 
3239
 
3240
checkmisc:
3240
checkmisc:
3241
 
3241
 
3242
    cmp   [ctrl_alt_del], 1
3242
    cmp   [ctrl_alt_del], 1
3243
    jne   nocpustart
3243
    jne   nocpustart
3244
    mov   ebp, cpustring
3244
    mov   ebp, cpustring
3245
    lea   esi,[ebp+6]
3245
    lea   esi,[ebp+6]
3246
    xor   ebx,ebx               ; no parameters
3246
    xor   ebx,ebx               ; no parameters
3247
    xor   edx,edx               ; no flags
3247
    xor   edx,edx               ; no flags
3248
    call  fs_RamdiskExecute.flags
3248
    call  fs_RamdiskExecute.flags
3249
    mov   [ctrl_alt_del], 0
3249
    mov   [ctrl_alt_del], 0
3250
  nocpustart:
3250
  nocpustart:
3251
    cmp   [mouse_active], 1
3251
    cmp   [mouse_active], 1
3252
    jne   mouse_not_active
3252
    jne   mouse_not_active
3253
    mov   [mouse_active], 0
3253
    mov   [mouse_active], 0
3254
    xor   edi, edi
3254
    xor   edi, edi
3255
    mov   ecx, [TASK_COUNT]
3255
    mov   ecx, [TASK_COUNT]
3256
   set_mouse_event:
3256
   set_mouse_event:
3257
    add   edi, 256
3257
    add   edi, 256
3258
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 00100000b
3258
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 00100000b
3259
    loop  set_mouse_event
3259
    loop  set_mouse_event
3260
  mouse_not_active:
3260
  mouse_not_active:
3261
 
3261
 
3262
 
3262
 
3263
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3263
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3264
    jz    nobackgr
3264
    jz    nobackgr
3265
    cmp    [background_defined], 0
3265
    cmp    [background_defined], 0
3266
    jz    nobackgr
3266
    jz    nobackgr
3267
    mov   [REDRAW_BACKGROUND],byte 2
3267
    mov   [REDRAW_BACKGROUND],byte 2
3268
    call  change_task
3268
    call  change_task
3269
	mov   [draw_data+32 + RECT.left],dword 0
3269
	mov   [draw_data+32 + RECT.left],dword 0
3270
	mov   [draw_data+32 + RECT.top],dword 0
3270
	mov   [draw_data+32 + RECT.top],dword 0
3271
    mov   eax,[ScreenWidth]
3271
    mov   eax,[ScreenWidth]
3272
    mov   ebx,[ScreenHeight]
3272
    mov   ebx,[ScreenHeight]
3273
	mov   [draw_data+32 + RECT.right],eax
3273
	mov   [draw_data+32 + RECT.right],eax
3274
	mov   [draw_data+32 + RECT.bottom],ebx
3274
	mov   [draw_data+32 + RECT.bottom],ebx
3275
    call  drawbackground
3275
    call  drawbackground
3276
    mov   [REDRAW_BACKGROUND],byte 0
3276
    mov   [REDRAW_BACKGROUND],byte 0
3277
    mov   [MOUSE_BACKGROUND],byte 0
3277
    mov   [MOUSE_BACKGROUND],byte 0
3278
 
3278
 
3279
  nobackgr:
3279
  nobackgr:
3280
 
3280
 
3281
 
3281
 
3282
    ; system shutdown request
3282
    ; system shutdown request
3283
 
3283
 
3284
    cmp  [SYS_SHUTDOWN],byte 0
3284
    cmp  [SYS_SHUTDOWN],byte 0
3285
    je   noshutdown
3285
    je   noshutdown
3286
 
3286
 
3287
    mov  edx,[shutdown_processes]
3287
    mov  edx,[shutdown_processes]
3288
    sub  dl,2
3288
    sub  dl,2
3289
 
3289
 
3290
    cmp  [SYS_SHUTDOWN],dl
3290
    cmp  [SYS_SHUTDOWN],dl
3291
    jne  no_mark_system_shutdown
3291
    jne  no_mark_system_shutdown
3292
 
3292
 
3293
    mov   edx,OS_BASE+0x3040
3293
    mov   edx,OS_BASE+0x3040
3294
    movzx ecx,byte [SYS_SHUTDOWN]
3294
    movzx ecx,byte [SYS_SHUTDOWN]
3295
    add   ecx,5
3295
    add   ecx,5
3296
  markz:
3296
  markz:
3297
    mov   [edx+TASKDATA.state],byte 3
3297
    mov   [edx+TASKDATA.state],byte 3
3298
    add   edx,0x20
3298
    add   edx,0x20
3299
    loop  markz
3299
    loop  markz
3300
 
3300
 
3301
  no_mark_system_shutdown:
3301
  no_mark_system_shutdown:
3302
 
3302
 
3303
    call [disable_mouse]
3303
    call [disable_mouse]
3304
 
3304
 
3305
    dec  byte [SYS_SHUTDOWN]
3305
    dec  byte [SYS_SHUTDOWN]
3306
 
3306
 
3307
    cmp  [SYS_SHUTDOWN],byte 0
3307
    cmp  [SYS_SHUTDOWN],byte 0
3308
    je   system_shutdown
3308
    je   system_shutdown
3309
 
3309
 
3310
  noshutdown:
3310
  noshutdown:
3311
 
3311
 
3312
 
3312
 
3313
    mov   eax,[TASK_COUNT]                  ; termination
3313
    mov   eax,[TASK_COUNT]                  ; termination
3314
    mov   ebx,TASK_DATA+TASKDATA.state
3314
    mov   ebx,TASK_DATA+TASKDATA.state
3315
    mov   esi,1
3315
    mov   esi,1
3316
 
3316
 
3317
  newct:
3317
  newct:
3318
    mov   cl,[ebx]
3318
    mov   cl,[ebx]
3319
    cmp   cl,byte 3
3319
    cmp   cl,byte 3
3320
    jz    terminate
3320
    jz    terminate
3321
    cmp   cl,byte 4
3321
    cmp   cl,byte 4
3322
    jz    terminate
3322
    jz    terminate
3323
 
3323
 
3324
    add   ebx,0x20
3324
    add   ebx,0x20
3325
    inc   esi
3325
    inc   esi
3326
    dec   eax
3326
    dec   eax
3327
    jnz   newct
3327
    jnz   newct
3328
 
3328
 
3329
    ret
3329
    ret
3330
 
3330
 
3331
 
3331
 
3332
 
3332
 
3333
 
3333
 
3334
; redraw screen
3334
; redraw screen
3335
 
3335
 
3336
redrawscreen:
3336
redrawscreen:
3337
 
3337
 
3338
; eax , if process window_data base is eax, do not set flag/limits
3338
; eax , if process window_data base is eax, do not set flag/limits
3339
 
3339
 
3340
         pushad
3340
         pushad
3341
         push  eax
3341
         push  eax
3342
 
3342
 
3343
;;;         mov   eax,2
3343
;;;         mov   eax,2
3344
;;;         call  delay_hs
3344
;;;         call  delay_hs
3345
 
3345
 
3346
         ;mov   ecx,0               ; redraw flags for apps
3346
         ;mov   ecx,0               ; redraw flags for apps
3347
         xor   ecx,ecx
3347
         xor   ecx,ecx
3348
       newdw2:
3348
       newdw2:
3349
 
3349
 
3350
         inc   ecx
3350
         inc   ecx
3351
         push  ecx
3351
         push  ecx
3352
 
3352
 
3353
         mov   eax,ecx
3353
         mov   eax,ecx
3354
         shl   eax,5
3354
         shl   eax,5
3355
         add   eax,window_data
3355
         add   eax,window_data
3356
 
3356
 
3357
         cmp   eax,[esp+4]
3357
         cmp   eax,[esp+4]
3358
         je    not_this_task
3358
         je    not_this_task
3359
                                   ; check if window in redraw area
3359
                                   ; check if window in redraw area
3360
         mov   edi,eax
3360
         mov   edi,eax
3361
 
3361
 
3362
         cmp   ecx,1               ; limit for background
3362
         cmp   ecx,1               ; limit for background
3363
         jz    bgli
3363
         jz    bgli
3364
 
3364
 
3365
         mov   eax, [edi + WDATA.box.left]
3365
         mov   eax, [edi + WDATA.box.left]
3366
         mov   ebx, [edi + WDATA.box.top]
3366
         mov   ebx, [edi + WDATA.box.top]
3367
         mov   ecx, [edi + WDATA.box.width]
3367
         mov   ecx, [edi + WDATA.box.width]
3368
         mov   edx, [edi + WDATA.box.height]
3368
         mov   edx, [edi + WDATA.box.height]
3369
         add   ecx,eax
3369
         add   ecx,eax
3370
         add   edx,ebx
3370
         add   edx,ebx
3371
 
3371
 
3372
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3372
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3373
         cmp   ecx,ebx
3373
         cmp   ecx,ebx
3374
         jb    ricino
3374
         jb    ricino
3375
 
3375
 
3376
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3376
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3377
         cmp   ecx,eax
3377
         cmp   ecx,eax
3378
         jb    ricino
3378
         jb    ricino
3379
 
3379
 
3380
         mov   eax, [edi + WDATA.box.left]
3380
         mov   eax, [edi + WDATA.box.left]
3381
         mov   ebx, [edi + WDATA.box.top]
3381
         mov   ebx, [edi + WDATA.box.top]
3382
         mov   ecx, [edi + WDATA.box.width]
3382
         mov   ecx, [edi + WDATA.box.width]
3383
         mov   edx, [edi + WDATA.box.height]
3383
         mov   edx, [edi + WDATA.box.height]
3384
         add   ecx, eax
3384
         add   ecx, eax
3385
         add   edx, ebx
3385
         add   edx, ebx
3386
 
3386
 
3387
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3387
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3388
         cmp   edx,eax
3388
         cmp   edx,eax
3389
         jb    ricino
3389
         jb    ricino
3390
 
3390
 
3391
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3391
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3392
         cmp   ecx,eax
3392
         cmp   ecx,eax
3393
         jb    ricino
3393
         jb    ricino
3394
 
3394
 
3395
        bgli:
3395
        bgli:
3396
 
3396
 
3397
         cmp   edi,esi
3397
         cmp   edi,esi
3398
         jz    ricino
3398
         jz    ricino
3399
 
3399
 
3400
         mov   eax,edi
3400
         mov   eax,edi
3401
         add   eax,draw_data-window_data
3401
         add   eax,draw_data-window_data
3402
 
3402
 
3403
         mov   ebx,[dlx]          ; set limits
3403
         mov   ebx,[dlx]          ; set limits
3404
         mov   [eax + RECT.left], ebx
3404
         mov   [eax + RECT.left], ebx
3405
         mov   ebx,[dly]
3405
         mov   ebx,[dly]
3406
         mov   [eax + RECT.top], ebx
3406
         mov   [eax + RECT.top], ebx
3407
         mov   ebx,[dlxe]
3407
         mov   ebx,[dlxe]
3408
         mov   [eax + RECT.right], ebx
3408
         mov   [eax + RECT.right], ebx
3409
         mov   ebx,[dlye]
3409
         mov   ebx,[dlye]
3410
         mov   [eax + RECT.bottom], ebx
3410
         mov   [eax + RECT.bottom], ebx
3411
 
3411
 
3412
         sub   eax,draw_data-window_data
3412
         sub   eax,draw_data-window_data
3413
 
3413
 
3414
         cmp   ecx,1
3414
         cmp   ecx,1
3415
         jne   nobgrd
3415
         jne   nobgrd
3416
         cmp   esi,1
3416
         cmp   esi,1
3417
         je    newdw8
3417
         je    newdw8
3418
         call  drawbackground
3418
         call  drawbackground
3419
 
3419
 
3420
       newdw8:
3420
       newdw8:
3421
       nobgrd:
3421
       nobgrd:
3422
 
3422
 
3423
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3423
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3424
 
3424
 
3425
       ricino:
3425
       ricino:
3426
 
3426
 
3427
       not_this_task:
3427
       not_this_task:
3428
 
3428
 
3429
         pop   ecx
3429
         pop   ecx
3430
 
3430
 
3431
         cmp   ecx,[TASK_COUNT]
3431
         cmp   ecx,[TASK_COUNT]
3432
         jle   newdw2
3432
         jle   newdw2
3433
 
3433
 
3434
         pop  eax
3434
         pop  eax
3435
         popad
3435
         popad
3436
 
3436
 
3437
         ret
3437
         ret
3438
 
3438
 
3439
calculatebackground:   ; background
3439
calculatebackground:   ; background
3440
 
3440
 
3441
        ; all black
3441
        ; all black
3442
 
3442
 
3443
        mov   [display_data-8],dword 4      ; size x
3443
        mov   [display_data-8],dword 4      ; size x
3444
        mov   [display_data-4],dword 2      ; size y
3444
        mov   [display_data-4],dword 2      ; size y
3445
 
3445
 
3446
        mov   edi, IMG_BACKGROUND                 ; set background to black
3446
        mov   edi, IMG_BACKGROUND                 ; set background to black
3447
        xor   eax, eax
3447
        xor   eax, eax
3448
        mov   ecx, 0x0fff00 / 4
3448
        mov   ecx, 0x0fff00 / 4
3449
        cld
3449
        cld
3450
        rep   stosd
3450
        rep   stosd
3451
 
3451
 
3452
        mov   edi,display_data              ; set os to use all pixels
3452
        mov   edi,display_data              ; set os to use all pixels
3453
        mov   eax,0x01010101
3453
        mov   eax,0x01010101
3454
        mov   ecx,0x15ff00 / 4
3454
        mov   ecx,0x15ff00 / 4
3455
        rep   stosd
3455
        rep   stosd
3456
 
3456
 
3457
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3457
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3458
 
3458
 
3459
        ret
3459
        ret
3460
 
3460
 
3461
uglobal
3461
uglobal
3462
  imax    dd 0x0
3462
  imax    dd 0x0
3463
endg
3463
endg
3464
 
3464
 
3465
 
3465
 
3466
 
3466
 
3467
delay_ms:     ; delay in 1/1000 sec
3467
delay_ms:     ; delay in 1/1000 sec
3468
 
3468
 
3469
 
3469
 
3470
        push  eax
3470
        push  eax
3471
        push  ecx
3471
        push  ecx
3472
 
3472
 
3473
        mov   ecx,esi
3473
        mov   ecx,esi
3474
        ; 
3474
        ; 
3475
        imul  ecx, 33941
3475
        imul  ecx, 33941
3476
        shr   ecx, 9
3476
        shr   ecx, 9
3477
        ; 
3477
        ; 
3478
 
3478
 
3479
        in    al,0x61
3479
        in    al,0x61
3480
        and   al,0x10
3480
        and   al,0x10
3481
        mov   ah,al
3481
        mov   ah,al
3482
        cld
3482
        cld
3483
 
3483
 
3484
 cnt1:  in    al,0x61
3484
 cnt1:  in    al,0x61
3485
        and   al,0x10
3485
        and   al,0x10
3486
        cmp   al,ah
3486
        cmp   al,ah
3487
        jz    cnt1
3487
        jz    cnt1
3488
 
3488
 
3489
        mov   ah,al
3489
        mov   ah,al
3490
        loop  cnt1
3490
        loop  cnt1
3491
 
3491
 
3492
        pop   ecx
3492
        pop   ecx
3493
        pop   eax
3493
        pop   eax
3494
 
3494
 
3495
        ret
3495
        ret
3496
 
3496
 
3497
 
3497
 
3498
set_app_param:
3498
set_app_param:
3499
        push edi
3499
        push edi
3500
 
3500
 
3501
        mov  edi,[TASK_BASE]
3501
        mov  edi,[TASK_BASE]
3502
        mov  [edi+TASKDATA.event_mask],eax
3502
        mov  [edi+TASKDATA.event_mask],eax
3503
 
3503
 
3504
        pop  edi
3504
        pop  edi
3505
        ret
3505
        ret
3506
 
3506
 
3507
 
3507
 
3508
 
3508
 
3509
delay_hs:     ; delay in 1/100 secs
3509
delay_hs:     ; delay in 1/100 secs
3510
        push  eax
3510
        push  eax
3511
        push  ecx
3511
        push  ecx
3512
        push  edx
3512
        push  edx
3513
 
3513
 
3514
        mov   edx,[timer_ticks]
3514
        mov   edx,[timer_ticks]
3515
        add   edx,eax
3515
        add   edx,eax
3516
 
3516
 
3517
      newtic:
3517
      newtic:
3518
        mov   ecx,[timer_ticks]
3518
        mov   ecx,[timer_ticks]
3519
        cmp   edx,ecx
3519
        cmp   edx,ecx
3520
        jbe   zerodelay
3520
        jbe   zerodelay
3521
 
3521
 
3522
        call  change_task
3522
        call  change_task
3523
 
3523
 
3524
        jmp   newtic
3524
        jmp   newtic
3525
 
3525
 
3526
      zerodelay:
3526
      zerodelay:
3527
        pop   edx
3527
        pop   edx
3528
        pop   ecx
3528
        pop   ecx
3529
        pop   eax
3529
        pop   eax
3530
 
3530
 
3531
        ret
3531
        ret
3532
 
3532
 
3533
 
3533
 
3534
memmove:       ; memory move in bytes
3534
memmove:       ; memory move in bytes
3535
 
3535
 
3536
; eax = from
3536
; eax = from
3537
; ebx = to
3537
; ebx = to
3538
; ecx = no of bytes
3538
; ecx = no of bytes
3539
    test ecx, ecx
3539
    test ecx, ecx
3540
    jle  .ret
3540
    jle  .ret
3541
 
3541
 
3542
 
3542
 
3543
    push esi edi ecx
3543
    push esi edi ecx
3544
 
3544
 
3545
    mov  edi, ebx
3545
    mov  edi, ebx
3546
    mov  esi, eax
3546
    mov  esi, eax
3547
 
3547
 
3548
    test ecx, not 11b
3548
    test ecx, not 11b
3549
    jz   @f
3549
    jz   @f
3550
 
3550
 
3551
    push ecx
3551
    push ecx
3552
    shr  ecx, 2
3552
    shr  ecx, 2
3553
    rep  movsd
3553
    rep  movsd
3554
    pop  ecx
3554
    pop  ecx
3555
    and  ecx, 11b
3555
    and  ecx, 11b
3556
    jz   .finish
3556
    jz   .finish
3557
  @@:
3557
  @@:
3558
    rep  movsb
3558
    rep  movsb
3559
 
3559
 
3560
  .finish:
3560
  .finish:
3561
    pop  ecx edi esi
3561
    pop  ecx edi esi
3562
  .ret:
3562
  .ret:
3563
    ret
3563
    ret
3564
 
3564
 
3565
 
3565
 
3566
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3566
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3567
;align 4
3567
;align 4
3568
;
3568
;
3569
;read_floppy_file:
3569
;read_floppy_file:
3570
;
3570
;
3571
;; as input
3571
;; as input
3572
;;
3572
;;
3573
;; eax pointer to file
3573
;; eax pointer to file
3574
;; ebx file lenght
3574
;; ebx file lenght
3575
;; ecx start 512 byte block number
3575
;; ecx start 512 byte block number
3576
;; edx number of blocks to read
3576
;; edx number of blocks to read
3577
;; esi pointer to return/work area (atleast 20 000 bytes)
3577
;; esi pointer to return/work area (atleast 20 000 bytes)
3578
;;
3578
;;
3579
;;
3579
;;
3580
;; on return
3580
;; on return
3581
;;
3581
;;
3582
;; eax = 0 command succesful
3582
;; eax = 0 command succesful
3583
;;       1 no fd base and/or partition defined
3583
;;       1 no fd base and/or partition defined
3584
;;       2 yet unsupported FS
3584
;;       2 yet unsupported FS
3585
;;       3 unknown FS
3585
;;       3 unknown FS
3586
;;       4 partition not defined at hd
3586
;;       4 partition not defined at hd
3587
;;       5 file not found
3587
;;       5 file not found
3588
;; ebx = size of file
3588
;; ebx = size of file
3589
;
3589
;
3590
;     mov   edi,[TASK_BASE]
3590
;     mov   edi,[TASK_BASE]
3591
;     add   edi,0x10
3591
;     add   edi,0x10
3592
;     add   esi,[edi]
3592
;     add   esi,[edi]
3593
;     add   eax,[edi]
3593
;     add   eax,[edi]
3594
;
3594
;
3595
;     pushad
3595
;     pushad
3596
;     mov  edi,esi
3596
;     mov  edi,esi
3597
;     add  edi,1024
3597
;     add  edi,1024
3598
;     mov  esi,0x100000+19*512
3598
;     mov  esi,0x100000+19*512
3599
;     sub  ecx,1
3599
;     sub  ecx,1
3600
;     shl  ecx,9
3600
;     shl  ecx,9
3601
;     add  esi,ecx
3601
;     add  esi,ecx
3602
;     shl  edx,9
3602
;     shl  edx,9
3603
;     mov  ecx,edx
3603
;     mov  ecx,edx
3604
;     cld
3604
;     cld
3605
;     rep  movsb
3605
;     rep  movsb
3606
;     popad
3606
;     popad
3607
;
3607
;
3608
;     mov   [esp+36],eax
3608
;     mov   [esp+36],eax
3609
;     mov   [esp+24],ebx
3609
;     mov   [esp+24],ebx
3610
;     ret
3610
;     ret
3611
 
3611
 
3612
 
3612
 
3613
 
3613
 
3614
align 4
3614
align 4
3615
 
3615
 
3616
sys_programirq:
3616
sys_programirq:
3617
 
3617
 
3618
    mov   edi,[TASK_BASE]
3618
    mov   edi,[TASK_BASE]
3619
    add   eax,[edi+TASKDATA.mem_start]
3619
    add   eax,[edi+TASKDATA.mem_start]
3620
 
3620
 
3621
    cmp   ebx,16
3621
    cmp   ebx,16
3622
    jae   .not_owner
3622
    jae   .not_owner
3623
    mov   edi,[TASK_BASE]
3623
    mov   edi,[TASK_BASE]
3624
    mov   edi,[edi+TASKDATA.pid]
3624
    mov   edi,[edi+TASKDATA.pid]
3625
    cmp   edi,[irq_owner+ebx*4]
3625
    cmp   edi,[irq_owner+ebx*4]
3626
    je    spril1
3626
    je    spril1
3627
.not_owner:
3627
.not_owner:
3628
    mov   [esp+36],dword 1
3628
    mov   [esp+36],dword 1
3629
    ret
3629
    ret
3630
  spril1:
3630
  spril1:
3631
 
3631
 
3632
    mov   esi,eax
3632
    mov   esi,eax
3633
    shl   ebx,6
3633
    shl   ebx,6
3634
    add   ebx,irq00read
3634
    add   ebx,irq00read
3635
    mov   edi,ebx
3635
    mov   edi,ebx
3636
    mov   ecx,16
3636
    mov   ecx,16
3637
    cld
3637
    cld
3638
    rep   movsd
3638
    rep   movsd
3639
    mov   [esp+36],dword 0
3639
    mov   [esp+36],dword 0
3640
    ret
3640
    ret
3641
 
3641
 
3642
 
3642
 
3643
align 4
3643
align 4
3644
 
3644
 
3645
get_irq_data:
3645
get_irq_data:
3646
     cmp   eax,16
3646
     cmp   eax,16
3647
     jae   .not_owner
3647
     jae   .not_owner
3648
     mov   edx,eax           ; check for correct owner
3648
     mov   edx,eax           ; check for correct owner
3649
     shl   edx,2
3649
     shl   edx,2
3650
     add   edx,irq_owner
3650
     add   edx,irq_owner
3651
     mov   edx,[edx]
3651
     mov   edx,[edx]
3652
     mov   edi,[TASK_BASE]
3652
     mov   edi,[TASK_BASE]
3653
     mov   edi,[edi+TASKDATA.pid]
3653
     mov   edi,[edi+TASKDATA.pid]
3654
     cmp   edx,edi
3654
     cmp   edx,edi
3655
     je    gidril1
3655
     je    gidril1
3656
.not_owner:
3656
.not_owner:
3657
     mov   [esp+32],dword 2     ; ecx=2
3657
     mov   [esp+32],dword 2     ; ecx=2
3658
     ret
3658
     ret
3659
 
3659
 
3660
  gidril1:
3660
  gidril1:
3661
 
3661
 
3662
     mov   ebx,eax
3662
     mov   ebx,eax
3663
     shl   ebx,12
3663
     shl   ebx,12
3664
     add   ebx,IRQ_SAVE
3664
     add   ebx,IRQ_SAVE
3665
     mov   eax,[ebx]
3665
     mov   eax,[ebx]
3666
     mov   ecx,1
3666
     mov   ecx,1
3667
     test  eax,eax
3667
     test  eax,eax
3668
     jz    gid1
3668
     jz    gid1
3669
 
3669
 
3670
     dec   eax
3670
     dec   eax
3671
     mov   esi,ebx
3671
     mov   esi,ebx
3672
     mov   [ebx],eax
3672
     mov   [ebx],eax
3673
     movzx ebx,byte [ebx+0x10]
3673
     movzx ebx,byte [ebx+0x10]
3674
     add   esi,0x10
3674
     add   esi,0x10
3675
     mov   edi,esi
3675
     mov   edi,esi
3676
     inc   esi
3676
     inc   esi
3677
     mov   ecx,4000 / 4
3677
     mov   ecx,4000 / 4
3678
     cld
3678
     cld
3679
     rep   movsd
3679
     rep   movsd
3680
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3680
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3681
   gid1:
3681
   gid1:
3682
     mov   [esp+36],eax
3682
     mov   [esp+36],eax
3683
     mov   [esp+32],ecx
3683
     mov   [esp+32],ecx
3684
     mov   [esp+24],ebx
3684
     mov   [esp+24],ebx
3685
     ret
3685
     ret
3686
 
3686
 
3687
 
3687
 
3688
set_io_access_rights:
3688
set_io_access_rights:
3689
 
3689
 
3690
     pushad
3690
     pushad
3691
 
3691
 
3692
     mov   edi,[CURRENT_TASK]
3692
     mov   edi,[CURRENT_TASK]
3693
     imul  edi,tss_step
3693
     imul  edi,tss_step
3694
     add   edi,tss_data+128
3694
     add   edi,tss_data+128
3695
;     add   edi,128
3695
;     add   edi,128
3696
 
3696
 
3697
     mov   ecx,eax
3697
     mov   ecx,eax
3698
     and   ecx,7    ; offset in byte
3698
     and   ecx,7    ; offset in byte
3699
 
3699
 
3700
     shr   eax,3    ; number of byte
3700
     shr   eax,3    ; number of byte
3701
     add   edi,eax
3701
     add   edi,eax
3702
 
3702
 
3703
     mov   ebx,1
3703
     mov   ebx,1
3704
     shl   ebx,cl
3704
     shl   ebx,cl
3705
 
3705
 
3706
     cmp   ebp,0                ; enable access - ebp = 0
3706
     cmp   ebp,0                ; enable access - ebp = 0
3707
     jne   siar1
3707
     jne   siar1
3708
 
3708
 
3709
     not   ebx
3709
     not   ebx
3710
     and   [edi],byte bl
3710
     and   [edi],byte bl
3711
 
3711
 
3712
     popad
3712
     popad
3713
 
3713
 
3714
     ret
3714
     ret
3715
 
3715
 
3716
   siar1:
3716
   siar1:
3717
 
3717
 
3718
     or    [edi],byte bl        ; disable access - ebp = 1
3718
     or    [edi],byte bl        ; disable access - ebp = 1
3719
 
3719
 
3720
     popad
3720
     popad
3721
 
3721
 
3722
     ret
3722
     ret
3723
 
3723
 
3724
r_f_port_area:
3724
r_f_port_area:
3725
 
3725
 
3726
     test  eax, eax
3726
     test  eax, eax
3727
     jnz   free_port_area
3727
     jnz   free_port_area
3728
;     je    r_port_area
3728
;     je    r_port_area
3729
;     jmp   free_port_area
3729
;     jmp   free_port_area
3730
 
3730
 
3731
;   r_port_area:
3731
;   r_port_area:
3732
 
3732
 
3733
     pushad
3733
     pushad
3734
 
3734
 
3735
     cmp   ebx,ecx            ; beginning > end ?
3735
     cmp   ebx,ecx            ; beginning > end ?
3736
     ja    rpal1
3736
     ja    rpal1
3737
     cmp   ecx,65536
3737
     cmp   ecx,65536
3738
     jae   rpal1
3738
     jae   rpal1
3739
     mov   esi,[RESERVED_PORTS]
3739
     mov   esi,[RESERVED_PORTS]
3740
     test  esi,esi            ; no reserved areas ?
3740
     test  esi,esi            ; no reserved areas ?
3741
     je    rpal2
3741
     je    rpal2
3742
     cmp   esi,255            ; max reserved
3742
     cmp   esi,255            ; max reserved
3743
     jae   rpal1
3743
     jae   rpal1
3744
   rpal3:
3744
   rpal3:
3745
     mov   edi,esi
3745
     mov   edi,esi
3746
     shl   edi,4
3746
     shl   edi,4
3747
     add   edi,RESERVED_PORTS
3747
     add   edi,RESERVED_PORTS
3748
     cmp   ebx,[edi+8]
3748
     cmp   ebx,[edi+8]
3749
     ja    rpal4
3749
     ja    rpal4
3750
     cmp   ecx,[edi+4]
3750
     cmp   ecx,[edi+4]
3751
     jae   rpal1
3751
     jae   rpal1
3752
;     jb    rpal4
3752
;     jb    rpal4
3753
;     jmp   rpal1
3753
;     jmp   rpal1
3754
   rpal4:
3754
   rpal4:
3755
 
3755
 
3756
     dec   esi
3756
     dec   esi
3757
     jnz   rpal3
3757
     jnz   rpal3
3758
     jmp   rpal2
3758
     jmp   rpal2
3759
   rpal1:
3759
   rpal1:
3760
     popad
3760
     popad
3761
     mov   eax,1
3761
     mov   eax,1
3762
     ret
3762
     ret
3763
 
3763
 
3764
   rpal2:
3764
   rpal2:
3765
     popad
3765
     popad
3766
 
3766
 
3767
 
3767
 
3768
     ; enable port access at port IO map
3768
     ; enable port access at port IO map
3769
     cli
3769
     cli
3770
     pushad                        ; start enable io map
3770
     pushad                        ; start enable io map
3771
 
3771
 
3772
     cmp   ecx,65536 ;16384
3772
     cmp   ecx,65536 ;16384
3773
     jae   no_unmask_io ; jge
3773
     jae   no_unmask_io ; jge
3774
 
3774
 
3775
     mov   eax,ebx
3775
     mov   eax,ebx
3776
 
3776
 
3777
   new_port_access:
3777
   new_port_access:
3778
 
3778
 
3779
     pushad
3779
     pushad
3780
 
3780
 
3781
     xor   ebp,ebp                ; enable - eax = port
3781
     xor   ebp,ebp                ; enable - eax = port
3782
     call  set_io_access_rights
3782
     call  set_io_access_rights
3783
 
3783
 
3784
     popad
3784
     popad
3785
 
3785
 
3786
     inc   eax
3786
     inc   eax
3787
     cmp   eax,ecx
3787
     cmp   eax,ecx
3788
     jbe   new_port_access
3788
     jbe   new_port_access
3789
 
3789
 
3790
   no_unmask_io:
3790
   no_unmask_io:
3791
 
3791
 
3792
     popad                         ; end enable io map
3792
     popad                         ; end enable io map
3793
     sti
3793
     sti
3794
 
3794
 
3795
     mov   edi,[RESERVED_PORTS]
3795
     mov   edi,[RESERVED_PORTS]
3796
     add   edi,1
3796
     add   edi,1
3797
     mov   [RESERVED_PORTS],edi
3797
     mov   [RESERVED_PORTS],edi
3798
     shl   edi,4
3798
     shl   edi,4
3799
     add   edi,RESERVED_PORTS
3799
     add   edi,RESERVED_PORTS
3800
     mov   esi,[TASK_BASE]
3800
     mov   esi,[TASK_BASE]
3801
     mov   esi,[esi+TASKDATA.pid]
3801
     mov   esi,[esi+TASKDATA.pid]
3802
     mov   [edi],esi
3802
     mov   [edi],esi
3803
     mov   [edi+4],ebx
3803
     mov   [edi+4],ebx
3804
     mov   [edi+8],ecx
3804
     mov   [edi+8],ecx
3805
 
3805
 
3806
     xor   eax, eax
3806
     xor   eax, eax
3807
     ret
3807
     ret
3808
 
3808
 
3809
free_port_area:
3809
free_port_area:
3810
 
3810
 
3811
     pushad
3811
     pushad
3812
 
3812
 
3813
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3813
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3814
     test  esi,esi
3814
     test  esi,esi
3815
     je    frpal2
3815
     je    frpal2
3816
     mov   edx,[TASK_BASE]
3816
     mov   edx,[TASK_BASE]
3817
     mov   edx,[edx+TASKDATA.pid]
3817
     mov   edx,[edx+TASKDATA.pid]
3818
   frpal3:
3818
   frpal3:
3819
     mov   edi,esi
3819
     mov   edi,esi
3820
     shl   edi,4
3820
     shl   edi,4
3821
     add   edi,RESERVED_PORTS
3821
     add   edi,RESERVED_PORTS
3822
     cmp   edx,[edi]
3822
     cmp   edx,[edi]
3823
     jne   frpal4
3823
     jne   frpal4
3824
     cmp   ebx,[edi+4]
3824
     cmp   ebx,[edi+4]
3825
     jne   frpal4
3825
     jne   frpal4
3826
     cmp   ecx,[edi+8]
3826
     cmp   ecx,[edi+8]
3827
     jne   frpal4
3827
     jne   frpal4
3828
     jmp   frpal1
3828
     jmp   frpal1
3829
   frpal4:
3829
   frpal4:
3830
     dec   esi
3830
     dec   esi
3831
     jnz   frpal3
3831
     jnz   frpal3
3832
   frpal2:
3832
   frpal2:
3833
     popad
3833
     popad
3834
     mov   eax,1
3834
     mov   eax,1
3835
     ret
3835
     ret
3836
   frpal1:
3836
   frpal1:
3837
     mov   ecx,256
3837
     mov   ecx,256
3838
     sub   ecx,esi
3838
     sub   ecx,esi
3839
     shl   ecx,4
3839
     shl   ecx,4
3840
     mov   esi,edi
3840
     mov   esi,edi
3841
     add   esi,16
3841
     add   esi,16
3842
     cld
3842
     cld
3843
     rep   movsb
3843
     rep   movsb
3844
 
3844
 
3845
     dec   dword [RESERVED_PORTS]
3845
     dec   dword [RESERVED_PORTS]
3846
 
3846
 
3847
     popad
3847
     popad
3848
 
3848
 
3849
 
3849
 
3850
     ; disable port access at port IO map
3850
     ; disable port access at port IO map
3851
 
3851
 
3852
     pushad                        ; start disable io map
3852
     pushad                        ; start disable io map
3853
 
3853
 
3854
     cmp   ecx,65536 ;16384
3854
     cmp   ecx,65536 ;16384
3855
     jge   no_mask_io
3855
     jge   no_mask_io
3856
 
3856
 
3857
     mov   eax,ebx
3857
     mov   eax,ebx
3858
 
3858
 
3859
   new_port_access_disable:
3859
   new_port_access_disable:
3860
 
3860
 
3861
     pushad
3861
     pushad
3862
 
3862
 
3863
     mov   ebp,1                  ; disable - eax = port
3863
     mov   ebp,1                  ; disable - eax = port
3864
     call  set_io_access_rights
3864
     call  set_io_access_rights
3865
 
3865
 
3866
     popad
3866
     popad
3867
 
3867
 
3868
     inc   eax
3868
     inc   eax
3869
     cmp   eax,ecx
3869
     cmp   eax,ecx
3870
     jbe   new_port_access_disable
3870
     jbe   new_port_access_disable
3871
 
3871
 
3872
   no_mask_io:
3872
   no_mask_io:
3873
 
3873
 
3874
     popad                         ; end disable io map
3874
     popad                         ; end disable io map
3875
 
3875
 
3876
     xor   eax, eax
3876
     xor   eax, eax
3877
     ret
3877
     ret
3878
 
3878
 
3879
 
3879
 
3880
reserve_free_irq:
3880
reserve_free_irq:
3881
 
3881
 
3882
     mov   ecx, 1
3882
     mov   ecx, 1
3883
     cmp   ebx, 16
3883
     cmp   ebx, 16
3884
     jae   fril1
3884
     jae   fril1
3885
     test  eax,eax
3885
     test  eax,eax
3886
     jz    reserve_irq
3886
     jz    reserve_irq
3887
 
3887
 
3888
     lea   edi,[irq_owner+ebx*4]
3888
     lea   edi,[irq_owner+ebx*4]
3889
     mov   edx,[edi]
3889
     mov   edx,[edi]
3890
     mov   eax,[TASK_BASE]
3890
     mov   eax,[TASK_BASE]
3891
     cmp   edx,[eax+TASKDATA.pid]
3891
     cmp   edx,[eax+TASKDATA.pid]
3892
     jne   fril1
3892
     jne   fril1
3893
     dec   ecx
3893
     dec   ecx
3894
     mov   [edi],ecx
3894
     mov   [edi],ecx
3895
   fril1:
3895
   fril1:
3896
     mov   [esp+36],ecx ; return in eax
3896
     mov   [esp+36],ecx ; return in eax
3897
     ret
3897
     ret
3898
 
3898
 
3899
  reserve_irq:
3899
  reserve_irq:
3900
 
3900
 
3901
     lea   edi,[irq_owner+ebx*4]
3901
     lea   edi,[irq_owner+ebx*4]
3902
     cmp   dword [edi], 0
3902
     cmp   dword [edi], 0
3903
     jnz   ril1
3903
     jnz   ril1
3904
 
3904
 
3905
     mov   edx,[TASK_BASE]
3905
     mov   edx,[TASK_BASE]
3906
     mov   edx,[edx+TASKDATA.pid]
3906
     mov   edx,[edx+TASKDATA.pid]
3907
     mov   [edi],edx
3907
     mov   [edi],edx
3908
     dec   ecx
3908
     dec   ecx
3909
   ril1:
3909
   ril1:
3910
     mov   [esp+36],ecx ; return in eax
3910
     mov   [esp+36],ecx ; return in eax
3911
     ret
3911
     ret
3912
 
3912
 
3913
drawbackground:
3913
drawbackground:
3914
       inc   [mouse_pause]
3914
       inc   [mouse_pause]
3915
       cmp   [SCR_MODE],word 0x12
3915
       cmp   [SCR_MODE],word 0x12
3916
       je   dbrv20
3916
       je   dbrv20
3917
     dbrv12:
3917
     dbrv12:
3918
       cmp  [SCR_MODE],word 0100000000000000b
3918
       cmp  [SCR_MODE],word 0100000000000000b
3919
       jge  dbrv20
3919
       jge  dbrv20
3920
       cmp  [SCR_MODE],word 0x13
3920
       cmp  [SCR_MODE],word 0x13
3921
       je   dbrv20
3921
       je   dbrv20
3922
       call  vesa12_drawbackground
3922
       call  vesa12_drawbackground
3923
       dec   [mouse_pause]
3923
       dec   [mouse_pause]
3924
       call   [draw_pointer]
3924
       call   [draw_pointer]
3925
       ret
3925
       ret
3926
     dbrv20:
3926
     dbrv20:
3927
       cmp   [display_data-12],dword 1
3927
       cmp   [display_data-12],dword 1
3928
       jne   bgrstr
3928
       jne   bgrstr
3929
       call  vesa20_drawbackground_tiled
3929
       call  vesa20_drawbackground_tiled
3930
       dec   [mouse_pause]
3930
       dec   [mouse_pause]
3931
       call   [draw_pointer]
3931
       call   [draw_pointer]
3932
       ret
3932
       ret
3933
     bgrstr:
3933
     bgrstr:
3934
       call  vesa20_drawbackground_stretch
3934
       call  vesa20_drawbackground_stretch
3935
       dec   [mouse_pause]
3935
       dec   [mouse_pause]
3936
       call   [draw_pointer]
3936
       call   [draw_pointer]
3937
       ret
3937
       ret
3938
 
3938
 
3939
align 4
3939
align 4
3940
 
3940
 
3941
syscall_putimage:                       ; PutImage
3941
syscall_putimage:                       ; PutImage
3942
 
3942
 
3943
     mov   edx,ecx
3943
     mov   edx,ecx
3944
     mov   ecx,ebx
3944
     mov   ecx,ebx
3945
        lea     ebx, [eax+std_application_base_address]
3945
        lea     ebx, [eax+std_application_base_address]
3946
 
3946
 
3947
sys_putimage:
3947
sys_putimage:
3948
     test  ecx,0x80008000
3948
     test  ecx,0x80008000
3949
     jnz   .exit
3949
     jnz   .exit
3950
     test  ecx,0x0000FFFF
3950
     test  ecx,0x0000FFFF
3951
     jz    .exit
3951
     jz    .exit
3952
     test  ecx,0xFFFF0000
3952
     test  ecx,0xFFFF0000
3953
     jnz   @f
3953
     jnz   @f
3954
  .exit:
3954
  .exit:
3955
     ret
3955
     ret
3956
 @@:
3956
 @@:
3957
        mov     edi,[CURRENT_TASK]
3957
        mov     edi,[CURRENT_TASK]
3958
        shl     edi,8
3958
        shl     edi,8
3959
        add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
3959
        add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
3960
        rol     edx,16
3960
        rol     edx,16
3961
        add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
3961
        add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
3962
        rol     edx,16
3962
        rol     edx,16
3963
  .forced:
3963
  .forced:
3964
        push    ebp esi 0
3964
        push    ebp esi 0
3965
        mov     ebp, putimage_get24bpp
3965
        mov     ebp, putimage_get24bpp
3966
        mov     esi, putimage_init24bpp
3966
        mov     esi, putimage_init24bpp
3967
sys_putimage_bpp:
3967
sys_putimage_bpp:
3968
;        call    [disable_mouse] ; this will be done in xxx_putimage
3968
;        call    [disable_mouse] ; this will be done in xxx_putimage
3969
;        mov     eax, vga_putimage
3969
;        mov     eax, vga_putimage
3970
        cmp     [SCR_MODE], word 0x12
3970
        cmp     [SCR_MODE], word 0x12
3971
        jz      @f   ;.doit
3971
        jz      @f   ;.doit
3972
        mov     eax, vesa12_putimage
3972
        mov     eax, vesa12_putimage
3973
        cmp     [SCR_MODE], word 0100000000000000b
3973
        cmp     [SCR_MODE], word 0100000000000000b
3974
        jae     @f
3974
        jae     @f
3975
        cmp     [SCR_MODE], word 0x13
3975
        cmp     [SCR_MODE], word 0x13
3976
        jnz     .doit
3976
        jnz     .doit
3977
@@:
3977
@@:
3978
        mov     eax, vesa20_putimage
3978
        mov     eax, vesa20_putimage
3979
.doit:
3979
.doit:
3980
        inc     [mouse_pause]
3980
        inc     [mouse_pause]
3981
        call    eax
3981
        call    eax
3982
        dec     [mouse_pause]
3982
        dec     [mouse_pause]
3983
        pop     ebp esi ebp
3983
        pop     ebp esi ebp
3984
        jmp     [draw_pointer]
3984
        jmp     [draw_pointer]
3985
 
3985
 
3986
syscall_putimage_palette:
3986
syscall_putimage_palette:
3987
        lea     edi, [esi+std_application_base_address]
3987
        lea     edi, [esi+std_application_base_address]
3988
        mov     esi, edx
3988
        mov     esi, edx
3989
        mov     edx, ecx
3989
        mov     edx, ecx
3990
        mov     ecx, ebx
3990
        mov     ecx, ebx
3991
        lea     ebx, [eax+std_application_base_address]
3991
        lea     ebx, [eax+std_application_base_address]
3992
sys_putimage_palette:
3992
sys_putimage_palette:
3993
; ebx = pointer to image
3993
; ebx = pointer to image
3994
; ecx = [xsize]*65536 + [ysize]
3994
; ecx = [xsize]*65536 + [ysize]
3995
; edx = [xstart]*65536 + [ystart]
3995
; edx = [xstart]*65536 + [ystart]
3996
; esi = number of bits per pixel, must be 8, 24 or 32
3996
; esi = number of bits per pixel, must be 8, 24 or 32
3997
; edi = pointer to palette
3997
; edi = pointer to palette
3998
; ebp = row delta
3998
; ebp = row delta
3999
        mov     eax, [CURRENT_TASK]
3999
        mov     eax, [CURRENT_TASK]
4000
        shl     eax, 8
4000
        shl     eax, 8
4001
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4001
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4002
        rol     edx, 16
4002
        rol     edx, 16
4003
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4003
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4004
        rol     edx, 16
4004
        rol     edx, 16
4005
.forced:
4005
.forced:
4006
        push    ebp esi ebp
4006
        push    ebp esi ebp
4007
        cmp     esi, 8
4007
        cmp     esi, 8
4008
        jnz     @f
4008
        jnz     @f
4009
        mov     ebp, putimage_get8bpp
4009
        mov     ebp, putimage_get8bpp
4010
        mov     esi, putimage_init8bpp
4010
        mov     esi, putimage_init8bpp
4011
        jmp     sys_putimage_bpp
4011
        jmp     sys_putimage_bpp
4012
@@:
4012
@@:
4013
        cmp     esi, 24
4013
        cmp     esi, 24
4014
        jnz     @f
4014
        jnz     @f
4015
        mov     ebp, putimage_get24bpp
4015
        mov     ebp, putimage_get24bpp
4016
        mov     esi, putimage_init24bpp
4016
        mov     esi, putimage_init24bpp
4017
        jmp     sys_putimage_bpp
4017
        jmp     sys_putimage_bpp
4018
@@:
4018
@@:
4019
        cmp     esi, 32
4019
        cmp     esi, 32
4020
        jnz     @f
4020
        jnz     @f
4021
        mov     ebp, putimage_get32bpp
4021
        mov     ebp, putimage_get32bpp
4022
        mov     esi, putimage_init32bpp
4022
        mov     esi, putimage_init32bpp
4023
        jmp     sys_putimage_bpp
4023
        jmp     sys_putimage_bpp
4024
@@:
4024
@@:
4025
        pop     ebp esi
4025
        pop     ebp esi
4026
        ret
4026
        ret
4027
 
4027
 
4028
putimage_init24bpp:
4028
putimage_init24bpp:
4029
        lea     eax, [eax*3]
4029
        lea     eax, [eax*3]
4030
putimage_init8bpp:
4030
putimage_init8bpp:
4031
        ret
4031
        ret
4032
 
4032
 
4033
putimage_get24bpp:
4033
putimage_get24bpp:
4034
        mov     eax, [esi]
4034
        mov     eax, [esi]
4035
        add     esi, 3
4035
        add     esi, 3
4036
        ret     4
4036
        ret     4
4037
putimage_get8bpp:
4037
putimage_get8bpp:
4038
        movzx   eax, byte [esi]
4038
        movzx   eax, byte [esi]
4039
        push    edx
4039
        push    edx
4040
        mov     edx, [esp+8]
4040
        mov     edx, [esp+8]
4041
        mov     eax, [edx+eax*4]
4041
        mov     eax, [edx+eax*4]
4042
        pop     edx
4042
        pop     edx
4043
        inc     esi
4043
        inc     esi
4044
        ret     4
4044
        ret     4
4045
 
4045
 
4046
putimage_init32bpp:
4046
putimage_init32bpp:
4047
        shl     eax, 2
4047
        shl     eax, 2
4048
        ret
4048
        ret
4049
putimage_get32bpp:
4049
putimage_get32bpp:
4050
        lodsd
4050
        lodsd
4051
        ret     4
4051
        ret     4
4052
 
4052
 
4053
; eax x beginning
4053
; eax x beginning
4054
; ebx y beginning
4054
; ebx y beginning
4055
; ecx x end
4055
; ecx x end
4056
	; edx y end
4056
	; edx y end
4057
; edi color
4057
; edi color
4058
 
4058
 
4059
__sys_drawbar:
4059
__sys_drawbar:
4060
        mov     esi,[CURRENT_TASK]
4060
        mov     esi,[CURRENT_TASK]
4061
        shl     esi,8
4061
        shl     esi,8
4062
        add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4062
        add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4063
        add     ecx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4063
        add     ecx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4064
        add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4064
        add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4065
        add     edx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4065
        add     edx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4066
  .forced:
4066
  .forced:
4067
    inc   [mouse_pause]
4067
    inc   [mouse_pause]
4068
;        call    [disable_mouse]
4068
;        call    [disable_mouse]
4069
    cmp   [SCR_MODE],word 0x12
4069
    cmp   [SCR_MODE],word 0x12
4070
    je   dbv20
4070
    je   dbv20
4071
   sdbv20:
4071
   sdbv20:
4072
    cmp  [SCR_MODE],word 0100000000000000b
4072
    cmp  [SCR_MODE],word 0100000000000000b
4073
    jge  dbv20
4073
    jge  dbv20
4074
    cmp  [SCR_MODE],word 0x13
4074
    cmp  [SCR_MODE],word 0x13
4075
    je   dbv20
4075
    je   dbv20
4076
    call vesa12_drawbar
4076
    call vesa12_drawbar
4077
    dec   [mouse_pause]
4077
    dec   [mouse_pause]
4078
    call   [draw_pointer]
4078
    call   [draw_pointer]
4079
    ret
4079
    ret
4080
  dbv20:
4080
  dbv20:
4081
    call vesa20_drawbar
4081
    call vesa20_drawbar
4082
    dec   [mouse_pause]
4082
    dec   [mouse_pause]
4083
    call   [draw_pointer]
4083
    call   [draw_pointer]
4084
    ret
4084
    ret
4085
 
4085
 
4086
 
4086
 
4087
 
4087
 
4088
kb_read:
4088
kb_read:
4089
 
4089
 
4090
        push    ecx edx
4090
        push    ecx edx
4091
 
4091
 
4092
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4092
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4093
      kr_loop:
4093
      kr_loop:
4094
        in      al,0x64
4094
        in      al,0x64
4095
        test    al,1
4095
        test    al,1
4096
        jnz     kr_ready
4096
        jnz     kr_ready
4097
        loop    kr_loop
4097
        loop    kr_loop
4098
        mov     ah,1
4098
        mov     ah,1
4099
        jmp     kr_exit
4099
        jmp     kr_exit
4100
      kr_ready:
4100
      kr_ready:
4101
        push    ecx
4101
        push    ecx
4102
        mov     ecx,32
4102
        mov     ecx,32
4103
      kr_delay:
4103
      kr_delay:
4104
        loop    kr_delay
4104
        loop    kr_delay
4105
        pop     ecx
4105
        pop     ecx
4106
        in      al,0x60
4106
        in      al,0x60
4107
        xor     ah,ah
4107
        xor     ah,ah
4108
      kr_exit:
4108
      kr_exit:
4109
 
4109
 
4110
        pop     edx ecx
4110
        pop     edx ecx
4111
 
4111
 
4112
        ret
4112
        ret
4113
 
4113
 
4114
 
4114
 
4115
kb_write:
4115
kb_write:
4116
 
4116
 
4117
        push    ecx edx
4117
        push    ecx edx
4118
 
4118
 
4119
        mov     dl,al
4119
        mov     dl,al
4120
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4120
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4121
;      kw_loop1:
4121
;      kw_loop1:
4122
;        in      al,0x64
4122
;        in      al,0x64
4123
;        test    al,0x20
4123
;        test    al,0x20
4124
;        jz      kw_ok1
4124
;        jz      kw_ok1
4125
;        loop    kw_loop1
4125
;        loop    kw_loop1
4126
;        mov     ah,1
4126
;        mov     ah,1
4127
;        jmp     kw_exit
4127
;        jmp     kw_exit
4128
;      kw_ok1:
4128
;      kw_ok1:
4129
        in      al,0x60
4129
        in      al,0x60
4130
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4130
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4131
      kw_loop:
4131
      kw_loop:
4132
        in      al,0x64
4132
        in      al,0x64
4133
        test    al,2
4133
        test    al,2
4134
        jz      kw_ok
4134
        jz      kw_ok
4135
        loop    kw_loop
4135
        loop    kw_loop
4136
        mov     ah,1
4136
        mov     ah,1
4137
        jmp     kw_exit
4137
        jmp     kw_exit
4138
      kw_ok:
4138
      kw_ok:
4139
        mov     al,dl
4139
        mov     al,dl
4140
        out     0x60,al
4140
        out     0x60,al
4141
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4141
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4142
      kw_loop3:
4142
      kw_loop3:
4143
        in      al,0x64
4143
        in      al,0x64
4144
        test    al,2
4144
        test    al,2
4145
        jz      kw_ok3
4145
        jz      kw_ok3
4146
        loop    kw_loop3
4146
        loop    kw_loop3
4147
        mov     ah,1
4147
        mov     ah,1
4148
        jmp     kw_exit
4148
        jmp     kw_exit
4149
      kw_ok3:
4149
      kw_ok3:
4150
        mov     ah,8
4150
        mov     ah,8
4151
      kw_loop4:
4151
      kw_loop4:
4152
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4152
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4153
      kw_loop5:
4153
      kw_loop5:
4154
        in      al,0x64
4154
        in      al,0x64
4155
        test    al,1
4155
        test    al,1
4156
        jnz     kw_ok4
4156
        jnz     kw_ok4
4157
        loop    kw_loop5
4157
        loop    kw_loop5
4158
        dec     ah
4158
        dec     ah
4159
        jnz     kw_loop4
4159
        jnz     kw_loop4
4160
      kw_ok4:
4160
      kw_ok4:
4161
        xor     ah,ah
4161
        xor     ah,ah
4162
      kw_exit:
4162
      kw_exit:
4163
 
4163
 
4164
        pop     edx ecx
4164
        pop     edx ecx
4165
 
4165
 
4166
        ret
4166
        ret
4167
 
4167
 
4168
 
4168
 
4169
kb_cmd:
4169
kb_cmd:
4170
 
4170
 
4171
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4171
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4172
      c_wait:
4172
      c_wait:
4173
        in      al,0x64
4173
        in      al,0x64
4174
        test    al,2
4174
        test    al,2
4175
        jz      c_send
4175
        jz      c_send
4176
        loop    c_wait
4176
        loop    c_wait
4177
        jmp     c_error
4177
        jmp     c_error
4178
      c_send:
4178
      c_send:
4179
        mov     al,bl
4179
        mov     al,bl
4180
        out     0x64,al
4180
        out     0x64,al
4181
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4181
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4182
      c_accept:
4182
      c_accept:
4183
        in      al,0x64
4183
        in      al,0x64
4184
        test    al,2
4184
        test    al,2
4185
        jz      c_ok
4185
        jz      c_ok
4186
        loop    c_accept
4186
        loop    c_accept
4187
      c_error:
4187
      c_error:
4188
        mov     ah,1
4188
        mov     ah,1
4189
        jmp     c_exit
4189
        jmp     c_exit
4190
      c_ok:
4190
      c_ok:
4191
        xor     ah,ah
4191
        xor     ah,ah
4192
      c_exit:
4192
      c_exit:
4193
        ret
4193
        ret
4194
 
4194
 
4195
 
4195
 
4196
setmouse:  ; set mousepicture -pointer
4196
setmouse:  ; set mousepicture -pointer
4197
           ; ps2 mouse enable
4197
           ; ps2 mouse enable
4198
 
4198
 
4199
     mov     [MOUSE_PICTURE],dword mousepointer
4199
     mov     [MOUSE_PICTURE],dword mousepointer
4200
 
4200
 
4201
     cli
4201
     cli
4202
;     mov     bl,0xa8                 ; enable mouse cmd
4202
;     mov     bl,0xa8                 ; enable mouse cmd
4203
;     call    kb_cmd
4203
;     call    kb_cmd
4204
;     call    kb_read                 ; read status
4204
;     call    kb_read                 ; read status
4205
;     mov     bl,0x20                 ; get command byte
4205
;     mov     bl,0x20                 ; get command byte
4206
;     call    kb_cmd
4206
;     call    kb_cmd
4207
;     call    kb_read
4207
;     call    kb_read
4208
;     or      al,3                    ; enable interrupt
4208
;     or      al,3                    ; enable interrupt
4209
;     mov     bl,0x60                 ; write command
4209
;     mov     bl,0x60                 ; write command
4210
;     push    eax
4210
;     push    eax
4211
;     call    kb_cmd
4211
;     call    kb_cmd
4212
;     pop     eax
4212
;     pop     eax
4213
;     call    kb_write
4213
;     call    kb_write
4214
;     mov     bl,0xd4                 ; for mouse
4214
;     mov     bl,0xd4                 ; for mouse
4215
;     call    kb_cmd
4215
;     call    kb_cmd
4216
;     mov     al,0xf4                 ; enable mouse device
4216
;     mov     al,0xf4                 ; enable mouse device
4217
;     call    kb_write
4217
;     call    kb_write
4218
;     call    kb_read           ; read status return
4218
;     call    kb_read           ; read status return
4219
 
4219
 
4220
     ; com1 mouse enable
4220
     ; com1 mouse enable
4221
 
4221
 
4222
     mov   bx,0x3f8 ; combase
4222
     mov   bx,0x3f8 ; combase
4223
 
4223
 
4224
     mov   dx,bx
4224
     mov   dx,bx
4225
     add   dx,3
4225
     add   dx,3
4226
     mov   al,0x80
4226
     mov   al,0x80
4227
     out   dx,al
4227
     out   dx,al
4228
 
4228
 
4229
     mov   dx,bx
4229
     mov   dx,bx
4230
     add   dx,1
4230
     add   dx,1
4231
     mov   al,0
4231
     mov   al,0
4232
     out   dx,al
4232
     out   dx,al
4233
 
4233
 
4234
     mov   dx,bx
4234
     mov   dx,bx
4235
     add   dx,0
4235
     add   dx,0
4236
     mov   al,0x30*2    ; 0x30 / 4
4236
     mov   al,0x30*2    ; 0x30 / 4
4237
     out   dx,al
4237
     out   dx,al
4238
 
4238
 
4239
     mov   dx,bx
4239
     mov   dx,bx
4240
     add   dx,3
4240
     add   dx,3
4241
     mov   al,2         ; 3
4241
     mov   al,2         ; 3
4242
     out   dx,al
4242
     out   dx,al
4243
 
4243
 
4244
     mov   dx,bx
4244
     mov   dx,bx
4245
     add   dx,4
4245
     add   dx,4
4246
     mov   al,0xb
4246
     mov   al,0xb
4247
     out   dx,al
4247
     out   dx,al
4248
 
4248
 
4249
     mov   dx,bx
4249
     mov   dx,bx
4250
     add   dx,1
4250
     add   dx,1
4251
     mov   al,1
4251
     mov   al,1
4252
     out   dx,al
4252
     out   dx,al
4253
 
4253
 
4254
 
4254
 
4255
     ; com2 mouse enable
4255
     ; com2 mouse enable
4256
 
4256
 
4257
     mov   bx,0x2f8 ; combase
4257
     mov   bx,0x2f8 ; combase
4258
 
4258
 
4259
     mov   dx,bx
4259
     mov   dx,bx
4260
     add   dx,3
4260
     add   dx,3
4261
     mov   al,0x80
4261
     mov   al,0x80
4262
     out   dx,al
4262
     out   dx,al
4263
 
4263
 
4264
     mov   dx,bx
4264
     mov   dx,bx
4265
     add   dx,1
4265
     add   dx,1
4266
     mov   al,0
4266
     mov   al,0
4267
     out   dx,al
4267
     out   dx,al
4268
 
4268
 
4269
     mov   dx,bx
4269
     mov   dx,bx
4270
     add   dx,0
4270
     add   dx,0
4271
     mov   al,0x30*2
4271
     mov   al,0x30*2
4272
     out   dx,al
4272
     out   dx,al
4273
 
4273
 
4274
     mov   dx,bx
4274
     mov   dx,bx
4275
     add   dx,3
4275
     add   dx,3
4276
     mov   al,2
4276
     mov   al,2
4277
     out   dx,al
4277
     out   dx,al
4278
 
4278
 
4279
     mov   dx,bx
4279
     mov   dx,bx
4280
     add   dx,4
4280
     add   dx,4
4281
     mov   al,0xb
4281
     mov   al,0xb
4282
     out   dx,al
4282
     out   dx,al
4283
 
4283
 
4284
     mov   dx,bx
4284
     mov   dx,bx
4285
     add   dx,1
4285
     add   dx,1
4286
     mov   al,1
4286
     mov   al,1
4287
     out   dx,al
4287
     out   dx,al
4288
 
4288
 
4289
     ret
4289
     ret
4290
 
4290
 
4291
 
4291
 
4292
_rdtsc:
4292
_rdtsc:
4293
     bt [cpu_caps], CAPS_TSC
4293
     bt [cpu_caps], CAPS_TSC
4294
     jnc ret_rdtsc
4294
     jnc ret_rdtsc
4295
     rdtsc
4295
     rdtsc
4296
     ret
4296
     ret
4297
   ret_rdtsc:
4297
   ret_rdtsc:
4298
     mov   edx,0xffffffff
4298
     mov   edx,0xffffffff
4299
     mov   eax,0xffffffff
4299
     mov   eax,0xffffffff
4300
     ret
4300
     ret
4301
 
4301
 
4302
rerouteirqs:
4302
rerouteirqs:
4303
 
4303
 
4304
        cli
4304
        cli
4305
 
4305
 
4306
        mov     al,0x11         ;  icw4, edge triggered
4306
        mov     al,0x11         ;  icw4, edge triggered
4307
        out     0x20,al
4307
        out     0x20,al
4308
        call    pic_delay
4308
        call    pic_delay
4309
        out     0xA0,al
4309
        out     0xA0,al
4310
        call    pic_delay
4310
        call    pic_delay
4311
 
4311
 
4312
        mov     al,0x20         ;  generate 0x20 +
4312
        mov     al,0x20         ;  generate 0x20 +
4313
        out     0x21,al
4313
        out     0x21,al
4314
        call    pic_delay
4314
        call    pic_delay
4315
        mov     al,0x28         ;  generate 0x28 +
4315
        mov     al,0x28         ;  generate 0x28 +
4316
        out     0xA1,al
4316
        out     0xA1,al
4317
        call    pic_delay
4317
        call    pic_delay
4318
 
4318
 
4319
        mov     al,0x04         ;  slave at irq2
4319
        mov     al,0x04         ;  slave at irq2
4320
        out     0x21,al
4320
        out     0x21,al
4321
        call    pic_delay
4321
        call    pic_delay
4322
        mov     al,0x02         ;  at irq9
4322
        mov     al,0x02         ;  at irq9
4323
        out     0xA1,al
4323
        out     0xA1,al
4324
        call    pic_delay
4324
        call    pic_delay
4325
 
4325
 
4326
        mov     al,0x01         ;  8086 mode
4326
        mov     al,0x01         ;  8086 mode
4327
        out     0x21,al
4327
        out     0x21,al
4328
        call    pic_delay
4328
        call    pic_delay
4329
        out     0xA1,al
4329
        out     0xA1,al
4330
        call    pic_delay
4330
        call    pic_delay
4331
 
4331
 
4332
        mov     al,255          ; mask all irq's
4332
        mov     al,255          ; mask all irq's
4333
        out     0xA1,al
4333
        out     0xA1,al
4334
        call    pic_delay
4334
        call    pic_delay
4335
        out     0x21,al
4335
        out     0x21,al
4336
        call    pic_delay
4336
        call    pic_delay
4337
 
4337
 
4338
        mov     ecx,0x1000
4338
        mov     ecx,0x1000
4339
        cld
4339
        cld
4340
picl1:  call    pic_delay
4340
picl1:  call    pic_delay
4341
        loop    picl1
4341
        loop    picl1
4342
 
4342
 
4343
        mov     al,255          ; mask all irq's
4343
        mov     al,255          ; mask all irq's
4344
        out     0xA1,al
4344
        out     0xA1,al
4345
        call    pic_delay
4345
        call    pic_delay
4346
        out     0x21,al
4346
        out     0x21,al
4347
        call    pic_delay
4347
        call    pic_delay
4348
 
4348
 
4349
        cli
4349
        cli
4350
 
4350
 
4351
        ret
4351
        ret
4352
 
4352
 
4353
 
4353
 
4354
pic_delay:
4354
pic_delay:
4355
 
4355
 
4356
        jmp     pdl1
4356
        jmp     pdl1
4357
pdl1:   ret
4357
pdl1:   ret
4358
 
4358
 
4359
 
4359
 
4360
sys_msg_board_str:
4360
sys_msg_board_str:
4361
 
4361
 
4362
     pushad
4362
     pushad
4363
   @@:
4363
   @@:
4364
     cmp    [esi],byte 0
4364
     cmp    [esi],byte 0
4365
     je     @f
4365
     je     @f
4366
     mov    eax,1
4366
     mov    eax,1
4367
     movzx  ebx,byte [esi]
4367
     movzx  ebx,byte [esi]
4368
     call   sys_msg_board
4368
     call   sys_msg_board
4369
     inc    esi
4369
     inc    esi
4370
     jmp    @b
4370
     jmp    @b
4371
   @@:
4371
   @@:
4372
     popad
4372
     popad
4373
     ret
4373
     ret
4374
 
4374
 
4375
uglobal
4375
uglobal
4376
  msg_board_data: times 4096 db 0
4376
  msg_board_data: times 4096 db 0
4377
  msg_board_count dd 0x0
4377
  msg_board_count dd 0x0
4378
endg
4378
endg
4379
 
4379
 
4380
sys_msg_board:
4380
sys_msg_board:
4381
 
4381
 
4382
; eax=1 : write :  bl byte to write
4382
; eax=1 : write :  bl byte to write
4383
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4383
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4384
 
4384
 
4385
     mov  ecx,[msg_board_count]
4385
     mov  ecx,[msg_board_count]
4386
     cmp  eax, 1
4386
     cmp  eax, 1
4387
     jne  smbl1
4387
     jne  smbl1
4388
 
4388
 
4389
 
4389
 
4390
     mov  [msg_board_data+ecx],bl
4390
     mov  [msg_board_data+ecx],bl
4391
     inc  ecx
4391
     inc  ecx
4392
     and  ecx, 4095
4392
     and  ecx, 4095
4393
     mov  [msg_board_count], ecx
4393
     mov  [msg_board_count], ecx
4394
     mov  [check_idle_semaphore], 5
4394
     mov  [check_idle_semaphore], 5
4395
     ret
4395
     ret
4396
   smbl1:
4396
   smbl1:
4397
 
4397
 
4398
     cmp   eax, 2
4398
     cmp   eax, 2
4399
     jne   smbl2
4399
     jne   smbl2
4400
     test  ecx, ecx
4400
     test  ecx, ecx
4401
     jz    smbl21
4401
     jz    smbl21
4402
;     mov   edi, msg_board_data
4402
;     mov   edi, msg_board_data
4403
;     mov   esi, msg_board_data+1
4403
;     mov   esi, msg_board_data+1
4404
;     movzx eax, byte [edi]
4404
;     movzx eax, byte [edi]
4405
     mov   eax, msg_board_data+1
4405
     mov   eax, msg_board_data+1
4406
     mov   ebx, msg_board_data
4406
     mov   ebx, msg_board_data
4407
     movzx edx, byte [ebx]
4407
     movzx edx, byte [ebx]
4408
     call  memmove
4408
     call  memmove
4409
;     push  ecx
4409
;     push  ecx
4410
;     shr   ecx, 2
4410
;     shr   ecx, 2
4411
;     cld
4411
;     cld
4412
;     rep   movsd
4412
;     rep   movsd
4413
;     pop   ecx
4413
;     pop   ecx
4414
;     and   ecx, 3
4414
;     and   ecx, 3
4415
;     rep   movsb
4415
;     rep   movsb
4416
     dec   [msg_board_count]
4416
     dec   [msg_board_count]
4417
     mov   [esp+36], edx ;eax
4417
     mov   [esp+36], edx ;eax
4418
     mov   [esp+24], dword 1
4418
     mov   [esp+24], dword 1
4419
     ret
4419
     ret
4420
   smbl21:
4420
   smbl21:
4421
     mov   [esp+36], ecx
4421
     mov   [esp+36], ecx
4422
     mov   [esp+24], ecx
4422
     mov   [esp+24], ecx
4423
 
4423
 
4424
   smbl2:
4424
   smbl2:
4425
     ret
4425
     ret
4426
 
4426
 
4427
 
4427
 
4428
 
4428
 
4429
sys_process_def:
4429
sys_process_def:
4430
        mov     edi, [CURRENT_TASK]
4430
        mov     edi, [CURRENT_TASK]
4431
 
4431
 
4432
        dec     eax             ; 1 = set keyboard mode
4432
        dec     eax             ; 1 = set keyboard mode
4433
     jne   no_set_keyboard_setup
4433
     jne   no_set_keyboard_setup
4434
 
4434
 
4435
     shl   edi,8
4435
     shl   edi,8
4436
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4436
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4437
 
4437
 
4438
     ret
4438
     ret
4439
 
4439
 
4440
   no_set_keyboard_setup:
4440
   no_set_keyboard_setup:
4441
 
4441
 
4442
        dec     eax             ; 2 = get keyboard mode
4442
        dec     eax             ; 2 = get keyboard mode
4443
     jne   no_get_keyboard_setup
4443
     jne   no_get_keyboard_setup
4444
 
4444
 
4445
     shl   edi,8
4445
     shl   edi,8
4446
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4446
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4447
 
4447
 
4448
     mov   [esp+36],eax
4448
     mov   [esp+36],eax
4449
 
4449
 
4450
     ret
4450
     ret
4451
 
4451
 
4452
   no_get_keyboard_setup:
4452
   no_get_keyboard_setup:
4453
 
4453
 
4454
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4454
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4455
     jne   no_get_keyboard_cas
4455
     jne   no_get_keyboard_cas
4456
 
4456
 
4457
;     xor   eax,eax
4457
;     xor   eax,eax
4458
;     movzx eax,byte [shift]
4458
;     movzx eax,byte [shift]
4459
;     movzx ebx,byte [ctrl]
4459
;     movzx ebx,byte [ctrl]
4460
;     shl   ebx,2
4460
;     shl   ebx,2
4461
;     add   eax,ebx
4461
;     add   eax,ebx
4462
;     movzx ebx,byte [alt]
4462
;     movzx ebx,byte [alt]
4463
;     shl   ebx,3
4463
;     shl   ebx,3
4464
;     add   eax,ebx
4464
;     add   eax,ebx
4465
 
4465
 
4466
 ;// mike.dld [
4466
 ;// mike.dld [
4467
     mov   eax, [kb_state]
4467
     mov   eax, [kb_state]
4468
 ;// mike.dld ]
4468
 ;// mike.dld ]
4469
 
4469
 
4470
     mov   [esp+36],eax
4470
     mov   [esp+36],eax
4471
 
4471
 
4472
     ret
4472
     ret
4473
 
4473
 
4474
   no_get_keyboard_cas:
4474
   no_get_keyboard_cas:
4475
 
4475
 
4476
        dec     eax
4476
        dec     eax
4477
        jnz     no_add_keyboard_hotkey
4477
        jnz     no_add_keyboard_hotkey
4478
 
4478
 
4479
        mov     eax, hotkey_list
4479
        mov     eax, hotkey_list
4480
@@:
4480
@@:
4481
        cmp     dword [eax+8], 0
4481
        cmp     dword [eax+8], 0
4482
        jz      .found_free
4482
        jz      .found_free
4483
        add     eax, 16
4483
        add     eax, 16
4484
        cmp     eax, hotkey_list+16*256
4484
        cmp     eax, hotkey_list+16*256
4485
        jb      @b
4485
        jb      @b
4486
        mov     dword [esp+36], 1
4486
        mov     dword [esp+36], 1
4487
        ret
4487
        ret
4488
.found_free:
4488
.found_free:
4489
        mov     [eax+8], edi
4489
        mov     [eax+8], edi
4490
        mov     [eax+4], ecx
4490
        mov     [eax+4], ecx
4491
        movzx   ebx, bl
4491
        movzx   ebx, bl
4492
        lea     ebx, [hotkey_scancodes+ebx*4]
4492
        lea     ebx, [hotkey_scancodes+ebx*4]
4493
        mov     ecx, [ebx]
4493
        mov     ecx, [ebx]
4494
        mov     [eax], ecx
4494
        mov     [eax], ecx
4495
        mov     [ebx], eax
4495
        mov     [ebx], eax
4496
        mov     [eax+12], ebx
4496
        mov     [eax+12], ebx
4497
        jecxz   @f
4497
        jecxz   @f
4498
        mov     [ecx+12], eax
4498
        mov     [ecx+12], eax
4499
@@:
4499
@@:
4500
        and     dword [esp+36], 0
4500
        and     dword [esp+36], 0
4501
        ret
4501
        ret
4502
 
4502
 
4503
no_add_keyboard_hotkey:
4503
no_add_keyboard_hotkey:
4504
 
4504
 
4505
        dec     eax
4505
        dec     eax
4506
        jnz     no_del_keyboard_hotkey
4506
        jnz     no_del_keyboard_hotkey
4507
 
4507
 
4508
        movzx   ebx, bl
4508
        movzx   ebx, bl
4509
        lea     ebx, [hotkey_scancodes+ebx*4]
4509
        lea     ebx, [hotkey_scancodes+ebx*4]
4510
        mov     eax, [ebx]
4510
        mov     eax, [ebx]
4511
.scan:
4511
.scan:
4512
        test    eax, eax
4512
        test    eax, eax
4513
        jz      .notfound
4513
        jz      .notfound
4514
        cmp     [eax+8], edi
4514
        cmp     [eax+8], edi
4515
        jnz     .next
4515
        jnz     .next
4516
        cmp     [eax+4], ecx
4516
        cmp     [eax+4], ecx
4517
        jz      .found
4517
        jz      .found
4518
.next:
4518
.next:
4519
        mov     eax, [eax]
4519
        mov     eax, [eax]
4520
        jmp     .scan
4520
        jmp     .scan
4521
.notfound:
4521
.notfound:
4522
        mov     dword [esp+36], 1
4522
        mov     dword [esp+36], 1
4523
        ret
4523
        ret
4524
.found:
4524
.found:
4525
        mov     ecx, [eax]
4525
        mov     ecx, [eax]
4526
        jecxz   @f
4526
        jecxz   @f
4527
        mov     edx, [eax+12]
4527
        mov     edx, [eax+12]
4528
        mov     [ecx+12], edx
4528
        mov     [ecx+12], edx
4529
@@:
4529
@@:
4530
        mov     ecx, [eax+12]
4530
        mov     ecx, [eax+12]
4531
        mov     edx, [eax]
4531
        mov     edx, [eax]
4532
        mov     [ecx], edx
4532
        mov     [ecx], edx
4533
        xor     edx, edx
4533
        xor     edx, edx
4534
        mov     [eax+4], edx
4534
        mov     [eax+4], edx
4535
        mov     [eax+8], edx
4535
        mov     [eax+8], edx
4536
        mov     [eax+12], edx
4536
        mov     [eax+12], edx
4537
        mov     [eax], edx
4537
        mov     [eax], edx
4538
        mov     [esp+36], edx
4538
        mov     [esp+36], edx
4539
        ret
4539
        ret
4540
 
4540
 
4541
no_del_keyboard_hotkey:
4541
no_del_keyboard_hotkey:
4542
     ret
4542
     ret
4543
 
4543
 
4544
 
4544
 
4545
align 4
4545
align 4
4546
 
4546
 
4547
sys_gs:                         ; direct screen access
4547
sys_gs:                         ; direct screen access
4548
 
4548
 
4549
     cmp  eax,1                 ; resolution
4549
     cmp  eax,1                 ; resolution
4550
     jne  no_gs1
4550
     jne  no_gs1
4551
     mov  eax,[ScreenWidth]
4551
     mov  eax,[ScreenWidth]
4552
     shl  eax,16
4552
     shl  eax,16
4553
     mov  ax,[ScreenHeight]
4553
     mov  ax,[ScreenHeight]
4554
     add  eax,0x00010001
4554
     add  eax,0x00010001
4555
     mov  [esp+36],eax
4555
     mov  [esp+36],eax
4556
     ret
4556
     ret
4557
   no_gs1:
4557
   no_gs1:
4558
 
4558
 
4559
     cmp   eax,2                ; bits per pixel
4559
     cmp   eax,2                ; bits per pixel
4560
     jne   no_gs2
4560
     jne   no_gs2
4561
     movzx eax,byte [ScreenBPP]
4561
     movzx eax,byte [ScreenBPP]
4562
     mov   [esp+36],eax
4562
     mov   [esp+36],eax
4563
     ret
4563
     ret
4564
   no_gs2:
4564
   no_gs2:
4565
 
4565
 
4566
     cmp   eax,3                ; bytes per scanline
4566
     cmp   eax,3                ; bytes per scanline
4567
     jne   no_gs3
4567
     jne   no_gs3
4568
     mov   eax,[BytesPerScanLine]
4568
     mov   eax,[BytesPerScanLine]
4569
     mov   [esp+36],eax
4569
     mov   [esp+36],eax
4570
     ret
4570
     ret
4571
   no_gs3:
4571
   no_gs3:
4572
 
4572
 
4573
     mov  [esp+36],dword -1
4573
     mov  [esp+36],dword -1
4574
     ret
4574
     ret
4575
 
4575
 
4576
 
4576
 
4577
align 4 ; PCI functions
4577
align 4 ; PCI functions
4578
 
4578
 
4579
sys_pci:
4579
sys_pci:
4580
 
4580
 
4581
     call  pci_api
4581
     call  pci_api
4582
     mov   [esp+36],eax
4582
     mov   [esp+36],eax
4583
     ret
4583
     ret
4584
 
4584
 
4585
 
4585
 
4586
align 4  ;  system functions
4586
align 4  ;  system functions
4587
 
4587
 
4588
syscall_setpixel:                       ; SetPixel
4588
syscall_setpixel:                       ; SetPixel
4589
 
4589
 
4590
 
4590
 
4591
     mov   edx,[TASK_BASE]
4591
     mov   edx,[TASK_BASE]
4592
     add   eax,[edx-twdw+WDATA.box.left]
4592
     add   eax,[edx-twdw+WDATA.box.left]
4593
     add   ebx,[edx-twdw+WDATA.box.top]
4593
     add   ebx,[edx-twdw+WDATA.box.top]
4594
        mov     edi,[CURRENT_TASK]
4594
        mov     edi,[CURRENT_TASK]
4595
        shl     edi,8
4595
        shl     edi,8
4596
        add     eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4596
        add     eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4597
        add     ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4597
        add     ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4598
     xor   edi,edi ; no force
4598
     xor   edi,edi ; no force
4599
;     mov   edi,1
4599
;     mov   edi,1
4600
     call  [disable_mouse]
4600
     call  [disable_mouse]
4601
     jmp   [putpixel]
4601
     jmp   [putpixel]
4602
 
4602
 
4603
align 4
4603
align 4
4604
 
4604
 
4605
syscall_writetext:                      ; WriteText
4605
syscall_writetext:                      ; WriteText
4606
 
4606
 
4607
     mov   edi,[TASK_BASE]
4607
     mov   edi,[TASK_BASE]
4608
     mov   ebp,[edi-twdw+WDATA.box.left]
4608
     mov   ebp,[edi-twdw+WDATA.box.left]
4609
        push    esi
4609
        push    esi
4610
        mov     esi,[CURRENT_TASK]
4610
        mov     esi,[CURRENT_TASK]
4611
        shl     esi,8
4611
        shl     esi,8
4612
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4612
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4613
     shl   ebp,16
4613
     shl   ebp,16
4614
     add   ebp,[edi-twdw+WDATA.box.top]
4614
     add   ebp,[edi-twdw+WDATA.box.top]
4615
        add     bp,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4615
        add     bp,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4616
        pop     esi
4616
        pop     esi
4617
     add   ecx,[edi+TASKDATA.mem_start]
4617
     add   ecx,[edi+TASKDATA.mem_start]
4618
     add   eax,ebp
4618
     add   eax,ebp
4619
     xor   edi,edi
4619
     xor   edi,edi
4620
     jmp   dtext
4620
     jmp   dtext
4621
 
4621
 
4622
align 4
4622
align 4
4623
 
4623
 
4624
syscall_openramdiskfile:                ; OpenRamdiskFile
4624
syscall_openramdiskfile:                ; OpenRamdiskFile
4625
 
4625
 
4626
 
4626
 
4627
     mov   edi,[TASK_BASE]
4627
     mov   edi,[TASK_BASE]
4628
     add   edi,TASKDATA.mem_start
4628
     add   edi,TASKDATA.mem_start
4629
     add   eax,[edi]
4629
     add   eax,[edi]
4630
     add   edx,[edi]
4630
     add   edx,[edi]
4631
     mov   esi,12
4631
     mov   esi,12
4632
     call  fileread
4632
     call  fileread
4633
     mov   [esp+36],ebx
4633
     mov   [esp+36],ebx
4634
     ret
4634
     ret
4635
 
4635
 
4636
align 4
4636
align 4
4637
 
4637
 
4638
syscall_drawrect:                       ; DrawRect
4638
syscall_drawrect:                       ; DrawRect
4639
 
4639
 
4640
     mov   edi,ecx
4640
     mov   edi,ecx
4641
     and   edi,0x80FFFFFF
4641
     and   edi,0x80FFFFFF
4642
     test  ax,ax
4642
     test  ax,ax
4643
     je    drectr
4643
     je    drectr
4644
     test  bx,bx
4644
     test  bx,bx
4645
     je    drectr
4645
     je    drectr
4646
     movzx ecx,ax
4646
     movzx ecx,ax
4647
     shr   eax,16
4647
     shr   eax,16
4648
     movzx edx,bx
4648
     movzx edx,bx
4649
     shr   ebx,16
4649
     shr   ebx,16
4650
        mov     esi,[CURRENT_TASK]
4650
        mov     esi,[CURRENT_TASK]
4651
        shl     esi,8
4651
        shl     esi,8
4652
        add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4652
        add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4653
        add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4653
        add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4654
     add   ecx,eax
4654
     add   ecx,eax
4655
     add   edx,ebx
4655
     add   edx,ebx
4656
     jmp   [drawbar]
4656
     jmp   [drawbar]
4657
    drectr:
4657
    drectr:
4658
     ret
4658
     ret
4659
 
4659
 
4660
align 4
4660
align 4
4661
 
4661
 
4662
syscall_getscreensize:                  ; GetScreenSize
4662
syscall_getscreensize:                  ; GetScreenSize
4663
 
4663
 
4664
     movzx eax,word[ScreenWidth]
4664
     movzx eax,word[ScreenWidth]
4665
     shl   eax,16
4665
     shl   eax,16
4666
     mov   ax,[ScreenHeight]
4666
     mov   ax,[ScreenHeight]
4667
     mov   [esp+36],eax
4667
     mov   [esp+36],eax
4668
     ret
4668
     ret
4669
 
4669
 
4670
align 4
4670
align 4
4671
 
4671
 
4672
syscall_cdaudio:                        ; CD
4672
syscall_cdaudio:                        ; CD
4673
 
4673
 
4674
     call  sys_cd_audio
4674
     call  sys_cd_audio
4675
     mov   [esp+36],eax
4675
     mov   [esp+36],eax
4676
     ret
4676
     ret
4677
 
4677
 
4678
align 4
4678
align 4
4679
 
4679
 
4680
syscall_delramdiskfile:                 ; DelRamdiskFile
4680
syscall_delramdiskfile:                 ; DelRamdiskFile
4681
 
4681
 
4682
     mov   edi,[TASK_BASE]
4682
     mov   edi,[TASK_BASE]
4683
     add   edi,TASKDATA.mem_start
4683
     add   edi,TASKDATA.mem_start
4684
     add   eax,[edi]
4684
     add   eax,[edi]
4685
     call  filedelete
4685
     call  filedelete
4686
     mov   [esp+36],eax
4686
     mov   [esp+36],eax
4687
     ret
4687
     ret
4688
 
4688
 
4689
align 4
4689
align 4
4690
 
4690
 
4691
syscall_writeramdiskfile:               ; WriteRamdiskFile
4691
syscall_writeramdiskfile:               ; WriteRamdiskFile
4692
 
4692
 
4693
     mov   edi,[TASK_BASE]
4693
     mov   edi,[TASK_BASE]
4694
     add   edi,TASKDATA.mem_start
4694
     add   edi,TASKDATA.mem_start
4695
     add   eax,[edi]
4695
     add   eax,[edi]
4696
     add   ebx,[edi]
4696
     add   ebx,[edi]
4697
     call  filesave
4697
     call  filesave
4698
     mov   [esp+36],eax
4698
     mov   [esp+36],eax
4699
     ret
4699
     ret
4700
 
4700
 
4701
align 4
4701
align 4
4702
 
4702
 
4703
syscall_getpixel:                       ; GetPixel
4703
syscall_getpixel:                       ; GetPixel
4704
     mov   ecx,[ScreenWidth]
4704
     mov   ecx,[ScreenWidth]
4705
     inc   ecx
4705
     inc   ecx
4706
     xor   edx,edx
4706
     xor   edx,edx
4707
     div   ecx
4707
     div   ecx
4708
     mov   ebx,edx
4708
     mov   ebx,edx
4709
     xchg  eax,ebx
4709
     xchg  eax,ebx
4710
     call  dword [GETPIXEL]
4710
     call  dword [GETPIXEL]
4711
     mov   [esp+36],ecx
4711
     mov   [esp+36],ecx
4712
     ret
4712
     ret
4713
 
4713
 
4714
align 4
4714
align 4
4715
 
4715
 
4716
syscall_readstring:                     ; ReadString
4716
syscall_readstring:                     ; ReadString
4717
 
4717
 
4718
     mov   edi,[TASK_BASE]
4718
     mov   edi,[TASK_BASE]
4719
     add   edi,TASKDATA.mem_start
4719
     add   edi,TASKDATA.mem_start
4720
     add   eax,[edi]
4720
     add   eax,[edi]
4721
     call  read_string
4721
     call  read_string
4722
     mov   [esp+36],eax
4722
     mov   [esp+36],eax
4723
     ret
4723
     ret
4724
 
4724
 
4725
align 4
4725
align 4
4726
 
4726
 
4727
syscall_drawline:                       ; DrawLine
4727
syscall_drawline:                       ; DrawLine
4728
 
4728
 
4729
     mov   edi,[TASK_BASE]
4729
     mov   edi,[TASK_BASE]
4730
     movzx edx,word[edi-twdw+WDATA.box.left]
4730
     movzx edx,word[edi-twdw+WDATA.box.left]
4731
     mov   ebp,edx
4731
     mov   ebp,edx
4732
        mov     esi,[CURRENT_TASK]
4732
        mov     esi,[CURRENT_TASK]
4733
        shl     esi,8
4733
        shl     esi,8
4734
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4734
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4735
        add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4735
        add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
4736
     shl   edx,16
4736
     shl   edx,16
4737
     add   ebp,edx
4737
     add   ebp,edx
4738
     movzx edx,word[edi-twdw+WDATA.box.top]
4738
     movzx edx,word[edi-twdw+WDATA.box.top]
4739
     add   eax,ebp
4739
     add   eax,ebp
4740
     mov   ebp,edx
4740
     mov   ebp,edx
4741
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4741
        add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4742
        add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4742
        add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
4743
     shl   edx,16
4743
     shl   edx,16
4744
     xor   edi,edi
4744
     xor   edi,edi
4745
     add   edx,ebp
4745
     add   edx,ebp
4746
     add   ebx,edx
4746
     add   ebx,edx
4747
     jmp   [draw_line]
4747
     jmp   [draw_line]
4748
 
4748
 
4749
align 4
4749
align 4
4750
 
4750
 
4751
syscall_getirqowner:                    ; GetIrqOwner
4751
syscall_getirqowner:                    ; GetIrqOwner
4752
     cmp   eax,16
4752
     cmp   eax,16
4753
     jae   .err
4753
     jae   .err
4754
     shl   eax,2
4754
     shl   eax,2
4755
     add   eax,irq_owner
4755
     add   eax,irq_owner
4756
     mov   eax,[eax]
4756
     mov   eax,[eax]
4757
     mov   [esp+36],eax
4757
     mov   [esp+36],eax
4758
     ret
4758
     ret
4759
.err:
4759
.err:
4760
     or    dword [esp+36], -1
4760
     or    dword [esp+36], -1
4761
     ret
4761
     ret
4762
 
4762
 
4763
align 4
4763
align 4
4764
 
4764
 
4765
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4765
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4766
 
4766
 
4767
     call  r_f_port_area
4767
     call  r_f_port_area
4768
     mov   [esp+36],eax
4768
     mov   [esp+36],eax
4769
     ret
4769
     ret
4770
 
4770
 
4771
align 4
4771
align 4
4772
 
4772
 
4773
syscall_threads:                        ; CreateThreads
4773
syscall_threads:                        ; CreateThreads
4774
 
4774
 
4775
     call  sys_threads
4775
     call  sys_threads
4776
     mov   [esp+36],eax
4776
     mov   [esp+36],eax
4777
     ret
4777
     ret
4778
 
4778
 
4779
align 4
4779
align 4
4780
 
4780
 
4781
stack_driver_stat:
4781
stack_driver_stat:
4782
 
4782
 
4783
     call  app_stack_handler            ; Stack status
4783
     call  app_stack_handler            ; Stack status
4784
 
4784
 
4785
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4785
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4786
;     call  change_task                 ; between sent packet
4786
;     call  change_task                 ; between sent packet
4787
 
4787
 
4788
     mov   [esp+36],eax
4788
     mov   [esp+36],eax
4789
     ret
4789
     ret
4790
 
4790
 
4791
align 4
4791
align 4
4792
 
4792
 
4793
socket:                                 ; Socket interface
4793
socket:                                 ; Socket interface
4794
     call  app_socket_handler
4794
     call  app_socket_handler
4795
 
4795
 
4796
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4796
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4797
;     call  change_task                 ; between sent packet
4797
;     call  change_task                 ; between sent packet
4798
 
4798
 
4799
     mov   [esp+36],eax
4799
     mov   [esp+36],eax
4800
     mov   [esp+24],ebx
4800
     mov   [esp+24],ebx
4801
     ret
4801
     ret
4802
 
4802
 
4803
align 4
4803
align 4
4804
 
4804
 
4805
user_events:                            ; User event times
4805
user_events:                            ; User event times
4806
 
4806
 
4807
     mov   eax,0x12345678
4807
     mov   eax,0x12345678
4808
     mov   [esp+36],eax
4808
     mov   [esp+36],eax
4809
 
4809
 
4810
     ret
4810
     ret
4811
 
4811
 
4812
align 4
4812
align 4
4813
 
4813
 
4814
read_from_hd:                           ; Read from hd - fn not in use
4814
read_from_hd:                           ; Read from hd - fn not in use
4815
 
4815
 
4816
     mov   edi,[TASK_BASE]
4816
     mov   edi,[TASK_BASE]
4817
     add   edi,TASKDATA.mem_start
4817
     add   edi,TASKDATA.mem_start
4818
     add   eax,[edi]
4818
     add   eax,[edi]
4819
     add   ecx,[edi]
4819
     add   ecx,[edi]
4820
     add   edx,[edi]
4820
     add   edx,[edi]
4821
     call  file_read
4821
     call  file_read
4822
 
4822
 
4823
     mov   [esp+36],eax
4823
     mov   [esp+36],eax
4824
     mov   [esp+24],ebx
4824
     mov   [esp+24],ebx
4825
 
4825
 
4826
     ret
4826
     ret
4827
 
4827
 
4828
align 4
4828
align 4
4829
paleholder:
4829
paleholder:
4830
	ret
4830
	ret
4831
 
4831
 
4832
; --------------- APM ---------------------
4832
; --------------- APM ---------------------
4833
apm_entry    dp    0
4833
apm_entry    dp    0
4834
apm_vf        dd    0
4834
apm_vf        dd    0
4835
align 4
4835
align 4
4836
sys_apm:
4836
sys_apm:
4837
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4837
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4838
    jne    @f
4838
    jne    @f
4839
    or    [esp + 56], byte 1    ; error
4839
    or    [esp + 56], byte 1    ; error
4840
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4840
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4841
    ret
4841
    ret
4842
 
4842
 
4843
@@:    xchg    eax, ecx
4843
@@:    xchg    eax, ecx
4844
    xchg    ebx, ecx
4844
    xchg    ebx, ecx
4845
 
4845
 
4846
    cmp    al, 3
4846
    cmp    al, 3
4847
    ja    @f
4847
    ja    @f
4848
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
4848
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
4849
    mov    eax, [apm_vf]
4849
    mov    eax, [apm_vf]
4850
    mov    [esp + 36], eax
4850
    mov    [esp + 36], eax
4851
    shr    eax, 16
4851
    shr    eax, 16
4852
    mov    [esp + 32], eax
4852
    mov    [esp + 32], eax
4853
    ret
4853
    ret
4854
 
4854
 
4855
@@:    call    pword [apm_entry]    ; call APM BIOS
4855
@@:    call    pword [apm_entry]    ; call APM BIOS
4856
    mov    [esp + 8 ], edi
4856
    mov    [esp + 8 ], edi
4857
    mov    [esp + 12], esi
4857
    mov    [esp + 12], esi
4858
    mov    [esp + 24], ebx
4858
    mov    [esp + 24], ebx
4859
    mov    [esp + 28], edx
4859
    mov    [esp + 28], edx
4860
    mov    [esp + 32], ecx
4860
    mov    [esp + 32], ecx
4861
    mov    [esp + 36], eax
4861
    mov    [esp + 36], eax
4862
    setc    al
4862
    setc    al
4863
    and    [esp + 56], byte 0xfe
4863
    and    [esp + 56], byte 0xfe
4864
    or    [esp + 56], al
4864
    or    [esp + 56], al
4865
    ret
4865
    ret
4866
; -----------------------------------------
4866
; -----------------------------------------
4867
 
4867
 
4868
align 4
4868
align 4
4869
 
4869
 
4870
undefined_syscall:                      ; Undefined system call
4870
undefined_syscall:                      ; Undefined system call
4871
 
4871
 
4872
     mov   [esp+36],dword -1
4872
     mov   [esp+36],dword -1
4873
     ret
4873
     ret
4874
 
4874
 
4875
align 4
4875
align 4
4876
system_shutdown:          ; shut down the system
4876
system_shutdown:          ; shut down the system
4877
 
4877
 
4878
           cmp byte [BOOT_VAR+0x9030], 1
4878
           cmp byte [BOOT_VAR+0x9030], 1
4879
           jne @F
4879
           jne @F
4880
           ret
4880
           ret
4881
@@:
4881
@@:
4882
           call stop_all_services
4882
           call stop_all_services
4883
 
4883
 
4884
     push eax
4884
     push eax
4885
     push edx
4885
     push edx
4886
     mov edx, 0x400   ;bocsh
4886
     mov edx, 0x400   ;bocsh
4887
     mov al,0xff      ;bocsh
4887
     mov al,0xff      ;bocsh
4888
     out dx, al       ;bocsh
4888
     out dx, al       ;bocsh
4889
     pop edx
4889
     pop edx
4890
     pop eax
4890
     pop eax
4891
 
4891
 
4892
           push 3                ; stop playing cd
4892
           push 3                ; stop playing cd
4893
           pop  eax
4893
           pop  eax
4894
           call sys_cd_audio
4894
           call sys_cd_audio
4895
 
4895
 
4896
yes_shutdown_param:
4896
yes_shutdown_param:
4897
           cli
4897
           cli
4898
 
4898
 
4899
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
4899
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
4900
           push 12
4900
           push 12
4901
           pop  esi
4901
           pop  esi
4902
           xor  ebx,ebx
4902
           xor  ebx,ebx
4903
           or   ecx,-1
4903
           or   ecx,-1
4904
           mov  edx, OS_BASE+0x80000
4904
           mov  edx, OS_BASE+0x80000
4905
           call fileread
4905
           call fileread
4906
 
4906
 
4907
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
4907
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
4908
           mov  edi,OS_BASE+0x40000
4908
           mov  edi,OS_BASE+0x40000
4909
           mov  ecx,1000
4909
           mov  ecx,1000
4910
           rep  movsb
4910
           rep  movsb
4911
 
4911
 
4912
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
4912
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
4913
           mov  edi, OS_BASE
4913
           mov  edi, OS_BASE
4914
           mov  ecx,0x10000/4
4914
           mov  ecx,0x10000/4
4915
           cld
4915
           cld
4916
           rep movsd
4916
           rep movsd
4917
 
4917
 
4918
           call restorefatchain
4918
           call restorefatchain
4919
 
4919
 
4920
           mov al, 0xFF
4920
           mov al, 0xFF
4921
           out 0x21, al
4921
           out 0x21, al
4922
           out 0xA1, al
4922
           out 0xA1, al
4923
 
4923
 
4924
           mov  word [OS_BASE+0x467+0],pr_mode_exit
4924
           mov  word [OS_BASE+0x467+0],pr_mode_exit
4925
           mov  word [OS_BASE+0x467+2],0x1000
4925
           mov  word [OS_BASE+0x467+2],0x1000
4926
 
4926
 
4927
           mov  al,0x0F
4927
           mov  al,0x0F
4928
           out  0x70,al
4928
           out  0x70,al
4929
           mov  al,0x05
4929
           mov  al,0x05
4930
           out  0x71,al
4930
           out  0x71,al
4931
 
4931
 
4932
           mov  al,0xFE
4932
           mov  al,0xFE
4933
           out  0x64,al
4933
           out  0x64,al
4934
           hlt
4934
           hlt
4935
 
4935
 
4936
 
4936
 
4937
include "data32.inc"
4937
include "data32.inc"
4938
 
4938
 
4939
uglobals_size = $ - endofcode
4939
uglobals_size = $ - endofcode
4940
diff16 "end of kernel code",0,$
4940
diff16 "end of kernel code",0,$