tinyfrac: general refactoring, use scancodes

git-svn-id: svn://kolibrios.org@8253 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-11-26 02:19:28 +00:00
parent fe0f60a15e
commit 7057eb8fa0

View File

@ -45,14 +45,14 @@
; released to the public domain by the author. ; released to the public domain by the author.
; ;
; ;
; to assemble & link: ; to assemble & link:
; TASM /m2 tinyfrac (assemble using two pass mode if required) ; TASM /m2 tinyfrac (assemble using two pass mode if required)
; TLINK /Tdc tinyfrac (link Target platform is DOS, COM file) ; TLINK /Tdc tinyfrac (link Target platform is DOS, COM file)
; ;
; ;
PIXWIDTH equ 511 PIXWIDTH equ 512
PIXHEIGHT equ 255 PIXHEIGHT equ 256
ZOOMLIMIT equ 13 ; can change to up to 13 for extended zoom in ZOOMLIMIT equ 13 ; can change to up to 13 for extended zoom in
@ -61,113 +61,54 @@ ZOOMLIMIT equ 13 ; can change to up to 13 for extended zoom in
DELTA equ 200 ; the unit of pan movement in pixels DELTA equ 200 ; the unit of pan movement in pixels
THRESHOLD equ 7 ; must be in the range of (0,255) THRESHOLD equ 7 ; must be in the range of (0,255)
STARTSCALE equ 5 ; a number from 0 to ZOOMLIMIT, inclusive STARTSCALE equ 5 ; a number from 0 to ZOOMLIMIT, inclusive
CHAR_COLOR equ 0fh ; white on black background (for PRINTZOOM feature)
IMGBUF equ 0x1000
; ************************************************************ ; ************************************************************
; ;
; Menuet header ; KolibriOS header
;
; ************************************************************
use32 use32
org 0x0 org 0x0
db 'MENUET01' db 'MENUET01'
dd 0x01 dd 0x01
dd START dd START
dd I_END dd I_END
dd 0x62000 dd PIXWIDTH*PIXHEIGHT*3+IMGBUF+I_END
dd 0x1000 dd 0x1000
dd 0,0 dd 0,0
include 'lang.inc' include 'lang.inc'
include '..\..\..\macros.inc' include '..\..\..\macros.inc'
STARTX dd 200
STARTY dd 120
scaleaddy dd 120
scaleaddx dd 200
START: START:
red:
call draw_window
call draw_fractal call draw_fractal
redraw:
call draw_window
still: still:
mcall 10
mov eax,10
mcall
dec eax dec eax
jz red jz redraw
dec eax dec eax
jz key jz key
button: button:
mov al,17 mcall 17
mcall
cmp ah,1 cmp ah,1
jne no_close jne still
or eax,-1 mcall -1
mcall
no_close:
cmp ah,2
jne no_bgr
mov eax,15 ; bgr 512 x 256
mov ebx,1
mov ecx,512
mov edx,256
mcall
mov eax,15
mov ebx,5
mov ecx,0x1000
mov edx,0
mov esi,512*3*256
mcall
mov eax,15
mov ebx,3
mcall
jmp still
no_bgr:
cmp ah,3
jb no_color
cmp ah,5
jg no_color
shr eax,8
sub eax,3
imul eax,8
add eax,8
not eax
and eax,11000b
mov [shlc],al
call draw_fractal
jmp still
no_color:
jmp still
key: key:
mov al,2 mcall 2
mcall shr eax,16
cmp ah,'e' cmp al,24 ;'o'
je cycle je cycle
cmp ah,'r' cmp al,23 ;'i'
je cycle je cycle
jmp no_cycle jmp no_cycle
cycle: cycle:
@ -175,7 +116,7 @@ still:
jmp still jmp still
no_cycle: no_cycle:
cmp ah,'q' cmp al,13 ;'+'
jne no_in jne no_in
inc byte [scale] inc byte [scale]
mov ebx,[STARTX] mov ebx,[STARTX]
@ -186,9 +127,11 @@ still:
imul ebx,2 imul ebx,2
sub ebx,[scaleaddy] sub ebx,[scaleaddy]
mov [STARTY],ebx mov [STARTY],ebx
call draw_fractal
jmp still
no_in: no_in:
cmp ah,'w' cmp al,12 ;'-'
jne no_out jne no_out
dec byte [scale] dec byte [scale]
mov ebx,[STARTX] mov ebx,[STARTX]
@ -199,50 +142,99 @@ still:
add ebx,[scaleaddy] add ebx,[scaleaddy]
shr ebx,1 shr ebx,1
mov [STARTY],ebx mov [STARTY],ebx
no_out:
cmp ah,130+48
jne no_up
sub [STARTY],100
no_up:
cmp ah,129+48
jne no_down
add [STARTY],100
no_down:
cmp ah,128+48
jne no_left
sub [STARTX],100
no_left:
cmp ah,131+48
jne no_right
add [STARTX],100
no_right:
call draw_fractal call draw_fractal
jmp still jmp still
no_out:
cmp al,72
jne no_up
sub [STARTY],100
call draw_fractal
jmp still
no_up:
cmp al,80
jne no_down
add [STARTY],100
call draw_fractal
jmp still
no_down:
cmp al,75
jne no_left
sub [STARTX],100
call draw_fractal
jmp still
no_left:
cmp al,77
jne no_right
add [STARTX],100
call draw_fractal
jmp still
no_right:
cmp al,19 ;'r'
jne no_red
mov ah,3
call colorize
jmp still
no_red:
cmp al,34 ;'g'
jne no_green
mov ah,4
call colorize
jmp still
no_green:
cmp al,48 ;'b'
jne no_blue
mov ah,5
call colorize
jmp still
no_blue:
cmp al,17 ;'w'
jne no_set_as_wallpaper
mcall 15, 1, PIXWIDTH, PIXHEIGHT
mcall 15, 4, 1 ;mode 1-tiled, 0-stretch
mcall 15, 5, IMGBUF, 0, PIXWIDTH*3*PIXHEIGHT
mcall 15, 3
no_set_as_wallpaper:
jmp still
colorize:
shr eax,8
sub eax,3
imul eax,8
add eax,8
not eax
and eax,11000b
mov [shlc],al
call draw_fractal
ret
color_cycle: color_cycle:
pusha pusha
mov ecx,0x08080808 mov ecx,0x08080808
mov esi,(256/8)*5 mov esi,(PIXHEIGHT/8)*5
cmp ah,'e' cmp al,24
je f_out je f_out
mov ecx,-0x08080808 mov ecx,-0x08080808
mov esi,(256/8)*5-1 mov esi,(PIXHEIGHT/8)*5-1
f_out: f_out:
newcycle: newcycle:
mov edi,0x1000 mov edi,IMGBUF
newpix: newpix:
mov eax,[edi] mov eax,[edi]
add eax,ecx add eax,ecx
mov [edi],eax mov [edi],eax
add edi,4 add edi,4
cmp edi,0x1000+512*256*3 cmp edi,IMGBUF+PIXWIDTH*PIXHEIGHT*3
jb newpix jb newpix
call put_image call put_image
mov eax,5 mov eax,5
@ -252,8 +244,8 @@ color_cycle:
jnz newcycle jnz newcycle
mov eax,0 mov eax,0
mov edi,0x1000 mov edi,IMGBUF
mov ecx,512*256*3 / 4 +50 mov ecx,PIXWIDTH*PIXHEIGHT*3 / 4 +50
cld cld
rep stosd rep stosd
@ -264,23 +256,16 @@ color_cycle:
ret ret
; ********************************************************************** ; **********************************************************************
; ;
; Tinyfrac ; Tinyfrac
; ;
; **********************************************************************
draw_fractal: draw_fractal:
pusha pusha
mov eax,4 mcall 4, 10*65536+10, 0xD0ffffff, calc_txt, 0
mov ebx,10*65536+30
mov ecx,0x80ffffff
mov edx,calc
mcall
popa popa
pusha pusha
@ -298,7 +283,7 @@ draw_fractal:
push cx push cx
mov cx, PIXWIDTH -1 ; width of screen in pixels mov cx, PIXWIDTH ; width of screen in pixels
sub bp,cx ; sub bp,cx ;
@@CalcPixel: @@CalcPixel:
@ -345,22 +330,6 @@ draw_fractal:
ret ret
put_image:
pusha
mov eax,7
mov ebx,0x1000
mov ecx,512*65536+256
mov edx,4*65536+21
mcall
popa
ret
shlc db 0 shlc db 0
put_pixel: put_pixel:
@ -384,15 +353,15 @@ put_pixel:
add cl,3 add cl,3
shl eax,cl shl eax,cl
and eax,ebx and eax,ebx
mov [0x1000+edi],eax mov [IMGBUF+edi],eax
popa popa
ret ret
;**************************************************************************** ;****************************************************************************
; ;
; This routine multiplies AX by DX and shifts the result (in ; This routine multiplies AX by DX and shifts the result (in
; DX:AX) to the right by scale bits (or scale+1 bits if CY is ; DX:AX) to the right by scale bits (or scale+1 bits if CY is
; set). The resulting value is left in AX. DX is destroyed. ; set). The resulting value is left in AX. DX is destroyed.
; ;
@ -414,74 +383,46 @@ scale db STARTSCALE
ret ; ret ;
; ********************************************************************** ; **********************************************************************
; ;
; WINDOW DEFINITIONS AND DRAW ; WINDOW DEFINITIONS AND DRAW
; ;
; ********************************************************************** ; **********************************************************************
draw_window: draw_window:
pusha pusha
mcall 12, 1
mov eax,12 mcall 48, 4 ;get skin height
mov ebx,1 lea ecx, [50*65536+PIXHEIGHT+4+eax]
mcall mcall 0,<50,PIXWIDTH+9>,,0x74000000,,header_txt ;draw window
xor eax,eax call put_image
mov ebx,50*65536+PIXWIDTH+8
mov ecx,100*65536+PIXHEIGHT+25
mov edx,0x14334455
mov edi,title
mcall
mov eax,8 mcall 12, 2
mov ebx,290*65536+112 popa
mov ecx,5*65536+12 ret
mov edx,2
mov esi,0x808080
mcall
mov ebx,420*65536+12
mov ecx,5*65536+12
mov edx,3
mov esi,0xa00000
mov edi,3
;mov eax,8
newcolor:
mcall
add ebx,13*65536
shr esi,8
inc edx
dec edi
jnz newcolor
mov eax,4
mov ebx,300*65536+8
mov ecx,0x80ffffff
mov edx,button_txt
mcall
mov eax,12
mov ebx,2
mcall
put_image:
pusha
mcall 7, IMGBUF, PIXWIDTH*65536+PIXHEIGHT, 0*65536+0
popa popa
ret ret
; *************************************************************** ; **********************************************************************
; ;
; DATA AREA ; DATA AREA
; ;
; **********************************************************************
header_txt db 'Move by Arrows, zoom +/-, cycle O/I, bgr W, color R/G/B',0
calc_txt db 'Calculating...',0
title db 'Tinyfrac - MOVE: ARROWS, ZOOM Q/W, CYCLE: E/R',0 STARTX dd 200
button_txt db 'Set as wallpaper',0 STARTY dd 120
calc db 'CALCULATING',0 scaleaddy dd 120
scaleaddx dd 200
I_END: I_END: