Throwing nonsense at the masses.

ZXNet echo conference «code.zx»

From Aleksey Malov To All 30 March 2000

Greetings, All! Chunky 8*8 generator using ordered dithering method. Try setting the chtab address to #4000. In the procedure, I sacrificed speed for volume. It's not difficult to increase the speed, although this will increase the length of the procedure by several bytes. ld hl,chtab;chunky table address must be a multiple of #800 cls ld (hl),0;clear the table inc hl bit 3,h jr z,cls;if location address ;chunky table is #x800, then ;put jr nz,cls dchunk ld e,l dchun1 ld d,e ld h,3 dch1 xor a; in this cycle the sub d; coordinates rrc d;points rrc d;which rra ;must be installed rl c ;in chunky table rra rl b dec h jr nz,dch1 ;now in C-y, in B-X ld a,c inc a; can be removed, but then ;the point will be put ;one pixel higher than necessary and 7 add a,chtab/256 ld h,a ld a,#40;now we define ;bit corresponding ;at this point rrca:djnz$-1 xor (hl); exactly Xor ld(hl),a inc e jr nz,dchun1 dec l jr nz,dchunk The length of the procedure is 49 bytes, although it is possible that you can try to make it shorter. The procedure for calculating 4*4 chunks by MEGUS/BW/XPJ. LD HL,CH_IMG;packed chunk tableLD DE,TEMP_BUFFER;temporary 64 ;byte buffer TEMP_BUFFER=#xx00 LD B,32 ;unpack the table into a temporary buffer L0 LD A,(HL):RLD:LD (DE),A:INC DE LD A,(HL):RLD:LD (DE),A:INC DE INC HL DJNZ L0 LD H,D LD L,B LD E,B LD BC,CHUNKY_TB;address 1k table ;chunk equal to #xx00 L1 LD A,(DE) XOR (HL) AND 15 XOR (HL) LD(BC),A INC B.C. INC L LD A,L AND 15 JR NZ,L1 INC E LD A,E AND #F0 LD L,A SUB #40 JR NZ,L1 ;now we create a table of pointers for chunky, if necessary, of course. ;after the previous procedure A=0 LD H,CHUNKPTR/256;in table ;pointers contain low bytes ;chunk addresses LD D,H I_C_PTR LD B,16 LD L,D I_C_PT1 LD (HL),A INC A INC L DJNZ I_C_PT1 INC H OR A JR NZ,I_C_PTR ret ;packed chunky table. CH_IMG DW #AA08,#AAAA,#FFBE,#FFFF DW #0000,#5544,#5555,#FFDD DW #2A02,#AAAa,#BFAB,#FFFF DW #0000,#1501,#5555,#7F57 Length of the table procedure: 64+32=96 bytes. Procedures for generating sine tables. Based on the use of the second derivative. Data in the table SINTAB are stored as two-bit increments of the derivative of the sine wavefunctions increased by one. The following procedure generates a 512 byte signed table sines with amplitude 255: LD HL,SINTAB-1 ;data table LD DE,SINUS+255;sine table, SINUS=#xx00 LD BC,#06FA;B=-C=difference of the first two values of the original table sinuses. INS INC E ;calculate new value LD A,E AND 3 ;check for end of byte JR NZ,$+3;data tables INC HL ;go to new byte XOR A ;took increment RLC (HL) ;differences RLA ;from RLC (HL); tables R.L.A. DEC A ;now increment=-1..+2 ADD A,B ;added it to the current one LD B,A ;differences ADD A,C ;and to current value LD C,A ;sine CALL INSSR; placed in memory ;positive and negative ;sine values in the 1st and 3rd quarters PUSH DE LD A,128;now we put +sin and -sin SUB E ;in the II and IV quarters LD E,A LD A,C CALL INSSR POP DE BIT 6,E ;check for end JR Z,INS ;here you can put ret, or place some of your own procedures INSSR LD (DE),A SET 7,E N.E.G. LD(DE),A INC D SBC A,A LD(DE),A RES 7,E XOR A LD(DE),A DEC D RET SINTAB ;packed data DB #58,#56,#15,#55 DB #49,#21,#85,#52 DB #21,#54,#88,#54DB #85,#52,#15,#48,#55 THE LENGTH OF THE PROCEDURE INCLUDING THE TABLE IS 77 BYTES. The following procedure creates a 256-byte signed table of 8-bit sines with an amplitude of 127. It is shorter than the 75-byte published in BORNDEAD procedures for creating unsigned sines. LD HL,SINTAB-1 ;data table LD DE,SINUS+255;sine table ;SINUS=#xx00 LD BC,#03FD;B=-C=difference of the first two ;values of the original table of sines. INS INC E ;calculate new value LD A,E AND 3 ;check for end of byte JR NZ,$+3;data tables INC HL ;go to new byte XOR A ;took increment RLC (HL) ;differences RLA ;from RLC (HL); tables R.L.A. DEC A ;now increment=-1..+2 ADD A,B ;added it to the current one LD B,A ;differences ADD A,C ;and to current value LD C,A ;sine LD (DE),A; included in the first quarter PUSH DE LD A,#80 SUB E LD E,A LD A,C LD (DE),A;in the second quarter SET 7,E N.E.G. LD (DE),A;in the fourth quarter POP DE SET 7,E LD (DE),A;in the third quarter RES 7,E BIT 6,E JR Z,INS; end of procedure ... DEFB #55,#61,#55,#55 DEFB #49,#52,#48,#86 DEFB #15,#55,#49,#18 DEFB #58,#49,#48,#61,#55 Length of procedure with table: 51+17=68 bytes Based on this algorithm, you can build a program that createstable of tangents for angles from 0 to 31 degrees (in the Wolf-like part of MALADY 4k intro by MEGUS/BW/XPJ this is the procedure used, though slightly simplified for getting unsigned values) or any table another function whose second derivative is in the interval [-1..2], although, strictly speaking, the concept of derivative is not applicable to discrete sequences. The word "second derivative" should be understood difference in function increments. Alternative output of Chunks. The method for outputting chunks published in BORNDEAD#5 is undoubtedly very cool (80 bars for 2 chunky), but has two drawbacks: size 16 kilobytes and, therefore, the practical impossibility of outputting to 2 screens. The method I propose is based on BORNDEAD's, but takes 8 kilobytes, which means he can calmly sit in page 7 and throw data in #c000 and #4000. Maximum time of one cycle: 82 cycles, the minimum is 70 (!) clock cycles for a couple of chunks. Chunky have even numbers from #e0 to #fе. To work you need to prepare on page 7 the following: #E070: LD H,A LD (HL),#XX;3 INC H ;times LD (HL),#XX INC L RET #E07E: ... ;similar #E0E0: JR #E070 JR #E07E ... #E0EE: JR #E0D2 JR #E100 JR #E10E ... #E0FE: JR #E162#E100: LD H,A LD (HL),#XX;3 INC H ;times LD (HL),#XX INC L RET #E10E: ... ;similar Well, you get the idea. Instead of #XX you need to put a byte, corresponding to the string of the output pair chunk'ov, and, instead of LD (HL), #XX with set #XX to certain values the following: #XX=#00 => LD (HL),B #XX=#FF => LD (HL),C #XX=#AA => LD (HL),D #XX=#55 => LD (HL),E The conclusion is as follows way: c2pout: ld (STK+1),SP ld hl,screen_addres LD SP,CHSCR;CHUNKY SCREEN LD BC,#00FF LD DE,#AA55 RET C2PRT LD HL,C2PRT PUSH HL STK LD SP,0 RET In CHSCR, at the end of each line there is the address of the following pieces of code: ld a,h add a,NN ;NN - the difference between the high bytes of the addresses of the (n+1)-th and n-th lines in the screen ld l,MM ;MM - ml. address byte of the beginning of the next line ld sp,address of the next line in chunky buffer ret Place the C2PRT address at the end of the chunky buffer. Procedure for finding the greatest common divisor of two numbers (maybe will it be useful for anyone): ;input:HL,DE - two numbers not equal to zero ;output: DE - max. common divisor. FIND_NOD JR NO1 NOT ADD HL,DE EX DE,HL NO1 OR A NOD SBC HL,DE JR C,NOT JR NZ,NOD RET I wish you health, happiness and creative Uzbeks. Aleksey Malov aka VIVID/Brainwave.