************************* GLOBAL LABELS ***************************************
_IRAM   EQU   $0000       Internal RAM $0000..$00FF (256byte).
_PORTA  EQU   $1000       Port A Data register.
_PIOC   EQU   $1002       Parallel I/O Control Register.
_PORTC  EQU   $1003       Port C Data register.
_PORTB  EQU   $1004       Port B Data register.
_PORTCL EQU   $1005       PPort C Alternate Latched.
_DDRC   EQU   $1007       Port C Data Direction Register.
_PORTD  EQU   $1008       Port D Data Register.
_DDRD   EQU   $1009       Port D Data Direction Register.
_PORTE  EQU   $100A       Port E Data Register.
_CFROC  EQU   $100B       Timer: Compare Force.
_OC1M   EQU   $100C       Timer: Output Compare 1 Mask.
_OC1D   EQU   $100D       Timer: Output Compare 2 Data.
_TCNT   EQU   $100E       Timer: 16 bit free running counter.
_TIC1   EQU   $1010       Timer: Input Capture Register 1.
_TIC2   EQU   $1012       Timer: Input Capture Register 2.
_TIC3   EQU   $1014       Timer: Input Capture Register 3.
_TOC1   EQU   $1016       Timer: Output Compare Register 1.
_TOC2   EQU   $1018       Timer: Output Compare Register 2.
_TOC3   EQU   $101A       Timer: Output Compare Register 3.
_TOC4   EQU   $101C       Timer: Output Compare Register 4.
_TOC5   EQU   $101E       Timer: Output Compare Register 5.
_TCTL1  EQU   $1020       Timer: Control Register 1.
_TCTL2  EQU   $1021       Timer: Control Register 2.
_TMSK1  EQU   $1022       Timer: Interrupt Mask Register 1.
_TFLG1  EQU   $1023       Timer: Interrupt Flag Register 1.
_TMSK2  EQU   $1024       Timer: Interrupt Mask Register 2.
_TFLG2  EQU   $1025       Timer: Interrupt Flag Register 2.
_PACTL  EQU   $1026       Timer: Pulse Accumulator Control.
_PACNT  EQU   $1027       Timer: Pulse Accumulator Count Register.
_SPCR   EQU   $1028       SPI: Control Register.
_SPSR   EQU   $1029       SPI: Status Register.
_SPDR   EQU   $102A       SPI: Data Register.
_BAUD   EQU   $102B       SCI: Baud Rate Register.
_SCCR1  EQU   $102C       SCI: Control Register 1.
_SCCR2  EQU   $102D       SCI: Control Register 2.
_SCSR   EQU   $102E       SCI: Status Register.
_SCDR   EQU   $102F       SCI: Data Register.
_ADCTL  EQU   $1030       A/D: Control Register.
_ADR1   EQU   $1031       A/D: Result Register 1.
_ADR2   EQU   $1032       A/D: Result Register 2.
_ADR3   EQU   $1033       A/D: Result Register 3.
_ADR4   EQU   $1034       A/D: Result Register 4.
_OPTION EQU   $1039       System Configuration Option.
_COPRST EQU   $103A       Arm/Reset COP Timer Circuitry.
_PPROG  EQU   $103B       EEPROM Programming Register.
_HPRIO  EQU   $103C       Highest Priority I bit.
_INIT   EQU   $103D       RAM and I/O Mapping Register.
_TEST1  EQU   $103E       Testing Functions Control Register.
_CONFIG EQU   $103F       System Configuration.
_DPRA   EQU   $1800       PIA: Data direction / Periferial register A.
_CRA    EQU   $1801       PIA: Control register A.
_DPRB   EQU   $1802       PIA: Data direction / Periferial register B.
_CRB    EQU   $1803       PIA: Control register B.
_XRAM   EQU   $2000       External RAM $2000..$3FFF (8192byte).
_EEPROM EQU   $B600       Internal EEPROM $B600..$B7FF (512byte).
_EPROM  EQU   $E000       User EPROM $E000..$FFFF (8192byte).
 

