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

  1. ; get.asm
  2. ;---------------------------------------------------------
  3. ; CS-DOS Command: get filename,linenumber
  4. ;---------------------------------------------------------
  5.  
  6. z61         =   $0061               ; pointer into RAM0
  7. status      =   $0090               ; i/o status byte
  8. poker       =   $0016               ; line number
  9. txttab      =   $002d               ; start of text
  10. txttop      =   $1210               ; top of basic text
  11. max0        =   $1212               ; top of RAM for RAM0
  12. int08       =   $1708               ; open file
  13. int0d       =   $170d               ; print ds$
  14. int0e       =   $170e               ; terminate program
  15. int11       =   $1711               ; evaluate constant
  16. int3f       =   $173f               ; Open %x for burst read
  17. sw1         =   $1bfc               ; command line switch
  18. lnkprg      =   $4f4f               ; link program lines
  19. stop        =   $ffe1
  20.  
  21. star        =   $0b00               ; run on 40 column screen
  22.             .wor star               ; shell put us in bank15
  23.             *   = star
  24.  
  25.             jmp get
  26.             dw Date
  27.  
  28. get         ldx #1                  ; first parameter is filename
  29.             jsr int3f               ; open it for burst read (any filetype will do)
  30.             bcc get0                ; open went ok
  31.             lda #3                  ; Error, just quit
  32.             jmp int0e
  33.  
  34. get0        ldx #2                  ; line # is %2
  35.             jsr int11               ; int11 puts value of %x in poker
  36.             jsr fndlin              ; get start of line into z61
  37.             bcs ed33                ; Line number is very high...append
  38.             lda poker               ; line specified?
  39.             ora poker+1
  40.             php
  41.             ldy #2                  ; make it the current line number
  42.             lda (z61),y
  43.             sta poker
  44.             iny
  45.             lda (z61),y
  46.             sta poker+1
  47.             plp
  48.             bne ed33                ; line was given...use it
  49.             lda #<1000              ; else 1000 is 1st line
  50.             sta poker
  51.             lda #>1000
  52.             sta poker+1
  53. ed33        lda #0
  54.             sta $ff00
  55. ed3         sec                     ; don't input past end of available RAM
  56.             lda max0                ; top of RAM0
  57.             sbc z61                 ; minus pointer
  58.             lda max0+1
  59.             sbc z61+1
  60.             bcc edx                 ; past end...abort
  61.             cmp #2                  ; leave at least one page free
  62.             bcc edx
  63.             ldy #0                  ; stash line link
  64.             lda #1
  65.             jsr stsh
  66.             jsr stsh
  67.             lda poker
  68.             jsr stsh
  69.             lda poker+1
  70. ed0         jsr stsh
  71. ed6         jsr $1779               ; chrin or burst fetch
  72.             jsr cvt                 ; convert to petscii (maybe)
  73.             bit status
  74.             bmi eol
  75.             bvs eol
  76.             cmp #13
  77.             beq eeol
  78.             cmp #10                 ; skip line feeds
  79.             beq ed6
  80.             cpy #$9f                ; max of 159 characters/line
  81.             bcc ed0
  82.             jsr stsh
  83. eol         cmp #13
  84.             beq eeol
  85.             jsr stsh
  86. eeol        cpy #4
  87.             bne eeeol
  88.             lda #" "
  89.             jsr stsh
  90. eeeol       lda #0
  91.             jsr stsh
  92.             clc
  93.             tya
  94.             adc z61
  95.             sta z61
  96.             bcc ed7
  97.             inc z61+1
  98. ed7         clc
  99.             lda poker
  100.             adc #10
  101.             sta poker
  102.             bcc ed1
  103.             inc poker+1
  104. ed1         bit status
  105.             bvs edx
  106.             bmi edx
  107.             jsr stop
  108.             bne ed3
  109. edx         lda #0
  110.             tay
  111.             jsr stsh
  112.             jsr stsh
  113.             clc
  114.             lda z61
  115.             adc #2
  116.             sta txttop
  117.             lda z61+1
  118.             adc #0
  119.             sta txttop+1
  120. rn1010      jsr lnkprg              ; let BASIC establish new line links
  121.             lda #0
  122.             jmp int0e               ; close + quit
  123.  
  124. stsh        sta $ff01               ; put byte in bank0
  125.             pha                     ; save it
  126.             sta (z61),y             ; store it
  127.             iny
  128.             lda #0                  ; and back to bank 15
  129.             sta $ff00
  130.             pla
  131.             rts
  132.  
  133. ;---------------------------------------------------------------
  134. ; Picked this routine out of ROM...it runs faster in Common RAM
  135. ;---------------------------------------------------------------
  136.  
  137. fndlin      lda txttab
  138.             ldx txttab+1
  139.             sta $ff01
  140. fnd0        ldy #1
  141.             sta z61
  142.             stx z61+1
  143.             lda (z61),y
  144.             beq eop                 ; end of program
  145.             iny
  146.             iny
  147.             lda poker+1
  148.             cmp (z61),y
  149.             bcc fndx
  150.             beq fnd1
  151.             dey
  152.             bne fnd2
  153. fnd1        lda poker
  154.             dey
  155.             cmp (z61),y
  156.             bcc fndx
  157.             beq fndx
  158. fnd2        ldy #2
  159.             lda (z61),y
  160.             sta oldlin
  161.             iny
  162.             lda (z61),y
  163.             sta oldlin+1
  164.             dey
  165.             dey
  166.             lda (z61),y
  167.             tax
  168.             dey
  169.             lda (z61),y
  170.             bcs fnd0
  171. fndx        clc
  172.             rts
  173.  
  174. eop         ldy #0
  175.             lda (txttab),y
  176.             iny
  177.             ora (txttab),y
  178.             bne eop0
  179.             sta poker
  180.             sta poker+1
  181.             beq fndx
  182.  
  183. eop0        clc
  184.             lda oldlin
  185.             adc #10
  186.             sta poker
  187.             lda oldlin+1
  188.             adc #0
  189.             sta poker+1
  190.             sec
  191.             rts
  192.  
  193. ;---------------------------
  194. ; ascii conversion routines
  195. ;---------------------------
  196.  
  197. cvt         pha                     ; Check for /a switch
  198.             lda sw1
  199.             cmp #"a"
  200.             beq a2p
  201.             pla                     ; Not there, don't convert
  202.             rts
  203.  
  204. a2p         pla
  205.             cmp #"a"
  206.             bcc a2px
  207.             cmp #$5b
  208.             bcs a2p2
  209.             ora #$80
  210.             bne a2px
  211.  
  212. a2p2        cmp #$61
  213.             bcc a2px
  214.             cmp #$7b
  215.             bcs a2px
  216.             and #$df
  217. a2px        rts
  218.  
  219. oldlin      *=*+2
  220.  
  221.             .end
  222.