Subversion Repositories Kolibri OS

Rev

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

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