Subversion Repositories Kolibri OS

Rev

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

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