User Tools

Site Tools


base:newshell

Newshell

;---------------------------------------
;Newshell
;
;(C) 2005 Nostalgia
;
;By Fungus / Nostalgia
;---------------------------------------

         *= $1000

cd       = $02

         lda $ba
         sta cd       ;save current
                      ;disk drive
         lda #$0b     ;setup
         sta $d011
         lda #$c1     ;no nmi
      ;  sta $0318
         lda #$80
      ;  sta $0291    ;no char shift
         lda #$17
         sta $d018    ;this set
         lda #$00
         sta $9d      ;st clear
         sta $d020
         sta $d021
         lda #$2f     ;i/o config
         sta $00      ;bit 4 = input
         lda $01
         and #$07     ;mem config
         ora #$20     ;motor off
         sta $01
         lda #$00
         sta $0289    ;no keys
         sta $0286

         lda #$93
         jsr $ffd2    ;clr screen

         ldx #$00     ;print msg 1
pm1      lda $1400,x
         sta $0400,x
         lda #$05
         sta $d800,x
         inx
         cpx #$a0
         bne pm1

         lda #$1b
         sta $d011

wplay    lda $01      ;wait for play
         and #$10
         bne wplay

         jsr lod      ;load header

         lda $01      ;motor off
         ora #$20
         sta $01

         ldx #$00
xl       lda loader1,x
         sta $04a0,x
         lda loader1+$0100,x
         sta $05a0,x
         lda loader1+$0200,x
         sta $06a0,x
         lda loader1+$0300,x
         sta $07a0,x
         inx
         bne xl

         jmp $04a0    ;begin real loader
lod
         lda #$01     ;open tape file
         tax
         tay
         jsr $ffba
         lda #$00
         jsr $ffbd
         lda #$00
         sta $c0
         sta $93
         jsr $f7d7    ;load header/file
         jmp $f84f

;---------------------------------------
;novaload tape routine

loader1  = *
         *= $04a0
         .offs loader1-*

savename = $0341

moreload jsr clrmem    ;clear memory
         jsr putindex
         jsr printload
         jsr printname

         sei
         lda #$04
         sta $b7
         jsr loader    ;loader
         lda $90
         beq loadok
         jmp loaderr

loadok   inc $a4
         bne nohi1
         inc $ad
nohi1    lda $a4       ;lo end
         sta $ae
         lda $ad       ;hi end
         sta $af
         lda #$01
         sta $ac
         lda #$08
         sta $ad
         jsr save
         jmp moreload


;---------------------------------------
;save routine

save
         lda #$00      ;save file
         sta $d020     ;border  = black

         jsr printsave

         lda #$01      ;open file for
         ldx cd        ;write
         ldy #$01
         jsr $ffba     ;setlfs
         lda #$10
         ldx #$41      ;$0340 16 chars
         ldy #$03
         jsr $ffbd     ;setname
         jsr $ffc0     ;open
         ldx #$01
         jsr $ffc9     ;chkout
         lda $ac       ;start addy low
         jsr $ffa8     ;send
         lda $ad       ;start addy high
         jsr $ffa8     ;send

         ldy #$00      ;save the file
saveb    sei
         inc $01
         lda ($ac),y
         dec $01
         jsr $ffa8
         inc $d020
         dec $d020

         inc $ac
         bne b1
         inc $ad
b1       lda $ad
         cmp $af
         bne saveb
         lda $ac
         cmp $ae
         bne saveb

         lda #$01
         jmp $ffc3     ;close the file

;---------------------------------------
;utility subroutines

loaderr
         lda #$02      ;print tape load
         sta $d020     ;error msg
         ldx #$17
perr1    lda et1,x
         and #$3f
         sta $0478,x
         lda #$01
         sta $d878,x
         dex
         bpl perr1
         jmp *         ;endless loop

printload
         ldx #$07      ;print loading
ll       lda lt,x      ;text
         and #$3f
         sta $0478,x
         lda #$05
         sta $d878,x
         dex
         bpl ll
         rts

printsave
         ldx #$07
dl       lda st,x      ;print save text
         and #$3f
         sta $0478,x
         lda #$05
         sta $d878,x
         dex
         bpl dl
         rts

printname
         ldx #$0f      ;print name
ln       lda savename,x
         and #$7f
         sta savename,x
         and #$3f
         sta $0480,x
         dex
         bpl ln
         rts

putindex
         lda fileidx
         inc fileidx
         pha
         lsr a
         lsr a
         lsr a
         lsr a
         jsr convert1
         sta savename+$0e
         pla
         and #$0f
         jsr convert1
         sta savename+$0f
         rts

convert1 ora #$30
         cmp #$3a
         bcc convert2
         adc #$06
convert2 rts

clrmem
         sei
         inc $01
         lda #$08
         sta clrit+$02
         lda #$00
         tax
clrit    sta $0800,x
         inx
         bne clrit
         inc clrit+$02
         bne clrit
         dec $01
         cli
         rts

;Transfer Messages

fileidx  .byte $00

et1      .text "Load Error!     "
         .text "        "
lt       .text "Loading "
st       .text "Saving  "

filename .text "                "
header   .byte $00,$00,$00,$00,$00,$00
base/newshell.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1