100 '***  SCREENWRITER PROGRAM WITH GRAPHICS FOR THE OSBORNE 1
110 '***
120 '***             written by Jack Walraven (Oct. 82)
130 '***
140 '***           2840 Leigh Rd, Victoria, B.C., Canada
150 '***
160 PRINT CHR$(26)
170 CLEAR
180 DIM PR$(100)
190 B=61440!:E=64383!
200 Z=B
210 C=83
220 RM=999:LM=999
230 SP=32
240 PRINT CHR$(36)
250 PRINT:PRINT
260 PRINT"CURSOR CONTROL AND ALPHA-NUMERICS  
270 PRINT"Use the arrow keys to move the cursor to the
280 PRINT"desired position. The cursor will show what
290 PRINT"direction it will move. Use the alph-numeric
300 PRINT"keys to lay out the screen format and message.
310 PRINT
320 PRINT"GRAPHICS! Use the ESC key to produce the graphic
330 PRINT"you desire. Use the TAB key to continue drawing
340 PRINT"that graphic in the direction you indicated with
350 PRINT"the arrow keys.
360 PRINT"When your design is completed, hit the ENTER
370 PRINT"key. The program will then read (PEEK) your
380 PRINT"design in video memory, write a BASIC program
390 PRINT"and save it in a sequential file, which you
400 PRINT"can then MERGE with any of your programs (just
410 PRINT"make sure that the line numbers don't overlap).
420 PRINT:PRINT:PRINT"press any key to begin
430 Y$=INPUT$(1)
440 PRINT CHR$(26)
450 INPUT "ENTER THE BEGINNING LINE NUMBER (default is 1): ";LN
460 PRINT CHR$(26)
470 IF LN=0 THEN LN=1
480 INPUT "INCREMENT BETWEEN LINE NUMBERS (default is 1): ";IC
490 PRINT CHR$(26)
500 IF IC =0 THEN IC=1
510 INPUT "FILE NAME without .ext (default is TEST): ";F$
520 IF F$="" THEN F$="TEST"
530 F$=F$+".BAS"
540 PRINT CHR$(26)
550 '*****remove cursor from screen
560 POKE Z+128,SP
570 POKE Z,C
580 '*****wait for keyboard input
590 A$=INKEY$:IF A$="" THEN 590
600 '*****check if input is arrow key
610 IF A$=CHR$(13) THEN POKE Z,SP:GOTO 1160
620 IF A$=CHR$(11) THEN C=94:GOTO 800
630 IF A$=CHR$(10) THEN C=118:GOTO 880
640 IF A$=CHR$(12) THEN C=62:GOTO 960
650 IF A$=CHR$(8) THEN C=60:GOTO 1060
660 A=ASC(A$)
670 IF X>31 THEN X=0
680 '*****check if input is graphic
690 IF A=27 THEN A=X:X1=X:X=X+1:POKE Z,A:GOTO 590
700 IF A=9 THEN A=X1
710 Z1=Z-61440!:IF C=62 AND (Z1-50)/128=INT((Z1-50)/128) THEN POKE Z,A:GOTO 590
720 IF C=60 AND Z1/128=INT(Z1/128) THEN POKE Z,A:GOTO 590
730 POKE Z,A
740 IF C=94 AND Z-127>B THEN Z=Z-128:GOTO 590
750 IF C=118 AND Z+128<E THEN Z=Z+128:GOTO 590
760 IF C=62 AND Z+1<E THEN Z=Z+1:GOTO 590
770 IF C=60 AND Z>B THEN Z=Z-1:GOTO 590
780 GOTO 590
790 '*****cursor up routine
800 IF Z-128<B THEN 590
810 IF C1<>C THEN 840
820 POKE Z,SP
830 Z=Z-128
840 C1=C
850 POKE Z,C
860 GOTO 590
870 '*****cursor down routine
880 IF Z+128>E GOTO 590
890 IF C1<>C THEN 920
900 POKE Z,SP
910 Z=Z+128
920 C1=C
930 POKE Z,C
940 GOTO 590
950 '*****cursor right routine
960 IF Z+1>E THEN 590
970 IF C1<>C THEN 1010
980 Z1=Z-61440!:IF Z1=RM THEN 590
990 POKE Z,SP
1000 Z=Z+1
1010 C1=C
1020 Z1=Z-61440!:IF (Z1-50)/128=INT((Z1-50)/128) THEN RM=Z1
1030 POKE Z,C
1040 GOTO 590
1050 '*****cursor left routine
1060 IF Z-1<B THEN 590
1070 IF C1<>C THEN 1110
1080 Z1=Z-61440!:IF Z1=LM THEN 590
1090 POKE Z,SP
1100 Z=Z-1
1110 C1=C
1120 Z1=Z-61440!:IF Z1/128=INT(Z1/128) THEN LM=Z1
1130 POKE Z,C
1140 GOTO 590
1150 '*****read (peek) screen and write BASIC program
1160 CU=1
1170 PR$(CU)=STR$(LN)+" PRINT CHR$(26)":CU=CU+1:LN=LN+IC
1180 PR$(CU)=STR$(LN)+"WHILE A<>32:Z1=Z:READ Z,A:Z=Z1+Z:POKE Z+61440!,A:WEND
1190 CU=CU+1:LN=LN+IC
1200 N2=0
1210 FOR N=0 TO 2816 STEP 128
1220    FOR N1=N TO N+50
1230            Z=N1+61440!
1240            T%=PEEK(Z)
1250            IF T%=32 THEN 1330
1260            POKE N1+61440!,127
1270            Z%=N1-N2
1280            Z$=MID$(STR$(Z%),2):T$=MID$(STR$(T%),2)
1290            IF LEN(PR$)<50 THEN PR$=PR$+Z$+","+T$+",":GOTO 1320
1300            PR$(CU)=STR$(LN)+" DATA "+PR$+Z$+","+T$
1310            CU=CU+1:LN=LN+IC:PR$=""
1320            N2=N1
1330    NEXT N1 
1340 NEXT N
1350 IF PR$="" THEN 1370
1360 PR$(CU)=STR$(LN)+" DATA "+PR$+"32,32"
1370 CU=CU+1:LN=LN+IC
1380 PR$(CU)=STR$(LN)+" Y$=INPUT$(1)
1390 '*****save file to disk
1400 OPEN "O",#1,F$
1410 FOR N=1 TO CU+1
1420    PRINT #1,PR$(N)
1430 NEXT N
1440 CLOSE #1
1450 PRINT CHR$(26)
1460 PRINT:PRINT "YOUR DESIGN: ";F$;" HAS BEEN SAVED TO DISK.
1470 END