Pl2 CORRIG 3.DOC
--------- EXERCISE CORRECTIONS on LineAs --------- 1) Exercise nr° 1: -------------- Here is the correction listing. I think this exercise didn't cause you much trouble, carefully look at this listing, it doesn't have any difficulty. TEXT INCLUDE "LINEQU.L" ;the EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;The macros SETBLOCK ;Initialization ;We search for the address of the internal Table for the LineAs DC.W $A000 ;return in a0 of the address ;of the internal table ;We drop the addresses of the VDI array tables in the internal table move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) PRINTLINE MOUSE ;text WAIT ;waiting lea INTIN,a6 ;address of INTIN in a6 move #0,6(a6) ;0 in intin+6 (mask color) move #1,8(a6) ;1 in intin+8 (foreground color) lea DATA,a5 ;address of 'DATA' in a5 move #31,d0 ;31 in d0 adda.l #10,a6 ;increment a6 by 10 units: ;a6 therefore points on intin+10 LOOP move (a5)+,(a6)+ ;we drop the data in ;the INTIN table pointed by ;a6 dbf d0,LOOP ;we loop 32 times for the ;32 data (16 words for the ;mask and 16 words for the ;foreground) DC.W $A00B ;TRANSFORM MOUSE move #0,intin ;counter=0 DC.W $A009 ;SHOW MOUSE PRINTLINE MESSAGE ;text WAIT ;waiting TERM ;end DATA MOUSE DC.B 27,'E','I change the shape of the mouse cursor...' DC.B ' mouse ...',0 MESSAGE DC.B 27,'E','Move the MOUSE please ...',7,0 DATA DC.W %0000001110000000 ;the 16 data (WORDS) DC.W %0000011111000000 ;of the MASK [...] (omission of repeated patterns) DC.W %0000001110000000 DC.W %0000000000000000 ;the 16 data (WORDS) DC.W %0000001110000000 ;of the FOREGROUND [...] (omission of repeated patterns) DC.W %0000000000000000 BSS INCLUDE "TABLEAU.L" ;the VDI table END 2) Exercise nr°2: -------------- Again, no major difficulty... It was just necessary to pay attention to using graphical coordinates that correspond to the used resolution. (OX)=640 from 0 to 339 (OY)=200 from 0 to 199 (MEDIUM resolution) TEXT INCLUDE "LINEQU.L" ;the EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;The macros SETBLOCK ;initialization DC.W $A000 ;we request the address of the T.I. and movea.l a0,a5 ;we put it in a5 because a0 might ;be modified by our MACROS... ; We place the addresses of the VDI arrays move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) PRINTLINE FRAME ;text WAIT ;waiting DC.W $A00A ;HIDE MOUSE CCONOUT #27 ;ESC CCONOUT #'E' ;+ 'E' = clear the screen move #1,_fg_bp_1(a5) move #1,_fg_bp_2(a5) ;color=%11=3 move #0,_wrt_mode(a5) ;Write mode AND move #1,_patmsk(a5) ;1+1=2 data for the PAT move.l #LINE,_patptr(a5) ;in 'LINE' is ;the new PAT move #%1111111111111111,_ln_mask(a5) ;solid LINE move #0,d5 ;0 in d5 move #22,d6 ;22 in d6 LOOP move #0,_x1(a5) ;_x1=0 move d5,_y1(a5) ;_y1=d5 move #630,_x2(a5) ;_x2=630 move d5,_y1(a5) ;_y2=d5 add #9,d5 ;we add 9 to d5 DC.W $A004 ;and we draw the H-LINE dbf d6,LOOP ;we repeat 23 times move #0,d5 ;0 in d5 move #42,d6 ;42 in d6 LOOP move d5,_x1(a5) ;_x1=d5 move #0,_y1(a5) ;_y1=0 move d5,_x2(a5) ;_x2=d5 move #197,_y2(a5) ;_y2=197 add #15,d5 ;we add 15 to d5 DC.W $A003 ;and we draw the LINE dbf d6,LOOP ;we repeat 43 times WAIT ;waiting TERM ;end DATA LINE DC.W %1111111111111111 ;the PAT (EVEN DC.W %1111111111111111 ;number of WORDS) FRAME DC.B 27,'E','I am going to draw a grid ...' DC.B 13,10,'Functions LINE and H-LINE:',0 BSS INCLUDE "TABLE.L" ;the VDI Table END 3) Exercise nr°3: -------------- Here is the listing of the program that draws a rectangle with a PAT redefined after loading the previous grid program. TEXT INCLUDE "LINEQU.L" ;the EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;The MACROS SETBLOCK ;initialization PRINTLINE FRAME ;text WAIT ;waiting PEXEC NUL,ZERO,PRG,#0 ;we load the program whose ;name is in 'PRG' in mode ;0 and without parameters. DC.W $A000 ;We look for the address of the T.I. movea.l a0,a5 ;We save this address because it ;might be erased by one of our ;MACRO if it uses this ;register... ; We set the VDI table addresses in the T.I. move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) move #1,_fg_bp_1(a5) move #0,_fg_bp_2(a5) ;Color=%01=1 move #0,_wrt_mode(a5) ;Write mode AND move #7,_patmsk(a5) ;7+1=8 data for the PAT move.l #FILL,_patptr(a5) ;The new PAT is in ;'FILL' ;coordinates of the rectangle move #129,_x1(a5) ;_x1=129 move #24,_y1(a5) ;_y1=24 move #496,_x2(a5) ;_x2=496 move #183,_y2(a5) ;_y2=183 DC.W $A005 ;FILLED RECTANGLE WAIT ;waiting TERM ;end DATA FILL DC.W %0111111111111110 ;the PAT (EVEN number of DC.W %0100000000000010 ;WORDS) DC.W %0101000000001010 DC.W %0101111111111010 DC.W %0101000000001010 DC.W %0100000000000010 DC.W %0111111111111110 DC.W %0000000000000000 FRAME DC.B 27,'E','I am going to draw a square with $A005 ' DC.B 'after loading FRAME.PRG ',0 NUL DC.B 0 ;No environment and ZERO DC.B 0 ;command line PRG DC.B 'A:\FRAME.PRG',0 ;the NAME of the prg to load BSS INCLUDE "TABLE.L" ;the VDI Table END 4) Exercise nr° 4: --------------- Here is the listing of the program that displays the SPRITE. It was necessary to use UNDRAW SPRITE each time to be able to display the SPRITE at different coordinates. It was also necessary to provide ALL the parameters that the DRAW SPRITE and UNDRAW SPRITE routines need for a correct result. I chose, for the shape of my SPRITE, an ATARI symbol and my initials: L-P. (It's not very original, I admit...) I also use the macro instruction VSYNC to synchronize our graphic editions: the program is significantly slowed down but the flickering of the SPRITE display disappears... TEXT INCLUDE "LINEQU.L" ;The EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;the MACROS SETBLOCK ;initialization DC.W $A000 ;T.I. address in a0 and movea.l a0,a5 ;in a5 to avoid losing it ;if a MACRO uses the ;a0 register... ; We set the VDI Table addresses in the T.I. move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) PRINTLINE PIX ;text WAIT ;waiting DC.W $A00A ;HIDE MOUSE CCONOUT #27 ;ESC CCONOUT #'E' ;+'E' = clear the screen move #0,_wrt_mode(a5) ;Write mode AND move.l #BLOCK,a0 ;Address of the definition ;block of the SPRITE in a0 move.l #SAVE,a2 ;Address of the Backup Buffer ;in a2 (128 bytes for medium ;resolution) ; The SPRITE first goes from left to right (X coordinate in d0 and Y coordinate in d1) move #10,X ;1 WORD=10 in 'X' BBB add #1,X ;Add 1 in 'X' move X,d0 ;Put the WORD of 'X' in d0 move #100,d1 ;Put 100 in d1 move.l #BLOCK,a0 ;The block address in a0 cmpi #620,d0 ;Is d0=620? beq TWO ;if YES, go to 'TWO' move.l #SAVE,a2 ;Otherwise put the address of the Backup ;buffer of the sprite in a2 DC.W $A00C ;and UNDRAW SPRITE move.l #BLOCK,a0 ;The block address in a0 move.l #SAVE,a2 ;The buffer address in a2 DC.W $A00D ;and DRAW SPRITE VSYNC ;Synchronize jmp BBB ;and repeat in 'BBB' ; Then the SPRITE returns from right to left. TWO sub #1,X ;subtract 1 in 'X' move X,d0 ;put the word of 'X' in d0 move #100,d1 ;put 100 in d1 move.l #BLOCK,a0 ;The block address in a0 cmpi #10,d0 ;Is d0=10? beq END ;If YES, then go to 'END' move.l #SAVE,a2 ;Otherwise address of the buffer in a2 DC.W $A00C ;and UNDRAW SPRITE move.l #BLOCK,a0 ;The block address in a0 move.l #SAVE,a2 ;The buffer address in a2 DC.W $A00D ;and DRAW SPRITE VSYNC ;Synchronize jmp TWO ;and repeat in 'TWO' END WAIT ;waiting TERM ;end DATA ;The definition block of the SPRITE: BLOCK DC.W 0 ;X of the hot point DC.W 0 ;Y of the hot point DC.W 0 ;VDI Format DC.W 0 ;Mask Color DC.W 1 ;Foreground Color DC.W 0 ;no mask DC.W %0000000000000000 ;1st line of the 1st plan DC.W 0 ;no mask DC.W %0000110110110000 ;2nd line of the 1st plan DC.W 0 ;no mask DC.W %0000110110110000 DC.W 0 DC.W %0000110110110000 DC.W 0 DC.W %0001100110011000 DC.W 0 DC.W %0011000110001100 DC.W 0 DC.W %0011000110001100 DC.W 0 DC.W %0110000110000110 DC.W 0 DC.W %0110000110000110 DC.W 0 DC.W %0000000000000000 DC.W 0 DC.W %0011000001111100 DC.W 0 DC.W %0011000001101100 DC.W 0 DC.W %0011000001111000 DC.W 0 DC.W %0011000001100000 DC.W 0 DC.W %0011111001100000 DC.W 0 ;no MASK DC.W %0000000000000000 ;16th line of the 1st plan PIX DC.B 27,'E','I am going to move a SPRITE with ' DC.B '$A00D',0 BSS X DS.W 1 ;reserve a WORD in 'X' SAVE DS.B 128 ;the BUFFER for the SPRITE (MEDIUM ;resolution) INCLUDE "TABLE.L" ;the VDI table END 5) Exercise nr°5: -------------- Here is the listing of the program that displays points of different colors on the screen. TEXT INCLUDE "LINEQU.L" ;the EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;the MACROS ; I first test if we are in the correct resolution: GETREZ ;ask for the Resolution tst d0 ;Do we have resolution=0 (LOW) beq OK ;If Yes, go to 'OK' PRINTLINE MEDIUM ;otherwise message WAIT ;waiting TERM ;and end OK SETBLOCK ;initialize DC.W $A000 ;T.I. address in a0 ; We set the VDI table addresses in the T.I. move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) DC.W $A00A ;HIDE MOUSE PRINTLINE MESSAGE ;text WAIT ;waiting CCONOUT #27 ;ESC CCONOUT #'E' ;+'E' = clear the screen ; I define a MACRO INSTRUCTION named POINT that takes 3 parameters ; and which allows editing a point on the screen thanks to the routine $A001 POINT MACRO $\1,$\2,$\3 ;macro with 3 parameters move \1,ptsin ;\1=X coordinate move \2,ptsin+2 ;\2=Y coordinate move \3,intin ;\3=color DC.W $A001 ;PUT PIXEL ENDM ;end of the macro ; Here I will display all the points on the screen and give them a ; color thanks to the random number given by RANDOM in d0. ; To not obtain too large a number with RANDOM, I mask the ; number in d0 with the maximum number of digits I need. ; We thus obtain a number between 0 and the value of the mask ; (See the chapter on BIOS and XBIOS for the RANDOM function...) ; If d0=0 (color 0), I repeat the test with RANDOM because the color ; of the border must not change. move #319,d5 ;319 in d5 move #1,d0 ;1 in d0 PALETTE NEW ;change the PALETTE for the ;first time LOOP move #199,d6 ;199 in d6 LOOP POINT d5,d6,d0 ;POINT at coordinates ;(d5,d6) and with the color ;contained in d0 AGAIN RANDOM ;Random number returned ;in d0 and.l #15,d0 ;mask the 4 lowest bits of d0: 15=%1111 tst d0 ;Do we have d0=0? beq AGAIN ;If yes, repeat dbf d6,LOOP ;loop d6 times in LOOP dbf d5,LOOP ;loop d5 times in LOOP ; Now we vary the value of the color palette: ; We created a vector that contains the addresses of the palettes. ; (In 'VECTOR') ; We take one of these addresses and change the palette (I do not use ; the PALETTE MACRO that we created because it expects a LABEL as a pa- ; rameter.) then we start over with the next palette address... ; I also use INKEY to test if a key is pressed and if so, ; the program ends. HERE move #14,d6 ;14 in d6 lea VECTOR,a6 ;address of 'VECTOR' in a6 CHANGE move.l (a6)+,-(sp) ;put the L-M pointed by a6 ;(an address for the palette) ;into -(SP) move #6,-(sp) ;Code 6 (PALETTE) trap #14 ;of BIOS addq.l #6,sp ;and reposition SP INKEY ;I test a key press tst d0 ;d0=0? (If=0,no key press) bne RETURN ;If NO (a key was pressed) go to 'RETURN' dbf d6,CHANGE ;Otherwise loop in 'CHANGE' jmp HERE ;then go to 'HERE' RETURN CCONOUT #27 ;ESC CCONOUT #'E' ;+'E' = clear the screen PALETTE OLD ;We restore the old PALETTE TERM ;and exit the program DATA ; The data defining the palettes that are displayed successively to ; achieve a rotation of colors. ; For each palette, we rotate one color to the right... ; Color 0 never changes to avoid flickering of the ; screen border (Color 0) NEW DC.W $000,$027,$037,$027,$017,$016,$006,$015 DC.W $014,$036,$025,$005,$004,$014,$007,$003 ONE DC.W $000,$007,$027,$037,$027,$017,$016,$006 DC.W $014,$015,$036,$025,$005,$004,$014,$007 TWO DC.W $000,$003,$007,$027,$037,$027,$017,$016 DC.W $006,$015,$014,$036,$025,$005,$004,$014 THREE DC.W $000,$007,$003,$007,$027,$037,$027,$017 DC.W $016,$006,$015,$014,$036,$025,$005,$004 FOUR DC.W $000,$014,$007,$003,$007,$027,$037,$027 DC.W $017,$016,$006,$015,$014,$036,$025,$005 FIVE DC.W $000,$004,$014,$007,$003,$007,$027,$037 DC.W $027,$017,$016,$006,$015,$014,$036,$025 SIX DC.W $000,$005,$004,$014,$007,$003,$007,$027 DC.W $037,$027,$017,$016,$006,$015,$014,$036 SEVEN DC.W $000,$025,$005,$004,$014,$007,$003,$014 DC.W $007,$027,$037,$027,$017,$016,$006,$015 EIGHT DC.W $000,$036,$025,$005,$004,$014,$007,$003 DC.W $014,$007,$027,$037,$027,$017,$016,$006 NINE DC.W $000,$015,$036,$025,$005,$004,$014,$007 DC.W $003,$014,$007,$027,$037,$027,$017,$016 TEN DC.W $000,$006,$015,$036,$025,$005,$004,$014 DC.W $07,$003,$014,$007,$027,$037,$027,$017 ELEVEN DC.W $000,$016,$006,$015,$036,$025,$005,$004 DC.W $014,$007,$003,$014,$007,$027,$037,$027 TWELVE DC.W $000,$017,$016,$006,$015,$036,$025,$005 DC.W $004,$014,$007,$003,$014,$007,$027,$037 THIRTEEN DC.W $000,$027,$017,$016,$006,$015,$036,$025 DC.W $005,$004,$014,$007,$003,$014,$007,$027 FOURTEEN DC.W $000,$037,$027,$017,$016,$006,$015,$036 DC.W $025,$005,$004,$014,$007,$003,$014,$007 ; The vector pointing to the addresses of the different palettes VECTOR DC.L NEW,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN DC.L EIGHT,NINE,TEN,ELEVEN,TWELVE,THIRTEEN,FOURTEEN ; The old palette OLD DC.W $777,$500,$070,$000,$000,$000,$000,$000 DC.W $000,$000,$000,$000,$000,$000,$000,$000 MESSAGE DC.B 27,'E',174,' Scrambled Image ',175,':with the' DC.B ' function',13,10,'$A001 and RANDOM for colors...' DC.B '13,10,13,10,'(Press a key to' DC.B 'Exit)',0 MEDIUM DC.B 27,'E','WARNING, This program only works ' DC.B 'in LOW RESOLUTION!',13,10,'You must ' DC.B 'change the resolution using the GEM DESKTOP...',7,0 BSS INCLUDE "TABLE.L" ;the VDI Table END 6) Exercise nr°6: -------------- Here is the corrected program that displays diamonds without and then with CLIPPING... TEXT INCLUDE "LINEQU.L" ;The EQUs INCLUDE "INIT_TOS.L" ;Setblock INCLUDE "MACROS.L" ;The MACROS SETBLOCK ;initialization DC.W $A000 ;T.I. address in a0 movea.l a0,a5 ;I save it just in case... ; We set the VDI table addresses in the T.I. move.l #CONTROL,ticontrol(a0) move.l #INTIN,tiintin(a0) move.l #PTSIN,tiptsin(a0) move.l #INTOUT,tiintout(a0) move.l #PTSOUT,tiptsout(a0) PRINTLINE ONE ;text WAIT ;waiting DC.W $A00A ;HIDE MOUSE CCONOUT #27 ;ESC CCONOUT #'E' ;+'E' = clear the screen move #0,_fg_bp_1(a5) move #1,_fg_bp_2(a5) ;color %10=2 move #0,_wrt_mode(a5) ;Write mode AND move #1,_patmsk(a5) ;2 data for the PAT move.l #PAT,_patptr(a5) ;in 'PAT' move #4,sptsin ;4 vertices (diamond) move #0,_clip(a5) ;NO CLIPPING jsr DRAW ;and we draw the diamond WAIT ;waiting PRINTLINE TWO ;text WAIT ;waiting CCONOUT #27 ;ESC CCONOUT #'E' ;+'E' = clear the screen move #1,_clip(a5) ;WITH CLIPPING ; The coordinates of the CLIPPING FRAME are: (0,0)-(320,190) move #0,_xmn_clip(a5) move #0,_ymn_clip(a5) move #320,_xmx_clip(a5) move #190,_ymx_clip(a5) jsr DRAW ;and we draw the diamond WAIT ;waiting TERM ;end ; Here we draw the diamond with FILLED POLYGON: ; Coordinates of the POLYGON in PTSIN: (320,10)-(570,100)-(320,190)- ; (70,100) and we loop with (320,10) DRAW move #320,ptsin move #10,ptsin+2 move #570,ptsin+4 move #100,ptsin+6 move #320,ptsin+8 move #190,ptsin+10 move #70,ptsin+12 move #100,ptsin+14 move #320,ptsin+16 move #10,ptsin+18 ; Here we call FILLED POLYGON for each HORIZONTAL line of the diamond: from Y=10 to Y=190 (because our diamond is only defined between these lines) move #9,d6 ;9 in d6 LOOP add #1,d6 ;add 1 to d6 move d6,_y1(a5) ;put d6 in _y1 DC.W $A006 ;FILLED POLYGON cmpi #190,d6 ;Do we have d6=190? bne LOOP ;If NO then repeat in LOOP rts ;RETURN from the SUBROUTINE DATA PAT DC.W %1111111111111110 ;the PAT (EVEN DC.W %0000000000000000 ;number of WORDS) ONE DC.B 27,'E','I draw a POLYGON with $A006:',0 TWO DC.B 27,'E','I draw the same POLYGON using ' DC.B 'CLIPPING',0 BSS INCLUDE "TABLE.L" ;The VDI Table END ------------------ That's it for the corrections of the exercises on LineAs... The listings of these 6 programs as well as the executable programs are of course on this disk in the files: 1) TRANSMOU.L & TRANSMOU.PRG 2) CADRE .L & CADRE .PRG 3) RECTANGL.L & RECTANGL.PRG 4) SPRITE .L & SPRITE .PRG 5) POINT .L & POINT .PRG 6) POLYGONE.L & POLYGONE.PRG Laurent PIECHOCKI 8,Impasse Bellevue Continue in the file: INTERRUP.DOC 57980 TENTELING ------------
Back to ASM_Tutorial