************************* HC11 INTERRUPT VECTORS ******************************
_ISCI   EQU   $FFD6       Serial Communication Interface (SCI)
_ISPI   EQU   $FFD8       Serial Peripherial Interface (SPI)
_IPAIE  EQU   $FFDA       Pulse Accumulator Input Edge
_IPAO   EQU   $FFDC       Pulse Accumulator Overflow
_ITOF   EQU   $FFDE       Timer Overflow
_ITOC5  EQU   $FFE0       Timer Output Compare 5
_ITOC4  EQU   $FFE2       Timer Output Compare 4
_ITOC3  EQU   $FFE4       Timer Output Compare 3
_ITOC2  EQU   $FFE6       Timer Output Compare 2
_ITOC1  EQU   $FFE8       Timer Output Compare 1
_ITIC3  EQU   $FFEA       Timer Input Capture 3
_ITIC2  EQU   $FFEC       Timer Input Capture 2
_ITIC1  EQU   $FFEE       Timer Input Capture 1
_IRTI   EQU   $FFF0       Real Time Interrupt (RTI)
_IIRQ   EQU   $FFF2       IRQ Pin
_IXIRQ  EQU   $FFF4       XIRQ Pin (Pseudo Non-Maskable Interrupt)
_ISWI   EQU   $FFF6       Software Interrupt (SWI)
_IILLOP EQU   $FFF8       Illegal Opcode Trap
_ICOP   EQU   $FFFA       COP Failure (Reset)
_ICLKM  EQU   $FFFC       Clock Monitor Fail (Reset)
_IRESET EQU   $FFFE       Reset

************************* INTERRUPT VECTOR TABLE ******************************
 ORG   _ITOC1      Set Output Compare 1 interrupt
 FDB   _SCHINT        to the scheduler interrupt rutine.
   ORG   _IRESET     Upon reset
  FDB   _START         go to START.
 

 ORG   _EPROM


************************* TASK SCHEDULE ***************************************
SCHTAB   FDB   STEJ Štetje impulzov dajalnika ( dolo?anje pozicije )
 FDB   SCI     Serijska komunikacija
 FDB   SCHRTS     Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   STEJ Štetje impulzov dajalnika ( dolo?anje pozicije )
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   STEJ Štetje impulzov dajalnika ( dolo?anje pozicije )
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   STEJ Štetje impulzov dajalnika ( dolo?anje pozicije )
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5
 FDB   SCHRTS      Void task.             ~ =  5

SCHRTS rts               Void task.
 

************************* THE SCHEDULER INTERRUPT RUTINE (~=80) ***************
_SCHINT     brclr     SCHTST $01 SCHERR  6 Branch if previous interrupt running.
                      inc   SCHTST          6 Set test bit to indicate running interrupt.
                      ldd   _TOC1       5 Load timer output compare register 1,
                      addd  #1200       4    increment it by time slice
                     std   _TOC1       5    and restore it to TOC1.
                     ldx   SCHPTR      5 Get pointer to current 1/64s period task.
                      ldx   0,X         5 Get the task's entry address.
                     ldaa  #$80        2 Clear currently pending
                     staa  _TFLG1      4    OC1F interrupt and
                     cli               2    allow interrupts.
                     jsr   0,X         6 EXECUTE THE TASK.
                     ldaa  SCHPTR+1    4 Get high byte of SCHPTR,
                     adda  #2          2    increment it,
                     anda  #%00011110  2    overlay 0's
                     staa  SCHPTR+1    4    and restore it to SCHPTR.
                     clr   SCHTST      6 Reset test bit to indicate end of interrupt.
                     rti               12 Return from OC1 interrupt
SCHERR  bra   SCHERR      Fatal error, can't continue!
 
 

