IzhNews #0C
31 июля 2001 |
|
Nonsense - the routine pointer with detailed explanations.
in basic ... (C) Pix / BrC Izhevsk you once again main coder of Brutal Creators (forgive me Noviset). Today, I will fail to theme building cursor. Of course, I did not spec in this area, and if you need a cool and fast pointer, it is that you read the counter. If you poboku escarpment, then read on. Behold, now there were only those who are not find articles on a cursor, or those who are guided by the principle of "if only to sing, and also those who are not very steep in the codes and wants to understand how the STE it, damn it, it works. For the latter, and wrote this article. I'll start with the problems arising from the most beginerskih coders. Often the first handwritten cursor disappears top of the Scrin, or begins to flicker. I'll try to explain what is happening. For this we consider the principle of construction images on the screen. As we know, there is a wonderful event 50 times per second, immediately after the arrival interrupts. The cursor is usually constructed to handle the interrupt, thus cursor and images are constructed simultaneously. The procedure for processing interrupt occurs approximately the following: a) restore the image under the old cursor (erase it); b) store the image in a new position; c) construct a new cursor; Thus we must do all 3 points to such time as the video controller builds image above the cursor position (old and new). Typically, the braking procedure no time to draw up a new cursor the point where its location starts is displayed on the monitor, so we it and do not see. Hence the rule: to build a new cursor, until the Border is drawn, and it requires a relatively fast procedure. <Much the same can be read the ZF # 3>. Well, pristipim: BEGXP EQU 184; initial coordinates BEGYP EQU 0; y = 184 x = 0 XY_KOOR DB BEGXP, BEGYP; current coordinates. Our procedures have to be quick, For all the complex (brake) calculations sdelaem once. For example, Sprite print up to a pixel can only y-ku, and the x step discrete (8pix). But we need to print both y, and the x with the same accuracy of 1 pixel. To do this, move the sprite on the number of pixels equal to the remainder of the division by 8. ie if x = 10, p = x% 8 = 2, then you need to move sprite 2 piskela right, and then print it in the position x / 8 (char), y (pixel). This can be done in the printing process, but it will be slow, therefore we make to our original sprite another 7 obrazovnnyh from it by the shift. They are something we'll use in the process of withdrawal. This entire mutenyu will deal with initialization procedure: INIT_CUR; proper initialization procedure cursor. LD A, BEGXP LD (XY_KOOR), A LD A, BEGYP LD (XY_KOOR +1), A Create a table of addresses for quick screen printing Y. To do this, will go to all line from 0 to 192 and write the address of their beginnings in Tabl_adr. INT_TAB LD DE, # 4000; top display area LD HL, TABL_ADR; HL = address of table LD B, 192; number of rows INT_TB1 LD (HL), D; enters the address of the string, which INC HL; in DE. LD (HL), E; .. INC HL; .. CALL DOWN_DE; calculate the address of the next line DJNZ INT_TB1; will go to all the rows. Now create the sprites, as mentioned above. At the same time mixing it with mask. LD HL, SUR_CUR; original sprite LD DE, CURSPR; there will be slipping. LD BC, 32; length of a sprite with a mask LDIR; first - offset # 00 INT_SPR LD B, 8; like the number of new Sprite. LD DE, NEW_SPR; new sprite written. INT_SP0 PUSH BC; for the cycle:) LD HL, CURSPR; beginning Sprite LD IX, CURSPR +16; top of the mask LD B, 16; length of Sprite or masks INT_SP1 LD A, (IX); take the mask LD (DE), A; put where it is necessary INC DE; seq. ale. LD A, (HL); take Sprite LD (DE), A; Kalda. INC DE; seq. INC HL; sled.spr. INC IX; neht.mask. DJNZ INT_SP1; well, a cycle like that. That, mixed with sprite mask now have a Sprite with a mask in the format mask Sprite mask, Sprite ... offset # 00.Teper will move. LD HL, CURSPR; outcome for the displacements. LD B, 8; height, such as INT_SP2 LD A, (HL); take OR A; cy = 0 RRA; -> LD (HL), A; we put in place INC HL; seq. LD A, (HL); take the second byte of Sprite RRA; -> LD (HL), A; put INC HL; further DJNZ INT_SP2; and so on ... LD HL, CURMASK; LD B, 8; INT_SP3 LD A, (HL); Tozha thing for masks SCF; cy = 1 RRA; -> LD (HL), A; INC HL; LD A, (HL); RRA; LD (HL), A; INC HL; DJNZ INT_SP3; with masks all ... POP BC; DJNZ INT_SP0; seq. displacement trace. Sprite LD A, # 37; LD (CUR_PR), A; some presets JP PR_CUR_; well and everything installs completed, there will be ; Trolled first kurosr. DOWN_DE INC D; percent address calculation followed by a string LD A, D; from the previous address. Standard. AND 7 RET NZ LD A, E ADD A, # 20 LD E, A RET C LD A, D SUB 8 LD D, A RET Now the routine cursor. Here, like, it's simple: a little mathematics, very little. No stack output. Speed is reached no shift spritov.Zdes same familiarity percent recovery under the old cursor. I think, figure it out, I'm lazy ... :) PR_CUR LD A, 0 LD B, 0 LD C, A SLA C RL B LD HL, TABL_ADR ADD HL, BC LD D, (HL) INC HL LD E, (HL) PR_CUR0 LD A, 0 SRL A SRL A SRL A ADD A, E LD E, A JR NC, PRCO INC D PRCO LD HL, SPR_BUF LD B, 8 PRC__ LD A, (HL) INC HL LD (DE), A INC DE LD A, (HL) LD (DE), A DEC DE INC HL CALL DOWN_DE DJNZ PRC__ WOST_PR OR A RET C PR_CUR_ LD A, (XY_KOOR) LD (PR_CUR +1), A LD B, 0 LD C, A SLA C RL B LD HL, TABL_ADR ADD HL, BC LD D, (HL) INC HL LD E, (HL) LD A, (XY_KOOR +1) LD (PR_CUR0 +1), A SRL A SRL A SRL A ADD A, E LD E, A JR NC, PRC0 INC D PRC0 LD A, (XY_KOOR +1) AND 7 LD BC, NEW_SPR LD H, 0 LD L, A ADD HL, HL ADD HL, HL ADD HL, HL ADD HL, HL ADD HL, HL ADD HL, BC LD IX, SPR_BUF LD B, 8 PRC1 LD A, (DE) LD (IX), A INC IX AND (HL); MASK INC HL XOR (HL); CUR INC HL LD (DE), A INC DE LD A, (DE) LD (IX), A INC IX AND (HL); MASK INC HL OR (HL); CUR INC HL LD (DE), A DEC DE CALL DOWN_DE DJNZ PRC1 RET Well, load spritik cursor and mask. SUR_CUR LCODE "CurSpr22.C"; fixed line noatr (sm5.11) What?! Long time no see so miserable code? Wait, is not a write! After we do not mind? Well, okay, all puhnite and write four-thread, any thread can Wikipedia to nonsense, and it'll only read my people delirium.
Other articles:
Similar articles:
В этот день... 21 November