;ISOCD.M68 - Program to read ISO-9660 formatted CD-ROMs ; ; NOTICE ; ;All rights reserved. This software is the property of Alpha Microsystems ;and the material contained herein is the proprietary property and trade ;secrets of Alpha Microsystems, embodying substantial creative efforts and ;confidential information, ideas and expressions, no part of which may be ;reproduced or transmitted in any form or by any means, electronic, ;mechanical, or otherwise, including photocopying or input into any ;information storage or retrieval system without the express written ;permission of Alpha Microsystems. ; ;CAUTION: Unauthorized distribution or reproduction of this material may ;subject you to legal action. ; ;Copyright (C) 1983, 1990 - Alpha Microsystems ; ;Edit History: ; ;[101] 05 November 1993 11:52 Edited by Rod Hewitt ; Added SET UNIX and SET DOS commands to allow different end-of-line ; formats to be handled. Added COPYR command to copy a file into an ; AMOS random access file ;[100] 19 October 1993 16:29 Edited by Rod Hewitt ; Created SEARCH SYS SEARCH SYSSYM SEARCH SCZSYM VMAJOR=1 VMINOR=0 VEDIT=101. BASE: PHDR -1,0,PH$REU!PH$REE!PH$M20 ;Define impure area .OFINI .OFDEF CDB,6 ; SCSI command data block .OFDEF INQURY,40. ; inquiry block .OFDEF SENBUF,18. ; sense buffer .OFDEF SBUF,2048. ; sector buffer .OFDEF CURDIR,4 ; current directory sector # .OFDEF CURDIRSZ,4 ; current directory size in bytes .OFDEF ROOTDIR,4 ; sector # of root directory .OFDEF ROOTDIRSZ,4 ; size of root directory .OFDEF BYTECNT,4 ; byte count for current directory .OFDEF FILECNT,4 ; file count for current directory .OFDEF ODDB,D.DDB ; output DDB .OFDEF CDID,1 ; SCSI id of CDROM .OFDEF UNIXFLG,1 ; DOS/UNIX flag (set for unix) .OFDEF DIRSTR,80. ; current directory string .OFSIZ IMPSIZ ; impure area size ;Define ISO-9660 primary volume descriptor record .OFINI .OFDEF P.VOLDTYP,1 ; volume descriptor type .OFDEF P.STDID,5 ; standard identifier .OFDEF P.VOLDVER,1 ; volume descriptor version .OFDEF P.UNUSED1,1 ; unused .OFDEF P.SYSID,32. ; system identifier .OFDEF P.VOLID,32. ; volume identifier .OFDEF P.UNUSED2,8. ; unused .OFDEF P.VOLSPACE,8. ; volume space size .OFDEF P.UNUSED3,32. ; unused .OFDEF P.VOLSETSIZE,4 ; volume set size .OFDEF P.VOLSEQNO,4 ; volume sequence number .OFDEF P.BLOCKSZ,4 ; logical block size .OFDEF P.PTHTBLSZ,8. ; path table size .OFDEF P.LTYPPTHTBL,4 ; location of occurance of L-type path .OFDEF P.LTYPPTHTBLO,4 ; ditto for optional L-type .OFDEF P.MTYPPTHTBL,4 ; location of occurance of M-type path .OFDEF P.MTYPPTHTBLO,4 ; ditto for optional M-type .OFDEF P.DIRROOT,34. ; directory record for root .OFDEF P.VOLSETID,128. ; volume set identifier .OFDEF P.PUBID,128. ; publisher identifier .OFDEF P.PREPID,128. ; data preparer identifier .OFDEF P.APPID,128. ; application identifier .OFDEF P.COPYFILEID,37. ; copyright file identifier .OFDEF P.ABSFILEID,37. ; abstract file identifier .OFDEF P.BIBFILEID,37. ; bibliographic file identifier .OFDEF P.VOLCREDATE,17. ; volume creation date/time .OFDEF P.VOLMODDATE,17. ; volume modification date/time .OFDEF P.VOLEXPDATE,17. ; volume expiration date/time .OFDEF P.VOLEFFDATE,17. ; volume effective date/time .OFDEF P.FILESTUCVER,1 ; file structure version ;Define ISO-9660 file/directory entries .OFINI .OFDEF F.LENDR,1 ; length of directory record .OFDEF F.ATTR,1 ; extended attribute record length .OFDEF F.EXTENLOC,8. ; location of extent .OFDEF F.DATALEN,8. ; data length .OFDEF F.RECDT,7. ; recording date/time .OFDEF F.FILEFLG,1 ; file flags .OFDEF F.FILEUNITSZ,1 ; file unit size .OFDEF F.INTGAPSZ,1 ; interleave gap size .OFDEF F.VOLSEQNO,4 ; volume sequence number .OFDEF F.LENFI,1 ; length of file identifier .OFDEF F.FILEID ; file identifier ;Define ISO-9660 (header) date and time format .OFINI .OFDEF DT.YEAR,4 ; year .OFDEF DT.MONTH,2 ; month .OFDEF DT.DAY,2 ; day .OFDEF DT.HOUR,2 ; hour .OFDEF DT.MINUTE,2 ; minute .OFDEF DT.SECOND,2 ; second .OFDEF DT.HUNSEC,2 ; hundreths of seconds .OFDEF DT.OFFSET,1 ; offset from GMT in 30 minute intervals ;Define ISO-9660 (file) date and time format .OFINI .OFDEF DF.YEAR,1 ; years since 1900 .OFDEF DF.MONTH,1 ; month .OFDEF DF.DAY,1 ; day .OFDEF DF.HOUR,1 ; hour .OFDEF DF.MINUTE,1 ; minute .OFDEF DF.SECOND,1 ; second .OFDEF DF.OFFSET,1 ; offset from GMT in 30 minute intervals ;Define macros to extract a word/lword from a field regardless of allignment DEFINE GETWORD ADDRESS,REGISTER CLR REGISTER ; pre-clear destination register MOVB 1+ADDRESS,REGISTER ; get first byte ROL REGISTER,#8. ; shift MOVB ADDRESS,REGISTER ; get second byte ENDM DEFINE GETLWORD ADDRESS,REGISTER CLR REGISTER ; pre-clear destination register MOVB 3+ADDRESS,REGISTER ; get first byte ROL REGISTER,#8. ; shift MOVB 2+ADDRESS,REGISTER ; get second byte ROL REGISTER,#8. ; shift MOVB 1+ADDRESS,REGISTER ; get third byte ROL REGISTER,#8. ; shift MOVB ADDRESS,REGISTER ; get fourth byte ENDM ;Macro to display digits from memory DEFINE DISPDIG ADDRESS,LENGTH SAVE D0,D1,A0 ; save work registers LEA A0,ADDRESS ; index address MOV #LENGTH-1,D0 ; get length 10$$: MOVB (A0)+,D1 ; get next byte TTY ; display it DBF D0,10$$ ; loop REST D0,D1,A0 ; restore registers ENDM ;Macro to advance current cursor position DEFINE ADVANCE COLUMN SAVE D1 MOVB #32.,D1 ; get a space character 10$$: CMP D3,#COLUMN ; there yet? BHIS 20$$ ; yes - TTY ; output a space INC D3 ; bump position BR 10$$ ; and loop 20$$: REST D1 ; restore ENDM PAGE ;*********** ;* START * ;*********** START: SUPVR ; we run in supervisor mode ;Get impure area and various register setup GETIMP IMPSIZ,A4 ; get impure space CLEAR @A4,IMPSIZ ; pre-clear ;Ensure we have a dispatcher installed. This is mandatory for a CD-Recorder MOV SCZDSP,D7 ; is a SCSI dispatcher installed? BNE 10$ ; yes - ok TYPECR EXIT 10$: ;Display version number etc TYPESP VCVT BASE+PH.VER,OT$TRM ; display version TYPECR < - Copyright (C) 1993 Alpha Microsystems Inc.> CRLF PAGE ;*************** ;* CHECK$ACD * ;*************** ; ; Check to see if ACD is installed - if it is, we can't run ; CHECK$ACD: LEA A0,DEVTBL ; get index to device table 10$: MOV @A0,D7 ; get link to next device BEQ 20$ ; skip if end of table MOV D7,A0 ; CMPW DV.DEV(A0),#[ACD] ; AlphaCD already installed? BNE 10$ ; no - TYPECR EXIT 20$: PAGE ;****************** ;* LOCATE$CDROM * ;****************** ; ; Scan the SCSI bus for a CD-ROM ; LOCATE$CDROM: TYPE MOV #6,D3 ; get starting SCSI id 10$: QGETW A1 ; get a SCSI request q-block MOVB D3,RQ.ID(A1) ; move in the SCSI id MOVB #^H12,0+RQ.CDB(A1) ; set command to inquiry MOVB #40.,4+RQ.CDB(A1) ; set inquiry length MOVB #6,RQ.CDBSZ(A1) ; set command length QGETW A5 ; get a data request q-block MOV A5,RQ.DPLK(A1) ; link to the SCSI request MOV #0,TD.LNK(A5) ; ensure the link is clear MOV #40.,TD.SIZ(A5) ; set transfer size LEA A6,INQURY(A4) ; index storage for inquiry data MOV A6,TD.BUF(A5) ; move into the data request CLEAR INQURY(A4),40. ; ensure inquiry block is clean MOV SCZDSP,A6 ; index the SCSI dispatcher CALL @A6 ; go execute the command QRET A5 ; free up the data request block MOVB RQ.EXSTS(A1),D0 ; get the execution status QRET A1 ; free up the SCSI request block TSTB D0 ; execution OK? BEQ 30$ ; yes - check drive type ;Didn't locate any SCSI device or not a CD-ROM, so decrement the ID and try ;again 20$: TYPE <.> ; display lifeline DEC D3 ; down to the next id JCC 10$ ; loop until we're done ;All out of SCSI IDs to check, so error out CRLF ; get a blank line TYPECR EXIT ; get outta here ;Got inquiry data, so check it to see if this is a CD-ROM 30$: MOVB INQURY(A4),D7 ; get device type AND #^H07F,D7 ; only low 7 bits count CMPB D7,#5 ; CD-ROM device? BNE 20$ ; no - try next SCSI device ;We located the CD-ROM drive, so save it's ID for use later MOVB D3,CDID(A4) ; save id CRLF ; get a blank line TYPESP CLR D1 ; pre-clear MOV D3,D1 ; get a copy DCVT 0,OT$TRM ; display SCSI id CRLF ; tidy display 99$: PAGE ;**************************** ;* READ$VOLUME$DESCRIPTOR * ;**************************** ; ; Read the volume descriptor at sector 16 to see if this is an ISO-9660 CD-ROM ; READ$VOLUME$DESCRIPTOR: MOV #16.,D4 ; get starting ISO sector number CALL READ$SECTOR ; read in the sector LEA A3,SBUF(A4) ; index sector buffer ;Check standard ID field LEA A6,P.STDID(A3) ; index the standard ID field LEA A0,COMPID ; index comparision id field MOV #5,D0 ; get comparision length 10$: CMMB (A6)+,(A0)+ ; standard ID field match? BNE 20$ ; no - SOB D0,10$ ; loop BR 30$ ; skip around 20$: TYPECR EXIT ;Display volume information 30$: TYPESP LEA A0,P.VOLID(A3) ; index the volume id MOV #32.,D0 ; get length of field 40$: MOVB (A0)+,D1 ; get next byte TTY ; display SOB D0,40$ ; loop TYPESP < created:> LEA A0,P.VOLCREDATE(A3) ; index the volume creation date/time CALL DISP$ISO$DATE$TIME ; and display it CRLF ; get a new line CRLF ; double for a nice look ;Set root directory location as current directory sector # LEA A0,P.DIRROOT(A3) ; index the root directory record GETLWORD F.EXTENLOC(A0),D7 ; get root directory location MOV D7,CURDIR(A4) ; save as current directory MOV D7,ROOTDIR(A4) ; save root directory GETLWORD F.DATALEN(A0),D7 ; get root directory size MOV D7,CURDIRSZ(A4) ; save it's size MOV D7,ROOTDIRSZ(A4) ; save root directory size MOVB #'\,DIRSTR(A4) ; setup root directory in dirstring MOVB #0,DIRSTR+1(A4) ; and null terminate PAGE ;*************** ;* MAIN$LOOP * ;*************** ; ; Main command prompt loop ; MAIN$LOOP: TTYI ; display start of command prompt ASCIZ #CD:# EVEN ;Display the current directory LEA A0,DIRSTR(A4) ; index directory string 5$: MOVB (A0)+,D1 ; get next byte. End of string? BEQ 7$ ; yes - TTY ; display it BR 5$ ; go get next byte 7$: TTYI ; display end of command prompt ASCIZ #># ; display prompt character EVEN ;Get command 10$: KBD CTRLCH ; get next command BYP ; skip past any blanks LIN ; end of line? BNE 20$ ; no - JMP MAIN$LOOP ; yes - just re-display prompt ;Check the command against the valid command table 20$: LEA A0,CMDTBL ; index command table 30$: MOV (A0)+,D5 ; get next handler address. End? BEQ 90$ ; yes - invalid command MOV A2,A1 ; get a copy of command line index CLR D6 ; flag command match so far 40$: MOVB (A0)+,D7 ; get next byte of command. End? BEQ 50$ ; yes - CMPB D7,(A1)+ ; matching command character? BEQ 40$ ; yes - process next character SET D6 ; no - not this command BR 40$ ; but continue to the command end ;See if the command matched 50$: TST D6 ; matching command? BNE 60$ ; no - LEA A6,BASE ; index program base ADD D5,A6 ; add in the handler offset JMP @A6 ; go execute the command ;Command didn't match so allign A0 up to the next lword and try the next ;command. As the padder bytes to the next command are -1, scan @A0 until ;we get non -1, then we're at the next lword 60$: MOVB @A0,D7 ; in the filler area still? BMI 70$ ; yes - BR 30$ ; no - go try next command 70$: INC A0 ; bump to next byte BR 60$ ; loop until we find it ;Come here when we get a bad command 90$: TYPECR JMP MAIN$LOOP ; go get next command ;Come here when we get a ^C during the command prompt CTRLCH: JOBIDX A6 ; index our JCB ANDW #^C,JOBSTS(A6) ; clear the ^C TYPECR <^C> ; display we got a ^C JMP MAIN$LOOP ; go get next prompt ;Define the command table. Format is: ; LWORD - offset to handler - zero terminates ; ASCIZ - command string ; padding - to next lword DEFINE CMDTABLE HANDLER,STRING LWORD HANDLER ; offset to handler ASCIZ #STRING# ; string to look for IF NE,.&1,BYTE -1 ; get onto a word boundry IF NE,.&2,WORD -1 ; get onto a longword boundry ENDM CMDTBL: CMDTABLE DIRWIDE, ; wide directory CMDTABLE EXIT$, ; exit command CMDTABLE EXIT$, ; another version of exit CMDTABLE EXIT$, ; yet another version of exit CMDTABLE EXIT$, ; yet another version of exit CMDTABLE COPYRANDOM, ; copy random file to AMOS CMDTABLE COPYFILE, ; copy file to AMOS CMDTABLE CHANGEDIR, ; change directory CMDTABLE TYPEFILE, ; type file CMDTABLE HELP, ; help command CMDTABLE HELP, ; help command again CMDTABLE DIRSTD, ; standard directory CMDTABLE SETDOS, ; set DOS line terminator CMDTABLE SETUNX, ; set UNIX line terminator CMDTABLE VERSION, ; display version number LWORD 0 ; end of table PAGE ;********** ;* HELP * ;********** ; ; Display user help ; HELP: CRLF TYPECR CRLF TYPECR < QUIT - return to AMOS> TYPECR < CD directory - change directory> TYPECR < DIR - list files> TTYI ASCII # DIR/W - wide file list# BYTE 13.,0 EVEN TYPECR < COPY file amosfile - transfer file to AMOS> TYPECR < COPYR file amosfile - transfer random file to AMOS> TYPECR < TYPE file - display file on terminal> TYPECR < SET DOS - sets normal line termination> TYPECR < SET UNIX - sets UNIX style line termination> CRLF JMP MAIN$LOOP PAGE ;************ ;* SETUNX * ;************ ; ; Set UNIX style line termination flag ; SETUNX: TYPECR SETB UNIXFLG(A4) ; set unix flag JMP MAIN$LOOP ; go get next command ;************ ;* SETDOS * ;************ ; ; Clear unix style line termination flag ; SETDOS: TYPECR CLRB UNIXFLG(A4) ; clear unix flag JMP MAIN$LOOP ; go get next command ;************* ;* VERSION * ;************* ; ; Display version number ; VERSION: CRLF TYPESP VCVT BASE+PH.VER,OT$TRM ; display version CRLF CRLF JMP MAIN$LOOP PAGE ;************ ;* DIRSTD * ;************ ; ; Standard directory listing for the current directory ; DIRSTD: MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size CLR FILECNT(A4) ; clear file count CLR BYTECNT(A4) ; clear byte count 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Display current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 25$ ; skip if none here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;Display the current file 25$: INC FILECNT(A4) ; bump file count CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of file identifier MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BNE 27$ ; yes - SUB #2,D0 ; decrement size of filename so we ; don't display the ISO version number ; field 27$: LEA A0,F.FILEID(A3) ; index the file id CLR D3 ; clear byte output counter 30$: MOVB (A0)+,D1 ; get next byte of file id CMPB D1,#32. ; printable character? BLO 35$ ; no - don't display CMPB D1,#126. ; printable character? BHI 35$ ; no - don't display TTY ; display it INC D3 ; bump byte output counter 35$: SOB D0,30$ ; loop for entire file id ;Now advance to column 12 where we output either the size or directory flag ADVANCE 14. ; use smart macro ;Display either size or if it's a directory MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 40$ ; no - it's a file TTYI ASCIZ # # EVEN ADD #10.,D3 ; bump cursor position BR 50$ ; skip around 40$: GETLWORD F.DATALEN(A3),D1 ; get length of file ADD D1,BYTECNT(A4) ; bump directory byte count DCVT 10.,OT$TRM!OT$ZER ; display it ADD #10.,D3 ; bump cursor position ;Display file's date and time 50$: LEA A0,F.RECDT(A3) ; index date and time fields TYPE < > ; seperate out CLR D1 ; pre-clear MOVB DF.MONTH(A0),D1 ; get month DCVT 2,OT$TRM ; display TYPE <-> MOVB DF.DAY(A0),D1 ; get day DCVT 2,OT$TRM ; display TYPE <-> MOVB DF.YEAR(A0),D1 ; get year DCVT 2,OT$TRM ; display TYPE < > MOVB DF.HOUR(A0),D1 ; get hour DCVT 2,OT$TRM ; display TYPE <:> MOVB DF.MINUTE(A0),D1 ; get minute DCVT 2,OT$TRM!OT$TSP ; display GETLWORD F.EXTENLOC(A3),D1 ; get address of file OCVT 8.,OT$TRM ; display it CRLF ; done with this line ;Bump to the next directory entry and process it CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Done processing this directory, output statistics 99$: MOV FILECNT(A4),D1 ; get file count DCVT 10.,OT$TRM!OT$ZER!OT$TSP ; display file count TYPESP MOV BYTECNT(A4),D1 ; get byte count DCVT 12.,OT$TRM!OT$ZER!OT$TSP ; display file count TYPECR CRLF ; extra for a nice look JMP MAIN$LOOP PAGE ;************* ;* DIRWIDE * ;************* ; ; Wide directory listing ; DIRWIDE: MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size CLR FILECNT(A4) ; clear file count CLR BYTECNT(A4) ; clear byte count CLR D3 ; pre-clear column counter 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Display current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 30$ ; skip if none here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;Display the current file 30$: INC FILECNT(A4) ; bump file count CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of file identifier MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 40$ ; no - TYPE <[> ; show it's a directory INC D3 ; and bump position BR 50$ ; skip around 40$: SUB #2,D0 ; decrement size of filename so we ; don't display the ISO version number ; field GETLWORD F.DATALEN(A3),D1 ; get length of file ADD D1,BYTECNT(A4) ; bump directory byte count 50$: LEA A0,F.FILEID(A3) ; index the file id 60$: MOVB (A0)+,D1 ; get next byte of file id CMPB D1,#32. ; printable character? BLO 65$ ; no - don't display CMPB D1,#126. ; printable character? BHI 65$ ; no - don't display TTY ; display it INC D3 ; bump byte output counter 65$: SOB D0,60$ ; loop for entire file id MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 70$ ; no - TYPE <]> ; show it's a directory INC D3 ; and bump position ;See if we need a new line yet 70$: CMP D3,#60. ; time for a new line? BLO 80$ ; no - CRLF ; get a new line CLR D3 ; reset column position BR 90$ ; go process next file 80$: MOV D3,D7 ; get a copy of current position DIV D7,#15. ; divide into column width SWAP D7 ; get the remainder AND #^H0FFFF,D7 ; mask out the quotient MOV #15.-1,D0 ; get characters per column DBF style SUB D7,D0 ; calculate space to next one MOVB #32.,D1 ; get a space 85$: TTY ; move along to next column INC D3 ; bump column counter DBF D0,85$ ; loop until there ;Bump to the next directory entry and process it 90$: CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Done processing this directory, output statistics 99$: TST D3 ; do we need a new line? BEQ 100$ ; no - CRLF ; yes - 100$: MOV FILECNT(A4),D1 ; get file count DCVT 10.,OT$TRM!OT$ZER!OT$TSP ; display file count TYPESP MOV BYTECNT(A4),D1 ; get byte count DCVT 12.,OT$TRM!OT$ZER!OT$TSP ; display file count TYPECR CRLF ; extra for a nice look JMP MAIN$LOOP PAGE ;************** ;* TYPEFILE * ;************** ; ; Routine to display the contents of a file on the screen ; ; A1 current indexes the command line directly after the word "TYPE" ; TYPEFILE: MOV A1,A2 ; use A2 instead so others work BYP ; skip past spaces LIN ; anything there? BNE 5$ ; yes - TYPECR JMP MAIN$LOOP ; back again 5$: MOV A2,A1 ; save "new" file name index MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Check current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 30$ ; skip if something here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;See if the current file is a directory 30$: MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 45$ ; no - ; yes - fall through to next one ;Bump to the next directory entry and process it 40$: CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Compare current filespec against user request 45$: CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of file identifier SUB #2,D0 ; decrement size of filename so we ; don't compare the ISO version number ; field MOV A1,A2 ; get a copy of filename index LEA A6,F.FILEID(A3) ; index the current directory fileid 50$: CMMB (A2)+,(A6)+ ; file name match? BNE 40$ ; no - SOB D0,50$ ; loop until all compared LIN ; is this really the right file? BNE 40$ ; no - try the next one ;Current directory entry is for this file, so lets display it GETLWORD F.DATALEN(A3),D3 ; get length of file GETLWORD F.EXTENLOC(A3),D4 ; get address of file 60$: CALL READ$SECTOR ; get the next block LEA A3,SBUF(A4) ; index the returned sector buffer MOV #2048.,D2 ; get size of sector 70$: CTRLC CTRLCH ; out if we need to MOVB (A3)+,D1 ; get next byte CMPB D1,#10. ; end of line character? BNE 75$ ; no - TSTB UNIXFLG(A4) ; in Unix mode? BEQ 75$ ; no - standard output CRLF ; yes - line feed = CR/LF BR 76$ ; skip around 75$: TTY ; display it 76$: DEC D2 ; decrement bytes this sector BNE 80$ ; some left this sector INC D4 ; bump sector number BR 60$ ; and go read some more 80$: DEC D3 ; decrement file bytes. Any left? BNE 70$ ; yes - display next one CRLF ; get a new line JMP MAIN$LOOP ; all done with this file ;No more files in this directory, so display file not found 99$: TYPECR CRLF JMP MAIN$LOOP PAGE ;************** ;* COPYFILE * ;************** ; ; Routine to copy an ISO file to AMOS in sequential format ; ; A1 current indexes the command line directly after the word "COPY" ; COPYFILE: MOV A1,A2 ; use A2 instead so others work BYP ; skip past spaces LIN ; anything there? BNE 5$ ; yes - TYPECR JMP MAIN$LOOP ; back again 5$: MOV A2,A1 ; get a copy of "new" filename index MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Check current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 30$ ; skip if something here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;See if the current file is a directory 30$: MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 45$ ; no - ; yes - fall through to next one ;Bump to the next directory entry and process it 40$: CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Compare current filespec against user request 45$: CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of file identifier SUB #2,D0 ; decrement size of filename so we ; don't compare the ISO version number ; field MOV A1,A2 ; get a copy of filename index LEA A6,F.FILEID(A3) ; index the current directory fileid 50$: CMMB (A2)+,(A6)+ ; file name match? BNE 40$ ; no - SOB D0,50$ ; loop until all compared CMPB @A2,#32. ; space between ISO & AMOS filenames? BNE 40$ ; no - this isn't the right file ;Open up the output file. A0 currently indexes just after the ISO filename ;so scan past the extra spaces to find the AMOS filename BYP ; skip past any spaces LIN ; anything there? BNE 55$ ; yes - TYPECR JMP MAIN$LOOP ; go get next command 55$: FSPEC ODDB(A4) ; process filespec INIT ODDB(A4) ; initialize DDB and get buffer LOOKUP ODDB(A4) ; does this file already exist? BNE 57$ ; no - ok DSKDEL ODDB(A4) ; yes - erase it first 57$: OPENO ODDB(A4) ; open it for output ;Current directory entry is for this file, so output it GETLWORD F.DATALEN(A3),D3 ; get length of file GETLWORD F.EXTENLOC(A3),D4 ; get address of file 60$: CALL READ$SECTOR ; get the next block LEA A3,SBUF(A4) ; index the returned sector buffer MOV #2048.,D2 ; get size of sector 70$: CTRLC CTRLCH ; out if we need to MOVB (A3)+,D1 ; get next byte CMPB D1,#10. ; end of line character? BNE 75$ ; no - TSTB UNIXFLG(A4) ; in Unix mode? BEQ 75$ ; no - standard output MOVB #13.,D1 ; get a carriage return FILOTB ODDB(A4) ; output it MOVB #10.,D1 ; get a line feed 75$: FILOTB ODDB(A4) ; write to output file DEC D2 ; decrement bytes this sector BNE 80$ ; some left this sector INC D4 ; bump sector number BR 60$ ; and go read some more 80$: DEC D3 ; decrement file bytes. Any left? BNE 70$ ; yes - display next one ;All done writing the file. Close it and remove the DDB buffer so we don't ;run out of memory if we do this lots of times CLOSE ODDB(A4) ; close the output file MOV D.BUF+ODDB(A4),D7 ; index the output buffer PUSH ; pseudo size PUSH D7 ; stack the buffer address DELMEM @SP ; delete the output buffer POP ; clean up POP ; ditto CLRB D.FLG+ODDB(A4) ; clear flags to say no longer INITed JMP MAIN$LOOP ; all done with this file ;No more files in this directory, so display file not found 99$: TYPECR CRLF JMP MAIN$LOOP PAGE ;**************** ;* COPYRANDOM * ;**************** ; ; Routine to copy an ISO file to AMOS in random format ; ; A1 current indexes the command line directly after the word "COPYR" ; COPYRANDOM: MOV A1,A2 ; use A2 instead so others work BYP ; skip past spaces LIN ; anything there? BNE 5$ ; yes - TYPECR JMP MAIN$LOOP ; back again 5$: MOV A2,A1 ; get a copy of "new" filename index MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Check current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 30$ ; skip if something here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;See if the current file is a directory 30$: MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BEQ 45$ ; no - ; yes - fall through to next one ;Bump to the next directory entry and process it 40$: CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Compare current filespec against user request 45$: CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of file identifier SUB #2,D0 ; decrement size of filename so we ; don't compare the ISO version number ; field MOV A1,A2 ; get a copy of filename index LEA A6,F.FILEID(A3) ; index the current directory fileid 50$: CMMB (A2)+,(A6)+ ; file name match? BNE 40$ ; no - SOB D0,50$ ; loop until all compared CMPB @A2,#32. ; space between ISO & AMOS filenames? BNE 40$ ; no - this isn't the right file ;Open up the output file. A0 currently indexes just after the ISO filename ;so scan past the extra spaces to find the AMOS filename BYP ; skip past any spaces LIN ; anything there? BNE 55$ ; yes - TYPECR JMP MAIN$LOOP ; go get next command 55$: FSPEC ODDB(A4) ; process filespec INIT ODDB(A4) ; initialize DDB and get buffer LOOKUP ODDB(A4) ; does this file already exist? BNE 57$ ; no - ok DSKDEL ODDB(A4) ; yes - erase it first 57$: GETLWORD F.DATALEN(A3),D3 ; get length of file GETLWORD F.EXTENLOC(A3),D4 ; get address of file ;Now calculate the disk drive requirements for this file and allocate ;a random file MOV D3,D5 ; get a copy of file size DIV D5,#512. ; calculate number of disk blocks MOV D5,D6 ; get a copy AND #^H0FFFF,D5 ; mask out remainder SWAP D6 ; get the remainder TSTW D6 ; any remainder? BEQ 58$ ; no - INC D5 ; yes - bump # of disk blocks 58$: MOV D5,D.ARG+ODDB(A4) ; setup number of blocks DSKCTG ODDB(A4) ; allocate a contiguous file OPENR ODDB(A4),F.EXC ; and open it CLR D.REC+ODDB(A4) ; start outputting at record 0 MOV #512.,D.SIZ+ODDB(A4) ; setup block size we want ;Now read through the ISO file and output blocks to the random access file ;we just created 60$: CALL READ$SECTOR ; get the next block LEA A3,SBUF(A4) ; index the returned sector buffer MOV #4,D3 ; get number of disk blocks we got 70$: MOV A3,D.BUF+ODDB(A4) ; point DDB buffer at ISO data OUTPUT ODDB(A4) ; write out the next block ADD #512.,A3 ; point to next disk blocks worth INC D.REC+ODDB(A4) ; bump to next block DEC D5 ; decrement total disk blocks BEQ 80$ ; skip out if we're done DEC D3 ; decrement disk blocks in this sector BNE 70$ ; more this sector BR 60$ ; go get another sector ;All done writing the file. Close it and remove the DDB buffer so we don't ;run out of memory if we do this lots of times 80$: CLOSE ODDB(A4) ; close the output file MOV D.BUF+ODDB(A4),D7 ; index the output buffer PUSH ; pseudo size PUSH D7 ; stack the buffer address DELMEM @SP ; delete the output buffer POP ; clean up POP ; ditto CLRB D.FLG+ODDB(A4) ; clear flags to say no longer INITed JMP MAIN$LOOP ; all done with this file ;No more files in this directory, so display file not found 99$: TYPECR CRLF JMP MAIN$LOOP PAGE ;*************** ;* CHANGEDIR * ;*************** ; ; Routine to change directory ; ; A1 current indexes the command line directly after the word "CD" ; CHANGEDIR: MOV A1,A2 ; use A2 instead so others work BYP ; skip past spaces LIN ; anything there? BNE 5$ ; yes - TYPECR JMP MAIN$LOOP ; back again ;Check to see if they want the root directory 5$: CMPB @A2,#'\ ; root directory? BNE 7$ ; no - MOV ROOTDIR(A4),CURDIR(A4) ; set current directory as root MOV ROOTDIRSZ(A4),CURDIRSZ(A4); set current directory size MOVB #'\,DIRSTR(A4) ; set root as current dir string MOVB #0,DIRSTR+1(A4) ; and null terminate JMP MAIN$LOOP ; and back we go ;Scan through the current directory in an attempt to find the directory wanted 7$: MOV CURDIR(A4),D4 ; get current directory record # MOV CURDIRSZ(A4),D5 ; get current directory size 10$: CALL READ$SECTOR ; read directory block SUB #2048.,D5 ; decrement directory size LEA A3,SBUF(A4) ; index the sector buffer ;Check current entry 20$: CLR D0 ; pre-clear MOVB F.LENDR(A3),D0 ; get length of directory entry BNE 30$ ; skip if something here ;Last directory entry in this block - continue to the next unless we're done CMP D5,#0 ; end of directory? (ie. all bytes ; processed) JLOS 99$ ; yes - INC D4 ; bump to the next directory sector BR 10$ ; and get the next directory sector ;See if the current file is a directory 30$: MOVB F.FILEFLG(A3),D7 ; get file flags BTST #1,D7 ; is this a directory? BNE 45$ ; yes - ; yes - fall through to next one ;Bump to the next directory entry and process it 40$: CLR D7 ; pre-clear MOVB F.LENDR(A3),D7 ; get length of directory record ADD D7,A3 ; bump to the next entry CTRLC CTRLCH ; check for ^C JMP 20$ ; go process it ;Compare current filespec against user request 45$: CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of directory string MOV A2,A0 ; get a copy of filename index LEA A6,F.FILEID(A3) ; index the current directory fileid 50$: CMMB (A0)+,(A6)+ ; file name match? BNE 40$ ; no - SOB D0,50$ ; loop until all compared ;Current directory entry is for the requested directory, so set that one ;up as the current directory GETLWORD F.EXTENLOC(A3),D7 ; get address of directory MOV D7,CURDIR(A4) ; setup as new directory GETLWORD F.DATALEN(A3),D7 ; get directory size MOV D7,CURDIRSZ(A4) ; save it's size ;Add current directory to directory string CLR D0 ; pre-clear MOVB F.LENFI(A3),D0 ; get length of directory string MOV A2,A0 ; get a copy of filename index LEA A6,DIRSTR(A4) ; index the directory string 60$: MOVB @A6,D7 ; did we reach the dir string end? BEQ 70$ ; yes - INC A6 ; no - bump to next character BR 60$ ; and keep on checking 70$: MOVB (A0)+,(A6)+ ; add new directory into string SOB D0,70$ ; loop for entire current dir MOVB #'\,(A6)+ ; add in a directory seperator MOVB #0,(A6)+ ; terminate it JMP MAIN$LOOP ; all done ;No more files in this directory, so display file not found 99$: TYPECR CRLF JMP MAIN$LOOP PAGE ;************************ ;* DISP$ISO$DATE$TIME * ;************************ ; ; Subroutine to display ISO-9660 format date and time ; ; Input: A0 -> date and time in ISO-9660 17 byte format ; DISP$ISO$DATE$TIME: DISPDIG DT.MONTH(A0),2 ; display month TTYI ; seperator ASCIZ #/# EVEN DISPDIG DT.DAY(A0),2 ; display day TTYI ; seperator ASCIZ #/# EVEN DISPDIG DT.YEAR(A0),4 ; display year TYPE < > ; seperate date and time CLR D1 ; pre-clear DISPDIG DT.HOUR(A0),2 ; display hour TYPE <:> ; seperator DISPDIG DT.MINUTE(A0),2 ; display minute TYPE <:> ; seperator DISPDIG DT.SECOND(A0),2 ; display second RTN ; all done PAGE ;***************** ;* READ$SECTOR * ;***************** ; ; Subroutine to read a sector from the CD-ROM ; ; Input: D4 = sector # to read ; ; Output: SBUF(A4) contains the sector if read correctly ; Z bit set if OK ; READ$SECTOR: SAVE A1,A5 ; save work registers 5$: QGETW A1 ; get a SCSI request q-block MOVB CDID(A4),RQ.ID(A1) ; move in the SCSI id MOVB #^H28,0+RQ.CDB(A1) ; set command to extended read MOV D4,D7 ; get a copy of block # MOVB D7,5+RQ.CDB(A1) ; setup LL block address ROR D7,#8. ; shift MOVB D7,4+RQ.CDB(A1) ; setup LH block address ROR D7,#8. ; shift MOVB D7,3+RQ.CDB(A1) ; setup HL block address ROR D7,#8. ; shift MOVB D7,2+RQ.CDB(A1) ; setup HH block address MOVB #1,8.+RQ.CDB(A1) ; setup transfer length (1 block) MOVB #10.,RQ.CDBSZ(A1) ; set command length QGETW A5 ; get a data request q-block MOV A5,RQ.DPLK(A1) ; link to the SCSI request MOV #0,TD.LNK(A5) ; ensure the link is clear MOV #2048.,TD.SIZ(A5) ; set transfer size LEA A6,SBUF(A4) ; index storage for sector MOV A6,TD.BUF(A5) ; move into the data request MOV SCZDSP,A6 ; index the SCSI dispatcher CALL @A6 ; go execute the command QRET A5 ; free up the data request block MOVB RQ.EXSTS(A1),D0 ; get the execution status MOVB RQ.STAT(A1),D2 ; get the SCSI status QRET A1 ; free up the SCSI request block TSTB D0 ; execution OK? BEQ 10$ ; no - ok REST A1,A5 ; clean up stack JMP EXECUTION$ERROR ; go process fatal dispatcher error 10$: TSTB D2 ; SCSI error? BEQ 99$ ; no - CMPB D2,#8. ; busy status? BNE 20$ ; no - SLEEP #100. ; stall for a moment JMP 5$ ; and go try again 20$: CALL RQSNS ; request sense information CMPB D2,#6 ; unit attention? JEQ 5$ ; yes - try command again REST A1,A5 ; restore registers JMP SCSI$ERROR ; go handle fatal error 99$: REST A1,A5 ; restore registers RTN ; back we go EXIT$: EXIT PAGE ;*********** ;* RQSNS * ;*********** ; ; Send a request sense command ; ; Output: D2 = sense key D0 = additional sense code ; RQSNS: SAVE A1,A5 ; preserve work registers QGETW A1 ; get a SCSI request q-block MOVB CDID(A4),RQ.ID(A1) ; move in the SCSI id MOVB #^H3,0+RQ.CDB(A1) ; set command to request sense MOVB #18.,4+RQ.CDB(A1) ; set transfer length MOVB #6,RQ.CDBSZ(A1) ; set command length QGETW A5 ; get a data request q-block MOV A5,RQ.DPLK(A1) ; link to the SCSI request MOV #0,TD.LNK(A5) ; ensure the link is clear MOV #18.,TD.SIZ(A5) ; set transfer size LEA A6,SENBUF(A4) ; index storage for sense data MOV A6,TD.BUF(A5) ; move into the data request CLEAR SENBUF(A4),40. ; ensure sense block is clean MOV SCZDSP,A6 ; index the SCSI dispatcher CALL @A6 ; go execute the command QRET A5 ; free up the data request block MOVB RQ.EXSTS(A1),D0 ; get the execution status QRET A1 ; free up the SCSI request block TSTB D0 ; execution OK? BEQ 10$ ; yes - REST A1,A5 ; restore work registers JMP EXECUTION$ERROR ; go handle fatal error 10$: MOVB SENBUF+2(A4),D2 ; get sense key AND #^H0F,D2 ; mask out all but bottom nibble MOVB SENBUF+^H0C(A4),D0 ; get additional sense code AND #^H0FF,D0 ; mask out all but bottom byte PUSH D1 CLR D1 MOVB SENBUF+13.(A4),D1 TYPE SENBUF+13= OCVT 0,OT$TRM!OT$TSP POP D1 REST A1,A5 ; restore work registers RTN ; all done PAGE ;********************* ;* EXECUTION$ERROR * ;********************* ; ; Come here when we get an un-expected dispatcher execution error ; EXECUTION$ERROR: CRLF TYPESP CLR D1 ; pre-clear MOVB D0,D1 ; get execution error code OCVT 0,OT$TRM ; display it CRLF ; tidy up EXIT ; back to AMOS ;**************** ;* SCSI$ERROR * ;**************** ; ; Come here when we get an un-expected SCSI sense error ; SCSI$ERROR: CRLF ;Check for either not ready or CD-DA and if so display appropriate message CMPB D2,#2 ; not ready? BNE 10$ ; no - TYPECR EXIT 10$: CMPB D2,#8. ; blank check (ie. audio CD)? BNE 20$ ; no - TYPECR EXIT 20$: TYPESP CLR D1 ; pre-clear MOVB D2,D1 ; get sense key OCVT 0,OT$TRM!OT$TSP TYPESP < additional sense=> MOVB D0,D1 ; get additional sense byte OCVT 0,OT$TRM CRLF EXIT PAGE ;***************** ;* DEFINITIONS * ;***************** ; ; Misc. definitions ; ;Comparision standard identifier COMPID: ASCII /CD001/ EVEN END