SLIDING INTO BDOS THE SMOOTH AND EASY WAY by: Michael J. Karas 2468 Hansen Court Simi Valley, CA 93065 Whaô  ió thió thinç everybodù ió talkinç abouô calleä  BDOS¿ Thió  serieó wilì attempô tï answeò thió questioî iî somå  detaiì buô  firsô wå neeä á littlå basió tï understanä WHÙ iî thå  firsô place®  Digitaì  Researcè CP/Í ió aî operatinç systeí foò smalleò typå micrï processoò computeò systemó thaô ió designeä tï  removå mucè oæ thå normaì computeò operatioî drudgerù experienceä bù thå computeò  operator®  Thå  operatinç  systeí softwarå  embodieó  á "systeí  philosophy¢  thaô structureó anä  generalizeó  upoî  thå operatinç  environmenô  oæ á piecå oæ electronicó  hardware®  Thå environmenô  presenteä  actuallù  allowó  thaô  piecå  oæ  quiet¬ transistorizeä machinerù tï bå useä aô á mucè higheò  level®  Thå fulì  impacô oæ whaô thió operatinç systeí provideó tï á computeò ió  mosô probablù felô bù thå typicaì micrï computeò hackeò  thaô workeä  thå  harä waù tï geô á computeò systeí  uð  anä  running® Whilå  building¬  debugging¬  anä  integratinç  thå  pieces¬  thå computeò  waó jusô á wholå buncè oæ partó interfaceä togetheò  iî aî  organizeä  manner®  However¬  wheî  thå thinç  ió  finallù  á "computer¢ ho÷ doeó iô geô used®  Thå lo÷ leveì procesó oæ pokinç datá intï memorù froí á fronô paneì oò eveî filling¬  dumping¬ oò blocë  movinç  memorù datá witè aî EPROÍ baseä "monitoò  program¢ hardlù  makeó thió computeò "useful"®  Thå procesó oæ puttinç  oî diskó  anä  bringinç  uð  CP/Í  lightó  thå  torcè  foò  computeò usability®  Iî thió caså thå hackeò experienceó aî elateä feelinç now "NOW I CAN DO SOMETHING!" Burieä insidå oæ thå totaì operatinç systeí presentatioî  ió thå   concepô  oæ  generalizatioî  broughô  uð  iî  thå  previouó paragraph®  Onå  oæ  thå majoò requirementó iî ordeò  tï  makå  á computeò  usefuì  ió thaô therå haó tï bå  applicationó  softwarå thaô  performó  thå  jobó intendeä foò thå  computer®  Jobó  likå accounting¬  worä  processing¬  spreaä sheeô  datá  analysis¬  oò inventorù   control®   Unfortunatelù  thå  procesó  oæ  producinç applicationó softwarå ió very¬ verù expensive® Á gooä packagå maù takå anywherå froí onå tï teî maî yearó oæ developmenô efforô  tï make®  Iæ thå procesó oæ makinç aî applicationó packagå haä tï bå custoí  tayloreä tï á specifiã hardwarå environment¬  theî  therå woulä  noô bå affordablå softwarå availablå foò uså upoî á  giveî XYÚ  computer®  Generalizatioî  iî thå operatioî  oæ  á  computeò environmenô  solveó thió probleí however®  Witè thå understandinç thaô aô á certaiî leveì "alì microprocessoò computeò systemó  arå alike¢ iô ió possible¬  witè minimuí constraints¬ tï definå á seô oæ logicaì typå operationó thaô makå á computeò useful® Š Thió  logicaì  seô oæ operations¬  foò thå Digitaì  Researcè CP/Í operatinç system¬  ió defineä withiî thå BDOÓ portioî oæ thå operatinç system®  Herå iî abouô ³ 1/² Ë byteó oæ tightlù writteî assemblù  languagå ió thå "generalizatioî converter¢  thaô  takeó I/Ï  requestó foò hardwarå independanô applicationó programó  anä turnó theí intï á loweò leveì seô oæ simplistiã hardwarå orienteä functionó  thaô  arå  theî  processeä  througè  thå  BIOS®   Thió conversioî  procesó ió beneficiaì iî thå lighô thaô CP/Í Veò  2.² caî bå setuð tï ruî oî á typicaì branä XYÚ computeò foò abouô onå halæ  oæ  thå efforô needeä tï converô eveî onå oæ  thå  simplesô applicatioî  packageó  haä  thaô applicatioî beeî  writteî  iî  á hardwarå  dependanô manner®  Conclusion»  softwarå developeró caî makå better¬  morå sophisticateä applicationó availablå foò loweò cosô  anä computeò useró finä á competitivå softwarå markeô placå wherå  therå  arå  manù timeó multiplå  packageó  availablå  thaô perform similar functions. Thå  thrusô oæ thió presentatioî ió tï sho÷ thå  prospectivå applicationó  programmeò  ho÷ tï uså mosô oæ thå generalizeä  seô oæ  "BDOÓ Systeí Calls¢ withiî Digitaì Researcheó CP/Í  Veò  2.2® Thå presentatioî schemå wilì bå tï describå alì oæ thå  functionó anä  uså  simplå examples®  Thå readeò ió assumeä tï bå  modistlù familiaò  witè 808° Assemblù Languagå Programminç aó alì  oæ  thå exampleó  wilì bå giveî iî machinå language®  Likewise¬  iî  thió environmenô  iô  ió  assumeä  bù  defaulô  thaô  thå  prospectivå programmeò  ió planninç tï codå iî assemblù language®  Iæ á  CP/Í compatiblå  higè leveì languagå ió useä foò programming¬  sucè aó Digitaì  Researcè PL/I-8° oò Microsofô BASIC-80¬  theî oæ  courså thå  prograí  interfacå  aô  thå  "Systeí  Call¢  leveì   becomeó transparenô tï thå programmer® Ruî timå subroutineó makå thå higè leveì  codeä applicatioî geô converteä througè yeô anotheò  step® (Onå majoò reasoî applicationó codå iî á higè leveì languagå runó sloweò   thaî   thå  equivalenô  functioî  writteî  iî   assemblù language). SUMMARY OF CP/M SYSTEM CALLS Thå  seô oæ systeí oò "BDOS¢ I/Ï entrù pointó  availablå  tï thå CP/Í programmeò ió completå yeô simple® Thå primarù beautù oæ thå  CP/Í  systeí  ió  thió smalì  worlä  oæ  completeness®  Manù programmeró  familaiò witè otheò operatinç systemó complaiî  thaô thå CP/Í systeí ió weak¬  unflexible¬ anä incomplete® However¬ iî á  microprocessoò typå computeò world¬  thå generalizatioî  leveì defineä foò thå CP/Í systeí allowó 85¥ oæ alì microprocessoò typå appliciatioî jobó tï bå programmeä witè relativå ease®  Also¬  iî mù  opinion¬  8-biô microprocessoò hardwarå ió easilù capablå  oæ performinç  abouô  9° percenô oæ thå typicaì taskó  targeteä  foò microcomputers®  Sï  whaô ió thió seô oæ functions¿  Thå charô oæ Figurå ± summarizes¬  iî functioî numbeò order¬ alì oæ thå systeí operationó  specifiã tï CP/Í Versioî 2.² thaô wilì bå covereä  iî thió  presentation®  Iî thå subsequenô sectionó thaô  follo÷  thå functionó  wilì  bå  groupeä  intï  categorieó  sï  thaô  relateä operations may become familiar with reference to one another. .pa Š.po3 FIGURE 1. DETAILED SUMMARY OF CP/M 2.2 SYSTEM CALLS Function Entry Value to Return Value from Number BDOS Passed in BDOS Passed in DEà HEØ Functioî (DE© oò (E© regó (HL© oò (A© register ------------------------------------------------------------------------- ° 0° ü Systeí Reseô ü ***ª ü ***ª | 1 01 | Console Input | **** | (A)=character | 2 02 | Console Output | (E)=character | **** | 3 03 | Reader Input | **** | (A)=character | 4 04 | Punch Output | (E)=character | **** | 5 05 | Printer Output | (E)=character | **** | 6 06 | Direct Console I/O | (E)=0FFH is input| (A)=character | | | (E)=chr is output| **** | 7 07 | Get IOBYTE | **** | (A)=IOBYTE | 8 08 | Set IOBYTE | (E)=IOBYTE | **** | 9 09 | Display Console String | (DE)=string addr | **** | 10 0A | Input Console String | (DE)=string addr | (A)=# chr input | 11 0B | Get Console Status | **** | (A)=000H idle | | | | (A)=0FFH ready | 12 0C | Get CP/M Version Number| **** | (HL)=Version # | 13 0D | Reset Disk Subsystem | **** | **** | 14 0E | Select Disk Drive | (E)=disk number | **** | 15 0F | Open a File | (DE)=FCB address | (A)=dir code | 16 10 | Close a File | (DE)=FCB address | (A)=dir code | 17 11 | Search for File | (DE)=FCB address | (A)=dir code | 18 12 | Search for Next | **** | (A)=dir code | 19 13 | Delete File | (DE)=FCB address | (A)=dir code | 20 14 | Read next Record | (DE)=FCB address | (A)=error code | 21 15 | Write next Record | (DE)=FCB address | (A)=error code | 22 16 | Create New File | (DE)=FCB address | (A)=dir code | 23 17 | Rename File | (DE)=FCB address | (A)=dir code | 24 18 | Get Login Vector | **** | (HL)=login vector| 25 19 | Get Logged Disk Number | **** | (A)=logged disk | 26 1A | Set R/W Data Buff Addr | (DE)=buffer addr | **** | 27 1B | Get Allocation Vector | **** | (HL)=alloc vector| | | | address | 28 1C | Write Protect Disk | (E)=disk number | **** | 29 1D | Get Read Only Vector | **** | (HL)=R/O vector | 30 1E | Set File Attributes | (DE)=FCB address | (A)=dir code | 31 1F | Get Addr of Disk Parms | **** | (HL)=parm addr | 32 20 | Get/Set User Select | (E)=0FFH get | (A)=current user | 33 21 | Read Random Record | (DE)=long FCB adr| (A)=error code | 34 22 | Write Random Record | (DE)=long FCB adr| (A)=error code | 35 23 | Get Size of File | (DE)=long FCB adr| (r0-2=rec cnt) | 36 24 | Set Random Record Num | (DE)=long FCB adr| (r0-2=rec numb) | 37 25 | Reset Drive | (DE)=drive vector| **** | 38 26 | Not used | | | 39 27 | Not used | | | 40 28 | Write Random with | (DE)=long FCB adr| (A)=error code | ------------------------------------------------------------------------- .pa Š.po8 Thå  technicaì meanó requireä tï "use¢ oò interfacå  tï  thå CP/Í systeí foò eacè functioî containó á certaiî commoî structurå thaô  wilì  bå discusseä here®  Thå baså memorù pagå  oæ  á  CP/Í systeí memorù mað includes¬  aô á specifiã memorù address¬ á JUMÐ instructioî  tï thå CP/Í BDOÓ entrù point®  Foò mosô CP/Í systemó thió ió addresó 00005H®  Tï accomplisè BDOÓ I/Ï thå numbeò oæ thå functioî  ió  placeä  intï thå (C©  register®  Iæ  thå  parameteò requireó  inpuô  parameters¬  theî theù arå passeä  iî  thå  (DE© registeò  paiò  oò  thå individuaì (E©  registeò  dependinç  upoî whetheò thå parameteò ió á word or bytå value® Resulô informatioî returneä  bù somå functionó ió senô bacë tï thå useró prograí  iî eitheò  thå (A© registeò oò thå (HL© registeò paiò dependinç upoî iæ  thå  valuå ió á bytå oò word®  Thå followinç  simplå  prograí segmenô demonstrateó thå schemå useä tï outpuô thå 2¶  characteró A-Z to the console screen through the use of function number 2. BDOS EQU 0005H ;SYSTEM ENTRY CONOUT EQU 2 ;OUTPUT FUNCTION ORG 0100H ;TPA BASE MVI B,26 ;PRINT 26 COUNTER MVI C,'A' ;START WITH 'A' ; LOOP: PUSH B ;SAVE COUNTER & LETTER MOV E,C ;LETTER TO (E) FOR OUTPUT MVI C,CONOUT ;BDOS FUNC TO (C) CALL BDOS ;GO GO OUTPUT POP B INR C ;SEQUENCE TO NEXT CHAR DCR B ;DECREASE CHR COUNTER JNZ LOOP ;MORE TO DO IF NOT TO ZERO RET ;IMMEDIATE CCP RETURN SYSTEM CALLS FOR OPERATOR CONSOLE INPUT AND OUTPUT Intrinsiã   tï   thå  operatioî  oæ  anù  computeò   system¬ especiallù  oæ  thå CP/Í gender¬  ió thå  operatoò  console®  Thå devicå  provideó  thå humaî interfacå tï thå machinå anä aó  sucè thå  BDOÓ  includeó á generalizeä seô oæ  operatoò  communicatioî functionó  tï  perforí I/Ï witè thå consolå device®  Thå  variouó options available will each be presented with a brief example. INPUT FROM CONSOLE KEYBOARD: Function 1. Thió  functioî waitó foò anä readó iî á characteò  froí  thå consolå  devicå keyboard®  Thå operatoò typeä characteò ió echoeä automaticallù bacë tï thå consolå displaù iæ thå characteò ió  aî ASCIÉ  printablå  characteò  (020È tï 07EH© oò iô ió  á  carriagå return¬  linå  feed¬  bacë  space¬  oò tab®  Notå thaô  thå  BDOÓ automaticallù expandó tabó tï columnó oæ eighô  characters®  Upoî outputtinç  thå  characteò  foò thå echo¬  á checë  ió  madå  foò Šconsolå  start/stop¬  CTL-S¬  anä iæ sï thå consolå inpuô routinå doeó noô returî tï thå useró prograí untiì anotheò arbitrarù  keù is depressed. ;CONSOLE INPUT EXAMPLE ; CONIN EQU 001H ;FUNC # 1 BDOS EQU 0005H ;SYSTEM ENTRY ORG 0100H ;START MVI C,CONIN ;FUNCTION CALL BDOS ;GO GET CHARACTER STA INCHAR ;SAVE FOR WHATEVER REASON RET ;IMMEDIATE CCP RETURN ; INCHAR: DÓ ± ;PLACÅ TÏ STORÅ INPUÔ CHAR ; END OUTPUT TO CONSOLE DISPLAY: Function 2. Thå  ASCIÉ  characteò  iî thå (E© registeò ió  senô  tï  thå consolå displaù device® Thå outpuô maù bå anù bytå valuå buô manù timeó  thå hardwarå driveò BIOÓ routineó automaticallù strið  ofæ thå  uppeò  biô oæ thå byte®  Upoî outpuô thå printeò  echï  flaç withiî  BDOÓ ió checkeä (CTL-P© anä iæ seô thå characteò ió  alsï senô  tï  thå  printeò  peripheraì device®  Notå  thaô  thå  BDOÓ automaticallù expandó outpuô tabó tï columnó oæ eighô characters® Upoî  outputtinç  thå  characteò á checë ió  madå  foò  inpuô  oæ consolå start/stop¬  CTL-S¬  anä iæ sï thå consolå outpuô routinå doeó  noô returî tï thå useró prograí untiì anotheò arbitrarù keù ió depressed. ;CONSOLE OUTPUT EXAMPLE ; CONOUT EQU 002H ;FUNC # 2 BDOS EQU 0005H ;SYSTEM ENTRY ORG 0100H ;START LDA OUTCHAR ;GET CHARACTER TO OUTPUT MOV E,A MVI C,CONOUT ;FUNCTION CALL BDOS ;GO SEND CHARACTER RET ;IMMEDIATE CCP RETURN ; OUTCHAR: DB 'X' ;PLACÅ TÏ GET OUTPUT CHAR ; END ŠDIRECT USER INTERFACE TO CONSOLE: Function 6. Somå  programminç  applicationó requirå thaô  thå  BDOÓ  noô monitoò  thå  input/outpuô  characteò  streaí  aó  ió  donå  witè functionó  ±  ¦ 2®  Tï allo÷ foò theså functionó thå  direcô  I/Ï functioî ió supported® Thå followinç examplå showó ho÷ iô ió useä tï  inpuô valueó anä echï theí untiì aî inpuô control-Ú characteò is typed. ;DIRECT CONSOLE I/O EXAMPLE ; DIRCIO EQU 006H ;FUNCTION NUMBER BDOS EQU 0005H ;SYSTEM ENTRY POINT CTLZ EQU 'Z'-040H ;ASCII CTL-Z CHARACTER INPUT EQU 0FFH ;DIRECT INPUT FLAG ORG 0100H ;CONSOLE INPUT ; LOOP: MVI E,INPUT ;SET FOR INPUT MVI C,DIRCIO ;FUNCTION CALL BDOS ;GET INPUT OR STATUS ORA A ;IF (A)=0 NO CHAR WAS READY JZ LOOP ;CONTINUE TO WAIT FOR INPUT CPI CTLZ ;IF INPUT WAS CTL Z THEN END RZ ;CCP RETURN ON END MOV E,A ;CHARACTER TO (E) FOR OUTPUT MVI C,DIRCIO ;SAME FUNCTION NUMBER AGAIN CALL BDOS ;GO OUTPUT IT JMP LOOP ;NEXT CHARACTER INPUT LOOP ; END PRINTING STRINGS OF CHARACTERS TO THE CONSOLE: Function 9. Messagå  strinç  sequenceó oæ characteró tï bå senô  tï  thå consolå  arå quitå commoî iî  applicationó  programming®  Typicaì useó  maù bå foò useò prompô messages¬  prograí sign-oî  messageó etc®  Thå  BDOÓ  provideó  á convenienô mechanisí  tï  allo÷  thå programmeò  tï  outpuô á wholå strinç oæ characteró  ratheò  thaî havinç  tï  looð witè singlå characteò  outputs®  Thå  strinç  ió intendeä  tï  bå storeä iî consecutivå memorù locationó  anä  enä witè  thå  ASCIÉ '$§ character®  Thå (DE© registeró arå  useä  tï poinô tï thå starô oæ thå string®  Thå '$§ signaló thå enä oæ thå strinç  tï  displaù anä ió noô senô tï thå  console®  Thå  outpuô byteó  maù bå anù 8-biô valuå buô manù timeó thå hardwarå  driveò BIOÓ  routineó automaticallù strið ofæ thå uppeò biô oæ thå byte® Upoî  outpuô oæ eacè characteò thå printeò echï flaç withiî  BDOÓ ió  checkeä (CTL-P© anä iæ seô thå characteò ió alsï senô tï  thå printeò  peripheraì  device®  Notå thaô  thå  BDOÓ  automaticallù expandó  outpuô  tabó  tï  columnó  oæ  eighô  characters®   Upoî outputtinç  eacè  characteò á checë ió madå foò inpuô oæ  consolå start/stop¬  CTL-S¬  anä iæ sï thå consolå strinç outpuô  routinå Šdoeó  noô returî tï thå useró prograí untiì anotheò arbitrarù keù ió depressed. ;CONSOLE STRING PRINT EXAMPLE ; CONSTR EQU 009H ;FUNC # 9 BDOS EQU 0005H ;SYSTEM ENTRY CR EQU 0DH ;ASCII CARRIAGE RETURN LF EQU 0AH ;ASCII LINE FEED ORG 0100H ;START LXI D,MESSAGE ;POINT AT STRING TO SEND MVI C,CONSTR ;FUNCTION CALL BDOS ;GO SEND STRING RET ;IMMEDIATE CCP RETURN ; MESSAGE: DB CR,LF,'Hello Operator',CR,LF,'$' ; END READING A STRING OF CHARACTERS IN FROM KEYBOARD: Function 10. Thå CP/Í consolå commanä processoò (CCP© assumeä tï bå  varù familiaò  tï  mosô CP/Í systeí operatoró allowó buffereä  commanä inpuô witè editinç features®  Iô turnó ouô thaô thió operatioî ió á  mucè needeä functioî foò gettinç iî stringó oæ texô  froí  thå operatoò console®  Uså oæ thió functioî allowó standardizatioî oæ thå commanä inpuô functionó sï thaô thå operatoò caî easilù learî thå  editinç keù functions®  Iô alsï removeó thå paiî oæ  writinç thå  samå  functioî  oveò  anä oveò  agaiî  bù  thå  applicationó programmer®  Thå  reaä strinç commanä inputó thå editeä texô tï á buffeò  pointerä  tï  bù  thå  (DE©  registeò  pair®  Thå  calleò specifieó  thå  maximuí lengtè desireä anä thå BDOÓ  returnó  thå actuaì  lengtè  oæ strinç entereä iæ carriagå returî  ió  entereä prioò tï exceedinç thå maximuí inpuô length®  Thå inpuô lengtè ió returneä  iî  botè thå (A© registeò anä aó parô  oæ  thå  buffer® Byteó  iî thå strinç buffeò pasô thå enä oæ thå entereä texô  arå uninitialized® Thå examplå showî belo÷ giveó aî assemblù languagå vie÷  poinô  oæ thå buffeò structurå anä ho÷ tï prograí aî  inpuô function. Thå  editinç functionó supporteä arå thå  followinç  controì and/or special characters: rub/del removes and echos the last entered char ctl-C initiates system reboot if first char ctl-Å echoó á CÒ ¦ LÆ tï consolå without putting them into buffer ctl-H (or back space key) back spaces one char removing last entered character ctl-J (or line feed key) terminates line input ctl-M (or carriage return) terminates input ctl-R retypes currently entered characters under current line Š ctl-U deletes all of currently entered data and restarts buffer input on new line ctl-X deletes all of currently entered data and restarts buffer input on same line ;CONSOLE INPUT BUFFER EXAMPLE ; CONBUF EQU 00AH ;STRING INPUT FUNCTION BDOS EQU 0005H ;SYSTEM ENTRY POINT LENGTÈ EQÕ 3² ;DESIREÄ MAXIMUÍ CHARACTERS ORG 0100H ;START POINT LXI D,STRING ;POINT AT BUFFER AREA MVI C,CONBUF ;FUNCTION NUMBER CALL BDOS ;GO GET STRING RET ;RETURN TO CCP WITHOUT ;...DOING ANYTHING WITH DATA ; ; ;CONSOLE INPUT BUFFER LAYOUT ; STRING: DB LENGTH ;MAXIMUM DESIRED INPUT LENGTH AMOUNT: DS 1 ;BYTE WHERE BDOS RETURNS ;..ACTUAL BYTE COUNT STRBF: DS LENGTH ;RESERVED STORAGE FOR UP TO ;"LENGTH" NUMBER OF CHARACTERS ; END DETERMINING IF THERE IS PENDING KEYBOARD INPUT: Function 11. Somå  computeò programó arå designeä tï spenä largå  amountó oæ  timå  processinç insidå oæ thå computeò oò manipulatinç  datá withiî  disë  fileó withouô stoppinç tï asë thå  useò  iæ  he/shå desireó  tï stoð thå processinç sequence®  Alsï it ió manù  timeó desirablå  tï  havå  á  "terminate¢  capabilitù  foò  applicatioî programó  withouô waitinç foò thå operatoò tï answeò á  characteò inpuô  request®  Iæ thå normaì consolå inpuô functioî ió useä thå useò computeò ió noô resumeä untiì á characteò ió alreadù  input® Thå  consolå inpuô statuó checë functioî maù bå useä tï polì  thå useò keyboarä tï determinå iæ á characteò inpuô ió pending® Iæ nï inpuô  ió readù theî thå useò prograí ió immediatelù resumeä witè aî indicatioî oæ iæ therå waó á pendinç input®  Iæ á characteò ió pendinç á 0FFÈ ió returneä iî thå (A© register®  Otherwiså á 000È valuå  ió returned®  Thå followinç examplå illustrateó thå uså oæ consolå  statuó tï terminatå á normallù endlesó looð thaô  printó the same string over and over. ;CONSOLE STATUS USAGE EXAMPLE Š; CONSTAT EQU 00BH ;FUNC # 11 CONSTR EQU 009H ;PRINT STRING FUNCTION BDOS EQU 0005H ;SYSTEM ENTRY CR EQU 0DH ;ASCII CARRIAGE RETURN LF EQU 0AH ;ASCII LINE FEED ORG 0100H ;START LOOP: LXI D,MESSAGE ;POINT AT STRING TO SEND MVI C,CONSTR ;FUNCTION CALL BDOS ;GO SEND STRING MVI C,CONSTAT ;GET ABORT STATUS CALL BDOS ORA A ;CHECK STATUS JZ LOOP ;NO KEY SO CONTINUE LOOP RET ;IMMEDIATE CCP RETURN IF ABORT ; MESSAGE: DB CR,LF,'Depress any Key to STOP','$' ; END AUXILLIARY PERIPHERAL CHARACTER INPUT AND OUTPUT FUNCTIONS Thå  generalizeä CP/Í BDOÓ provideó thå capabilitù foò threå characteò bù characteò logicaì I/Ï deviceó tï bå attecheä tï  thå computeò  system®  Thió requiremenô stemó froí thå facô thaô mosô computeró  arå  designeä tï interfacå tï thå reaì worlä  iî  morå wayó thaî jusô á consolå device® Thå threå deviceó arå classifieä as: a©  Á listeò typå devicå thaô ió generallù expecteä tï bå  á printeò  oæ  somå sort®  Thió classificatioî ió  aî  outpuô  onlù device. b©  Aî inpuô devicå supportinç characteò inpuô froí á sourcå otheò thaî thå console®  Thå devicå ió specifcallù aî inpuô  typå unit®  CP/Í  jargoî referó tï thió devicå aó thå "READER¢ foò  nï particular reason. c©  Á  generalizeä characteò outpuô onlù devicå useä  aó  á specifiã datá destinatioî otheò thaî thå consolå oò standarä lisô device®  Somå  computeò  systemó  uså thió  device¬  ofteî  timeó referred to as the "PUNCH" device as a second printer output. Thå  threå  followinç exampleó  illustratå  thå  programminç techniques used to talk to each of these three devices. ;LIST DEVICE OUTPUT EXAMPLE ; LIST EQU 005H ;FUNC # 5 ŠBDOS EQU 0005H ;SYSTEM ENTRY ORG 0100H ;START LDA LSTCHAR ;GET CHARACTER TO OUTPUT MOV E,A MVI C,LIST ;FUNCTION CALL BDOS ;GO SEND CHARACTER RET ;IMMEDIATE CCP RETURN ; LSTCHAR: DB 'L' ;PLACÅ TÏ GET OUTPUT CHAR ; END ;READER DEVICE INPUT EXAMPLE ; READER EQU 003H ;FUNC # 3 BDOS EQU 0005H ;SYSTEM ENTRY ORG 0100H ;START MVI C,READER ;FUNCTION CALL BDOS ;GO GET CHARACTER STA RDRCHR ;SAVE FOR WHATEVER REASON RET ;IMMEDIATE CCP RETURN ; RDRCHR: DÓ ± ;PLACÅ TÏ STORÅ INPUÔ CHAR ; END ;PUNCH DEVICE OUTPUT EXAMPLE ; PUNCH EQU 004H ;FUNC # 4 BDOS EQU 0005H ;SYSTEM ENTRY ORG 0100H ;START LDA PNCHCHR ;GET CHARACTER TO OUTPUT MOV E,A MVI C,PUNCH ;FUNCTION CALL BDOS ;GO SEND CHARACTER RET ;IMMEDIATE CCP RETURN ; PNCHCHR: DB 'P' ;PLACÅ TÏ GET OUTPUT CHAR ; END Š SYSTEM CONTROL BDOS FUNCTIONS Thió  familù oæ systeí calló supporteä bù thå CP/Í BDOÓ  arå designeä  tï  allo÷  thå programmeò á degreå  oæ  flexibilitù  iî manipulatinç  thå  operatioî oæ generaì  CP/Í  environment®  Eacè functioî herå wilì generallù bå discusseä individuallù duå tï thå unique nature of each operation. SYSTEM RESET: Function 0. Thå  systeí  reseô functioî ió designeä tï allo÷ restarô  oæ thå  CP/Í  systeí  commanä processoò  afteò  á  useò  applicatioî completeó  executioî oò ió aborted®  Thå systeí reseô functioî ió equivalenô  tï á JMÐ tï addresó 0000È oò á CTL-à whicè  forceó  á systeí WARÍ Reboot®  Thå rebooô operatioî då-activateó alì activå driveó excepô drivå Aº whicè ió re-logged® Operatioî ió extremelù simple as: RESET EQU 000H ;SYSTEM RESET FUNC BDOS EQU 0005H ;SYSTEM ENTRY POINT ORG 0100H MVI C,RESET JMP BDOS ;CALL ALSO PERMISSABLE ;EXCEPT THAT FUNCTION ;DOES NOT RETURN TO USER ;PROGRAM GET AND SET IOBYTE: Functions 7 & 8. Thå    generalizeä   CP/Í   operatinç   systeí   environmenô communicateó viá I/Ï tï "logical¢ typå devices®  Thió meanó  thaô thå console¬  lister¬ "reader"¬ anä "punch¢ arå jusô treateä aó á generiã  devicå classsifications®  Thå CP/Í systeí allowó foò anä supports¬ tï á degree¬ thå capabilitù foò thå hardwarå tï contaiî multiplå  physicaì deviceó (peripheraló and/oò reaì I/Ï  devices© withiî  eacè oæ thå generiã logicaì devicå  classifications®  Thå meanó tï supporô thå assignmenô oæ multiplå physicaì deviceó tï á giveî classificatioî ió donå througè thå IOBYTE¬  normallù storeä aô addresó 00003È oæ thå baså pagå oæ thå CP/Í memory®  Thå  BIOÓ hardwarå  I/Ï softwarå maù thuslù bå writteî tï easilù kno÷ whicè onå  oæ twï printeró tï talë tï wheî thå BDOÓ requireó outpuô  tï onå oæ twï printers®  Á "defaulô standard¢ IOBYTÅ formaô haó beeî adopteä  baseä  upoî aî 8-biô  microprocessoò  systeí  conventioî developeä bù Inteì Corð aó follows: (lister) (punch) (reader) (console) Logical Devices => LST: PUN: RDR: CON: IOBYTE bits => 7 6 5 4 3 2 1 0 --------------------------------------------------------- Bit pattern dec binary 0 00 TTY: TTY: TTY: TTY: Š 1 01 CRT: PTP: PTR: CRT: 2 10 LPT: UP1: UR1: BAT: 3 11 UL1: UP2: UR2: UC1: Thå  designatoró iî thå tablå specifù thå "standarä typeó oæ physical devices and are defined as follows: TTY: A teletype console with keyboard, hard copy display and possibly an integral tape reader/punch CRT: An interactive cathode ray type terminal with keyboard input and display screen BAT: A batch processor workstation with a card reader type input device and a hard copy display/output device UC1: A user defined alternate "console" unit LPTº Linå printer UL1: A user defined list device PTR: Paper Tape Reader UR1: User defined "reader" character input device UR2: User defined "reader" character input device PTP: Paper Tape Punch UP1: User defined "punch" character output device UP2: User defined "punch" character output device Thå BDOÓ supporô foò thå I/Ï devicå assignmenô ió á standarä mechanisí  tï accesó thå IOBYTE'ó currenô valuå anä switcè iô  tï somå  otheò  value®  Supposå  á CP/Í computeò  haä  twï  printeró connecteä aó LSTº  anä UL1:® Iæ thå applicationó prograí needó tï switcè printinç outpuô tï anotheò printer¬  thå procesó coulä  bå handeled as follows: ;GET AND SET IOBYTE EXAMPLE ; SETIOB EQU 008H ;SET IOBYTE FUNCTION GETIOB EQU 007H ;GET IOBYTE FUNCTION BDOS EQU 00005H ;SYSTEM ENTRY POINT LSTMASK EQU 11$00$00$00B ;IOBYTE MASK FOR LIST ;..DEVICE LPT EQU 10$00$00$00B ;BIT VALUE FOR LPT #1 UL1 EQU 11$00$00$00B ;BIT VALUE FOR LPT #2 ORG 0100H ;PROGRAM START MVI C,GETIOB ;GO GET CURRENT IOBYTE VAL CALL BDOS ANI (NOT LSTMASK) AND 0FFH ;KEEP ALL OTHER BITS ORI UL1 AND LSTMASK ;SET IOBYTE FOR PRINTER #2 MOV E,A MVI C,SETIOB ;FUNCTION TO RESET THE IOBYTE CALL BDOS RET ;IMMEDIATE CCP RETURN ; END GET CP/M VERSION NUMBER: Function 12. Š Sometimeó  iô  ió necessarù foò aî applicationó  prograí  tï "know¢ whaô versioî oæ CP/Í thå prograí ió runninç under® Versioî 2.°  anä abovå supporô á featurå tï telì thå applicatioî  prograí whaô  thå  versioî  numbeò is®  One reasoî ió tï  permiô  versioî dependanô functionó sucè aó randoí recorä filå I/Ï tï bå useä  iæ iô  ió  supporteä bù thå versioî oæ CP/Í beinç used®  Thå  systeí calì  tï  geô thå versioî numbeò returnó á twï bytå  valuå  spliô into two parts as follows: if (H)=0 then this is a CP/M System (H)=1 then this is an MP/M System (L)=version number in hex if (L)=00 then older than CP/M 2.0 (L)=20 then version CP/M 2.0 (L)=21 then version CP/M 2.1 (L)=22 then version CP/M 2.2 A program to read the CP/M version number is as follows: ;VERSION NUMBER EXAMPLE ; GETVERS EQU 00CH ;FUNCTION 12 BDOS EQU 00005H ;SYSTEM ENTRY POINT ORG 0100H ;PROGRAM START MVI C,GETVERS ;FETCH VERSION NUMBER CALL BDOS MOV A,L ;SAVE CP/M VERSION NUMBER STA CURVERS RET ;BACK TO CCP ; CURVERS: DS 1 ;STORE THE VERSION NUM HERE END RESETTING THE CP/M DISK SYSTEM: Function 13. Thå  CP/Í  operatinç  systeí containó  featureó  tï  controì accesó  tï  fileó  upoî thå disë  drives®  Á  directorù  checksuí scheme¬  beyonä  thå  scopå oæ  thió  presentation¬  permitó  thå operatinç  systeí tï determinå wheî á disë haó beeî changeä iî  á drivå  thuó preventinç thå á wronç disë froí beinç writteî  upon® Thió  ió neaô excepô thaô iî manù caseó aî appliciationó  prograí maù  requirå  disë changeó aó functionó arå changeä oò ne÷  fileó arå   required®   Thió  systeí  controì  functioî   permitó   thå applicatioî  tï forcå read/writå statuó tï bå seô foò alì drives¬ drivå  Aº  tï  bå logged¬  anä reseô oæ thå defaulô  disë  recorä buffeò addresó tï itó defaulô valuå oæ 080È withiî thå CP/Í  baså page®  Thå followinç prograí sequencå showó ho÷ tï reseô thå disë system. ;RESET DISK SYSTEM EXAMPLE ; RESET EQU 0DH ;FUNCTION 13 ŠBDOS EQU 0005H ;SYSTEM ENTRY POINT ORG 0100H ;PROGRAM START MVI C,RESET ;SET UP FUNCTION CALL BDOS ;GO RESET THE DRIVES RET ;BACK TO THE CCP ; END GET AND SET OF CURRENT USER CODE: Function 32. CP/Í Versioî 2.² permitó thå filå systeí oî á giveî drivå tï bå  partitioneä intï uð tï 1µ individuaì directorù areaó sï  thaô usagå areaó caî bå setup® Foò instance¬ thå systeí operatoò coulä puô  alì assemblù languagå developmenô programó iî onå useò  areá whilå  havinç disë utilitù programó iî another®  Thå BDOÓ  allowó thå applicatioî programmeò tï determinå thå currentlù logged useò numbeò anä tï modifù iô iæ necessary®  Thå followinç examplå setó thå currenô useò numbeò uð bù one®  Iæ thå highesô useò numbeò ió currently logged then the user 0 area is selected. ;GET/SET USER EXAMPLE ; GSUSR EQU 020H ;FUNCTION 20 GET EQU 0FFH ;GET FLAG BDOS EQU 0005H ;SYSTEM ENTRY POINT ORG 0100H ;START UP POINT MVI E,SET ;MAKE THIS A FETCH NUM RQST MVI C,GSUSR CALL BDOS ;GET THE CURRENT USER # INR A ;BUMP RETURNED USER UP 1 ANI 00FH ;MASK TO MOD(15) MOV E,A ;MOVE FOR SET TO NEW USER MVI C,GSUSR CALL BDOS RET ;CCP GETS US BACK ; END SYSTEM FUNCTIONS THAT CONTROL THE DISKS Thå  datá storagå fileó foò applicationó programó arå storeä upoî  thå  disë driveó attacheä tï thå CP/Í  computer®  Thå  BDOÓ supportó á numbeò oæ functionó thaô allo÷ thå statå anä selectioî status of the drives to be controlled. SELECT DISK: Function 14. Thå simplesô controì functioî ió tï selecô thå currenô  disë witè  whicè  tï  refeò  tï aó thå loggeä  oò  defaulô  disk®  Thå function is equivalent to the console CCP command: A>B: Š B> Whicè  changeä  thå currentlù loggeä disë tï  drivå  B:®  Á  BDOÓ prograí  tï affecô thå samå thinç ió giveî iî thå examplå prograí oæ  thå  nexô  sectioî below®  Drivå numberó  corresponä  tï  thå consolå displayeä drivå designatoró aó follows: A: = Drive # 0 B: = Drive # 1 *** P: = Drive # 15 Oncå  á drivå haó beeî selecteä iô haó itó directorù  "activated¢ anä ió maintaineä iî á loggeä iî statuó untiì thå nexô warí boot¬ cold boot, or disk reset BDOS function. DETERMINE LOGGED DISK: Function 25. Aî  applicationó prograí caî determinå whicè disë  drivå  ió thå  currentlù  loggeä  oò  defaulô drivå  througè  uså  oæ  thió function®  Thå BDOÓ wilì returî iî thå (A© registeò thå numbeò oæ the currently selected drive according to the table given above. Thå prograí segmenô belo÷ showó á sequencå oæ BDOÓ interfacå codå  thaô firsô determineó iæ drivå Bº  ió selected¬  anä iæ noô theî doeó á BDOS call to change it. ;SELECT AND POLL LOGGED DISK DRIVE EXAMPLE ; SELECT EQU 0EH ;FUNCTION 14 ASKDRV EQU 19H ;FUNCTION 25 BDOS EQU 0005H ;SYSTEM ENTRY POINT ORG 0100H ;PROG START MVI C,ASKDRV ;FIND OUT IF B: IS SELECTED CALL BDOS CPI 'B'-'A' RZ ;DONT SELECT IF ALREADY ;..LOGGED MVI E,'B'-'A' ;SET TO LOG AND SELECT B: MVI C,SELECT CALL BDOS RET ;FINISHED WITH ANOTHER PROG ; END DRIVE STATUS SET AND RESET: Functions 28 & 37. Drivå  statuó  maù  bå  individuallù  controlleä  bù   theså functions®  Operatioî 2¸ allowó á thå currentlù selecteä drivå tï be write protected (set to read/only). The process is simply: Š WPDSK EQU 01CH BDOS EQU 0005H MVI C,WPDSK ;WRITE PROTECT DISK CALL BDOS Thå  writå  protecô statuó oæ á specifiã disë maù bå  removeä  bù functioî  3·  whicè  deactivateó thå directorieó  oæ  eacè  drivå specifieä  aô  calì  time®  Eacè drivå bù  defaulô  theî  becomeó read/writå  agaiî buô requireó reactivatioî througè  reselection® Thå  reseô drivå vectoò ió á 16-biô valuå passeä tï thå BDOÓ witè á  "1¢  biô  iî  eacè  biô positioî  foò  á  drivå  thaô  equireó resetting®  Thå  mosô  significanô  biô oæ  thå  1¶  biô  quanitù correspondó  tï  drivå  Pº  anä thå LS tï  drivå  A:®  Thå  codå sequence to reset drive B: would be: RESDSK EQU 025H BDOS EQU 0005H MVI C,RESDSK ;FUNCTION CODE LXÉ  D,0000$0000$0000$0010  ;DRIVÅ Bº BIÔ SEÔ CALL BDOS GET DRIVE LOGIN AND READ?ONLY VECTORS: Function 24 & 29. Thå  BDOÓ keepó tracë oæ alì driveó thaô havå beeî  selecteä sincå  thå lasô booô oò disë reseô functions®  Theså  driveó  arå considereä   iî  á  onlinå  statuó  iî  thaô  thå  systeí   knowó immediatelù  whaô  thå spacå allocatioî mað oæ thå drivå  ió  anä whetheò  thå  drivå ió iî read/onlù statuó oò  not®  Functioî  2´ allowó  thå  applicatioî prograí tï determinå whaô subseô oæ  thå currenô  drivå complemenô arå iî thió onlinå loggeä  status®  Thå vectoò returneä iî thå (HL© registeò paiò ió á biô mað likå abovå wherå á "1¢ biô meanó thå drivå ió active®  Thå mosô  significanô biô oæ thå 16-biô numbeò correspondó tï drivå P:®  Thå codå belo÷ fetches the vector and saves it in a local data area. ;LOGIN VECTOR EXAMPLE ; LOGIN EQU 018H ;FUNCTION 24 BDOS EQU 0005H ;SYSTEM ENTRY POINT ORÇ 0100H MVI C,LOGIN ;FUNCTION CALL BDOS SHLD LOCLOG ;SAVE VECTOR HERE RET ;TO CCP ; LOCLOG: DS 2 END Iî  á similaò manneò thå BDOÓ allowó determinatioî oæ  whicè driveó arå iî thå writå protecteä read/onlù status®  Á "1¢ biô iî thå  returneä  vectoò indicateó read/onlù statuó foò  á  specifiã drive. The code here shows how to fetch it. Š ;READ/ONLY VECTOR EXAMPLE ; ROVEC EQU 01DH ;FUNCTION 29 BDOS EQU 0005H ;SYSTEM ENTRY POINT ORÇ 0100H MVI C,ROVEC ;FUNCTION CALL BDOS SHLD LOCROV ;SAVE VECTOR HERE RET ;TO CCP ; LOCROV: DS 2 END GET ALLOCATION VECTOR AND DISK PARM POINTER: Function 27 & 31. Twï  morå  miscellaneouó disë drivå interfacå functionó  arå provideä  thaô  permiô severaì speciaì typeó oæ functionó  tï  bå performed®  Thå first¬ functioî 2· returnó aî addresó iî thå (HL© registeró thaô pointó tï á biô strinç iî memorù thaô  correspondó tï thå datá blocë allocatioî mað oæ thå currentlù selecteä drive® Thå  mað  containó  onå  bitó  iî eacè  positioî  wherå  á  blocë allocated¬ startinç witè thå MS oæ thå forsô bytå iî thå string® Thå  lengtè oæ thå biô strinç dependó upoî thå totaì capacitù  oæ thå  drivå  iî  allocatablå  blocks®   Functioî  3±  permitó   aî applicatioî  tï  determinå thå characteristicó oæ  thå  currentlù selecteä drive® Thå BDOÓ returnó aî addresó iî thå (HL© registeró thaô  pointó  tï  á tablå oæ 3³ byteó thaô describå  thå  currenô drive®  Datá  iî  thå  tablå  includeó sucè  datá  aó  numbeò  oæ possiblå  directorù entrieó oî thå disk¬  numbeò  oæ  allocatablå blockó oî thå disk¬ and¬ indirectly¬ thå sizå oæ eacè disë block® Thå  prograí  belo÷  ió  á comprehensivå  examplå  oæ  ho÷  theså functionó  caî bå useä tï determinå thå remaininç spacå lefô oî á thå selecteä drive® Thå prograí storeó thå availablå spacå oæ thå drivå specifieä iî thå firsô bytå oæ thå defaulô FC intï  memorù locatioî "KPDISK¢ anä theî exitó tï thå CCP® Thå readeò caî adapô the code as desired. ; ;CP/M BDOS INTERFACE EQUATES ; BASE EQU 0000H ;BASE OF CP/M SYSTEM LOGDRIV EQU 0004H+BASE ;LOCATION OF CURRENTLY LOGGED DRIVE BDOS EQU 0005H+BASE ;THE BDOS I/O VECTOR SLCTDSK EQU 14 ;SELECT DISK DRIVE GALVEC EQU 27 ;GET ADDRESS ALLOCATION VECTOR GDSKP EQU 31 ;GET ADDRESS OF DISK PARAMETER TABLE ; ; ORG 0100H ; ; ;PROGRAM TO FETCH REMAINING DISK SPACE IN KBYTES Š; SPCGET: LDA LOGDRIV ;GET CURRENTLY LOGGED DRIVE AND SAVE ANI 0FH ;STRIP OUT USER NUMBER STA SAVDRIV ;SAVE CODE ; LDA FCB ;CHECK IF SAME AS SELECT DCR A ;ADJUST FCB DRIVE TO MATCH SELECT DRIVE MOV E,A ;..SELECT IN BDOS MVI C,SLCTDSK ;SELECT DISK FUNCTION CALL BDOS ; MVI C,GDSKP ;FIND ADDRESS OF DISK PARAMETER HEADER CALL BDOS LXI B,0002H ;INDEX TO BLOCK SHIFT FACTOR DAD B MOV B,M ;(B) = BYTE BLOCK SHIFT FACTOR INX H INX H INX H MOV E,M ;(DE) = WORD DISK BLOCK COUNT INX H MOV D,M INX D ; MOV A,B ;ADJUST SHIFT FOR KBYTE SIZE SUI 03H LXI H,0001H ;CALCULATE BLOCK SIZE SPCCAL: ORA A ;KNOW KBYTES PER BLOCK? JZ SPCKNW DAD H ;DOUBLE # SECTORS PER TRACK DCR A ;DECREMENT BLOCK SHIFT JMP SPCCAL ; SPCKNW: MOV C,L ;(BC)=KBYTES PER BLOCK MOV B,H LXI H,0 ;INITIALIZE KPDISK SHLD KPDISK PUSH B ;SAVE KBYTES/BLOCK PUSH D ;SAVE NUMBER OF BLOCKS MVI C,GALVEC ;NOW POINT TO THE ALLOCATION VECTOR CALL BDOS ;(HL)=ALLOCATION VECTOR ADDRESS POP D POP B ; SHLD ALLSAVE ;SAVE ALLOCATION POINTER MVI H,1 ;SET MINIMUM START BIT COUNT ; UALLOC: DCR H ;DEC BIT COUNT JNZ STACT ;STILL ACTIVE BYTE ; LHLD ALLSAVE ;GET POINTER Š MOV A,M INX H SHLD ALLSAVE ;SAVE NEW POINTER MVI H,08H ;SET BIT COUNTER TO MAX ; STACT: RLC ;GET ALLOCATION BIT TO CARRY JC ALLOC ;DONT COUNT ALLOCATED BLOCKS PUSH H LHLD KPDISK ;GET KBYTES LEFT COUNT DAD B ;ADD IN ONE MORE BLOCK COUNT SHLD KPDISK POP H ; ALLOC: DCX D ;DEC TOTAL BLOCK COUNT MOV L,A MOV A,D ORA E ;ALL BLOCKS SCANNED YET MOV A,L ;RESTORE ALLOC BIT PATTERN JNZ UALLOC ;MORE TO COUNT ; LDA SAVDRIV ;RETURN DISK SELECT TO PREVIOUS MOV E,A ;..SELECT IN BDOS MVI C,SLCTDSK ;SELECT DISK FUNCTION CALL BDOS RET ;BACK TO THE CCP ; ; ;PROGRAM DATA STORAGE ALLOCATIONS ; BLKSIZ: DS 2 ;STORAGE FOR ALLOCATION BLOCK SIZE ALLSAVE: DS 2 ;STORAGE FOR ALLOCATION PNT SAVE SAVDRIV: DS 1 ;SAVE CURRENT DISK SELECT DURING RELOG KPDISK: DS 2 ;STORAGE FOR KBYTES PER DRIVE LEFT ; END Thå  nexô parô iî thió serieó wilì presenô thå thå CP/Í filå systeí aó vieweä froí thå BDOÓ interfacå aspect® Thå FILÅ CONTROÌ BLOCË  (FCB©  wilì bå presented®  Iî additioî thå  procedureó  tï preparå fileó foò I/Ï anä theî thå actuaì I/Ï procedureó wilì  bå presented®  Thå  serieó  wilì  rounä ouô tï á conclusioî  witè  á comprehensivå programminç examplå thaô presentó á sequentiaì filå I/Ï  seô  oæ subroutineó thaô permiô characteò bù  characteò  I/Ï with a file to be done.