Deja Vu #05
31 мая 1998 |
|
CODING - Procedures: FULL SCREEN SCROLL UP, broken TV.
SoundTrack: SECTOR / SERIOUS SPECCY GROUP'98 __________________________________________ (C) Kolotov Sergei, SerzhSoft, may, 1998. __________________________________________ Again OPTIMIZATION Great and Terrible The leader of the Samara Hacker M.M.A aka UnBeliever, with a smile. The fourth issue Deja Vu readers could familiarize themselves with Article MMA, devoted gap optimizatsii.Bes k controversial, Maxim raised J k is very good topic and k quite interested in all F k opisal.Napomnyu that it k was to create protseduB k algebra fast scrolling [Total screen up. K l [article includes research [Hodnik program in the form D [a new tough material ac [Sembler STORM.Deystvi [Indeed, it is quite And [the place, and most Ji [important - _ochen_ bys `[Try ASM. But ... Personally to me he is not attracted. Although this is a purely subjective opinion. Just I'm not used to the "cobbled together" mnemonic, when the command and operands are separated by only a single space ... And so, the guys from X-TRADE just rock! I advise everyone to try in kodit on STORM'e, it's cool! If DARK and LD still would have done the normal mnemonic, I did not hesitate for a long time to storm'il! Because This assembly has not yet received a fairly wide distribution, it certainly is not all managed to find the source of the procedure MMASledovatelno, it would be good to publish it in "normal" text that we now do ... ;-------------------------------------; ABSOLUTLY COOL LDI SCROLL ; COMPLITLY CODED BY M.M.A ;------------------------------------- ORG # 8000 CALL INSTAL; Building a table ; Display addresses LD HL, # C000, DE, # 4000, BC, 6144 LDIR; The transfer to the screen ; Loaded at address # C000 ; Pictures ;-------------------------------------; 192 times call the procedure shifts ; The screen up one line ;------------------------------------; LD B, 192 LOO PUSH BC DI CALL ONELINE EI: HALT; can be removed to obtain uniform "twitches" of strings. POP BC DJNZ LOO RET; / ;------------------------------------ INSTAL LD HL, # 4000; This installer LD B, 192; addresses can be LOOP2 CALL DOWNHL; make faster PUSH HL; but why? METK3 LD (TABL), HL; LD HL, (METK3 +1) INC HL INC HL LD (METK3 +1), HL POP HL DJNZ LOOP2 RET ;-------------------------------------; Procedure itself upward shift on the line ;------------------------------------- ONELINE LD (METK2 +1), SP; 20 LD BC, 6144 - # 20, 10 LD HL, # 4000; 10 LD (METK1 +1), HL; 16 LD HL, TABL; 10 LD (METK4 +1), HL; 16 METK4 LD SP, 0, 10 (B) POP HL; 11 (C) LD (METK4 +1), SP; 20 (E) METK1 LD DE, 0, 10 (F) LD (METK1 +1), HL; 16 (O) .32 LDI; 16 * 32 () JP PE, METK4; 10 (578) LD SP, # 5800, 10 .16 PUSH BC; 11 * 16 METK2 LD SP, 0, 10 RET; TOTAL 110,682 CTTA ; ++++++++++++++++++++++++++++++++++++ ; + + ; + "DOWN HL" SUBROUTEN FROM MASM1.1 + ; + + ; ++++++++++++++++++++++++++++++++++++ ; ; For a quick all transitions JR on the team ; RET replaced with actual RET NZ, RET C DOWNHL INC H; 4 LD A, H; 4 AND 7, 7 RET NZ; 5 / 11 LD A, L; 4 ADD A, 32; 7 LD L, A; 4 RET C; 5 / 11 LD A, H; 4 SUB; 8 7 LD H, A; 4 RET; 10 TOTAL 55 TABL And now some comments ... Carefully looking closer, you will notice that bars here and there counted wrong ... First, the team POP HL is not 11 but 10 tick! And secondly, this command does not seem at all taken into account! Indeed, in the cycle (where else it says "TOTAL - 578") total instruction execution time is not 578 cycles, as indicated, and all 588! A total run time is much more marked: 82 +112308 +196 = 112586 tick! As much as much as 2,000 policy makers at the top! So, check out a program, let's try to optimize it, or better yet - write at all from scratch! Will not you long tormented by their rhetoric see and understand: ;--------------------------------------; ; FULL SCREEN SCROLL UP; ; Coded by Kolotov Sergey; ; (C) SerzhSoft, Shadrinsk, may, 1998; ;--------------------------------------; _NULL EQU 0 ;--------------------------------------; _DATA EQU # 6000 SCR_TBL EQU _DATA;, # 0300 DATAEND EQU SCR_TBL + # 0300 ;--------------------------------------; ORG # 8000 ;--------------------------------------; MAINPRG EI ; CALL MK_STBL ; CALL MKSRLUP ; LD HL, # 0000 LD DE, # 4000 LD BC, # 1800 LDIR ; LD B, # C0 LP_MAIN PUSH BC HALT DI CALL SRL_UP EI POP BC DJNZ LP_MAIN ; RET ;--------------------------------------; MK_STBL LD HL, SCR_TBL LD DE, # 4000 LD B, # C0 LP_MSTB LD (HL), E INC HL LD (HL), D INC HL ; INC D LD A, D AND # 07 JR NZ, $ +12 LD A, E ADD A, # 20 LD E, A JR C, $ +6 LD A, D SUB # 08 LD D, A ; LD (HL), E INC HL LD (HL), D INC HL DJNZ LP_MSTB ; RET ;--------------------------------------; MKSRLUP LD HL, SRL_UP LD (HL), # ED; ld (...), sp INC HL LD (HL), # 73 INC HL PUSH HL INC HL INC HL LD (HL), # 01; ld bc, ... INC HL LD (HL), # E0 INC HL LD (HL), # 17; ld bc, # 17E0 INC HL LD (HL), # 31; ld sp, ... INC HL LD DE, SCR_TBL LD (HL), E INC HL LD (HL), D; ld sp, SCR_TBL INC HL PUSH HL; lp_srup LD (HL), # D1; pop de INC HL LD (HL), # E1; pop hl INC HL LD B, # 20 LP_MSU1 LD (HL), # ED; ldi INC HL LD (HL), # A0 INC HL DJNZ LP_MSU1 LD (HL), # EA; jp pe, ... INC HL POP DE LD (HL), E INC HL LD (HL), D; jp pe, lp_srup INC HL LD (HL), # 31; ld sp, ... INC HL LD (HL), B; # 00 INC HL LD (HL), # 58; ld sp, # 5800 INC HL LD B, # 10 LP_MSU2 LD (HL), # C5; push bc INC HL DJNZ LP_MSU2 LD (HL), # 31; ld sp, _NULL INC HL EX DE, HL POP HL; ld (...), sp LD (HL), E; ^ ^ ^ INC HL LD (HL), D EX DE, HL INC HL INC HL LD (HL), # C9; ret RET ;--------------------------------------; _CODE EQU $ SRL_UP EQU _CODE;, # 0066 CODEEND EQU SRL_UP + # 0066 ;--------------------------------------; A couple of words about the program ... As you can see all written in traditional style "realtime - programming ", a feature which is to create a real-time fast running, large-scale procedures. In this case - is generated by high-speed procedure shift the entire screen to the line up (SRL_UP). For this procedure is called MKSRLUP, the transmission control is in the segment of additional code, "we get something like: SRL_UP LD (SP_SRUP +1), SP; 20 LD BC, # 17E0; 10 LD SP, SCR_TBL; 10 ; LP_SRUP POP DE; 10 (ALL) POP HL; 10 (542) .32 LDI; 16 * 32 (*) JP PE, LP_SRUP; 10 (191) ; LD SP, # 5800, 10 .16 PUSH BC; 11 * 16 ; SP_SRUP LD SP, _NULL; 10 RET ; TOTAL: 40 + 103 522 + 196 = 103 758 cycles! MK_STBL procedure creates a segment data plate screen addresses SCR_TBL, occupies 768 bytes. Since the load of a screen is not very convenient (and, still need to locate a suitable! :-)), it was decided copy to screen the standard present in all computers picture placed in ROM at address # 0000. :-) It's called - "CHAOS", although some authorities insist on a different title, namely "Broken TV! Well nevazhno.Glavnoe that the effect of scrolling is very good visible and thus seen quite well - exactly where the beam scanning the screen "surpasses" our procedure ... The program takes only 147 bytes! If you are ready to donate more amounts of memory, the speed can still improve ... Then the program will change a bit: ... ;--------------------------------------; LNS_NUM EQU # 40 ;--------------------------------------; ... ;--------------------------------------; MKSRLUP LD HL, SRL_UP LD (HL), # ED; ld (...), sp INC HL LD (HL), # 73 INC HL PUSH HL INC HL INC HL LD (HL), # 01; ld bc, ... INC HL LD (HL), # E0 INC HL LD (HL), # 17; ld bc, # 17E0 INC HL LD (HL), # 31; ld sp, ... INC HL LD DE, SCR_TBL LD (HL), E INC HL LD (HL), D; ld sp, SCR_TBL INC HL LD (HL), # C3; jp ... INC HL LD D, H LD E, L LD BC, # 0042 2 ADD HL, BC EX DE, HL LD (HL), E INC HL LD (HL), D; jp lp_srup + # 0042 INC HL PUSH HL; lp_srup LD C, LNS_NUM LP_MSU0 LD (HL), # D1; pop de INC HL LD (HL), # E1; pop hl INC HL LD B, # 20 LP_MSU1 LD (HL), # ED; ldi INC HL LD (HL), # A0 INC HL DJNZ LP_MSU1 DEC C JR NZ, LP_MSU0 LD (HL), # EA; jp pe, ... INC HL POP DE LD (HL), E INC HL LD (HL), D; jp pe, lp_srup INC HL LD (HL), # 31; ld sp, ... INC HL LD (HL), B; # 00 INC HL LD (HL), # 58; ld sp, # 5800 INC HL LD B, # 10 LP_MSU2 LD (HL), # C5; push bc INC HL DJNZ LP_MSU2 LD (HL), # 31; ld sp, _NULL INC HL EX DE, HL POP HL; ld (...), sp LD (HL), E; ^ ^ ^ INC HL LD (HL), D EX DE, HL INC HL INC HL LD (HL), # C9; ret RET ;--------------------------------------; LN_SRUP EQU LNS_NUM * # 0042 + # 0027 ;--------------------------------------; _CODE EQU $ SRL_UP EQU _CODE;, LN_SRUP CODEEND EQU SRL_UP + LN_SRUP ;--------------------------------------; As you see, has changed the procedure MKSRLUP, which generates the now much more volumetric procedure SRL_UP: SRL_UP LD (SP_SRUP +1), SP; 20 LD BC, # 17E0; 10 LD SP, SCR_TBL; 10 JP LP_SRUP + # 0042, 10 ; LP_SRUP POP DE; 10 POP HL; 10 .32 LDI; 16 * 32 ... POP DE; 10 TOTAL POP HL; 10 LNS_NUM .32 LDI; 16 * 32 times ... / POP DE; 10 / POP HL; 10 / .32 LDI; 16 * 32 / ; JP PE, LP_SRUP; 10 ; LD SP, # 5800, 10 .16 PUSH BC; 11 * 16 ; SP_SRUP LD SP, _NULL; 10 RET Constant LNS_NUM determines the number of lines of the screen, which are copied in one iteration cycle. Thus, when LNS_NUM = 64 (# 40) total time of the procedure is calculated as follows: 50 + ((532 * 64 +10) * (192/64) -532) + 196 = = 246 + 101642 = 101888 cycles. Thus, the win was in 1870 cycles, which, of course, not so much. Rather, from this you have to understand themselves principles of optimization of the program on time Implementation and use them where necessary and where there is no need! Finally, I want to still see that In any case, for the transfer of large amounts of data faster than most satisfied program, working with the stack. Perhaps The next article is really about and talk. In the meantime, try to understand yourself ... Good luck! With best wishes Serzh.
Other articles:
Similar articles:
В этот день... 21 November