************************* ENABLE THE SCHEDULER ********************************
SCHON   clr   SCHTST      6 Reset test bit to indicate no interrupt running.
                 ldx   #SCHTAB     3 Initialize pointer
                 stx   SCHPTR      5    to first 1/64s period tasks.
                 ldd   _TCNT       5 Load free running counter
                 addd  #1200       4    increment it by time slice
                 std   _TOC1       5    and store it to output compare register 1.
                 ldaa  #$80        2 Select OC1,
                 staa  _TFLG1      4    clear any pending OC1F,
                 staa  _TMSK1      4    enable OC1 interrupt and
                 cli               2    start interrupts.
                 rts               5 Return(Scheduler running).
 

************************* TIMER TASK (~<=77) **********************************
*  This is a real-time clock driver. TIM should be placed into the task
*  schedule at a 1/256 second duty cycle. TIM updates four global variables
*  TIMH (Hours 0..23), TIMM (minutes 0..59), TIMS (seconds 0..59) and
*  TIMF (second fractions 0..255).
*******************************************************************************
TIM      inc   TIMF        6 Increment fraction counter,
             bne   TIMRTS      3 Branch down if no overflow
             inc   TIMS        6 Increment second counter,
             ldaa  TIMS        4    load it to A
             cmpa  #60         2    and compare with 60.
             bcs   TIMRTS      3 Branch down if no overflow
             clr   TIMS        6    and reset second counter otherwise.
             inc   TIMM        6 Increment minute counter,
             ldaa  TIMM        4    load it to A
             cmpa  #60         2    and compare with 60.
             bcs   TIMRTS      3 Branch down if no overflow
             clr   TIMM        6    and reset minute counter otherwise.
             inc   TIMH        6 Increment hour counter,
             ldaa  TIMH        4    load it to A
             cmpa  #24         2    and compare with 24.
             bcs   TIMRTS      3 Branch down if no overflow
             clr   TIMH        6    and reset hour counter otherwise.
TIMRTS  rts               5 Return().
 
 

************************* SYNCHRONIZE WITH SCHEDULER **************************
*  Call this subroutine from any non-realtime routine to request D<1100
*  uninterrupted subsequent maschine cycles. Upon return, you have the
*  requested number of uninterrupted cycles, plus D extra cycles. Use D=0 to
*  find out the number of cycles left until next scheduler interrupt.
*******************************************************************************
SCHSYN  pshx              4  Push X.
 addd  #$0020      4  Add the system overhead of 32 machine cycles.
         pshb              3  Push number of machine cycles
         psha              3     from D to stack
         tsx               3     and make X point to it.
SCHWAI  ldd   _TOC1       4  Load output compare register,
         subd  _TCNT       5     subtract free running counter
         subd  0,X         6     and number of cycles.
         bmi   SCHWAI      3  Loop back if not enough cycles until interrupt.
         pulx              5  Dummy pull X to clear D from stack.
         pulx              5  Restore X.
         rts               5  Return(D=extra cycles left).
 
************************* RESET ***********************************************
_START  lds   #$3FFF      Define stack segment.
                  jsr   INIT        Initialize RAM variables.
                 jsr   SCHON       Start scheduler.
                 jsr   STRUP
                 jsr   MAIN        Call MAIN -- there should be no return.
   HALT    bra   HALT        Dead loop!
 

************************* INITIALIZE RAM VARIABLES ****************************
INIT     ldx   #$0000      Clear
             stx   TIMH           hours, minutes,
             stx   TIMS           seconds and fractions.
             ldx   #SKLADB+2     Clear the
             stx   SKLADB           skladisce
             stx   SKLADE           buffer.
             ldx   #TRAB+2     Clear the
             stx   TRAB           SCI transmitting
             stx   TRAE           buffer.
             ldx   #RECB+2     Clear the
             stx   RECB           SCI receiveing
             stx   RECE           buffer.
             clr   _CRA        Enable Data direction register A and
             clr   _CRB           Data direction register B.
             ldaa  #%00111111     Dolo?iš spodnjih šest bitov A
             staa  _DPRA           za izhode 7 in 8 vhod
             ldaa  #$00        Set all bits of port B
             staa  _DPRB          to output.
             ldaa  #$04        Enable Data registers
             staa  _CRB
             ldaa  #%00110100           of port A and
             staa  _CRA           port B.
             ldaa  #%00001110  Initialize port A
             staa  _DPRA          to activate
             clr   _DPRB       Clear port B.
             ldaa  _OPTION     Get system options,
             oraa  #%10000000     set A/D power on
             staa  _OPTION        and store options.
             ldaa #$0A
             staa _SCSR
             clr NOVPOD Resetiranje spremenljivk
             clr SPRMAG
             clr PRISEL
             clr FORZANKA
             clr KOCKA
             clr SMER
             clr NOVAKCK
             clr ISCIPRE
             jsr BRISNAD1
             ldaa #06  Dolo?anje števila mest
             staa STMEST    v nadstropju
             ldy #BRISTER Brisi terminalsko okno
             sty IZPISI
             jsr TRASTR
             rts               Return().
