wr128b(ZX128), 48K improved for 48K v2
Немного трюков из поуета, ибо впадлу листать:
[PALETTE CODE REMOVED - ax = cx = 0 after it]
_mainloop: _loop: db 0xbb ; mov bx, 320
_320i: dw 320 ;
pusha needed due to some other things happening ;)
cwd
mov ax, di
div bx ; dx = x & ax = y
db 0x81, 0xea ; sub dx, 160
_160i: dw 160
db 0x2d ; sub ax, 100
_100i: dw 100
[HUGE CHUNK OF MAGIC REMOVED]
; 19 bytes sine table approx from 0 to 2*Pi : 255 values amplitude=53 [-26;0;+26]
_sin:
mov bx,ax ; al=bl=x
imul bl ; ax=x*x
mov al,ah ; ax=x*x*256+x%256
imul bl ; ax=x*(x*x*256+x%256)
mov al,ah ; ax=(x*(x*x*256+x%256))*256+(x*(x*x*256+x%256))%256
shr bx,2 ; bx=x/4
add al,13 ; ax=13+(x*(x*x*256+x%256))*256+(x*(x*x*256+x%256))%256
sub ax,bx ; ax=-x/4+100+(x*(x*x*256+x%256))*256+(x*(x*x*256+x%256))%256
db 0d4h,64 ; ax=(-x/4+100+(x*(x*x*256+x%256))*256+(x*(x*x*256+x%256))%256)%64
ret
;9 bytes parabola
_sin: ; sin(x)=(x*4/pi)-x*x*(4/pi*pi) if x>0 from from http://www.coranac.com/2009/07/sines/ in deg : sin(x)=(10*x-x*x)/6000*scale
; sin(x)=(x*4/pi)+x*x*(4/pi*pi) if x=<0
mov bx,ax ; al=bl=x
mul al ; ax=x*x
xchg ax,bx ; ax=x bx=x*x
aad ; ax=10*x (2 bytes smaller than mov dl,10 + mul dl)
sub ax,bx ; ax=10*x-x*x if x>0 else branch/replace by add ax,bx or use absolute value trick
mov al,ah
ret ; ah=6000*scale, using scale=23,4375 ah=256*al
Pseudo Random number generator ASM/8086
http://www.df.lth.se/~john_e/gems/gem0002.html
Here is a small pseudo random generator. I found it on Andrew Griffinis homepage, but I seem to have misslaid his e-mail and homepage address.
;
; pseudo random number generator
;
; input:
; bp = seed (!=0)
;
; output:
; ax = random word
;
; destroys:
; bp
; flags
;
mov al,16
r_loop: rol bp,1
jnc r_skip
xor bp,0ah
r_skip: dec al
jne r_loop
mov ax,bp
One improvement that can be done is to replace store BP someway so you can reuse it later in the random routine.
Max McGuire has submitted a new version (note that in order for this version to run on a 286 and below, FS has to be replaced with another segment register):
I'm submitting to you an alternative pseudo random generator that I found in the source for the intro Chaos by Consub of CSB. Here's his original code:
mov ax,fs
mov bx,13
mul bx
xchg ah,al
mov fs,ax
I kept the same basic idea, but optimized (at least I think I optimized) this code for speed by making a few changes (I also changed the seed from fs to dx):
mov bx,dx
shl dx,2
add dx,bx
xchg dl,dh
I don't know if this algorithm generates random numbers that are uniformly distributed between 0 and 65535
ожыдание вывода на экран:
verical retrace check:
mov dx, 3dah
@wait1:
in al, dx
test al, 8
jz @wait1
@wait2:
in al, dx
test al, 8
jnz @wait2
проверка нажатия Esc:
in al, 0x60
dec al
jnz short _mainloop
http://www.df.lth.se/~john_e/gems/gem0004.html
SALC - Set AL on Carry | ASM/8086 |
This small gem presents an undocumented opcode available on all Intel CPUs. The instruction mnemonic is called SALC
and sets AL
to match the carry flag, ie if the Carry is set, AL
will be set to FF
, else zero. The instruction macro looks like this:
; ; salc - set al to carry (undocumented opcode) ; ; input: ; none ; ; output: ; al = 0FFh * CF ; ; destroys: ; nothing ; macro db 0d6h endm
It does not affect any flags. It was first documented officially when Intel released the Pentium Pro processor. It is officially named SALC
.
salc
_palette: mov dx, 0x3c9
times 3 out dx, al
inc ax
jnz short _palette
This is what I currently use - inspired by the palette code of some other 256b/128b intros (one of them is spongy - not sure what the other intro with the "ignore setting the index" trick was and another one brought the salc trick for setting ax to zero). Not sure whether that's a good idea or not ;)
Nice rotation code from baze/3SC.
fsincos
fld st2
fmul st0, st1
fld st4
fmul st0, st3
fsubp st1, st0
fxch st3
fmulp st2, st0
fmulp st3, st0
faddp st2, st0
;Input st0=A st1=X st2=Y st3=Z Output st0=(cos(A)*X - sin(A)*Y) st1=(cos(A)*Y + sin(A)*X) st2=Z
int 2jkjkghghk0h
интро, написанное из-за того, что вахрушка Gargaj влепил двухдневный бан из-за пиздежа чмыря Димочки Быстрова.