home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / cpm3 / writeccp.lbr / WRITECCP.MZC / WRITECCP.MAC
Encoding:
Text File  |  1987-10-26  |  6.7 KB  |  328 lines

  1. ;    This program originated as EXCWTSYS.MAC from the Executive
  2. ;    technical reference.  It has been modified to write only
  3. ;    CCP.COM to the system tracks on drive A. (G Peace - 12/84)
  4.  
  5. .z80
  6.  
  7. dmabank    equ    0fd4ah
  8. idellen    equ    0002h
  9. idevlen    equ    0080h
  10. idevshd    equ    00a2h
  11. idevtbl    equ    0022h
  12. idrvlen    equ    0080h
  13. idrvtbl    equ    0002h
  14. idvilen    equ    000ah
  15. idvslen    equ    0100h
  16. ishdlen    equ    0040h
  17. ivers    equ    0
  18. sys    equ    0
  19. wsec    equ    005dh
  20.  
  21.  
  22. open    equ    15
  23. read    equ    20
  24. setdma    equ    26
  25. pmsg    equ    9
  26.  
  27. bdos    equ    5
  28.  
  29.  
  30. getdev    equ    3ch        ;bios fcn: hl=devtbl
  31. getdrv    equ    42h        ;bios fcn: hl=drvtbl
  32. move    equ    4bh        ;bios fcn: move
  33. xmove    equ    57h        ;bios fcn: set banks for move
  34.  
  35.  
  36. start:    ld    sp,stack    ; pt to a stack
  37.  
  38.     ld    bc,codelen    ; len of our code
  39.     ld    de,himem    ; destination
  40.     ld    hl,ourcode    ; from here
  41.     ldir            ; move a hunk to non-rom area
  42.  
  43.     ld    bc,secend-sec1    ; init entire area 1st
  44.     ld    de,sec1        ; i/o area
  45.     ld    hl,initial    ; what to init it with
  46.     ldir            ; all cleared out
  47.  
  48.     ld    de,startmsg    ; tell what we're going to do
  49.     call    msg
  50.  
  51.     ld    de,ccp        ; 3rd file to read in
  52.     ld    hl,ccpsec
  53.     call    dofile
  54.  
  55. ;    track 1
  56.     ld    hl,track1
  57.     ld    de,0001h
  58.     ld    a,4
  59.     call    write
  60.  
  61.     ld    de,donemsg    ; that is it!
  62.     call    msg
  63.  
  64. ;    all done
  65.  
  66. exit:
  67.     jp    0        ; warm boot
  68.  
  69.  
  70.  
  71. ;    call the bios with rtn addr (lo) in a
  72.  
  73. bios:    ld    (biosl),a    ; set lo of bios addr
  74.     ld    a,(2)        ; get hi of addr
  75.     ld    (biosh),a
  76.  
  77. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78. ;    modified code follows
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80.  
  81. biosjp:    jp    0        ; really jp to bios entry
  82. biosl    equ    biosjp+1    ; lo of bios fcn addr
  83. biosh    equ    biosl+1        ; and hi of addr
  84.  
  85.  
  86. msg:    ld    c,pmsg        ; let bdos issue a message
  87.     jp    bdos        ; pt'ed to by de
  88.  
  89. ;    write
  90. ;        write all or part of a sector to disk
  91. ;    a    # sectors to write
  92. ;    e    track #
  93. ;    d    sector number-1 (0=1)
  94. ;    hl    ptr to dma address
  95.  
  96. ;    write5
  97. ;        same, but sets a to 5 (full track)
  98.  
  99. write5:    ld    a,5        ; set to full track
  100.  
  101. write:    or    a        ; see if anything to write
  102.     ret    z        ; no, all done
  103.  
  104.     ld    b,a        ; save # sectors to write
  105.     ld    (wtaddr),hl    ; set dma addr
  106.     ld    a,d        ; get sector number
  107.     inc    a        ; adj properly
  108.     ld    (wtsec),a
  109.     ld    a,e        ; get track number
  110.     ld    (wttrk),a
  111.     ld    a,b        ; restore # sectors to write
  112.  
  113.     ld    bc,iolen    ; length of i/o init area
  114.     ld    de,dmabank    ; in ho common ram
  115.     ld    hl,wtparms    ; to do some track
  116.     ldir            ; this is it
  117.  
  118.     ld    b,a        ; get # sectors to write
  119.     ld    a,wsec        ;and the offset to write it
  120.     call    torom
  121.     or    a        ; any errors writing?
  122.     ret    z        ; no, all done writing
  123.  
  124.     jp    wterr        ; yes, then abort
  125.  
  126.  
  127. ;    dofile
  128. ;        open then read in a file
  129. ;        if "optional"<>0 then file is optional
  130. ;    a    returned=#sectors actually read in
  131. ;    de    ptr to fcb to use
  132. ;    hl    dma address starting
  133.  
  134.  
  135. dofile:        ; open then read this file
  136.     push    hl        ; save dma addr
  137.     ld    (thefcb),de    ; and ptr to fcb
  138.  
  139.     ld    hl,1        ; copy fname and ftype
  140.     add    hl,de        ; from fcb+1
  141.     ld    de,fname    ; copy in this file name
  142.     ld    bc,8
  143.     ldir
  144.     inc    de        ; bump over the '.'
  145.     ld    bc,3        ; for file type
  146.     ldir
  147.  
  148.     ld    de,(thefcb)    ; pt to file
  149.     ld    c,open        ; open the file
  150.     call    bdos
  151.     inc    a        ; ff=not found
  152.     pop    de        ; restore starting dma addr
  153.     jp    z,badopen    ; open error
  154.  
  155.     ld    b,-1        ; init # sectors read count
  156.  
  157. rdloop:    inc    b        ; bump # sectors read
  158.     push    de
  159.     push    bc        ; save sector count
  160.  
  161.     ld    c,setdma    ; set dma addr
  162.     call    bdos
  163.  
  164.     ld    de,(thefcb)    ; crnt fcb
  165.     ld    c,read
  166.     call    bdos        ; read one more 128 byte sector
  167.  
  168.     pop    bc        ; restore sector count
  169.     pop    de
  170.     ld    hl,128        ; advance dma addr too
  171.     add    hl,de
  172.     ex    de,hl
  173.  
  174.     or    a        ; see if done or error
  175.     jr    z,rdloop    ; not done yet
  176.  
  177.     dec    a        ; 1=done
  178.     jr    nz,badread    ; no, error
  179.  
  180.     or    b        ; pass back # sectors read in
  181.  
  182.     ret            ; all done reading, no errors
  183.  
  184.  
  185. wterr:    ld    de,wtmsg    ; write error (no fname)
  186. abort:    call    msg
  187.     jp    exit        ; and all done
  188.  
  189. badopen:
  190.     ld    de,openmsg    ; issue msg
  191.     jr    fabort
  192.  
  193. badread:
  194.     ld    de,readmsg    ; issus msg
  195.  
  196. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  197. ;    fall through
  198. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  199.  
  200. ;    common open/read error handler
  201. ;    if "optional" then return a=0 and done, else error msg.
  202.  
  203. fabort:            ; error opening then reading a file
  204.     call    msg        ; issue msg
  205.     ld    de,fname    ; then say file name
  206.     call    msg
  207.  
  208.     ld    a,(optional)    ; is this file optional
  209.     or    a
  210.     jp    z,exit        ; no, abort now
  211.     xor    a        ; yes, pass back a=0
  212.     ret            ; and done with file
  213.  
  214.  
  215. ;    torom
  216. ;        a=rom routine address
  217. ;        aka ourcode (before it is moved)
  218. ourcode:        ; code which is moved above 4000h
  219.     ld    (thecall+1),a    ; alter the call
  220.     in    a,(sys)
  221.     or    80h    ; turn on rom
  222.     out    (sys),a
  223. xcall:    call    100h    ; call the rom
  224.     push    af    ; save
  225.     in    a,(sys)
  226.     and    07fh    ; turn rom off
  227.     out    (sys),a
  228.     pop    af
  229.     ret        ; and all done
  230. codelen    equ    $-ourcode    ; length to move up
  231.  
  232. himem    equ    5000h    ; move the code here
  233.  
  234. torom    equ    himem    ; routine to call to rom
  235. thecall    equ    torom+(xcall-ourcode)    ; the call instruction
  236.  
  237. stack    equ    himem+400h    ; someplace also in non-rom
  238.  
  239.  
  240. ;    misc variables etc....
  241.  
  242. optional: db    0        ; non-zero if file is optional
  243.  
  244. wtfm:    db    0        ; ? write fontm (0=no)
  245. wtfa:    db    0        ; ? write fonta (0=no)
  246. wtrom:    db    0        ; ? write rom's ram (0=no)
  247.  
  248.  
  249. thefcb:    dw    0        ; ptr to current fcb
  250.  
  251.  
  252. startmsg:
  253.     db    0dh,0ah
  254.     db    'WRITECCP will write CCP.COM to drive A, track1, sector 1'
  255.     db    0dh,0ah,'$'
  256.  
  257. donemsg:
  258.     db    0dh,0ah
  259.     db    'System tracks aok',0dh,0ah,'$'
  260.  
  261. fname:    ds    8        ; common name for messages
  262.     db    '.'
  263. ftype:    ds    3
  264.     db    0dh,0ah,07h,'$'
  265.  
  266. readmsg:
  267.     db    0dh,0ah,'Error reading $'
  268.  
  269. openmsg:
  270.     db    0dh,0ah,'Unable to open $'
  271.  
  272. wtmsg:    db    0dh,0ah,'Error writing system tracks',0dh,0ah,'$'
  273.  
  274. ldrmsg:    db    0dh,0ah,'Error: cpmldr.com is too long'
  275.     db    7,0dh,0ah,'$'
  276.  
  277. ;    this is set of parms passed to the rom
  278. ;    to write 1-5 sectors
  279.  
  280. wtparms:
  281.     db    1    ; bank
  282. wtaddr:    dw    0    ; addr
  283. wtsec:    db    1    ; sector
  284. wttrk:    dw    0    ; track
  285.     db    0    ; unit 'A'
  286.     db    0ch    ; type
  287. iolen    equ    $-wtparms    ; length to move up there
  288.  
  289. ccp:
  290.     db    0,'CCP     COM'
  291.     dw    0,0,00,0,0,0,0,0,0,0,0,
  292.  
  293. initial:                ; do not change this
  294.     db    'ReservedReserved'    ; oh well, fill the unused
  295.                     ; areas on the system
  296.                     ; tracks with something
  297.  
  298. sec1    equ    $    ; start of i/o areas ( 3 tracks long)
  299. sec2    equ    sec1+1024
  300. sec3    equ    sec2+1024
  301. sec4    equ    sec3+1024
  302. sec5    equ    sec4+1024
  303. track0    equ    sec1
  304.  
  305. sec6    equ    sec5+1024    ; sector 1 track 1
  306. sec7    equ    sec6+1024
  307. sec8    equ    sec7+1024
  308. sec9    equ    sec8+1024
  309. sec10    equ    sec9+1024
  310. track1    equ    sec6
  311.     ; secec1ec1u    sec10+1024    ; sector 1 track 2
  312. sec12    equ    sec11+1024
  313. sec13    equ    sec12+1024
  314. sec14    equ    sec13+1024
  315. sec15    equ    sec14+1024
  316. track2    equ    sec11
  317.  
  318. secend    equ    sec15+1024
  319.  
  320. bootsec    equ    sec1        ; excbsec2+ sec 1 trk 0
  321. ldrsec    equ    sec2        ; cpmldr sec 2 trk 0
  322. ccpsec    equ    sec6        ; ccp sec 1 tk 1
  323. oursec    equ    sec10        ; where special stuff goes
  324. fmsec    equ    sec11        ; where main font begins
  325. fasec    equ    sec13        ; where alt font begins
  326. romsec    equ    sec15        ; rom's ram override
  327.  
  328.  
  329.     end
  330. u    sec11        ; where main font beg