Added APM interface disconnection before real-mode shutdown.

Optimized FIRE program: code size 690->474, now it fits in one sector;
                        memory requirements 0.5Mb -> 200Kb.

git-svn-id: svn://kolibrios.org@79 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2006-05-15 12:49:40 +00:00
parent 60290f1452
commit 65a732dc5a
2 changed files with 152 additions and 196 deletions

View File

@ -376,6 +376,9 @@ restart_kernel_4000:
dd 0 ; cannot save parameters dd 0 ; cannot save parameters
APM_PowerOff: APM_PowerOff:
mov ax, 5304h
xor bx, bx
int 15h
;!!!!!!!!!!!!!!!!!!!!!!!! ;!!!!!!!!!!!!!!!!!!!!!!!!
mov ax,0x5300 mov ax,0x5300
xor bx,bx xor bx,bx

View File

@ -5,144 +5,170 @@
use32 use32
org 0x0 org 0x0
db 'MENUET00' ; 8 byte id db 'MENUET01' ; 8 byte id
dd 38 ; required os dd 1 ; header version
dd START ; program start dd START ; program start
dd I_END ; image size dd I_END ; image size
dd 0x80000 ; reguired amount of memory dd mem_end ; reguired amount of memory
dd 0x80000 dd mem_end
dd 0x00000000 ; reserved=no extended header dd 0,0 ; no parameters, no path
include 'lang.inc' ;include 'lang.inc'
include 'macros.inc' include 'macros.inc'
START: START:
call draw_window red:
mov edi,0x40000 ; ************************************************
mov ecx,320*600+100 ; ********* WINDOW DEFINITIONS AND DRAW **********
mov eax,0 ; ************************************************
cld
rep stosb draw_window:
mov eax,12 ; tell os about redraw
mov ebx,1
int 0x40
xor eax,eax ; define and draw window
mov ebx,100*65536+321
mov ecx,70*65536+222
mov edx,0x00000000
mov esi,0x00000000
mov edi,0x00000000
int 0x40
mov al,4 ; 'FIRE FOR MENUET'
mov ebx,110*65536+8
mov ecx,dword 0x00FFFFFF
mov edx,text
mov esi,textlen-text
int 0x40
mov al,8
mov ebx,(321-19)*65536+12 ; button start x & size
mov ecx,5*65536+12 ; button start y & size
mov edx,1 ; button number
mov esi,0x009a0000
int 0x40
mov ebx,ecx ;5*65536+12
inc edx
int 0x40
mov ebx,18*65536+12
inc edx
int 0x40
mov ebx,31*65536+12
inc edx
int 0x40
mov al,12 ; tell os about redraw end
mov ebx,2
int 0x40
sta: ; calculate fire image sta: ; calculate fire image
mov esi, FireScreen mov esi, FireScreen+0x2300-80
add esi, 0x2300
sub esi, 80
mov ecx, 80 mov ecx, 80
xor edx, edx mov eax, [FireSeed]
NEWLINE: NEWLINE:
mov eax,dword [FireSeed] ; New number mul [RandSeedConst]
mov edx, 0x8405
mul edx
inc eax inc eax
mov dword [FireSeed], eax ; Store seed
mov [esi], dl mov [esi], dl
inc esi inc esi
dec ecx loop NEWLINE
jnz NEWLINE
mov ecx, 0x2300 mov [FireSeed], eax
sub ecx, 80
mov esi, FireScreen mov ecx, 0x2300-80
add esi, 80 sub esi, ecx
xor edx, edx
xor eax, eax
FIRELOOP: FIRELOOP:
lodsb
xor eax,eax cmp [type], ah
cmp [type],0
jnz notype1 jnz notype1
mov al, [esi] mov dl, [esi + 1]
add al, [esi + 2] add eax, edx
adc ah, 0 mov dl, [esi]
add al, [esi + 1] add eax, edx
adc ah, 0 mov dl, [esi + 80]
add al, [esi + 81] jmp typedone
adc ah, 0
notype1: notype1:
cmp [type],1 ; cmp [type],1
jnz notype2 ; jnz notype2
mov al, [esi] mov dl, [esi - 2]
add al, [esi - 1] ; add eax, edx
adc ah, 0 ; mov dl, [esi - 2]
add al, [esi - 1] ; add eax, edx
adc ah, 0 lea eax, [eax + edx*2]
add al, [esi + 79] mov dl, [esi + 78]
adc ah,0 ; notype2:
notype2:
cmp [type],2 ; type 2 is never used
jnz notype3 ; cmp [type],2
mov al, [esi] ; jnz notype3
add al, [esi - 1] ; mov dl, [esi - 2]
adc ah,0 ; add eax, edx
add al, [esi + 1] ; mov dl, [esi]
adc ah, 0 ; add eax, edx
add al, [esi + 81] ; mov dl, [esi + 80]
adc ah,0 ; notype3:
notype3:
typedone:
add eax, edx
shr eax, 2 shr eax, 2
jz ZERO jz ZERO
dec eax dec eax
ZERO: ZERO:
mov [esi - 80], al mov [esi - 81], al
inc esi loop FIRELOOP
dec ecx
jnz FIRELOOP
pusha mov al, 5 ; in this moment always high 24 bits of eax are zero!
mov eax,5
mov ebx,[delay] mov ebx,[delay]
int 0x40 int 0x40
mov al,byte [calc] inc [calc]
inc al cmp [calc], byte 2
mov byte [calc],al jnz nodrw
cmp al,byte 2
jz pdraw
jmp nodrw
pdraw: pdraw:
mov byte [calc],byte 0 mov byte [calc],ah ;byte 0
mov edi,0x40000 mov edi,ImageData
push edi ; pointer for sysfunction 7, draw image
add edi,[fcolor] add edi,[fcolor]
mov esi,FireScreen mov esi,FireScreen
xor edx,edx xor edx,edx
newc: newc:
xor eax, eax
lodsb
movzx eax,byte [esi]
mov ebx,eax
mov ecx,eax mov ecx,eax
shl ax,8 shr eax,1
shr bx,1 add cl,al
mov al,bl mov ch,al
add ecx,eax
shl ax,8
mov ch,ah
mov [edi+0],cx mov [edi+0],ecx
mov [edi+3],cx mov [edi+3],ecx
mov [edi+6],cx mov [edi+6],ecx
mov [edi+9],cx mov [edi+9],cx
mov [edi+0+320*3],cx lea ebx, [edi+320*3]
mov [edi+3+320*3],cx mov [ebx+0],ecx
mov [edi+6+320*3],cx mov [ebx+3],ecx
mov [edi+9+320*3],cx mov [ebx+6],ecx
mov [ebx+9],ecx
add edi,12 add edi,12
inc edx inc edx
@ -151,156 +177,83 @@ sta: ; calculate fire image
xor edx,edx xor edx,edx
add edi,320*3 add edi,320*3
nnl: nnl:
inc esi cmp esi,FireScreen+8000; 0x2000
cmp esi,FireScreen+0x2000
jnz newc jnz newc
mov eax,dword 0x00000007 ; display image mov al,7 ; display image
mov ebx,0x40000 ; high 24 bits of eax are zero!
pop ebx
mov ecx,4*80*65536+200 mov ecx,4*80*65536+200
mov edx,1*65536+22 mov edx,1*65536+22
int 0x40 int 0x40
nodrw: nodrw:
popa
mov eax,11 ; check if os wants to talk to us mov eax,11 ; check if os wants to talk to us
int 0x40 int 0x40
cmp eax,1 dec eax
jz red jz red
cmp eax,3 cmp al, 3-1
jz button jnz nob4
jmp sta
red: ; draw window
call draw_window
jmp sta
button: ; get button id button: ; get button id
mov eax,17 mov al,17
int 0x40 int 0x40
shr eax, 8
cmp ah,1 dec eax
jnz noclose jnz noclose
mov eax,-1 ; close this program or eax,-1 ; close this program
int 0x40 int 0x40
noclose: noclose:
cmp ah,2 ; change fire type dec eax ; change fire type
jnz nob2 jnz nob2
mov eax,[type] xor [type], 1
add eax,1
and eax,1
mov [type],eax
nob2: nob2:
cmp ah,3 ; change delay dec eax ; change delay
jnz nob3 jnz nob3
mov eax,[delay] xor [delay], 1
sub eax,1
and eax,1
mov [delay],eax
nob3: nob3:
cmp ah,4 ; change color dec eax ; change color
jnz nob4 jnz nob4
mov eax,[fcolor] mov eax,[fcolor]
add eax,1 inc eax
cmp eax,2 ; cmp al,2
jbe fcok ; jbe fcok
mov eax,0 jnp fcok
xor eax,eax
fcok: fcok:
mov [fcolor],eax mov [fcolor],eax
mov eax,0 mov edi,ImageData
mov ecx,0x10000 mov ecx,(320*600)/4
mov edi,0x40000 xor eax,eax
cld
rep stosd rep stosd
nob4: nob4:
jmp sta jmp sta
; ************************************************
; ********* WINDOW DEFINITIONS AND DRAW **********
; ************************************************
draw_window:
pusha
mov eax,12 ; tell os about redraw
mov ebx,1
int 0x40
mov eax,0 ; define and draw window
mov ebx,100*65536+321
mov ecx,70*65536+222
mov edx,0x00000000
mov esi,0x00000000
mov edi,0x00000000
int 0x40
mov eax,dword 0x00000004 ; 'FIRE FOR MENUET'
mov ebx,110*65536+8
mov ecx,dword 0x00FFFFFF
mov edx,text
mov esi,textlen-text
int 0x40
mov eax,8
mov ebx,(321-19)*65536+12 ; button start x & size
mov ecx,5*65536+12 ; button start y & size
mov edx,1 ; button number
mov esi,0x009a0000
int 0x40
mov eax,8
mov ebx,5*65536+12
mov ecx,5*65536+12
mov edx,2
int 0x40
mov eax,8
mov ebx,18*65536+12
mov ecx,5*65536+12
mov edx,3
int 0x40
mov eax,8
mov ebx,31*65536+12
mov ecx,5*65536+12
mov edx,4
int 0x40
mov eax,12 ; tell os about redraw end
mov ebx,2
int 0x40
popa
ret
; DATA SECTION ; DATA SECTION
RandSeedConst dd 0x8405
calc dd 0
fcolor dd 2 fcolor dd 2
xx db 'x' xx db 'x'
type dd 0 type db 0
calc db 0
delay dd 0 delay dd 0
FireSeed dd 0x1234 FireSeed dd 0x1234
text: db 'FIRE FOR MENUET' text: db 'FIRE FOR MENUET'
textlen: textlen:
FireScreen:
I_END: I_END:
FireScreen:
rb 0x2300
ImageData:
rb 320*200*3
; stack
align 512
rb 512
mem_end: