Prince-of-Persia-Apple-II

A running-jumping-swordfighting game Jordan Mechner made on the Apple II from 1985-89
Log | Files | Refs | README | LICENSE

BLAST18.S (2627B)


      1 * draz/blast18
      2 org = $9200
      3  lst off
      4 *-------------------------------
      5 rw18 = $d000
      6 temp18buf = $4000
      7 endtempbuf = $5200
      8 
      9 floppyslot = 6
     10 floppydrive = 2
     11 
     12 slot = $fd
     13 ztrack = $fe
     14 
     15  dum $300
     16 TABLEND ds 1 ;hi byte of table end addr
     17 TABSTART ds 1 ;hi byte of table start addr
     18 TRACK ds 1 ;track #
     19  ds 1
     20 IDBYTE ds 1 ;18-sector ID byte
     21 OFFSET ds 1 ;sector offset (00-11)
     22 Len1 ds 1
     23 Len2 ds 1
     24  dend
     25 
     26  dum $f0
     27 obj_lo ds 1
     28 obj_hi ds 1
     29 dst_lo ds 1
     30 dst_hi ds 1
     31 len_lo ds 1
     32 len_hi ds 1
     33 flushflag ds 1
     34  dend
     35 *-------------------------------
     36  org org
     37 
     38 * In: TABSTART, TABLEND, TRACK, IDBYTE, OFFSET
     39 
     40 blast18 lda $c083
     41  lda $c083 ;enable RAM
     42 
     43 * set BbundID
     44 
     45  lda IDBYTE
     46  sta BbundID
     47 
     48  jsr rw18
     49  db 7
     50 BbundID db $a9
     51 
     52 * turn on drive and delay .5 seconds
     53 
     54  ldx #floppyslot*16
     55  stx slot
     56  ldx #floppydrive
     57  stx drive
     58 
     59  jsr rw18
     60  db 0
     61 drive db 2,5
     62 
     63 * seek first track
     64 
     65  lda TRACK
     66  sta track
     67 
     68  jsr rw18
     69  db 2,1
     70 track db 0
     71 
     72 * Write out data (1-2 tracks)
     73 
     74  ldy #0
     75  lda TABSTART
     76  sty obj_lo
     77  sta obj_hi
     78 
     79  lda OFFSET
     80  clc
     81  adc #>temp18buf
     82  sty dst_lo
     83  sta dst_hi
     84 
     85  lda #>endtempbuf
     86  sec
     87  sbc dst_hi
     88  sty len_lo
     89  sta len_hi ;# sectors left on this track (1-18)
     90 
     91  lda TABLEND
     92  sec
     93  sbc TABSTART
     94  clc
     95  adc #1 ;total # of sectors to write (1-36)
     96  cmp len_hi
     97  bcs :ok ;write to end of track
     98  sta len_hi ;write portion of track
     99 
    100 :ok lda len_hi
    101  sta Len1
    102  jsr wrtrack ;write 1st track
    103 
    104 * Write out 2nd track if necessary
    105 
    106  ldy #0
    107  sty Len2
    108  sty obj_lo
    109  lda TABSTART
    110  clc
    111  adc Len1
    112  cmp TABLEND
    113  beq :1
    114  bcs :done ;it fit on 1 track
    115 :1 sta obj_hi
    116 
    117  lda #>temp18buf ;start at beginning of 2nd track
    118  sty dst_lo
    119  sta dst_hi
    120 
    121  lda TABLEND
    122  sec
    123  sbc obj_hi
    124  clc
    125  adc #1 ;# of sectors left to write (1-18)
    126  sty len_lo
    127  sta len_hi
    128  sta Len2
    129 
    130  lda TRACK
    131  clc
    132  adc #1
    133  sta ztrack
    134  jsr wrtrack ;write out second track
    135 
    136 * turn off drive
    137 
    138 :done jsr rw18
    139  db 1
    140 
    141 * out of here!
    142 
    143  sta $c082
    144 
    145  rts
    146 *-------------------------------
    147 *
    148 * write 1 track
    149 *
    150 * In: obj, dst, len
    151 *  (trashes these vars)
    152 *
    153 *-------------------------------
    154 * read in current data
    155 
    156 wrtrack
    157  jsr rw18
    158  db $83,>temp18buf
    159 
    160 :loop ldy #0
    161  sty flushflag
    162  lda (obj_lo),y
    163  sta (dst_lo),y
    164 
    165  inc obj_lo
    166  bne :1
    167  inc obj_hi
    168 
    169 :1 inc dst_lo
    170  bne :2
    171  inc dst_hi
    172 
    173 :2 lda len_lo
    174  bne :3
    175  dec len_hi
    176 :3 dec len_lo
    177 
    178  lda dst_hi
    179  cmp #>temp18buf+$1200
    180  bne :4
    181  jmp flush?
    182 
    183 :4 lda len_lo
    184  ora len_hi
    185  bne :loop
    186 
    187  jmp flush?
    188 
    189 *-------------------------------
    190 flush? lda flushflag
    191  bne :nodata
    192 
    193  ldy #<temp18buf
    194  lda #>temp18buf
    195  sty dst_lo
    196  sta dst_hi
    197  jsr rw18
    198  db $c5,>temp18buf
    199 
    200  lda len_lo
    201  ora len_hi
    202  beq :nodata
    203 
    204  jsr rw18
    205  db $83,>temp18buf
    206 
    207  inc flushflag
    208 
    209 :nodata rts
    210 *-------------------------------
    211 eof
    212  sav blast18