home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1996
/
ARCHIVE_96.iso
/
discs
/
mag_discs
/
volume_9
/
issue_12
/
crossley
/
prog_hcopy
Wrap
Text File
|
1996-07-23
|
7KB
|
205 lines
; > a.pscrn
;
; Assembly language program for screen printing
; 1 line per scan. pressing 'q' will stop the program
.INCLUDE "^.A.SWINAMES" ; converts swi names to numbers
.INCLUDE "^.A.REGNAMES" ; converts register names to numbers
.INCLUDE "^.A.ADR"
;
.AREA A$$code
.ENTRY main
;
; memory assignments
;
pname: .ASCIZ "printer:" ; file name
.ALIGN
;
thrshld: .BLKL 1
handle: .BLKL 1
lwdth: .BLKL 1 ; pixels/line - 1
scrnht: .BLKL 1 ; lines/screen - 1
;
bwdth: .BLKL 1
code2: .BYTE 2,27,64 ; resets printer:
.ALIGN
code3: .BYTE 3,27,43,2 ; sets line spacing
.ALIGN
code6: .BYTE 6,27,40,71,1,0,1 ; sets raster graphics
.ALIGN
code6x: .BYTE 6,27,40,85,1,0,20 ;sets size of vert. unit
.ALIGN
code_6: .BYTE 8,27,46,0,20,20,1,0,0 ;print raster graphics
.ALIGN
;
; screen data
;
VDU_Input: .LONG 149 ; screen start address code
.LONG -1 ; end of list marker
displaystart: .BLKL 1
;
;
;
; main is the entry point
;
main::
;
ADR R0,VDU_Input
ADR R1,displaystart
SWI OS_ReadVduVariables
;
; find screen size in pixels
;
mvn a1, #0
mov a2, #11
SWI OS_ReadModeVariable ; get pixels/line-1
str a3, lwdth
add a3, a3, #1
mov v1, a3
mvn a1, #0
mov a2, #12
SWI OS_ReadModeVariable ; get no. of lines
str a3, scrnht
;
; v2=line byte ctr, v3=pix ctr, v4=dsplstrt
; v5=pix. accumulator, v6=linectr, a3=0/1,
;
ldr v2, lwdth ; get line width-1
add v2, v2, #1 ; cnvt to line width
mov a1, v2, lsr #8 ; divide by 256 (=nh)
strb a1, code_6+8 ; store
sub a2, v2, a1, lsl #8 ; find remainder (=nl)
strb a2, code_6+7 ; store
mov v2, v2, lsr #3 ; lwdth/8, bytes per line
ldr v4, displaystart ; screen address in v4;
;
SWI OS_WriteS ; write instructions
.ASCIZ "Threshold hex value, <threshold->black, >0x80 inverts "
.ALIGN
ADR a1, thrshld
add a1, a1, #0x80000000 ; echo to screen
mov a2, #0x2 ; 2 digits permitted
mov a3, #0x30
mov a4, #0x80
SWI OS_ReadLine ; read value as a string
mov a1, #0x10
ADR a2, thrshld
swi OS_ReadUnsigned ; cnvt to number
mov v5, a3
str v5, thrshld ; store
;
; open printer and leave if it fails
;
mov a1, #0x80
add a1, a1, #3 ; open new file
ADR a2, pname
swi OS_Find
mov v6, a1 ; handle in v6
cmp a1, #0 ; is it zero?
bne cont2 ; no, continue from cont2
swi OS_WriteS ; if zero, error, send msg
.ASCIZ "Error opening printer \r\n"
.ALIGN
b ferror ; and leave
cont2:
str v6, handle ; save handle
swi OS_WriteS ; send message
.ASCIZ "Printer open\r\n"
.ALIGN
mov a1, #2
ldr a2, handle
ADR a3, code2
add a3, a3, #1
ldrb a4, code2 ; ESC @
swi OS_GBPB ; send reset code
;
mov a1, #2
ldr a2, handle
ADR a3, code6
add a3, a3, #1
ldrb a4, code6 ; ESC ( G 1 0 1
swi OS_GBPB ; enter raster graphics
;
mov a1, #2
ldr a2, handle
ADR a3, code6x
add a3, a3, #1
ldrb a4, code6x ; ESC ( U 10 20
swi OS_GBPB ; set size of ver. unit
;
mov a1, #2
ldr a2, handle
ADR a3, code3
add a3, a3, #1
ldrb a4, code3 ; ESC + 2
swi OS_GBPB ; set line spacing
;
ldr v6, scrnht
newline:
mov a1, #2 ; send before each line
ldr a2, handle
ADR a3, code_6
add a3, a3, #1
ldrb a4, code_6 ; ESC . 0 20 20 1 nl nh
swi OS_GBPB ; printer now ready for data
ldr v2, lwdth
add v2, v2, #1
mov v2, v2, lsr #3
sub v2, v2, #1 ; byte ctr initialised
finline:
mov v5, #0
mov v3, #7 ; initialise pix ctr
ldr v1, thrshld
finbyte: ; get 8 pixels and combine
mov a3, #1
ldrb a4, [v4],#1 ; get byte and inc address
cmp v1, #0x80
eorge a3, a3, #1 ; >=&80, change a3
cmp a4, v1 ; data comp. with threshold
eorge a3, a3, #1 ; >=, change a3
add v5, a3, v5, lsl #1 ; old *2+new
subs v3, v3, #1 ; dec. ctr
bge finbyte ; get more data if >=0
mov a1, v5 ; done byte
ldr a2, handle
swi OS_BPut ; done 8 pixels, send byte
subs v2, v2, #1 ; dec. ctr, set flags
bge finline ; get more data
mov a1, #13 ; done line
ldr a2, handle
swi OS_BPut ; done line, send lf/cr
;
mov a1, #145
mov a2, #0
swi OS_Byte ; key pressed ?
bcc kpres ; yes, goto kpres
subs v6, v6, #1
bge newline
; b stop
kpres:
swi OS_WriteS ; detect a key press
.ASCIZ "Key pressed "
.ALIGN
cmp a3, #0x71 ; was the key 'q'?
beq stop ; 'q' pressed, goto stop
;
;
stop:
;
mov a1, #0
ldr a2, handle
swi OS_Find ; mpt buffers, close file
b no_close
ferror:
SWI OS_WriteS
.ASCIZ "Error opening file\n"
.ALIGN
no_close:
;
mov a1, #0
SWI OS_Exit