Jim Lawless' Blog


BSave and BLoad for the Commodore 64

Originally published on: Thu, 06 Aug 2009 01:15:42 +0000

I wrote this little subroutine package for the Commodore 64 in 2002. You can likely still find a cached Usenet post to comp.sys.cbm referring to it.

I thought that I would add in an open-source license header and would present it here.

The source code below is for two machine language library routines which can be called from BASIC. The first routine will save a section of the C64's memory to disk. The second will load a file from disk into a specific spot in memory. These functions are akin to Applesoft BASIC's BSAVE and BLOAD binary I/O commands.

I did not wedge the CHRGET routine to add any new command verbs to BASIC; one must use the SYS command to invoke each subroutine. A jump-table at the beginning of the module controls which of the two functions you'll execute. Address 49152 is the BSAVE routine. Address 49152+3 is the BLOAD routine.

Please note that the filename parameter must always be in a variable. I didn't have the routine that would parse a literal properly readily available ... and still don't remember how to do it off the top of my head. ;-)


; BSaVe and bLoaD extentsions for the Commodore 64
;
; License: MIT / X11
; Copyright (c) 2009 by James K. Lawless
; jimbo@radiks.net http://www.radiks.net/~jimbo
; http://www.mailsend-online.com
;
; Permission is hereby granted, free of charge, to any person
; obtaining a copy of this software and associated documentation
; files (the "Software"), to deal in the Software without
; restriction, including without limitation the rights to use,
; copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following
; conditions:
;
; The above copyright notice and this permission notice shall be
; included in all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
; OTHER DEALINGS IN THE SOFTWARE.
;
; To use in C64 BASIC:
; sys 49152,a$,start-addr,end-addr
; The above will save to file named in a$
; sys 49152+3,a$,start-addr
; The above will load a file named in a$
; to the specified location
;
; To save the default BASIC screen:
; a$="screen,s,w"
; sys 49152,a$,1024,1024+999
;
; To reload the default BASIC screen
; a$="screen,s,r"
; sys 49152+3,a$,1024

   *=$c000
; jump table for functions
   jmp save
   jmp load
flag .BYTE 00
save = *
   lda #$00
   sta flag
   jmp main
load = *
   lda #$01
   sta flag
   jmp main

main = *
   jsr $aefd ; skip comma
   jsr $b08b ; search for variable
   jsr $b185 ; find address
   sta $fb
   tya
   sta $fc
   lda #$00
   tay
   lda ($fb),y
   pha
   iny
   lda ($fb),y
   pha
   iny
   lda ($fb),y
   tay
   pla
   tax
   pla
   jsr $ffbd ; SETNAM
   lda #$02
   ldx #$08
   ldy #$00
   jsr $ffba ; SETLFS

   lda flag
   cmp #$00
   beq dosave
   jmp doload

dosave = *
   jsr $aefd ; skip comma
   jsr $ad8a ; eval expr
   jsr $b7f7 ; get uint in a,y
   sta $fc
   tya
   sta $fb

   jsr $aefd ; skip comma
   jsr $ad8a ; eval expr
   jsr $b7f7 ; get uint in a,y
   sta $fd
   tya
   tax
   ldy $fd
   lda #$fb

   jsr $ffd8 ; save ram
   rts

doload = *
   jsr $aefd ; skip comma
   jsr $ad8a ; eval expr
   jsr $b7f7 ; get uint in a,y
   sta $fd
   tya
   tax
   ldy $fd
   lda #$00
   jsr $ffd5 ; load ram
   rts

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless



Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks


Previous post: A Quine in Forth
Next post:A Lightweight Alternative to Windows Shortcuts


About Jim ...


Click **here**
to try out MailWrench;
a command-line SMTP /
SMTPS (Google Gmail)
mailer for Windows.


Follow me on Twitter

http://twitter.com/lawlessGuy


Recent Posts

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

A Review of Kevin Mitnick's Book Ghost in the Wires

Spellbound by Web Programming

Backlinks to my Blog Posts

Play MP3 Files with Python on Windows


Random Posts

Command-Line Image Format Conversion

Changing the C64 Text Color in C

Rhino JavaScript to EXE with launch4j

Getting the Windows Console Text Color

Learning Z-80 Assembly Language on the TRS-80

Obfuscated C

Obfuscated Ruby

Blog Posts by Category

COM Scripting in C by way of JavaScript

Jim Butterfield : The Commodore Guru


Full List of Posts

http://www.mailsend-online.com/bloglist.htm


Recent Posts from my Other Blog

Remembering Dr. San Guinary

Why Some Web Sites will go Dark on Jan 18th

SNL Superhero Skit

More Ruby Games

My Ruby Game Challenge Entry

Steal this Bookmarklet

Nerd Toys

Learn New Jargon, You Must

Spot the Wiebe

Tech Magazine Glory Days

Book Review : Paull Allen - Idea Man

A 90's Experiment in Online Systems - The U.S. West CommunityLink Service