home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / mag_discs / volume_9 / issue_12 / crossley / prog_hcopy
Text File  |  1996-07-23  |  7KB  |  205 lines

  1. ;     > a.pscrn
  2. ;       
  3. ;       Assembly language program for screen printing
  4. ; 1 line per scan. pressing 'q' will stop the program  
  5.  
  6. .INCLUDE "^.A.SWINAMES"     ; converts swi names to numbers
  7. .INCLUDE "^.A.REGNAMES"     ; converts register names to numbers
  8. .INCLUDE "^.A.ADR"
  9. ;
  10.         .AREA A$$code
  11.         .ENTRY  main
  12. ;
  13. ;       memory assignments
  14. ;
  15. pname:   .ASCIZ "printer:"          ; file name
  16. .ALIGN
  17. ;
  18. thrshld: .BLKL  1
  19. handle:  .BLKL  1
  20. lwdth:   .BLKL  1                   ; pixels/line - 1
  21. scrnht:  .BLKL  1                   ; lines/screen - 1
  22. ;
  23. bwdth:   .BLKL  1
  24. code2:   .BYTE  2,27,64             ; resets printer:
  25. .ALIGN
  26. code3:   .BYTE  3,27,43,2           ; sets line spacing
  27. .ALIGN
  28. code6:   .BYTE  6,27,40,71,1,0,1    ; sets raster graphics
  29. .ALIGN
  30. code6x:  .BYTE  6,27,40,85,1,0,20   ;sets size of vert. unit
  31. .ALIGN
  32. code_6:  .BYTE  8,27,46,0,20,20,1,0,0   ;print raster graphics
  33. .ALIGN
  34. ;
  35. ;  screen data
  36. ;
  37. VDU_Input:    .LONG 149             ; screen start address code 
  38.               .LONG -1              ; end of list marker
  39. displaystart: .BLKL 1
  40. ;
  41. ;               
  42. ;
  43. ;       main is the entry point
  44. ;                                                          
  45. main::
  46. ;
  47.         ADR   R0,VDU_Input
  48.         ADR   R1,displaystart
  49.         SWI   OS_ReadVduVariables   
  50. ;
  51. ;     find screen size in pixels
  52. ;
  53.         mvn   a1, #0
  54.         mov   a2, #11
  55.         SWI OS_ReadModeVariable     ; get pixels/line-1
  56.         str   a3, lwdth
  57.         add   a3, a3, #1
  58.         mov   v1, a3
  59.         mvn   a1, #0
  60.         mov   a2, #12
  61.         SWI OS_ReadModeVariable     ; get no. of lines
  62.         str   a3, scrnht
  63. ;
  64. ; v2=line byte ctr, v3=pix ctr, v4=dsplstrt
  65. ; v5=pix. accumulator, v6=linectr, a3=0/1, 
  66. ;
  67.         ldr   v2, lwdth               ; get line width-1
  68.         add   v2, v2, #1              ; cnvt to line width
  69.         mov   a1, v2, lsr #8          ; divide by 256 (=nh)
  70.         strb   a1, code_6+8           ; store       
  71.         sub   a2, v2, a1, lsl #8      ; find remainder (=nl)
  72.         strb   a2, code_6+7           ; store
  73.         mov   v2, v2, lsr #3          ; lwdth/8, bytes per line
  74.         ldr   v4, displaystart        ; screen address in v4;
  75. ;
  76.         SWI OS_WriteS                 ; write instructions
  77. .ASCIZ  "Threshold hex value, <threshold->black, >0x80 inverts "
  78. .ALIGN
  79.         ADR     a1, thrshld          
  80.         add     a1, a1, #0x80000000  ; echo to screen
  81.         mov     a2, #0x2             ; 2 digits permitted
  82.         mov     a3, #0x30
  83.         mov     a4, #0x80
  84.         SWI OS_ReadLine              ; read value as a string
  85.         mov     a1, #0x10
  86.         ADR     a2, thrshld
  87.         swi   OS_ReadUnsigned        ; cnvt to number 
  88.         mov     v5, a3
  89.         str     v5, thrshld          ; store
  90. ;
  91. ; open printer and leave if it fails
  92. ;
  93.         mov  a1, #0x80
  94.         add  a1, a1, #3                ; open new file
  95.         ADR  a2, pname
  96.         swi  OS_Find
  97.         mov  v6, a1                    ; handle in v6 
  98.         cmp  a1, #0                    ; is it zero?
  99.         bne  cont2                     ; no, continue from cont2
  100.         swi  OS_WriteS                 ; if zero, error, send msg
  101. .ASCIZ  "Error opening printer \r\n"
  102. .ALIGN
  103.         b  ferror                      ; and leave
  104. cont2:
  105.         str  v6, handle                ; save handle
  106.  swi  OS_WriteS                        ; send message
  107. .ASCIZ  "Printer open\r\n"
  108. .ALIGN
  109.  
  110.  
  111.          mov   a1, #2
  112.          ldr   a2, handle
  113.          ADR   a3, code2
  114.          add   a3, a3, #1
  115.          ldrb  a4, code2               ; ESC @
  116.          swi OS_GBPB                   ; send reset code
  117. ;        
  118.          mov   a1, #2
  119.          ldr   a2, handle
  120.          ADR   a3, code6
  121.          add   a3, a3, #1
  122.          ldrb  a4, code6               ; ESC ( G 1 0 1
  123.          swi  OS_GBPB                  ; enter raster graphics
  124. ;
  125.          mov   a1, #2
  126.          ldr   a2, handle
  127.          ADR   a3, code6x
  128.          add   a3, a3, #1              
  129.          ldrb  a4, code6x              ; ESC ( U 10 20
  130.          swi  OS_GBPB                  ; set size of ver. unit
  131. ;
  132.          mov   a1, #2
  133.          ldr   a2, handle
  134.          ADR   a3, code3
  135.          add   a3, a3, #1
  136.          ldrb  a4, code3               ; ESC + 2
  137.          swi   OS_GBPB                 ; set line spacing
  138. ;   
  139.          ldr   v6, scrnht
  140. newline:
  141.          mov   a1, #2                  ; send before each line
  142.          ldr   a2, handle
  143.          ADR   a3, code_6
  144.          add   a3, a3, #1
  145.          ldrb  a4, code_6              ; ESC . 0 20 20 1 nl nh
  146.          swi   OS_GBPB                 ; printer now ready for data
  147.          ldr   v2, lwdth
  148.          add   v2, v2, #1
  149.          mov   v2, v2, lsr #3 
  150.          sub   v2, v2, #1              ; byte ctr initialised
  151. finline:
  152.          mov   v5, #0
  153.          mov   v3, #7                  ; initialise pix ctr
  154.          ldr   v1, thrshld
  155. finbyte:                               ; get 8 pixels and combine
  156.           mov   a3, #1
  157.           ldrb  a4, [v4],#1            ; get byte and inc address
  158.           cmp   v1, #0x80
  159.           eorge a3, a3, #1             ; >=&80, change a3 
  160.           cmp   a4, v1                 ; data comp. with threshold
  161.           eorge a3, a3, #1             ; >=, change a3
  162.           add   v5, a3, v5, lsl #1     ; old *2+new
  163.           subs  v3, v3, #1             ; dec. ctr
  164.           bge   finbyte                ; get more data if >=0
  165.           mov   a1, v5                 ; done byte
  166.           ldr   a2, handle
  167.           swi  OS_BPut                 ; done 8 pixels, send byte
  168.  
  169.           subs   v2, v2, #1            ; dec. ctr, set flags
  170.           bge   finline                ; get more data
  171.           mov   a1, #13                ; done line
  172.           ldr   a2, handle
  173.           swi  OS_BPut                 ; done line, send lf/cr
  174. ;
  175.           mov   a1, #145                           
  176.           mov   a2, #0
  177.           swi    OS_Byte               ; key pressed ?
  178.           bcc    kpres                 ; yes, goto kpres
  179.           subs   v6, v6, #1
  180.           bge   newline
  181. ;         b     stop
  182. kpres:
  183. swi OS_WriteS                          ; detect a key press
  184. .ASCIZ  "Key pressed "
  185. .ALIGN   
  186.          cmp    a3, #0x71              ; was the key 'q'?
  187.          beq    stop                   ; 'q' pressed, goto stop
  188.  
  189. ;
  190. ;
  191. stop:
  192. ;                                      
  193.          mov  a1, #0
  194.          ldr  a2, handle
  195.          swi  OS_Find                 ; mpt buffers, close file
  196.          b   no_close
  197. ferror:
  198.          SWI OS_WriteS
  199. .ASCIZ   "Error opening file\n"
  200. .ALIGN                         
  201. no_close:
  202. ;
  203.          mov   a1, #0
  204.          SWI OS_Exit
  205.