Subversion Repositories Kolibri OS

Rev

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

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