xref: /freebsd/contrib/file/magic/Magdir/c64 (revision ae316d1d1cffd71ab7751f94e10118777a88e027)
1
2#------------------------------------------------------------------------------
3# $File: c64,v 1.16 2024/03/07 22:30:21 christos Exp $
4# c64:  file(1) magic for various commodore 64 related files
5#
6# From: Dirk Jagdmann <doj@cubic.org>
7
80x16500	belong		0x12014100	D64 Image
90x16500	belong		0x12014180	D71 Image
100x61800 belong		0x28034400	D81 Image
110	belong		0x43154164	X64 Image
12
13# C64 (and other CBM) cartridges
14# Extended by David Korth <gerbilsoft@gerbilsoft.com>
15# Update:	Joerg Jenderek
16# Reference: https://vice-emu.sourceforge.io/vice_17.html#SEC391
17#		http://ist.uwaterloo.ca/~schepers/formats/CRT.TTX
18#		http://mark0.net/download/triddefs_xml.7z/defs/c/crt-c64.trid.xml
19# Note:		called "C64 Cartridge image" by TrID and
20#		"CRT C64 Cartridge Image Format" by DROID via PUID fmt/822
21
220	string		C64\40CARTRIDGE
23# skip DROID fmt-822-signature-id-1179.crt with missing packet length
24>0x44	ubelong		>0x10
25>>0	use		c64-crt
26#	display Commodore 64 cartridge information
270	name		c64-crt
28>0	string		x		Commodore 64 cartridge
29#!:mime	application/octet-stream
30!:mime	application/x-commodore-crt
31!:ext	crt
32#		http://mark0.net/download/triddefs_xml.7z/defs/c/car-ccs64.trid.xml
33#!:ext	crt/car
34>0x20	ubyte	0	\b,
35>0x20	ubyte	!0
36# 32-byte null padded cartridge name like: "BUGS BUNNY" "CART64" "EasyFlash" "FINAL CARTRIDGE" "Magic Desk" "VICE CART"
37>>0x20	string/T	x	\b: "%.32s",
38# cartridge hardware type
39>0x16	beshort	0
40# cartridge port EXROM line status
41>>0x18	beshort	0x0000	16 KB game
42>>0x18	beshort	0x0001	8 KB game
43>>0x18	beshort	0x0100	UltiMax mode
44>>0x18	beshort	0x0101	RAM/disabled
45>0x16	beshort	1	Action Replay
46>0x16	beshort	2	KCS Power Cartridge
47>0x16	beshort	3	Final Cartridge III
48>0x16	beshort	4	Simons' BASIC
49>0x16	beshort	5	Ocean type 1
50>0x16	beshort	6	Expert Cartridge
51>0x16	beshort	7	Fun Play, Power Play
52>0x16	beshort	8	Super Games
53>0x16	beshort	9	Atomic Power
54>0x16	beshort	10	Epyx Fastload
55>0x16	beshort	11	Westermann Learning
56>0x16	beshort	12	Rex Utility
57>0x16	beshort	13	Final Cartridge I
58>0x16	beshort	14	Magic Formel
59>0x16	beshort	15	C64 Game System, System 3
60>0x16	beshort	16	Warp Speed
61>0x16	beshort	17	Dinamic
62>0x16	beshort	18	Zaxxon / Super Zaxxon (Sega)
63>0x16	beshort	19	Magic Desk, Domark, HES Australia
64>0x16	beshort	20	Super Snapshot V5
65>0x16	beshort	21	Comal-80
66>0x16	beshort	22	Structured BASIC
67>0x16	beshort	23	Ross
68>0x16	beshort	24	Dela EP64
69>0x16	beshort	25	Dela EP7x8
70>0x16	beshort	26	Dela EP256
71>0x16	beshort	27	Rex EP256
72>0x16	beshort	28	Mikro Assembler
73>0x16	beshort	29	Final Cartridge Plus
74>0x16	beshort	30	Action Replay 4
75>0x16	beshort	31	Stardos
76>0x16	beshort	32	EasyFlash
77>0x16	beshort	33	EasyFlash Xbank
78>0x16	beshort	34	Capture
79>0x16	beshort	35	Action Replay 3
80>0x16	beshort	36
81# cartridge Hardware Revision/Subtype (usually 0) (added in v1.01)
82>>0x1A	ubyte	1	Nordic Replay
83>>0x1A	ubyte	!1	Retro Replay
84>0x16	beshort	37	MMC64
85>0x16	beshort	38	MMC Replay
86>0x16	beshort	39	IDE64
87>0x16	beshort	40	Super Snapshot V4
88>0x16	beshort	41	IEEE-488
89>0x16	beshort	42	Game Killer
90>0x16	beshort	43	Prophet64
91>0x16	beshort	44	EXOS
92>0x16	beshort	45	Freeze Frame
93>0x16	beshort	46	Freeze Machine
94>0x16	beshort	47	Snapshot64
95>0x16	beshort	48	Super Explode V5.0
96>0x16	beshort	49	Magic Voice
97>0x16	beshort	50	Action Replay 2
98>0x16	beshort	51	MACH 5
99>0x16	beshort	52	Diashow-Maker
100>0x16	beshort	53	Pagefox
101>0x16	beshort	54	Kingsoft
102>0x16	beshort	55	Silverrock 128K Cartridge
103>0x16	beshort	56	Formel 64
104>0x16	beshort	57
105>>0x1A	ubyte	1	Hucky
106>>0x1A	ubyte	!1	RGCD
107>0x16	beshort	58	RR-Net MK3
108>0x16	beshort	59	EasyCalc
109>0x16	beshort	60	GMod2
110>0x16	beshort	61	MAX Basic
111>0x16	beshort	62	GMod3
112>0x16	beshort	63	ZIPP-CODE 48
113>0x16	beshort	64	Blackbox V8
114>0x16	beshort	65	Blackbox V3
115>0x16	beshort	66	Blackbox V4
116>0x16	beshort	67	REX RAM-Floppy
117>0x16	beshort	68	BIS-Plus
118>0x16	beshort	69	SD-BOX
119>0x16	beshort	70	MultiMAX
120>0x16	beshort	71	Blackbox V9
121>0x16	beshort	72	Lt. Kernal Host Adaptor
122>0x16	beshort	73	RAMLink
123>0x16	beshort	74	H.E.R.O.
124>0x16	beshort	75	IEEE Flash! 64
125>0x16	beshort	76	Turtle Graphics II
126>0x16	beshort	77	Freeze Frame MK2
127>0x16	beshort	78	Partner 64
128# cartridge hardware type: (0-78)
129>0x16	ubeshort >78	unknown type %#x
130# Cartridge Hardware Revision/Subtype (usually 0 added in v1.01)
131>>0x1A	ubyte	>0	revision %#x
132# padded with 3 space characters for CRT but for CCS64 Cartridge (*.CAR) maybe different according to TrID
133>14	ubeshort	!0x2020	\b, at 14 %#x
134# file header length like: 20h (reported wrong) 40h (default and minimum)
135>0x10	ubelong	!0x40	\b, header length %#x
136# cartridge version like: 1.0 1.1 (adds CRT sub type/hardware revision) 2.0 (introduces VIC20, PLUS4, C128, CBM2)
137>0x14	ubeshort	!0x0100
138>>0x14	ubyte		x	\b, version %u
139>>0x15	ubyte		x	\b.%u
140# cartridge content start with ROM signature which must be CHIP
141>0x40	ubelong	!0x43484950	\b, invalid ROM signature
142>>0x40	string	x		"%0.4s"
143# total packet length (length of ROM image size and header combined) like: 2010h 4010h
144>0x44	ubelong	x	\b, packet length %#x
145
1460	string		C128\40CARTRIDGE	Commodore 128 cartridge
147>0x20	ubyte	0	\b,
148>0x20	ubyte	!0
149>>0x20	string/T	x	\b: "%.32s",
150>0x16	beshort	0	generic cartridge
151>0x16	beshort	1	Warpspeed128
152>>0x1A	ubyte	1	\b, REU support
153>>0x1A	ubyte	2	\b, REU support, with I/O and ROM banking
154
1550	string		CBM2\40CARTRIDGE	Commodore CBM-II cartridge
156>0x20	ubyte	!0
157>>0x20	string/T	x	\b: "%.32s"
158
1590	string		VIC20\40CARTRIDGE	Commodore VIC-20 cartridge
160>0x20	ubyte	0	\b,
161>0x20	ubyte	!0
162>>0x20	string/T	x	\b: "%.32s",
163>0x16	beshort	0	generic cartridge
164>0x16	beshort	1	Mega-Cart
165>0x16	beshort	2	Behr Bonz
166>0x16	beshort	3	Vic Flash Plugin
167>0x16	beshort	4	UltiMem
168>0x16	beshort	5	Final Expansion
169
1700	string		PLUS4\40CARTRIDGE	Commodore 16/Plus4 cartridge
171>0x20	ubyte	!0
172>>0x20	string/T	x	\b: "%.32s"
173
174
175# DreamLoad archives see:
176# https://www.lemon64.com/forum/viewtopic.php?t=37415\
177# &sid=494dc2ca91289e05dadf80a7f8a968fe (at the bottom).
178# https://www.c64-wiki.com/wiki/DreamLoad.
179# Example HVSC Commodore 64 music collection:
180# https://kohina.duckdns.org/HVSC/C64Music/10_Years_HVSC.dfi
181
1820	byte	0
183>1	string	DREAMLOAD\40FILE\40ARCHIVE
184>>0x17	byte	0	DFI Image
185>>>0x1a	leshort	x	version: %d.
186>>>0x18	leshort	x	\b%d
187>>>0x1c	lelong	x	tracks: %d
188
1890	string		GCR-1541	GCR Image
190>8	byte		x		version: %i
191>9	byte		x		tracks: %i
192
1939	string		PSUR		ARC archive (c64)
1942	string		-LH1-		LHA archive (c64)
195
1960	string		C64File		PC64 Emulator file
197>8	string		>\0		"%s"
1980	string		C64Image	PC64 Freezer Image
199
2000	beshort		0x38CD		C64 PCLink Image
2010	string		CBM\144\0\0	Power 64 C64 Emulator Snapshot
202
2030	belong		0xFF424CFF	WRAptor packer (c64)
204
205# URL:		http://fileformats.archiveteam.org/wiki/T64
206# Reference:	http://ist.uwaterloo.ca/~schepers/formats/T64.TXT
207#		https://vice-emu.sourceforge.io/vice_16.html#SEC394
208#		https://www.infinite-loop.at/Power64/Documentation/Power64-ReadMe/AE-File_Formats.html
209#		http://mark0.net/download/triddefs_xml.7z/defs/e/emu-t64.trid.xml
210# Note:		called "Commodore 64 Tape container" by TrID, "T64 Tape Image Format" by DROID via PUID fmt/820 and
211# 		"T64 tape Image" by ./c64,v 1.14
212#		verified by command like `deark -m t64 -l -d2 Caitan_the_Demo.t64` and
213#		`cbmconvert -v2 -t -D4 ironmanoffroad.d64 ironmanoffroad.t64`
214# 32 byte signature starting like C64S\x20tape\x20file
215# C64\x20tape\x20image\x20file\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0
216# C64S\x20tape\x20image\x20file\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0
2170	string/b	C64
218# skip raw Commodore TAPe by check for unsed areas (\0 filled) and valid low (40h+m*20h; m=0-FFffh) offset
219>0x46	ubequad&0xFFff1F00C0ffFFff	0	Commodore Tape image
220#!:mime	application/octet-stream
221#!:mime	application/x-commodore-tape
222!:ext	t64
223# version like: 0100h (examples found) 0101h 0200h (no examples)
224>>32	leshort		x		Version:%#x
225#>>32	leshort		!0x0100		Version:%#x
226# number of used directory entries like: 0 1 2 5
227>>36	leshort		!0		Entries:%i
228# tape container name, 24 characters (padded with 20h but with A0h for DirMaster created samples) like:
229# ->ZYRON'S PD<- IMAGETAPE MY-T64-TEST\240\240\240 OPERATIONWOLF+3-711.T64
230>>40	string/24/Tb	>\040		Name:%.24s
231# MaxFiles; maximal directory entries like: 0 1 2 5 30 (=1Eh some emulators expect exactly this value) 31 32
232>>34	uleshort	x		MaxFiles:%u
233# 1st C64 filetype: 0~free 1~normal tape file 2~tape file with header 3~memory snapshot 4~tape block 5~digitized stream 6-255~reserved
234>>0x40	ubyte		!1		\b, C64 file type %#x
235# 1st start address or load address of first entry like: 0000 (empty|snapshot) 04a0h (ironmanoffroad.t64) 0801h (typically) 1201h (3501_quizmaster_program_s1.t64)
236>>0x42	uleshort	!0x0801		\b, load address %#4.4x
237# 1st actual end address in memory
238>>0x44	uleshort	x		\b, end address %#4.4x
239# reserved; must be 0
240>>0x26	ubeshort	!0		\b, at +0x26 %#x
241# not used like: 0 (examples found and according to TrID)
242>>0x46	ubeshort	!0		\b, at 0x46 %#4.4x
243# not used like: 0 (examples found and according to TrID)
244>>0x4c	ubelong		!0		\b, at 0x4C %#8.8x
245# offset (=64+32*m) into 1st container file like: 0 (empty) 60h 80h E0h 400h 440h ...
246>>0x48	ulelong		>0		\b, at %#x
247# 1st filename (in PETASCII, padded with 20h, not A0h) like: "DRILLINSTR. /HTL" "WIZBALL+        " ...
248>>>0x50	string/16/bT	x		"%0.16s"
249# https://www.lyonlabs.org/commodore/onrequest/Inside_Commodore_Dos.pdf
250# file type like: 0~Scratched 1~SEQunclosed 81h~SEQ 82h~PRG C2h~PRGlocked ...
251>>>0x41	ubyte		x
252>>>>0x41	ubyte	=0x00		Scratched type
253>>>>0x41	ubyte	=0x01		SEQ unclosed type
254#>>>>0x41	ubyte	=0x44		foo type
255>>>>0x41	ubyte	=0x80		DEL type
256>>>>0x41	ubyte	=0x81		SEQ type
257>>>>0x41	ubyte	=0x82		PRG type
258>>>>0x41	ubyte	=0x83		USR type
259>>>>0x41	ubyte	=0x84		REL type
260>>>>0x41	ubyte	=0xC2		PRG locked type
261# other 	unusual file type
262>>>>0x41	default	x
263>>>>>0x41	ubyte	x		%#2.2x type
264# inspect 1st entry content (often Commodore C64 BASIC program *.PRG) without load adress
265#>>(0x48.l)	ubequad		x	\b, 1st data %16.16llx...
266
267# Raw tape file format (.tap files)
268# Esa Hyyti <esa@netlab.tkk.fi>
269# Update:	Joerg Jenderek
270# URL:		http://fileformats.archiveteam.org/wiki/Tap_file
271#		https://vice-emu.sourceforge.io/vice_16.html#SEC392
272# Reference:	http://ist.uwaterloo.ca/~schepers/formats/TAP.TXT
273# Note:		called "TAP (Commodore 64)" by DROID via PUID fmt/802
274#		a variant starting with C16-TAPE-RAW should exist, but no examples found
2750	string/b	C64-TAPE-RAW	Commodore raw Tape image (platform
276#0	string		C64-TAPE-RAW	C64 Raw Tape File (.tap),
277#!:mime	application/octet-stream
278!:mime	application/x-commodore-tape
279!:ext	tap
280# According to TrID als raw suffix, but no such samples found
281#!:ext	tap/raw
282# computer platform like: 0~C64 1~VIC-20 2~C16 Plus/4 3~PET 4~C5x0 5~C6x0 C7x0
283>0xD	ubyte		0		C64
284>0xD	ubyte		1		VIC-20
285>0xD	ubyte		2		C16 Plus/4
286>0xD	ubyte		3		PET
287>0xD	ubyte		4		C5x0
288>0xD	ubyte		5		C6x0 C7x0
289# this should not happen!
290>0xD	ubyte		>5		%#2.2x
291>0xD	ubyte		x		\b),
292# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/t/tap.trid.xml
293#		http://mark0.net/download/triddefs_xml.7z/defs/t/tap-1.trid.xml
294# Note:		called "C64 Tape image format" (v0-original) (v1-updated)" by TrID
295# TAP version like: 0~OriginalLayout 1~Updated (often)
296>0x0c	byte		x		Version:%u,
297# file data size (not including header)
298>0x10	lelong		x		Length:%u cycles
299# video standard like: 0~PAL 1~NTSC 2~OLD NTSC 3~PALN
300>0xE	ubyte		x    		\b, video
301>0xE	ubyte		0		PAL
302>0xE	ubyte		1		NTSC
303>0xE	ubyte		2		old NTSC
304>0xE	ubyte		3		PALN
305# this should not happen!
306>0xE	ubyte		>3		%#2.2x
307# reserved for future expansion like: 0
308>0xF	ubyte		!0		\b, at 0xF %#2.2x
309# file data
310#>014	ubequad		x		\b, data %16.16llx
311
312# magic for Goattracker2, http://covertbitops.c64.org/
313# from Alex Myczko <alex@aiei.ch>
3140	string		GTS5		GoatTracker 2 song
315>4	string		>\0		\b, "%s"
316>36	string		>\0		\b by %s
317>68	string		>\0		\b (C) %s
318>100	byte		>0		\b, %u subsong(s)
319
320# CBM BASIC (cc65 compiled)
321# Summary:	binary executable or Basic program for Commodore C64 computers
322# Update:	Joerg Jenderek
323# URL:		http://fileformats.archiveteam.org/wiki/Commodore_BASIC_tokenized_file
324# Reference:	https://www.c64-wiki.com/wiki/BASIC_token
325#		https://github.com/thezerobit/bastext/blob/master/bastext.doc
326#		http://mark0.net/download/triddefs_xml.7z/defs/p/prg-c64.trid.xml
327# TODO:		unify Commodore BASIC/program sub routines
328# Note:		"PUCrunch archive data" moved from ./archive and merged with c64-exe
3290	leshort		0x0801
330# display Commodore C64 BASIC program (strength=50) after "Lynx archive" (strength=330) handled by ./archive
331#!:strength +0
332# if first token is not SYS this implies BASIC program in most cases
333>6		ubyte		!0x9e
334# but sELF-ExTRACTING-zIP executable unzp6420.prg contains SYS token at end of second BASIC line (at 0x35)
335>>23		search/30	\323ELF-E\330TRACTING-\332IP
336>>>0		use		c64-exe
337>>23		default		x
338>>>0		use		c64-prg
339# if first token is SYS this implies binary executable
340>6		ubyte		=0x9e
341>>0		use		c64-exe
342# display information about C64 binary executable (memory address, line number, token)
3430	name	c64-exe
344>0		uleshort	x	Commodore C64
345# http://a1bert.kapsi.fi/Dev/pucrunch/
346# start address 0801h; next offset 080bh; BASIC line number is 239=00EFh; BASIC instruction is SYS 2061
347# the above combination appartly also occur for other Commodore programs like: gunzip111.c64.prg
348# and there exist PUCrunch archive for other machines like C16 with other magics
349>0		string	\x01\x08\x0b\x08\xef\x00\x9e\x32\x30\x36\x31	program, probably PUCrunch archive data
350!:mime	application/x-compress-pucrunch
351!:ext	prg/pck
352>0		string	!\x01\x08\x0b\x08\xef\x00\x9e\x32\x30\x36\x31	program
353!:mime	application/x-commodore-exec
354!:ext	prg/
355# start address like: 801h
356>0		uleshort	!0x0801	\b, start address %#4.4x
357# 1st BASIC fragment
358>2		use		basic-line
359# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
360>(2.s-0x800)	ubyte		x
361>>&-1		ubyte		!0	\b, no EOL=%#x
362# valid 2nd BASIC fragment found only in sELF-ExTRACTING-zIP executable unzp6420.prg
363>>23		search/30	\323ELF-E\330TRACTING-\332IP
364# jump again from beginning
365>>>(2.s-0x800)	ubyte		x
366>>>>&0		use		basic-line
367# Zero-byte marking the end of the BASIC line
368>-3		ubyte		!0	\b, 3 last bytes %#2.2x
369# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
370>>-2		ubeshort	x	\b%4.4x
371# display information about tokenized C64 BASIC program (memory address, line number, token)
3720	name	c64-prg
373>0		uleshort	x	Commodore C64 BASIC program
374!:mime	application/x-commodore-basic
375# Tokenized BASIC programs were stored by Commodore as file type program "PRG" in separate field in directory structures.
376# So file name can have no suffix like in saveroms; When transferring to other platforms, they are often saved with .prg extensions.
377# BAS suffix is typically used for the BASIC source but also found in program pods.bas
378!:ext	prg/bas/
379# start address like: 801h
380>0		uleshort	!0x0801	\b, start address %#4.4x
381# 1st BASIC fragment
382>2		use		basic-line
383# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
384>(2.s-0x0800)	ubyte		x
385>>&-1		ubyte		!0	\b, no EOL=%#x
386# 2nd BASIC fragment
387>>&0		use		basic-line
388# zero-byte marking the end of the BASIC line
389>-3		ubyte		!0	\b, 3 last bytes %#2.2x
390# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
391>>-2		ubeshort	x	\b%4.4x
392# Summary:	binary executable or Basic program for Commodore C128 computers
393# URL:		https://en.wikipedia.org/wiki/Commodore_128
394# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/prg-c128.trid.xml
395# From:		Joerg Jenderek
396# Note:		Commodore 128 BASIC 7.0 variant; there exist varaints with different start addresses
3970		leshort		0x1C01
398!:strength	+1
399# GRR: line above with strength 51 (50+1) is too generic because it matches SVr3 curses screen image, big-endian with strength (50) handled by ./terminfo
400# probably skip SVr3 curses images with "invalid high" second line offset
401>2		uleshort	<0x1D02
402# skip foo with "invalid low" second line offset
403>>2		uleshort	>0x1C06
404# if first token is not SYS this implies BASIC program
405>>>6		ubyte		!0x9e
406>>>>0			use	c128-prg
407# if first token is SYS this implies binary executable
408>>>6		ubyte		=0x9e
409>>>>0		use		c128-exe
410# Summary:	binary executable or Basic program for Commodore C128 computers
411# Note:		Commodore 128 BASIC 7.1 extension by Rick Simon
412# start adress 132Dh
413#0		leshort		0x132D	THIS_IS_C128_7.1
414#>0			use	c128-prg
415# Summary:	binary executable or Basic program for Commodore C128 computers
416# Note:		Commodore 128 BASIC 7.0 saved with graphics mode enabled
417# start adress 4001h
418#0		leshort		0x4001	THIS_IS_C128_GRAPHIC
419#>0			use	c128-prg
420# display information about tokenized C128 BASIC program (memory address, line number, token)
4210	name	c128-prg
422>0		uleshort	x	Commodore C128 BASIC program
423!:mime	application/x-commodore-basic
424!:ext	prg
425# start address like: 1C01h
426>0		uleshort	!0x1C01	\b, start address %#4.4x
427# 1st BASIC fragment
428>2		use		basic-line
429# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
430>(2.s-0x1C00)	ubyte		x
431>>&-1		ubyte		!0	\b, no EOL=%#x
432# 2nd BASIC fragment
433>>&0		use		basic-line
434# Zero-byte marking the end of the BASIC line
435>-3		ubyte		!0	\b, 3 last bytes %#2.2x
436# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
437>>-2		ubeshort	x	\b%4.4x
438# display information about C128 program (memory address, line number, token)
4390	name	c128-exe
440>0		uleshort	x	Commodore C128 program
441!:mime	application/x-commodore-exec
442!:ext	prg/
443# start address like: 1C01h
444>0		uleshort	!0x1C01	\b, start address %#4.4x
445# 1st BASIC fragment
446>2		use		basic-line
447# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
448>(2.s-0x1C00)	ubyte		x
449>>&-1		ubyte		!0	\b, no EOL=%#x
450# no valid 2nd BASIC fragment in Commodore executables
451#>>&0		use		basic-line
452# Zero-byte marking the end of the BASIC line
453>-3		ubyte		!0	\b, 3 last bytes %#2.2x
454# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
455>>-2		ubeshort	x	\b%4.4x
456# Summary:	binary executable or Basic program for Commodore C16/VIC-20/Plus4 computers
457# URL:		https://en.wikipedia.org/wiki/Commodore_Plus/4
458# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/prg-vic20.trid.xml
459#		defs/p/prg-plus4.trid.xml
460# From:		Joerg Jenderek
461# Note:		there exist VIC-20 variants with different start address
462# GRR: line below is too generic because it matches Novell LANalyzer capture
463# with regular trace header record handled by ./sniffer
4640		leshort		0x1001
465# skip regular Novell LANalyzer capture (novell-2.tr1 novell-lanalyzer.tr1 novell-win10.tr1) with "invalid low" token value 54h
466>6		ubyte		>0x7F
467# skip regular Novell LANalyzer capture (novell-2.tr1 novell-lanalyzer.tr1 novell-win10.tr1) with "invalid low" second line offset 4Ch
468#>>2		uleshort	>0x1006	OFFSET_NOT_TOO_LOW
469# skip foo with "invalid high" second line offset but not for 0x123b (Minefield.prg)
470#>>>2		uleshort	<0x1102	OFFSET_NOT_TOO_HIGH
471# if first token is not SYS this implies BASIC program
472>>6		ubyte		!0x9e
473# valid second end of line separator implies BASIC program
474>>>(2.s-0x1000)		ubyte	=0
475>>>>0			use	c16-prg
476# invalid second end of line separator !=0 implies binary executable like: Minefield.prg
477>>>(2.s-0x1000)		ubyte	!0
478>>>>0			use	c16-exe
479# if first token is SYS this implies binary executable
480>>6		ubyte		=0x9e
481>>>0		use		c16-exe
482# display information about C16 program (memory address, line number, token)
4830	name	c16-exe
484>0		uleshort	x	Commodore C16/VIC-20/Plus4 program
485!:mime	application/x-commodore-exec
486!:ext	prg/
487# start address like: 1001h
488>0		uleshort	!0x1001	\b, start address %#4.4x
489# 1st BASIC fragment
490>2		use		basic-line
491# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
492>(2.s-0x1000)	ubyte		x
493>>&-1		ubyte		!0	\b, no EOL=%#x
494# no valid 2nd BASIC fragment in excutables
495#>>&0		use		basic-line
496# Zero-byte marking the end of the BASIC line
497>-3		ubyte		!0	\b, 3 last bytes %#2.2x
498# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
499>>-2		ubeshort	x	\b%4.4x
500# display information about tokenized C16 BASIC program (memory address, line number, token)
5010	name	c16-prg
502>0		uleshort	x	Commodore C16/VIC-20/Plus4 BASIC program
503!:mime	application/x-commodore-basic
504!:ext	prg
505# start address like: 1001h
506>0		uleshort	!0x1001	\b, start address %#4.4x
507# 1st BASIC fragment
508>2		use		basic-line
509# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
510>(2.s-0x1000)	ubyte		x
511>>&-1		ubyte		!0	\b, no EOL=%#x
512# 2nd BASIC fragment
513>>&0		use		basic-line
514# Zero-byte marking the end of the BASIC line
515>-3		ubyte		!0	\b, 3 last bytes %#2.2x
516# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
517>>-2		ubeshort	x	\b%4.4x
518# Summary:	binary executable or Basic program for Commodore VIC-20 computer with 8K RAM expansion
519# URL:		https://en.wikipedia.org/wiki/VIC-20
520# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/prg-vic20-8k.trid.xml
521# From:		Joerg Jenderek
522# Note:		Basic v2.0 with Basic v4.0 extension (VIC20); there exist VIC-20 variants with different start addresses
523# start adress 1201h
5240		leshort		0x1201
525# if first token is not SYS this implies BASIC program
526>6		ubyte		!0x9e
527>>0		use		vic-prg
528# if first token is SYS this implies binary executable
529>6		ubyte		=0x9e
530>>0		use		vic-exe
531# display information about Commodore VIC-20 BASIC+8K program (memory address, line number, token)
5320	name	vic-prg
533>0		uleshort	x	Commodore VIC-20 +8K BASIC program
534!:mime	application/x-commodore-basic
535!:ext	prg
536# start address like: 1201h
537>0		uleshort	!0x1201	\b, start address %#4.4x
538# 1st BASIC fragment
539>2		use		basic-line
540# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
541>(2.s-0x1200)	ubyte		x
542>>&-1		ubyte		!0	\b, no EOL=%#x
543# 2nd BASIC fragment
544>>&0		use		basic-line
545# Zero-byte marking the end of the BASIC line
546>-3		ubyte		!0	\b, 3 last bytes %#2.2x
547# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
548>>-2		ubeshort	x	\b%4.4x
549# display information about Commodore VIC-20 +8K program (memory address, line number, token)
5500	name	vic-exe
551>0		uleshort	x	Commodore VIC-20 +8K program
552!:mime	application/x-commodore-exec
553!:ext	prg/
554# start address like: 1201h
555>0		uleshort	!0x1201	\b, start address %#4.4x
556# 1st BASIC fragment
557>2		use		basic-line
558# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
559>(2.s-0x0400)	ubyte		x
560>>&-1		ubyte		!0	\b, no EOL=%#x
561# no valid 2nd BASIC fragment in excutables
562#>>&0		use		basic-line
563# Zero-byte marking the end of the BASIC line
564>-3		ubyte		!0	\b, 3 last bytes %#2.2x
565# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
566>>-2		ubeshort	x	\b%4.4x
567# Summary:	binary executable or Basic program for Commodore PET computers
568# URL:		https://en.wikipedia.org/wiki/Commodore_PET
569# Reference:	http://mark0.net/download/triddefs_xml.7z/defs/p/prg-pet.trid.xml
570# From:		Joerg Jenderek
571# start adress 0401h
5720		leshort		0x0401
573!:strength	+1
574# GRR: line above with strength 51 (50+1) is too generic because it matches TTComp archive data, ASCII, 1K dictionary
575# (strength=48=50-2) handled by ./archive and shared library (strength=50) handled by ./ibm6000
576# skip TTComp archive data, ASCII, 1K dictionary ttcomp-ascii-1k.bin with "invalid high" second line offset 4162h
577>2		uleshort	<0x0502
578# skip foo with "invalid low" second line offset
579#>>2		uleshort	>0x0406	OFFSET_NOT_TOO_LOW
580# skip bar with "invalid end of line"
581#>>>(2.s-0x0400)	ubyte		=0	END_OF_LINE_OK
582# if first token is not SYS this implies BASIC program
583>>6		ubyte		!0x9e
584>>>0		use		pet-prg
585# if first token is SYS this implies binary executable
586>>6		ubyte		=0x9e
587>>>0		use		pet-exe
588# display information about Commodore PET BASIC program (memory address, line number, token)
5890	name	pet-prg
590>0		uleshort	x	Commodore PET BASIC program
591!:mime	application/x-commodore-basic
592!:ext	prg
593# start address like: 0401h
594>0		uleshort	!0x0401	\b, start address %#4.4x
595# 1st BASIC fragment
596>2		use		basic-line
597# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
598>(2.s-0x0400)	ubyte		x
599# 2nd BASIC fragment
600>>&0		use		basic-line
601# zero-byte marking the end of the BASIC line
602>-3		ubyte		!0	\b, 3 last bytes %#2.2x
603# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
604>>-2		ubeshort	x	\b%4.4x
605# display information about Commodore PET program (memory address, line number, token)
6060	name	pet-exe
607>0		uleshort	x	Commodore PET program
608!:mime	application/x-commodore-exec
609!:ext	prg/
610# start address like: 0401h
611>0		uleshort	!0x0401	\b, start address %#4.4x
612# 1st BASIC fragment
613>2		use		basic-line
614# jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
615>(2.s-0x0400)	ubyte		x
616>>&-1		ubyte		!0	\b, no EOL=%#x
617# no valid 2nd BASIC fragment in excutables
618#>>&0		use		basic-line
619# Zero-byte marking the end of the BASIC line
620>-3		ubyte		!0	\b, 3 last bytes %#2.2x
621# Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
622>>-2		ubeshort	x	\b%4.4x
623# display information about tokenized BASIC line (memory address, line number, Token)
6240	name	basic-line
625# pointer to memory address of beginning of "next" BASIC line
626# greater then previous offset but maximal 100h difference
627>0		uleshort	x	\b, offset %#4.4x
628# offset 0x0000 indicates the end of BASIC program; so bytes afterwards may be some other data
629>0		uleshort	0
630# not line number but first 2 data bytes
631>>2		ubeshort	x	\b, data %#4.4x
632# not token but next 2 data bytes
633>>4		ubeshort	x	\b%4.4x
634# not token arguments but next data bytes
635>>6		ubequad		x 	\b%16.16llx
636>>14		ubequad		x 	\b%16.16llx...
637# like 0x0d20352020204c594e5820495820204259205749 "\r 5   LYNX IX  BY WILL CORLEY" for LyNX archive Darkon.lnx handled by ./archive
638#>>3		string		x 	"%-0.30s"
639>0		uleshort	>0
640# BASIC line number with range from 0 to 65520; practice to increment numbers by some value (5, 10 or 100)
641>>2		uleshort	x	\b, line %u
642# https://www.c64-wiki.com/wiki/BASIC_token
643# The "high-bit" bytes from #128-#254 stood for the various BASIC commands and mathematical operators
644>>4		ubyte		x	\b, token (%#x)
645# https://www.c64-wiki.com/wiki/REM
646>>4		string		\x8f	REM
647# remark string like: ** SYNTHESIZER BY RICOCHET **
648>>>5		string		>\0	%s
649#>>>>&1		uleshort	x	\b, NEXT OFFSET %#4.4x
650# https://www.c64-wiki.com/wiki/PRINT
651>>4		string		\x99	PRINT
652# string like: "Hello world" "\021 \323ELF-E\330TRACTING-\332IP (64 ONLY)\016\231":\2362141
653>>>5		string		x	%s
654#>>>>&0		ubequad		x	AFTER_PRINT=%#16.16llx
655# https://www.c64-wiki.com/wiki/POKE
656>>4		string		\x97	POKE
657# <Memory address>,<number>
658>>>5		regex		\^[0-9,\040]+	%s
659# BASIC command delimiter colon (:=3Ah)
660>>>>&-2		ubyte		=0x3A
661# after BASIC command delimiter colon remaining (<255) other tokenized BASIC commands
662>>>>>&0		string		x		"%s"
663# https://www.c64-wiki.com/wiki/SYS	0x9e=\236
664>>4		string		\x9e	SYS
665# SYS <Address> parameter is a 16-bit unsigned integer; in the range 0 - 65535
666>>>5		regex		\^[0-9]{1,5}	%s
667# maybe followed by spaces, "control-characters" or colon (:) followed by next commnds or in victracker.prg
668# (\302(43)\252256\254\302(44)\25236) /T.L.R/
669#>>>5		string		x	SYS_STRING="%s"
670# https://www.c64-wiki.com/wiki/GOSUB
671>>4		string		\x8d	GOSUB
672# <line>
673>>>5		string		>\0	%s
674