Subversion Repositories Kolibri OS

Rev

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

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