Apps/unvwater: Improved code style and readability

This commit is contained in:
2025-03-13 09:01:14 +02:00
parent 36ce6f0b74
commit eaf0e3c030
5 changed files with 186 additions and 335 deletions

View File

@@ -463,7 +463,7 @@ tup.append_table(img_files, {
{"DEMOS/TINYFRAC", VAR_PROGS .. "/demos/tinyfrac/trunk/tinyfrac"}, {"DEMOS/TINYFRAC", VAR_PROGS .. "/demos/tinyfrac/trunk/tinyfrac"},
{"DEMOS/TRANTEST", VAR_PROGS .. "/demos/trantest/trunk/trantest"}, {"DEMOS/TRANTEST", VAR_PROGS .. "/demos/trantest/trunk/trantest"},
{"DEMOS/TUBE", VAR_PROGS .. "/demos/tube/tube"}, {"DEMOS/TUBE", VAR_PROGS .. "/demos/tube/tube"},
{"DEMOS/UNVWATER", VAR_PROGS .. "/demos/unvwater/trunk/unvwater"}, {"DEMOS/UNVWATER", VAR_PROGS .. "/demos/unvwater/unvwater"},
{"DEMOS/WEB", VAR_PROGS .. "/demos/web/trunk/web"}, {"DEMOS/WEB", VAR_PROGS .. "/demos/web/trunk/web"},
{"DEMOS/ZEROLINE", VAR_PROGS .. "/demos/zeroline/trunk/zeroline"}, {"DEMOS/ZEROLINE", VAR_PROGS .. "/demos/zeroline/trunk/zeroline"},
{"DEVELOP/BOARD", VAR_PROGS .. "/system/board/trunk/board"}, {"DEVELOP/BOARD", VAR_PROGS .. "/system/board/trunk/board"},

View File

@@ -1,4 +1,4 @@
if tup.getconfig("NO_FASM") ~= "" then return end if tup.getconfig("NO_FASM") ~= "" then return end
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_fasm.lua") tup.include(HELPERDIR .. "/use_fasm.lua")
tup.rule("unvwater.asm", FASM .. " -dlang=" .. tup.getconfig("LANG") .. " %f %o " .. tup.getconfig("KPACK_CMD"), "%B") tup.rule("unvwater.asm", FASM .. " -dlang=" .. tup.getconfig("LANG") .. " %f %o " .. tup.getconfig("KPACK_CMD"), "%B")

View File

@@ -1,142 +0,0 @@
include 'proc32.inc'
macro start_draw_window x,y,xsize,ysize,areacolor,caption;,capsize
{
mov eax, 12 ; function 12:tell os about windowdraw
mov ebx, 1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax, 48 ; function 48.4 : get skin height
mov ebx, 4
int 0x40
push eax
lea ecx, [y*65536+ysize+eax]; [y start] *65536 + [y size] + [skin_height]
xor eax, eax ; function 0 : define and draw window
mov ebx, x*65536+xsize ; [x start] *65536 + [x size]
mov edx, areacolor ; color of work area RRGGBB
;mov esi, 0x00334455 ; color of grab bar RRGGBB
mov edi, caption;0x00ddeeff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
;mov eax, 4 ; function 4 : write text to window
;mov ebx, 8*65536+8 ; [x start] *65536 + [y start]
;mov ecx, 0x00ffffff ; color of text RRGGBB
;mov edx, caption ; pointer to text beginning
;mov esi, capsize ; text length
;mov eax, 71 ; function 71.1
;mov ebx, 1 ; set window caption
;mov ecx, caption ; pointer to text
;int 0x40
pop eax
}
macro end_draw_window
{
mov eax, 12 ; end of redraw
mov ebx, 2
int 0x40
}
proc draw_button stdcall, x:dword, y:dword, xsize:dword, ysize:dword, \
id:dword, butcolor:dword, text:dword, textlen:byte, textcolor:dword
;pusha
mov ebx, dword [x]
shl ebx, 16
add ebx, dword [xsize] ; [x start] *65536 + [x size]
mov ecx, dword [y]
shl ecx, 16
add ecx, dword [ysize] ; [y start] *65536 + [y size]
mov edx, dword [id] ; button id
mov esi, dword [butcolor] ; button color RRGGBB
mov eax, 8 ; function 8 : define and draw button
int 0x40
mov ebx, dword [x]
add ebx, 5
shl ebx, 16
mov eax, dword [ysize]
sub eax, 5
shr eax, 1
add ebx, eax
add ebx, dword [y] ;mov ebx, (x+5)*65536+y+(ysize-5)/2 ; Draw button text
mov ecx, dword [textcolor]
mov edx, dword [text]
xor eax, eax
mov al, byte [textlen]
mov esi, eax
mov eax, 4
int 0x40
;popa
ret
endp
macro outtextxy x,y,prompt,prompt_len,color
{
pusha
mov ebx, x*65536+y ; draw info text with function 4
mov ecx, color
mov edx, prompt
xor eax, eax
mov al, prompt_len
mov esi, eax
mov eax, 4
int 0x40
popa
}
;proc bar x:dword, y:dword, xsize:dword, ysize:dword, color:dword
macro bar x, y, xsize, ysize, color
{
pusha
mov eax, 13
;mov ebx, [x]
;shl ebx, 16
;add ebx, [xsize]
;mov ecx, [y]
;shl ecx, 16
;add ecx, [ysize]
;mov edx, [color]
mov ebx, x*65536+xsize
mov ecx, y*65536+ysize
mov edx, color
int 0x40
popa
;ret
;endp
}
macro line x1,y1,x2,y2,color
{
pusha
mov eax, 38
mov ebx, x1*65536+x2
mov ecx, y1*65536+y2
mov edx, color
int 0x40
popa
}
macro rectangle x,y,xsize,ysize,color
{
x2=x+xsize
y2=y+ysize
line x,y,x2,y,color
line x,y,x,y2,color
line x,y2,x2,y2,color
line x2,y,x2,y2,color
}
macro putpixel x,y,color
{
mov eax, 1
mov ebx, x
mov ecx, y
mov edx, color
int 0x40
}

View File

@@ -1,191 +0,0 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A unvwater demo
; Programmed by Octavio Vega Fernandez
; http://octavio.vega.fernandez.googlepages.com/CV4.HTM
; Converted to KolibriOS, By Asper
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use32
org 0x0
db 'MENUET01' ; header
dd 1 ; version
dd STARTAPP ; program start
dd I_END ; program image size
dd MEM ; size memory for program
dd STACKTOP ; pointer of stack
dd 0
dd 0
;macro start_draw_window x,y,xsize,ysize,areacolor,caption;,capsize
;{
; mov eax, 12 ; function 12:tell os about windowdraw
; mov ebx, 1 ; 1, start of draw
; int 0x40
; ; DRAW WINDOW
; mov eax, 48 ; function 48.4 : get skin height
; mov ebx, 4
; int 0x40
; push eax
; lea ecx, [y*65536+ysize+eax]; [y start] *65536 + [y size] + [skin_height]
; xor eax, eax ; function 0 : define and draw window
; mov ebx, x*65536+xsize ; [x start] *65536 + [x size]
; mov edx, areacolor ; color of work area RRGGBB
; ;mov esi, 0x00334455 ; color of grab bar RRGGBB
; mov edi, caption;0x00ddeeff ; color of frames RRGGBB
; int 0x40
; pop eax
;}
;
;macro end_draw_window
;{
; mov eax, 12 ; end of redraw
; mov ebx, 2
; int 0x40
;}
include "aspapi.inc"
SCREEN_WIDTH equ 100h
SCREEN_HEIGHT equ 100h
STARTAPP:
mov eax, 18 ;Get CPU speed
mov ebx, 5
int 0x40
shr eax, 28
mov dword [delay], eax
init_palette:
mov edi, Paleta
;xor eax, eax
mov eax, 0x40
@@:
stosd
inc al
jnz @b
MAIN:
l1:
xor esi, esi
l11:
xor ebx, ebx
mov edx, 303h
sub esi, 101h
l2:
and esi, 0xFFFF ;esi=si
add bl, [esi+img]
adc bh, ah
inc esi
dec dh
jnz l2
mov dh, 3
add esi, 100h-3
dec dl
jnz l2
sub esi, 1ffh
and esi, 0xFFFF ;esi=si
mov al, [img+esi]
sub bx, ax
shl ax, 2
sub bx, ax
shr bx, 2
mov ax, bx
shr ax, 7
sub bx, ax
mov [img+esi], bl
inc si
jnz l11
call copy_buffer_to_video
still:
mov eax, 11 ; Test if there is an event in the queue.
int 0x40
cmp al,1 ; redraw request ?
jz red
cmp al,2 ; key in buffer ?
jz key
cmp al,3 ; button in buffer ?
jz button
jmp MAIN
red:
call draw_window
jmp MAIN
key:
mov eax, 2
int 0x40
cmp ah, 27 ; Test Esc in ASCII
je close_app
jmp MAIN
button:
mov eax, 17 ; Get pressed button code
int 0x40
cmp ah, 1 ; Test x button
je close_app
jmp MAIN
draw_window:
start_draw_window 100,70,SCREEN_WIDTH+9,SCREEN_HEIGHT+4,0x54224466,labelt;, 14;labellen-labelt
mov dword [skin_h], eax
end_draw_window
ret
fail:
; Type something here.
close_app:
mov eax, -1 ; close this program
int 0x40
copy_buffer_to_video:
pusha
; mov eax, 18 ;@WAITVSYNC();
; mov ebx, 14
; int 0x40
mov eax, 5 ;delay
mov ebx, dword [delay]
int 0x40
mov eax, dword [skin_h]
lea edx, [5*65536+eax]
mov eax, 65
mov ebx, img
mov ecx, SCREEN_WIDTH*65536+SCREEN_HEIGHT ;ecx = w*65536+h
; mov edx, 5*65536+25 ;edx = x*65536+y
mov esi, 8
mov edi, Paleta
xor ebp, ebp
int 0x40
popa
ret
; DATA AREA
; Application Title
labelt db 'UnvWater demo',0
delay dd 0
skin_h dd 25 ; Skin height.
I_END:
Paleta rb 1024
img db 1
rb 10000h
rb 256
STACKTOP:
MEM:

View File

@@ -0,0 +1,184 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A unvwater demo
; Programmed by Octavio Vega Fernandez
; http://octavio.vega.fernandez.googlepages.com/CV4.HTM
; Converted to KolibriOS, By Asper
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use32
org 0x0
db 'MENUET01' ; header
dd 1 ; version
dd STARTAPP ; program start
dd I_END ; program image size
dd MEM ; size memory for program
dd STACKTOP ; pointer of stack
dd 0,0
include '../../proc32.inc'
include '../../macros.inc'
include '../../KOSfuncs.inc'
macro start_draw_window x,y,xsize,ysize,areacolor,caption;,capsize
{
mcall SF_REDRAW, SSF_BEGIN_DRAW
mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
push eax
lea ecx, [y*65536+ysize+eax]; [y start] *65536 + [y size] + [skin_height]
mov ebx, x*65536+xsize ; [x start] *65536 + [x size]
mov edx, areacolor ; color of work area RRGGBB
mov edi, caption;0x00ddeeff ; color of frames RRGGBB
mcall SF_CREATE_WINDOW
pop eax
}
SCREEN_WIDTH equ (600-10) ;10 px for borders
SCREEN_HEIGHT equ 400
STARTAPP:
mcall SF_SYSTEM, SSF_GET_CPU_FREQUENCY
shr eax, 28
mov dword [delay], eax
init_palette:
mov edi, Paleta
mov eax, 0x40
@@:
stosd
inc al
jnz @b
MAIN:
xor esi, esi
mov ecx, SCREEN_WIDTH*SCREEN_HEIGHT
l11:
xor ebx, ebx
mov edx, 303h
sub esi, SCREEN_WIDTH+1
l2:
cmp esi,0
jge @f
add esi, ecx
@@:
cmp esi, ecx
jl @f
sub esi, ecx
@@:
add bl, [esi+img]
adc bh, ah
inc esi
dec dh
jnz l2
mov dh, 3
add esi, SCREEN_WIDTH-3
dec dl
jnz l2
sub esi, 2*SCREEN_WIDTH-1
cmp esi,0
jge @f
add esi, ecx
@@:
cmp esi, ecx
jl @f
sub esi, ecx
@@:
mov al, [img+esi]
sub bx, ax
shl ax, 2
sub bx, ax
shr bx, 2
mov ax, bx
shr ax, 7
sub bx, ax
mov [img+esi], bl
inc esi
cmp esi, ecx
jl l11
call copy_buffer_to_video
still:
mcall SF_CHECK_EVENT ; Test if there is an event in the queue.
cmp al,EV_REDRAW
jz red
cmp al,EV_KEY
jz key
cmp al,EV_BUTTON
jz button
jmp MAIN
red:
call draw_window
jmp MAIN
key:
mcall SF_GET_KEY
cmp ah, 27 ; Test Esc in ASCII
je close_app
jmp MAIN
button:
mcall SF_GET_BUTTON ; Get pressed button code
cmp ah, 1 ; Test x button
je close_app
jmp MAIN
draw_window:
start_draw_window 100,70,SCREEN_WIDTH+9,SCREEN_HEIGHT+4,0x54224466,labelt;, 14;labellen-labelt
mov dword [skin_h], eax
mcall SF_REDRAW, SSF_END_DRAW
ret
fail:
; Type something here.
close_app:
mcall SF_TERMINATE_PROCESS
copy_buffer_to_video:
pusha
;mcall SF_SYSTEM, SSF_WAIT_RETRACE
mcall SF_SLEEP, [delay]
mov eax, dword [skin_h]
lea edx, [5*65536+eax]
mov ecx, SCREEN_WIDTH*65536+SCREEN_HEIGHT ;ecx = w*65536+h
;mov edx, 5*65536+25 ;edx = x*65536+y
mov esi, 8
mov edi, Paleta
xor ebp, ebp
mcall SF_PUT_IMAGE_EXT, img
popa
ret
; DATA AREA
; Application Title
labelt db 'UnvWater demo',0
delay dd 0
skin_h dd 25 ; Skin height.
I_END:
Paleta rb 1024
img db 1
rb SCREEN_WIDTH*SCREEN_HEIGHT
rb 256
align 4
STACKTOP:
MEM: