-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpetcat.c
2395 lines (1984 loc) · 75.7 KB
/
petcat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of Commodore 64 emulator
* and Program Development System.
*
* Copyright (C) 1993-1995,1996, Jouko Valta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* This program converts your SEQ files as well as expands tokenized
* C64/128 BASIC programs into 7-bit ASCII text. Unprintable characters
* can be shown as hexadecimal codes in parenthesis, via `-c' option.
* It is also possible to convert programs from ascii listings into
* tokenized basic v2.0, v3.5, v4.0, v7.0 or simon's basic programs. This
* program also replaces certain control code names with the actual codes.
*
* A list of Toolkit Basic (published by Compute! Books) token codes
* would be greatly appreciated. (-:
*
* Runs on UNIX or Atari ST.
*
* In shell:
* tr '\015A-Za-z\301-\332\\\|\[\{\]\}' '\012a-zA-ZA-Z\|\\\{\[\}\]'
* or
* tr '\015A-Za-z\\\|\[\{\]\}' '\012a-zA-Z\|\\\{\[\}\]'
*
* Written by
* Jouko Valta <jopi@stekt.oulu.fi>
*
* With additional changes by
* Ettore Perazzoli <ettore@comm2000.it>
* Spiro Trikaliotis <spiro.trikaliotis@gmx.de>
*
* Support for Final Cartridge III extensions to c64 2.0 basic
* Matti 'ccr' Hämäläinen <ccr@tnsp.org>
*
* Support for many of the other extensions by
* Marco van den Heuvel <blackystardust68@yahoo.com>
*
*/
/* #define DEBUG */
#include "vice.h"
#include "version.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "archdep.h"
#include "charset.h" /* ctrl1, ctrl2, cbmkeys */
#include "cmdline.h"
#include "event.h"
#include "lib.h"
#include "network.h"
#include "types.h"
/* dummy functions */
void ui_error(const char *format, ...)
{
}
#define PETCATVERSION 2.17
#define PETCATLEVEL 1
#define B_1 1
#define B_2 2
#define B_SUPER 3
#define B_TURTLE 4
#define B_SIMON 5
#define B_SPEECH 6
#define B_ATBAS 7
#define B_4 8
#define B_4E 9 /* C64 extension, Expand only */
#define B_35 10
#define B_7 11
#define B_10 12
#define B_FC3 13
#define B_ULTRA 14
#define B_GRAPH 15
#define B_WS 16
#define B_MIGHTY 17
#define B_PEG 18
#define B_X 19
#define B_DRAGO 20
#define B_REU 21
#define B_BASL 22
#define B_71 23
#define B_MAGIC 24
#define B_EASY 25
#define B_BLARG 26
#define B_VIC4 27
#define B_VIC5 28
#define B_WSF 29
#define B_GB 30
/* Limits */
#define NUM_B_1 75 /* Basic 1.0 */
#define NUM_COMM 76 /* common for all versions 2.0 ... 10.0 */
#define NUM_SECC 18 /* VIC-20 extension */
#define NUM_TUCC 34 /* VIC-20 Turtle Basic extension */
#define NUM_V4CC 15 /* PET 4.0 */
#define NUM_4ECC 24 /* 4.0 extension (C64) */
#define NUM_VIC4 20 /* 4.0 extension (VIC20) */
#define NUM_VIC5 38 /* 5.0 extension (VIC20) */
#define NUM_SPECC 27 /* Speech Basic */
#define NUM_ATBCC 43 /* Atbasic */
#define NUM_FC3CC 29 /* Final Cartridge III */
#define NUM_KWCE 11
#define NUM_V7FE 39
#define NUM_V71FE 56
#define NUM_V10FE 62
#define NUM_ULTRCC 51 /* Ultrabasic-64 */
#define NUM_GRAPHCC 51 /* graphics basic (c64) */
#define NUM_WSCC 51 /* WS basic (c64) */
#define NUM_MIGHTYCC 51 /* Mighty basic (vic20) */
#define NUM_PEGCC 33 /* Pegasus basic 4.0 (c64) */
#define NUM_XCC 33 /* Xbasic (c64) */
#define NUM_DRAGOCC 13 /* Drago basic 2.2 (c64) */
#define NUM_REUCC 14 /* REU-basic (c64) */
#define NUM_BASLCC 51 /* Basic Lightning (c64) */
#define NUM_MAGICCC 50 /* Magic Basic (c64) */
#define NUM_EASYCC 51 /* Easy Basic (vic20) */
#define NUM_WSFCC 51 /* WS basic final (c64) */
#define NUM_GBCC 29
#define NUM_BLARGE0 11 /* Blarg (c64) */
#define MAX_COMM 0xCB /* common for all versions */
#define MAX_SECC 0xDD /* VIC-20 extension */
#define MAX_TUCC 0xED /* VIC-20 Turtle Basic extension */
#define MAX_V4CC 0xDA /* PET 4.0 */
#define MAX_4ECC 0xE3 /* 4.0 extension (C64) */
#define MAX_VIC4 0xDF /* 4.0 extension (VIC20) */
#define MAX_VIC5 0xF1 /* 5.0 extension (VIC20) */
#define MAX_SPECC 0xE6 /* Speech Basic */
#define MAX_ATBCC 0xF6 /* Atbasic */
#define MAX_FC3CC 0xE8 /* Final Cartridge III */
#define MAX_ULTRCC 0xFE /* Ultrabasic-64 */
#define MAX_GRAPHCC 0xFE /* graphics basic (c64) */
#define MAX_WSCC 0xFE /* WS basic (c64) */
#define MAX_MIGHTYCC 0xFE /* Mighty basic (vic20) */
#define MAX_PEGCC 0xEC /* Pegasus basic 4.0 (c64) */
#define MAX_XCC 0xEC /* Xbasic (c64) */
#define MAX_DRAGOCC 0xD8 /* Drago basic 2.2 (c64) */
#define MAX_REUCC 0xDA /* REU-basic (c64) */
#define MAX_BASLCC 0xFE /* Basic Lightning (c64) */
#define MAX_MAGICCC 0xFD /* Magic Basic (c64) */
#define MAX_EASYCC 0xFE /* Easy Basic (vic20) */
#define MAX_WSFCC 0xFE /* WS basic final (c64) */
#define MAX_GBCC 0xE8 /* Game Basic (c64) */
#define MAX_BLARGE0 0xEA /* Blarg (c64) */
#define MAX_KWCE 0x0A
#define MAX_V7FE 0x26
#define MAX_V71FE 0x39
#define MAX_V10FE 0x3D
#define KW_NONE 0xFE /* flag unused token */
#define CLARIF_LP '{' /* control code left delimiter */
#define CLARIF_RP '}' /* control code right delimiter */
#define CLARIF_LP_ST "{" /* control code left delimiter, "string version" */
#define CLARIF_RP_ST "}" /* control code right delimiter, "string version" */
/* ------------------------------------------------------------------------- */
const char machine_name[] = "PETCAT";
static const unsigned char MagicHeaderP00[8] = "C64File\0";
/*
* Printer's control code symbols
*/
/* all numeric codes */
static const char *hexcodes[] = {
"$00","$01","$02","$03","$04","$05","$06","$07","$08","$09","$0a","$0b","$0c","$0d","$0e","$0f",
"$10","$11","$12","$13","$14","$15","$16","$17","$18","$19","$1a","$1b","$1c","$1d","$1e","$1f",
"$20","$21","$22","$23","$24","$25","$26","$27","$28","$29","$2a","$2b","$2c","$2d","$2e","$2f",
"$30","$31","$32","$33","$34","$35","$36","$37","$38","$39","$3a","$3b","$3c","$3d","$3e","$3f",
"$40","$41","$42","$43","$44","$45","$46","$47","$48","$49","$4a","$4b","$4c","$4d","$4e","$4f",
"$50","$51","$52","$53","$54","$55","$56","$57","$58","$59","$5a","$5b","$5c","$5d","$5e","$5f",
"$60","$61","$62","$63","$64","$65","$66","$67","$68","$69","$6a","$6b","$6c","$6d","$6e","$6f",
"$70","$71","$72","$73","$74","$75","$76","$77","$78","$79","$7a","$7b","$7c","$7d","$7e","$7f",
"$80","$81","$82","$83","$84","$85","$86","$87","$88","$89","$8a","$8b","$8c","$8d","$8e","$8f",
"$90","$91","$92","$93","$94","$95","$96","$97","$98","$99","$9a","$9b","$9c","$9d","$9e","$9f",
"$a0","$a1","$a2","$a3","$a4","$a5","$a6","$a7","$a8","$a9","$aa","$ab","$ac","$ad","$ae","$af",
"$b0","$b1","$b2","$b3","$b4","$b5","$b6","$b7","$b8","$b9","$ba","$bb","$bc","$bd","$be","$bf",
"$c0","$c1","$c2","$c3","$c4","$c5","$c6","$c7","$c8","$c9","$ca","$cb","$cc","$cd","$ce","$cf",
"$d0","$d1","$d2","$d3","$d4","$d5","$d6","$d7","$d8","$d9","$da","$db","$dc","$dd","$de","$df",
"$e0","$e1","$e2","$e3","$e4","$e5","$e6","$e7","$e8","$e9","$ea","$eb","$ec","$ed","$ee","$ef",
"$f0","$f1","$f2","$f3","$f4","$f5","$f6","$f7","$f8","$f9","$fa","$fb","$fc","$fd","$fe","$ff",
};
/* 0x00 - 0x1f */
static const char *ctrl1[] = {
"", "", "", "", "", "wht", "", "",
"dish", "ensh", "\n", "", "\f", "\n", "swlc", "",
"", "down", "rvon", "home", "del", "", "", "",
"", "", "", "esc", "red", "rght", "grn", "blu"
};
/* 0x80 - 0x9f */
static const char *ctrl2[] = {
"", "orng", "", "", "", "F1", "F3", "F5",
"F7", "F2", "F4", "F6", "F8", "sret", "swuc", "",
"blk", "up", "rvof", "clr", "inst", "brn", "lred", "gry1",
"gry2", "lgrn", "lblu", "gry3", "pur", "left", "yel", "cyn"
};
/*
* Alternate mnemonics for control codes
* These are used by MikroBITTI for clarification
*/
/* 0x00 - 0x1f */
const char *a_ctrl1[] = {
"", "", "", "", "", "wht", "", "",
"up/lo lock on", "up/lo lock off", "", "", "", "return", "lower case", "",
"", "down", "rvs on", "home", "delete", "", "", "",
"", "", "", "esc", "red", "right", "grn", "blu"
};
/* 0x00 - 0x1f */
const char *b_ctrl1[] = {
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "REVERSE ON", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
/* 0x20 - 0x3f */
const char *cbmchars[] = {
"space", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", ""
};
/* 0x80 - 0x9f */
const char *a_ctrl2[] = {
"", "orange", "", "", "", "f1", "f3", "f5",
"f7", "f2", "f4", "f6", "f8", "shift return", "upper case", "",
"blk", "up", "rvs off", "clear", "insert", "brown", "lt red", "grey1",
"grey2", "lt green", "lt blue", "grey3", "pur", "left", "yel", "cyn"
};
/* keys for charcodes 0xa0-0xe0 */
static const char *cbmkeys[] = {
"SHIFT-SPACE", "CBM-K", "CBM-I", "CBM-T", "CBM-@", "CBM-G", "CBM-+","CBM-M",
"CBM-POUND","SHIFT-POUND", "CBM-N", "CBM-Q", "CBM-D", "CBM-Z", "CBM-S", "CBM-P",
"CBM-A", "CBM-E", "CBM-R", "CBM-W", "CBM-H", "CBM-J", "CBM-L", "CBM-Y",
"CBM-U", "CBM-O", "SHIFT-@", "CBM-F", "CBM-C", "CBM-X", "CBM-V", "CBM-B",
"SHIFT-*","SHIFT-A","SHIFT-B","SHIFT-C","SHIFT-D","SHIFT-E","SHIFT-F","SHIFT-G",
"SHIFT-H","SHIFT-I","SHIFT-J","SHIFT-K","SHIFT-L","SHIFT-M","SHIFT-N","SHIFT-O",
"SHIFT-P","SHIFT-Q","SHIFT-R","SHIFT-S","SHIFT-T","SHIFT-U","SHIFT-V","SHIFT-W",
"SHIFT-X","SHIFT-Y","SHIFT-Z","SHIFT-+","CBM--","SHIFT--","SHIFT-^","CBM-*"
};
/* alternative keys for charcodes 0xa0-0xe0 */
static const char *a_cbmkeys[] = {
"","","","","","","","",
"","","","","","","","",
"","","","","","","","",
"","","","","","","","",
"","","","","","","","",
"","","","","","","","",
"","","","","","","","",
"","","","","","","CBM-^",""
};
#define NUM_VERSIONS 30
const char *VersNames[] = {
"Basic 1.0",
"Basic 2.0",
"Basic 2.0 with Super Expander",
"Basic 2.0 with Turtle Basic v1.0",
"Basic 2.0 with Simon's Basic",
"Basic 2.0 with Speech Basic v2.7",
"Basic 2.0 with @Basic",
"Basic 4.0",
"Basic 4.0 extension for C64",
"Basic 3.5",
"Basic 7.0",
"Basic 10.0",
"Basic 2.0 with Final Cartridge III",
"Basic 2.0 with Ultrabasic-64",
"Basic 2.0 with graphics basic",
"Basic 2.0 with WS basic",
"Basic 2.0 with Mighty basic",
"Basic 2.0 with Pegasus basic 4.0",
"Basic 2.0 with Xbasic",
"Basic 2.0 with Drago basic 2.2",
"Basic 2.0 with REU-basic",
"Basic 2.0 with Basic Lightning",
"Basic 7.1 extension",
"Basic 2.0 with Magic Basic",
"Basic 2.0 with Easy Basic",
"Basic 2.0 with Blarg",
"Basic 4.0 extension for VIC20",
"Basic 5.0 extension for VIC20",
"Basic 2.0 with WS basic final",
"Basic 2.0 with Game Basic",
""
};
/*
* Two BASIC tokens which need some special care
*/
#define TOKEN_REM (0x8F - 0x80)
#define TOKEN_DATA (0x83 - 0x80)
/*
* CBM Basic Keywords
*/
const char *keyword[] = {
/* Common Keywords, 80 - cb */
"end", "for", "next", "data", "input#", "input", "dim", "read",
"let", "goto", "run", "if", "restore", "gosub", "return", "rem",
"stop", "on", "wait", "load", "save", "verify", "def", "poke",
"print#", "print", "cont", "list", "clr", "cmd", "sys", "open",
"close", "get", "new", "tab(", "to", "fn", "spc(", "then",
"not", "step", "+", "-", "*", "/", "^", "and",
"or", ">", "=", "<", "sgn", "int", "abs", "usr",
"fre", "pos", "sqr", "rnd", "log", "exp", "cos", "sin",
"tan", "atn", "peek", "len", "str$", "val", "asc", "chr$",
"left$", "right$", "mid$", "go",
/*
* The following codes (0xcc- 0xfe) are for 3.5, 7.0, and 10.0 only.
* On 10.0 gshape, sshape, and draw are replaced with paste, cut, and line
* respectively. */
"rgr", "rlcr", "rlum" /* 0xce -- v7 prefix */, "joy",
"rdot", "dec", "hex$", "err$", "instr", "else", "resume", "trap",
"tron", "troff", "sound", "vol", "auto", "pudef", "graphic", "paint",
"char", "box", "circle", "gshape", "sshape", "draw", "locate", "color",
"scnclr", "scale", "help", "do", "loop", "exit", "directory", "dsave",
"dload", "header", "scratch", "collect", "copy", "rename", "backup",
"delete", "renumber", "key", "monitor", "using", "until", "while",
/* 0xfe -- prefix */ "", "~" /* '~' is ASCII for 'pi' */
};
/*
* 7.0, 7.1 and 10.0 only.
* On 10.0 stash, fetch, and swap are replaced with dma.
*/
const char *kwce[] = {
"", "", "pot", "bump", "pen", "rsppos", "rsprite", "rspcolor",
"xor", "rwindow", "pointer"
};
const char *kwfe[] = {
"", "", "bank", "filter", "play", "tempo", "movspr", "sprite",
"sprcolor", "rreg", "envelope", "sleep", "catalog", "dopen", "append",
"dclose", "bsave",
"bload", "record", "concat", "dverify", "dclear", "sprsav", "collision",
"begin", "bend", "window", "boot", "width", "sprdef", "quit", "stash",
"", "fetch", "", "swap", "off", "fast", "slow",
/* Basic 10.0 only (fe27 - fe3d) */
"type",
"bverify", "ectory", "erase", "find", "change", "set", "screen", "polygon",
"ellipse", "viewport", "gcopy", "pen", "palette", "dmode", "dpat", "pic",
"genlock", "foreground", "", "background", "border", "highlight"
};
/* Basic 7.1 extension */
const char *kwfe71[] = {
"", "", "bank", "filter", "play", "tempo", "movspr", "sprite",
"sprcolor", "rreg", "envelope", "sleep", "catalog", "dopen", "append",
"dclose", "bsave",
"bload", "record", "concat", "dverify", "dclear", "sprsav", "collision",
"begin", "bend", "window", "boot", "width", "sprdef", "quit", "stash",
"", "fetch", "", "swap", "off", "fast", "slow",
/* Basic 7.1 extension only (fe27 - fe37) */
"cwind",
"sscrn", "lscrn", "hide", "show", "sfont", "lfont", "view", "fcopy",
"esave", "send", "check", "esc", "old", "find", "dump", "merge"
};
const char *superkwcc[] = { /* VIC Super Expander commands 0xcc - 0xdd */
"key", "graphic", "scnclr", "circle", "draw", "region", "color", "point",
"sound", "char", "paint", "rpot", "rpen", "rsnd", "rcolr", "rgr",
"rjoy", "rdot"
};
const char *petkwcc[] = { /* PET Basic 4.0 0xcc - 0xda */
"concat", "dopen", "dclose", "record",
"header", "collect", "backup", "copy","append", "dsave","dload", "catalog",
"rename", "scratch", "directory",
/* Basic 4 Extension for C64 (0xdb - 0xe3) */
"color", "cold", "key", "dverify", "delete",
"auto", "merge", "old", "monitor"
};
/* ------------------------------------------------------------------------- */
/*
* Third party products for VIC-20
*/
/* Turtle Basic v1.0 Keywords -- Craig Bruce */
const char *turtlekwcc[] = {
"graphic", "old", "turn", "pen", "draw", "move", "point", "kill",
"write", "repeat", "screen", "doke", "reloc", "fill", "rtime", "base",
"pause", "pop", "color", "merge", "char", "take", "sound", "vol",
"put", "place", "cls", "accept", "reset", "grab", "rdot", "plr$",
"deek", "joy"
};
/* Easy Basic Keywords */
const char *easykwcc[] = {
"delete", "old", "renumber", "dump", "merge", "plot",
"trace", "kill", "help", "dload", "dsave", "dverify",
"append", "screen", "directory", "key", "send", "pop",
"off", "pout", "header", "find", "auto", "pprint",
"accept", "reset", "scratch", "color", "take", "pause",
"base", "copychr", "char", "clk", "cls", "fill",
"retime", "sound", "poff", "plist", "put", "volume",
"joy", "msb", "lsb", "vector", "rkey", "dec",
"hex$", "grab", "ds$"
};
/* Mighty basic Keywords */
const char *mightykwcc[] = {
"delete", "old", "renumber", "help", "header", "move",
"trace", "kill", "dump", "dsave", "dload", "dverify",
"dresave", "scratch", "directory", "key", "send", "pop",
"off", "bsave", "bload", "find", "auto", "pprint",
"accept", "reset", "else", "color", "take", "pause",
"base", "copychr", "char", "beep", "cls", "fill",
"merge", "sound", "give", "plist", "put", "volume",
"rtime", "msb", "lsb", "vector", "joy", "dec",
"hex$", "grab", "ds$"
};
/* Basic 4.0 extension Keywords */
const char *vic4kwcc[] = {
"concat", "dopen", "dclose", "record", "header", "collect",
"backup", "copy", "append", "dsave", "dload", "catalog",
"rename", "scratch", "directory", "ieee", "serial", "parallel",
"monitor", "modem"
};
/* Basic 5.0 extension Keywords */
const char *vic5kwcc[] = {
"concat", "dopen", "dclose", "record", "header", "collect",
"backup", "copy", "append", "dsave", "dload", "catalog",
"rename", "scratch", "directory", "dverify", "monitor", "repeat",
"bell", "commands", "renew", "`", "key", "auto",
"off", "", "merge", "color", "mem", "enter",
"delete", "find", "number", "else", "call", "graphic",
"alpha", "dmerge"
};
/*
* Third party products for C=64
*/
/* Speech Basic v2.7 Keywords (Tokens CC - E6) */
const char *speechkwcc[] = {
"reset", "basic", "help", "key",
"himem", "disk", "dir", "bload", "bsave", "map", "mem", "pause",
"block", "hear", "record", "play", "voldef", "coldef", "hex", "dez",
"screen", "exec", "mon", "<-", "from", "speed", "off"
};
/* Blarg Keywords */
const char *blargkwe0[] = {
"plot", "line", "circle", "gron", "groff", "mode", "origin",
"clear", "buffer", "swap", "color"
};
/* @Basic (Atbasic) Keywords (Tokens CC - F6) -- André Fachat */
const char *atbasickwcc[] = {
"trace", "delete", "auto", "old", "dump", "find", "renumber", "dload",
"dsave", "dverify", "directory", "catalog", "scratch", "collect",
"rename", "copy", "backup", "disk", "header", "append", "merge", "mload",
"mverify", "msave", "key", "basic", "reset", "exit", "enter", "doke",
"set", "help", "screen", "lomem", "himem", "colour", "type", "time",
"deek", "hex$", "bin$", "off", "alarm"
};
/* Ultrabasic-64 Keywords (Tokens CC - FE) -- Marco van den Heuvel */
const char *ultrabasic64kwcc[] = {
"dot", "draw", "box", "tic", "copy", "sprite", "off", "mode",
"norm", "graph", "dump", "gread", "char", "place", "multi", "hires",
"hex", "bit", "colors", "pixel", "fill", "circle", "block", "sdata",
"vol", "gen", "scoll", "bcoll", "joy", "paddle", "pen", "sound",
"tune", "tdata", "set", "turnto", "turn", "tup", "tdown", "tcolor",
"turtle", "move", "bye", "rotate", "tpos", "ctr", "sctr", "[",
"]", "hard", "exit"
};
/* Graphics basic (c64) Keywords (Tokens CC - FE) -- Marco van den Heuvel */
const char *graphicsbasickwcc[] = {
"background", "border", "dir", "disk", "fill", "key",
"circle", "procedure", "dot", "find", "change", "ren",
"else", "copy", "scroll", "roll", "box", "scale",
"do", "line", "sprite", "color", "hires", "clear",
"text", "window", "off", "at", "shape", "xysize",
"speed", "from", "setorigin", "animate", "multi", "eze",
"move", "under", "edit", "reset", "xpos", "gprint",
"voice", "adsr", "wave", "ne", "volume", "play",
"ypos", "sound", "joy"
};
/* WS (WohnzimmerSoft) basic (c64) Keywords (Tokens CC - FE) -- Marco van den Heuvel */
const char *wsbasickwcc[] = {
"copy", "old", "port", "doke", "vpoke", "fill", "error",
"send", "call", "bit", "dir", "bload", "bsave", "find",
"speed", "pitch", "say", "fast", "slow", "talk", "shutup",
"stash", "fetch", "swap", "off", "screen", "device", "object",
"vstash", "vfetch", "quiet", "color", "cls", "curpos", "monitor",
"subend", "do", "loop", "exit", "deek", "rsc", "rsm",
"dec", "hex$", "hi", "lo", "ds$", "line", "vpeek",
"row", "joy"
};
/* WS (WohnzimmerSoft) basic final (c64) Keywords (Tokens CC - FE) -- Marco van den Heuvel */
const char *wsfbasickwcc[] = {
"copy", "bank", "old", "doke", "display", "fill", "error",
"send", "call", "bit", "dir", "bload", "bsave", "find",
"speed", "pitch", "say", "fast", "slow", "talk", "shutup",
"stash", "fetch", "swap", "off", "mode", "device", "object",
"vstash", "vfetch", "latch", "color", "cls", "curpos", "monitor",
"subend", "do", "loop", "exit", "deek", "col", "rsm",
"dec", "hex$", "hi", "lo", "ds$", "line", "bnk",
"ypos", "joy"
};
/* Pegasus basic 4.0 (c64) Keywords (Tokens CC - EC) -- Marco van den Heuvel */
const char *pegbasickwcc[] = {
"off", "asc(", "sin(", "cos(", "tan(", "atn(",
"deg(", "rad(", "frac(", "mod(", "round(", "dec(",
"bin(", "deek(", "instr(", "joy(", "pot(", "screen(",
"test(", "using", "ds$", "hex$(", "bin$(", "space$(",
"ucase$(", "string$(", "input$(", "time$", "spritex(", "spritey(",
"turtlex(", "turtley(", "turtleang"
};
/* Xbasic (c64) Keywords (Tokens CC - EC) -- Marco van den Heuvel */
const char *xbasickwcc[] = {
"sprat", "brdr", "screen", "quit", "sprmult", "move",
"sprite", "asprite", "dsprite", "sid", "envelope", "gate",
"frq", "wave", "vol", "fcut", "fmode", "filter",
"frsn", "cset", "multi", "extnd", "locate", "center",
"hires", "line", "hprnt", "plot", "text", "clear",
"colr", "stick", "btn"
};
/* Drago basic 2.2 (c64) Keywords (Tokens CC - D8) -- Marco van den Heuvel */
const char *dragobasickwcc[] = {
"punkt", "linia", "rysuj", "param", "kuntur", "anim", "kolor",
"puwid", "ryselip", "koguma", "fiut", "figura", "figuma"
};
/* REU-basic (c64) Keywords (Tokens CC - DA) -- Marco van den Heuvel */
const char *reubasickwcc[] = {
"push", "pull", "flip", "rec", "stash", "fetch", "swap", "reu",
"size", "dir", "@", "kill", "rom", "ram", "move"
};
/* Basic Lightning (c64) Keywords (Tokens CC - FE) -- Marco van den Heuvel */
const char *baslkwcc[] = {
"else", "hex$", "deek", "true", "import", "cfn", "size",
"false", "ver$", "lpx", "lpy", "common%", "crow", "ccol",
"atr", "inc", "num", "row2", "col2", "spn2", "hgt",
"wid", "row", "col", "spn", "task", "halt", "repeat",
"until", "while", "wend", "cif", "celse", "cend", "label",
"doke", "exit", "allocate", "disable", "pull", "dload", "dsave",
"var", "local", "procend", "proc", "casend", "of", "case",
"rpt", "setatr"
};
/* Magic Basic (c64) Keywords (Tokens CC - FD) -- Marco van den Heuvel */
const char *magickwcc[] = {
"assembler", "auto", "cdrive", "cat", "dappend", "delete",
"dez", "dir", "dload", "dsave", "dverify", "config",
"find", " ", " ", "help", "hex", "jump",
"llist", "lprint", "off", "old", "renum", "crun",
"send", "status", "hires", "multi", "clear", "plot",
"invert", "line", "text", "graphik", "page", "box",
"draw", "mix", "copy", "circle", "gsave", "gload",
"frame", "hprint", "vprint", "block", "fill", " ",
"replace", "lrun"
};
/* Game Basic (c64) Keywords (Tokens CC - E8) -- Marco van den Heuvel */
const char *gbkwcc[] = {
"window", "bfile", "upper", "lower", "cls", "screen", "parse",
"proc", "else", "scratch", "replace", "device", "dir", "repeat",
"until", "disk", "fetch#", "put#", "prompt", "pop", "help",
"exit", "disable", "enter", "reset", "warm", "num", "type",
"text$"
};
/* Simon's Basic Keywords */
const char *simonskw[] = {
"", "hires", "plot", "line", "block", "fchr", "fcol", "fill",
"rec", "rot", "draw", "char", "hi col", "inv", "frac", "move",
"place", "upb", "upw", "leftw", "leftb", "downb", "downw", "rightb",
"rightw", "multi", "colour", "mmob", "bflash", "mob set", "music", "flash",
"repeat", "play", ">>", "centre", "envelope", "cgoto", "wave", "fetch",
"at(", "until", ">>", ">>", "use", ">>", "global", ">>",
"reset", "proc", "call", "exec", "end proc", "exit", "end loop", "on key",
"disable", "resume", "loop", "delay", ">>", ">>", ">>", ">>",
"secure", "disapa", "circle", "on error","no error","local","rcomp","else",
"retrace", "trace", "dir", "page", "dump", "find", "option", "auto",
"old", "joy", "mod", "div", ">>", "dup", "inkey", "inst",
"test", "lin", "exor", "insert", "pot", "penx", ">>", "peny",
"sound", "graphics", "design", "rlocmob", "cmob", "bckgnds", "pause","nrm",
"mob off", "off", "angl", "arc", "cold", "scrsv", "scrld", "text",
"cset", "vol", "disk", "hrdcpy", "key", "paint", "low col", "copy",
"merge", "renumber", "mem", "detect", "check", "display", "err", "out"
};
/* Final Cartridge III Keywords -- Matti 'ccr' Hämäläinen */
const char *fc3kw[] = {
"off", "auto", "del", "renum", "?ERROR?", "find", "old", "dload",
"dverify", "dsave", "append", "dappend", "dos", "kill",
"mon", "pdir", "plist", "bar", "desktop", "dump", "array", "mem",
"trace", "replace", "order", "pack", "unpack", "mread", "mwrite"
};
/* ------------------------------------------------------------------------- */
static int parse_version(char *str);
static void list_keywords(int version);
static void pet_2_asc (int ctrls);
static void _p_toascii(int c, int ctrls);
static int p_expand(int version, int addr, int ctrls);
static void p_tokenize(int version, unsigned int addr, int ctrls);
static unsigned char sstrcmp(unsigned char *line, const char **wordlist,
int token, int maxitems);
static unsigned char sstrcmp_codes(unsigned char *line, const char **wordlist,
int token, int maxitems);
/* ------------------------------------------------------------------------- */
static FILE *source, *dest;
static int kwlen;
static int codesnocase=0; /* flag, =1 if controlcodes should be interpreted case insensitive */
/* dummy functions */
int cmdline_register_options(const cmdline_option_t *c)
{
return 0;
}
int network_connected(void)
{
return 0;
}
int network_get_mode(void)
{
return NETWORK_IDLE;
}
void network_event_record(unsigned int type, void *data, unsigned int size)
{
}
void event_record_in_list(event_list_state_t *list, unsigned int type,
void *data, unsigned int size)
{
}
/* ------------------------------------------------------------------------- */
/*
29/01/2009 gpz
- added -ic option
*/
int main(int argc, char **argv)
{
char *progname, *outfilename = NULL;
int c = 0;
long offset = 0;
int wr_mode = 0, version = B_7; /* best defaults */
int load_addr = 0, ctrls= -1, hdr = -1, show_words = 0;
int fil = 0, outf = 0, overwrt = 0, textmode = 0;
int flg = 0; /* files on stdin */
archdep_init(&argc, argv);
/* Parse arguments */
progname = argv[0];
while (--argc && ((*++argv)[0] == '-')) {
if (!strcmp(argv[0], "--")) {
--argc;
++argv;
break;
}
if (!strcmp(argv[0], "-l")) { /* load address */
if (argc > 1 && sscanf(argv[1], "%x", &load_addr) == 1) {
--argc; ++argv;
continue;
}
/* Fall to error */
}
if (!strcmp(argv[0], "-ic")) {
codesnocase = 1;
continue;
}
if (!strcmp(argv[0], "-c")) {
ctrls = 1;
continue;
} else {
if (!strcmp(argv[0], "-nc")) {
ctrls = 0;
continue;
}
}
if (!strcmp(argv[0], "-h")) {
hdr = 1;
continue;
} else if (!strcmp(argv[0], "-nh")) {
hdr = 0;
continue;
} else if (!strcmp(argv[0], "-f")) { /* force overwrite */
++overwrt;
continue;
}
else if (!strcmp(argv[0], "-o")) {
if (argc > 1) {
outfilename = argv[1];
++outf;
--argc; ++argv;
continue;
}
fprintf (stderr, "\nOutput filename missing\n");
/* Fall to error */
}
/* reading offset */
if (!strcmp(argv[0], "-skip") || !strcmp(argv[0], "-offset")) {
if (argc > 1 && sscanf(argv[1], "%lx", &offset) == 1)
{
--argc; ++argv;
continue;
}
/* Fall to error */
} else if (!strcmp(argv[0], "-text")) { /* force text mode */
++textmode;
continue;
} else if (!strcmp(argv[0], "-help") ||
!strncmp(argv[0], "-v", 2)) { /* version ID */
fprintf(stdout,
"\n\t%s V%4.2f PL %d -- Basic list/crunch utility.\n\tPart of "PACKAGE" "VERSION"\n",
progname, (float)PETCATVERSION, PETCATLEVEL );
/* Fall to error for Usage */
/* Basic version */
} else if (!strncmp(argv[0], "-w", 2) && !wr_mode) {
version = parse_version((strlen(argv[0]) > 2 ? &argv[0][2] : NULL)); ++wr_mode;
continue;
} else if (!strncmp(argv[0], "-k", 2) && !wr_mode) {
version = parse_version((strlen(argv[0]) > 2 ? &argv[0][2] : NULL)); ++show_words;
continue;
} else if ((version = parse_version(&argv[0][1])) >= 0) {
continue;
}
fprintf(stdout,
"\nUsage: %7s [-c | -nc] [-h | -nh] [-text | -<version> | -w<version>]"
"\n\t\t[-skip <bytes>] [-l <hex>] [--] [file list]\n\t\t[-k[<version>]]\n",
progname);
fprintf(stdout, "\n"
" -help\tOutput this help screen here\n"
" -v\t\tSame as above\n"
" -c\t\tcontrols (interpret also control codes) <default if textmode>\n"
" -nc\t\tno controls (suppress control codes in printout)\n"
" \t\t<default if non-textmode>\n"
" -ic\t\tinterpret control codes case-insensitive\n"
" -h\t\twrite header <default if output is stdout>\n"
" -nh\t\tno header <default if output is a file>\n"
" -skip <n>\tSkip <n> bytes in the beginning of input file. Ignored on P00.\n"
" -text\tForce text mode\n"
" -<version>\tuse keywords for <version> instead of the v7.0 ones\n"
" -w<version>\ttokenize using keywords on specified Basic version.\n"
" -k<version>\tlist all keywords for the specified Basic version\n"
" -k\t\tlist all Basic versions available.\n"
" -l\t\tSpecify load address for program (in hex, no loading chars!).\n"
" -o <name>\tSpecify the output file name\n"
" -f\t\tForce overwritten the output file\n"
" \t\tThe default depends on the BASIC version.\n");
fprintf(stdout, "\n\tVersions:\n"
"\t1\tPET Basic V1.0\n"
"\t2\tBasic v2.0\n"
"\tsuper\tBasic v2.0 with Super Expander (VIC)\n"
"\tturtle\tBasic v2.0 with Turtle Basic by Craig Bruce (VIC)\n"
"\tmighty\tBasic v2.0 with Mighty Basic by Craig Bruce (VIC)\n"
"\ta\tBasic v2.0 with AtBasic (C64)\n"
"\tsimon\tBasic v2.0 with Simon's Basic extension (C64)\n"
"\tspeech\tBasic v2.0 with Speech Basic v2.7 (C64)\n"
"\tF\tBasic v2.0 with Final Cartridge III (C64)\n"
"\tultra\tBasic v2.0 with Ultrabasic-64 (C64)\n"
"\tgraph\tBasic v2.0 with Graphics basic (C64)\n"
"\tWSB\tBasic v2.0 with WS basic (C64)\n"
"\tWSBF\tBasic v2.0 with WS basic final (C64)\n"
"\tPegasus\tBasic v2.0 with Pegasus basic 4.0 (C64)\n"
"\tXbasic\tBasic v2.0 with Xbasic (C64)\n"
"\tDrago\tBasic v2.0 with Drago basic 2.2 (C64)\n"
"\tREU\tBasic v2.0 with REU-basic (C64)\n"
"\tLightning\tBasic v2.0 with Basic Lightning (C64)\n"
"\tmagic\tBasic v2.0 with Magic Basic (C64)\n"
"\teasy\tBasic v2.0 with Easy Basic (VIC20)\n"
"\tblarg\tBasic v2.0 with Blarg (C64)\n"
"\tGame\tBasic v2.0 with Game Basic (C64)\n"
"\t4 -w4e\tPET Basic v4.0 program (PET/C64)\n"
"\t3\tBasic v3.5 program (C16)\n"
"\t4v\tBasic 2.0 with Basic 4.0 extensions (VIC20)\n"
"\t5\tBasic 2.0 with Basic 5.0 extensions (VIC20)\n"
"\t70\tBasic v7.0 program (C128)\n"
"\t71\tBasic v7.1 program (C128)\n"
"\t10\tBasic v10.0 program (C64DX)\n\n");
fprintf(stdout, "\tUsage examples:\n"
"\tpetcat -2 -o outputfile.txt -- inputfile.prg\n"
"\t\tConvert inputfile.prg to a text file in outputfile.txt,\n"
"\t\tusing BASIC V2 only\n"
"\tpetcat -wsimon -o outputfile.prg -- inputfile.txt\n"
"\t\tConvert inputfile.txt to a PRG file in outputfile.prg,\n"
"\t\tusing Simon's BASIC\n");
exit(1);
}
/*
* Check parameters
*/
if (argc)
fil++;
if (hdr==-1)
hdr = outf ? 0 : 1;
if (version == B_10) {
keyword[0x63] = "paste";
keyword[0x64] = "cut";
keyword[0x65] = "line";
keyword[0x6e] = "dir";
kwfe[0x1f] = "dma";
kwfe[0x21] = "dma";
kwfe[0x23] = "dma";
}
if (show_words) {
list_keywords(version);
return (0);
}
if (ctrls < 0)
ctrls = (textmode ? 0 : 1); /*default ON for prgs, OFF for text */
if (!load_addr) {
switch (version) {
case B_PEG:
case B_SUPER:
load_addr = 0x0401;
break;
case B_TURTLE:
load_addr = 0x3701;
break;
case B_GRAPH:
case B_35:
load_addr = 0x1001;
break;
case B_71:
case B_7:
load_addr = 0x1c01;
break;
case B_10:
load_addr = 0x2001;
break;
case B_ULTRA:
load_addr = 0x2c01;
break;
case B_EASY:
load_addr = 0x3001;
break;
case B_MIGHTY:
load_addr = 0x3201;
break;
default:
load_addr = 0x0801;
}
}
if (wr_mode) {
fprintf (stderr, "\nLoad address %04x\n", load_addr);
if ((load_addr & 255) != 1) {
fprintf (stderr, "I'm afraid I cannot accept that.\n");
exit(1);
}
fprintf(stderr, "Control code set: %s\n\n",
(ctrls ? "enabled" : "disabled"));
}
/*
* Loop all files
*/
do {
int plen = 0;
flg = 0; /* stdin loop flag */