📄 chap4.asm
字号:
tpa tab pula pshb save old CCR sei make atomic, entering critical section ldab Size cmpb #FifoSize Full if Size==FifoSize beq PutNotFull clra bra PutDonePutNotFull incb stab Size Size++ ldx #Fifo ldab PutI abx staa 0,x Put data into fifo incb cmpb #FifoSize bne PutNoWrap skip if no wrapping needed clrb Wrap PutNoWrap clra sucess coma RegA=-1 means OK stab PutIPutDone tab end critical section pula tpa restore CCR to previous value tba rts; Program 4.25. Assembly routine to get from a two index with counter FIFO. ***********Get a byte from the FIFO******************* Input RegX points to place for 8 bit data from Get* Output RegA is -1 if successful, 0 if Fifo was empty when calledGetFifo tpa psha save old CCR sei make atomic, entering critical section clra assume it will fail tst Size beq GetDone ldy #Fifo ldab GetI aby coma RegA=-1 means OK ldab 0,y Data from FIFO stab 0,x Return by reference ldab GetI incb cmpb #FifoSize bne GetNoWrap skip if no wrapping needed clrb Wrap GetNoWrap stab GetIGetDone tab end critical section pula tpa restore CCR to previous value tba rts; Program 4.27. Example of a vectored interrupt. ; MC68HC11A8TimeHan ldaa #$80 ;TOF is bit 7 staa TFLG2 ;clear TOF;*Timer interrupt calculations* rtiExtHan ldaa PIOC ldaa PORTCL ;clear STAF;*External interrupt calculations* rti org $FFDE ;timer overflow fdb TimeHan org $FFF2 ;IRQ external fdb ExtHan; Program 4.28. Example of a polled interrupt. ; MC68HC11A8ExtHan ldaa PIOC ;which one bita #$80 ;STAF? bne STAFHan ldaa OtherStatus1 bita #$80 ;External? bne OtherHan swi ;errorSTAFHan ldaa PORTCL ;clear STAF;*STAF interrupt calculations* rtiOtherHan ldaa OtherData;*Other interrupt calculations* rti org $FFF2 ;IRQ external fdb ExtHan; Program 4.29. Interrupting keyboard software. ; MC68HC11A8; PC6-PC0 inputs = keyboard DATA; STRA=STROBE interrupt on rise; 6 STAI 1 Interrupts armed; 5 CWOM 0 Normal outputs; 4 HNDS 0 No handshake; 3 OIN 0; 2 PLS 0 STRB not used; 1 EGA 1 STAF set on rise of READY; 0 INVB 0 STRB not used Init sei ;Make this atomic ldaa #$80 ;PC7 is an output staa DDRC ;PC6-0 inputs ldaa #$42 staa PIOC ldaa PIOC ;clears STAF ldaa PORTCL clr PORTC ;Make PC7=0 jsr InitFifo cli ;Enable IRQ rtsExtHan ldaa PIOC ;poll STAF bmi KeyHan swi ;errorKeyHan ldaa PORTCL ;clear STAF jsr PutFifo rti org $FFF2 ;IRQ external fdb ExtHan; Program 4.31. Helper routines for the printer interface. ; MC68HC11A8;*****goes in RAM**************OK rmb 1 ;0=busy, 1=doneLine rmb 20 ;ASCII, end with 0Pt rmb 2 ;pointer to Line;*****goes in ROM**************;Input RegX=>stringFill ldy #Line ;RegX=>string sty Pt ;initialize pointerFloop ldaa 0,X ;copy data staa 0,Y inx iny tsta ;end? bne Floop clr OK rts;Return RegA=dataGet ldx Pt ldaa 0,X ;read data inx stx Pt rts; Program 4.32. Initialization routines for the printer interface. ; MC68HC11A8; PC6-PC0 outputs = printer DATA; STRA=READY interrupt on rise; 6 STAI 1 Interrupts armed; 5 CWOM 0 Normal outputs; 4 HNDS 1 Output handshake; 3 OIN 1; 2 PLS 1 START=STRB pulse; 1 EGA 1 STAF set on rise of READY; 0 INVB 0 STRB not used ;Input RegX=>stringInit sei ;Make this atomic bsr Fill ;Init global ldaa #$FF ;PC7 is an output staa DDRC ;PC6-0 outputs ldaa #$5E staa PIOC bsr Get ;start first staa PORTCL cli ;Enable IRQ rts; Program 4.33. ISR routines for the printer interface. ; MC68HC11A8ExtHan ldaa PIOC ;poll STAF? bmi PrtHan swi ;errorPrtHan bsr Get tsta beq Disarm staa PORTCL ;start next bra Done Disarm ldaa #$1E ;STAI=0 staa PIOC inc OK ;line completeDone rti org $FFF2 ;IRQ external fdb ExtHan; Program 4.35. Assembly software for the XIRQ interrupt. * Called to initialize the power systemRITUAL ldaa #0 Backup power initially off staa PORTB Set the flip flop, make XIRQ=1 ldaa #1 staa PORTB Flip flop ready to receive rising edge of TooLow ldaa #$10 Enable XIRQ, Disable IRQ tap rts Back to main, foreground thread*Note that the software can only enable XIRQ and can not disable XIRQ.* In this way, XIRQ is non-maskable.XIRQHAN ldaa #2 staa PORTB Enable BackUp power, acknowledge XIRQ ldaa #3 staa PORTB Will thread another rising edge of TooLow rti org $FFF4 fdb XIRQHAN XIRQ interrupt vector; Program 4.37. 6811 assembly structure for interrupt polling using linked lists. start fdb llSTAF place to start pollingSreg equ 0 Index to Status RegisterAmask equ 2 and maskCmask equ 3 compare maskDevHan equ 4 device handlerNextPt equ 6 next pointernum fcb 3 number of devicesllSTAF fdb $1002 address of PIOC fcb $ff look at all the bits in PIOC fcb $C0 expect exact match with $C0 fdb STAFhan device handler fdb llCA1 pointer to next device to pollllCA1 fdb $2011 address of 6821 Port A Control/Status fcb $87 look at bits 7,2,1,0 fcb $85 expect bits 7,2,1,0 to be 1,1,0,1 fdb CA1han device handler for CA1 fdb llCB2 pointer to next device to pollllCB2 fdb $2013 address of 6821 Port B Control/Status fcb $7C look at bits 6,5,4,3,2 fcb $4C expect bits 6,5,4,3,2 to be 1,0,0,1,1 fdb CB2han device handler for CB2 fdb 0 no more; Program 4.38. 6811 assembly implementation of interrupt polling using linked lists. IrqHan ldx start Reg X points to linked list place to start ldab num number of possible devicesnext ldy Sreg,x Reg Y points to status reg ldaa ,y read status anda Amask,x clear bits that are indeterminate cmpa Cmask,x expected value if this device active bne Notyet skip if this device not requesting ldy DevHan,x Reg Y points to device handler jsr ,y call device handler, will return hereNotyet ldx NextPt,x Reg X points to next entry decb device counter bne next check next device rti ; Program 4.45. 6811 assembly implementation of a periodic interrupt using an external clock. TIME rmb 2 incremented every 1msRITUAL sei disable interrupts during RITUAL ldaa #$42 PIOC STAI=1, HNDS=0, EGA=1 staa $1002 Arm interrupt on rise of STRA ldd #0 std TIME initialize variable ldaa $1005 initially clear STRA cli enable rts* POLL for zeros and ones IRQHAN ldaa $1002 11000010 if interrupting cmpa #$C2 beq CLKHAN swiCLKHAN ldaa $1005 Acknowledge ldx TIME inx stx TIME rti; Program 4.46. 6811 assembly implementation of a periodic interrupt using real time interrupt. RITUAL sei disable interrupts during RITUAL ldaa #3 Set RTR1,RTR0 = 11 Interrupt period = 32.768ms staa $1026 ldaa #$40 Set RTII=1 staa $1024 cli Enable IRQ interrupts rtsRTIHAN ldaa $1025 Polling for zeros and ones expect=X1XX0000 anda #$4F ignore TOF, PAOVF, and PAIF cmpa #$40 RTIF should equal 1 beq OK swi ErrorOK ldaa #$40 RTIF is cleared by writing to TFLG2 staa $1025 with bit 6 set* service occurs every 32.768ms or about 30.517Hz rti 1 This other device could be a 6821 parallel port connected to the 6811 in expanded mode.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -