Adventurer #07
31 января 1998 |
|
Exchange of experience - Quick procedure line.
(C) Yevgeny Veselov (VEKA / CPU) (C) Music ALOS jnr. / Spark Rapid procedure line. I present to you two programs draw a line, running faster than located in ROM. The first of them - to set point, invoke an external routine that you can use it to display any objects. The coordinates of the end of the line are given in registers HL and DE (E and L - x, D and H - y). LINE LD A, H; calculation of displacements SUB D JR NC, LINE1 EX DE, HL; line is drawn from the bottom up NEG; change in sign of bias LINE1 LD H, A; H = dy = y2-y1 LD A, L SUB E LD BC, # 141C; INC D [# 14], INC E [# 1C] JR NC, LINE2 INC C; if x1 <x2 then DEC E [# 1D] NEG; change in sign of bias LINE2 CP H LD L, A; L = dx = x2-x1 JR C, LINE3; if dxdy LD H, A LD A, B; replacement INC D <-> INC / DEC E LD B, C LD C, A LINE3 LD A, B; code modification LD (LINE5), A LD A, C LD (LINE6), A LD B, H; number of points in line LD A, H INC L INC B LINE4 CALL PLOT; installation point LINE5 NOP ; Change coordinates with a large displacement ; Direction depends on the sign of the bias SUB L JR NC, LINE7 LINE6 NOP ; Change coordinates with a smaller displacement ADD A, H LINE7 DJNZ LINE4 RET IN PLOT must be maintained following Registers: HL, DE, B, A. Coordinates are in register DE (E = x, D = y). The next program is similar to the previous one, but works directly with address of the display file. Also, instead of samomodifitsirueschegosya code used parts of the program for each of the four directions. Due to this significantly increases the speed, and more length ;-). And where are the four directions? Have a look at the line after the first JR. See EX DE, HL? Now look at the picture. If D (y1)> H (y2), then the line should be drawn from top to bottom (lines 5 .. 8 on the figure), but it runs EX DE, HL, and all line drawn from the bottom up (Both lines 1 .. 4). All this applies to the first procedure line. If you want the line has always been in a given direction, then you will have to redo the initial block of the program (calculation of bias) or write to Editor, and will be published an amended version. Another important point: in the second procedure, the display address is calculated once before the withdrawal line (see the four locations CALL GET_ADR). Coordinates are specified in register DE, and the results of calculation entered in the register HL (e) and C (mask) and you can use all the registers. Most importantly, the origin for This should be at the bottom of the screen (note the second and third lines in the procedure GET_ADR). LINE LD A, H SUB D JR NC, LINE1 EX DE, HL NEG LINE1 LD H, A LD A, L SUB E JR NC, LINER NEG CP H LD L, A JR C, LINELU PUSH HL CALL GET_ADR POP DE LD B, E LD A, E INC D INC B EX AF, AF ' LINELD1 LD A, (HL) OR C LD (HL), A RLC C JP NC, LINELD2 DEC L LINELD2 EX AF, AF ' SUB D JR NC, LINELD4 ADD A, E EX AF, AF ' LD A, H DEC H AND 7 JP NZ, LINELD3 LD A, L SUB # 20 LD L, A JR C, LINELD3 LD A, H ADD A, 8 LD H, A LINELD3 DJNZ LINELD1 RET LINELD4 EX AF, AF ' DJNZ LINELD1 RET LINELU PUSH HL CALL GET_ADR POP DE LD B, D LD A, D INC E INC B EX AF, AF ' LINELU1 LD A, (HL) OR C LD (HL), A LD A, H DEC H AND 7 JP NZ, LINELU2 LD A, L SUB # 20 LD L, A JR C, LINELU2 LD A, H ADD A, 8 LD H, A LINELU2 EX AF, AF ' SUB E JR NC, LINELU3 ADD A, D RLC C JP NC, LINELU3 DEC L LINELU3 EX AF, AF ' DJNZ LINELU1 RET LINER CP H LD L, A JR C, LINERU PUSH HL CALL GET_ADR POP DE LD B, E LD A, E INC D INC B EX AF, AF ' LINERD1 LD A, (HL) OR C LD (HL), A RRC C JP NC, LINERD2 INC L LINERD2 EX AF, AF ' SUB D JR NC, LINERD4 ADD A, E EX AF, AF ' LD A, H DEC H AND 7 JP NZ, LINERD3 LD A, L SUB # 20 LD L, A JR C, LINERD3 LD A, H ADD A, 8 LD H, A LINERD3 DJNZ LINERD1 RET LINERD4 EX AF, AF ' DJNZ LINERD1 RET LINERU PUSH HL CALL GET_ADR POP DE LD B, D LD A, D INC E INC B EX AF, AF ' LINERU1 LD A, (HL) OR C LD (HL), A LD A, H DEC H AND 7 JP NZ, LINERU2 LD A, L SUB # 20 LD L, A JR C, LINERU2 LD A, H ADD A, 8 LD H, A LINERU2 EX AF, AF ' SUB E JR NC, LINERU3 ADD A, D RRC C JP NC, LINERU3 INC L LINERU3 EX AF, AF ' DJNZ LINERU1 RET Here are some routines of calculation address in the screen and set the point used when drawing lines (set point is needed only for the first procedure). PLOT PUSH HL; installation point PUSH DE EX AF, AF ' CALL GET_ADR OR (HL) LD (HL), A EX AF, AF ' POP DE POP HL RET GET_ADR LD A, # BF; calculation of addresses in the screen SUB D LD D, A SRL A SCF RRA SRL A XOR D AND # F8 XOR D LD H, A LD A, E RLCA RLCA RLCA XOR D AND # C7 XOR D RLCA RLCA LD L, A LD A, E AND 7 INC A LD C, B; preserving B LD B, A LD A, 1 GETADR1 RRCA DJNZ GETADR1 LD B, C; restore B LD C, A; mask c RET These routines are only for example. In practice, the better to insert address calculation and installation point directly into the line and used to calculate the table (see ZX-Format N7, "Coding for Beginners"). In the Appendix you will find the source these procedures (LINE1 and LINE2).
Other articles:
Similar articles:
В этот день... 21 November