home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11mac.mac < prev    next >
Text File  |  2020-01-01  |  12KB  |  603 lines

  1.     .sbttl    define macros from IN:K11MAC.MAC
  2.     .nlist
  3.  
  4. ;    include file for kermit-11
  5. ;
  6. ;    Brian Nelson  01-Dec-83  13:56:12
  7.  
  8.  
  9.     k11inc    =    1
  10.  
  11. ;    the $RWDAT psect MUST be first for RT11 so that the added
  12. ;    QUEUE words are never mapped by APR1 for the XM exec.
  13.  
  14.     .psect    $rtque    ,rw,d,gbl,rel,ovr
  15.     .psect    $rwdat    ,rw,d,gbl,rel,con
  16.     .psect    $code    ,ro,i,lcl,rel,con
  17.     .psect    $pdata    ,ro,d,lcl,rel,con
  18.     .psect
  19.  
  20.     soh    =    1        ; packet start for synch
  21.     cr    =    15        ; a lonely carriage return
  22.     lf    =    12        ; it's normal companion
  23.     ff    =    14        ; sometimes a form feed is nice
  24.     space    =    40        ; don't ask
  25.     del    =    177        ; the RUBOUT
  26.     esc    =    33        ; and at last, escape
  27.  
  28.     r0    =    %0
  29.     r1    =    %1
  30.     r2    =    %2
  31.     r3    =    %3
  32.     r4    =    %4
  33.     r5    =    %5
  34.     sp    =    %6
  35.     pc    =    %7
  36.  
  37.  
  38.  
  39.  
  40.     .macro    strcat    dst,src
  41.     mov    src    ,-(sp)
  42.     mov    dst    ,-(sp)
  43.     jsr    pc    ,strcat
  44.     .globl    strcat
  45.     .endm    strcat
  46.  
  47.  
  48.     .macro    strcmp    s1,s2
  49.     mov    s2    ,-(sp)
  50.     mov    s1    ,-(sp)
  51.     call    strcmp
  52.     .globl    strcmp
  53.     .endm    strcmp
  54.  
  55.     .macro    strcpy    dst,src
  56.     mov    src    ,-(sp)
  57.     mov    dst    ,-(sp)
  58.     jsr    pc    ,strcpy
  59.     .globl    strcpy
  60.     .endm    strcpy
  61.  
  62.     .macro    textsrc    text
  63.     .if b    ,text
  64.     .ift
  65.     mov    #fgetcr0,getcroutine
  66.     clr    tgetaddr
  67.     .iff
  68.     mov    #tgetcr0,getcroutine
  69.     mov    text    ,tgetaddr
  70.     .endc
  71.     .globl    getcroutine,tgetaddr,fgetcr0,tgetcr0
  72.     .endm    textsrc
  73.  
  74.  
  75.  
  76.  
  77. ;    The following macro is for RT systems w/o clock. It will loop for
  78. ;    the .twait, you must insert check as in:
  79. ;
  80. ;    tst    clkflg            ; does this systems have a clock
  81. ;    bne    10$            ; yes
  82. ;    cpuwait    #time            ; no
  83. ;    br    20$            ; 
  84. ; 10$:    .twait    #rtwork,#timarg        ; clock is present with twait support
  85. ; 20$:
  86.  
  87.     .macro    cpuwait    ticks        ; loop for specified number of ticks
  88.     mov    ticks    ,-(sp)        ; Adjust the inner loop for timing of
  89.     clr    -(sp)            ; 1/60 of a second (one clock tick)
  90.     mov    #13700/2,(sp)        ; this inner loop takes 1/60 second
  91.     dec    (sp)            ; with a vaule of 13700 (8) on a
  92.     bne    .-2            ; PDP 11/44, try 13700/2 for default.
  93.     dec    2(sp)            ; end of inner loop, now do the outer
  94.     bne    .-14            ; loop
  95.     cmp    (sp)+    ,(sp)+        ; all done
  96.     .endm    cpuwait
  97.  
  98.  
  99.  
  100.  
  101.  
  102. ;    Define IXOR macro to get around the mode restrictions for
  103. ;    the hardware XOR  instruction and to fix for RT11 systems
  104. ;    that don't have the EIS chip option.
  105.  
  106.  
  107.  
  108.     .macro    indexm    reg        ; check for auto increment/decrement
  109.     .ntype    $$$0    ,reg        ; modes for macro's that can't have
  110.     .if    ne    ,$$$0-27    ; always allow pc autoincrement
  111.     $$$0    =    <$$$0 & 177770>/10 ; these modes in their arg list.
  112.     .ift                ;
  113.     .if    ge    ,$$$0-2        ; get the mode into 0..7
  114.     .ift                ; if mode >= 2 and mode <= 5 then error
  115.     .iif    ge    ,5-$$$0, .error    ; can't use auto inc/dec mode here
  116.     .endc                ;
  117.     .endc                ;
  118.     .endm    indexm            ; end of indexm macro
  119.  
  120.  
  121.     .macro    ixor    reg,dst        ; do this for rt11 versions
  122.     .chksp    reg            ; can't allow SP args
  123.     .chksp    dst            ; can't allow SP args
  124.     indexm    reg            ; check for allowed addressing mode
  125.     indexm    dst            ; check for allowed addressing mode
  126.     mov    reg    ,-(sp)        ; it's much simpler to do this
  127.     bic    dst    ,@sp        ; for all rt systems rather than
  128.     bic    reg    ,dst        ; to be selective
  129.     bis    (sp)+    ,dst        ; all done
  130.     .endm    ixor            ; for RT11 xor
  131.  
  132.     .macro    xor    reg,dst
  133.     ixor    reg,dst
  134.     .endm    xor
  135.  
  136.  
  137.  
  138.  
  139.     .macro    clrpar    reg
  140.     clr    -(sp)
  141.     bisb    reg    ,@sp
  142.     call    clrpar
  143.     clr    reg
  144.     bisb    (sp)+    ,reg
  145.     .globl    clrpar
  146.     .endm    clrpar
  147.  
  148.     .macro    setpar    src,dst
  149.     movb    src    ,-(sp)
  150.     call    dopari
  151.     movb    (sp)+    ,dst
  152.     global    <dopari>
  153.     .endm    setpar
  154.  
  155.  
  156.     .macro    tochar    src,dst
  157.     clr    -(sp)
  158.     bisb    src    ,@sp
  159.     add    #40    ,@sp
  160.     movb    (sp)+    ,dst
  161.     .endm    tochar
  162.  
  163.     .macro    unchar    src,dst
  164.     clr    -(sp)
  165.     bisb    src    ,@sp
  166.     sub    #40    ,@sp
  167.     movb    (sp)+    ,dst
  168.     .endm    unchar
  169.  
  170.     .macro    ctl    src,dst
  171.     clr    -(sp)
  172.     bisb    src    ,@sp
  173.     call    l$xor
  174.     movb    (sp)+    ,dst
  175.     global    <l$xor>
  176.     .endm    ctl
  177.     
  178.  
  179.     .macro    spack    type,pnum,len,msg
  180.     .if b    ,len
  181.     .ift
  182.     .iif nb    ,msg    ,.error    ; bad call to SPACK macro
  183.     calls    spack$    ,<type,pnum,#0,#null>
  184.     .iff
  185.     calls    spack$    ,<type,pnum,len,msg>
  186.     .endc
  187.     .globl    null
  188.     .endm    spack
  189.  
  190.     .macro    rpack    len.a,pakn.a,msg.a
  191.     sub    #10    ,sp
  192.     mov    sp    ,r1
  193.     calls    rpack$    ,<msg.a,r1>
  194.     mov    (r1)+    ,len.a
  195.     mov    (r1)+    ,pakn.a
  196.     mov    @r1    ,r1
  197.     add    #10    ,sp
  198.     .endm    rpack
  199.  
  200.     .macro    strlen    string
  201.     mov    string    ,r0
  202.     call    l$len
  203.     global    <l$len>
  204.     .endm    strlen
  205.  
  206.     .macro    push    reg
  207.     mov    reg    ,-(sp)
  208.     .endm    push
  209.  
  210.     .macro    pop    reg
  211.     mov    (sp)+    ,reg
  212.     .endm    pop
  213.  
  214.     .macro    rodata
  215.     .psect    $pdata
  216.     .endm    rodata
  217.  
  218.  
  219.     .macro    code
  220.     .psect    $code
  221.     .endm    code
  222.  
  223.     .macro    direrr    val
  224.     mov    val    ,-(sp)
  225.     call    direr$
  226.     .globl    direr$
  227.     .endm    direrr
  228.  
  229.  
  230.  
  231.     .macro    copyz    from,to,maxlen
  232.     .if    b,maxlen
  233.     .ift
  234.     clr    -(sp)
  235.     .iff
  236.     mov    maxlen    ,-(sp)
  237.     .endc
  238.     mov    from    ,-(sp)
  239.     mov    to    ,-(sp)
  240.     call    copyz$
  241.     .globl    copyz$
  242.     .endm    copyz
  243.  
  244.  
  245.     .macro    message    txt,docr
  246.     .save
  247.     .psect    $pdata
  248.     $$ = .
  249.     .if b    ,<txt>
  250.     .ift
  251.     .byte    15,12,0
  252.     .iff
  253.     .asciz    @txt@
  254.     .endc
  255.     .even
  256.     .restore
  257.     mov    #$$    ,-(sp)        ; dump the text next please
  258.     call    mout            ; to the terminal
  259.     .globl    mout            ; perhaps
  260.     .if nb    ,<txt>
  261.     .ift
  262.     .iif nb,docr, message
  263.     .endc
  264.     .endm    message
  265.  
  266.     .macro    scan    ch,str
  267.     mov    str    ,-(sp)
  268.     clr    -(sp)
  269.     bisb    ch    ,@sp
  270.     call    scanch
  271.     .globl    scanch
  272.     .endm    scan
  273.  
  274.     .macro    incm64    val
  275.     save    <r2,r3>
  276.     mov    val    ,r3
  277.     inc    r3
  278.     clr    r2
  279.     div    #100    ,r2
  280.     mov    r3    ,val
  281.     unsave    <r3,r2>
  282.     .endm    incm64
  283.  
  284.     .macro    iferr    lab
  285.     tst    r0
  286.     bne    lab
  287.     .endm    iferr
  288.  
  289.     .macro    .newline    ; print crlf on channel 0 (KB:)
  290.     call    l$pcrlf
  291.     .globl    l$pcrlf
  292.     .endm    .newline
  293.  
  294.     .macro    save    list
  295.     .if b , <list>
  296.     .ift
  297.      save    <r0,r1,r2,r3,r4,r5>
  298.     .iff
  299.     .irp    x,<list>
  300.      mov    x,-(sp)
  301.         .endr
  302.     .endc
  303.     .endm    save
  304.  
  305.  
  306.     .macro    unsave    list
  307.     .if b , <list>
  308.     .ift
  309.     unsave    <r5,r4,r3,r2,r1,r0>
  310.     .iff
  311.     .irp    x,<list>
  312.      mov    (sp)+,x
  313.         .endr
  314.     .endc
  315.     .endm    unsave
  316.  
  317.     .macro    print    s,l
  318.     .print    s,l
  319.     .endm    print
  320.  
  321.     .macro    .print    stradr    ,strlen
  322.  
  323.      .ntype    $$6    ,stradr
  324.      .iif eq, $$6 - 25, .error stradr; can't use (r5)+ in .print
  325.      .iif eq, $$6 - 45, .error stradr; can't use -(r5) in .print
  326.       save    <r5>            ; Same as the RT11 .print but
  327.       .if     b    ,strlen        ; allows an optional length
  328.        .ift                ; to be passed as an argument.
  329.          clr -(sp)
  330.        .iff
  331.          mov strlen    ,-(sp)
  332.       .endc
  333.  
  334.       mov    stradr    ,-(sp)
  335.       mov    sp    ,r5
  336.       call    l$ttyou            ; Example: .print r5,#12.
  337.       .globl    l$ttyou
  338.       add    #4    ,sp        ;          .print #str
  339.       unsave    <r5>        ;   str:   .asciz /HELLO/
  340.  
  341.     .endm    .print
  342.  
  343.     .MACRO    GLOBAL    LIST
  344.     .GLOBL    LIST
  345.     .ENDM    GLOBAL
  346.  
  347.     .MACRO    .ASSUME    ARG1,COND,ARG2
  348.     .IF    COND    <ARG1>-<ARG2>
  349.     .IFF
  350.     .ERROR    ARG1 ;"COND ARG2" FAILS
  351.     .ENDC
  352.     .ENDM    .ASSUME
  353.  
  354.     .macro    .chksp    arg
  355.     .ntype    $$5    ,arg
  356.     .iif eq,<$$5 & 7>-6, .error arg ; Illegal use of SP(r6) in call
  357.     .endm    .chksp
  358.  
  359.     .macro    decout    val
  360.     mov    r5    ,-(sp)
  361.     clr    -(sp)
  362.     mov    val    ,-(sp)
  363.     mov    sp    ,r5
  364.     call    l$wrdec
  365.     cmp    (sp)+    ,(sp)+
  366.     mov    (sp)+    ,r5
  367.     .globl    l$wrdec
  368.     .endm    decout
  369.  
  370.     .macro    octout    val
  371.     calls    l$wroct    ,<val>
  372.     .endm    octout
  373.  
  374.     .macro    deccvt    val,buf,width
  375.     mov    r5    ,-(sp)
  376.     .if    b,width
  377.     .ift
  378.     clr    -(sp)
  379.     .iff
  380.     mov    width    ,-(sp)
  381.     .endc
  382.     mov    val    ,-(sp)
  383.     mov    buf    ,-(sp)
  384.     mov    sp    ,r5
  385.     call    l$cvtnum
  386.     add    #6    ,sp
  387.     mov    (sp)+    ,r5
  388.     .globl    l$cvtn
  389.     .endm    deccvt
  390.  
  391.  
  392. ;    CALLS macro
  393. ;
  394. ;    subroutine call with arguements passed in an area
  395. ;    pointed to by R5 (similiar to F4 and BP2). All args
  396. ;    are pushed onto the stack, with the first args  at
  397. ;    the lower address and the last ones at the  higher
  398. ;    addresses. R5 will point to the SP before the call.
  399. ;    R5 is saved and restored.
  400.  
  401.  
  402.  
  403.     .macro    calls    name,arglst,gbl    ; standard  call  macro using
  404.                     ; the hardware stack (%6) for
  405.       .if b, gbl
  406.       .ift
  407.        .globl    name
  408.       .iff
  409.       .iif dif, 'gbl ,nogbl, .globl name
  410.       .iif dif, 'gbl ,NOGBL, .globl name
  411.       .endc
  412.       $$    =    0        ; arguement transmission with
  413.       .irp    x    ,<arglst>    ; r5 passed as  a pointer  to
  414.         $$    =    $$ + 1        ; to the arguement list.  The
  415.       .endr                ; called name is declared globl
  416.      .if eq    ,$$            ; No args present ? If so, gen
  417.       .ift                ; a simple jsr pc call to sub.
  418.         jsr    pc    ,name        ; No argument list given.
  419.       .iff
  420.  
  421.         push    r5        ; At least one arg in <arglst>
  422.         .if eq , $$ - 1        ; One arguement in the list
  423.  
  424.          .ift
  425.           mov    arglst    ,-(sp)    ; One arg. Generate less code
  426.           .chksp    arglst        ; Check for SP modes on param.
  427.           mov    sp    ,r5    ; Set pointer to argument list
  428.           jsr    pc    ,name    ; call the subroutine
  429.           tst    (sp)+        ; pop parameter list from stack
  430.           pop    r5        ; restore r5 pointer
  431.  
  432.          .iff            ; argcount > 1
  433.  
  434.  
  435.           $$2    =    $$    ; more than 1 arguement. Thus
  436.           .rept    $$        ; extract the args in reverse
  437.           $$1    =    0    ; order so that we might save
  438.           .irp x    ,<arglst>    ; a little core (4 words).
  439.            $$1    =    $$1 + 1    ; Scan the arg list until we
  440.            .if eq    , $$2 - $$1    ; we come to the last one we
  441.         .ift            ; before the one we just did.
  442.          .chksp    x        ; Check for SP addressing mode.
  443.          mov    x    ,-(sp)    ; Push it, and exit the .irp.
  444.          .mexit            ; exit
  445.            .endc
  446.           .endr
  447.           $$2 = $$2 - 1        ; backwards to previous arg.
  448.           .endr
  449.           mov    sp    ,r5    ; Set up the argument lst ptr.
  450.           jsr    pc    ,name    ; and go to the routine.
  451.           .if ne , $$ - 2        ; Gen 'Add 2*argnum, sp' ?
  452.           .ift            ; yes, else gen CMP (sp)+,(sp)+
  453.            add    #$$*2    ,sp    ; fix the stack up, restore r5
  454.           .iff
  455.            cmp    (sp)+    ,(sp)+
  456.           .endc
  457.           unsave    <r5>        ; restore r5 pointer
  458.           .endc
  459.      .endc
  460.  
  461.     .endm    calls            ; thats all
  462.  
  463.  
  464.     
  465.  
  466.     .macro    bdump    adr,siz
  467.     mov    siz    ,-(sp)
  468.     mov    adr    ,-(sp)
  469.     call    dump$b
  470.     global    <dump$b>
  471.     .endm    bdump
  472.  
  473.  
  474.  
  475.     .macro    dispat    val,dsp,baseval,basedsp,default
  476.     .save
  477.     .if nb    ,baseval
  478.     .ift
  479.     .psect    genval    ,ro,d,lcl,rel,con
  480. baseval:
  481.     .psect    gendsp    ,ro,d,lcl,rel,con
  482. basedsp:
  483.     .word    default
  484.     .iff
  485.     .psect    genval    ,ro,d,lcl,rel,con
  486.     .if b    ,val
  487.     .ift
  488.     .byte    0
  489.     .even
  490.     .iff
  491.     .byte    val
  492.     .psect    gendsp    ro,d,lcl,rel,con
  493.     .word    dsp
  494.     .endc
  495.     .endc
  496.     .restore
  497.     .endm
  498.  
  499.     .macro    prsbuf    dst
  500.     mov    dst    ,r0
  501.     call    prsarg
  502.     .globl    prsarg
  503.     .endm    prsbuf
  504.  
  505.     .macro    malloc    size
  506.     mov    size    ,r0
  507.     call    malloc
  508.     .globl    malloc
  509.     .endm    malloc
  510.  
  511.  
  512. ;    offset into local and remote's parameter vectors
  513.  
  514.     p.spsiz    =    0        ; spsizinelength
  515.     p.time    =    1        ; timeout
  516.     p.npad    =    2        ; number of pad characters
  517.     p.padc    =    3        ; the pad character
  518.     p.eol    =    4        ; eol char
  519.     p.qctl    =    5        ; control chracter quoting
  520.     p.qbin    =    6        ; 8 bit quote
  521.     p.chkt    =    7        ; flavor of checksuming to do
  522.     p.rept    =    10        ; repeated character prefix
  523.     p.capas    =    11        ; capability bitmask
  524.     p.winds    =    12        ; /43/ window size
  525.     p.mxl1    =    13        ; /43/ High order, long packet size
  526.     p.mxl2    =    14        ; /43/ Low order of long packet size
  527.     p.vend    =    17        ; end of parameter vector
  528.  
  529.     CAPA.A    =    10        ; bit set for attribute handling
  530.     CAPA.S    =    4        ; /42/ Bit set for sliding windows
  531.     CAPA.L    =    2        ; /42/ Bit mask for long packets
  532.  
  533.     log$pa    =    1        ; if set in TRACE then log all packets
  534.     log$fi    =    2        ; if set in TRACE then log all files
  535.     log$co    =    4        ; virtual terminal logging to disk
  536.     log$st    =    10        ; state logging
  537.     log$rp    =    20        ; dump each rpack character to local tt
  538.     log$io    =    40        ; dump anything read or sent
  539.     log$al    =    log$fi ! log$pa    ; all bits possible in TRACE
  540.     log$al    =    log$co ! log$st ! log$al ! log$rp ! log$io
  541.     log$op    =    100000        ; the logfile is open now
  542.  
  543.  
  544.     par$od    =    1        ; set parity odd
  545.     par$ev    =    2        ; set parity even
  546.     par$ma    =    3        ; set parity mark
  547.     par$sp    =    4        ; set parity space
  548.     par$no    =    5        ; set parity none
  549.  
  550.     terminal=    -1        ; terminal
  551.     TEXT    =    0        ; normal ascii text files
  552.     BINARY    =    1        ; image mode
  553.     DECNAT    =    2        ; 8bit record type /52/
  554.  
  555.     ter$cc    =    1        ; if set for ttyini then allow ^C
  556.     ter$xo    =    2        ; if ter$bi then set xon/xoff back
  557.     ter$bi    =    4        ; use raw binary mode please
  558.                     ; NOTE: ter$bi overrides ter$cc always
  559.     ter$pa    =    10
  560.  
  561.     con$esc    =    '\-100
  562.  
  563.     sy$11m    =    1        ;    for rsx11m
  564.     sy$ias    =    3        ;    for ias
  565.     sy$rsts    =    4        ;    for rsts
  566.     sy$vms    =    5        ;    for vms ame
  567.     sy$mpl    =    6        ;    for m+
  568.     sy$rt    =    7        ;    for rt11
  569.     sy$pos    =    11
  570.     sy$pro    =    11        ;    for p/os ??
  571.  
  572.  
  573. ;    The PRO$XXX values directly correspond to the values used in RSTS
  574. ;    The JOB$XXX values are the values we would need to know at runtime
  575. ;    PRO$XXX value is stored (only ONCE, at startup) in PROCTYP
  576. ;    JOB$XXX value is stored (only ONCE, at startup) in JOBTYPE
  577.  
  578.     PRO$LOC    =:    0        ; /45/ Process is a real user
  579.     PRO$DIA    =:    1        ; /45/ Dialup user
  580.     PRO$BAT    =:    2        ; /45/ Process is a batch user
  581.     PRO$NET    =:    4        ; /45/ Process is via DECNET
  582.     PRO$SER    =:    6        ; /45/ Process is Decnet server
  583.     JOB$INT    =:    0        ; /45/ Job is local,dial or net
  584.     JOB$BAT    =:    1        ; /45/ Job is batch
  585.  
  586.     LN$MAX    =    80.
  587.     LN$CNT    =    5
  588.     LN$ALL    =    10.
  589.  
  590.     tty    =    0        ;
  591.     vt100    =    1        ;
  592.     vt200    =    2
  593.     vtpos    =    3
  594.     vtprt11    =    4
  595.  
  596.     $rdata    =    1
  597.     $sdata    =    2
  598.  
  599.     MAXLNG    =    600.        ; /42/ Long packet buffer size
  600.  
  601.  
  602.     .list
  603.