                         .module lab3.c
                         .area memory(abs)
                         .org 0xffd6
 FFD6                 _interrupt_vectors::
 FFD6 F000              .word 61440
 FFD8 F000              .word 61440
 FFDA F000              .word 61440
 FFDC F000              .word 61440
 FFDE F000              .word 61440
 FFE0 F000              .word 61440
 FFE2 F000              .word 61440
 FFE4 F000              .word 61440
 FFE6 F000              .word 61440
 FFE8 0431              .word _ThreadSwitcher
 FFEA F000              .word 61440
 FFEC F000              .word 61440
 FFEE F000              .word 61440
 FFF0 F000              .word 61440
 FFF2 F000              .word 61440
 FFF4 F000              .word 61440
 FFF6 F000              .word 61440
 FFF8 F000              .word 61440
 FFFA F000              .word 61440
 FFFC F000              .word 61440
 FFFE 0000              .word __start
                         .area data
                         .area text
                       ;  IX -> 0,x
                       ;      semaphore -> +4,x
 0000                 _Wait::
 0000 37                pshb
 0001 36                psha
 0002 3C                pshx
 0003 3C                pshx
 0004 30                tsx
 0005 EF00              stx 0,x
                       ; /************************************************************************
                       ; * Term:   Fall 2003
                       ; * Course: ECE 473
                       ; * Name:   Olamide Adabonyan / Philip Lechowicz
                       ; * E-mail: o_mide@yahoo.com / phillech@aol.com
                       ; *
                       ; * Date Submitted:   11/27/02
                       ; * Demo Approval:    ________
                       ; ************************************************************************/
 0007 0F                     sei
                       
 0008 2003              bra L5
 000A                 L4:
 000A 0E                     cli
 000B 01                 nop
 000C 0F                 sei
                       
 000D                 L5:
                       ; 
                       ; #include <hc11.h>
 000D 1AEE04            ldy 4,x
 0010 18EC00            ldd 0,y
 0013 2FF5              ble L4
                       ; #include "vectors.c"    //locate TOC1 jmp addi from EEPROM
                       ; 
                       ; #define stacksize 150
                       ; #define switchtime 20000
                       ; 
                       ; #define endProg() asm("swi")
                       ; #define enableInt() asm("cli")
 0015 1AEE04            ldy 4,x
 0018 18EC00            ldd 0,y
 001B 830001            subd #1
 001E 1AEE04            ldy 4,x
 0021 18ED00            std 0,y
                       ; #define disableInt() asm("sei")
 0024 0E                     cli
                       
                       ; 
 0025                 L3:
 0025 08                inx
 0026 08                inx
 0027 35                txs
 0028 38                pulx
 0029 1838              puly
 002B                   .dbline 0 ; func end
 002B 39                rts
                       ;  IX -> 0,x
                       ;      semaphore -> +4,x
 002C                 _Signal::
 002C 37                pshb
 002D 36                psha
 002E 3C                pshx
 002F 3C                pshx
 0030 30                tsx
 0031 EF00              stx 0,x
                       ; int displayFree;    //Semaphore used to share Display
                       ; char t1_iteration;
                       ; 
                       ; void Program01(void);
 0033 0F                     sei
                       
                       ; void Program02(void);
 0034 1AEE04            ldy 4,x
 0037 18EC00            ldd 0,y
 003A C30001            addd #1
 003D 1AEE04            ldy 4,x
 0040 18ED00            std 0,y
                       ; void Program03(void);
 0043 0E                     cli
                       
                       ; void Message1(char *NamePt, unsigned int num);
 0044                 L7:
 0044 08                inx
 0045 08                inx
 0046 35                txs
 0047 38                pulx
 0048 1838              puly
 004A                   .dbline 0 ; func end
 004A 39                rts
                       ;  IX -> 0,x
                       ;         SaveSP -> +3,x
 004B                 _InitFifo::
 004B BD0000            jsr __enterb
 004E 04                .byte 0x4
 004F 07                     tpa
 0050 A703               staa 3,x
 0052 0F                 sei
                       
 0053 CC0002            ldd #_Fifo
 0056 FD000C            std _GETPT
 0059 CC0002            ldd #_Fifo
 005C FD000E            std _PUTPT
 005F A603                   ldaa 3,x
 0061 06                 tap
                       
 0062                 L8:
 0062 08                inx
 0063 08                inx
 0064 08                inx
 0065 08                inx
 0066 35                txs
 0067 38                pulx
 0068                   .dbline 0 ; func end
 0068 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;          ?temp -> +5,x
                       ;         SaveSP -> +7,x
                       ;            Ppt -> +8,x
                       ;           data -> +13,x
 0069                 _PutFifo::
 0069 BD0000            jsr __enterb
 006C 4A                .byte 0x4a
                       ; void Message2(char *NamePt, char *NamePt2);
                       ; void Message3(char *NamePt);
                       ; 
                       ; 
 006D 07                     tpa
 006E A707               staa 7,x
 0070 0F                 sei
                       
                       ; //===========================[.c header files]
 0071 FC000E            ldd _PUTPT
 0074 ED08              std 8,x
                       ; #include "spin.c"
 0076 EC08              ldd 8,x
 0078 ED05              std 5,x
 007A C30001            addd #1
 007D ED08              std 8,x
 007F 1AEE05            ldy 5,x
 0082 E60D              ldab 13,x
 0084 18E700            stab 0,y
                       ; #include "fifo.c"
                       ; #include "lab3sci.c"
 0087 CC000C            ldd #_Fifo+10
 008A ED02              std 2,x
 008C EC08              ldd 8,x
 008E 1AA302            cpd 2,x
 0091 2605              bne L10
                       ; //============================
 0093 CC0002            ldd #_Fifo
 0096 ED08              std 8,x
 0098                 L10:
                       ; 
 0098 EC08              ldd 8,x
 009A 1AB3000C          cpd _GETPT
 009E 2608              bne L13
                       ; 
                       ; 
 00A0 A607                   ldaa 7,x
 00A2 06                 tap
                       
                       ; /*******************************************************
 00A3 CC0000            ldd #0
 00A6 200B              bra L9
 00A8                 L13:
                       ; Name: TCB (Thread Control Block)...
                       ; Purpose: - data structure for TCB
                       ; ********************************************************/
                       ; struct  TCB
                       ; {   
 00A8 EC08              ldd 8,x
 00AA FD000E            std _PUTPT
                       ;     struct TCB *Next;      /* Link to Next TCB */
 00AD A607                   ldaa 7,x
 00AF 06                 tap
                       
                       ;     unsigned char *SP;     /* Stack Pointer  */
 00B0 CCFFFF            ldd #-1
 00B3                 L9:
 00B3 8F                xgdx
 00B4 C3000A            addd #10
 00B7 8F                xgdx
 00B8 35                txs
 00B9 38                pulx
 00BA 1838              puly
 00BC                   .dbline 0 ; func end
 00BC 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;          ?temp -> +5,x
                       ;         SaveSP -> +7,x
                       ;         datapt -> +10,x
 00BD                 _GetFifo::
 00BD BD0000            jsr __enterb
 00C0 48                .byte 0x48
                       ;     unsigned char Id;      /* 1,2 or 4 */
                       ;     unsigned char MoreStack[stacksize];  /* additional stack */
                       ;     unsigned char CCR;     /* Initial CCR */
                       ;     unsigned char RegB;    /* Initial RegB */
                       ;     unsigned char RegA;    /* Initial RegA */
                       ;     unsigned int RegX;     /* Initial RegX */
                       ;     unsigned int RegY;     /* Initial RegY */
                       ;     void (*PC)(void);      /* Initial Program Counter */
                       ; };
 00C1 FC000E            ldd _PUTPT
 00C4 1AB3000C          cpd _GETPT
 00C8 2605              bne L16
                       ; typedef struct TCB TCBType;
 00CA CC0000            ldd #0
 00CD 2034              bra L15
 00CF                 L16:
                       ; typedef TCBType * TCBPtr;
                       ; TCBPtr RunPt;   /* Pointer to thread currently running */
                       ; 
 00CF 07                     tpa
 00D0 A707               staa 7,x
 00D2 0F                 sei
                       
                       ; 
 00D3 FC000C            ldd _GETPT
 00D6 ED05              std 5,x
 00D8 C30001            addd #1
 00DB FD000C            std _GETPT
 00DE 1AEE05            ldy 5,x
 00E1 18E600            ldab 0,y
 00E4 1AEE0A            ldy 10,x
 00E7 18E700            stab 0,y
                       ; 
 00EA CC000C            ldd #_Fifo+10
 00ED ED02              std 2,x
 00EF FC000C            ldd _GETPT
 00F2 1AA302            cpd 2,x
 00F5 2606              bne L18
                       ; /*******************************************************
 00F7 CC0002            ldd #_Fifo
 00FA FD000C            std _GETPT
 00FD                 L18:
                       ; Name: Threads 1, 2 & 3
 00FD A607                   ldaa 7,x
 00FF 06                 tap
                       
                       ; Purpose: - create structure and initialize theads 1, 2, & 3 
 0100 CCFFFF            ldd #-1
 0103                 L15:
 0103 8F                xgdx
 0104 C30008            addd #8
 0107 8F                xgdx
 0108 35                txs
 0109 38                pulx
 010A 1838              puly
 010C                   .dbline 0 ; func end
 010C 39                rts
                       ;  IX -> 0,x
                       ;           data -> +5,x
 010D                 _OutChar::
 010D 37                pshb
 010E 36                psha
 010F 3C                pshx
 0110 3C                pshx
 0111 30                tsx
 0112 EF00              stx 0,x
 0114                 L22:
 0114                 L23:
 0114 18CE102E          ldy #0x102e
 0118 181F0080F7        brclr 0,y,#128,L22
 011D E605              ldab 5,x
 011F F7102F            stab 0x102f
 0122                 L21:
 0122 08                inx
 0123 08                inx
 0124 35                txs
 0125 38                pulx
 0126 1838              puly
 0128                   .dbline 0 ; func end
 0128 39                rts
                       ;  IX -> 0,x
                       ;         number -> +4,x
 0129                 _OutUDec::
 0129 37                pshb
 012A 36                psha
 012B 3C                pshx
 012C 3C                pshx
 012D 30                tsx
 012E EF00              stx 0,x
 0130 EC04              ldd 4,x
 0132 1A83000A          cpd #10
 0136 251A              blo L26
 0138 EC04              ldd 4,x
 013A 18CE000A          ldy #10
 013E BD0000            jsr __divu
 0141 BD0129            jsr _OutUDec
 0144 EC04              ldd 4,x
 0146 18CE000A          ldy #10
 014A BD0000            jsr __modu
 014D BD0129            jsr _OutUDec
 0150 2009              bra L27
 0152                 L26:
 0152 EC04              ldd 4,x
 0154 C30030            addd #48
 0157 4F                clra
 0158 BD010D            jsr _OutChar
 015B                 L27:
 015B                 L25:
 015B 08                inx
 015C 08                inx
 015D 35                txs
 015E 38                pulx
 015F 1838              puly
 0161                   .dbline 0 ; func end
 0161 39                rts
                       ;  IX -> 0,x
                       ;          ?temp -> +2,x
                       ;          ?temp -> +3,x
                       ;         letter -> +5,x
                       ;             pt -> +8,x
 0162                 _OutString::
 0162 BD0000            jsr __enterb
 0165 46                .byte 0x46
 0166 2006              bra L30
 0168                 L29:
 0168 E605              ldab 5,x
 016A 4F                clra
 016B BD010D            jsr _OutChar
 016E                 L30:
 016E EC08              ldd 8,x
 0170 ED03              std 3,x
 0172 C30001            addd #1
 0175 ED08              std 8,x
 0177 1AEE03            ldy 3,x
 017A 18E600            ldab 0,y
 017D E702              stab 2,x
 017F E705              stab 5,x
 0181 6D02              tst 2,x
 0183 26E3              bne L29
 0185                 L28:
 0185 8F                xgdx
 0186 C30006            addd #6
 0189 8F                xgdx
 018A 35                txs
 018B 38                pulx
 018C 1838              puly
 018E                   .dbline 0 ; func end
 018E 39                rts
                         .area data
 0000                 _sys::
 0000                   .blkw 1
                         .area idata
 0000 00A4              .word _sys+164
                         .area data
 0002                   .blkw 1
                         .area idata
 0002 009A              .word _sys+5+149
                         .area data
 0004                   .blkb 1
                         .area idata
 0004 01                .byte 1
                         .area data
 0005                   .blkb 1
                         .area idata
 0005 00                .byte 0
                         .area data
 0006                   .blkb 149
                         .area idata
 0006 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 0042 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 007E 00000000000000000000   .word 0,0,0,0,0
 0088 00000000000000000000   .word 0,0,0,0,0
 0092 000000000000000000     .byte 0,0,0,0,0,0,0,0,0
                         .area data
 009B                   .blkb 1
                         .area idata
 009B 40                .byte 64
                         .area data
 009C                   .blkb 1
                         .area idata
 009C 00                .byte 0
                         .area data
 009D                   .blkb 1
                         .area idata
 009D 00                .byte 0
                         .area data
 009E                   .blkb 2
                         .area idata
 009E 0000              .word 0
                         .area data
 00A0                   .blkb 2
                         .area idata
 00A0 0000              .word 0
                         .area data
 00A2                   .blkw 1
                         .area idata
 00A2 01A7              .word _Program01
                         .area data
 00A4                   .blkw 1
                         .area idata
 00A4 0148              .word _sys+328
                         .area data
 00A6                   .blkw 1
                         .area idata
 00A6 013E              .word _sys+164+5+149
                         .area data
 00A8                   .blkb 1
                         .area idata
 00A8 02                .byte 2
                         .area data
 00A9                   .blkb 1
                         .area idata
 00A9 00                .byte 0
                         .area data
 00AA                   .blkb 149
                         .area idata
 00AA 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 00E6 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 0122 00000000000000000000   .word 0,0,0,0,0
 012C 00000000000000000000   .word 0,0,0,0,0
 0136 000000000000000000     .byte 0,0,0,0,0,0,0,0,0
                         .area data
 013F                   .blkb 1
                         .area idata
 013F 40                .byte 64
                         .area data
 0140                   .blkb 1
                         .area idata
 0140 00                .byte 0
                         .area data
 0141                   .blkb 1
                         .area idata
 0141 00                .byte 0
                         .area data
 0142                   .blkb 2
                         .area idata
 0142 0000              .word 0
                         .area data
 0144                   .blkb 2
                         .area idata
 0144 0000              .word 0
                         .area data
 0146                   .blkw 1
                         .area idata
 0146 0348              .word _Program02
                         .area data
 0148                   .blkw 1
                         .area idata
 0148 0000              .word _sys
                         .area data
 014A                   .blkw 1
                         .area idata
 014A 01E2              .word _sys+328+5+149
                         .area data
 014C                   .blkb 1
                         .area idata
 014C 03                .byte 3
                         .area data
 014D                   .blkb 1
                         .area idata
 014D 00                .byte 0
                         .area data
 014E                   .blkb 149
                         .area idata
 014E 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 018A 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000   .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 01C6 00000000000000000000   .word 0,0,0,0,0
 01D0 00000000000000000000   .word 0,0,0,0,0
 01DA 000000000000000000     .byte 0,0,0,0,0,0,0,0,0
                         .area data
 01E3                   .blkb 1
                         .area idata
 01E3 40                .byte 64
                         .area data
 01E4                   .blkb 1
                         .area idata
 01E4 00                .byte 0
                         .area data
 01E5                   .blkb 1
                         .area idata
 01E5 00                .byte 0
                         .area data
 01E6                   .blkb 2
                         .area idata
 01E6 0000              .word 0
                         .area data
 01E8                   .blkb 2
                         .area idata
 01E8 0000              .word 0
                         .area data
 01EA                   .blkw 1
                         .area idata
 01EA 0392              .word _Program03
                         .area data
                         .area text
 018F                 L43:
 018F 54312068617320657865637574656420   .byte 'T,49,32,'h,'a,'s,32,'e,'x,'e,'c,'u,'t,'e,'d,32
 019F 00                .byte 0
 01A0                 L44:
 01A0 2074696D657300    .byte 32,'t,'i,'m,'e,'s,0
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;           temp -> +4,x
                       ;        t1_msg2 -> +5,x
                       ;        t1_msg1 -> +12,x
                       ;         dummy2 -> +29,x
                       ;         dummy1 -> +30,x
                       ;          dummy -> +31,x
                       ;              i -> +32,x
                       ;           flag -> +33,x
 01A7                 _Program01::
 01A7 BD0000            jsr __enterb
 01AA 22                .byte 0x22
                       ; ********************************************************/
                       ; TCBType sys[3]=
                       ; {
                       ;   {  
                       ;      &sys[1],                           /* Pointer to Next */
                       ;      &sys[0].MoreStack[stacksize-1],    /* Initial SP */
                       ;      1,                                 /* Id */
                       ;      { 0},
                       ;      0x40,0,0,0,0,                      /* CCR,B,A,X,Y */
                       ;      Program01,                         /* Initial PC */
                       ;   },
                       ;   {  
                       ;      &sys[2],                           /* Pointer to Next */
                       ;      &sys[1].MoreStack[stacksize-1],    /* Initial SP */
                       ;      2,                                 /* Id */
                       ;      { 0},
                       ;      0x40,0,0,0,0,                      /* CCR,B,A,X,Y */
                       ;      Program02,                         /* Initial PC */
                       ;   },
                       ;   {  
                       ;      &sys[0],                           /* Pointer to Next */
                       ;      &sys[2].MoreStack[stacksize-1],    /* Initial SP */
                       ;      3,                                 /* Id */
                       ;      { 0},
                       ;      0x40,0,0,0,0,                      /* CCR,B,A,X,Y */
                       ;      Program03,                         /* Initial PC */
                       ;   } 
                       ; };
                       ; 
                       ; 
                       ; 
                       ; 
                       ; /*******************************************************
                       ; Name: Programs 1, 2 & 3
                       ; Purpose: - output messages to screen depending on thread running
                       ; Inputs: none
                       ; Outputs: none
                       ; ********************************************************/
                       ; void Program01(void)
                       ; {
                       ;     //myId=RunPt->Id;       //debugger
                       ;     char i, flag, temp, dummy, dummy1, dummy2;
                       ;     char t1_msg1[] = "T1 has executed ";
 01AB EC00              ldd 0,x
 01AD C3000C            addd #12
 01B0 18CE018F          ldy #L43
 01B4 3C                pshx
 01B5 8F                xgdx
 01B6 CC0011            ldd #17
 01B9 BD0000            jsr __asgnblk
 01BC 38                pulx
                       ;     char t1_msg2[] = " times";
 01BD EC00              ldd 0,x
 01BF C30005            addd #5
 01C2 18CE01A0          ldy #L44
 01C6 3C                pshx
 01C7 8F                xgdx
 01C8 CC0007            ldd #7
 01CB BD0000            jsr __asgnblk
 01CE 38                pulx
 01CF 7E033D            jmp L46
 01D2                 L45:
                       ;     
                       ;     while(1)
                       ;     {
                       ;         t1_iteration++;
 01D2 F60010            ldab _t1_iteration
 01D5 CB01              addb #1
 01D7 F70010            stab _t1_iteration
                       ;         Message1("Thread 1 Iteration #", t1_iteration);
 01DA F60010            ldab _t1_iteration
 01DD 4F                clra
 01DE 37                pshb
 01DF 36                psha
 01E0 CC05BD            ldd #L48
 01E3 BD03B8            jsr _Message1
 01E6 1838              puly
                       ; 
                       ;         for(i=0; i<16; i++)
 01E8 6F20              clr 32,x
 01EA 2027              bra L52
 01EC                 L49:
                       ;         {
                       ;             flag = PutFifo(t1_msg1[i]);
 01EC EC00              ldd 0,x
 01EE C3000C            addd #12
 01F1 ED02              std 2,x
 01F3 E620              ldab 32,x
 01F5 4F                clra
 01F6 E302              addd 2,x
 01F8 188F              xgdy
 01FA 18E600            ldab 0,y
 01FD 4F                clra
 01FE BD0069            jsr _PutFifo
 0201 E721              stab 33,x
                       ;             if (flag == 0)
 0203 6D21              tst 33,x
 0205 2606              bne L53
                       ;                 i--;
 0207 E620              ldab 32,x
 0209 C001              subb #1
 020B E720              stab 32,x
 020D                 L53:
 020D                 L50:
 020D E620              ldab 32,x
 020F CB01              addb #1
 0211 E720              stab 32,x
 0213                 L52:
 0213 E620              ldab 32,x
 0215 C110              cmpb #16
 0217 25D3              blo L49
                       ;         }
                       ;         
                       ;         //convert # of T1 iterations to ascii
                       ;         if (t1_iteration >= 10)
 0219 F60010            ldab _t1_iteration
 021C C10A              cmpb #10
 021E 2403              bhs X1
 0220 7E02D9            jmp L55
 0223                 X1:
                       ;         {
                       ;             if(t1_iteration >=100)
 0223 F60010            ldab _t1_iteration
 0226 C164              cmpb #100
 0228 2403              bhs X2
 022A 7E028F            jmp L57
 022D                 X2:
                       ;             {
                       ;                 temp = (t1_iteration/10);
 022D F60010            ldab _t1_iteration
 0230 4F                clra
 0231 18CE000A          ldy #10
 0235 BD0000            jsr __divi
 0238 E704              stab 4,x
                       ;                 dummy = (temp/10) + 0x30;
 023A E604              ldab 4,x
 023C 4F                clra
 023D 18CE000A          ldy #10
 0241 BD0000            jsr __divi
 0244 C30030            addd #48
 0247 E71F              stab 31,x
                       ;                 dummy1 = (temp%10) + 0x30;
 0249 E604              ldab 4,x
 024B 4F                clra
 024C 18CE000A          ldy #10
 0250 BD0000            jsr __modi
 0253 C30030            addd #48
 0256 E71E              stab 30,x
                       ;                 dummy2 = (t1_iteration%10) + 0x30;
 0258 F60010            ldab _t1_iteration
 025B 4F                clra
 025C 18CE000A          ldy #10
 0260 BD0000            jsr __modi
 0263 C30030            addd #48
 0266 E71D              stab 29,x
 0268                 L59:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy);
 0268 E61F              ldab 31,x
 026A 4F                clra
 026B BD0069            jsr _PutFifo
 026E E721              stab 33,x
 0270                 L60:
                       ;                 while(flag == 0);   //FIFO full
 0270 6D21              tst 33,x
 0272 27F4              beq L59
 0274                 L62:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy1);
 0274 E61E              ldab 30,x
 0276 4F                clra
 0277 BD0069            jsr _PutFifo
 027A E721              stab 33,x
 027C                 L63:
                       ;                 while(flag == 0);   //FIFO full
 027C 6D21              tst 33,x
 027E 27F4              beq L62
 0280                 L65:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy2);
 0280 E61D              ldab 29,x
 0282 4F                clra
 0283 BD0069            jsr _PutFifo
 0286 E721              stab 33,x
 0288                 L66:
                       ;                 while(flag == 0);   //FIFO full
 0288 6D21              tst 33,x
 028A 27F4              beq L65
                       ;             }
 028C 7E030C            jmp L56
 028F                 L57:
                       ;             else
                       ;             {
                       ;                 dummy = 0x30;
 028F C630              ldab #48
 0291 E71F              stab 31,x
                       ;                 dummy1 = (t1_iteration/10) + 0x30;
 0293 F60010            ldab _t1_iteration
 0296 4F                clra
 0297 18CE000A          ldy #10
 029B BD0000            jsr __divi
 029E C30030            addd #48
 02A1 E71E              stab 30,x
                       ;                 dummy2 = (t1_iteration%10) + 0x30;
 02A3 F60010            ldab _t1_iteration
 02A6 4F                clra
 02A7 18CE000A          ldy #10
 02AB BD0000            jsr __modi
 02AE C30030            addd #48
 02B1 E71D              stab 29,x
 02B3                 L68:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy);
 02B3 E61F              ldab 31,x
 02B5 4F                clra
 02B6 BD0069            jsr _PutFifo
 02B9 E721              stab 33,x
 02BB                 L69:
                       ;                 while(flag == 0);   //FIFO full
 02BB 6D21              tst 33,x
 02BD 27F4              beq L68
 02BF                 L71:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy1);
 02BF E61E              ldab 30,x
 02C1 4F                clra
 02C2 BD0069            jsr _PutFifo
 02C5 E721              stab 33,x
 02C7                 L72:
                       ;                 while(flag == 0);   //FIFO full
 02C7 6D21              tst 33,x
 02C9 27F4              beq L71
 02CB                 L74:
                       ; 
                       ;                 do 
                       ;                     flag = PutFifo(dummy2);
 02CB E61D              ldab 29,x
 02CD 4F                clra
 02CE BD0069            jsr _PutFifo
 02D1 E721              stab 33,x
 02D3                 L75:
                       ;                 while(flag == 0);   //FIFO full
 02D3 6D21              tst 33,x
 02D5 27F4              beq L74
                       ;             }
                       ;         }
 02D7 2033              bra L56
 02D9                 L55:
                       ;         else
                       ;         {
                       ;             dummy = dummy1 = 0x30;
 02D9 C630              ldab #48
 02DB E71E              stab 30,x
 02DD C630              ldab #48
 02DF E71F              stab 31,x
                       ;             dummy2 = t1_iteration + 0x30;
 02E1 F60010            ldab _t1_iteration
 02E4 CB30              addb #48
 02E6 E71D              stab 29,x
 02E8                 L77:
                       ; 
                       ;             do 
                       ;                 flag = PutFifo(dummy);
 02E8 E61F              ldab 31,x
 02EA 4F                clra
 02EB BD0069            jsr _PutFifo
 02EE E721              stab 33,x
 02F0                 L78:
                       ;             while(flag == 0);   //FIFO full
 02F0 6D21              tst 33,x
 02F2 27F4              beq L77
 02F4                 L80:
                       ; 
                       ;             do 
                       ;                 flag = PutFifo(dummy1);
 02F4 E61E              ldab 30,x
 02F6 4F                clra
 02F7 BD0069            jsr _PutFifo
 02FA E721              stab 33,x
 02FC                 L81:
                       ;             while(flag == 0);   //FIFO full
 02FC 6D21              tst 33,x
 02FE 27F4              beq L80
 0300                 L83:
                       ; 
                       ;             do 
                       ;                 flag = PutFifo(dummy2);
 0300 E61D              ldab 29,x
 0302 4F                clra
 0303 BD0069            jsr _PutFifo
 0306 E721              stab 33,x
 0308                 L84:
                       ;             while(flag == 0);   //FIFO full
 0308 6D21              tst 33,x
 030A 27F4              beq L83
                       ;         }
 030C                 L56:
                       ;         
                       ; 
                       ;         for(i=0; i<6; i++)
 030C 6F20              clr 32,x
 030E 2027              bra L89
 0310                 L86:
                       ;         {
                       ;             flag = PutFifo(t1_msg2[i]);
 0310 EC00              ldd 0,x
 0312 C30005            addd #5
 0315 ED02              std 2,x
 0317 E620              ldab 32,x
 0319 4F                clra
 031A E302              addd 2,x
 031C 188F              xgdy
 031E 18E600            ldab 0,y
 0321 4F                clra
 0322 BD0069            jsr _PutFifo
 0325 E721              stab 33,x
                       ;             if (flag == 0)  //FIFO full
 0327 6D21              tst 33,x
 0329 2606              bne L90
                       ;                 i--;
 032B E620              ldab 32,x
 032D C001              subb #1
 032F E720              stab 32,x
 0331                 L90:
 0331                 L87:
 0331 E620              ldab 32,x
 0333 CB01              addb #1
 0335 E720              stab 32,x
 0337                 L89:
 0337 E620              ldab 32,x
 0339 C106              cmpb #6
 033B 25D3              blo L86
 033D                 L46:
 033D 7E01D2            jmp L45
 0340                 X0:
                       ;         }
                       ;     }
                       ; }
 0340                 L42:
 0340 8F                xgdx
 0341 C30022            addd #34
 0344 8F                xgdx
 0345 35                txs
 0346 38                pulx
 0347                   .dbline 0 ; func end
 0347 39                rts
                       ;  IX -> 0,x
                       ;  rMEM -> 2,x
                       ;        t1_msg1 -> +5,x
                       ;           flag -> +30,x
                       ;              i -> +31,x
 0348                 _Program02::
 0348 BD0000            jsr __enterb
 034B 20                .byte 0x20
                       ; 
                       ; void Program02(void)
                       ; {
 034C 203A              bra L94
 034E                 L93:
                       ;     //myId=RunPt->Id;       //debugger
                       ;     char i, flag;
                       ;     char t1_msg1[25];
                       ;     
                       ;     while(1)
                       ;     {
                       ;         for(i=0; i<25; i++)
 034E 6F1F              clr 31,x
 0350 2021              bra L99
 0352                 L96:
                       ;         {
                       ;             flag = GetFifo(t1_msg1+i);
 0352 EC00              ldd 0,x
 0354 C30005            addd #5
 0357 ED02              std 2,x
 0359 E61F              ldab 31,x
 035B 4F                clra
 035C E302              addd 2,x
 035E BD00BD            jsr _GetFifo
 0361 E71E              stab 30,x
                       ;             if(flag == 0)   //FIFO empty
 0363 6D1E              tst 30,x
 0365 2606              bne L100
                       ;                 i--;
 0367 E61F              ldab 31,x
 0369 C001              subb #1
 036B E71F              stab 31,x
 036D                 L100:
 036D                 L97:
 036D E61F              ldab 31,x
 036F CB01              addb #1
 0371 E71F              stab 31,x
 0373                 L99:
 0373 E61F              ldab 31,x
 0375 C119              cmpb #25
 0377 25D9              blo L96
 0379 EC00              ldd 0,x
 037B C30005            addd #5
 037E 37                pshb
 037F 36                psha
 0380 CC05A9            ldd #L102
 0383 BD03E2            jsr _Message2
 0386 1838              puly
 0388                 L94:
 0388 20C4              bra L93
 038A                 X3:
                       ;         }   
                       ; 
                       ;         Message2("Thread 2 recieved: ", t1_msg1);
                       ;     }
                       ; }
 038A                 L92:
 038A 8F                xgdx
 038B C30020            addd #32
 038E 8F                xgdx
 038F 35                txs
 0390 38                pulx
 0391                   .dbline 0 ; func end
 0391 39                rts
                       ;  IX -> 0,x
                       ;              i -> +3,x
 0392                 _Program03::
 0392 BD0000            jsr __enterb
 0395 04                .byte 0x4
                       ; 
                       ; void Program03(void)
                       ; {
 0396 2017              bra L105
 0398                 L104:
                       ;     //myId=RunPt->Id;       //debugger
                       ;     char i;
                       ;     while(1)
                       ;     {
                       ;         Message3("Thread 3 is printing");
 0398 CC0594            ldd #L107
 039B BD040C            jsr _Message3
                       ;         for (i=0; i<150; i++)
 039E 6F03              clr 3,x
 03A0 2007              bra L111
 03A2                 L108:
 03A2 01                    nop
                       
 03A3                 L109:
 03A3 E603              ldab 3,x
 03A5 CB01              addb #1
 03A7 E703              stab 3,x
 03A9                 L111:
 03A9 E603              ldab 3,x
 03AB C196              cmpb #150
 03AD 25F3              blo L108
 03AF                 L105:
 03AF 20E7              bra L104
 03B1                 X4:
                       ;             asm("nop");
                       ; 
                       ;     }
                       ; }
 03B1                 L103:
 03B1 08                inx
 03B2 08                inx
 03B3 08                inx
 03B4 08                inx
 03B5 35                txs
 03B6 38                pulx
 03B7                   .dbline 0 ; func end
 03B7 39                rts
                       ;  IX -> 0,x
                       ;            num -> +8,x
                       ;         NamePt -> +4,x
 03B8                 _Message1::
 03B8 37                pshb
 03B9 36                psha
 03BA 3C                pshx
 03BB 3C                pshx
 03BC 30                tsx
 03BD EF00              stx 0,x
                       ; 
                       ; 
                       ; /*******************************************************
                       ; Name: Message
                       ; Purpose: - output message proper message to screen depending
                       ;            on which thread is calling it
                       ; Inputs: none
                       ; Outputs: none
                       ; ********************************************************/
                       ; void Message1(char *NamePt, unsigned int num)
                       ; {
                       ;     Wait(&displayFree);
 03BF CC0011            ldd #_displayFree
 03C2 BD0000            jsr _Wait
                       ;     OutString(NamePt);
 03C5 EC04              ldd 4,x
 03C7 BD0162            jsr _OutString
                       ;     OutUDec(num);
 03CA EC08              ldd 8,x
 03CC BD0129            jsr _OutUDec
                       ;     OutString("\n\r");
 03CF CC0591            ldd #L113
 03D2 BD0162            jsr _OutString
                       ;     Signal(&displayFree);
 03D5 CC0011            ldd #_displayFree
 03D8 BD002C            jsr _Signal
                       ; }
 03DB                 L112:
 03DB 08                inx
 03DC 08                inx
 03DD 35                txs
 03DE 38                pulx
 03DF 1838              puly
 03E1                   .dbline 0 ; func end
 03E1 39                rts
                       ;  IX -> 0,x
                       ;        NamePt2 -> +8,x
                       ;         NamePt -> +4,x
 03E2                 _Message2::
 03E2 37                pshb
 03E3 36                psha
 03E4 3C                pshx
 03E5 3C                pshx
 03E6 30                tsx
 03E7 EF00              stx 0,x
                       ; 
                       ; void Message2(char *NamePt, char *NamePt2)
                       ; {
                       ;     Wait(&displayFree);
 03E9 CC0011            ldd #_displayFree
 03EC BD0000            jsr _Wait
                       ;     OutString(NamePt);
 03EF EC04              ldd 4,x
 03F1 BD0162            jsr _OutString
                       ;     OutString(NamePt2);
 03F4 EC08              ldd 8,x
 03F6 BD0162            jsr _OutString
                       ;     OutString("\n\r");
 03F9 CC0591            ldd #L113
 03FC BD0162            jsr _OutString
                       ;     Signal(&displayFree);
 03FF CC0011            ldd #_displayFree
 0402 BD002C            jsr _Signal
                       ; }
 0405                 L114:
 0405 08                inx
 0406 08                inx
 0407 35                txs
 0408 38                pulx
 0409 1838              puly
 040B                   .dbline 0 ; func end
 040B 39                rts
                       ;  IX -> 0,x
                       ;         NamePt -> +4,x
 040C                 _Message3::
 040C 37                pshb
 040D 36                psha
 040E 3C                pshx
 040F 3C                pshx
 0410 30                tsx
 0411 EF00              stx 0,x
                       ; 
                       ; void Message3(char *NamePt)
                       ; {
                       ;     Wait(&displayFree);
 0413 CC0011            ldd #_displayFree
 0416 BD0000            jsr _Wait
                       ;     OutString(NamePt);
 0419 EC04              ldd 4,x
 041B BD0162            jsr _OutString
                       ;     OutString("\n\r");
 041E CC0591            ldd #L113
 0421 BD0162            jsr _OutString
                       ;     Signal(&displayFree);
 0424 CC0011            ldd #_displayFree
 0427 BD002C            jsr _Signal
                       ; }
 042A                 L115:
 042A 08                inx
 042B 08                inx
 042C 35                txs
 042D 38                pulx
 042E 1838              puly
 0430                   .dbline 0 ; func end
 0430 39                rts
 0431                 _ThreadSwitcher::
                       ; 
                       ; 
                       ; 
                       ; 
                       ; /*******************************************************
                       ; Name: ThreadSwitcher
                       ; Purpose: - Switch threads in a round-robin manner
                       ; Inputs: none
                       ; Outputs: none
                       ; ********************************************************/
                       ; #pragma interrupt_handler ThreadSwitcher()
                       ; void ThreadSwitcher()
                       ; {
                       ;     //OutString("switch...");             //debugger
                       ;     asm(" ldx _RunPt\n"
 0431 FE0000                 ldx _RunPt
 0434 AF02               sts 2,x
                       
                       ;         " sts 2,x");
                       ;     
                       ;     RunPt = RunPt->Next;
 0436 18FE0000          ldy _RunPt
 043A 18EC00            ldd 0,y
 043D FD0000            std _RunPt
                       ;     
                       ;     asm(" ldx _RunPt\n"
 0440 FE0000                 ldx _RunPt
 0443 AE02               lds 2,x
                       
                       ;         " lds 2,x");
                       ;     
                       ;     TOC1 = TCNT + switchtime;  // Thread runs for 10 ms (i.e. if switchtime is 20000)
                         ; vol
 0445 FC100E            ldd 0x100e
 0448 C34E20            addd #20000
 044B FD1016            std 0x1016
                       ;     TFLG1 = 0x80;
 044E C680              ldab #128
 0450 F71023            stab 0x1023
                       ; }
 0453                 L116:
 0453                   .dbline 0 ; func end
 0453 3B                rti
 0454                 _main::
                       ; 
                       ; 
                       ; 
                       ; /*******************************************************
                       ; Name: Main
                       ; Purpose: - initializes system
                       ;          - runs first thread
                       ; Inputs: none
                       ; Outputs: none
                       ; ********************************************************/
                       ; main()
                       ; { 
                       ;     disableInt();       //disable interrupts
 0454 0F                    sei
                       
                       ; 
                       ;     //init vars and FIFO...
                       ;     OutString("\n\r\n\r::[473 lab3-start]::  .:mide & phil:. \n\r\n\r");
 0455 CC0562            ldd #L118
 0458 BD0162            jsr _OutString
                       ;     OutString("Initializing Variables and FIFO...\n\r");
 045B CC053D            ldd #L119
 045E BD0162            jsr _OutString
                       ;     t1_iteration = 0;
 0461 7F0010            clr _t1_iteration
                       ;     InitFifo();
 0464 BD004B            jsr _InitFifo
                       ; 
                       ;     //SCI config...
                       ;     OutString("Initializing SCI...\n\r");
 0467 CC0527            ldd #L120
 046A BD0162            jsr _OutString
                       ;     SCCR1=0;
 046D 7F102C            clr 0x102c
                       ;     SCCR2=0x0c;         // enable SCI
 0470 C60C              ldab #12
 0472 F7102D            stab 0x102d
                       ;     BAUD=0x30;
 0475 C630              ldab #48
 0477 F7102B            stab 0x102b
                       ;     
                       ;     //OC1 config...
                       ;     OutString("Initializing Thread Swithcher...\n\r");
 047A CC0504            ldd #L121
 047D BD0162            jsr _OutString
                       ;     //TOC1vector = &ThreadSwitcher; //not needed here because we are using EEPROM
                       ;     TMSK1 = 0x80;
 0480 C680              ldab #128
 0482 F71022            stab 0x1022
                       ;     TFLG1 = 0x80;
 0485 C680              ldab #128
 0487 F71023            stab 0x1023
                       ;     TOC1 = TCNT + (switchtime*2);
                         ; vol
 048A FC100E            ldd 0x100e
 048D C39C40            addd #0x9c40
 0490 FD1016            std 0x1016
                       ; 
                       ;     //Thread & Semaphore config...
                       ;     OutString("Initializing Threads & Semaphore...\n\r");
 0493 CC04DE            ldd #L122
 0496 BD0162            jsr _OutString
                       ;     displayFree = 1; 
 0499 CC0001            ldd #1
 049C FD0011            std _displayFree
                       ;     RunPt=&sys[0];      //Specify first thread to run
 049F CC0000            ldd #_sys
 04A2 FD0000            std _RunPt
                       ;     asm("  ldx _RunPt\n"
 04A5 FE0000                  ldx _RunPt
 04A8 AE02                lds 2,x
                         
                       
                       ;         "  lds 2,x\n");
                       ;     OutString("\n\r::[System Initialization Complete]::\n\r\n\r");
 04AA CC04B3            ldd #L123
 04AD BD0162            jsr _OutString
                       ;     enableInt();        //enable interrupts
 04B0 0E                    cli
                       
                       ;     asm("rti");         //launch first thread
 04B1 3B                    rti
                       
                       ; }
 04B2                 L117:
 04B2                   .dbline 0 ; func end
 04B2 39                rts
                         .area bss
 0000                 _RunPt::
 0000                   .blkb 2
 0002                 _Fifo::
 0002                   .blkb 10
 000C                 _GETPT::
 000C                   .blkb 2
 000E                 _PUTPT::
 000E                   .blkb 2
 0010                 _t1_iteration::
 0010                   .blkb 1
 0011                 _displayFree::
 0011                   .blkb 2
                         .area text
 04B3                 L123:
 04B3 0A0D3A3A5B53797374656D20496E6974   .byte 10,13,58,58,91,'S,'y,'s,'t,'e,'m,32,'I,'n,'i,'t
 04C3 69616C697A6174696F6E20436F6D706C   .byte 'i,'a,'l,'i,'z,'a,'t,'i,'o,'n,32,'C,'o,'m,'p,'l
 04D3 6574655D3A3A0A0D0A0D00     .byte 'e,'t,'e,93,58,58,10,13,10,13,0
 04DE                 L122:
 04DE 496E697469616C697A696E6720546872   .byte 'I,'n,'i,'t,'i,'a,'l,'i,'z,'i,'n,'g,32,'T,'h,'r
 04EE 6561647320262053656D6170686F7265   .byte 'e,'a,'d,'s,32,38,32,'S,'e,'m,'a,'p,'h,'o,'r,'e
 04FE 2E2E2E0A0D00      .byte 46,46,46,10,13,0
 0504                 L121:
 0504 496E697469616C697A696E6720546872   .byte 'I,'n,'i,'t,'i,'a,'l,'i,'z,'i,'n,'g,32,'T,'h,'r
 0514 656164205377697468636865722E2E2E   .byte 'e,'a,'d,32,'S,'w,'i,'t,'h,'c,'h,'e,'r,46,46,46
 0524 0A0D00            .byte 10,13,0
 0527                 L120:
 0527 496E697469616C697A696E6720534349   .byte 'I,'n,'i,'t,'i,'a,'l,'i,'z,'i,'n,'g,32,'S,'C,'I
 0537 2E2E2E0A0D00      .byte 46,46,46,10,13,0
 053D                 L119:
 053D 496E697469616C697A696E6720566172   .byte 'I,'n,'i,'t,'i,'a,'l,'i,'z,'i,'n,'g,32,'V,'a,'r
 054D 6961626C657320616E64204649464F2E   .byte 'i,'a,'b,'l,'e,'s,32,'a,'n,'d,32,'F,'I,'F,'O,46
 055D 2E2E0A0D00        .byte 46,46,10,13,0
 0562                 L118:
 0562 0A0D0A0D3A3A5B343733206C6162332D   .byte 10,13,10,13,58,58,91,52,55,51,32,'l,'a,'b,51,45
 0572 73746172745D3A3A20202E3A6D696465   .byte 's,'t,'a,'r,'t,93,58,58,32,32,46,58,'m,'i,'d,'e
 0582 2026207068696C3A2E200A0D0A0D00     .byte 32,38,32,'p,'h,'i,'l,58,46,32,10,13,10,13,0
 0591                 L113:
 0591 0A0D00            .byte 10,13,0
 0594                 L107:
 0594 5468726561642033206973207072696E   .byte 'T,'h,'r,'e,'a,'d,32,51,32,'i,'s,32,'p,'r,'i,'n
 05A4 74696E6700        .byte 't,'i,'n,'g,0
 05A9                 L102:
 05A9 54687265616420322072656369657665   .byte 'T,'h,'r,'e,'a,'d,32,50,32,'r,'e,'c,'i,'e,'v,'e
 05B9 643A2000          .byte 'd,58,32,0
 05BD                 L48:
 05BD 54687265616420312049746572617469   .byte 'T,'h,'r,'e,'a,'d,32,49,32,'I,'t,'e,'r,'a,'t,'i
 05CD 6F6E202300        .byte 'o,'n,32,35,0
