1: ; 2: ;**************************************************** 3: ;* * 4: ;* Sample Random Access Proqram for CP/M-86 * 5: ;* * 6: ;**************************************************** 7: ; 8: ; BDOS Functions 9: ; 10: coninp equ 1 ;console input function 11: conout equ 2 ;console output function 12: pstrinq equ 9 ;print string unti1 '$' 13: rstring equ 10 ;read console buffer 14: version equ 12 ;return version number 15: openf equ 15 ;file open function 16: closef equ 16 ;close function 17: makef equ 22 ;make file function 18: readr equ 33 ;read random 19: writer equ 34 ;write random 20: ; 21: ; Equates for non graphic characters 22: cr equ 0dh ;carriage return 23: lf equ 0ah ;line feed 24: ; 25: ; 26: ; load SP, ready file for random access 27: ; 28: cseq 29: pushf ;push flaqs in CCP stack 30: pop ax ;save flags in AX 31: cli ;disable interrupts 32: mov bx,ds ;set SS register to base 33: mov ss,bx ;set SS, SP with interru 34: mov sp,offset stack ; for 80888 35: push ax ;restore the flags 36: popf 37: ; 38: ; CP/M-86 initial release returns the file 39: ; system version number of 2.2: check is 40: ; shown below for illustration ourposes. 41: ; 42: mov cl,version 43: call bdos 44: cmp a1,20h ;version 2.0 or later? 45: jnb versok 46: ; bad version, message and go back 47: mov dx,offset badver 48: call print 49: jmp abort 50: ; 51: versok: 52: ; correct version for random access 53: mov cl,openf ;open defau|t fct 54: dx,oftset tcb 55: call bdos 56: inc al ;err 255 becomes zero 57: jnz ready 59: ; cannot open file, so create it 60: mov cl,makef 61: mov dx,offset fcb 62: call bdos 63: inc al ;err 255 becomes zero 64: jnz ready 65: ; 66: ; cannot create file, directory null 67: mov dx,offset nospace 68: call print 69: jmp abort ;back to ccp 70: ; 71: ; loop back to "ready" after each command 72: ; 73: ready: 74: ; file is ready for processing 75: ; 76: call readcom ;read next command 77: mov ranrec,dx ;store inout record# 78: mov ranovf,0h ;clear hiqh byte if set 79: cmp al, 0 ;quit? 80: jnz notq 81: ; 82: ; quit processinq, close file 83: mov cl,closef 84: mov dx,offset fcb 85: call bdos 86: inc al ;err 255 becomes 0 87: jz error ;error message, retrv 88: jmps abort ;back to ccp 89: ; 90: ; 91: ; end of quit command, process write 92: ; 93: ; 94: notq: 95: ; not the quit command, random write? 96: cmp al,'W' 97: notw 98: ; 99: ; this is a random write, fill buffer unti1 cr 100: mov dx,offset datmsq 101: call print ;data prompt 102: mov cx,127 ;up to 127 characters 103: mov bx,offset buff ;destination 104: rloop: ;read next character to buff 105: push cx ;save loop conntro1 106: push bx ;next destination 107: call getchr ;character to AL 108: pop bx ;restore destination 109: pop cx 110: cmp al,cr ;end of line? 111: jz erloop 112: ; not end, store character 113: mov byte ptr [bx],al 114: inc bx ;next to fill 115: loop rloop ;decrement cx ..loop if 116: erloop: 117: ; end of read loop, store 00 118: mov byte ptr [bx],0h 119: ; 120: ; write the record to selected record number 121: mov cl,writer 122: mov dx,offset fcb 123: call bdos 124: or al,al ;error code zero? 125: jz readv ;for another record 126: jmps error ;messaqe if not 127: ; 128: ; 129: ; 130: ; end of write command, process read 131: ; 132: ; 133: notw: 134: ; not a write command, read record? 135: cmp al,'R' 136: jz ranread 137: jmps error ;skip if not 138: ; 139: ; read random record 140: ranread: 141: mov cl,readr 142: mov dx,offset fcb 143: call bdos 144: or al,al ;return code 00? 145: jz readok 146: jmps error 147: ; 148: ; read was successful, write to console 149: readok: 150: call crlf ;new line 151: mov cx,128 ;max 128 characters 152: mov si,offset buff ;next to get 153: wloop: 154: lods a1 ;next character 155: and a1,07fh ;mask parity 156: jnz wloopl 157: jmp ready ;for another command if 158: wloopl: 159: push cx . ;save counter 160: push ;save next to get 161: cmp al, ;qraphic? 162: jb skipw ;skip output if not grap 163: call- putchr ;output character 164: skipw: 165: poo si 166: pop cx 167: loop wloop ;decrement CX and check 168: jmp ready 169: ; 170: ; 171: ; end of read command, all errors end-up here 172: ; 173: ; 174: error: 175: mov dx,offset errmsg 176: call print 177: jmp ready 178: ; 179: ; BDOS entry subroutine 180: bdos: 181: int 224 ;entry to BDOS if by INT 182: ret 183: ; 184: abort: ;return to CCP 185: mov cl,0 186: call bdos ;use function 0 to end e 187: ; 188: ; utility subroutines for console i/o 189: ; 190: getchr: 191: ;read next console character to a 192: mov cl,coninp 193: call bdos 194: ret 195: ; 196: putchr: 197: ;write character from a to console 198: mov cl,conout 199: mov dl,al ;character to send 200: call bdos ;send character 201: ret 202: ; 203: crlf: 204: ;send carriage return line feed 205: mov al,cr ;carriage return 206: call putchr 207: mov al,lf ;line feed 208: call putchr 209: ret 210: ; 211: print: 212: ;print the buffer addressed by dx until $ 213: push. dx 214: call crlf 215: pop dx ;new line 216: mov cl,pstring 217: call bdos ;print.the string 218: ret 219: ; 220: readcom: 221: ;read the next command line to the conbuf 222: mov dx,offset prompt 223: call print ;command? 224: mov cl,rstring 225: mov dx,offset conbuf 226: ca11 bdos ;read command 1ine 227: ; command line is present, scan it 228: mov ax,0 ;start with 0000 229: mov bx,offset conlin 230: readc: mov dl,[bx] ;next command character 231: inc bx ;to next command positio 232: mov dh,0 ;zero hiqh bvte for add 233: or dl,dl ;check for end of comman 234: jnz getnum 235: ret 236: ; not zero, numeric? 237: qetnum: 238: sub dl,'0' 239: cmp dl,10 ;carry if numeric 240: jnb endrd 241: mov cl,10 242: mul cl ;mu1tipy accumulator bv 243: add ax,dx ;+digit 244: jmps readc ;for another char 245: endrd: return va1ue 246: ; end of read, restore value in a and 247: mov dx,ax ;return value in DX 248: mov al,-1[bx] 249: cmp al, a ;check for 1ower case 250: jnb transl 251: ret 252: transl: and al,5fH ;translate to upper case 253: ret 254: ; 255: ; 256: ; Template for Page 0 of data Group 257: ; Contains default FCB and DMA buffer 258: ; 259: dseg 260: org 05ch 261: fcb rb 33 ;default file control bl 262: ranrec rw 1 ;random record position 263: ranovf rb 1 ;high order (overflow) b 264: buff rb 128 ;default DMA bu@fer 265: ; 266: ; string data area for console messaqes 267: badver db 'sorry, you need cp/m version 2$' 268: nospace db 'no directory space$' 269: datmsg db 'type data: $' 270: errmsg db 'error, try again.$' 271: prompt db 'next command? $' 272: ; 273: ; 274 ; fixed and variab1e data area 275: ; 276: conbuf db conlen ;length of console buffer 277: consiz rs 1 ;resulting size after read 278: conlin rs 32 ;length 32 buffer 279: conlen equ offset $ - offset consiz 280: ; 281: rs 31 ;16 level stack 282: stack rb 1 283: db 0 ;end byte for GENCMD 284: end