Subversion Repositories Kolibri OS

Rev

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

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