*******************************************************************************

************************   MAIN PROGRAM   *************************************
MAIN  jsr RECSTR sko?i na podprogram za sprejem znakov
             jsr LOGIST sko?i na podprogram za logistiko
             bra  MAIN

********************************************************************************

BRISTER  FCB $0D,$0C,$00     tabela za brisanje terminala CR LF

POZX fdb $003B,$003B,$003B,$005E,$005E,$005E,$0082,$0082,$0082,$0010
*POZY fcb $0D,$00,$30,$00,$52,$00,$52,$00,$30,$00,$0D,$00,$0D,tovornjak je 0136
POZY fdb $0D00,$3000,$5200,$5200,$3000,$0D00,$0D00,$3000,$5200,$0000

**********************   PREIZKUSNA RUTINA ZA LOKACIJO   ***********************
LOKPRB   ldx #POZX
                   ldb FORZANKA
                 abx
                 ldd 0,X
                 stad KOORX
                 ldy #POZY
                 ldb FORZANKA
                 aby
                 ldab 0,Y
                 stab KOORY
                 clr PRISEL
                 ldaa FORZANKA
                 inca
                 inca
                 cmpa #$12
                 bne MIMO
                 ldaa #$00
    MIMO staa FORZANKA
                 ldaa #$01
                 staa STANJEX
                 staa STANJEY
LOOP jsr PREMIK
                 ldaa PRISEL
                 beq LOOP
                 jsr GORDOL
                 rts
********************************************************************************
 

************************* START UP POZICIJA *********************************
STRUP    ldab    #%00010000 magnet v zgornjo pozicijo
         stab    _DPRA
STRGOR1  ldaa    _DPRB
         anda    #%00010000
         bne     STRGOR1
         ldaa    #0
         staa    _DPRA

STRPEL ldab _DPRB  preverja ali je desno stikalo vklopljeno
         andb #%00000010  pogleda, ?e je dosegel izhodiš?e po X osi
         beq IZKLOPX  ?e je bit postavljen sko?i na IZKLOPX
         ldaa #%00000010  druga?e pa premika naprej po X-osi
         staa _DPRA
IZKLOPX  ldab _DPRB preveri, ?e je stikalo nazaj vklopljeno
         andb #%00000100 pogleda, ?e je dosegel izhodiš?e po Y osi
         beq OBA  ?e je sko?i na OBA
         ldaa #%00000100   druga?e pa premika naprej po Y-osi
         staa _DPRA
OBA ldab _DPRB preveri stikalo desno in nazaj
         andb #%00000110   ?e katerikoli ni izklopljen
         bne STRPEL sko?i na za?etek
         ldaa #$00 druga?e pa ustavi oba motorja
         staa _DPRA
 
         staa STEVECY resetira števec impulzov po Y osi
         ldx #$0000
         stx STEVECX resetira števec impulzov po X osi
         staa STANJEX resetira STANJEX
         staa STANJEY resetira STANJEY
KONEC rts
********************************************************************************
 

