bios.z80 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ; Minimal CPM 2.2 BIOS -jcw, 2018-11-10
  2. VERS: equ 01h
  3. ; Memory map -------------------------------------------------------------------
  4. CCP: equ 0E800h
  5. BDOS: equ CCP + 0806h
  6. BIOS: equ CCP + 1600h
  7. BEND: equ CCP + 17FEh
  8. ; low memory -------------------------------------------------------------------
  9. iobyte: equ 03h ; Intel standard I/O definition byte
  10. usrdrv: equ 04h ; Current user number and drive
  11. tpabuf: equ 0080h ; Default I/O buffer and command line storage
  12. org BIOS
  13. ; BIOS jump table --------------------------------------------------------------
  14. jp boot ; 0 Initialize
  15. wboote: jp wboot ; 1 Warm boot
  16. jp conist ; 2 Console status
  17. jp conin ; 3 Console input
  18. jp conout ; 4 Console OUTput
  19. jp list ; 5 List OUTput
  20. jp punch ; 6 punch OUTput
  21. jp reader ; 7 Reader input
  22. jp home ; 8 Home disk
  23. jp seldsk ; 9 Select disk
  24. jp settrk ; 10 Select track
  25. jp setsec ; 11 Select sector
  26. jp setdma ; 12 Set DMA ADDress
  27. jp read ; 13 Read 128 bytes
  28. jp write ; 14 Write 128 bytes
  29. jp listst ; 15 List status
  30. jp sectrn ; 16 Sector translate
  31. ; Disk Parameter Headers -------------------------------------------------------
  32. dpbase: dw 0,0,0,0,dirbuf,dpb,0,alv0
  33. dw 0,0,0,0,dirbuf,dpb,0,alv1
  34. dpb: dw 26 ; SPT - sectors per track
  35. db 3 ; BSH - block shift factor
  36. db 7 ; BLM - block mask
  37. db 0 ; EXM - Extent mask
  38. dw 248 ; DSM - Storage size (blocks - 1)
  39. dw 63 ; DRM - Number of directory entries - 1
  40. db 192 ; AL0 - 1 bit set per directory block
  41. db 0 ; AL1 - ... 8 more bits
  42. dw 0 ; CKS - DIR check vector size (DRM+1)/4 (0=fixed disk)
  43. dw 2 ; OFF - Reserved tracks
  44. ; Cold boot --------------------------------------------------------------------
  45. boot: di
  46. ld sp,0100h
  47. ld de,dirbuf
  48. in a,(3) ; display greeting
  49. xor a
  50. ld (iobyte),a
  51. ld (usrdrv),a
  52. jr gocpm
  53. ; Warm boot --------------------------------------------------------------------
  54. wboot: di
  55. ld sp,0100h
  56. ld a,(usrdrv)
  57. ld b,44 ; read CCP + BDOS into memory
  58. ld de,1 ; skip first sector on first track
  59. ld hl,CCP ; start address
  60. in a,(4) ; disk read request
  61. ; Common code for cold and warm boot
  62. gocpm: ld hl,tpabuf ; Address of BIOS DMA buffer
  63. ld (dmaadr),hl
  64. ld a,0C3h ; Opcode for 'JP'
  65. ld (00h),a ; Load at start of RAM
  66. ld hl,wboote ; Address of jump for a warm boot
  67. ld (01h),hl
  68. ld (05h),a ; Opcode for 'JP'
  69. ld hl,BDOS ; Address of jump for the BDOS
  70. ld (06h),hl
  71. ld a,(usrdrv) ; Save new drive number (0)
  72. ld c,a ; Pass drive number in C
  73. jp CCP ; Start CP/M by jumping to the CCP
  74. ; Console I/O ------------------------------------------------------------------
  75. conist: in a,(0)
  76. ret
  77. conin: in a,(1)
  78. ret
  79. conout: in a,(2)
  80. ret
  81. reader: ld a,1Ah
  82. ret
  83. ; Disk I/O ---------------------------------------------------------------------
  84. seldsk: ld a,c
  85. cp 2
  86. jr nc,baddsk
  87. ld h,0
  88. ld l,c
  89. add hl,hl
  90. add hl,hl
  91. add hl,hl
  92. add hl,hl
  93. ld de,dpbase
  94. add hl,de
  95. savdsk: ld (sekdsk),a
  96. ret
  97. baddsk: ld hl,0
  98. ld a,(usrdrv)
  99. sub a,c
  100. ret nz
  101. ld (usrdrv),a
  102. jr savdsk
  103. home: ld c,0
  104. settrk: ld a,c
  105. ld (seksat+1),a
  106. ret
  107. setsec: ld hl,seksat
  108. ld (hl),c
  109. ret
  110. setdma: ld (dmaadr),bc
  111. ret
  112. sectrn: ld l,c
  113. ld h,b
  114. ret
  115. read: ld b,1
  116. jr rdwr
  117. write: ld b,1+80h
  118. rdwr: ld a,(sekdsk)
  119. ld de,(seksat)
  120. ld hl,(dmaadr)
  121. in a,(4)
  122. ret
  123. listst:
  124. list:
  125. punch:
  126. xor a
  127. ret
  128. ; Data area --------------------------------------------------------------------
  129. dirbuf: db 13,10,'64K CP/M Version 2.2',13,10,0
  130. ds dirbuf+128-$ ; scratch directory area
  131. sekdsk: ds 1 ; seek disk number
  132. seksat: ds 2 ; seek sector and track number
  133. dmaadr: ds 2 ; last dma address
  134. alv0: ds 31 ; allocation vector 0 (max 248 blocks)
  135. alv1: ds 31 ; allocation vector 1 (max 248 blocks)
  136. spare: equ BEND-$
  137. ds spare ; BIOS base page and version number
  138. dw BIOS + VERS ; ... at end of memory
  139. ; ------------------------------------------------------------------------------
  140. end