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 / ENTERPRS / CPM / UTILS / A / BIOS-R62.LZH / FAST8502.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  18KB  |  922 lines

  1.  
  2.  
  3.     title    '8502 drivers        4 Dec 85'
  4.  
  5.     maclib    x6502
  6.  
  7.     maclib    z80
  8.  
  9.     maclib    cxequ
  10.  
  11. $-MACRO
  12. ;
  13. ;      COMMON EQUATES
  14. ;
  15. ; page 0 variables, from 0a to 8f are usable
  16. ;
  17. prtno        equ    0000Ah        ; 0Ah
  18. second$adr    equ    prtno+1        ; 0Bh
  19. DATCHN        equ    second$adr+1    ; 0Ch
  20. CMDCHN        equ    datchn+1    ; 0Dh
  21. DEVNO        equ    cmdchn+1    ; 0Eh
  22. adr$1        equ    devno+1        ; 0Fh
  23. temp$byte    equ    adr$1+2        ; 11h
  24. ;        equ    temp$byte+1    ; 12h
  25.  
  26. pal$nts        equ    00a03h        ; FF=PAL=50Hz 0=NTSC=60Hz
  27. serial        equ    00a1ch
  28. d2pra        equ    0dd00h        ; serial control port (clk and data)
  29. d1sdr        equ    0dc0ch        ; Fast serial data reg.
  30. d1icr        equ    0dc0dh        ; serial channel interrupt control reg
  31.  
  32. clkbit        equ    10h        ; d2pra clock bit mask
  33. ;
  34. ;    KERNAL EQUATES
  35. ;
  36. K$spin$spout    equ    0FF64h        ; C=0 spin  C=1 spout
  37.  
  38. K$setbnk    equ    0FF68h        ; set the logical bank # for open
  39.                     ;  disk commands
  40.                     ;I A=load and store bank # (C128 type bank)
  41.                     ;  X=file name bank #
  42.  
  43. K$readst    equ    0FFB7h        ; read status byte
  44.                     ;O A = status
  45.  
  46. K$setlfs    equ    0FFBAh        ; setup a logical file
  47.                     ;I A=logical file #
  48.                     ;  X=device # (0-31)
  49.                     ;  Y=seconday command (FF if nane)
  50.  
  51. K$setnam    equ    0FFBDh        ; set up file name for OPEN
  52.                     ;I A=name length
  53.                     ;  X=low byte pointer to name
  54.                     ;  Y=high byte pointer to name
  55.  
  56. K$open        equ    0FFC0h        ; open a logical file (after setlfs
  57.                     ; and setnam)
  58.                     ;O A = error # (1,2,4,5,6,240)
  59.  
  60. K$chkin        equ    0FFC6h        ; open a channel for input
  61.                     ;I X = logical file #
  62.                     ;O A = errors #(0,3,5,6)
  63.  
  64. K$chkout    equ    0FFC9h        ; open a channel for output
  65.                     ;I X = logical file #
  66.                     ;O A = error #(0,3,5,7)
  67.  
  68. K$clrchn    equ    0FFCCh        ; clears ALL I/O channel 
  69.  
  70. K$chrin        equ    0FFCFh        ; get a character from input channel
  71.                     ;O A=input character 
  72.  
  73. K$chrout    equ    0FFD2h        ; output a character to output channel
  74.                     ;I A =output char
  75.  
  76. ;GETIN        equ    0FFE4h
  77.  
  78. K$clall        equ    0FFE7h        ; close ALL open logical files
  79.  
  80. K$close        equ    0FFC3h        ; close a logical file
  81.                     ;I A = logical channel # to be closed
  82.                     ;O A = error #(0,240)
  83.  
  84. RESET        equ    0FFFCh
  85.  
  86.     PAGE
  87. ;
  88.     org    bios8502
  89. ;
  90. ; **** THIS IS THE COMMAND LOOP ****
  91. ;
  92. start:
  93.     @ldx    -1,#        ;-K
  94.     @txs            ;-K set the stack to the top
  95.     @JSR    VICIO        ;-K  go find and do requested operation
  96. bios$exit:
  97.     @sei            ;?K  DISABLE INTERRUPTS
  98.     @ldx    3eh,#        ;?K  set up Z80 memory map as required
  99.     @stx    force$map    ;?K
  100.     @ldx    82h,#        ;-K
  101.     @stx    CIA1+int$ctrl    ;-K  turn on CIA timer B interrupts
  102.     @jmp    enable$z80+6    ;-K
  103.  
  104.     PAGE
  105. ;
  106. ;
  107. ;
  108. iotbl:
  109.     dw    sys$reset    ;-1 reset system (C128)
  110.     dw    initilize    ;0 initialize the 8502
  111.     dw    READ        ;1 Read a sector of data to sector buffer
  112.     dw    WRITE        ;2 Write a "     "   "   "    "      "
  113.     dw    readf        ;3 Set-up for fast read (154X only)
  114.     dw    writef        ;4 Set-up for fast write (154X only)
  115.     dw    dsktst        ;5 test for 154x and diskette type
  116.     dw    query$dsk    ;6 get disk characteristics
  117.     dw    PRINT        ;7 print data character
  118.     dw    FORMAT        ;8 format disk as 1541 disk
  119.     dw    user$fun    ;9 vector to user code (L=viccount,H=vicdata) 
  120.     dw    ram$dsk$rd    ;10 RAM disk read
  121.     dw    ram$dsk$wr    ;11 RAM disk write
  122.  
  123.  
  124. NUMCMD        equ    ($-IOTBL)/2    ; NUMBER OF COMMANDS
  125. iotbl$low    equ    low(iotbl)
  126.  
  127.  
  128. ;
  129. ;
  130. ;
  131. sys$reset:            ;**CMD ENTRY**
  132.     @jsr    en$kernal    ;-K
  133.     @JMP    (RESET)        ;+K
  134. ;
  135. ;
  136. ;
  137. user$fun:            ;**CMD ENTRY**
  138.     @jmp    (vic$count)    ;-K
  139.  
  140.     page
  141. ;
  142. ; **** IO COMMAND DISPATCH ROUTINE ****
  143. ;
  144. VICIO:
  145.     @lda    vic$cmd        ;-K  get the command
  146.     @cmp    NUMCMD,#    ;-K  is this a valid command
  147.     @bcs    bad$command    ;-K  no, exit without doing anything
  148.                 ;-K  yes, get vector to it
  149.     @cld            ;-K  clear to binary mode
  150.     @asl    a        ;-K  A=2*CMD (carry cleared)
  151.     @clc            ;-K
  152.     @adc    iotbl$low+2,#    ;-K  add to vector table start address
  153.     @sta    VICIO2+1    ;-K  modify the JMP instructions ind adr
  154. VICIO2:
  155.     @jmp    (IOTBL)        ;-K  this is the ind adr that
  156.                    ; is modified above
  157. ;
  158. ;
  159. ;
  160. input$byte:
  161.     @sei
  162.     @lda    d2pra
  163.     @eor    clk$bit,#
  164.     @sta    d2pra
  165. ;
  166.     @lda    8,#
  167. in$1:
  168.     @bit    d1icr
  169.     @beq    in$1
  170.     @lda    d1sdr
  171. bad$command:
  172.     @RTS            ;-K
  173.  
  174.     page
  175. ;
  176. ;    initialize the 8502
  177. ;
  178. initilize:            ;**CMD ENTRY**
  179.     @ldx    low(irqs),#        ;-K
  180.     @ldy    high(irqs),#        ;-K
  181.     @stx    314h            ;-K  IRQ vector
  182.     @sty    315h            ;-K
  183.     @stx    316h            ;-K  BRK vector
  184.     @sty    317h            ;-K
  185.     @stx    318h            ;-K  NMI vector
  186.     @sty    319h            ;-K
  187.  
  188.     @jsr    en$kernal        ;-K
  189.     @lda    0fffeh            ;+K
  190.     @sta    0fffeh            ;+K  write to RAM under ROM
  191.     @lda    0ffffh            ;+K
  192.     @sta    0ffffh            ;+K
  193.  
  194.     @lda    6,#            ;+K
  195.     @sta    CIA2+data$dir$b        ;+K setup user port for RS232
  196.  
  197.     @lda    pal$nts            ;+K -1=50Hz(PAL) 0=60Hz(NTSC)
  198.     @sta    sys$freq        ;+K
  199.     @jmp    K$clall            ;+K  close all open files
  200.  
  201.     PAGE
  202. ;
  203. ; **** DISK SECTOR READ ****
  204. ;
  205. READ:                ;**CMD ENTRY**
  206.     @JSR    set$drv        ;-K
  207.     @jsr    en$kernal    ;+K
  208.     @ldx    datchn        ;+K
  209.     @jsr    K$chkin        ;+K
  210.     @bcs    disk$changed    ;+K
  211.     @jsr    K$clrchn    ;+K  clear the input channel for now
  212.  
  213.     @LDA    '1',#        ;+K  read command
  214.     @JSR    setup        ;+K  send it
  215.     @JSR    CKINDT        ;+K
  216.     @LDX    0,#        ;+K
  217. ;
  218. READ1:
  219.     @JSR    K$chrin        ;+K  get a byte from the KERNAL
  220.     @STA    @BUFFER,X    ;+K  save it in the buffer
  221.     @INX            ;+K  advance the buffer pointer
  222.     @BNE    READ1        ;+K  loop back if not past buf end
  223.     @jmp    K$clrchn    ;+K  CLEAR CHANNEL
  224. ;
  225. ;
  226. disk$changed:
  227.     @lda    0bh,#        ;?K  disk changed error code
  228.     @sta    vic$data    ;?K
  229.     @jmp    en$K$open    ;?K
  230.  
  231.     page
  232. ;
  233. ; **** DISK SECTOR WRITE ****
  234. ;
  235. WRITE:                ;**CMD ENTRY**
  236.     @jsr    set$drv        ;-K
  237.     @jsr    ckotcm        ;-K
  238.     @LDY    setpnt$lng,#    ;+K
  239. ;
  240. WRITE0:
  241.     @LDA    SETPNT,X    ;+K
  242.     @JSR    K$chrout    ;+K
  243.     @INX            ;+K
  244.     @DEY            ;+K
  245.     @BNE    WRITE0        ;+K
  246.  
  247.     @JSR    K$clrchn    ;+K
  248.     @JSR    CKINCM        ;+K
  249.     @BNE    WRITE2        ;+K
  250.  
  251.     @JSR    K$clrchn    ;+K
  252.     @JSR    CKOTDT        ;+K
  253.     @LDX    0,#        ;+K
  254. ;
  255. WRITE1:
  256.         @sei             ;+K  disable interrupts
  257.     @ldy    3fh,#        ;+K  enable all RAM in bank 0
  258.     @sty    force$map    ;+K
  259.     @LDA    @BUFFER,X    ;-K
  260.     @ldy    0,#        ;-K  re-enable kernal
  261.     @sty    force$map    ;-K
  262. ;    @cli            ;+K  interrupts back on
  263.     @JSR    K$chrout    ;+K  write buffer character
  264.     @INX            ;+K
  265.     @BNE    WRITE1        ;+K  write all 256 bytes of buffer
  266.  
  267.     @JSR    K$clrchn    ;+K  clear the channel
  268.     @LDA    '2',#        ;+K  write command
  269.     @JMP    setup        ;+K
  270. ;
  271. WRITE2:
  272.     @lda    0ffh,#        ;+K
  273.     @sta    vic$data    ;+K  writes thru ROM to RAM
  274.     @jmp    opencm        ;+K
  275.  
  276.     page
  277. ;
  278. ;    Set-up for fast disk write
  279. ;
  280. writef:                ;**CMD ENTRY**
  281.     @lda    2,#        ;-K 2=read command
  282.     @skip2            ;-K
  283. ;
  284. ;    Set-up for fast disk read
  285. ;
  286. readf:                ;**CMD ENTRY**
  287.     @lda    0,#        ;-K 0=read command
  288.     @sta    f$cmd        ;-K
  289.     @lda    0,#        ;-K
  290.     @sta    vic$data    ;-K
  291.     @jsr    set$drv$f    ;-K
  292.     @ldy    f$cmd$lng,#    ;-K  command set above rd/wr
  293.     @jsr    send$fast    ;-K
  294.     @jmp    clk$hi        ;+K
  295.  
  296.     page
  297. ;
  298. ;    test the format of the disk return code to CP/M
  299. ;    telling the disk type. Also test for FAST disk drive.
  300. ;
  301. dsktst:                ;**CMD ENTRY**
  302.     @lda    vic$drv        ;-K
  303.     @eor    0ffh,#        ;-K
  304.     @and    fast        ;-K
  305.     @sta    fast        ;-K  clear fast indicator bit for current drive
  306.  
  307.     @jsr    set$and$open    ;-K  set drv close and reopen the channel
  308.  
  309.     @ldx    0,#        ;+K  delay to allow drive to reset status
  310. tst$delay:
  311.     @nop            ;+K
  312.     @nop            ;+K
  313.     @dex            ;+K
  314.     @bne    tst$delay    ;+K
  315.  
  316.     @ldy    inq$cmd$lng,#    ;+K
  317.     @ldx    inq$cmd,#    ;+K
  318.     @jsr    send$fast$cmd    ;+K
  319.  
  320.     @jsr    input$byte    ;+K
  321.     @sta    vic$data    ;+K
  322.     @jsr    clk$hi        ;+K
  323.     @jsr    dis$kernal    ;+K
  324.     @lda    vic$drv        ;-K
  325.     @ora    fast        ;-K  set current drive as fast
  326.     @sta    fast        ;-K
  327.     @rts            ;-K
  328.  
  329.     page
  330. ;
  331. ;
  332. ;
  333. query$dsk:                ;**CMD ENTRY**
  334.     @jsr    set$drv$f        ;-K  will query track set by user
  335.     @ldy    query$cmd$lng,#        ;-K  command length is 4
  336.     @ldx    query$cmd,#        ;-K
  337.     @jsr    send$fast$cmd        ;-K
  338.     @jsr    input$byte        ;+K
  339.     @sta    vic$data        ;+K
  340.     @bpl    clk$hi            ;+K  exit if not MFM
  341.     @and    0eh,#            ;+K  test for error
  342.     @bne    clk$hi            ;+K  exit if error
  343.     @jsr    input$byte        ;+K  read offset sectors status byte
  344.     @sta    @buffer            ;+K
  345.     @and    0eh,#            ;+K  test for error
  346.     @bne    clk$hi            ;+K  exit if error 
  347.     @tax                ;+K get a zero in X
  348.     @ldy    5,#            ;+K five info bytes are sent back
  349. query$loop:
  350.     @inx
  351.     @jsr    input$byte
  352.     @sta    @buffer,X
  353.     @dey
  354.     @bne    query$loop
  355.  
  356. clk$hi:
  357.     @lda    d2pra            ;+K set clock bit HIGH
  358.     @and    0ffh-clkbit,#
  359.     @sta    d2pra
  360.     @rts
  361.  
  362.     PAGE
  363. ;
  364. ; **** PRINTER OUTPUT ****
  365. ;
  366. ;    this routine will support two printers
  367. ;    the device number is passed in vic$drv (4,5)
  368. ;    secondary address in vic$trk
  369. ;    the logical file number is equal to the device #
  370. ;    if VIC$count=0 then output character in VIC$data
  371. ;    if VIC$count<>0 then output characters pointered to by @buffer
  372. ;
  373. PRINT:                ;**CMD ENTRY**
  374.     @lda    vic$drv        ;-K
  375.     @sta    prtno        ;-K
  376.     @lda    vic$trk        ;-K
  377.     @sta    second$adr    ;-K  this line should be deleted and one
  378.     @cmp    second$adr    ;-K  ..below used.
  379. ;;    @sta    second$adr    ;-K  save secondary adr
  380.     @bne    reopen$prt    ;-K
  381.  
  382.     @jsr    en$kernal    ;-K
  383. print$cont:
  384.     @ldx    prtno        ;+K
  385.     @JSR    K$chkout    ;+K
  386.     @BCS    PERR0        ;+K  PRINT ERROR IF CARRY SET
  387.  
  388.     @jsr    dis$kernal    ;+K
  389.     @ldx    vic$count    ;-K  
  390.     @bne    print$buffer    ;-K
  391.     @LDA    vic$data    ;-K  GET CHARACTER
  392.     @sta    io$0        ;-K
  393.     @JSR    K$chrout    ;+K  AND PRINT IT
  394.     @JMP    K$clrchn    ;+K  CLEAR CHANNEL
  395.  
  396. print$buffer:
  397.     @stx    temp$byte    ;-K
  398.     @lda    @buffer        ;-K
  399.     @sta    adr$1        ;-K
  400.     @lda    @buffer+1    ;-K
  401.     @sta    adr$1+1        ;-K
  402.     @ldy    0,#        ;-K
  403.     @ldx    0,#        ;-K
  404.  
  405. print$buf$loop:
  406.     @sta    bank$0        ;?K    enable RAM bank 0 (no I/O)
  407.     @lda    (adr$1),y    ;rK
  408.     @stx    force$map    ;rK
  409.     @jsr    K$chrout    ;+K
  410.     @iny            ;+K
  411.     @dec    temp$byte    ;+K
  412.     @bne    print$buf$loop    ;+K
  413.     @jmp    K$clrchn    ;+K
  414.  
  415. ;
  416. ;
  417. PERR0:
  418.     @CMP    3,#        ;+K  FILE NOT OPEN?
  419.     @BNE    PERR1        ;+K  BRANCH IF NO
  420. reopen$prt:
  421.     @JSR    OPNPRT        ;?K  OPEN PRINTER CHANNEL
  422.     @BCC    print$cont    ;+K  IF CARRY CLEAR, OK TO PRINT
  423. PERR1:    @LDA    255,#        ;+K  NO DEVICE PRESENT
  424.     @STA    vic$data    ;+K  FLAG BAD ATTEMPT writes to ram under ROM
  425. PRTST:    @RTS            ;+K
  426.  
  427.     PAGE
  428. ;
  429. ; **** FORMAT DISK ROUTINE ****
  430. ;
  431. FORMAT:                ;**CMD ENTRY**
  432.     @jsr    set$drv$num    ;-K
  433.     @lda    fast        ;-K
  434.     @and    vicdrv        ;-K
  435.     @bne    format$fast    ;-K
  436.  
  437.     @JSR    CKOTCM        ;-K  returns X=0
  438.     @LDY    fmtcmd$lng,#    ;+K
  439. FMT1:    @LDA    FMTCMD,X    ;+K
  440.     @JSR    K$chrout    ;+K
  441.     @INX            ;+K
  442.     @DEY            ;+K
  443.     @BNE    FMT1        ;+K
  444.     @JSR    K$clrchn    ;+K
  445. fmt2:    @JSR    CKINCM        ;+K check for errors
  446.     @BEQ    setup3        ;+K no errors, return good status
  447.     @BNE    setup5        ;+K error return error status
  448.  
  449. format$fast:
  450.     @ldx    @buffer        ;-K get command length
  451. fast$F:                ;-K
  452.     @lda    @buffer+1-1,x    ;-K
  453.     @sta    F$cmd-1,x    ;-K
  454.     @dex            ;-K transfer command tail from buffer+1
  455.     @bne    fast$F
  456.     @ldy    @buffer        ;-K
  457.     @iny            ;-K
  458.     @iny            ;-K  count is tail length plus 2
  459.     @ldx    F$cmd        ;-K
  460.     @jsr    send$fast$cmd    ;-K
  461.     @jmp    fmt2        ;+K
  462.  
  463.     PAGE
  464. ;
  465. ;
  466. ;
  467. ram$dsk$rd:            ; RAM disk read
  468.     @ldx    81h,#            ;-K
  469.     @skip$2                ;-K
  470. ;
  471. ;
  472. ;
  473. ram$dsk$wr:            ; RAM disk write
  474.     @ldx    80h,#            ;-K
  475.     @lda    3fh,#            ;-K  point to RAM bank 0
  476.     @stx    RM$command        ;-K
  477.     @sta    force$map        ;-K
  478.     @rts                ;-K
  479.  
  480.  
  481.     PAGE
  482. ;
  483. ;
  484. ;
  485. setup:
  486.     @STA    DSKCMD+1    ;?K
  487.     @LDA    2,#        ;?K  RETRY COUNT
  488.     @STA    vic$data    ;?K  writes to RAM under ROM
  489.  
  490.     @JSR    CKOTCM        ;?K  returns X=0
  491.     @LDY    dskcmd$lng,#    ;+K
  492. setup2:
  493.     @LDA    DSKCMD,X    ;+K
  494.     @JSR    K$chrout    ;+K
  495.     @INX            ;+K
  496.     @DEY            ;+K
  497.     @BNE    setup2        ;+K
  498.  
  499.     @JSR    K$clrchn    ;+K
  500.     @JSR    CKINCM        ;+K
  501.     @BEQ    setup3        ;+K
  502.  
  503.     @jsr    dis$kernal    ;+K
  504.     @DEC    vic$data    ;-K
  505.     @BEQ    setup5        ;-K
  506.  
  507.     @jmp    disk$changed    ;-k
  508. ;
  509. ;
  510. setup5:
  511.     @LDA    0dh,#        ;?K  normal read/write error flag
  512.     @skip2            ;?K  ALWAYS
  513. ;
  514. ;
  515. ;
  516. setup3:
  517.     @lda    0,#        ;?K  get data good flag
  518. setup4:
  519.     @STA    vic$data    ;?K  writes to RAM under ROM    
  520.     @jsr    en$kernal    ;?K
  521.     @JMP    K$clrchn    ;+K
  522.  
  523.     page
  524. ;
  525. ;
  526. ;
  527. send$fast$cmd:
  528.     @jsr    set$cmd        ;?K  unit # must have been set already
  529. send$fast:
  530.     @ldx    0,#        ;?K
  531.     @stx    force$map    ;?K  enable the kernal
  532.     @ldx    cmdchn        ;+K
  533.     @jsr    K$chkout    ;+K
  534.     @bcs    chan$error    ;+K
  535.     @ldx    0,#        ;+K
  536. sendf:
  537.     @lda    f$cmd$buf,x    ;+K
  538.     @jsr    K$chrout    ;+K
  539.     @inx            ;+K
  540.     @dey            ;+K
  541.     @bne    sendf        ;+K
  542.     @jsr    K$clrchn    ;+K
  543.     @bit    serial        ;+K
  544.     @bvc    not$fast    ;+K
  545.     @bit    d1icr        ;+K  clear interrupts from chip
  546.     @rts            ;+K
  547.  
  548. chan$error:
  549.     @lda    0dh,#        ;+K  get error code
  550.     @skip2            ;+K
  551. not$fast:
  552.     @lda    0ch,#        ;+K  get error code
  553.     @sta    vic$data    ;+K
  554.     @jsr    clk$hi        ;+K
  555.     @jmp    bios$exit    ;+K
  556. ;
  557. ;
  558. ;
  559. set$cmd:
  560.     @lda    dskcmd+5    ;?K check lsb of unit #
  561.     @ror    a        ;?K get lsb to carry bit
  562.     @bcc    unit$0        ;?K
  563.     @inx            ;?K  make command for unit 1
  564. unit$0:
  565.     @stx    F$cmd        ;?K
  566.     @rts
  567.  
  568.     page
  569. ;
  570. ;    ........not tested........
  571. ;
  572. ;rd$buff:
  573. ;    @sei            ; disable interrupts
  574. ;    @lda    vic$data
  575. ;    @sta    adr$1+1        ; save hi part of address
  576. ;    @lda    0,#
  577. ;    @sta    adr$1        ; save low part of address
  578. ;    @tax            ; get a zero for both indexes
  579. ;    @tay
  580. ;
  581. ;rd$buf$1:
  582. ;    @lda    (adr$1),y    
  583. ;    @sta    @buffer,x
  584. ;    @inx
  585. ;    @iny
  586. ;    @bne    rd$buf$1
  587. ;    @rts
  588.  
  589.     PAGE
  590. ;
  591. ;
  592. ;
  593. set$drv:
  594.     @lda    vic$trk        ;-K
  595.     @jsr    binasc        ;-K
  596.     @stx    dskcmd+7    ;-K
  597.     @sta    dskcmd+8    ;-K
  598.  
  599.     @lda    vic$sect    ;-K
  600.     @bmi    no$side$1    ;-K
  601.     @jsr    binasc        ;-K
  602.     @stx    dskcmd+10    ;-K
  603.     @sta    dskcmd+11    ;-K
  604.     @jmp    set$drv$num    ;-K
  605.  
  606. no$side$1:
  607.     @lda    04h,#        ;-K
  608.     @sta    vic$data    ;-K
  609.     @jmp    bios$exit    ;-K
  610.  
  611. ;
  612. ;
  613. ;
  614. set$drv$f:
  615.     @lda    vic$count    ;-K
  616.     @sta    f$rd$count    ;-K
  617.  
  618.     @lda    vic$trk        ;-K
  619.     @sta    f$rd$trk
  620.  
  621.     @lda    vic$sect    ;-K
  622.     @bpl    side$0        ;-K
  623.     @tax            ;-K
  624.     @lda    f$cmd        ;-K
  625.     @ora    10h,#        ;-K
  626.     @sta    f$cmd        ;-K
  627.     @txa            ;-K
  628.     @and    7fh,#        ;-K
  629. side$0:
  630.     @sta    f$rd$sect    ;-K
  631.  
  632.     page
  633. ;
  634. ;         VIC$DRV               dev,dat,cmd
  635. ;        00000001    device  #8-0     8,11,15
  636. ;        00000010    device  #9-0     9,12,16
  637. ;        00000100    device #10-0    10,13,17
  638. ;        00001000    device #11-0    11,14,18
  639. ;        10000001    device  #8-1     8,11,15
  640. ;        10000010    device    #9-1     9,12,16
  641. ;        10000100    device #10-1    10,13,17
  642. ;        10001000    device #11-1    11,14,18
  643. ;
  644. set$drv$num:
  645. ;    @cli            ;-K
  646.     @ldy    8-1,#        ;-K start as drive 8
  647.     @ldx    '0',#        ;-K ..unit 0
  648.     @lda    vic$drv        ;-K get requested drv#
  649.     @bpl    unit$nu$0
  650.     @inx            ;-K make unit 1
  651. unit$nu$0:
  652.     @iny            ;-K add one to the drive #
  653.     @lsr    a        ;-K is drive number correct?
  654.     @bcc    unit$nu$0    ;-K no, loop back
  655.  
  656.     @stx    dskcmd+5    ;-K save unit# to disk cmd string
  657.     @stx    fmtcmd+1    ;-K save unit# to format cmd string
  658.     @txa
  659.     @ror    a        ;-K get lsb to carry bit
  660.     @lda    F$cmd
  661.     @and    0feh,#
  662.     @adc    0,#        ; set the lsb if carry set (carry cleared)
  663.     @sta    F$cmd
  664.     @tya             ;-K get device # to A
  665.     @sta    devno        ;-K save device #
  666.     @adc    3,#        ;-K make the data chan# (carry cleared above)
  667.     @sta    datchn        ;-K save data chan#
  668.     @adc    4,#        ;-K make the cmd chan#
  669.     @sta    cmdchn        ;-K save cmd chan#
  670.     @lda    serial        ;-K
  671.     @and    0bfh,#        ;-K
  672.     @sta    serial        ;-K  clear the fast serial indicator
  673.     @rts            ;-K
  674.  
  675.     page
  676.  
  677. ;
  678. ; **** CONVERT BINARY TO ASCII ****
  679. ;
  680. BINASC:
  681.     @CLD            ;?K
  682.     @LDX    '0',#        ;?K
  683.     @SEC            ;?K
  684.  
  685. BA0:
  686.     @SBC    10,#        ;?K
  687.     @BCC    BA1        ;?K
  688.  
  689.     @INX            ;?K
  690.     @BCS    BA0        ;?K
  691.  
  692. BA1:
  693.     @ADC    3Ah,#        ;?K
  694.     @RTS            ;?K
  695.  
  696.     PAGE
  697. ;
  698. ; **** OPEN DISK COMMAND CHANNEL ****
  699. ;
  700. set$and$open:
  701.     @jsr    set$drv$num    ;-K
  702. en$K$open:
  703.     @jsr    en$kernal    ;-K
  704. opencm:
  705.     @LDA    CMDCHN        ;+K
  706.     @clc            ;+K  clear the carry to force true closing 
  707.     @JSR    K$close        ;+K
  708.  
  709.     @LDA    CMDCHN        ;+K
  710.     @LDX    DEVNO        ;+K
  711.     @LDY    15,#        ;+K
  712.     @JSR    K$setlfs    ;+K
  713.  
  714.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  715.     @sta    F$stat        ;+K  write status byte value = 0
  716.     @tax            ;+K  file name bank (C128 type bank#)
  717.     @jsr    K$setbnk    ;+K
  718.  
  719.     @ldx    write$stat,#    ;+K
  720.     @jsr    set$cmd        ;+K
  721.  
  722.     @lda    4,#        ;+K write status command lenght
  723.     @ldx    low(f$cmd$buf),#    ;+K
  724.     @ldy    high(f$cmd$buf),#    ;+K
  725.     @JSR    K$setnam        ;+K
  726.  
  727.     @JSR    K$open        ;+K
  728.     @bcs    misdsk
  729.  
  730.     @JSR    K$readst
  731.     @ROL    A        ;+K  GET MSB TO CARRY
  732.     @BCS    MISDSK        ;+K  DEVICE MISSING IF CARRY SET
  733.  
  734.     @bit    serial        ;+K  test for fast device
  735.     @bvs    no$dt$open    ;+K  do not open data channel if fast
  736. ;
  737. ; **** OPEN DISK DATA CHANNEL ****
  738. ;
  739. OPENDT:
  740.     @LDA    DATCHN        ;+K
  741.     @clc            ;+K  forces true closing of channel
  742.     @JSR    K$close        ;+K
  743.     @LDA    DATCHN        ;+K
  744.     @LDX    DEVNO        ;+K
  745.     @LDY    8,#        ;+K
  746.     @JSR    K$setlfs    ;+K
  747.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  748.     @tax            ;+K  file name bank (C128 type bank#)
  749.     @jsr    K$setbnk    ;+K
  750.     @LDA    1,#        ;+K
  751.     @LDX    low(POUND),#    ;+K
  752.     @LDY    high(POUND),#    ;+K
  753.     @JSR    K$setnam    ;+K
  754.     @jsr    K$open        ;+K
  755.     @bcs    misdsk
  756. no$dt$open:
  757.     @rts
  758.  
  759.     page
  760. ;
  761. ;
  762. ;  * DEVICE MISSING, CLEAN UP ERROR *
  763. ;
  764. MISDSK:
  765.     @LDA    0fh,#        ;+K  SET ERROR CODE for missing drive
  766.     @STA    vic$data    ;+K  writes to RAM under ROM
  767.     @LDA    CMDCHN        ;+K  K$close CHANNEL
  768.     @clc            ;+K  force true closing of channel
  769.     @JSR    K$close        ;+K
  770.     @JMP    bios$exit    ;+K
  771.  
  772.     PAGE
  773. ;
  774. ; **** SELF CORRECTING CHECK IO ROUTINES ****
  775. ;
  776. CKICM:
  777.     @JSR    OPENCM        ;+K
  778.  
  779. CKINCM:
  780.     @LDX    CMDCHN        ;+K
  781.     @JSR    K$chkin        ;+K
  782.     @BCS    CKICM        ;+K
  783.  
  784.     @JSR    K$chrin        ;+K
  785.     @CMP    '0',#        ;+K
  786.     @RTS            ;+K
  787. ;
  788. ;
  789. ;
  790. CKIDT:
  791.     @JSR    OPENDT        ;+K
  792. CKINDT:
  793.     @LDX    DATCHN        ;+K
  794.     @JSR    K$chkin        ;+K
  795.     @BCS    CKIDT        ;+K
  796.  
  797.     @RTS            ;+K
  798. ;
  799. ;
  800. ;
  801. CKODT:
  802.     @JSR    OPENDT        ;+K
  803. CKOTDT:
  804.     @LDX    DATCHN        ;+K
  805.     @JSR    K$chkout    ;+K
  806.     @BCS    CKODT        ;+K
  807.  
  808.     @RTS            ;+K
  809. ;
  810. ;
  811. ;
  812. CKOCM:
  813.     @jsr    OPENCM        ;+K
  814. CKOTCM:
  815.     @jsr    en$kernal    ;?K
  816.     @LDX    CMDCHN        ;+K
  817.     @JSR    K$chkout    ;+K
  818.     @BCS    CKOCM        ;+K
  819.  
  820.     @LDX    0,#        ;+K
  821.     @RTS            ;+K
  822.  
  823.     PAGE
  824. ;
  825. ; **** OPEN PRINTER CHANNEL ****
  826. ;
  827. opnprt:
  828.     @jsr    en$kernal    ;-K
  829.     @lda    prtno        ;+K
  830.     @clc            ;+K
  831.     @JSR    K$close        ;+K
  832.  
  833.     @lda    prtno        ;+K
  834.     @TAX            ;+K  LDX #4 (or #5)
  835.     @ldy    second$adr    ;+K secondary adr passed in vic$trk (normaly=7)
  836.     @JSR    K$setlfs    ;+K
  837.     @LDA    0,#        ;+K
  838.     @JSR    K$setnam    ;+K
  839.     @lda    0,#        ;+K  bank (C128 type) for load and store 
  840.     @tax            ;+K  file name bank (C128 type bank#)
  841.     @jsr    K$setbnk    ;+K
  842.     @JMP    K$open        ;+K
  843.  
  844.     page
  845. ;
  846. ;    handle all interrupts in BIOS 8502 (throw them away)
  847. ;
  848. irqs:
  849.     @lda    CIA$1+int$ctrl
  850.     @lda    CIA$2+int$ctrl
  851.     @lda    0fh,#
  852.     @sta    VIC+25
  853.  
  854.     @pla
  855.     @sta    force$map
  856.     @pla
  857.     @tay
  858.     @pla
  859.     @tax
  860.     @pla
  861.     @rti
  862.  
  863. ;
  864. ;
  865. ;
  866. en$kernal:
  867.     @ldy    0,#        ;?K
  868.     @sty    force$map    ;?K
  869. ;    @cli            ;+K  enable interrupts
  870.     @rts            ;+K
  871.  
  872. ;
  873. ;
  874. ;
  875. dis$kernal:
  876.     @sei            ;?K  disable interrupts
  877.     @ldy    3eh,#        ;?K
  878.     @sty    force$map    ;?K
  879.     @rts            ;-K
  880.  
  881.     page
  882. ;
  883. ;
  884. ;
  885. DSKCMD:        db    'U1:8 0 tt ss',CR
  886. dskcmd$lng    equ    $-dskcmd
  887.  
  888. POUND:        db    '#'
  889.  
  890. FMTCMD:        db    'N0:CP/M DISK,65',CR
  891. fmtcmd$lng    equ     $-FMTCMD
  892.  
  893. SETPNT:        db    'B-P 8 0',CR
  894. setpnt$lng    equ    $-setpnt
  895. ;
  896. ;    fast command buffer
  897. ;
  898. f$cmd$buf:    db    'U0'    ; not set
  899. f$cmd:        db    0    ; byte 3
  900. F$stat:
  901. f$rd$trk:    db    1    ; byte 4
  902. f$rd$sect:    db    0    ; byte 5
  903. f$rd$count:    db    1    ; byte 6
  904.         db    0    ; byte 7
  905.         db    0    ; byte 8
  906.         db    0    ; byte 9
  907.         db    0    ; byte 10
  908.         db    0    ; byte 11
  909.  
  910. f$cmd$lng    equ    6        ; U0+cmd+track+sector+#sectors
  911.  
  912. write$stat    equ    01001100b
  913. write$stat$lng    equ    4        ; U0+cmd+(status to write)
  914.  
  915. inq$cmd:    equ    00000100b
  916. inq$cmd$lng    equ    3        ; U0+cmd
  917.  
  918. query$cmd:    equ    10001010b
  919. query$cmd$lng    equ    4        ; U0+cmd+(track offset)
  920.  
  921.  
  922.