        UNL
STATUS  EQU R22
DEVICE  EQU R31
COMAND  EQU R30
RECORD  EQU R28
LUNO    EQU R29
BUFLEN  EQU R26
DATLEN  EQU R24
BUFADR  EQU R21
ATTRIB  EQU R19
TEMP1H  EQU R13
TEMP1L  EQU R14
TEMP2H  EQU R15
TEMP2L  EQU R16
TEMP3H  EQU R17
TEMP3L  EQU R18
DOS     EQU >D013
SELDOS  EQU >C801
SELCOS  EQU >C804
SELRAM  EQU >C80A
CLS     EQU >C87F
WRTSCN  EQU >C83D
KEYIN   EQU >C846
PRNTST  EQU >C852
KEYSCN  EQU >C855
CURSOR  EQU >C858
AFMESS  EQU >C894
BINASC  EQU >C897
AFPNUM  EQU >C8A3
BUFIN   EQU >D070 
CURDRV  EQU >EF5E
PARAM   EQU >EFC0
DRVTST  EQU ?00000001
DRIVEA  EQU >64
DRIVEB  EQU >65
READS   EQU >12
RAMVDP  EQU ?00000000
RAM     EQU ?00000001
INPUT   EQU ?01000000
HIMEM   EQU >7FFF
NBFIC   EQU >C0F8
OPEN    EQU >00
CLOSE   EQU >01
READ    EQU >03
BUFV    EQU >0000
LONGH   EQU >C500
LONGL   EQU >C501
EXEADR  EQU >C502
HEADER  EQU >C410
JESTER  EQU >C400
VERH    EQU >C406
VERL    EQU >C407
FLAG    EQU >C408
ARLOCH  EQU >C409
ARLOCL  EQU >C40A
CODLGH  EQU >C40B
CODLGL  EQU >C40C
ABRH    EQU >C40D
ABRL    EQU >C40E
CODEXE  EQU >C411
EXLMEM  EQU >D01F

        CALL @SELDOS
        CALL @SELRAM
        CALL @LF
        MOVD %MESS1,TEMP3L
        CALL @PRNTST
        LDA  @CURDRV
        BTJO %DRVTST,A,DRVA
        MOV  %DRIVEB,A
        JMP  DEBUT
DRVA    MOV  %DRIVEA,A
DEBUT   STA  @DRIVE
        CALL @ARGV
        BTJO %>FF,STATUS,BADEND
        CALL @LDHD
        BTJO %>FF,STATUS,BADEND
        CALL @CHECKF
        BTJO %>FF,STATUS,BADEND
        JMP  EXEC
BADEND  CALL @AFMESS
        CALL @FIN
        RETS

EXEC    LDA  @FLAG
        BTJZ %>04,A,TSTRAM
        CALL @LF
        CALL @EXLMEM
        BTJZ %>FF,STATUS,QUERY
        MOVD %MESS2,TEMP3L
        CALL @PRNTST
        CALL @FIN
        RETS
QUERY   MOVD %MESS3,TEMP3L
        CALL @PRNTST
        CALL @KEYIN
        CMP  %27,A
        JNE  TSTRAM
        CALL @FIN
        RETS
TSTRAM  DINT 
        LDA  @FLAG
        BTJZ %>01,A,GOCOD2
        CALL @LDRAM
        LDA  @DRIVE
        MOV  %1,B
        STA  @COD1(B)
        MOVD %COD1,TEMP2L
        JMP  EXCOD
GOCOD2  CALL @LDVDP
        CALL @FIN
        MOVD %COD2,TEMP2L
        BTJZ %>FF,STATUS,EXCOD
        CALL @AFMESS
        RETS

EXCOD   DINT
        LDA  *TEMP2L
        ADD  A,TEMP2L
        ADC  %0,TEMP2H
        XCHB A
REPT1   LDA  *TEMP2L
        STA  @HEADER(B)
        DECD TEMP2L
        DJNZ B,REPT1
        MOV  %1,B
        BR   @CODEXE(B)
        RETS

LF      MOV  %>0A,A
        CALL @WRTSCN
        MOV  %>0D,A
        CALL @WRTSCN
        RETS

LDRAM   LDA  @ARLOCL
        XCHB A
        LDA  @ARLOCH
        MOVD B,BUFADR
        LDA  @DRIVE
        MOV  A,DEVICE
        MOV  %RAM,A
        OR   %INPUT,A
        MOV  A,ATTRIB
        LDA  @CODLGL
        XCHB A
        LDA  @CODLGH
        MOVD B,BUFLEN
        MOVD %1,RECORD
        MOV  %1,LUNO
        MOV  %READ,COMAND
        RETS


LDVDP   MOVD %BUFV,BUFADR
        MOV  %RAMVDP,A
        OR   %INPUT,A
        MOV  A,ATTRIB
        MOVD %>8000,BUFLEN
        MOVD %1,RECORD
        MOV  %1,LUNO
        MOV  %READ,COMAND
        LDA  @DRIVE
        MOV  A,DEVICE
        CALL @DOS
        RETS

LDHD    MOVD %FILEN,BUFADR
        LDA  @DRIVE
        MOV  A,DEVICE
        MOV  %RAM,A
        OR   %INPUT,A
        MOV  A,ATTRIB
        LDA  @LENF
        XCHB A
        CLR  A
        MOVD B,DATLEN
        MOVD %>14,BUFLEN
        MOVD %0,RECORD
        MOV  %1,LUNO
        MOV  %OPEN,COMAND
        CALL @DOS
        BTJO %>FF,STATUS,FIN0
