home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / cpmsim / srccpm / bios32.asm < prev    next >
Encoding:
Assembly Source File  |  1992-07-09  |  10.1 KB  |  332 lines

  1. ;       CBIOS for Z80-Simulator
  2. ;
  3. ;       Copyright (C) 1988 by Udo Munk
  4. ;
  5. MSIZE   EQU     32              ;cp/m version memory size in kilobytes
  6. ;
  7. ;    "bias" is address offset from 3400H for memory systems
  8. ;    than 16K (referred to as "b" throughout the text).
  9. ;
  10. BIAS    EQU    (MSIZE-20)*1024
  11. CCP    EQU    3400H+BIAS    ;base of ccp
  12. BDOS    EQU    CCP+806H    ;base of bdos
  13. BIOS    EQU    CCP+1600H    ;base of bios
  14. CDISK    EQU    0004H        ;current disk number 0=A,...,15=P
  15. IOBYTE    EQU    0003H        ;intel i/o byte
  16. ;
  17. ;       I/O ports
  18. ;
  19. CONSTA  EQU     0               ;console status port
  20. CONDAT  EQU     1               ;console data port
  21. PRTSTA  EQU     2               ;printer status port
  22. PRTDAT  EQU     3               ;printer data port
  23. AUXDAT  EQU     5               ;auxiliary data port
  24. FDCD    EQU     10              ;fdc-port: # of drive
  25. FDCT    EQU     11              ;fdc-port: # of track
  26. FDCS    EQU     12              ;fdc-port: # of sector
  27. FDCOP   EQU     13              ;fdc-port: command
  28. FDCST   EQU     14              ;fdc-port: status
  29. DMAL    EQU     15              ;dma-port: dma address low
  30. DMAH    EQU     16              ;dma-port: dma address high
  31. ;
  32.     ORG    BIOS        ;origin of this program
  33. NSECTS  EQU     (BIOS-CCP)/128  ;warm start sector count
  34. ;
  35. ;    jump vector for individual subroutines
  36. ;
  37.     JP      BOOT            ;cold start
  38. WBOOTE: JP      WBOOT           ;warm start
  39.     JP      CONST           ;console status
  40.     JP      CONIN           ;console character in
  41.     JP      CONOUT          ;console character out
  42.     JP      LIST            ;list character out
  43.     JP      PUNCH           ;punch character out
  44.     JP      READER          ;reader character out
  45.     JP      HOME            ;move head to home position
  46.     JP      SELDSK          ;select disk
  47.     JP      SETTRK          ;set track number
  48.     JP      SETSEC          ;set sector number
  49.     JP      SETDMA          ;set dma address
  50.     JP      READ            ;read disk
  51.     JP      WRITE           ;write disk
  52.     JP      LISTST          ;return list status
  53.     JP      SECTRAN         ;sector translate
  54. ;
  55. ;    fixed data tables for four-drive standard
  56. ;    IBM-compatible 8" disks
  57. ;
  58. ;    disk parameter header for disk 00
  59. DPBASE:    DEFW    TRANS,0000H
  60.     DEFW    0000H,0000H
  61.     DEFW    DIRBF,DPBLK
  62.     DEFW    CHK00,ALL00
  63. ;    disk parameter header for disk 01
  64.     DEFW    TRANS,0000H
  65.     DEFW    0000H,0000H
  66.     DEFW    DIRBF,DPBLK
  67.     DEFW    CHK01,ALL01
  68. ;    disk parameter header for disk 02
  69.     DEFW    TRANS,0000H
  70.     DEFW    0000H,0000H
  71.     DEFW    DIRBF,DPBLK
  72.     DEFW    CHK02,ALL02
  73. ;    disk parameter header for disk 03
  74.     DEFW    TRANS,0000H
  75.     DEFW    0000H,0000H
  76.     DEFW    DIRBF,DPBLK
  77.     DEFW    CHK03,ALL03
  78. ;
  79. ;    sector translate vector
  80. ;
  81. TRANS:    DEFB    1,7,13,19    ;sectors 1,2,3,4
  82.     DEFB    25,5,11,17    ;sectors 5,6,7,8
  83.     DEFB    23,3,9,15    ;sectors 9,10,11,12
  84.     DEFB    21,2,8,14    ;sectors 13,14,15,16
  85.     DEFB    20,26,6,12    ;sectors 17,18,19,20
  86.     DEFB    18,24,4,10    ;sectors 21,22,23,24
  87.     DEFB    16,22        ;sectors 25,26
  88. ;
  89. ;       disk parameter block, common to all disks
  90. ;
  91. DPBLK:  DEFW    26              ;sectors per track
  92.     DEFB    3               ;block shift factor
  93.     DEFB    7               ;block mask
  94.     DEFB    0               ;null mask
  95.     DEFW    242             ;disk size-1
  96.     DEFW    63              ;directory max
  97.     DEFB    192             ;alloc 0
  98.     DEFB    0               ;alloc 1
  99. ;       DEFW    16              ;check size
  100.     DEFW    0               ;because medium not changable with z80sim!
  101.     DEFW    2               ;track offset
  102. ;
  103. ;       signon message
  104. ;
  105. SIGNON: DEFM    '32K CP/M Vers. 2.2'
  106.     DEFB    0
  107. ;
  108. ;    end of fixed tables
  109. ;
  110. ;    individual subroutines to perform each function
  111. ;       simplest case is to just perform parameter initialization
  112. ;
  113. BOOT:   LD      SP,80H          ;use space below buffer for stack
  114.     LD      HL,SIGNON       ;print message
  115. BOOTL:  LD      A,(HL)
  116.     OR      A
  117.     JP      Z,BOOTC
  118.     LD      C,A
  119.     CALL    CONOUT
  120.     INC     HL
  121.     JP      BOOTL
  122. BOOTC:  XOR     A               ;zero in the accum
  123.     LD    (IOBYTE),A    ;clear the iobyte
  124.     LD    (CDISK),A    ;select disk zero
  125.     JP    GOCPM        ;initialize and go to cp/m
  126. ;
  127. ;       simplest case is to read the disk until all sectors loaded
  128. ;
  129. WBOOT:  LD      SP,80H          ;use space below buffer for stack
  130.     LD    C,0        ;select disk 0
  131.     CALL    SELDSK
  132.     CALL    HOME        ;go to track 00
  133. ;
  134.     LD    B,NSECTS    ;b counts # of sectors to load
  135.     LD    C,0        ;c has the current track number
  136.     LD    D,2        ;d has the next sector to read
  137. ;    note that we begin by reading track 0, sector 2 since sector 1
  138. ;    contains the cold start loader, which is skipped in a warm start
  139.     LD      HL,CCP          ;base of cp/m (initial load point)
  140. LOAD1:                          ;load one more sector
  141.     PUSH    BC              ;save sector count, current track
  142.     PUSH    DE              ;save next sector to read
  143.     PUSH    HL              ;save dma address
  144.     LD      C,D             ;get sector address to register c
  145.     CALL    SETSEC          ;set sector address from register c
  146.     POP     BC              ;recall dma address to b,c
  147.     PUSH    BC              ;replace on stack for later recall
  148.     CALL    SETDMA          ;set dma address from b,c
  149. ;    drive set to 0, track set, sector set, dma address set
  150.     CALL    READ
  151.     CP    00H        ;any errors?
  152.     JP    NZ,WBOOT    ;retry the entire boot if an error occurs
  153. ;    no error, move to next sector
  154.     POP     HL              ;recall dma address
  155.     LD      DE,128          ;dma=dma+128
  156.     ADD     HL,DE           ;new dma address is in h,l
  157.     POP     DE              ;recall sector address
  158.     POP     BC              ;recall number of sectors remaining, and current trk
  159.     DEC     B               ;sectors=sectors-1
  160.     JP      Z,GOCPM         ;transfer to cp/m if all have been loaded
  161. ;    more sectors remain to load, check for track change
  162.     INC    D
  163.     LD      A,D             ;sector=27?, if so, change tracks
  164.     CP      27
  165.     JP      C,LOAD1         ;carry generated if sector<27
  166. ;    end of current track, go to next track
  167.     LD      D,1             ;begin with first sector of next track
  168.     INC     C               ;track=track+1
  169. ;    save register state, and change tracks
  170.     CALL    SETTRK          ;track address set from register c
  171.     JP      LOAD1           ;for another sector
  172. ;    end of load operation, set parameters and go to cp/m
  173. GOCPM:
  174.     LD    A,0C3H        ;c3 is a jmp instruction
  175.     LD    (0),A        ;for jmp to wboot
  176.     LD    HL,WBOOTE    ;wboot entry point
  177.     LD    (1),HL        ;set address field for jmp at 0
  178. ;
  179.     LD    (5),A        ;for jmp to bdos
  180.     LD    HL,BDOS        ;bdos entry point
  181.     LD    (6),HL        ;address field of jump at 5 to bdos
  182. ;
  183.     LD    BC,80H        ;default dma address is 80h
  184.     CALL    SETDMA
  185. ;
  186.     EI            ;enable the interrupt system
  187.     LD    A,(CDISK)    ;get current disk number
  188.     LD    C,A        ;send to the ccp
  189.     JP      CCP             ;go to cp/m for further processing
  190. ;
  191. ;
  192. ;       simple i/o handlers
  193. ;
  194. ;       console status, return 0ffh if character ready, 00h if not
  195. ;
  196. CONST:  IN      A,(CONSTA)      ;get console status
  197.     RET
  198. ;
  199. ;       console character into register a
  200. ;
  201. CONIN:  IN      A,(CONDAT)      ;get character from console
  202.     RET
  203. ;
  204. ;       console character output from register c
  205. ;
  206. CONOUT: LD      A,C             ;get to accumulator
  207.     OUT     (CONDAT),A      ;send character to console
  208.     RET
  209. ;
  210. ;       list character from register c
  211. ;
  212. LIST:   LD      A,C             ;character to register a
  213.     OUT     (PRTDAT),A
  214.     RET
  215. ;
  216. ;       return list status (0 if not ready, 1 if ready)
  217. ;
  218. LISTST: IN      A,(PRTSTA)
  219.     RET
  220. ;
  221. ;       punch character from register c
  222. ;
  223. PUNCH:  LD      A,C             ;character to register a
  224.     OUT     (AUXDAT),A
  225.     RET
  226. ;
  227. ;       read character into register a from reader device
  228. ;
  229. READER: IN      A,(AUXDAT)
  230.     RET
  231. ;
  232. ;
  233. ;    i/o drivers for the disk follow
  234. ;
  235. ;       move to the track 00 position of current drive
  236. ;    translate this call into a settrk call with parameter 00
  237. ;
  238. HOME:   LD      C,0             ;select track 0
  239.     JP      SETTRK          ;we will move to 00 on first read/write
  240. ;
  241. ;       select disk given by register C
  242. ;
  243. SELDSK: LD      HL,0000H        ;error return code
  244.     LD    A,C
  245.     CP    4        ;must be between 0 and 3
  246.     RET    NC        ;no carry if 4,5,...
  247. ;    disk number is in the proper range
  248. ;    compute proper disk parameter header address
  249.     OUT     (FDCD),A        ;selekt disk drive
  250.     LD    L,A        ;L=disk number 0,1,2,3
  251.     ADD    HL,HL        ;*2
  252.     ADD    HL,HL        ;*4
  253.     ADD    HL,HL        ;*8
  254.     ADD    HL,HL        ;*16 (size of each header)
  255.     LD    DE,DPBASE
  256.     ADD    HL,DE        ;HL=.dpbase(diskno*16)
  257.     RET
  258. ;
  259. ;       set track given by register c
  260. ;
  261. SETTRK: LD      A,C
  262.     OUT     (FDCT),A
  263.     RET
  264. ;
  265. ;       set sector given by register c
  266. ;
  267. SETSEC: LD      A,C
  268.     OUT     (FDCS),A
  269.     RET
  270. ;
  271. ;       translate the sector given by BC using the
  272. ;       translate table given by DE
  273. ;
  274. SECTRAN:
  275.     EX      DE,HL           ;HL=.trans
  276.     ADD     HL,BC           ;HL=.trans(sector)
  277.     LD      L,(HL)          ;L = trans(sector)
  278.     LD      H,0             ;HL= trans(sector)
  279.     RET                     ;with value in HL
  280. ;
  281. ;       set dma address given by registers b and c
  282. ;
  283. SETDMA: LD      A,C             ;low order address
  284.     OUT     (DMAL),A
  285.     LD      A,B             ;high order address
  286.     OUT     (DMAH),A        ;in dma
  287.     RET
  288. ;
  289. ;       perform read operation
  290. ;
  291. READ:   XOR     A               ;read command -> A
  292.     JP      WAITIO          ;to perform the actual i/o
  293. ;
  294. ;       perform a write operation
  295. ;
  296. WRITE:  LD      A,1             ;write command -> A
  297. ;
  298. ;       enter here from read and write to perform the actual i/o
  299. ;    operation.  return a 00h in register a if the operation completes
  300. ;    properly, and 01h if an error occurs during the read or write
  301. ;
  302. ;       in this case, we have saved the disk number in 'diskno' (0-3)
  303. ;            the track number in 'track' (0-76)
  304. ;            the sector number in 'sector' (1-26)
  305. ;            the dma address in 'dmaad' (0-65535)
  306. ;
  307. WAITIO: OUT     (FDCOP),A       ;start i/o operation
  308.     IN      A,(FDCST)       ;status of i/o operation -> A
  309.     RET
  310. ;
  311. ;    the remainder of the CBIOS is reserved uninitialized
  312. ;    data area, and does not need to be a part of the
  313. ;    system memory image (the space must be available,
  314. ;    however, between "begdat" and "enddat").
  315. ;
  316. ;    scratch ram area for BDOS use
  317. ;
  318. BEGDAT  EQU     $               ;beginning of data area
  319. DIRBF:  DEFS    128             ;scratch directory area
  320. ALL00:  DEFS    31              ;allocation vector 0
  321. ALL01:  DEFS    31              ;allocation vector 1
  322. ALL02:  DEFS    31              ;allocation vector 2
  323. ALL03:  DEFS    31              ;allocation vector 3
  324. CHK00:  DEFS    16              ;check vector 0
  325. CHK01:  DEFS    16              ;check vector 1
  326. CHK02:  DEFS    16              ;check vector 2
  327. CHK03:  DEFS    16              ;check vector 3
  328. ;
  329. ENDDAT  EQU     $               ;end of data area
  330. DATSIZ    EQU    $-BEGDAT    ;size of data area
  331.     END
  332.