Signetics 2650 & 2636 programming/Tutorial code - Interrupts
Appearance
Tutorial code - Interrupts
[edit | edit source]This is the code for the tutorial Interrupts
This code block must be merged with the standard 'Hardware definitions' code before it can be assembled |
; Tutorial - Interrupts ;============================================================================= Reg0 equ $1F0E ;save r0 here during interrupts StatusL equ $1F0F ;save the program status word lower here during interrupts Obj1dup equ $1F1E ;tracks which duplicates have been output org 0 reset_vector: ; the microprocessor starts here when the reset button is pressed bcta,un reset org 3 interrupt_vector: ;Save state of processor when interrupt occured: stra,r0 Reg0 ;preserve r0 ppsl $10 ;bank 1, logical compare spsl stra,r0 StatusL ;save PSL with bank 1 already selected! loda,r0 collisions tmi,r0 vrle ;case bcfr,eq IVdup1 ; interrupt caused by VRLE bsta,un Object1A ; set initial state of object 1 bcta,un IVend ; quit interrupt routine IVdup1: ; loda,r0 Obj1dup ; comi,r0 1 ; next duplicate is the first bcfr,eq IVdup2 bsta,un Object1B ; set first duplicate of object 1 bcta,un IVend ; quit interrupt routine IVdup2: ; loda,r0 Obj1dup ; comi,r0 2 ; next duplicate is the second bcfr,eq IVend bsta,un Object1C ; set second duplicate of object 1 IVend: ;Restore processor to state it was in before interrupt: loda,r0 StatusL strz r4 ;put a copy of PSL in r4 lpsl ;restores psl (but with bank 1 still selected) loda,r0 Reg0 ;restore r0 (but probably changes the condition code) andi,r4 $C0 ;this restores the condition code! cpsl $10 ;switch to bank 0 rete,un ;exit interrupt routine ;====================================================================================== reset: lodi,r0 intinhibit ; initialise program status word lpsu ; inhibit interrupts, stack pointer=0 lpsl ; register bank 0, without carry, arithmetic compare eorz r0 stra,r0 effects ; initialise the 74LS378 bsta,un DefineUnused ; push all unused objects offscreen lodi,r0 $AA ; blank the score digits stra,r0 score12 stra,r0 score34 lodi,r0 %00000000 ; X / 000 / 0 / 000 stra,r0 backgnd ; / black background / disabled / black screen spsl compare ; logical compares cpsu intinhibit ; enable interrupts endless: nop ; this is the main program loop nop ; the processor is free to perform other tasks nop ; in between servicing PVI interrupts bctr,un endless ;================================================================== ; subroutine - Primary object ; set initial state of object 1: shape, colour, size, HC,VC ; and HCB,VCB for first duplicate, B Object1A: lodi,r3 10 lodi,r0 $FF loop1A: stra,r0 shape1,r3- ; rectangle shape brnr,r3 loop1A stra,r3 objectsize ; size 0 lodi,r0 $07 ; white stra,r0 colours12 lodi,r0 10 stra,r0 vc1 ; vc = 10 rrl,r0 stra,r0 vcb1 ; vcb = 20 rrl,r0 stra,r0 hc1 ; hc = 40 rrl,r0 stra,r0 hcb1 ; vcb = 80 lodi,r0 1 stra,r0 Obj1dup ;next to draw is the first duplicate retc,un ;================================================================== ; subroutine - First duplicate ; set: shape, colour, size ; and VCB for second duplicate Object1B: lodi,r3 10 lodi,r0 $FF ppsl withcarry ; include carry in rotate instructions loop1B: stra,r0 shape1,r3- ; triangle shape cpsl carrybit rrr,r0 ; shift right with 0 from the carry bit brnr,r3 loop1B lodi,r3 1 stra,r3 objectsize ; size 1 lodi,r0 $08 ; yellow stra,r0 colours12 lodi,r0 80 stra,r0 vcb1 ; vcb = 80 lodi,r0 2 stra,r0 Obj1dup ;next to draw is the second duplicate retc,un ;================================================================== ; subroutine - Second duplicate ; set: shape, colour, size, HCB ; and VCB to push next duplicate off screen Object1C: lodi,r3 10 lodi,r0 $FF ppsl withcarry ; include carry in rotate instructions loop1C: stra,r0 shape1,r3- ; triangle shape cpsl carrybit rrl,r0 ; shift left with 0 from the carry bit brnr,r3 loop1C lodi,r3 2 stra,r3 objectsize ; size 2 lodi,r0 $28 ; green stra,r0 colours12 lodi,r0 250 stra,r0 vcb1 ; make sure there are no more duplicates lodi,r0 60 stra,r0 hcb1 ; hcb = 60 lodi,r0 0 stra,r0 Obj1dup ;next to draw is the primary object retc,un ;=================================================================== ; subroutine - define position of unused objects DefineUnused: lodi,r0 254 stra,r0 vc2 ; push unused objects offscreen stra,r0 vc3 stra,r0 vc4 lodi,r0 $FF ; set all objects black stra,r0 colours12 stra,r0 colours34 retc,un