Mode Mixer

Type
Utility
Category
Mixed-mode display list designer
Author
Karl E. Wiegers
Published in
Antic, May 1985 (Vol. 4, No. 1)
Year
1985
Language
Atari BASIC
Requirements
32K RAM (more for large displays), Atari BASIC, disk drive
Mode Mixer main menu: large MODE MIXER title and six numbered options, Create, Change, See, Save, Load and Done

About the program

ANTIC can show 14 different graphics modes. Atari BASIC gives you nine of them on a 400/800 and more on an XL, but only one per screen apart from the text window. Mixing modes, such as a band of big title text over a hi-res picture over a few lines of normal text, means writing your own display list. Karl E. Wiegers' Mode Mixer from Antic's May 1985 issue takes care of the arithmetic. You describe the screen one band ("segment") at a time, and the program builds the display list, shows it, and writes a BASIC program that sets it up for you.

Typing it in

The menus use inverse-video words: {inv} … {/inv} means press the Atari (inverse) key before and after. Everything else is plain text. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program. Wiegers advised saving a couple of backup copies before you RUN it.

How to use it

Press a number at the menu (RETURN is not needed):

  1. Create a new display. For each segment, enter the ANTIC mode number (2–15, not the BASIC GRAPHICS number) and the number of mode lines. A table at the top keeps track, including the scan lines remaining out of 192. The goal is to reach zero. Up to 16 segments are allowed. Entering 0 lines cancels an entry, and entering mode 0 finishes.
  2. Change a segment, add one at the bottom, or delete one by giving it 0 lines.
  3. See the display. The screen goes black while the list is calculated, a little tune plays (Wiegers called it reminiscent of Woody Woodpecker), and the bands appear in blue or black.
  4. Save writes a LISTed BASIC program to D1:name.DSP.
  5. Load a .DSP file back in for editing.
  6. Done.

To use a saved display, type NEW, ENTER "D:name.DSP" and RUN it. The generated program has line 10 calling a display-list builder at line 30000, a memory-allocation subroutine at 31000, an END at 29999, and one POKE 87,n statement per segment. Put your own POSITION/PRINT #6 (text modes) or PLOT/DRAWTO (graphics modes) after each POKE. Each segment behaves like a small screen of its own with 0,0 at its top left corner. You can ENTER the file into an existing program too, but its line numbers replace any lines with the same numbers. Press RESET after running a generated program.

How it works

Each ANTIC mode line takes a fixed number of TV scan lines, from 1 (ANTIC 15, GRAPHICS 8) to 16 (ANTIC 7, GRAPHICS 2). Mode Mixer uses a table of these values (SLPER) to check that the total comes to 192. The generated code works out where each segment's screen memory starts. Before drawing in a segment, it points the OS screen pointer at that memory and POKEs location 87 (DINDEX) with the segment's BASIC mode, so PLOT and PRINT #6 use the right resolution and colours.

Listing

