Writing the Wrongs – Loading and Saving Graphics Screens on the Apple II Series

Update:

In the June 2002 issue of Call-A.P.P.L.E. magazine we apparently fell asleep at the wheel and a program which I wrote for demonstration of a simple task of manipulating images between floppies.  The original program in the magazine is wrong and will not work no matter how hard one tries.  It helps, if we use the correct BASIC command.  And thus here, in the spirit of our old magazine column’s name, we try to Write the Wrongs for our members.

Original Article

Loading and Saving Graphics Screens on the Apple II Series

This is a new column which we are introducing this month to supplement our Apple II coverage. Each month, you will find hand tips and tricks in this column which are specifically for the Apple II series computers. While primarily focused on the beginning programmer, even the more advanced programmers may find a nify trick or two in this column which may be helpful.

This months tip concerns saving the graphics on Hi-Res screens. On the Apple II series computers, there are 2 Hi-Res pages. Hi-res Page 1 and Hi-Res Page 2. Hi-Res page 1 exists at address $2000, while Hi-Res Page 2 exists at address $4000. Each one of these pages has a length of $2000.

In order to save a Hi-Res page to floppy, you can use the BSAVE command which does a binary save. We have both the starting address for the pages in $2000 or $4000 depending on the page you want to save, and the length is always going to be $2000. We can now type the following statement to save page 1 to a file called PAGE1:
BSAVE PAGE1, A$2000 , L$2000

After the computer writes the file to the floppy disk, you should see the file named PAGE1 in the catalog of the floppy. The resulting binary file will be 34 sectors long. If you file is not this length, make sure that the length you specified is L$2000.
You could then reload the file from floppy with the following command sequence:

BLOAD PAGE1

This graphic would then load into the same page from which it was saved. However, if you wanted to load it into a different page, say for example, Hi-Res Page 2, you could specify the page start address as shown in the following command:

BLOAD PAGE1, A$4000

This command would load the PAGE1 graphic file into Hi-Res page 2 at address $4000. The same would be true if you saved the graphic from Hi-Res Page 2 and wanted to load it into Page 1. You would only need to specify the starting address as $2000 and it would load there.

If you don’t want to do this by hand, you can use the graphics manipulation program provided with this article. While not very sophisticated, this is the only code you need to load or save the graphics files. We have also included a few other handy items in this program such as a universal Applesoft error handler that will allow errors to be handled and recognized without ending the program.

Also take a look at POKE 34, 5. This command allows us to freeze the top 5 lines of the screen, which gives us the header that we require for our program. While 5 lines is really a bit much, it suffices to show the example. Normally you would not want to freeze much more than 3 lines. To reset this back to

 

Complete Source Listing (Applesoft)

