Deja Vu #03
31 декабря 1997 |
|
Coding - The procedure of the "floating attributes.
Author: Sergey Kolotov, SerzhSoft __________________________________________ FLOATING ATTRIBUTES Behold the codes. Kuzma Fes'kov If all the distinguished Sir Clive Sinclair, after a Speccy would have seen For example, boot with Enlight'96, he probably would not believe his eyes. And how would He was still able to react if his child with attributes that are tightly tied to familiarity, suddenly, "spits the high mountains on All these zamorochki and begins to move attributes as he only likes ... Like all guessed it - we are talking about Floating-colored inscription "Enlight", consisting of colored squares the size of one of familiarity. Of course, after some during the Great Sir surely would have guessed "Where's the dog fumbled. The thing is that, along with the change of attributes, of work with the graphical information that is visible picture is collection of graphics and all those same attributes. For example, it is necessary to derive the black screen box with a red X-coordinate 5 (in pixels). In this case, work will involve two familiarity. In the first we establish familiarity Color INK equal to 2 (red) and zabem eight graphic byte with a value % 00000111. As a result, we obtain some desired us square in red, beginning with a 5 pixel and a length of 3 pixels. Now we will work with the second familiarity. Here we have the opposite color instead INK Place the red PAPER, but the schedule also fill byte% 00000111. Unincorporated pixels have the color of PAPER, and finally we obtain the missing part of the shifted square width of 5 pixels. Here we painted red square the size of a single familiarity. To add to it, For example, the right one, say green, we will do so: The second change the color of familiarity INK to green (4) - that's half the work already done. Third, familiarity again zabem byte% 00000111, and set it in color PAPER = 4. That's it! Thus, it is possible to derive an algorithm to fill a line of "shifted" to Distance X (in pixels) of attributes: 1. Calculates the bytes of graphics, in which will be included (8-( x mod 8)) the right bits. 2. This byte fill the entire line of familiarity screen (32 characters). That is already scheduled, and brought ... 3. Attributes will be output with (x div 8) position. Moreover, each attribute will two colors: INK - the color of this "square" and PAPER - the color of the previous one. In the the first attribute to set the color PAPER - background color (eg, 0), because previous something he does not. Note. The operation "mod" - taking the remainder of the division, and "div" - integer division. There is another "but." The whole range attributes of brightness at each of them must be the same. That is, or at all - BRIGHT 1, or - BRIGHT 0. Otherwise, we get a distorted picture - one of the adjacent squares, which does not match the brightness, will be shown as two rectangles of one color, but with different BRIGHT'om! For better absorption of the material (these words do not evoke Do you have some memories!) let's look at podrobnenko specific program from the full screen showing the "swimming attributes. This program is just used one of the techniques of modern demomaking'a on the Speccy - Programming in realtime, as I argued in the preceding article. Indeed, in time to bring floating attributes the entire screen for one interruption, while leaving a few thousand cycles per player music - traditional methods can not do. Realtime-programming - that is what will save the us! To easily understand the software, you need to have a direct two texts: the program itself and its description. Better, of course, print them on printer (at least, the program), but it is not all, unfortunately, is available. The matter is complicated by the fact that the program listing is 64-character format, which is still DEJA VU in the journal have not met ... But believing in the steepness of coders (DANIIL, CARDINAL !!!), I hope that it will not create problems for them. The best solution problems would have been possible without the interference switch between two windows show (window article - 42 characters and a window listing of 64 characters), and stores the position text and there, and there ... I think that the 128 KB memory will not create any problems for this. And further it is useful for other papers. All the more so in other journals, this has not been (and if they pull?)! So, we turn to the description ... First we must define the addresses: where to have the code, where the data; which generates realtime'ovye procedure? So how we want our program to work and wheelbarrows on the brake, it means that all codes, we will have to sit in the second page of RAM, that is, addresses # 8000 (32768). Many programmers (and I belong to These included) always put the team in early direct transition at the beginning of the program (JP ...). Then there are constants, variables, data, finally ... And this, in my opinion, correctly. Indeed, in almost all languages programming at the beginning are descriptions of variables and only then is the program itself. Yes, and just convenient when the variables are always in sight, "and not necessary every time to strain the leaf search for the end of the program where they are, other time, sit! Still need to decide: where to have different tables, arrays, etc. We can proceed like this: Select memory address # 6000 to # 7fff for data and proudly call this area "segment of data. "Specifies constants _DATA, indicating the beginning of this" segment ", and now all the plates and arrays we adresovyvat using this pointer. Example: _DATA EQU # 4000 TRK_TBL EQU _DATA;, # 0100 SHF_TBL EQU _DATA + # 0100;, # 0100 Here, for convenience, in comments after the decimal point indicates the size of plaques or an array of ... Yes, if you dismantle the entire program in detail - not enough for a megabyte, so I highlighted only some of the procedures and the most important points. Will hope that the rest of you will understand themselves, relying on his knowledge and given comments ... Once launched, you'll have to wait about 15 seconds while waiting for the program will calculate the 256-byte table "sinus" displacements (TRK_TBL), on which, and will "float" attribute. The table is calculated using the procedure CALCTRK, in which not the least is the use of a calculator, which slows the calculation. Of course, it was possible to fill all at once, or 256 bytes in assembler or load file INSERT'om (INCBIN) ... But assignment of such plates by hand - it rather tedious, besides here, you can experiment with different values, substituting them in the process CALCTRK. For example, try replacing # 3f on any other number and see what happens ... By the way, I hope that the editors DEJA VU will find a way to embed start This program directly from the viewer Articles with the support of the music (with special attention to the third bit is the port # FD). Moreover, in this If, instead of calling CALCTRK need to have already calculated plate TRK_TBL, to not to bore readers. So, what happens after you run this program? On the screen you will see nice picture of the eight-floating attributes. It is possible to change the rate of "navigation" (the key '1'...' 0 ') and "style" (the key 'A' .. 'Z'). Feel free to experiment. You'll love it. On the curb you can see two bands: blue and red. They show the performance and the relative speed of the procedures graphics output (blue line) and attributes (red). This is done for emphasis visibility - you can estimate approximately how many processor cycles is each of the procedures and how long it remains free ... Perhaps a simple pattern you is not so interesting. It is possible to replace it on any of the images - 8 colors. For This procedure should be replaced by MAKESCR Transfer pictures to the ATR_SCR. The picture is of the format 48 * 24 points, each point - 1 byte with color INK. The lines are one behind another. RENDER procedure converts a normal picture (INK) in a format INK + PAPER for further use in the program ... RAMPAGE procedure produces output in Port # FD. Moreover, the full address of the port (# 7FFD) and, moreover, set the second bit of register A. This is done for preventive purposes - in the hope that Some lamer finally learn how to need to turn to port # FD and begin to carry out any of this ... Most important, in my opinion - is procedures and MAKE_FS MAKE_OA. These procedures, I would call the "virtual programmer"! They have a just and kodyat in realtime ... That is, generate the desired sequence of codes in the memory - the procedures and FILLSEG OUTATR2. On These procedures created and lay the responsibility for the rapid withdrawal of the image on the screen. Place reserved for them immediately after the last "normal" procedure (in this case, OUT_ATR). AND they have something just must be in the fast RAM - in page 2 (# 8000). For all the procedures generated we distinguish the so-called code segment, which is addressed label _CODE. A it is all caused by the procedure should be "repelled" is from this label. In short, as well as in _DATA. Of course, you can say: "Why us all the freaking segments, _DATA, _CODE! "Imagine that you need to link multiple effects, while sitting in memory, but working alternately. And we need to allocate space for each for data and additional realtime-codes. At all simply may not have enough memory, but if they will use the same area of memory, addressing them segment, then all must come out. And the clearer it will look ... The procedure creates MAKE_ST plate shifts of bytes of graphics. There are 8 such shifts: # FF, # 7F, # 3F, # 1F, # 0F, # 07, # 03, # 01. But the plate is 256 bytes - shifts are repeated. The table is created for accelerate the calculations and principle - not required. But then everything will slow down ... Procedure OUT_TRK displays graphic information shifted attributes, and the procedure OUT_ATR displays the attributes themselves. During the call, these procedures interruption in any case prohibited, as in OUT_TRK and OUT_ATR is working with stack, and if, for example, execution time exceeds the interval between interrupts, the bugs - are inevitable! I think you have decent "Download" and therefore I will call it a day. Read carefully the commentary to the program, understand, and better download the assembler and try to make any changes to the listing ... can then cool and you get ... If you do not become ill after reading this article and you want to know more about anything else that cool effect, for example, from best'ovyh megadem, then do not be lazy to write to the editor. That "order" effect, which receives the greatest The number of votes and will be considered next time. But manages, as release magazine do not wait! Author: Sergey Kolotov __________________________________________ ;----------------------------------------; ; FLOATING ATTRIBUTES; ; (C) SerzhSoft, Shadrinsk, 07.10.97; ;----------------------------------------; ORG # 8000; address assembles. JP MAINPRG; jump through ne variables at the beginning Lo ;----------------------------------------; _NULL EQU 0; used in change commands LAST_K EQU # 5C08; code down the fold. BANK_M EQU # 5B5C; copy port # FD STACK_A EQU # 2D28; entry of A to stack calculator FP_TO_A EQU # 2DD5; withdrawal number of stack of pa-in p-p A ;----------------------------------------; _DATA EQU # 6000; address segment ment data GOVERNMENTAL TRK_TBL EQU _DATA + # 0000, # 0100 - Table mp-torii Navigation SHF_TBL EQU _DATA + # 0100;, # 0100 - Table shifted ZN-places ATR_SCR EQU _DATA + # 0200;, # 0480 - col. ct Tinka 48 * * 24 points DATAEND EQU ATR_SCR + # 0480; end Segment Data ;----------------------------------------; TRK_UK DW TRK_TBL; Index "beginning la "trajectory STP_TRK DB 1; step change in the motion. on trajectory STP_SCR DB 6, a step change in output image ;----------------------------------------; MAINPRG; top of the head unit program EI; bit. prairie. LD A, # 17; selected 7 th page of RAM and done CALL RAMPAGE; see 0th eq wounds (the third bit in A) XOR A; A resets OUT (# FE), A; BORDER 0 LD HL, # 5AFF; further - LD (HL), A; clear the 0th eq wounds LD D, H; and starting LD E, L; since the last am ributa DEC E; and moving from above xy - down. LD BC, # 1AFF; it is necessary that would not arise PUSH BC; situation where schedule is LDDR; reset to zero and one hundred rye attributes POP BC; still "sit" on the screen. LD HL, # DAFF; similar eyes schaem LD (HL), A; the first screen of at LD D, H; with # c000, because we LD E, L; connect the 7-th page DEC E; where he is and we find reduces LDDR; it is on this address. CALL CALCTRK; calculation of trajectories theory of motion TRK_TBL CALL MAKE_ST; calculated shifts bytes SHF_TBL CALL MAKE_OA; creation Ave algebra output attributes CALL MAKE_FS; capacity-e pr-algebra filled. Segment scr. CALL MAKESCR; drew al ributnuyu car-ku CALL RENDER; and changed its as needed SET 3, (IY + # 30); caps-establish Vili mode zag Lavna letters ; LP_MAIN; main loop HALT; waited Interrupt (Ns of the beam) LD A, (BANK_M); and changed active and visible XOR # 0A; screen space mi, ie CALL RAMPAGE; "see one, and working with others " DI; ban interrupt th LD A, # 01; BORDER 1 OUT (# FE), A CALL OUT_TRK; derive the boundary crystallographic Institute formation LD A, # 02; set OUT (# FE), A; BORDER 2 CALL OUT_ATR; derive Atri butnuyu information mation XOR A OUT (# FE), A; BORDER 0 EI; permit limit closing the LD HL, STP_TRK; produce LD A, (TRK_UK); movement of trajectory ADD A, (HL); (modified pointer) LD (TRK_UK), A; with a given step GOM (STP_TRK) LD A, (LAST_K); took the code seq. down keys CP ""; if this code gap JR Z, EX_MAIN; then complete the work SUB "0" when pressed JR C, LP_MAIN; digital cluster Vishal CP # 0A; (ie '0'...' 9 '), JR NC, GO_MAIN; its value (No code) LD (HL), A; put in a ne belt STP_TRK JR LP_MAIN; the main cycle GO_MAIN SUB # 11, but if pressed JR C, LP_MAIN; any friend. key CP # 1A, then JR NC, LP_MAIN; respectively INC HL; puts the number of 0 .. 25 LD (HL), A; in cell STP_SCR JR LP_MAIN; stuck ... ; EX_MAIN; completion Work Goals Noah percent-algebra LD HL, # 2758; set register HL ' EXX; to correct Nogo output in BASIC, RET; that and you performs ;----------------------------------------; RAMPAGE; Connection page of RAM and a choice visible screen OR # 40; set 6, a-a insurance LD BC, # 7FFD LD (BANK_M), A; remembered with derzhimoe A in cell OUT (C), A; and gave it value Port # FD RET; exit from the procedure ; CALCTRK; calculation and populate the table trajectory LD HL, TRK_TBL; top Tabley particle trajectory LP_CTRK PUSH HL; store ad interest element Table LD A, L; number of elements that in the table CALL STACK_A; puts on stack tracing oscillator LD A, # 40; 1/4-aya width screen at the peak mudflows CALL STACK_A; placed there is RST # 28; calc DB # A3; stk_pi / 2 DB # 01; exchange DB # 05; divide DB # 04; multiply DB # 1F; sin DB # 38; endcalc LD A, # 3F; maximum deviation "Sine" CALL STACK_A; put on stack tracing oscillator RST # 28; calc DB # 04; multiply DB # 38; endcalc CALL FP_TO_A; shoot number from the stack Calculator pa JR Z, $ +4 ;-----> if number of positive Indeed NEG; a =- a | POP HL ;<---- v Vos rehydrating your e-ta LD (HL), A; (HL) = 63 * sin (L * 256/2/pi) INC L; the transition to seq. elements that table JR NZ, LP_CTRK; cycle calculation All 256 E-tam RET; output ; MAKESCR; establishment of demonstration Color Image 48 * 24 points LD HL, ATR_SCR; buffer address a picture LD C, # 18; height car Tinky: 24 LP_MS21 LD B, # 30, the width of car Tinky: 48 LP_MS22 LD A, B; compute SUB C; color point AND # 07; reject extra bits LD (HL), A; put INC HL; transition to seq. point DJNZ LP_MS22; spun Loop Columns DEC C; until the picture not finished las JR NZ, LP_MS21; twist cycle the lines RET; output ; RENDER; bringing images to the desired for the program note LD HL, ATR_SCR; address is located Proposition car roughcast LD C, # 18, height: 24 LP_REN1 LD E, (HL); have color first point INC HL; and moved to second LD B, # 2F; left - another 47 points LP_REN2 LD A, E; A = value previous color duschey point LD E, (HL); to E have brought color of the current point RLA; eventually RLA; all these RLA; operations we get: XOR E; color previous ing point-like PAPER AND # 38, and the value color of the current point XOR E; remained netsya color INK OR # 40; include bits Brightness LD (HL), A; here, a new value and calculated ... INC HL; move more DJNZ LP_REN2; twist cycle one line DEC C; continue work JR NZ, LP_REN1; until the transition doing everything line RET; exit from the procedure ; MAKE_ST; computation table shifts bytes Graphics LD HL, SHF_TBL; starting address table shift gov LP_MST1 LD A, # FF; primary value-all bits to 1 LP_MST2 LD (HL), A; put those kuschy element in table SRL A; shift bytes to the right, 7_bit = 0 INC L; the transition to next element RET Z; if the table ended - output OR A; if bytes is not full of nulen, JR NZ, LP_MST2; simply twist cycle JR LP_MST1; otherwise - again set all bits ; MAKE_FS; creates a procedure for filling in one segment of the screen LD HL, FILLSEG; starting address buffer under procedure LD C, # 10; height in value COMEST * 2 LP_MFS1 LD (HL), # 08; command code ex af, af ' INC HL; more ... LD (HL), # D9; command code exx INC HL; more ... LD A, # C5; to begin with Manda push bc LP_MFS2 LD B, # 10, all you need 16 teams to 1 line LP_MFS3 LD (HL), A; code of the current push instructions INC HL; next Team DJNZ LP_MFS3; total floor chile 1916 push ADD A, # 10, moved to next team push JR NC, LP_MFS2; and reiterated yet exist. such a k-hole DEC C; reduced meter semi series JR NZ, LP_MFS1; repeat 8 * 2 = 16 times LD (HL), # C3; command code jp ... INC HL; more ... LD DE, RT_OTRK; address "Return" of FILLSEG LD (HL), E; record in Bytes INC HL; settings to Manda jp LD (HL), D; and get in eventually jp RT_OTRK RET; exit from the procedure ; OUT_TRK; procedure for graphics output "Floating attributes" LD IX, (STP_SCR); record in the XL values of STP_SCR LD HL, # C000 + # 0800; final address first Vågå segment ment LD (SP_OTR1 +1), HL; paste the team LD SP, ... LD HL, (TRK_UK); pointer Table trajectory LP_OTRK LD D, SHF_TBL/256; starsh.bayt Address Table Litsa shift gov LD A, # 08; in the segment - 8 lines familiarity LP_PUSH EX AF, AF '; kept in alternative Otherwise AF ' LD E, (HL); value Table spectrum trajectory LD A, (DE); this shift Table shifts LD C, A; here and take bytes out LD B, A; and records reg-algebra C and B PUSH BC; and then this a couple of throws on stack LD A, XL; move ADD A, L; on the table trajectory LD L, A; to step in Register XL EX AF, AF '; the number of wasps tavshihsya string of characters places DEC A; subtract unit, and - until JR NZ, LP_PUSH; they do not con chilis - twist cycle LD (HL_OTRK +1), HL; remember Index trajectory POP BC; shoot POP DE; obtained POP HL POP AF; 8 values EX AF, AF '; trajectory EXX; from the stack POP BC; and put POP DE; all POP HL; working p-algebra POP AF; BC, DE, HL, AF , BC ', DE', HL ' , AF ' LD (SP_OTR2 +1), SP; remember system Decree-l Stack SP_OTR1 LD SP, _NULL; SP = e end segment is equivalent to wound JP FILLSEG; call cos Data Repository Procedure FILLSEG ; RT_OTRK; here we are "back" of the procedure FILLSEG team jp LD HL, # 1000, go to next ADD HL, SP; segment graphics screen LD (SP_OTR1 +1), HL; put in team Download SP SP_OTR2 LD SP, _NULL; recovered Vai systems Noe value Stack DEC HL; check: indicates whether Register HL LD A, H; end Segment screen ... HL_OTRK LD HL, _NULL; (restore Index trajectory CP # D8; ... or already time zakrug lyatsya? JR C, LP_OTRK; if we have in the screen, then run around RET; exit Procedure ; MAKE_OA; creates a procedure for the withdrawal of "floating" attributes on images LD HL, OUTATR2; buffer address under the procedure LD DE, # D800; starting address attribute is equivalent to wound LD B, # 18, total - 24 line Atri casks LP_MOA1 PUSH BC; kept on stack PUSH DE; DE used is later EX DE, HL; in DE - Address buffer under procedure LD HL, BL_MOA1; block address processing one line LD BC, LN_MOA1; the length of this code block ka LDIR; transfer EX DE, HL; on creating Dime piece Codes POP DE; fast O line LD B, # 10; attributes Th cut glass (16 * 2 = 32 b). LP_MOA2 LD (HL), # E1; command code pop hl-take 2 bytes INC HL; more ... LD (HL), # 22; ld (...), hl - Put to screen INC HL; more ... LD (HL), E; ml. Byte Hell rez on the screen (Atrib.) INC HL; more ... LD (HL), D; Art. Byte Hell rez on the screen (Atrib.) INC HL; more ... INC DE; moved to another INC DE; address in eq wound DJNZ LP_MOA2; spun cycle - the creation Is 16 pieces POP BC; restored row count DJNZ LP_MOA1; and spun cycle (24 line) LD (HL), # C3; command code jp ... INC HL; more ... LD DE, RT_OATR; address returns Create REC. pr-algebra LD (HL), E; put in Codes INC HL; address commands hole jp, sex tea LD (HL), D; Thus Thus the command jp RT_OATR RET; exit from the procedure ; BL_MOA1; block codes for the formation of Pr-algebra OUTATR2 - calculations LD A, (BC); took bytes bias Pictures CPL; proinvertiro Wali and fast rektirovali ADD A, # 48; - beginning with "0" instead of "-48" RRA; divide RRA; obtained RRA; number 8 AND # 1F; reject unnecessary high-order bits ADD A, E; added to top line Pictures LD L, A; attributes - ADC A, D; calculate the hell res SUB L; biased if SRI LD H, A; attributes - in HL LD A, E; Index ADD A, # 30, beginning LD E, A; current ADC A, D; line SUB E; translate LD D, A; the next LD A, XL; move ADD A, C; on the table "Navigation" LD C, A; offset in XL LD SP, HL; attributes will We shall withdraw from the stack LN_MOA1 EQU $-BL_MOA1; length of the floor chennogo block Codes ; OUT_ATR; procedure for deriving image attributes on the table on the screen LD (SP_OATR +1), SP; store system stack LD DE, ATR_SCR; address Atri butnoy car roughcast 48 * 24 LD BC, (TRK_UK); pointer Table the motion tion LD IX, (STP_SCR); XL = STP_SCR: step in Table chain motion JP OUTATR2; transition to created pr-py O ; RT_OATR; here is a "return" from the procedure OUTATR2 by jp SP_OATR LD SP, _NULL; recovered Vai systems LIMITED stack RET; exit from the procedure ;----------------------------------------; _CODE EQU $; top segment ment gene of the recorded Codes FILLSEG EQU _CODE + # 0000, # 0423 - for complement segment that is equivalent to wound OUTATR2 EQU _CODE + # 0423;, # 0873 - you water attributes Comrade Pictures CODEEND EQU OUTATR2 + # 0873; end additional Tel'nykh to Dov ;-----------------------------------------;
Other articles:
Similar articles:
В этот день... 23 November