************************   SERIJSKA  KOMUNIKACIJA    ***************************
SCI       pshy
             pshx
             psha
             pshb
             ldaa _SCSR
             tab
             anda #%11000000 preveri ali lahko oddaja
             beq SCISPR
             ldx TRAB
             cpx TRAE
             beq SCISPR buffer prazen -> sprejem
             ldaa 0,X
             staa _SCDR
             inx
             cpx #TRAE
             bne SCIZAK
             ldx #TRAB+2
SCIZAK stx TRAB
 
SCISPR tba
             anda #%00100000 preveri ali lahko sprejema
             beq SCIKONC
             ldaa _SCDR
             ldx RECE
             staa 0,X
             cmpa #$0D
             bne RECMIM
             clr NOVPOD
             ldy #BRISTER
             sty IZPISI
             jsr TRASTR
             bra RECMIM1
RECMIM jsr TRACHR

 
RECMIM1 inx
             cpx #RECE
             bne SCIZAK2
             ldx #RECB+2
SCIZAK2  cpx RECB
             beq SCIKONC
             stx RECE

SCIKONC pulb
             pula
             pulx
             puly
             rts
********************************************************************************
 

**************************   SPREJME ZNAK   ************************************
RECCHR pshx
             pshb
             ldx RECB  preveri ?e je buffer prazen
             cpx RECE
             beq RECKONC
             ldaa 0,X  v A naloži prvi znak
             inx
             cpx #RECE preveri ?e je na fizi?nem koncu bufferja
             bne REC1  *skok
             ldx #RECB+2
REC1 ldab #$01 postavi flag NOVPOD
             stab NOVPOD
             stx RECB

RECKONC pulb
             pulx
             rts

********************************************************************************

**************************   SPREJME STRING   **********************************
RECSTR ldab NOVAKCK  ali lahko sprejme nov ukaz
             bne RSKNC
RSZAC jsr RECCHR
             beq RSKNC
             cmpa #$0D  *Preveri ?e je pritisnjen enter
             beq PRENT
             cmpa #$08
             beq PRBKS  *Preveri ?e je pritisnjen back space
             ldab SMER
             bne RSKCK  preveri ali že ima SMER dolo?eno
             cmpa #'n
             bne RSVN
             staa SMER  dolo?i smer noter ?e je pritisnjen n
             clr KOCKA
             bra RSKNC
RSVN cmpa #'N
             bne RSVEN
             ldaa #'n
             staa SMER  dolo?i smer noter ?e je pritisnjen N
             clr KOCKA
             bra RSKNC

RSVEN cmpa #'v
             bne RSVV
             staa SMER  dolo?i smer ven ?e je pritisnjen v
             clr KOCKA
             bra RSKNC
RSVV cmpa #'V
             bne RSKNC
             ldaa #'v
             staa SMER  dolo?i smer ven ?e je pritisnjen V
             clr KOCKA
             bra RSKNC
RSKCK ldab KOCKA
             bne RSDRG
    * for i=0 to a
             suba #$30   dolo?i številko kocki - desetice
             ldab #$01
             stab KOCKA
             beq RSDRG
RSSTJ ldab #10
             addb KOCKA
             stab KOCKA
             deca
             bne RSSTJ
             bra RSKNC

RSDRG suba #$30   dolo?i številko kocki - enice
             deca
             adda KOCKA
             staa KOCKA
             bra RSKNC
 
PRBKS clr SMER   ?e je back space briše vse
             clr KOCKA
             clr NOVAKCK
             bra RSKNC
 
PRENT ldaa #$01  ?e je enter sprejme ukaz
             staa NOVAKCK
 
RSKNC rts
 

********************************************************************************
 

**************************   ODDAJ ZNAK   **************************************

TRACHR pshy  odda znak
             pshx
             psha
             pshb
             ldx TRAE
             staa 0,X
             inx
             cpx #TRAE
             bne TRACHR1
             ldx #TRAB+2
TRACHR1 cpx TRAB
             beq TRACKNC
             stx TRAE

TRACKNC pulb
             pula
             pulx
             puly
             rts
********************************************************************************

************************   ODDAJ STRING     ************************************
TRASTR pshx
             psha
             pshb
             ldaa NOVPOD
             bne TRSKNC
             ldy IZPISI
TRSNAZ ldaa 0,y
             beq TRSKNC
             jsr TRACHR
             iny
             bra TRSNAZ
TRSKNC ldaa #$01
             staa NOVPOD
             pulb
             pula
             pulx
             rts
 

STRING FCB $0C,$0D
 FCC "VNESI NOVE PODATKE IN JIH POTRDI Z ENTER"
 FCB $0A,$00
********************************************************************************
 

************************   STETJE IMPULZOV  ************************************
STEJ     pshy
             psha
             pshb
             pshx
**stej premike po X osi ( levo, desno )
             ldaa _DPRA
             anda #%01000000
             bne NEKAMX *sko?i ?e je AX=1
             ldab _DPRB
             andb #%01000000
             bne NEKAMX1 *AX=0 sko?i ?e je BX=1
             clr LEVO
             clr DESNO
             clr PREJX
             bra GLEJY

NEKAMX ldab _DPRB
             andb #%01000000
             bne INCDECX *AX=1 sko?i ?e je BX=1
             ldaa #%00000001
             staa DESNO
             bra GLEJY

NEKAMX1 ldaa #%00000001
             staa LEVO
             bra GLEJY
 
INCDECX  tst PREJX
             bne GLEJY
             ldaa #%00000001
             staa PREJX
             tst DESNO
             beq VECAJX
             ldx STEVECX
             dex
             stx STEVECX
             bra GLEJY
VECAJX ldx STEVECX
             inx
             stx STEVECX
 

GLEJY ldaa _DPRA
             anda #%10000000
             bne NEKAMY *sko?i ?e je AY=1
             ldab _DPRB
             andb #%10000000
             bne NEKAMY1 *AY=0 sko?i ?e je BY=1
             clr NAPREJ
             clr NAZAJ
             clr PREJY
             bra KNCSTEV

NEKAMY ldab _DPRB
             andb #%10000000
             bne INCDECY *AY=1 sko?i ?e je BY=1
             ldaa #%00000001
             staa NAZAJ
             bra KNCSTEV

NEKAMY1 ldaa #%00000001
             staa NAPREJ
             bra KNCSTEV
 
INCDECY  tst PREJY
             bne KNCSTEV
             ldaa #%00000001
             staa PREJY
             tst NAZAJ
             beq VECAJY
             dec STEVECY
                  bra KNCSTEV
VECAJY inc STEVECY
 
KNCSTEV pulx
             pulb
             pula
             puly
             rts
******************************************************************************
 

*******************************  PREMIK PO OSEH   *****************************

PREMIK psha
             pshb
             pshx
*Najprej gleda x os
             ldaa STANJEX
             beq KNCXGLJY
             ldd KOORX
             subd STEVECX
             beq GASIX
             bpl GRELEVO
             ldaa #$02
             staa _DPRA
             staa STANJEX
             bra KNCXGLJY
GRELEVO  ldaa #$01
             staa _DPRA
             staa STANJEX
              bra KNCXGLJY
GASIX    ldaa #$00
              staa _DPRA
              staa STANJEX

KNCXGLJY ldaa STANJEY
              beq KNCYGLJV
              ldaa KOORY
              suba STEVECY
              beq GASIY
              bpl GRENAPREJ
              ldaa #$04
              staa STANJEY
              adda STANJEX
              staa _DPRA
              bra KNCYGLJV
GRENAPREJ ldaa #$08
              staa STANJEY
              adda STANJEX
              staa _DPRA
              bra KNCYGLJV
GASIY    ldaa #$00
              staa STANJEY
              adda STANJEX
              staa _DPRA
              bne KNCYGLJV
              ldab #$01
              stab PRISEL
              stab STANJEX
              stab STANJEY
KNCYGLJV ldaa STANJEX
              bne KNVEN
              ldaa STANJEY
             bne KNVEN
              ldaa #$01
              staa PRISEL
KNVEN pulx
              pulb
              pula
              rts
********************************************************************************
 

*******************************   PREMIK GOR DOL   *****************************
GORDOL  ldab    #%00100000
        stab    _DPRA
MAGDOL  ldaa    _DPRB           ;KO JE DVIGALO SPUŠ?ENO NADALJUJEMO
        anda    #%00100000
        bne     MAGDOL
        ldaa    #%00000000
        staa    _DPRA
        ldaa    SPRMAG
        bne     MAGNPR
        ldaa    _CRA
        oraa    #%00001000      ;VKLU?IMO MAGNET
        staa    _CRA
        ldaa    #1
        staa    SPRMAG
        bra     MAGGOR
MAGNPR  ldaa    _CRA
        anda    #%11110111      ;ALI IZKLU?IMO MAGNET
        staa    _CRA
        clr     SPRMAG
MAGGOR  ldab    #%00010000
        stab    _DPRA
MAGGOR1 ldaa    _DPRB
        anda    #%00010000
        bne     MAGGOR1
        ldaa    #%00000000
        staa    _DPRA
        rts
********************************************************************************

**********************************   LOGISTIKA   *******************************
LOGIST ldaa NOVAKCK
              beq  LOGKNC
              ldaa SMER
              cmpa #$76
              beq LOGVEN
              jsr ISCINOT
              cmpa $FF
              beq LOGERR1
              ldab #18
              stab POSSKL
              jsr MOVEASS
              ldaa POSSKL2
              staa POSSKL
              jsr MOVEASS
LOGERR1 clr SMER
              clr KOCKA
              clr NOVAKCK
              bra LOGKNC
LOGVEN  jsr ISCIVEN
              cmpa $FF
              beq LOGERR2
              ldaa POSSKL2
              staa POSSKL
              jsr MOVEASS
              ldab #18
              stab POSSKL
              jsr MOVEASS
LOGERR2 clr NOVAKCK
              clr SMER
              clr KOCKA
LOGKNC rts

*******************************************************************************

********************************   BRISANJE NADSTROPIJ   **********************

BRISNAD1 ldab #$09
INFORB1 ldx #NAD1
              dex
              abx
              ldaa #$00
              staa 0,X
              decb
              bne INFORB1
              ldab #$09
INFORB2 ldx #NAD2
              dex
              abx
              ldaa #$00
              staa 0,X
              decb
              bne INFORB2
              ldab #$9
INFORB3 ldx #NAD3
              dex
              abx
              ldaa #$00
              staa 0,X
              decb
              bne INFORB3
              rts
*******************************************************************************
 
 
*********************************   ISCI VHODNO   *****************************
ISCINOT ldab STMEST
INFOR ldx #NAD1
              decb
              cmpb #$FF
              beq INNAD2
              abx
              ldaa 0,X
              bne INFOR
              ldaa KOCKA
              staa 0,X
              tba
              aba
              staa POSSKL2
              bra INKNC
INNAD2 ldab STMEST
 
INFOR2 ldx #NAD2
              decb
              ldaa ISCIPRE
              bne INMIM
              cmpb #$00
              bra INMIM1
INMIM cmpb #$FF
INMIM1 beq NIPROS
              abx
              ldaa 0,X
              bne INFOR2
              ldaa KOCKA
              staa 0,X
              tba
              aba
              staa POSSKL2
              bra INKNC
 

INNAD3 ldab STMEST tretji štuk še ne dela
INFOR3 ldx #NAD3
              decb
              cmpb #$FF
              beq NIPROS
              abx
              ldaa 0,X
              bne INFOR3
              ldaa KOCKA
              staa 0,X
              tba
              aba
              staa POSSKL2
              bra INKNC
 

NIPROS clr NOVPOD
              ldx #ERR1
              stx IZPISI
              jsr TRASTR
              ldaa #$FF
              staa POSSKL2
INKNC rts

ERR1 FCB $0C,$0D
 FCC "SKLADISCE JE POLNO"
 FCB $0A,$00

*******************************************************************************