0 ONERR GOTO 32000
10 REM ***************************
15 REM GRAPHICS MANIPULATOR
20 REM VERSION 1.1 BY BILL MARTENS
22 REM (C) 2002 by A.P.P.L.E.
25 REM ***************************
30 TEXT
35 REM ****************
40 REM SET DEFAULTS
45 REM ****************
50 D$=CHR$(4)
52 PRINT: PRINT CHR$(4)”COMMAND”
55 SL=6 : DR=1 : MD=0
60 REM ****************
64 REM MAIN MENU
66 REM ****************
70 HOME
80 GOSUB 850
130 PRINT
140 PRINT “(L)OAD GRAPHIC”
150 PRINT “(S)AVE GRAPHIC”
155 PRINT “(C)HANGE DRIVE SETTINGS
160 PRINT “(Q)UIT PROGRAM”
170 PRINT
180 PRINT “===========================================”
190 PRINT
200 PRINT ” CHOOSE OPTION >”
210 GET A$: IF A$=”” THEN 210
220 IF A$=”L” THEN 300
230 IF A$=”S” THEN 500
235 IF A$=”C” THEN 700
240 IF A$=”Q” THEN 32767
250 GOTO 210
260 REM ****************
270 REM LOAD GRAPHICS
280 REM ****************
300 HOME
302 MD=1
302 INPUT “NAME OF FILE TO LOAD (* = CATALOG)”;NA$
304 IF NA$=”” OR NA$=” “THEN 300
306 IF NA$=”*” THEN 600
310 PRINT “PAGE TO LOAD (1 / 2 / Q=EXIT) >”;
320 GET P$:IF P$=”” THEN 320
330 IF P$ = “1” THEN 390
340 IF P$ = “2” THEN 420
350 IF P$ = “Q” THEN 70
360 REM ****************
370 REM LOAD TO PAGE 1
380 REM ****************
382 POKE 16304,0
384 POKE 16302,0
386 POKE 16300,0
388 POKE 16297,0
390 PRINT D$;”BLOAD “;NA$;”,A$2000 ,S”;SL;”, D”;DR
400 GET A$
410 GOTO 70
420 REM ****************
425 REM LOAD TO PAGE 2
430 REM ****************
435 POKE 16304,0
440 POKE 16302,0
445 POKE 16299,0
447 POKE 16297,0
450 PRINT D$;”BLOAD “;NA$;”,A$4000 ,S”;SL;”, D”;DR
455 GET A$
460 GOTO 70
500 REM ****************
502 REM SAVE GRAPHICS
504 REM ****************
510 HOME
511 MD=2
512 INPUT “NAME OF FILE TO SAVE (* = CATALOG)”;NA$
514 IF NA$=”” OR NA$=” “THEN 300
516 IF NA$=”*” THEN 600
518 PRINT “PAGE TO SAVE (1 / 2 / Q=EXIT) >”;
520 GET P$:IF P$=”” THEN 520
522 IF P$ = “1” THEN 530
524 IF P$ = “2” THEN 570
526 IF P$ = “Q” THEN 70
528 GOTO 520
530 REM ****************
532 REM SAVE TO PAGE 1
534 REM ****************
536 PRINT D$;”BSAVE “;NA$;”,A$2000 , L$2000 ,S”;SL;”, D”;DR
537 PRINT “PRESS ANY KEY TO CONTINUE
538 GET A$
540 GOTO 70
570 REM ****************
575 REM SAVE TO PAGE 2
580 REM ****************
585 PRINT D$;”BSAVE “;NA$;”,A$4000, L$2000 ,S”;SL;”, D”;DR
586 PRINT “PRESS ANY KEY TO CONTINUE
587 GET A$
590 GOTO 70
600 REM *****************************
602 REM CATALOG THE CURRENT DISK
604 REM *****************************
610 HOME
615 PRINT D$;”CATALOG , S”;SL;”,D”;DR
620 PRINT
625 PRINT “PRESS ANY KEY TO CONTINUE
630 GET A$
635 IF MD=1 THEN 302
640 IF MD=2 THEN 502
700 REM ***************************
702 REM DRIVE AND SLOT SELECTOR
704 REM ***************************
710 HOME
720 PRINT “SLOT OF DISK DRIVE : “;
722 GET S$:IF S$=”” THEN 722
724 IF S$=”4″ THEN 722
726 ST=VAL(S$)
728 IF ST<3 OR ST>7 THEN 722
730 SL=ST
740 PRINT
742 PRINT “SELECT DRIVE (1/2)”
744 GET DT$:IF DT$=”” THEN 744
746 DT=VAL(DT$)
748 IF DT<1 OR DT>2 THEN 744
750 DR=DT
760 GOTO 70
840 REM ****************
842 REM SETUP HEADER
844 REM ****************
846 POKE 34,0
848 HOME
850 PRINT “A.P.P.L.E. PRESENTS : THE GRAPHICS MANIPULATOR”
854 PRINT ” VERSION 1.0 © 2002 BY A.P.P.L.E.”
858 PRINT “===========================================”
860 PRINT “CURRENT DRIVE : SLOT=”;SL;” DRIVE=”;DR
862 PRINT “===========================================”
864 POKE 34,5
866 RETURN
32000 REM ****************
32002 REM ERROR ROUTINE
32003 REM ****************
32005 CALL 37888
32010 ER=PEEK(222) : EL= PEEK(219)*256+PEEK(218)
32020 READ E1,E1$
32025 IF E1=999 THEN 32070
32030 IF E1=ER THEN 32050
32040 GOTO 32020
32050 PRINT E1$;” IN LINE “;EL
32055 PRINT “PRESS ANY KEY TO CONTINUE”;
32057 GET A$
32060 GOTO 70
32070 PRINT “UNKNOWN ERROR IN LINE “;EL
32072 RESTORE
32074 PRINT “PRESS ANY KEY TO CONTINUE”;
32076 GET A$
32080 GOTO 70
32090 REM ******************
32092 REM ERROR MESSAGES
32094 REM ******************
32100 DATA 0, NEXT WITHOUT FOR
32110 DATA 1, LANGUAGE NOT AVAILABLE
32120 DATA 2, RANGE ERROR
32130 DATA 3, RANGE ERROR
32140 DATA 4, DISK WRITE PROTECTED
32150 DATA 5, END OF DATA
32160 DATA 6, FILE NOT FOUND ON DISK
32170 DATA 7, VOLUME NUMBER DOESN’T MATCH
32180 DATA 8, INPUT / OUTPUT ERROR
32190 DATA 9, CURRENT DISK IS FULL
32200 DATA 10, FILE IS LOCKED
32210 DATA 11, SYNTAX ERROR
32220 DATA 12, NO BUFFERS AVAILABLE
32230 DATA 13, WRONG TYPE OF FILE
32240 DATA 14, PROGRAM WON’T FIT IN MEMORY
32250 DATA 15, NOT LEGAL COMMAND
32260 DATA 16, SYNTAX ERROR
32270 DATA 22, RETURN WITHOUT GOSUB
32280 DATA 42, OUT OF DATA
32290 DATA 53, ILLEGAL NUMBER
32300 DATA 69, OVERFLOW ERROR
32310 DATA 77, NO MORE MEMORY AVAILABLE
32320 DATA 90, UNDEFINED STATEMENT
32330 DATA 107, BAD SUBSCRIPT
32340 DATA 120, REDIMENSIONED ARRAY
32350 DATA 133, CAN’T DEVIDE BY ZERO (0)
32360 DATA 163, TYPE MISMATCH
32370 DATA 176, STRING TOO LONG
32380 DATA 191, FORMULA TOO LONG
32390 DATA 224, UNDEFINED FUNCTION
32400 DATA 254, BAD RESPONSE TTO AN INPUT
32410 DATA 255, CTRL-C HAS BEEN STRUCK
32766 DATA 999, XXXX
32767 END

Please follow and like us:

About the Author

billm

A.P.P.L.E. Chairman of the Board and Club president -- Bill worked for the founder, Val J. Golding and A.P.P.L.E. from 1981 to 1982. In 1999, he began archiving the materials which were distributed and sold by A.P.P.L.E.. That project led to the group that remained of A.P.P.L.E. Bill was involved in the financial industry in Tokyo and has over 20 major office infrastructure projects to his name. In March 2001, he retired to write books and to spend more time pursuing personal interests. As the president of the users group, Bill is in charge of distribution of Call-A.P.P.L.E. magazine as well as the organization of this web site. Bill currently resides in Tokyo, Japan and Shelton, Wa splitting time between the places.