Subversion Repositories Kolibri OS

Rev

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

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