*********************************   ISCI IZHODNO   ****************************
ISCIVEN  ldab STMEST
OUTFOR ldx #NAD1
              decb
              cmpb #$FF
              beq OUTN2
              abx
              ldaa 0,X
              cmpa KOCKA
              bne OUTFOR
              stab PRELOZI
              tba
              aba
              staa POSSKL2
              ldx #NAD2
              ldab PRELOZI
              abx
              ldaa 0,X
              beq OUTKNC
              staa KOCKA
              ldab PRELOZI
              tba
              aba
              staa POSSKL
              jsr MOVEASS
              ldaa #$01
              staa ISCIPRE
              jsr ISCINOT
              clr ISCIPRE
              ldaa POSSKL2
              staa POSSKL
              jsr MOVEASS
              ldab PRELOZI
              tba
              aba
              staa POSSKL2
              ldab PRELOZI
              ldx #NAD2
              abx
              ldaa #$00
              staa 0,X
              ldx #NAD1
              abx
              staa 0,X
              bra OUTKNC
 OUTN2 ldab STMEST
OUTFORN2 ldx #NAD2
              decb
              cmpb #$FF
              beq NIKCK
              abx
              ldaa 0,X
              cmpa KOCKA
              bne OUTFORN2
              ldaa #$00
              staa 0,X
              tba
              aba
              staa POSSKL2
              bra OUTKNC

NIKCK clr NOVPOD
              ldx #ERR2
              stx IZPISI
              jsr TRASTR
              ldaa #$FF
              staa POSSKL2
OUTKNC rts

ERR2 FCB $0C,$0D
 FCC "NI KOCKE"
 FCB $0A,$00
*******************************************************************************

*********************************   PREMIKANJE   ******************************
MOVEASS  ldx #POZX
              ldab POSSKL
              abx
              ldd 0,X
              stad KOORX
              ldab POSSKL
              ldy #POZY
              aby
              ldab 0,Y
              stab KOORY
              clr PRISEL
              ldaa #$01
              staa STANJEX
              staa STANJEY
MLOOP jsr PREMIK
              ldaa PRISEL
              beq MLOOP
              jsr GORDOL
              rts
       ORG   _XRAM
*******************************************************************************

************************* KERNEL VARIABLES (7 bytes) **************************
SCHPTR  RMB   2           16 bit pointer to current task in SCHTAH.
SCHTST  RMB   1           Test task on exceeding time slice.
TIMH    RMB   1           Hours (0..23),
TIMM    RMB   1              minutes (0..59),
TIMS    RMB   1              seconds (0..59),
TIMF    RMB   1              and fractions (0..255).
************************* DRIVER VARIABLES (100 bytes) ************************
SPRMAG RMB  1
STANJEX  RMB  1
STANJEY  RMB  1
KOORX RMB  2
KOORY RMB  1
NAPREJ RMB  1
NAZAJ RMB  1
LEVO RMB  1
DESNO    RMB  1
PREJX    RMB  1
PREJY    RMB  1
STEVECX  RMB  2
STEVECY  RMB  1
SKLADB   RMB   3+40     SKLAD buffer
SKLADE   RMB   2              kapaciteta 10 kontejnerjev 2X,Y,Z
TRAB    RMB   3+64        SCI transmitting buffer
TRAE    RMB   2              with a capacity of 64 characters.
RECB    RMB   3+40         SCI receiveing buffer
RECE    RMB   2              with a capacity of 8 characters.
NEKI    RMB   2
NOVPOD  RMB   1
PROBAY RMB  1
NAD1 RMB 10
NAD2 RMB 10
NAD3 RMB 10
PRISEL RMB 1
FORZANKA RMB 1
SMER RMB 1
KOCKA RMB 1
NOVAKCK  RMB 1
POSSKL RMB 1
IZPISI RMB 2
POSSKL2 RMB 1
STMEST RMB 1
PRELOZI RMB 1
ISCIPRE  RMB 1
************************* APPLICATION VARIABLES *******************************
*
*
*
************************* VARIABLE HEAP ***************************************
HEAP    RMB   1

        END