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'
dd 0x01
db 'MENUET01' dd START
dd 0x01 dd I_END
dd START dd PIXWIDTH*PIXHEIGHT*3+IMGBUF+I_END
dd I_END dd 0x1000
dd 0x62000 dd 0,0
dd 0x1000
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:
call draw_fractal
red: redraw:
call draw_window call draw_window
call draw_fractal
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
@ -291,14 +276,14 @@ draw_fractal:
; This routine is the fractal drawing engine. It has been ; This routine is the fractal drawing engine. It has been
; optimized for size, sacrificing speed. ; optimized for size, sacrificing speed.
mov cx, PIXHEIGHT ; height of screen in pixels mov cx, PIXHEIGHT ; height of screen in pixels
sub di,cx ; adjust our Y offset sub di,cx ; adjust our Y offset
@@CalcRow: @@CalcRow:
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
mov ebx,1 mcall 48, 4 ;get skin height
mcall lea ecx, [50*65536+PIXHEIGHT+4+eax]
mcall 0,<50,PIXWIDTH+9>,,0x74000000,,header_txt ;draw window
xor eax,eax
mov ebx,50*65536+PIXWIDTH+8 call put_image
mov ecx,100*65536+PIXHEIGHT+25
mov edx,0x14334455 mcall 12, 2
mov edi,title
mcall
mov eax,8
mov ebx,290*65536+112
mov ecx,5*65536+12
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
popa popa
ret ret
put_image:
pusha
mcall 7, IMGBUF, PIXWIDTH*65536+PIXHEIGHT, 0*65536+0
popa
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: