home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / examples.arc / PUT.A < prev    next >
Text File  |  1989-12-01  |  7KB  |  162 lines

  1. ;put.asm
  2. ;============================================================
  3. ; user installable command:   put filename startline endline
  4. ;============================================================
  5.                                   
  6. z61         = $0061               
  7. int04       = $1704               
  8. int09       = $1709               
  9. int0e       = $170e               
  10. int11       = $1711               
  11. int0b       = $170b               
  12. int0d       = $170d               
  13. int13       = $1713               
  14. sw1         = $1bfc               
  15. chrout      = $ffd2               
  16. chkout      = $ffc9               
  17. clrchn      = $ffcc               
  18. poker       = $0016               
  19. fndlin      = $5064               
  20. stop        = $ffe1               
  21. primm       = $ff7d               
  22.                                   
  23. star        = $0b00               
  24.             .wor star             
  25.             * = star              
  26.  
  27.             jmp put
  28.             dw  Date
  29.                    
  30. put         lda #0
  31.             sta $ff00             
  32.             ldx #1                ; put only?
  33.             jsr int04             
  34.             bcc put00             
  35.             jsr primm             
  36.             .asc 13,"Syntax:  put[/a] filename start end",13,0
  37.             jmp int0e             
  38.                                   
  39. put00       ldx #3                ; get endline
  40.             jsr int11             ; returns value of %3 in .x lo .a hi
  41.             bcc put1              ; it was there, use it
  42.             lda #$ff              ; otherwise use $ffff
  43.             tax                   
  44. put1        stx endlin            
  45.             sta endlin+1          
  46.             ldx #2                
  47.             jsr int11             ; get start line
  48.             bcc put2              ; it was there...use it
  49.             lda #0                ; otherwise use zero
  50.             tax                   
  51. put2        stx poker             
  52.             sta poker+1           
  53.             jsr fndlin            ; find 1st line
  54.             ldx #1                ; first scratch it
  55.             jsr int13             
  56.             ldx #1                ; open %1 for write
  57.             lda #"s"              ; as a seq file
  58.             jsr int09             
  59.             bcc put0              ; open went fine
  60.             jsr int0d             ; print disk status
  61.             jmp int0e             ; and..abort
  62.                                   
  63. putxx       jmp putx              
  64.                                   
  65. put0        lda #0                ; bank 15
  66.             sta $ff00             
  67.             jsr chkout            ; setup for output
  68.             bcs putxx             ; disk error
  69. put3        ldy #0                
  70.             sta $ff01             ; get from bank0
  71.             lda (z61),y           ; check if all done  (link=0)
  72.             iny                   
  73.             ora (z61),y           
  74.             beq putxx             ; end of program...quit
  75.             jsr putlin            ; send line to output
  76.             ldy #3                ; check if line# in range
  77.             lda (z61),y           ; 1st check high byte
  78.             cmp endlin+1          
  79.             bcc put4              ; less...next line
  80.             beq put5              ; equal..check low byte too
  81.             bcs putxx             ; greater...quit
  82.                                   
  83. put5        dey                   ; check low byte
  84.             lda (z61),y           
  85.             cmp endlin            
  86.             bcc put4              ; less..next line
  87.             bcs putxx             ; past end...done
  88.                                   
  89. put4        ldy #0                ; next line
  90.             lda (z61),y           ; get address of next line
  91.             pha                   
  92.             iny                   
  93.             lda (z61),y           
  94.             sta z61+1             
  95.             pla                   
  96.             sta z61               
  97.             jmp put3              ; and repeat
  98.                                   
  99. putlin      ldy #4                ; offset to data
  100. put7        sta $ff01             
  101.             lda (z61),y           ; get from bank0
  102.             iny                   
  103.             ldx #0                
  104.             stx $ff00             ; bank 15 for chrout
  105.             cmp #0                ; end of line?
  106.             beq put6              ; yes..do a cr
  107.             jsr cvt               
  108.             jsr chrout            ; otherwise spit it out
  109.             bcs putx              ; error...abort
  110.             bcc put7              ; ok..next char
  111.                                   
  112. put6        lda #13               ; done line..cr and return
  113.             jsr chrout            
  114.             lda sw1               ; ascii convert?
  115.             cmp #"a"              ; ascii convert?
  116.             bne put66             
  117.             lda #10               ; ok. add line feed
  118.             jsr chrout            
  119. put66       jsr stop              
  120.             beq putxy             
  121.             sta $ff01             ; and reset bank0 for main routine
  122.             rts                   
  123.                                   
  124. putxy       pla                   
  125.             pla                   
  126. putx        lda #0                
  127.             sta $ff00             
  128.             jsr clrchn            
  129.             jsr int0b             ; check ds$ and abort if error
  130. puty        jmp int0e             ; close all files and back to BASIC
  131.                                   
  132. endlin      .wor 0                
  133.  
  134.  
  135. ;-------------------------------------------
  136. ; Convert PETSCII to ASCII if /a is present
  137. ;-------------------------------------------
  138.                                   
  139. cvt         pha                   
  140.             lda sw1               
  141.             cmp #"a"              
  142.             beq p2a               
  143.             pla                   
  144.             rts                   
  145.                                   
  146. p2a         pla                   
  147.             cmp #"a"
  148.             bcc p2ax              
  149.             cmp #$5b              
  150.             bcs p2a2              
  151.             ora #$20              
  152.             bne p2ax              
  153.                                   
  154. p2a2        cmp #$c1              
  155.             bcc p2ax              
  156.             cmp #$db              
  157.             bcs p2ax              
  158.             and #$7f              
  159. p2ax        rts                   
  160.                                   
  161.             .end                  
  162.