home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / starter.lbr / STARTER.AZM / STARTER.ASM
Encoding:
Assembly Source File  |  1993-10-25  |  8.6 KB  |  411 lines

  1. ;====================================================
  2. ; STARTER A.K.A. START MAKER by Claude Ostyn        :
  3. ; Version 3  9/27/83                    :    
  4. ;                            :
  5. ; This is a self-modifying program with hooks into  :    
  6. ; CCP and BDOS.  Use extreme caution.            :    
  7. ;====================================================     
  8. ;EQUATES
  9.  
  10. ; ASCII
  11. cr    equ    0dh
  12. lf    equ    0ah
  13. ctrlz    equ    1ah
  14. escape  equ    27
  15. half    equ    ')'
  16. full    equ    '('
  17. ; BDOS functions
  18. rconf    equ    1            ;read CON: into A
  19. wconf    equ    2            ;write A to CON:
  20. rbuff    equ    10            ;read a console line
  21. ; CP/M disk access functions
  22. initf    equ    13            ;initialize BDOS
  23. openf    equ    15            ;open file
  24. closf    equ    16            ;close file
  25. findf    equ    17            ;find file
  26. delef    equ    19            ;delete file
  27. readf    equ    20            ;read one record
  28. writf    equ    21            ;write one record
  29. makef    equ    22            ;create file
  30. sdmaf    equ    26            ;set DMA function
  31. ; CP/M addresses
  32. rboot    equ    0            ;cold boot
  33. drive    equ    4            ;current drive
  34. bdos    equ    5            ;BDOS entry for calls
  35. memax    equ    7            ;MSB of top memory
  36. tfcb    equ    5ch            ;transient file control block
  37. fcbex    equ    tfcb+12            ;file extent
  38. fcbs2    equ    tfcb+14            ;system use in FCB
  39. fcbrc    equ    tfcb+15            ;record count in FCB
  40. fcbcr    equ    tfcb+32            ;current record in FCB
  41. tbuff    equ    80h            ;transient buffer
  42. tpa    equ    100h            ;TPA
  43. ; CP/M flags
  44. bdaok    equ    0            ;BDOS return for all OK
  45. bder1    equ    1            ;BDOS return 1
  46. bder2    equ    2            ;BDOS return 2
  47. bderr    equ    255            ;BDOS return error flag
  48. ; special values for this program
  49. imagelen    equ    4        ;number of records in AUTOST
  50.  
  51. ;START
  52.            org    tpa
  53. tempjmp:    jmp    maker        ;this jump will be changed to nop
  54.                     ;by program        
  55.  
  56. ;AUTOSTART PROGRAM PART
  57.     lhld    01
  58.     mvi    l,0
  59.     mov    a,h
  60.     sui    16h
  61.     mov    h,a
  62.     shld    ccp
  63.     lxi    d,message2
  64.     call    print
  65.     lxi    d,command
  66.     lxi    b,42
  67.  automove:
  68.     lhld    ccp
  69.     mvi    l,07
  70.     call    again
  71.     lhld    ccp
  72.     mvi    l,88h
  73.     mvi    a,08h
  74.     mov    m,a
  75.     lhld    ccp
  76.     mvi    l,89h
  77.     mov    a,h
  78.     mov    m,a
  79.     lhld    ccp
  80.     pchl
  81. again:
  82.     ldax    d
  83.     mov    m,a
  84.     inx    h
  85.     inx    d
  86.     dcx    b
  87.     mov    a,b
  88.     ora    c
  89.     jnz    again
  90.     ret        
  91. print:
  92.     mvi    c,9
  93.     jmp    bdos
  94.  
  95. ;AUTOSTART STORAGE AREA
  96. ccp:        ds    2
  97. command:     ds    84
  98. message:     ds    2
  99. message2:    ds    88
  100.  
  101. ;END OF AUTOST PROGRAM
  102.  
  103. maker:
  104. start:        lxi    sp,stak        ;set up user's stack
  105.         lda    drive        ;save initial drive selected
  106.         sta    drsav
  107.         xra    a
  108.         sta    tempjmp        ;cancel the jump to here
  109.         sta    tempjmp+1
  110.         sta    tempjmp+2
  111. start1:        call    showmsg
  112.         db    26,9,9,'STARTER',escape, half,'  Version 1.3',cr,lf,lf
  113.         db    9,9,'Copyright 1983 Claude Ostyn',cr,lf,lf,lf
  114.         db    escape,full,0
  115.         mvi    a,imagelen    ;length of AUTOST image
  116.         lxi    h,recct        ;in number of 128 byte records 
  117.         mov    m,a        ;store it at recct
  118.         call    showmsg
  119. sinon:        db    'This program will create another program called',cr,lf
  120.         db    'AUTOST.COM and put it on a diskette in drive B.',cr,lf,lf
  121.         db    'Ozzie looks for AUTOST.COM when it is booted.',cr,lf
  122.         db    'If it finds it, it then executes the command',cr,lf
  123.         db    'requested by AUTOST.COM.',cr,lf,lf,lf,lf
  124. contline:    db    'Press <RETURN> to proceed, or CONTROL-Z to exit. ',0     
  125.     
  126.         call     chrin        ;get answer
  127.         cpi    ctrlz        ;control-z?
  128.         jz    exit        ;if yes, exit
  129. start2:        call    blank        ;blank input areas
  130.         call    showmsg
  131. promptfile:    db    26,cr,lf,lf
  132.         db    'Enter the command to be executed by AUTOST.COM,'
  133.         db    cr,lf,'(up to 80 characters).',cr,lf 
  134.         db    'Example:   MBASIC ZAPGAME',cr,lf,lf,lf
  135.         db    '________________________________________',cr,0
  136.         lxi    h,inbuff        ;set maximum input length     
  137.         mvi    m,80        ;at 80
  138.         lxi    d,inbuff
  139.         mvi    c,rbuff
  140.         call    bdos
  141.         lxi    h,inbuff+1    ;point to char. counter
  142.         mov    a,m        
  143.         cpi    0        ;if zero, then
  144.         jz    exit        ;exit
  145.         call    movcommand    ;move command line into AUTOST
  146.         call    showmsg
  147. promptmessage:    db    cr,lf,lf,'Enter the message to be displayed while',cr,lf
  148.         db    'AUTOST.COM is executing (up to 80 characters).',cr,lf,lf,lf
  149.         db      '__________________________'
  150.         db    '_________________________',cr,0
  151.         lxi    d,message    ;point to message area
  152.         mvi    c,rbuff
  153.         call    bdos        ;and enter the message
  154.         call    setend        ;put cr/lf at end
  155.  
  156. copyit:        call    putname        ;put B:AUTOST.COM into FCB
  157.         call    showmsg
  158.         db    cr,lf,lf
  159.         db    'Put the disk on which you want to create',cr,lf
  160.         db    'AUTOST.COM in drive B, and press any key,',cr,lf
  161.         db    'or CTRL-Z to make changes.',cr,lf
  162.         db    cr,lf,0
  163.         call    chrin
  164.         cpi    ctrlz
  165.         jz    start2        
  166.         call    showmsg
  167.         db    lf,lf,9,9,'<<< WAIT >>>',0
  168.         call    put
  169.         call    showmsg
  170.         db    'Copy this AUTOST.COM on another disk? ',0
  171.         call    chrin
  172.         cpi    'Y'
  173.         jz    copyit
  174. exit:        call    showmsg
  175.         db    26,cr,lf,lf,9,'Returning to CP/M...',cr,lf,lf,0
  176.         lda    drsav        ;restore initial drive
  177.         sta    drive
  178.         jmp    rboot
  179.  
  180. ;make changes at end of message
  181. setend:
  182.         lxi    h,message+1    ;point to 1 before 1st chr
  183.          lookforend:
  184.         inx    h
  185.         mov    a,m
  186.         cpi    '$'        ;look for terminator
  187.         jnz    lookforend
  188.         mvi    m,cr        ;and replace with cr/lf sequence
  189.         inx    h
  190.         mvi    m,lf
  191.         inx    h
  192.         mvi    m,lf
  193.         inx    h
  194.         mvi    m,'$'
  195.         ret
  196.  
  197.  
  198. ; Write a file from "buffer" to disk
  199.  
  200. put:        lxi    h,tpa        ;set up buffer start
  201.         shld    next
  202.         lda    recct        ;save record count
  203.         sta    ctsav
  204. put1:        mvi    c,initf        ;enable write on any disk
  205.         call    bdos
  206.         xra    a        ;initialize FCB
  207.         sta    fcbcr        ;current record
  208.         lxi    h,0
  209.         shld    fcbex        ;extent and s1
  210.         shld    fcbs2        ;s2 and record count
  211.         lxi    d,tfcb        ;see if file exists
  212.         mvi    c,findf        ;find function
  213.         call    bdos
  214.         cpi    bderr        ;is it there?
  215.         jz    put2
  216.         call    showmsg
  217.         db    cr,lf,'OK to erase existing AUTOST.COM? ' ,0
  218.         call    chrin
  219.         cpi    'Y'
  220.         jnz    putex        ;if no, try again
  221.         call    showmsg
  222.         db    escape,'R',0bh,0
  223.         lxi    d,tfcb        ;if yes, erase it
  224.         mvi    c,delef
  225.         call    bdos
  226. put2:        lxi    d,tfcb
  227.         mvi    c,makef
  228.         call    bdos
  229.         cpi    bderr
  230.         jnz    put3
  231.         call    wropn
  232.         jmp    putex
  233.  
  234. put3:        lhld    next
  235.         xchg
  236.         mvi    c,sdmaf
  237.         call    bdos
  238.         lhld    next
  239.         lxi    d,128
  240.         dad    d
  241.         shld    next
  242.         lxi    d,tfcb
  243.         mvi    c,writf
  244.         call    bdos
  245.         cpi    bdaok
  246.         jz    put4
  247.         call    wemsg
  248.         jmp    putex
  249. put4:        lda    recct
  250.         dcr    a
  251.         sta    recct
  252.         jnz    put3
  253.         call    cpdma
  254.         lxi    d,tfcb
  255.         mvi    c,closf
  256.         call     bdos
  257.         lda    ctsav
  258.         sta    recct
  259.         call    showmsg
  260.         db    cr,9,9,'<<< DONE! >>>',9,9,cr,lf,lf,9,0
  261. putex:        call    showmsg
  262.         db    cr,lf,0
  263.         call    cpdma
  264.         ret
  265.  
  266. ; display write error message
  267. wemsg:        call    showmsg
  268.         db    cr,lf,lf,'Permanent write error',cr,lf,0
  269.         ret
  270.  
  271. ; display write open message
  272. wropn:        call    showmsg
  273.         db    cr,lf,lf,'Cannot open for write ',cr,lf,0
  274.         ret
  275.  
  276. ;restore CP/M DMA address to the transient buffer
  277. cpdma:        lxi    d,tbuff
  278.         mvi    c,sdmaf
  279.         call    bdos    
  280.         ret
  281.  
  282. ;console character into register a, masked to 7 bits
  283. chrin:        push    b
  284.         push    d
  285.         push    h
  286.     readit:
  287.         mvi    e,0ffh
  288.         mvi    c,6
  289.         call    bdos
  290.         cpi    0
  291.         jz    readit
  292.         ani    7fh
  293.         call    ucase
  294.         call    cout
  295.         pop    h
  296.         pop    d
  297.         pop    b
  298.         ret
  299.  
  300. ;character in register A output to console
  301. cout:        push    b
  302.         push    d
  303.         push    h
  304.         push    psw
  305.         mvi    c,wconf
  306.         mov    e,a
  307.         call    bdos
  308.         pop    psw
  309.         pop    h
  310.         pop    d
  311.         pop    b
  312.         ret
  313.  
  314. ;message pointed to by stack out to console
  315. showmsg:        xthl
  316.         xra    a
  317.         add    m
  318.         inx    h
  319.         xthl
  320.         rz
  321.         call    cout
  322.         jmp    showmsg
  323.  
  324. ;put name of new file into FCB
  325. putname:
  326.         mvi    a,2
  327.         sta    tfcb        ;force drive b designator
  328.         lxi    d,filename
  329.         lxi    h,tfcb+1    ;point to name area
  330.         mvi    b,11
  331.         movname:
  332.         ldax    d
  333.         mov    m,a
  334.         inx    h    
  335.         inx    d
  336.         dcr    b
  337.         jnz    movname
  338.         ret
  339.  
  340. ; move the command line into AUTOST image
  341. movcommand:
  342.         lxi    h,command    ;length of command in image
  343.         lxi    d,inbuff+1    ;point to character counter    
  344.         ldax    d        ;get it into a
  345.         mov    m,a        ;and put it in command
  346.            mov    b,a        ;also copy it into b
  347.         inx    d        ;point to command itself
  348.         inx    h        ;do same in image
  349.         mov    a,b        ;put counter into a
  350.         cpi    0        ;check if zero
  351.         rz            ;if zero, return
  352.        moveit:
  353.         ldax    d        ;get byte to move
  354.         call    ucase        ;convert to upper-case if necessary
  355.         mov    m,a        ;move it
  356.         inx    h        ;increment destination
  357.         inx    d        ;increment source loc.
  358.         dcr    b        ;decrement counter
  359.         jnz    moveit        ;repeat
  360.         ret
  361.  
  362. ;convert to uppercase if letter
  363. ucase:        
  364.         cpi    ':'        ;first check that it is not
  365.         rz            ;one of the ASCII codes
  366.         cpi    '{'        ;larger than lower case
  367.         rz            ;and, if it is, just return
  368.         cpi    '}'
  369.         rz    
  370.         cpi    '~'
  371.         rz    
  372.         cpi    'Z'+7        ;lowercase?
  373.         rc            ;if not, don't convert
  374.         ani    5fh        ;convert to uppercase
  375.         ret
  376.  
  377. ;initialize input areas
  378. blank:
  379.         lxi    h,command    ;command area
  380.         mvi    b,82        ;put zero in 82 bytes
  381.     movzero:
  382.         mvi    m,0
  383.         inx    h
  384.         dcr    b
  385.         jnz    movzero
  386.         lxi    h,message
  387.         mvi    m,80
  388.         inx    h
  389.         mvi    m,0        ;zero counter
  390.         mvi    b,82
  391.     movterm:            ;put terminator in 82 bytes 
  392.         inx    h
  393.         mvi    m,'$'
  394.         dcr    b
  395.         jnz    movterm
  396.         ret        
  397.  
  398. ;RAM variables and buffers
  399. drsav:        ds    1
  400. recct:        ds    1
  401. ctsav:        ds    1
  402. next:        ds    2
  403. ;set up stack space
  404.         ds    80
  405. stak        db    0
  406.  
  407. ;for filename, format is XXXXXXXXTYP to fit FCB image
  408. filename:    db    'AUTOST  COM'
  409. inbuff:    
  410.         end 
  411.