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

BOOT.S (2877B)


      1 *  boot
      2 org = $800
      3  lst off
      4 *-------------------------------
      5 * $800 TS (0,0) boot sector
      6 
      7 SLOT = $2b
      8 sector = $50
      9 
     10 text = $fb2f
     11 home = $fc58
     12 vtab = $FB5B
     13 cout = $FDF0
     14 normal = $fe84
     15 pr0 = $fe93
     16 in0 = $fe89
     17 
     18 *-------------------------------
     19  org org
     20 
     21  hex 01
     22 
     23 entry lda #$60
     24  sta entry
     25 
     26  lda #$ff
     27  sta $4fb
     28  sta $3f3
     29  sta $3f4
     30  sta $c000 ;80store off
     31  sta $c002 ;RAMRD main
     32  sta $c004 ;RAMWRT main
     33  sta $c00c ;80col off
     34  sta $c00e ;Altcharset off
     35  sta $c081 ;write RAM, read ROM (2nd 4k bank)
     36  jsr text
     37  jsr home
     38  jsr normal
     39  jsr pr0
     40  jsr in0
     41 
     42  ldx SLOT
     43  txa
     44  lsr
     45  lsr
     46  lsr
     47  lsr
     48  ora #$c0
     49  sta :rdsect+2
     50  lda #$0f
     51  sta sector
     52 
     53 :0 ldy sector
     54  lda skewtbl,y
     55  sta $3d
     56  lda sectaddr,y
     57  beq :1
     58  sta $27
     59 :rdsect jsr $005c
     60 :1 dec sector
     61  bne :0
     62 
     63  lda SLOT
     64  jmp $900
     65 
     66 skewtbl hex 00,0d,0b,09,07,05,03,01
     67  hex 0e,0c,0a,08,06,04,02,0f
     68 
     69 sectaddr hex 00,09,00,00,00,00,00,00
     70  hex 30,31,32,33,34,00,00,00
     71 
     72 *===============================
     73 *  boot stage 2
     74 
     75 rw18 = $d000
     76 
     77 slot = $fd
     78 track = $fe
     79 lastrack = $ff
     80 
     81  dum $00
     82 
     83 dest ds 2
     84 source ds 2
     85 endsourc ds 2
     86 
     87  dend
     88 *-------------------------------
     89  ds $900-*
     90 
     91 stage2 stx slot
     92 
     93  jsr check128k ;check for 128K memory
     94 
     95  jsr moverw18 ;& move RW18 to D000
     96 
     97  lda #0
     98  sta lastrack
     99  sta $3f3
    100  sta $3f4 ;zero reset vector
    101 
    102  jsr rw18
    103  hex 07,a9 ;Bbund ID byte
    104 
    105  jsr rw18
    106  hex 00,01,00 ;drive 1 on
    107 
    108  jsr rw18 ;seek track 1
    109  hex 02,00,01
    110 
    111 * load & run stage 3 boot
    112 * from drive 1
    113 
    114  jsr rw18
    115  hex c3,ee
    116 
    117  jmp $ee00
    118 
    119 *-------------------------------------------------
    120 * Check for AUX memory routine
    121 
    122 CHECKER lda #$EE
    123  sta $C005
    124  sta $C003
    125  sta $0800
    126  lda $0C00
    127  cmp #$EE
    128  bne :0
    129  asl $0C00
    130  lda $0800
    131  cmp $0C00
    132  beq :1
    133 :0 clc
    134 :1 sta $C004
    135  sta $C002
    136  rts
    137 
    138 CHECKEND = *-CHECKER
    139 
    140 *-------------------------------------------------
    141 *
    142 * Check to make sure //c or //e
    143 * with 128k
    144 *
    145 *-------------------------------
    146 check128k
    147  sta $c081
    148 
    149  lda $FBB3 ;Apple // family ID byte
    150  cmp #6
    151  bne NOT128K ;Must be e/c/GS
    152 
    153  bit $C017
    154  bmi NOT128K
    155 
    156  ldx #CHECKEND
    157 :0 lda CHECKER,X
    158  sta $180,X
    159  dex
    160  bpl :0
    161 
    162  jsr $180
    163  bcs NOT128K
    164 
    165  rts
    166 
    167 *-------------------------------
    168 * Turn off drive and display message
    169 
    170 NOT128K ldx SLOT
    171  lda $C088,X
    172 
    173  jsr text
    174  jsr home
    175  lda #8
    176  jsr vtab
    177 
    178  ldy #0
    179 :0 lda MEMTEXT,Y
    180  beq *
    181  jsr cout
    182  cmp #$8D
    183  bne :1
    184  lda #4
    185  sta $24
    186 :1 iny
    187  bne :0
    188 
    189 MEMTEXT hex 8D
    190  asc "REQUIRES A //C OR //E WITH 128K"
    191  hex 00
    192 
    193 *-------------------------------
    194 * Move RW18
    195 * d0 < 30.40
    196 *-------------------------------
    197 moverw18
    198  bit $c08b
    199  bit $c08b ;rd/wrt RAM, 1st 4k bank
    200 
    201  lda #$d0
    202  ldx #$30
    203  ldy #$40
    204 
    205 * a < x.y
    206 * 20 < 40.60 means 2000 < 4000.5fffm
    207 * WARNING: If x >= y, routine will wipe out 64k
    208 
    209 movemem sta dest+1
    210  stx source+1
    211  sty endsourc+1
    212 
    213  ldy #0
    214  sty dest
    215  sty source
    216  sty endsourc
    217 
    218 :loop lda (source),y
    219  sta (dest),y
    220 
    221  iny
    222  bne :loop
    223 
    224  inc source+1
    225  inc dest+1
    226 
    227  lda source+1
    228  cmp endsourc+1
    229  bne :loop
    230 
    231  rts
    232 
    233 *-------------------------------
    234  sav boot