Subversion Repositories Kolibri OS

Rev

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

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