Subversion Repositories Kolibri OS

Rev

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

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