Subversion Repositories Kolibri OS

Rev

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

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