LDREC   MOVD %HEADER,BUFADR
        LDA  @DRIVE
        MOV  A,DEVICE
        MOV  %RAM,A
        OR   %INPUT,A
        MOV  A,ATTRIB
        MOVD %>11,BUFLEN
        MOVD %0,RECORD
        MOV  %1,LUNO
        MOV  %READ,COMAND
        CALL @DOS
FIN0    RETS

ARGV    DINT
        MOVD %FILEN,TEMP3L
        DECD TEMP3L
        DECD TEMP3L
        DECD TEMP3L
        CLR  B
        LDA  @PARAM(B)
LECA    CMP  %>41,A        
        JNE  LECB
        ADD  %>23,A
        STA  @LEC
        INC  B
        JMP  LEC2PT
LECB    CMP  %>42,A
        JNE  LECCAR
        ADD  %>23,A
        STA  @LEC
        INC  B
LEC2PT  LDA  @PARAM(B)
        CMP  %>3A,A
        JEQ  LECFIL
        PUSH A
        LDA  @LEC
        SUB  %>23,A
        STA  *TEMP3L
        LDA  @LENF
        INC  A
        STA  @LENF
        CLR  A
        STA  @LEC
        POP  A
        DECD TEMP3L
        JMP  LECCAR
LECFIL  INC  B
        LDA  @PARAM(B)
LECCAR  CMP  %>00,A
        JEQ  FIN4
        STA  *TEMP3L
        DECD TEMP3L
        LDA  @LENF
        INC  A
        STA  @LENF
        INC  B
        LDA  @PARAM(B)
        JMP  LECCAR

FIN4    MOV  %>2E,A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  %>42,A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  %>49,A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  %>4E,A
        STA  *TEMP3L
        LDA  @LENF
        ADD  %7,A
        STA  @LENF
        LDA  @LEC
        CMP  %0,A
        JEQ  FIN4C
        CMPA @DRIVE
        JNE  FIN4B
        MOV  %>21,STATUS
        EINT
        CALL @AFMESS
        MOV  %>25,STATUS
        CALL @AFMESS
        CALL @KEYIN
        CLR  STATUS
FIN4B   LDA  @LEC
        STA  @DRIVE
FIN4C   RETS

FIN     MOV  %1,LUNO
        MOV  %CLOSE,COMAND
        LDA  @DRIVE
        MOV  A,DEVICE
        CALL @DOS
        EINT
        RETS

CHECKF  MOV  %>FF,B
REPT3   INC  B
        LDA  @JESTXT(B)
        JZ   TSTVH
        CMPA @JESTER(B)
        JZ   REPT3
        MOV  %>17,STATUS
        RETS
TSTVH   LDA  @VERH
        CLR  B
        CMPA @VER(B)
        JN   TSTVL
        JZ   TSTVL
        MOV  %>0D,STATUS
        RETS
TSTVL   LDA  @VERL
        INC  B
        CMPA @VER(B)
        JN   FIN6
        JZ   FIN6
        MOV  %>0D,STATUS
FIN6    RETS

LENF    BYTE 0
DRIVE   BYTE 0
LEC     BYTE 0
        TEXT '                 '
        BYTE 0,0
FILEN   BYTE 0
VER     BYTE 1,0
JESTXT  BYTE 'JESTER',0    
MESS1   TEXT '    *******************************',>0A,>0D
        TEXT '    * Jester Binary Loader V01.00 *',>0A,>0D
        TEXT '    *******************************',>0A,>0D,0
MESS2   TEXT 'Exelmemoire requise! ',0
MESS3   TEXT 'Ecraser exelmemoire (Abandon=Esc) ?',0
COD1    BYTE 60,>00
        BYTE >8E,>D0,>13,>77,>FF,>16,>02,>E0,>23,>8E,>C4,>3E,>8A,>C4,>08,>27
        BYTE >02,>10,>88,>00,>00,>0E,>F7,>88,>80,>00,>10,>A2,>00,>2E,>DB,>10
        BYTE >E3,>F9,>8A,>C4,>0E,>B6,>8A,>C4,>0D,>9C,>01,>0A,>72,>01,>1D,>72
        BYTE >01,>1E,>8A,>C4,>11,>D0,>1F,>8E,>D0,>13,>0A
COD2    BYTE 69,>00
        BYTE >06,>88,>00,>00,>0E,>F6,>8A,>C4,>0A,>B6,>8A,>C4,>09,>98,>01,>12
        BYTE >8A,>C4,>0C,>B6,>8A,>C4,>0B,>98,>01,>10,>D7,>00,>9B,>12,>DB,>12
        BYTE >DB,>10,>E3,>F6,>8A,>C4,>08,>27,>02,>10,>88,>00,>00,>0E,>F7,>88
        BYTE >80,>00,>10,>A2,>00,>2E,>DB,>10,>E3,>F9,>8A,>C4,>0E,>B6,>8A,>C4
        BYTE >0D,>9C,>01,>0A
        ENDE3,>F9,>8A,>C4,>0E,>B6,>8A,>C4,>0D,>9C,>01,>0A,>72,>01,>1D,>72
        BYTE >01,>1E,>8A,>C4,>11,>D0,>1F,>8E,>D0,>13,>0A
