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