Apps/fire: Improved code style and readability

This commit is contained in:
2025-03-15 20:27:18 +02:00
committed by Max Logaev
parent 20aba254bc
commit afd07534ab
3 changed files with 62 additions and 91 deletions

View File

@@ -1,82 +1,60 @@
; ;
; FIRE for MENUET - Compile with FASM ; Fire for Kolibri OS - Compile with FASM
; ;
use32 use32
org 0
db 'MENUET01' ; 8 byte id
dd 1 ; header version
dd START ; program start
dd image_end ; image size
dd mem_end ; reguired amount of memory
dd stacktop
dd 0,0 ; no parameters, no path
org 0x0 include '..\..\macros.inc'
db 'MENUET01' ; 8 byte id include '..\..\KOSfuncs.inc'
dd 1 ; header version
dd START ; program start Screen_W equ 480
dd I_END ; image size
dd mem_end ; reguired amount of memory
dd mem_end
dd 0,0 ; no parameters, no path
include '..\..\..\macros.inc'
START: START:
red:
; ************************************************ ; ************************************************
; ********* WINDOW DEFINITIONS AND DRAW ********** ; ********* WINDOW DEFINITIONS AND DRAW **********
; ************************************************ ; ************************************************
draw_window: draw_window:
mov eax,12 ; tell os about redraw mcall SF_REDRAW, SSF_BEGIN_DRAW
mov ebx,1
mcall
xor eax,eax ; define and draw window mcall SF_CREATE_WINDOW,<100,Screen_W+1>,<70,222>,0x01000000,0,0
mov ebx,100*65536+321
mov ecx,70*65536+222
mov edx,0x01000000
mov esi,0x00000000
mov edi,0x00000000
mcall
mcall 13,0*65536+321,0*65536+30,0 mcall SF_DRAW_RECT,<0,Screen_W+1>,<0,30>,0
mcall ,0*65536+1 ,0*65536+222 mcall ,<0,1>,<0,222>
mcall ,321*65536+1,0*65536+223 mcall ,<Screen_W+1,1>,<0,223>
mcall ,0*65536+321,222*65536+1 mcall ,<0,Screen_W+1>,<222,1>
mcall SF_DRAW_TEXT,<(Screen_W-108)/2,8>,dword 0x00FFFFFF,text,textlen-text
mov al,4 ; 'FIRE FOR KOLIBRI' mcall SF_DEFINE_BUTTON,<(Screen_W+1-19),12>,<5,12>,1,0x009a0000
mov ebx,106*65536+8
mov ecx,dword 0x00FFFFFF
mov edx,text
mov esi,textlen-text
mcall
mov al,8 mov ebx,ecx ;5*65536+12
mov ebx,(321-19)*65536+12 ; button start x & size inc edx
mov ecx,5*65536+12 ; button start y & size mcall
mov edx,1 ; button number
mov esi,0x009a0000
mcall
mov ebx,ecx ;5*65536+12
inc edx inc edx
mcall mcall ,<18,12>
mov ebx,18*65536+12
inc edx inc edx
mcall mcall ,<31,12>
mov ebx,31*65536+12 mcall SF_REDRAW, SSF_END_DRAW
inc edx
mcall
mov al,12 ; tell os about redraw end
mov ebx,2
mcall
sta: ; calculate fire image sta: ; calculate fire image
mov esi, FireScreen+0x2300-80 mov esi, FireScreen.end+Screen_W*3-Screen_W/4
mov ecx, 80 mov ecx, Screen_W/4
mov eax, [FireSeed] mov eax, [FireSeed]
NEWLINE: NEWLINE:
@@ -89,7 +67,7 @@ sta: ; calculate fire image
mov [FireSeed], eax mov [FireSeed], eax
mov ecx, 0x2300-80 mov ecx, (Screen_W*200)/8+Screen_W*3-Screen_W/4
sub esi, ecx sub esi, ecx
xor edx, edx xor edx, edx
xor eax, eax xor eax, eax
@@ -103,7 +81,7 @@ sta: ; calculate fire image
add eax, edx add eax, edx
mov dl, [esi] mov dl, [esi]
add eax, edx add eax, edx
mov dl, [esi + 80] mov dl, [esi + Screen_W/4]
jmp typedone jmp typedone
notype1: notype1:
@@ -114,7 +92,7 @@ sta: ; calculate fire image
; mov dl, [esi - 2] ; mov dl, [esi - 2]
; add eax, edx ; add eax, edx
lea eax, [eax + edx*2] lea eax, [eax + edx*2]
mov dl, [esi + 78] mov dl, [esi + Screen_W/4-2]
; notype2: ; notype2:
; type 2 is never used ; type 2 is never used
@@ -124,7 +102,7 @@ sta: ; calculate fire image
; add eax, edx ; add eax, edx
; mov dl, [esi] ; mov dl, [esi]
; add eax, edx ; add eax, edx
; mov dl, [esi + 80] ; mov dl, [esi + Screen_W/4]
; notype3: ; notype3:
typedone: typedone:
@@ -135,12 +113,10 @@ typedone:
ZERO: ZERO:
mov [esi - 81], al mov [esi - Screen_W/4-1], al
loop FIRELOOP loop FIRELOOP
mov al, 5 ; in this moment always high 24 bits of eax are zero! mcall SF_SLEEP,[delay]
mov ebx,[delay]
mcall
inc [calc] inc [calc]
cmp [calc], byte 2 cmp [calc], byte 2
@@ -169,7 +145,7 @@ typedone:
mov [edi+3],ecx mov [edi+3],ecx
mov [edi+6],ecx mov [edi+6],ecx
mov [edi+9],cx mov [edi+9],cx
lea ebx, [edi+320*3] lea ebx, [edi+Screen_W*3]
mov [ebx+0],ecx mov [ebx+0],ecx
mov [ebx+3],ecx mov [ebx+3],ecx
mov [ebx+6],ecx mov [ebx+6],ecx
@@ -177,50 +153,43 @@ typedone:
add edi,12 add edi,12
inc edx inc edx
cmp edx,80 cmp edx,Screen_W/4
jnz nnl jnz nnl
xor edx,edx xor edx,edx
add edi,320*3 add edi,Screen_W*3
nnl: nnl:
cmp esi,FireScreen+8000; 0x2000 cmp esi,FireScreen.end
jnz newc jnz newc
mov al,7 ; display image
; high 24 bits of eax are zero!
pop ebx pop ebx
mov ecx,4*80*65536+200 mcall SF_PUT_IMAGE,,<Screen_W,200>,<1,22>
mov edx,1*65536+22
mcall
nodrw: nodrw:
mov eax,11 ; check if os wants to talk to us mcall SF_CHECK_EVENT ; check if os wants to talk to us
mcall
dec eax dec eax
jz red jz draw_window
cmp al, 3-1 cmp al, 3-1
jnz nob4 jnz nob4
button: ; get button id button: ; get button id
mov al,17 mcall SF_GET_BUTTON
mcall
shr eax, 8 shr eax, 8
dec eax dec eax
jnz noclose jnz @f
or eax,-1 ; close this program mcall SF_TERMINATE_PROCESS ; close this program
mcall @@:
noclose:
dec eax ; change fire type dec eax ; change fire type
jnz nob2 jnz @f
xor [type], 1 xor [type], 1
nob2: @@:
dec eax ; change delay dec eax ; change delay
jnz nob3 jnz @f
xor [delay], 1 xor [delay], 1
nob3: @@:
dec eax ; change color dec eax ; change color
jnz nob4 jnz nob4
@@ -233,7 +202,7 @@ typedone:
fcok: fcok:
mov [fcolor],eax mov [fcolor],eax
mov edi,ImageData mov edi,ImageData
mov ecx,(320*600)/4 mov ecx,(Screen_W*200*3)/4
xor eax,eax xor eax,eax
rep stosd rep stosd
@@ -246,19 +215,23 @@ fcolor dd 2
xx db 'x' xx db 'x'
type db 0 type db 0
calc db 0 calc db 0
delay dd 0 delay dd 1
FireSeed dd 0x1234 FireSeed dd 0x1234
text: db 'FIRE FOR KOLIBRI' text: db 'Fire for Kolibri'
textlen: textlen:
I_END: align 4
image_end:
FireScreen: FireScreen:
rb 0x2300 rb (Screen_W*200)/8 ;wisible fire
.end:
rb Screen_W*3 ;hidden fire (need for generation)
ImageData: ImageData:
rb 320*200*3 rb Screen_W*200*3
; stack ; stack
align 512 align 512
rb 512 rb 512
stacktop:
mem_end: mem_end:

View File

@@ -1,2 +0,0 @@
@fasm fire.asm fire
@pause