1 REM MODE MIXER
2 REM BY KARL E. WIEGERS
3 REM ANTIC MAGAZINE
10 DIM INC(16),MODE(16),LINES(16),SLPER(15),BPER(15),BAS(15)
12 DIM B$(20),FNAME$(14),A$(100),BL$(39)
15 BL$(1)=" ":BL$(39)=BL$:BL$(2)=BL$
20 FOR I=2 TO 15:READ A:SLPER(I)=A:NEXT I:DATA 8,10,8,16,8,16,8,4,4,2,1,2,1,1
25 FOR I=2 TO 15:READ A:BPER(I)=A:NEXT I:DATA 40,40,40,40,20,20,10,10,20,20,20,40,40,40
30 FOR I=2 TO 15:READ A:BAS(I)=A:NEXT I:DATA 0,0,0,0,1,2,3,4,5,6,7,7,8,8
39 REM Display List Interrupt Routine
40 FOR I=0 TO 19:READ A:POKE 1771+I,A:NEXT I
50 DATA 72,138,72,169,0,162,28,141,10,212,141
60 DATA 23,208,142,24,208,104,170,104,64
70 OFF=40000:NO=500:MEMORY=550:LOCS=600:SPACE=625
80 OPEN #1,4,0,"K:"
99 REM Menu
100 GRAPHICS 0:POKE 752,1:POKE 559,0:POKE 710,0:POKE 709,90:POKE 711,198:GOSUB LOCS
110 RESTORE 120:FOR I=1 TO 25:READ A:POKE DL+I+2,A:NEXT I
120 DATA 71,0,0,7,6,6,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,6,6,6,65
130 POKE DL+4,LMEM:POKE DL+5,HMEM:POKE 559,34
135 POKE 87,2
140 POSITION 5,0:? #6;"mode {inv}mixer{/inv}"
145 POKE 87,1:BYTE=40:GOSUB MEMORY
150 POSITION 1,0:? #6;"PICK AN OPTION:"
155 POKE 87,0:BYTE=40:GOSUB MEMORY:POKE 82,6
160 POSITION 6,1:? "1 - {inv}CREATE{/inv} A NEW DISPLAY"
161 ? :? "2 - {inv}CHANGE{/inv} THE CURRENT DISPLAY"
162 ? :? "3 - {inv}SEE{/inv} THE CURRENT DISPLAY"
163 ? :? "4 - {inv}SAVE{/inv} CURRENT DISPLAY ON DISK"
164 ? :? "5 - {inv}LOAD{/inv} A DISPLAY FROM DISK"
165 ? :? "6 - {inv}DONE{/inv} WITH THIS PROGRAM"
170 POKE 82,2
175 POKE 87,1:BYTE=560:GOSUB MEMORY
180 POSITION 7,0:? #6;"?"
190 GET #1,CH:CH=CH-48
200 POSITION 9,0:? #6;CH
210 IF CH<1 OR CH>6 THEN GOSUB NO:? #6:? #6;"  enter only 1-6";:GOTO 190
220 ON CH GOTO 1000,2000,6000,7000,3000
230 GRAPHICS 0:END
500 FOR I=1 TO 15:SOUND 0,96,10,10:NEXT I
510 FOR I=1 TO 15:SOUND 0,128,10,10:NEXT I
520 SOUND 0,0,0,0:RETURN
550 HMEM=256*HMEM+LMEM+BYTE:LMEM=HMEM-256*INT(HMEM/256):HMEM=INT(HMEM/256)
560 POKE 88,LMEM:POKE 89,HMEM:RETURN
600 DL=PEEK(560)+256*PEEK(561):LMEM=PEEK(88):HMEM=PEEK(89)
610 MEM=HMEM*256+LMEM:RETURN
625 POKE 752,1:POSITION 7,23:? "PRESS {inv}SPACE BAR{/inv} TO CONTINUE";
630 GET #1,A:IF A<>32 THEN 630
635 RETURN
900 POKE DL+24,130
930 POKE 512,235:POKE 513,6:POKE 54286,192
940 ? " SEG.  MODE  # LINES  SCAN LINES LEFT"
950 ? " ____  ____  _______  _______________"
960 ? "  --    --      --        192"
970 POKE 703,4:RETURN
999 REM Create a New Display
1000 GRAPHICS 0:FOR I=1 TO 16:MODE(I)=0:LINES(I)=0:NEXT I
1005 POKE 752,1:LEFT=192:NSEG=0:POKE 1536,0:F=0
1010 POKE 1777,28:GOSUB 900
1020 CH=NSEG+1:IF CH=17 THEN GOSUB SPACE:GOTO 100
1030 GOSUB 1040:NSEG=NSEG+1:GOTO 1020
1040 ? :? "Enter graphics mode for segment ";CH;
1045 TRAP 1070:INPUT GRA:IF GRA=0 THEN 100
1050 IF GRA>1 AND GRA<16 THEN 1080
1055 GOTO 1070
1060 POP :TRAP OFF:IF NSEG>0 THEN 100
1065 GOTO 100
1070 GOSUB NO:? "{inv}MUST BE 2-15{/inv}":GOTO 1040
1080 ? "How many mode lines ";:TRAP 1100:INPUT NUM
1085 IF NUM=0 THEN NSEG=NSEG-1:RETURN
1090 IF NUM>0 AND NUM<=(LEFT/SLPER(GRA)) THEN TRAP OFF:GOTO 1110
1100 GOSUB NO:? "{inv}MUST BE 0-{/inv}";INT(LEFT/SLPER(GRA)):GOTO 1080
1110 MODE(CH)=GRA:LINES(CH)=NUM:LEFT=LEFT-NUM*SLPER(GRA)
1120 POSITION 4,2+CH:? #6;CH:POSITION 10,2+CH:? #6;GRA
1125 POSITION 18,2+CH:? #6;NUM
1130 POSITION 28,2+CH:? #6;LEFT
1140 RETURN
1999 REM Change Current Display
2000 GRAPHICS 0:IF NSEG=0 THEN GOSUB NO:POSITION 8,5:? "{inv}NO DISPLAY IN MEMORY NOW{/inv}":GOSUB SPACE:GOTO 100
2005 POKE 1777,200:GRAPHICS 0:POKE 752,1:GOSUB 900:F=0
2010 LEFT=192:FOR I=1 TO NSEG
2020 POSITION 4,2+I:? #6;I:POSITION 10,2+I:? #6;MODE(I)
2030 POSITION 18,2+I:? #6;LINES(I)
2040 LEFT=LEFT-LINES(I)*SLPER(MODE(I)):POSITION 28,2+I:? #6;LEFT:NEXT I
2050 ? :? "Enter segment number to change: ";
2055 TRAP 2100:INPUT CH:IF CH=0 THEN 100
2060 IF CH>16 THEN 2080
2062 IF CH<1 OR CH>NSEG+1 THEN 2100
2065 LEFT=LEFT+LINES(CH)*SLPER(MODE(CH))
2070 IF CH<>NSEG+1 THEN 2150
2080 IF LEFT=0 OR NSEG=16 THEN GOSUB NO:? "{inv}DISPLAY IS FULL{/inv}":GOTO 2050
2090 IF CH=NSEG+1 THEN 2110
2100 GOSUB NO:? "{inv}MUST BE FROM 1-{/inv}";NSEG+1-(LEFT=0):GOTO 2050
2110 GOSUB 1040:NSEG=CH-(NUM=0):GOTO 2170
2150 GOSUB 1040:IF NUM<>0 THEN 2170
2155 IF NSEG=0 THEN POSITION 2,3:? #6;BL$(4):GOTO 2050
2157 IF NSEG=15 THEN POSITION 2,18:? #6;BL$(4):GOTO 2050
2160 FOR I=CH+1 TO NSEG+1:LINES(I-1)=LINES(I):MODE(I-1)=MODE(I):NEXT I
2165 LINES(NSEG+1)=0:MODE(NSEG+1)=0
2170 LEFT=192:FOR I=1 TO NSEG:LEFT=LEFT-LINES(I)*SLPER(MODE(I))
2180 POSITION 4,2+I:? #6;I:POSITION 10,2+I:? #6;MODE(I);" "
2183 POSITION 18,2+I:? #6;LINES(I);"  "
2185 POSITION 28,2+I:? #6;LEFT;"  ":NEXT I
2190 ? #6;BL$(4):GOTO 2050
2999 REM Load Display from Disk
3000 GRAPHICS 0:POKE 710,16
3010 POKE 82,2:? "    DISPLAYS STORED ON THIS DISK"
3020 TRAP 3060:I=0:OPEN #4,6,0,"D:*.DSP"
3030 INPUT #4,A$:I=I+1
3040 POSITION 6,3+I
3050 ? A$(3,10):GOTO 3030
3060 CLOSE #4:I=I-1:TRAP OFF
3070 IF I=0 THEN GOSUB NO:POSITION 7,6:? "{inv}NO DISPLAYS ON THIS DISK{/inv}":GOSUB SPACE:GOTO 100
3080 POSITION 6,4+I:? BL$
3090 POSITION 2,18:? "LOAD what display:":? "(0 TO RETURN TO MENU)"
3100 POSITION 21,18:INPUT A$:IF A$="0" THEN 100
3110 IF A$="" THEN GOSUB NO:GOTO 3100
3120 FNAME$="D:":FNAME$(3)=A$
3130 FNAME$(LEN(FNAME$)+1)=".DSP"
3140 ? CHR$(125);"LOADING ";FNAME$;"...."
3150 TRAP 3160:OPEN #4,4,0,FNAME$:NSEG=0:TRAP OFF:GOTO 3180
3160 GOSUB NO:? :? "{inv}CANNOT LOAD FILE{/inv}-ERROR ";PEEK(195):GOSUB SPACE
3170 TRAP OFF:CLOSE #4:GOTO 3000
3180 FOR I=1 TO 20:INPUT #4,A$
3190 IF A$(4,7)="POKE" OR A$(5,8)="POKE" THEN NSEG=NSEG+1
3200 IF A$(7,9)="END" THEN INPUT #4,A$,A$,A$:POP :GOTO 3220
3210 NEXT I
3220 FOR I=1 TO 16:MODE(I)=0:LINES(I)=0:NEXT I
3230 J=12:CT=-6
3240 B$="":INPUT #4,A$:IF A$(7,10)="POKE" THEN 3290
3250 IF A$(J,J)="," THEN POKE 1542+CT,VAL(B$):CT=CT+1:B$="":GOTO 3270
3260 B$(LEN(B$)+1)=A$(J,J)
3270 J=J+1:IF J>LEN(A$) THEN POKE 1542+CT,VAL(B$):CT=CT+1:J=12:GOTO 3240
3280 GOTO 3250
3290 CLOSE #4
3300 OSMODE=PEEK(1539)-64
3310 FOR I=2 TO 15:IF OSMODE=I THEN 3330
3320 NEXT I
3330 POP :MODE(1)=I:LINES(1)=1:J=6:Y=1
3340 J=J+1:OSMODE=PEEK(1535+J)
3350 IF OSMODE=65 THEN 2000
3360 IF OSMODE>65 THEN OSMODE=OSMODE-64:J=J+2
3370 IF OSMODE=MODE(Y) THEN LINES(Y)=LINES(Y)+1:GOTO 3340
3380 FOR I=2 TO 15:IF OSMODE=I THEN 3400
3390 NEXT I
3400 POP :Y=Y+1:MODE(Y)=I:LINES(Y)=1:GOTO 3340
5999 REM See the Current Display
6000 GRAPHICS 0:IF NSEG=0 THEN 2000
6010 POKE 82,6:? :? :? "The screen will be black":? "briefly while your display"
6020 ? "is created."
6040 ? :? "Press any key when you are":? "done viewing the display."
6050 GOSUB SPACE:POKE 82,2
6100 DATA 8,8,7,7,6,5,0,0,0,1,4,0,2,3
6110 RESTORE 6100
6120 READ MAX:FOR I=1 TO NSEG:IF BAS(MODE(I))=MAX THEN POP :GOTO 6140
6130 NEXT I
6140 GRAPHICS MAX:POKE 752,1:GOSUB LOCS:POKE 559,0
6145 FOR I=0 TO 16:INC(I)=0:NEXT I
6150 FOURK=INT(MEM/4096+1)*4096
6160 POKE 1536,112:POKE 1537,112:POKE 1538,112
6170 POKE 1539,64+MODE(1)
6180 POKE 1540,LMEM:POKE 1541,HMEM
6185 CT=0
6190 FOR I=1 TO NSEG:TRAP 6280
6195 IF I=1 AND LINES(I)=1 THEN 6280
6200 FOR J=1 TO LINES(I):IF I=1 AND J=1 THEN 6270
6210 MEM=MEM+BPER(MODE(I)):IF MEM<=FOURK THEN 6260
6220 FOURK=INT(MEM/4096+1)*4096
6230 POKE 1542+CT,INT(MEM/256):CT=CT+1:GOTO 6270
6240 Y=MEM-256*INT(MEM/256):POKE 1542+CT,Y:CT=CT+1:INC(I)=Y
6250 POKE 1542+CT,INT(MEM/256):CT=CT+1:GOTO 6270
6260 POKE 1542+CT,MODE(I):CT=CT+1
6270 NEXT J
6280 NEXT I:TRAP OFF
6290 POKE 1542+CT,65
6320 POKE 560,0:POKE 561,6:POKE 559,34
6330 DATA 108,81,64,53,53,64
6340 RESTORE 6330:FOR I=1 TO 6:READ Y:FOR J=1 TO 5:SOUND 0,Y,10,8
6350 NEXT J:NEXT I:SOUND 0,0,0,0
6360 GET #1,A
6370 IF F=1 THEN GRAPHICS 0:GOTO 7070
6380 F=1:GOTO 100
6999 REM Save Display on Disk
7000 GRAPHICS 0:IF NSEG=0 THEN 2000
7010 ? "Enter a {inv}NAME{/inv} for this display:":? "(0 TO RETURN TO MENU)"
7020 POSITION 10,4:INPUT A$
7030 IF A$="0" THEN 100
7040 FNAME$="D:":FNAME$(LEN(FNAME$)+1)=A$
7050 FNAME$(LEN(FNAME$)+1)=".DSP"
7060 IF F=0 THEN F=1:GOTO 6000
7070 ? :? "Storing ";FNAME$;" on disk...."
7080 TRAP 7500:OPEN #4,8,0,FNAME$
7100 ? #4;"10 GOSUB 30000:LMEM=PEEK(88):HMEM=PEEK(89)":LN=20
7110 FOR I=1 TO NSEG
7120 ? #4;LN;" POKE 87,";BAS(MODE(I))-(MODE(I)=14);
7130 IF I=1 THEN ? #4;"":GOTO 7165
7140 BYTE=LINES(I-1)*BPER(MODE(I-1))+INC(I-1)
7150 ? #4;":BYTE=";BYTE;
7160 ? #4;":GOSUB 31000"
7165 LN=LN+10:NEXT I
7170 ? #4;"29999 END"
7200 ? #4;"30000 POKE 106,PEEK(106)-1:DL=256*PEEK(106)"
7210 ? #4;"30010 GRAPHICS ";MAX;":POKE 559,0"
7230 LN=30020
7240 ? #4;"30020 FOR I=0 TO ";CT+6;":READ A:POKE DL+I,A:NEXT I"
7250 FOR I=1 TO 11
7260 LN=LN+10:? #4;LN;" DATA ";
7270 FOR J=1 TO 19
7280 A=PEEK(1535+20*(I-1)+J):? #4;A;
7285 IF A=65 THEN ? #4;"":LN=LN+10:GOTO 7340
7290 ? #4;",";
7300 NEXT J
7310 ? #4;PEEK(1535+20*I)
7320 NEXT I
7340 ? #4;LN;" POKE DL+4,PEEK(88):POKE DL+5,PEEK(89)":LN=LN+10
7350 ? #4;LN;" POKE 560,0:POKE 561,DL/256:POKE 559,34"
7370 ? #4;LN+10;" RETURN"
7380 ? #4;"31000 HMEM=256*HMEM+LMEM+BYTE"
7390 ? #4;"31010 LMEM=HMEM-256*INT(HMEM/256)"
7400 ? #4;"31020 HMEM=INT(HMEM/256)"
7410 ? #4;"31030 POKE 88,LMEM:POKE 89,HMEM:RETURN"
7420 CLOSE #4:GOTO 100
7500 GOSUB NO:? :? "{inv}CANNOT STORE-ERROR {/inv}";PEEK(195)
7510 CLOSE #4
7520 GOSUB SPACE:GOTO 7000

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: MODEMIX.BAS.

Credits