home *** CD-ROM | disk | FTP | other *** search
-
- ; ***************************************************
- ; **** ****
- ; **** OPRINT V1.0 ****
- ; **** ****
- ; **** Func: Prints any file to the PRT: device ****
- ; **** ****
- ; **** Written with AsmOne V1.0 ****
- ; **** ****
- ; **** By: Orlando Budelacci ****
- ; **** Birmannsgasse 34 ****
- ; **** CH-4055 Basle ****
- ; **** Switzerland ****
- ; **** ****
- ; **** Published in Zine issue #8 ****
- ; **** ****
- ; **** by BRAINSTORM! ****
- ; **** ****
- ; **** ****
- ; **** As always: 100% pc-relative ****
- ; **** (like every program should be!)****
- ; **** ****
- ; **** Note: Don't start from the Assembler! ****
- ; **** ****
- ; **** Note2: Program breaks after a few seconds ****
- ; **** if no printer is connected. By the ****
- ; **** way, if anyone knows how to check ****
- ; **** fast, if there is a printer ****
- ; **** connected, please contact me! ****
- ; **** BUT no hardware access routines! ****
- ; **** ****
- ; ***************************************************
-
- ;Exec
- AllocMem = -198
- Freemem = -210
- Findtask = -294
- AllocSignal = -330
- AddPort = -354
- RemPort = -360
- OpenLib = -408
- CloseLib = -414
- OpenDev = -444
- CloseDev = -450
- Doio = -456
-
- ;Dos
- Open = -30
- Close = -36
- Read = -42
- Write = -48
- Output = -60
- Examine = -102
- IoErr = -132
- Lock = -84
-
- ;Mem-Types
- Public = $1
- Clear = $10000
- Chip = $2
-
- SysBase: macro
- move.l 4.w,a6
- endm
-
- start:
-
- ; -------------------------------------
- ; ---- PARAMETERS ----
- ; -------------------------------------
-
- cmp.b #1,d0
- bne.s parameter
- lea parflag(pc),a5
- move.b #1,(a5)
- bra.s open_dos
-
- parameter:
-
- Filename_search:
- movem.l d0/a0,-(sp) ;save parameters given from
- ;system
-
- ; -------------------------------------
- ; ---- ALLOCMEM FOR FILENAME BUFFER ---
- ; -------------------------------------
-
- SysBase
- move.l #255,d0 ;amount of memory
- move.l #Clear+Public,d1
- jsr AllocMem(a6)
- lea filebuffer(pc),a2
- move.l d0,(a2)
-
- movem.l (sp)+,d0/a0
- lea filebuffer(pc),a2
- tst.l (a2)
- beq.L error
-
- ; -------------------------------------
- ; ---- COPY FILENAME IN BUFFER ----
- ; -------------------------------------
-
- subq.l #2,d0
- move.l filebuffer(pc),a3
- copyname:
- move.b (a0)+,(a3)+
- dbf d0,copyname
-
- ; -------------------------------------
- ; ---- OPEN DOS LIBRARY ----
- ; -------------------------------------
-
- open_dos:
- SysBase
- lea dosname(pc),a1
- jsr -408(a6) ;OpenLib
- lea dosbase(pc),a3
- move.l d0,(a3)
- beq.L error
-
- ; -------------------------------------
- ; ---- GET OUTPUT HANDLE ----
- ; -------------------------------------
-
- get_output:
- move.l d0,a6
- jsr OutPut(a6)
- lea windowhandle(pc),a3
- move.l d0,(a3)
- beq.L error
-
- ; *** Put text in window ***
- ; *** if no filename was specified at start of program then ***
- ; *** print out 'how to use' text ***
-
- put_text:
- lea parflag(pc),a3
- tst.b (a3)
- beq.s file_name_found
- lea info_text(pc),a1
- bsr.L print
- bra.L close_dos_lib
-
- file_name_found:
- lea text(pc),a1
- bsr.L print
-
- ; -------------------------------------
- ; ---- OPEN FILE ----
- ; -------------------------------------
-
- Open_file:
- move.l filebuffer(pc),d1
- move.l #1005,d2
- jsr -30(a6) ;OpenFile
- lea handle(pc),a2
- move.l d0,(a2)
- beq.L error
-
- ; -------------------------------------
- ; ---- ALLOCMEM INFOBLOCK ----
- ; -------------------------------------
-
- Allocmem_Infoblock:
- SysBase
- move.l #260,d0
- move.l #Clear+Chip,d1
- jsr AllocMem(a6)
- lea infoblock(pc),a2
- move.l d0,(a2)
- beq.L error
-
- ; -------------------------------------
- ; ---- CREAT FILE LOCK ----
- ; -------------------------------------
-
- Create_Lock:
- move.l dosbase(pc),a6
- move.l filebuffer(pc),d1
- moveq #-2,d2 ;modus = read
- jsr Lock(a6)
- lea locksave(pc),a2
- move.l d0,(a2)
- beq.L error
-
- ; -------------------------------------
- ; ---- EXAMINE ----
- ; -------------------------------------
-
- X_amine:
- move.l locksave(pc),d1
- move.l infoblock(pc),d2
- jsr Examine(a6)
-
- ; -------------------------------------
- ; ---- UNLOCK ----
- ; -------------------------------------
-
- Un_lock:
- move.l locksave(pc),d1
- jsr -90(a6)
-
- ; -------------------------------------
- ; ---- GET LENGTH OF FILE ----
- ; -------------------------------------
-
- Get_Length:
- move.l infoblock(pc),a2
- move.l 124(a2),d0 ;at offset 124 from the
- lea length(pc),a2 ;start of infoblock
- move.l d0,(a2) ;is the length of the program
-
- ; -------------------------------------
- ; ---- ALLOCATE MEMORY FOR FILE ----
- ; -------------------------------------
-
- Alloc_file_mem:
- SysBase
- moveq #Public,d1
- jsr AllocMem(a6) ;allocmem
- lea startaddr(pc),a0
- move.l d0,(a0)
- beq.L alloc_error
-
- ; -------------------------------------
- ; ---- LOAD THE FILE ----
- ; -------------------------------------
-
- Read_file:
- move.l dosbase(pc),a6
- move.l handle(pc),d1
- move.l startaddr(pc),d2 ;start of memory block
- move.l length(pc),d3 ;length of file to load
- jsr Read(a6) ;ReadFile
-
- ; -------------------------------------
- ; ---- CLOSE THE FILE ----
- ; -------------------------------------
-
- Close_file:
- move.l handle(pc),d1
- jsr Close(a6) ;Close File
-
- lea file_loaded(pc),a1
- bsr.L print
-
-
- ; -------------------------------------
- ; ---- PRINT ROUTINE ----
- ; -------------------------------------
-
- OOpen_prt:
- move.l dosbase(pc),a6
- lea Oprtname(pc),a1
- move.l a1,d1
- move.l #1006,d2 ;modus = write new
- jsr Open(a6)
- lea Oprthandle(pc),a2
- move.l d0,(a2)
- bne.s Owrite
-
- ;* ! *
-
- lea printer_error(pc),a1
- bsr.L print
- bra.s end_printer
-
- OWrite:
- lea printing_text(pc),a1
- bsr.L print
-
- move.l dosbase(pc),a6
- move.l Oprthandle(pc),d1 ;Datei-Identifikation
- move.l startaddr(pc),d2 ;zeiger auf Daten-Puffer
- ;alloc-mem range
- move.l length(pc),d3 ;laenge in bytes
- jsr Write(a6) ;Printen!!!
-
- OClose_prt:
- move.l dosbase(pc),a6
- move.l Oprthandle(pc),d1
- jsr Close(a6)
-
- ; -------------------------------------
- ; ---- PRINT 'FINISH' MESSAGE ----
- ; -------------------------------------
-
- end_really:
- lea end_text(pc),a1
- bsr.S print
-
- End_printer:
-
- closeend:
- SysBase
- move.l startaddr(pc),a1
- move.l length(pc),d0
- jsr FreeMem(a6)
-
- move.l infoblock(pc),a1
- move.l #260,d0
- jsr FreeMem(a6)
-
- ; -------------------------------------
- ; ---- CLOSE DOS LIBRARY? ----
- ; -------------------------------------
-
- Close_dos_lib:
- SysBase
- lea filebuffer(pc),a2
- tst.l (a2)
- beq.s closedoslib
-
- ; -------------------------------------
- ; ---- FREE FILE BUFFER ----
- ; -------------------------------------
-
- free: move.l filebuffer(pc),a1
- moveq #0,d0
- add.w #255,d0
- jsr FreeMem(a6)
-
- ; -------------------------------------
- ; ---- CLOSE DOS LIBRARY ----
- ; -------------------------------------
-
- closedoslib:
- move.l dosbase(pc),a1
- jsr CloseLib(a6) ;CloseLib
-
- Exit: moveq #0,d0
- rts
-
-
- ; -------------------------------------
- ; ---- FILE ERRORS ----
- ; -------------------------------------
-
- error:
- move.l dosbase(pc),a6
- jsr IoErr(a6)
- cmp.l #205,d0
- bne.S msg2
- lea filenotfound(pc),a1
- bsr.S print
-
- msg2:
- moveq #103,d7
- cmp.l d7,d0
- bne.S msg3
- bra.s alloc_error
-
- msg3:
- moveq #0,d0
- bra.s close_dos_lib
-
-
- ; -------------------------------------
- ; ---- NOT ENOUGH MEMORY ERROR ----
- ; -------------------------------------
-
- alloc_error:
- lea memoryerror(pc),a1
- bsr.S print
- bra.s closeend
-
- ; -------------------------------------
- ; ---- PRINT TEXT ROUTINE ----
- ; -------------------------------------
-
- ; * Prints any ascii text in the current window *
- ; * Dosbase must be in label >>> dosbase <<< *
- ; * Pointer to text must be in >>> a1 <<< *
- ; * Output handle must be stored in >>> windowhandle <<<< *
- ; * all registers saved and written back *
-
- print:
- movem.l d0-d3/a1/a6,-(sp)
- move.l a1,d2 ;pointer to text
- moveq #0,d3 ;counter for chars
-
- endsearch: ;end of text=$00
- tst.b (a1)+
- beq.s EndFound
- addq.l #1,d3
- bra.s endsearch
-
- Endfound:
- move.l windowhandle(pc),d1
- move.l dosbase(pc),a6
- jsr Write(a6)
- movem.l (sp)+,d0-d3/a1/a6
- rts
-
- ; -------------------------------------
- ; ---- ASCII MESSAGES ----
- ; -------------------------------------
-
- text:
- dc.b $a
- dc.b $9b,'1;33;40m'
- dc.b 'OPrint V1.01',$a
- dc.b $9b,'0;31;40m'
- dc.b 'By Orlando Budelacci, December 1990, Public domain.',$a,0
- textend:
- info_text:
- dc.b $9b,'1;33;40m'
- dc.b 'OPrint V1.01',$a
- dc.b $9b,'0;31;40m'
- dc.b 'By Orlando Budelacci, December 1990, Public domain.',$a
- dc.b 'Prints any file to the PRT: device',$a,$a
- dc.b 'The source of this program was published in '
- dc.b $9b,'0;33;40m'
- dc.b 'ZINE #8 by BRAINSTORM.',$a
- dc.b $9b,'0;31;40m',$a
- dc.b 'Usage: OPrint [filename]',$a,$a
- dc.b 'By:',$a
- dc.b ' Orlando Budelacci',$a
- dc.b ' Birmannsgasse 34',$a
- dc.b ' CH-4055 Basle',$a,$a
- dc.b 0
-
- printer_error:
- dc.b 'Printer-trouble!!!',$a,$a
- dc.b 'Make sure that the following files are on the disk:',$a
- dc.b 'devs/printer.device',$a
- dc.b 'devs/parallel.device',$a
- dc.b 'devs/printers/[generic]',$a
- dc.b 'devs/system-configuration',$a
- dc.b 'l/port-handler',$a,$a
- dc.b $9b,$20,$70 ;visible cursor
- dc.b 0
-
- file_loaded:
- dc.b $9b,$30,$20,$70 ;invisible cursor
- dc.b 'File loaded...',$a
- dc.b 'Trying to set up devices and handler...',0
-
- printing_text:
- dc.b 'Ok! Devices and handler loaded.',$a,$a
- dc.b 'PRINTING... be patient.',$a,0
-
- end_text:
- dc.b 'Finished!',$a,$a
- dc.b $9b,$20,$70 ;visible cursor
-
- dc.b 0
-
- dosname: dc.b 'dos.library',0
- even
- filenotfound: dc.b 'File not found!',$a,$a,0
- memoryerror: dc.b 'Not enough memory!',$a,$a,0
- even
-
-
- ; -------------------------------------
- ; ---- HANDLES, POINTERS ----
- ; -------------------------------------
-
- filebuffer: dc.l 0
- Handle: dc.l 0
- Dosbase: dc.l 0
- Windowhandle: dc.l 0
- Locksave: dc.l 0
- length: dc.l 0
- startaddr: dc.l 0
- infoblock: dc.l 0
- Oprtname: dc.b 'PRT:',0
- parflag: dc.b 0
- even
- Oprthandle: dc.l 0
-