VolksForth

Atari8bit-sio
Login

Atari SIO

Requires: 6502 Assembler

\ Atari SIO Routine
\needs code INCLUDE" D1:TAS65.FS"
CR
.( loading Atari SIO ) CR

$80 CONSTANT B/SEC 
  8 CONSTANT SEC/BLK    
VARIABLE DRV        2 DRV     !

\ Double Density
: DD $100 ['] B/SEC   2+ !
        4 ['] SEC/BLK 2+ ! ;
\ Single Density 
: SD $80  ['] B/SEC   2+ !
       8  ['] SEC/BLK 2+ ! ; 

\ SIO CMNDS:
\ $50 Write
\ $52 Read

CODE SIO ( buf sec iodir cnmd -- ior )
  4    # LDA \ # of stack val   
  SETUP  JSR \ get stack values 
  N      LDA \ SIO Command 
  $302   STA \ DCMND 
  N 2+   LDA \ IO Direction W=80 R=40
  $303   STA \ DSTATS
  $31  # LDA \ Disk Drive 
  $300   STA \ DDEVIC
  DRV    LDA \ Drive Number
  $301   STA \ DUNIT
  &7     LDA \ Timeout
  $306   STA \ DTIMLO
  N 4 +  LDA \ Sector count low
  $30A   STA \ DAUX1
  N 5 +  LDA \ Sector count high
  $30B   STA \ DAUX2
  N 6 +  LDA \ buffer low
  $304   STA \ DBUFLO
  N 7 +  LDA \ buffer high
  $305   STA \ DBUFHI
' B/SEC 2+  LDA \ Bytes per sector
  $308   STA \ DBYTLO
' B/SEC 3 + LDA \ 
  $309   STA \ DBYTHI
LABEL SIOV  
  $E459  JSR \ SIOV
  $303   LDA \ DSTATS
  PUSH0A JMP \ EXIT
  END-CODE

: BLOCK@ ( addr blk -- ior )
  SEC/BLK * DUP SEC/BLK + SWAP DO
   DUP I $40 $52 SIO 
   1- ?DUP IF 1+ ENDLOOP EXIT THEN  
   B/SEC +
  LOOP DROP FALSE ;

: BLOCK! ( addr blk -- ior )
  SEC/BLK * DUP SEC/BLK + SWAP DO
   DUP I $80 $50 SIO 
   1- ?DUP IF 1+ ENDLOOP EXIT THEN
   B/SEC +
  LOOP DROP FALSE ;  

.( SIO loaded ) CR