Pl2 CORRIG 4.DOC

From Atari Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

                            -----------------
                             CORRECTIONS of 

                             EXERCISES NR°4
                              
                            -----------------


1) Exercise nr°1:
   --------------
  a) If TACR is worth %100 and the data register is worth 42, what will be
     the call frequency of a program on this TIMER?
    
     With TACR = %100, we have a prescaler of 50, the data register
     is worth 42, so we get:

     frequency = 245760 / 50 / 42 = about 117 calls per second (Delay Mode)


     Will the program be installed on TIMER A or TIMER B?

     TACR manages the operating mode of TIMER A. (have you forgotten
     already ?) 



  b) How to stop a program under interruption installed
     on TIMER A ? :

     It is enough to set the first 4 bits of the TACR register to 0
 

  c) We want to install a program under interruption that must execute
     about 245 times per second, give a possible value of the control
     and data registers to achieve this effect.

     If the control register is worth %10, we have a prescaler of 10 and
     if the data register also worth 10, we get:

     frequency = 245760 / 10 / 10 = 245.76 calls per second (Delay Mode)


  d) Can we install several programs under interruption in the
     same TIMER?
     
     Of course NOT!
     Just look at how to install a routine
     on a TIMER, the first thing we do is set all the 
     registers of the concerned TIMER to 0 to disable the routine that
     was already there....
 

  e) A program under interruption must necessarily execute in
     SUPERVISOR MODE.
     Find a reason for this ...

     A simple reason is that at the end of the program (Before the RTE),
     we clear the concerned bit of the ISR register.
     And any modification of the MFP registries SHOULD be done in SUPERVISOR
     MODE...


1) Exercise nr°2:
   -------------- 
   Here are the macros for TIMERS A and B:


TIMERA    MACRO     $\1,$\2,$\3    ;MACRO with 3 parameters         

; Zeroing the different bit vectors for TIMER A

          and.b     #%11011111,$FFFA13  ;IMRA
          and.b     #%11011111,$FFFA0F  ;ISRA
          and.b     #%11011111,$FFFA0B  ;IPRA
          and.b     #%11011111,$FFFA07  ;IERA

; XBTIMER and installing our routine

          pea       \1                  ;\1=LABEL of the start of the routine
                                        ;   to put under interruption
          move.w    #\2,-(sp)           ;\2=control register
          move.w    #\3,-(sp)           ;\3=data register
          move.w    #0,-(sp)            ;0 =TIMER A
          move.w    #$1F,-(sp)          ;XBTIMER           
          trap      #14                 ;XBIOS
          adda.l    #12,sp              ;we reposition SP

; Setting to 1 the different bit vectors for TIMER A

          or.b      #%100000,$FFFA07    ;IERA
          or.b      #%100000,$FFFA13    ;IMRA
          
          ENDM                          ;End of the macro



 
TIMERB   MACRO     $\1,$\2,$\3         ;MACRO with 3 parameters

; Zeroing the different bit vectors for TIMER B

          and.b     #%11111110,$FFFA13  ;IMRB
          and.b     #%11111110,$FFFA0F  ;ISRB
          and.b     #%11111110,$FFFA0B  ;IPRB
          and.b     #%11111110,$FFFA07  ;IERA

; XBTIMER and installing the routine on TIMER B

          pea       \1                  ;\1=LABEL of the start of the routine
                                        ;   to put under interruption
          move.w    #\2,-(sp)           ;\2=control register
          move.w    #\3,-(sp)           ;\3=data register
          move.w    #1,-(sp)            ;1 = TIMER B
          move.w    #$1F,-(sp)          ;XBTIMER      
          trap      #14                 ;XBIOS
          adda.l    #12,sp              ;we reposition SP

; Setting to 1 the different bit vectors

          or.b      #%1,$FFFA07         ;IERB
          or.b      #%1,$FFFA13         ;IMRB
          
          ENDM                          ;END of the MACRO



2) Exercise nr°3:
   --------------
   Two solutions exist to stop TIMERS A and B.

   The first consists of setting the first 4 bits of the TACR registers
   (For TIMER A) or TBCR (For TIMER B) to 0.

   So we would write:

     BCLR  #0,$FFFA19    ;bit 0 of the TACR register
     BCLR  #1,$FFFA19    ;bit 1
     BCLR  #2,$FFFA19    ;bit 2
     BCLR  #3,$FFFA19    ;bit 3

   For TIMER A (In SUPERVISOR MODE!)   

   Or 

     BCLR  #0,$FFFA1B    ;bit 0 of the TBCR register
     BCLR  #1,$FFFA1B    ;bit 1
     BCLR  #2,$FFFA1B    ;bit 2
     BCLR  #3,$FFFA1B    ;bit 3

   For TIMER B (In SUPERVISOR MODE!)


   There is also an XBIOS function that allows to block an
   interruption of the MFP 68901: It is the JDISINT function of code 26.

   We just need to pass the IPL of the MFP that must be stopped.
   It is with this function that we will create our MACROS:

 
   For TIMER A (Level 13/6 in the MFP), we will write:
    
STOPTIMEA   MACRO
            move.w    #13,-(sp)    ;TIMER A ( IPL 13/6)
            move.w    #26,-(sp)    ;JDISINT
            trap      #14          ;XBIOS
            addq.l    #4,sp        ;we reposition SP
            ENDM                   
 
   For TIMER B (Level 8/6 in the MFP), we will write:
 
STOPTIMEB   MACRO
            move.w    #8,-(sp)     ;TIMER B ( IPL 8/6 )     
            move.w    #26,-(sp)    ;JDISINT
            trap      #14          ;XBIOS
            addq.l    #4,sp        ;we reposition SP
            ENDM
          


