c64 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. #------------------------------------------------------------------------------
  2. # $File: c64,v 1.14 2023/06/16 19:24:06 christos Exp $
  3. # c64: file(1) magic for various commodore 64 related files
  4. #
  5. # From: Dirk Jagdmann <doj@cubic.org>
  6. 0x16500 belong 0x12014100 D64 Image
  7. 0x16500 belong 0x12014180 D71 Image
  8. 0x61800 belong 0x28034400 D81 Image
  9. 0 belong 0x43154164 X64 Image
  10. # C64 (and other CBM) cartridges
  11. # Extended by David Korth <gerbilsoft@gerbilsoft.com>
  12. # Reference: https://vice-emu.sourceforge.io/vice_17.html#SEC391
  13. 0 string C64\40CARTRIDGE Commodore 64 cartridge
  14. >0x20 ubyte 0 \b,
  15. >0x20 ubyte !0
  16. >>0x20 string/T x \b: "%.32s",
  17. >0x16 beshort 0
  18. >>0x18 beshort 0x0000 16 KB game
  19. >>0x18 beshort 0x0001 8 KB game
  20. >>0x18 beshort 0x0100 UltiMax mode
  21. >>0x18 beshort 0x0101 RAM/disabled
  22. >0x16 beshort 1 Action Replay
  23. >0x16 beshort 2 KCS Power Cartridge
  24. >0x16 beshort 3 Final Cartridge III
  25. >0x16 beshort 4 Simons' BASIC
  26. >0x16 beshort 5 Ocean type 1
  27. >0x16 beshort 6 Expert Cartridge
  28. >0x16 beshort 7 Fun Play, Power Play
  29. >0x16 beshort 8 Super Games
  30. >0x16 beshort 9 Atomic Power
  31. >0x16 beshort 10 Epyx Fastload
  32. >0x16 beshort 11 Westermann Learning
  33. >0x16 beshort 12 Rex Utility
  34. >0x16 beshort 13 Final Cartridge I
  35. >0x16 beshort 14 Magic Formel
  36. >0x16 beshort 15 C64 Game System, System 3
  37. >0x16 beshort 16 Warp Speed
  38. >0x16 beshort 17 Dinamic
  39. >0x16 beshort 18 Zaxxon / Super Zaxxon (Sega)
  40. >0x16 beshort 19 Magic Desk, Domark, HES Australia
  41. >0x16 beshort 20 Super Snapshot V5
  42. >0x16 beshort 21 Comal-80
  43. >0x16 beshort 22 Structured BASIC
  44. >0x16 beshort 23 Ross
  45. >0x16 beshort 24 Dela EP64
  46. >0x16 beshort 25 Dela EP7x8
  47. >0x16 beshort 26 Dela EP256
  48. >0x16 beshort 27 Rex EP256
  49. >0x16 beshort 28 Mikro Assembler
  50. >0x16 beshort 29 Final Cartridge Plus
  51. >0x16 beshort 30 Action Replay 4
  52. >0x16 beshort 31 Stardos
  53. >0x16 beshort 32 EasyFlash
  54. >0x16 beshort 33 EasyFlash Xbank
  55. >0x16 beshort 34 Capture
  56. >0x16 beshort 35 Action Replay 3
  57. >0x16 beshort 36
  58. >>0x1A ubyte 1 Nordic Replay
  59. >>0x1A ubyte !1 Retro Replay
  60. >0x16 beshort 37 MMC64
  61. >0x16 beshort 38 MMC Replay
  62. >0x16 beshort 39 IDE64
  63. >0x16 beshort 40 Super Snapshot V4
  64. >0x16 beshort 41 IEEE-488
  65. >0x16 beshort 42 Game Killer
  66. >0x16 beshort 43 Prophet64
  67. >0x16 beshort 44 EXOS
  68. >0x16 beshort 45 Freeze Frame
  69. >0x16 beshort 46 Freeze Machine
  70. >0x16 beshort 47 Snapshot64
  71. >0x16 beshort 48 Super Explode V5.0
  72. >0x16 beshort 49 Magic Voice
  73. >0x16 beshort 50 Action Replay 2
  74. >0x16 beshort 51 MACH 5
  75. >0x16 beshort 52 Diashow-Maker
  76. >0x16 beshort 53 Pagefox
  77. >0x16 beshort 54 Kingsoft
  78. >0x16 beshort 55 Silverrock 128K Cartridge
  79. >0x16 beshort 56 Formel 64
  80. >0x16 beshort 57
  81. >>0x1A ubyte 1 Hucky
  82. >>0x1A ubyte !1 RGCD
  83. >0x16 beshort 58 RR-Net MK3
  84. >0x16 beshort 59 EasyCalc
  85. >0x16 beshort 60 GMod2
  86. >0x16 beshort 61 MAX Basic
  87. >0x16 beshort 62 GMod3
  88. >0x16 beshort 63 ZIPP-CODE 48
  89. >0x16 beshort 64 Blackbox V8
  90. >0x16 beshort 65 Blackbox V3
  91. >0x16 beshort 66 Blackbox V4
  92. >0x16 beshort 67 REX RAM-Floppy
  93. >0x16 beshort 68 BIS-Plus
  94. >0x16 beshort 69 SD-BOX
  95. >0x16 beshort 70 MultiMAX
  96. >0x16 beshort 71 Blackbox V9
  97. >0x16 beshort 72 Lt. Kernal Host Adaptor
  98. >0x16 beshort 73 RAMLink
  99. >0x16 beshort 74 H.E.R.O.
  100. >0x16 beshort 75 IEEE Flash! 64
  101. >0x16 beshort 76 Turtle Graphics II
  102. >0x16 beshort 77 Freeze Frame MK2
  103. 0 string C128\40CARTRIDGE Commodore 128 cartridge
  104. >0x20 ubyte 0 \b,
  105. >0x20 ubyte !0
  106. >>0x20 string/T x \b: "%.32s",
  107. >0x16 beshort 0 generic cartridge
  108. >0x16 beshort 1 Warpspeed128
  109. >>0x1A ubyte 1 \b, REU support
  110. >>0x1A ubyte 2 \b, REU support, with I/O and ROM banking
  111. 0 string CBM2\40CARTRIDGE Commodore CBM-II cartridge
  112. >0x20 ubyte !0
  113. >>0x20 string/T x \b: "%.32s"
  114. 0 string VIC20\40CARTRIDGE Commodore VIC-20 cartridge
  115. >0x20 ubyte 0 \b,
  116. >0x20 ubyte !0
  117. >>0x20 string/T x \b: "%.32s",
  118. >0x16 beshort 0 generic cartridge
  119. >0x16 beshort 1 Mega-Cart
  120. >0x16 beshort 2 Behr Bonz
  121. >0x16 beshort 3 Vic Flash Plugin
  122. >0x16 beshort 4 UltiMem
  123. >0x16 beshort 5 Final Expansion
  124. 0 string PLUS4\40CARTRIDGE Commodore 16/Plus4 cartridge
  125. >0x20 ubyte !0
  126. >>0x20 string/T x \b: "%.32s"
  127. # DreamLoad archives see:
  128. # https://www.lemon64.com/forum/viewtopic.php?t=37415\
  129. # &sid=494dc2ca91289e05dadf80a7f8a968fe (at the bottom).
  130. # https://www.c64-wiki.com/wiki/DreamLoad.
  131. # Example HVSC Commodore 64 music collection:
  132. # https://kohina.duckdns.org/HVSC/C64Music/10_Years_HVSC.dfi
  133. 0 byte 0
  134. >1 string DREAMLOAD\40FILE\40ARCHIVE
  135. >>0x17 byte 0 DFI Image
  136. >>>0x1a leshort x version: %d.
  137. >>>0x18 leshort x \b%d
  138. >>>0x1c lelong x tracks: %d
  139. 0 string GCR-1541 GCR Image
  140. >8 byte x version: %i
  141. >9 byte x tracks: %i
  142. 9 string PSUR ARC archive (c64)
  143. 2 string -LH1- LHA archive (c64)
  144. 0 string C64File PC64 Emulator file
  145. >8 string >\0 "%s"
  146. 0 string C64Image PC64 Freezer Image
  147. 0 beshort 0x38CD C64 PCLink Image
  148. 0 string CBM\144\0\0 Power 64 C64 Emulator Snapshot
  149. 0 belong 0xFF424CFF WRAptor packer (c64)
  150. 0 string C64S\x20tape\x20file T64 tape Image
  151. >32 leshort x Version:%#x
  152. >36 leshort !0 Entries:%i
  153. >40 string x Name:%.24s
  154. 0 string C64\x20tape\x20image\x20file\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0 T64 tape Image
  155. >32 leshort x Version:%#x
  156. >36 leshort !0 Entries:%i
  157. >40 string x Name:%.24s
  158. 0 string C64S\x20tape\x20image\x20file\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0 T64 tape Image
  159. >32 leshort x Version:%#x
  160. >36 leshort !0 Entries:%i
  161. >40 string x Name:%.24s
  162. # Raw tape file format (.tap files)
  163. # Esa Hyyti <esa@netlab.tkk.fi>
  164. 0 string C64-TAPE-RAW C64 Raw Tape File (.tap),
  165. >0x0c byte x Version:%u,
  166. >0x10 lelong x Length:%u cycles
  167. # magic for Goattracker2, http://covertbitops.c64.org/
  168. # from Alex Myczko <alex@aiei.ch>
  169. 0 string GTS5 GoatTracker 2 song
  170. >4 string >\0 \b, "%s"
  171. >36 string >\0 \b by %s
  172. >68 string >\0 \b (C) %s
  173. >100 byte >0 \b, %u subsong(s)
  174. # CBM BASIC (cc65 compiled)
  175. # Summary: binary executable or Basic program for Commodore C64 computers
  176. # Update: Joerg Jenderek
  177. # URL: http://fileformats.archiveteam.org/wiki/Commodore_BASIC_tokenized_file
  178. # Reference: https://www.c64-wiki.com/wiki/BASIC_token
  179. # https://github.com/thezerobit/bastext/blob/master/bastext.doc
  180. # http://mark0.net/download/triddefs_xml.7z/defs/p/prg-c64.trid.xml
  181. # TODO: unify Commodore BASIC/program sub routines
  182. # Note: "PUCrunch archive data" moved from ./archive and merged with c64-exe
  183. 0 leshort 0x0801
  184. # display Commodore C64 BASIC program (strength=50) after "Lynx archive" (strength=330) handled by ./archive
  185. #!:strength +0
  186. # if first token is not SYS this implies BASIC program in most cases
  187. >6 ubyte !0x9e
  188. # but sELF-ExTRACTING-zIP executable unzp6420.prg contains SYS token at end of second BASIC line (at 0x35)
  189. >>23 search/30 \323ELF-E\330TRACTING-\332IP
  190. >>>0 use c64-exe
  191. >>23 default x
  192. >>>0 use c64-prg
  193. # if first token is SYS this implies binary executable
  194. >6 ubyte =0x9e
  195. >>0 use c64-exe
  196. # display information about C64 binary executable (memory address, line number, token)
  197. 0 name c64-exe
  198. >0 uleshort x Commodore C64
  199. # http://a1bert.kapsi.fi/Dev/pucrunch/
  200. # start address 0801h; next offset 080bh; BASIC line number is 239=00EFh; BASIC instruction is SYS 2061
  201. # the above combination appartly also occur for other Commodore programs like: gunzip111.c64.prg
  202. # and there exist PUCrunch archive for other machines like C16 with other magics
  203. >0 string \x01\x08\x0b\x08\xef\x00\x9e\x32\x30\x36\x31 program, probably PUCrunch archive data
  204. !:mime application/x-compress-pucrunch
  205. !:ext prg/pck
  206. >0 string !\x01\x08\x0b\x08\xef\x00\x9e\x32\x30\x36\x31 program
  207. !:mime application/x-commodore-exec
  208. !:ext prg/
  209. # start address like: 801h
  210. >0 uleshort !0x0801 \b, start address %#4.4x
  211. # 1st BASIC fragment
  212. >2 use basic-line
  213. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  214. >(2.s-0x800) ubyte x
  215. >>&-1 ubyte !0 \b, no EOL=%#x
  216. # valid 2nd BASIC fragment found only in sELF-ExTRACTING-zIP executable unzp6420.prg
  217. >>23 search/30 \323ELF-E\330TRACTING-\332IP
  218. # jump again from beginning
  219. >>>(2.s-0x800) ubyte x
  220. >>>>&0 use basic-line
  221. # Zero-byte marking the end of the BASIC line
  222. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  223. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  224. >>-2 ubeshort x \b%4.4x
  225. # display information about tokenized C64 BASIC program (memory address, line number, token)
  226. 0 name c64-prg
  227. >0 uleshort x Commodore C64 BASIC program
  228. !:mime application/x-commodore-basic
  229. # Tokenized BASIC programs were stored by Commodore as file type program "PRG" in separate field in directory structures.
  230. # So file name can have no suffix like in saveroms; When transferring to other platforms, they are often saved with .prg extensions.
  231. # BAS suffix is typically used for the BASIC source but also found in program pods.bas
  232. !:ext prg/bas/
  233. # start address like: 801h
  234. >0 uleshort !0x0801 \b, start address %#4.4x
  235. # 1st BASIC fragment
  236. >2 use basic-line
  237. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  238. >(2.s-0x0800) ubyte x
  239. >>&-1 ubyte !0 \b, no EOL=%#x
  240. # 2nd BASIC fragment
  241. >>&0 use basic-line
  242. # zero-byte marking the end of the BASIC line
  243. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  244. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  245. >>-2 ubeshort x \b%4.4x
  246. # Summary: binary executable or Basic program for Commodore C128 computers
  247. # URL: https://en.wikipedia.org/wiki/Commodore_128
  248. # Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/prg-c128.trid.xml
  249. # From: Joerg Jenderek
  250. # Note: Commodore 128 BASIC 7.0 variant; there exist varaints with different start addresses
  251. 0 leshort 0x1C01
  252. !:strength +1
  253. # 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
  254. # probably skip SVr3 curses images with "invalid high" second line offset
  255. >2 uleshort <0x1D02
  256. # skip foo with "invalid low" second line offset
  257. >>2 uleshort >0x1C06
  258. # if first token is not SYS this implies BASIC program
  259. >>>6 ubyte !0x9e
  260. >>>>0 use c128-prg
  261. # if first token is SYS this implies binary executable
  262. >>>6 ubyte =0x9e
  263. >>>>0 use c128-exe
  264. # Summary: binary executable or Basic program for Commodore C128 computers
  265. # Note: Commodore 128 BASIC 7.1 extension by Rick Simon
  266. # start adress 132Dh
  267. #0 leshort 0x132D THIS_IS_C128_7.1
  268. #>0 use c128-prg
  269. # Summary: binary executable or Basic program for Commodore C128 computers
  270. # Note: Commodore 128 BASIC 7.0 saved with graphics mode enabled
  271. # start adress 4001h
  272. #0 leshort 0x4001 THIS_IS_C128_GRAPHIC
  273. #>0 use c128-prg
  274. # display information about tokenized C128 BASIC program (memory address, line number, token)
  275. 0 name c128-prg
  276. >0 uleshort x Commodore C128 BASIC program
  277. !:mime application/x-commodore-basic
  278. !:ext prg
  279. # start address like: 1C01h
  280. >0 uleshort !0x1C01 \b, start address %#4.4x
  281. # 1st BASIC fragment
  282. >2 use basic-line
  283. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  284. >(2.s-0x1C00) ubyte x
  285. >>&-1 ubyte !0 \b, no EOL=%#x
  286. # 2nd BASIC fragment
  287. >>&0 use basic-line
  288. # Zero-byte marking the end of the BASIC line
  289. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  290. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  291. >>-2 ubeshort x \b%4.4x
  292. # display information about C128 program (memory address, line number, token)
  293. 0 name c128-exe
  294. >0 uleshort x Commodore C128 program
  295. !:mime application/x-commodore-exec
  296. !:ext prg/
  297. # start address like: 1C01h
  298. >0 uleshort !0x1C01 \b, start address %#4.4x
  299. # 1st BASIC fragment
  300. >2 use basic-line
  301. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  302. >(2.s-0x1C00) ubyte x
  303. >>&-1 ubyte !0 \b, no EOL=%#x
  304. # no valid 2nd BASIC fragment in Commodore executables
  305. #>>&0 use basic-line
  306. # Zero-byte marking the end of the BASIC line
  307. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  308. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  309. >>-2 ubeshort x \b%4.4x
  310. # Summary: binary executable or Basic program for Commodore C16/VIC-20/Plus4 computers
  311. # URL: https://en.wikipedia.org/wiki/Commodore_Plus/4
  312. # Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/prg-vic20.trid.xml
  313. # defs/p/prg-plus4.trid.xml
  314. # From: Joerg Jenderek
  315. # Note: there exist VIC-20 variants with different start address
  316. # GRR: line below is too generic because it matches Novell LANalyzer capture
  317. # with regular trace header record handled by ./sniffer
  318. 0 leshort 0x1001
  319. # skip regular Novell LANalyzer capture (novell-2.tr1 novell-lanalyzer.tr1 novell-win10.tr1) with "invalid low" token value 54h
  320. >6 ubyte >0x7F
  321. # skip regular Novell LANalyzer capture (novell-2.tr1 novell-lanalyzer.tr1 novell-win10.tr1) with "invalid low" second line offset 4Ch
  322. #>>2 uleshort >0x1006 OFFSET_NOT_TOO_LOW
  323. # skip foo with "invalid high" second line offset but not for 0x123b (Minefield.prg)
  324. #>>>2 uleshort <0x1102 OFFSET_NOT_TOO_HIGH
  325. # if first token is not SYS this implies BASIC program
  326. >>6 ubyte !0x9e
  327. # valid second end of line separator implies BASIC program
  328. >>>(2.s-0x1000) ubyte =0
  329. >>>>0 use c16-prg
  330. # invalid second end of line separator !=0 implies binary executable like: Minefield.prg
  331. >>>(2.s-0x1000) ubyte !0
  332. >>>>0 use c16-exe
  333. # if first token is SYS this implies binary executable
  334. >>6 ubyte =0x9e
  335. >>>0 use c16-exe
  336. # display information about C16 program (memory address, line number, token)
  337. 0 name c16-exe
  338. >0 uleshort x Commodore C16/VIC-20/Plus4 program
  339. !:mime application/x-commodore-exec
  340. !:ext prg/
  341. # start address like: 1001h
  342. >0 uleshort !0x1001 \b, start address %#4.4x
  343. # 1st BASIC fragment
  344. >2 use basic-line
  345. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  346. >(2.s-0x1000) ubyte x
  347. >>&-1 ubyte !0 \b, no EOL=%#x
  348. # no valid 2nd BASIC fragment in excutables
  349. #>>&0 use basic-line
  350. # Zero-byte marking the end of the BASIC line
  351. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  352. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  353. >>-2 ubeshort x \b%4.4x
  354. # display information about tokenized C16 BASIC program (memory address, line number, token)
  355. 0 name c16-prg
  356. >0 uleshort x Commodore C16/VIC-20/Plus4 BASIC program
  357. !:mime application/x-commodore-basic
  358. !:ext prg
  359. # start address like: 1001h
  360. >0 uleshort !0x1001 \b, start address %#4.4x
  361. # 1st BASIC fragment
  362. >2 use basic-line
  363. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  364. >(2.s-0x1000) ubyte x
  365. >>&-1 ubyte !0 \b, no EOL=%#x
  366. # 2nd BASIC fragment
  367. >>&0 use basic-line
  368. # Zero-byte marking the end of the BASIC line
  369. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  370. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  371. >>-2 ubeshort x \b%4.4x
  372. # Summary: binary executable or Basic program for Commodore VIC-20 computer with 8K RAM expansion
  373. # URL: https://en.wikipedia.org/wiki/VIC-20
  374. # Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/prg-vic20-8k.trid.xml
  375. # From: Joerg Jenderek
  376. # Note: Basic v2.0 with Basic v4.0 extension (VIC20); there exist VIC-20 variants with different start addresses
  377. # start adress 1201h
  378. 0 leshort 0x1201
  379. # if first token is not SYS this implies BASIC program
  380. >6 ubyte !0x9e
  381. >>0 use vic-prg
  382. # if first token is SYS this implies binary executable
  383. >6 ubyte =0x9e
  384. >>0 use vic-exe
  385. # display information about Commodore VIC-20 BASIC+8K program (memory address, line number, token)
  386. 0 name vic-prg
  387. >0 uleshort x Commodore VIC-20 +8K BASIC program
  388. !:mime application/x-commodore-basic
  389. !:ext prg
  390. # start address like: 1201h
  391. >0 uleshort !0x1201 \b, start address %#4.4x
  392. # 1st BASIC fragment
  393. >2 use basic-line
  394. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  395. >(2.s-0x1200) ubyte x
  396. >>&-1 ubyte !0 \b, no EOL=%#x
  397. # 2nd BASIC fragment
  398. >>&0 use basic-line
  399. # Zero-byte marking the end of the BASIC line
  400. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  401. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  402. >>-2 ubeshort x \b%4.4x
  403. # display information about Commodore VIC-20 +8K program (memory address, line number, token)
  404. 0 name vic-exe
  405. >0 uleshort x Commodore VIC-20 +8K program
  406. !:mime application/x-commodore-exec
  407. !:ext prg/
  408. # start address like: 1201h
  409. >0 uleshort !0x1201 \b, start address %#4.4x
  410. # 1st BASIC fragment
  411. >2 use basic-line
  412. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  413. >(2.s-0x0400) ubyte x
  414. >>&-1 ubyte !0 \b, no EOL=%#x
  415. # no valid 2nd BASIC fragment in excutables
  416. #>>&0 use basic-line
  417. # Zero-byte marking the end of the BASIC line
  418. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  419. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  420. >>-2 ubeshort x \b%4.4x
  421. # Summary: binary executable or Basic program for Commodore PET computers
  422. # URL: https://en.wikipedia.org/wiki/Commodore_PET
  423. # Reference: http://mark0.net/download/triddefs_xml.7z/defs/p/prg-pet.trid.xml
  424. # From: Joerg Jenderek
  425. # start adress 0401h
  426. 0 leshort 0x0401
  427. !:strength +1
  428. # GRR: line above with strength 51 (50+1) is too generic because it matches TTComp archive data, ASCII, 1K dictionary
  429. # (strength=48=50-2) handled by ./archive and shared library (strength=50) handled by ./ibm6000
  430. # skip TTComp archive data, ASCII, 1K dictionary ttcomp-ascii-1k.bin with "invalid high" second line offset 4162h
  431. >2 uleshort <0x0502
  432. # skip foo with "invalid low" second line offset
  433. #>>2 uleshort >0x0406 OFFSET_NOT_TOO_LOW
  434. # skip bar with "invalid end of line"
  435. #>>>(2.s-0x0400) ubyte =0 END_OF_LINE_OK
  436. # if first token is not SYS this implies BASIC program
  437. >>6 ubyte !0x9e
  438. >>>0 use pet-prg
  439. # if first token is SYS this implies binary executable
  440. >>6 ubyte =0x9e
  441. >>>0 use pet-exe
  442. # display information about Commodore PET BASIC program (memory address, line number, token)
  443. 0 name pet-prg
  444. >0 uleshort x Commodore PET BASIC program
  445. !:mime application/x-commodore-basic
  446. !:ext prg
  447. # start address like: 0401h
  448. >0 uleshort !0x0401 \b, start address %#4.4x
  449. # 1st BASIC fragment
  450. >2 use basic-line
  451. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  452. >(2.s-0x0400) ubyte x
  453. # 2nd BASIC fragment
  454. >>&0 use basic-line
  455. # zero-byte marking the end of the BASIC line
  456. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  457. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  458. >>-2 ubeshort x \b%4.4x
  459. # display information about Commodore PET program (memory address, line number, token)
  460. 0 name pet-exe
  461. >0 uleshort x Commodore PET program
  462. !:mime application/x-commodore-exec
  463. !:ext prg/
  464. # start address like: 0401h
  465. >0 uleshort !0x0401 \b, start address %#4.4x
  466. # 1st BASIC fragment
  467. >2 use basic-line
  468. # jump to 1 byte before next BASIC fragment; this must be zero-byte marking the end of line
  469. >(2.s-0x0400) ubyte x
  470. >>&-1 ubyte !0 \b, no EOL=%#x
  471. # no valid 2nd BASIC fragment in excutables
  472. #>>&0 use basic-line
  473. # Zero-byte marking the end of the BASIC line
  474. >-3 ubyte !0 \b, 3 last bytes %#2.2x
  475. # Two zero-bytes in place of the pointer to next BASIC line indicates the end of the program
  476. >>-2 ubeshort x \b%4.4x
  477. # display information about tokenized BASIC line (memory address, line number, Token)
  478. 0 name basic-line
  479. # pointer to memory address of beginning of "next" BASIC line
  480. # greater then previous offset but maximal 100h difference
  481. >0 uleshort x \b, offset %#4.4x
  482. # offset 0x0000 indicates the end of BASIC program; so bytes afterwards may be some other data
  483. >0 uleshort 0
  484. # not line number but first 2 data bytes
  485. >>2 ubeshort x \b, data %#4.4x
  486. # not token but next 2 data bytes
  487. >>4 ubeshort x \b%4.4x
  488. # not token arguments but next data bytes
  489. >>6 ubequad x \b%16.16llx
  490. >>14 ubequad x \b%16.16llx...
  491. # like 0x0d20352020204c594e5820495820204259205749 "\r 5 LYNX IX BY WILL CORLEY" for LyNX archive Darkon.lnx handled by ./archive
  492. #>>3 string x "%-0.30s"
  493. >0 uleshort >0
  494. # BASIC line number with range from 0 to 65520; practice to increment numbers by some value (5, 10 or 100)
  495. >>2 uleshort x \b, line %u
  496. # https://www.c64-wiki.com/wiki/BASIC_token
  497. # The "high-bit" bytes from #128-#254 stood for the various BASIC commands and mathematical operators
  498. >>4 ubyte x \b, token (%#x)
  499. # https://www.c64-wiki.com/wiki/REM
  500. >>4 string \x8f REM
  501. # remark string like: ** SYNTHESIZER BY RICOCHET **
  502. >>>5 string >\0 %s
  503. #>>>>&1 uleshort x \b, NEXT OFFSET %#4.4x
  504. # https://www.c64-wiki.com/wiki/PRINT
  505. >>4 string \x99 PRINT
  506. # string like: "Hello world" "\021 \323ELF-E\330TRACTING-\332IP (64 ONLY)\016\231":\2362141
  507. >>>5 string x %s
  508. #>>>>&0 ubequad x AFTER_PRINT=%#16.16llx
  509. # https://www.c64-wiki.com/wiki/POKE
  510. >>4 string \x97 POKE
  511. # <Memory address>,<number>
  512. >>>5 regex \^[0-9,\040]+ %s
  513. # BASIC command delimiter colon (:=3Ah)
  514. >>>>&-2 ubyte =0x3A
  515. # after BASIC command delimiter colon remaining (<255) other tokenized BASIC commands
  516. >>>>>&0 string x "%s"
  517. # https://www.c64-wiki.com/wiki/SYS 0x9e=\236
  518. >>4 string \x9e SYS
  519. # SYS <Address> parameter is a 16-bit unsigned integer; in the range 0 - 65535
  520. >>>5 regex \^[0-9]{1,5} %s
  521. # maybe followed by spaces, "control-characters" or colon (:) followed by next commnds or in victracker.prg
  522. # (\302(43)\252256\254\302(44)\25236) /T.L.R/
  523. #>>>5 string x SYS_STRING="%s"
  524. # https://www.c64-wiki.com/wiki/GOSUB
  525. >>4 string \x8d GOSUB
  526. # <line>
  527. >>>5 string >\0 %s