Subversion Repositories Kolibri OS

Rev

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

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