3) Exercise nr°3:
   --------------
   Here is the listing of the program that varies the palette of colors
   under interruption.
   There was no difficulty. 


               TEXT

               INCLUDE       "INIT_TOS.L"    ;Setblock
               INCLUDE       "MACROS.L"      ;The MACROS
               INCLUDE       "TIMERS.L"      ;The file of MACROS
                                             ;for the TIMERS

               SETBLOCK            ;initialisation

               SUPER               ;SUPERVISOR MODE

               PRINTLINE     CA    ;text
               WAIT                ;wait

               TIMERA        ROUTINE,200,%111     ;We install the routine
                                                  ;on TIMER A with the
                                                  ;data register=200
                                                  ;and control register
                                                  ;=%111

               USER                ;USER MODE for
          
               KEEP          2000  ;return to DESKTOP with the program 

; The routine under interruption that changes the colors:

ROUTINE        cmpi          #30,TESTE  ;Do we have 30 in 'TESTE'?
               bgt           DEUX       ;If it's greater, go to 'DEUX'
               move.l        #PAL1,$45A ;Address of the new palette in
                                        ;'colorptr'
               add           #1,TESTE   ;Otherwise add 1 to 'TESTE' 
               bclr          #5,$FFFA0F ;Clear ISRA (bit 5=TIMER A)
               RTE                      ;RETURN FROM EXCEPTION

DEUX           move.l        #PAL2,$45A ;Address of the new palette in
                                        ;'colorptr'
               add           #1,TESTE   ;Add 1 to 'TESTE'
               cmpi          #60,TESTE  ;Do we have 60 in 'TESTE' ?
               bne           NON        ;If NO, go to 'NON'
               move          #0,TESTE   ;Set 0 in 'TESTE'
NON            bclr          #5,$FFFA0F ;Clear ISRA (bit 5=TIMER A)
               RTE                      ;RETURN FROM EXCEPTION

               DATA

; Palette nr° 1

PAL1           DC.W          $777,$700,$070,$000,$000,$777,$777,$777
               DC.W          $777,$777,$777,$777,$777,$777,$777,$777

; Palette nr° 2

PAL2           DC.W          $777,$700,$007,$000,$000,$777,$777,$777
               DC.W          $777,$777,$777,$777,$777,$777,$777,$777

CA             DC.B          27,'E','Routine under interruption (TIMER A )'
               DC.B          ' that changes the',13,10,'color nr°3 of the'
               DC.B          ' palette (System Variable $45A):',0

               BSS

               DS.B          500
PILE           DS.B          1     ;For SETBLOCK
SAUV_SP        DS.L          1     ;For SUPER and USER     
TESTE          DS.W          1     ;For the routine under interruption

               END
  


4) Exercise nr°4:
   --------------
   Here too, no major difficulty...


               TEXT

               INCLUDE       "INIT_TOS.L"    ;SETBLOCK
               INCLUDE       "MACROS.L"      ;The MACROS
               INCLUDE       "TIMERS.L"      ;The TIMERS MACROS
               INCLUDE       "MACROS_2.L"    ;The MACRO HEXA

               SETBLOCK                 ;initialisation                   

               SUPER                    ;SUPERVISOR MODE

               PRINTLINE     LA         ;text
               CCONOUT       #13        ;13 +
               CCONOUT       #10        ;10 = return to the line at
                                        ;column 1
               WAIT                     ;wait

               TIMERA        PRG,50,%111     ;We install our routine
                                             ;on TIMER A with the da-
                                             ;ta register = 50 and the
                                             ;control register=%111

; The loop that displays the values of the variable

BOUCLE         HEXA          VAL     ;Displays the L-M of 'VAL' in HEXA
               CCONOUT       #13     ;13 +
               CCONOUT       #10     ;10 = return to the line at column 1
               WAIT                  ;wait
               cmpi.b        #'Q',d0 ;Key = Q?   
               beq           RETOUR  ;If YES, go to 'RETOUR'   
               cmpi.b        #'q',d0 ;Key = q?   
               beq           RETOUR  ;If YES, go to 'RETOUR'   
               jmp           BOUCLE  and we start again with 'BOUCLE'


; The routine under interruption that just increments the L-M 
; in 'VAL'

PRG            add.l         #1,VAL          ;Add 1 to the L-M in 'VAL'
               bclr          #5,$FFFA0F      ;Clear ISRA (bit 5=TIMER A)
               RTE                           ;RETURN FROM EXCEPTION

RETOUR         USER           ;USER MODE
               STOPTIMEA      ;we stop TIMER A
               TERM           ;and END!

               DATA

LA             DC.B          27,'E','Routine under interruption (TIMER A )'
               DC.B          ' that increments the',13,10,'content of the di'
               DC.B          'splayed variable ([Q] to QUIT) ...',0

               BSS

               DS.B          500
PILE           DS.B          1     ;For SETBLOCK
SAUV_SP        DS.L          1     ;For SUPER and USER
VAL            DS.L          1     ;The variable to display

               END


                           --------------------
     
  Well, the listings and the executable programs of these exercises 
  can be found in the files:

  1)  TIMERS .L    for the MACROS    TIMERA,TIMERB,STOPTIMEA,STOPTIMEB

  2)  PALETTE.L    for the program of changing the palette under
                   interruption.
  and  PALETTE.PRG
    
  3)  AFFICHE.L    for the program that displays the L-M incremented under
                   interruption.

  and  AFFICHE.PRG



      
  PIECHOCKI Laurent
  8, Impasse Bellevue            Continued in the file:ANNEXE.DOC
  57980  TENTELING                                     ----------


Back to ASM_Tutorial