home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / libinc / demo / readboot.s65 < prev    next >
Text File  |  1984-11-21  |  2KB  |  88 lines

  1.       .include #system
  2.       .include #macros
  3.       .include #cio
  4.       .include #os
  5.       .include #16bit
  6.  
  7. maxsecs = 16
  8. :more  = @special + @s2 + @p1 + @p2 + @p3   ; len will be ignored
  9.  
  10. ;; This is more or less an example, not written for beauty or
  11. ;; anything. Maybe you can pick up some ideas about using STDIO
  12. ;; This little ditty was actually put to use, to get some gamedisks
  13. ;; working on the XL
  14.  
  15. main:
  16.       print       0,"SD boot sector reader -- 1991 Natürlich!"
  17.       print       0,"Input diskette in drive 1",0,:more  ; same IOCB chan.
  18.       print       0,"Press פדקרפמ to continue",0,:more   ; so we can use
  19.       getc        0,@special                             ; @special to save
  20.       print       0,"Reading boot sectors",0,:more       ; some bytes
  21.       
  22.       readsector  1,1,buffer        ; read first sector
  23.       bpl         :ok1
  24.       jmp         :failure  
  25. :ok1      
  26.       lda         buffer+1          ; get number of sectors to
  27.       bne         :cool
  28.       jmp         :invalid 
  29. :cool 
  30.       cmp         #maxsecs+1        ; can we read that many
  31.       bcc         :fits
  32.       jmp         :toomuch 
  33. :fits
  34.       sta         size+1
  35.       sbc         #0                ; minus one
  36.       beq         :fine
  37.       
  38.       tay
  39.       SETUP_SIO   1,SIOREAD,2,buffer+128
  40.       jsr         sd_secs
  41.       bpl         :fine
  42.       jmp         :failure
  43.       
  44. :fine
  45.       lsr.w       size
  46.       bput        0,prompt,filename-prompt,@p1+@p2+@p3
  47.       input       0,filename,buffer-filename,@p1+@p2+@p3+@special
  48.             
  49.       open        1,8,0,filename,@p1+@p2+@p3+@p4
  50.       bmi         :noopen
  51.       bput        1,buffer,size,@special+@p1+@p2
  52.       php
  53.       close       1,@special+@p1
  54.       plp
  55.       bpl         :ok
  56.       jsr         :diskfull
  57.       jmp         :fine
  58.         
  59. :ok
  60.       print       0,"Done"
  61.       rts
  62.  
  63. :failure:
  64.       print       0,"Couldn't read sectors"
  65.       rts
  66.       
  67. :noopen:
  68.       print       0,"Couldn't open output file"
  69.       rts
  70.       
  71. :diskfull:
  72.       print       0,"Disk full ? Retry with another..."
  73.       rts
  74.  
  75. :toomuch
  76.       print       0,"Too many sectors in that boot segment"
  77.       rts      
  78.  
  79. :invalid
  80.       print       0,"That bootsector is unusable"
  81.       rts
  82.       
  83. size:       .word 0
  84. prompt:     .byte "Output file name: "
  85. filename:   .ds   128
  86. buffer:     .ds   128*maxsecs
  87.  
  88.