Inferno #06
03 декабря 2004 |
|
For Coderz - Small programmers' tricks.
Etudes 1. Poll keys regardless of Caps Lock. Suppose you need to interview key "R". In battery already have some code down klavishi.No unknown state of Caps Lock. OR 32 CP "r" It was so done in ZXUnRar, while do not have to forcibly make LD (IY +48), 8 [Caps Lock on], and therefore mask file name can be entered, without switching system variables. Similarly, done check the file extensions and other identifiers that can be written in different registers. 2. Poll keys slightly shorter than standard. Normal polling cycle through 5, (IY +1) and variable 23560 (LAST_K) can be reduced: LD HL, 23560 LD A, (HL) LD (HL), H; symbol # 5C anyway ; Neklaviaturny ... And further validation of keys. The computer is ready to receive the next key. It is important for key scrolling, etc. (For convenience, scroll never forget to set the constants Keyboard REPDEL = # 5C09 and REPPER = # 5C0A. First it is desirable to equate to 15, the second - To 1.) 3. Checking the three-letter extension. Very korotkaya.Vyrabotana when optimizing ZXRar, she's in ACEdit: goodH3 PUSH AF CP "A JR NC, $ +3 LD A, B AND 32 ADD A, 65 LD L, A POP AF CALL etoAN JR C, goodH3N LD A, B CALL etoAN JR C, goodH3N LD A, H CP 32; 2sym CALL NZ, etoAN RET NC goodH3N LD B, 32, H, B RET etoAN CP "0 RET C CP ": CCF RET NC SUB L RET C ADD A, -26 RET Cause it with the following parameters: A, B, H - symbols of the expansion in order. On Output B and H or stored (if three-letter extension), or overwritten with spaces (if any single character). Criterion harder than Ivan Roshchina: for any "XAs" exclusion is not made, the name must include letters of one of a register and tsifry.Zapreschen tearing probel.Probel may be at the end (for a 2-character extensions). Names beginning with the digits may have a 2 nd and 3 rd marks the numbers or letters same registra.Imena, beginning no with tsifrobukvy, are single-character. 4. Move to TR-DOS disk. Virtually any system program You can insert a function to delete a file, it is among the standard Call # 3D13. A Move among the standard features there, but it You can call, then do not have to write and debug terrible algorithm. (No tune, he'll drive the source zaporet;)) MOVEDISK LD HL, MOVER, (EMCALL +1), HL LD C, H CALL eM3D13 LD HL, # 3D13, (EMCALL +1), HL JR prcREPR MOVER LD HL, 5806 PUSH HL LD A, H; -2 LD (# 5D15), A; NO MSG LD (# 5D1F), A; NO LDIR? JP 15663 In this type of procedure (5806, you know) is configured to use the driver processing oshibok.U me it is usually a (Does not support Retry / Abort / Ignore and do not always stable with No disk, input suppresses sound off and IM2, the output includes): eM3D13 LD (EMBC +1), BC LD (EMBC +4), DE LD (EMBC +7), HL LD (EMSP +1), SP CALL AYOFF; usual jammers AY EMREP LD DE, # 5C00, BC, # 400, HL, SYSBUF, SP, HL JR NZ, $ +3 EX DE, HL LDIR DRV LD A, 0, C, 1 CALL # 3D13 LD A, (DRV); PUSH: POP buggy in MOVE CP -1 LD ($ -1), A LD C, # 1918 CALL NZ, # 3D13 EMBC LD BC, 0, DE, 0, HL, 0 LD A, 7 CP C JR C, EMCALL LD A, 195, (23746), A EMCALL CALL # 3D13 EMLDIQ LD HL, (23796) PUSH HL LD DE, # 5C00, BC, # 400 LD HL, SYSBUF LDIR POP HL LD (23796), HL EMSP LD SP, 0 LD A, 201, (23746), A DI EMQq LD DE, IMTAB +256, A, IMER, (DE), A DEC D LD (DE), A INC E JR NZ, $ -2 LD A, D, I, A IM 2 OR A RET POPEMQ POP AF EMQ CALL EMQq EI RET ONERR EX (SP), HL LD A, L CP 8020 JR NZ, EMREP CALL 8020 JR NC, EMSP POP HL RET (In 23747 / 8 should already be addressed ONERR) Procedure to 4-kilobyte buffer between the address lying in STKEND (23,653 / 4), and register SP. Other subprogrammes TR-DOS (Eg, delete, and # 18) required a maximum of 257 bytes, not counting the stack. With a stack must be measured in each case as follows: at the end of BASIC area (required below STKEND, so you need to adjust STKEND) put some data, which safety check after the disk operations. When you find the minimum size stack, it is better to do over his stock in the 16 bytes, because depth of the stack in different versions TR-DOS is different. For example, ramdisku need a deeper stack, because it must determine the current page, and then turn it on back. 5. Random number in the right range. Suppose you have an algorithm for generating random number from 0 to 255. For example: [Cut] I wrote this: LD HL, (SEED) LD A, H AND 31 LD H, A INC H, L LD A, (HL) LD (SEED), HL You can instead INC H, L fit with the addition of anything or even multiplication of, say, 5, then slozhenie.Glavnoe, to make sure that repetition period was larger and the procedure not long walked in the close-mail addresses (there are consecutive zeros, or ff-ki, or text messagi). Probability numbers will be equal to their frequency in Rom. If you need a more even distribution, then: LD HL, (SEED) LD A, H AND 31 LD H, A INC L LD A, (HL) INC H RLCA XOR (HL) LD (SEED), HL And here is the procedure of Wolf2004, independent from memory (ie, completely predictable when transfer from computer to computer): LD HL, (SEED) LD B, H, C, L DB ")))) ADD HL, BC LD BC, 20981 ADD HL, BC LD (SEED), HL LD A, H But only a sequence of type color squares she does not generate. She was written for a single value. [End cut] To turn this number into a number, more or less uniform distribution between 0 and n-1, better not do so: LD C, n SUB C JR NC, $ -1 ADD A, C as well: ADD A, n JR NC, $ -2 In this council, and is. 6. Printing messages 8x8. Suppose we have a procedure for printing letters of 8x8. Very often trebuetsya.Naprimer, is as follows: PR88 PUSH DE, HL LD H, 0, L, A; if FNT is a multiple of 1024, DB ")))"; it is necessary to replace these LD BC, FNT; team on the classic ADD HL, BC; rlca: l, a, h, 'FNT / 4: db ")) LD B, 8 LD A, (HL), (DE), A INC L, D DJNZ $ -4 POP HL, DE INC E RET Actually, it can be printed letters of a different size. And we need to use it to print, for example, the menu in the window, and so that the text was smaller extra spaces and control codes. More precisely, that there was only one control code - 13 (Enter) and terminator - 0. Done as follows: PRTXTCR LD DE, 0 LD A, E ADD A, 32 LD E, A JR NC, $ +6 LD A, D ADD A, 8 LD D, A Behold here the procedure should be called PRTXT LD (PRTXTCR +1), DE PRTXT0 LD A, (HL) INC HL CP 1913 JR Z, PRTXTCR RET C CALL PR88 JR PRTXT Very convenient. When you call DE determines the address on the screen upper left corner of the window - the beginning Print. Each Enter (13) shifts the position Press down on the line, but strictly according to the same vertical, where he was the top-left corner of the window. 7. Register R. Add the number to less than 7 bits of register R, to correct the register After some delay, so you can: LD A, R RLCA ADD A, the number of * 2 RRCA LD R, A 8. Conditional compilation (continued). If you want to compile number equal to 0 if metka = 0, and 1 if metka <> 0 then do not: IFN metka metka = 1 ENDIF as well: metka = ~ metka <1 ~ '1 Where ~ metka understood as ALASM'om 0 ~ + metka, ie metka-1. (If interested, - ~ Metka, as well as the ~-metka, understood as-1-metka, and it's shorter to write in the form metka ~.) Comes in handy for creating logical variables that can be applied in difficult conditions such as IFN metka1'metka2. Thus, for example, made in ACEdit. A ZASM'ovskoe expression IFUSED replaced by IF ~? Label. And, again went talk about It then turns IFDEF IF? label, IFN in IF, and IF in the IFN. By the way, I recommend to save memory all the tables in the form DB # xx, # yy ... replaced by DD xxyy ..., and type of DW # xxyy, # zztt ... - By DD yyxxttzz ... PS: Vitamin told to write that comment on the pieces of the program is possible through an IF ... ENDIF. I personally use IFN 0 ... ENDIF. A. Coder
Other articles:
Similar articles:
В этот день... 21 November