badline 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +102 -0
  3. data/CLAUDE.md +15 -7
  4. data/README.md +142 -16
  5. data/doc/media.md +19 -0
  6. data/doc/pinned-behaviour.md +67 -0
  7. data/doc/snapshot-format.md +274 -31
  8. data/doc/snapshots.md +14 -0
  9. data/exe/badline-ruby +1 -1
  10. data/lib/badline/audio/machine_player.rb +2 -14
  11. data/lib/badline/c64/common.rb +1 -1
  12. data/lib/badline/c64/true_drives.rb +13 -1
  13. data/lib/badline/c64.rb +6 -0
  14. data/lib/badline/chips/crtc/keyed_state.rb +46 -0
  15. data/lib/badline/chips/crtc.rb +163 -0
  16. data/lib/badline/chips/pia/control_lines.rb +138 -0
  17. data/lib/badline/chips/pia/keyed_parts.rb +56 -0
  18. data/lib/badline/chips/pia.rb +138 -0
  19. data/lib/badline/chips/tia.rb +16 -0
  20. data/lib/badline/core.rb +3 -0
  21. data/lib/badline/drives/datasette/keyed_state.rb +8 -3
  22. data/lib/badline/drives/engine/core.rb +6 -14
  23. data/lib/badline/drives/engine/idle.rb +42 -4
  24. data/lib/badline/drives/engine/idle_cpu.rb +18 -0
  25. data/lib/badline/drives/engine/serial_connection.rb +25 -0
  26. data/lib/badline/drives/engine/sleep.rb +1 -0
  27. data/lib/badline/drives/engine.rb +1 -0
  28. data/lib/badline/drives/ieee_bus.rb +28 -0
  29. data/lib/badline/drives/model1541/byte_ready.rb +19 -3
  30. data/lib/badline/drives/model1541/mechanism.rb +10 -1
  31. data/lib/badline/drives/model1541.rb +1 -0
  32. data/lib/badline/drives/model1551/bus.rb +138 -0
  33. data/lib/badline/drives/model1551/cable.rb +107 -0
  34. data/lib/badline/drives/model1551/cpu.rb +14 -0
  35. data/lib/badline/drives/model1551/keyed_state.rb +65 -0
  36. data/lib/badline/drives/model1551/port.rb +74 -0
  37. data/lib/badline/drives/model1551/tia.rb +71 -0
  38. data/lib/badline/drives/model1551.rb +192 -0
  39. data/lib/badline/drives/model1571.rb +1 -0
  40. data/lib/badline/drives/model1581.rb +1 -0
  41. data/lib/badline/drives.rb +1 -0
  42. data/lib/badline/frontend/app.rb +1 -1
  43. data/lib/badline/frontend/boot.rb +20 -1
  44. data/lib/badline/frontend/controls.rb +23 -3
  45. data/lib/badline/frontend/gamepads.rb +10 -3
  46. data/lib/badline/frontend/keys.rb +88 -0
  47. data/lib/badline/frontend/media_slots.rb +1 -0
  48. data/lib/badline/frontend/menu/menu_dialogs.rb +15 -6
  49. data/lib/badline/frontend/menu/menu_media.rb +96 -19
  50. data/lib/badline/frontend/menu/menu_pages.rb +25 -7
  51. data/lib/badline/frontend/menu/menu_ports.rb +22 -1
  52. data/lib/badline/frontend/menu/pause_menu.rb +1 -0
  53. data/lib/badline/frontend/pet_keyboard.rb +124 -0
  54. data/lib/badline/frontend/player/player_controller.rb +11 -4
  55. data/lib/badline/frontend/screens.rb +2 -1
  56. data/lib/badline/frontend/timeline.rb +16 -9
  57. data/lib/badline/frontend.rb +1 -0
  58. data/lib/badline/kernal_trap/dos/writes.rb +3 -1
  59. data/lib/badline/kernal_trap/dos.rb +6 -1
  60. data/lib/badline/kernal_trap/frames.rb +117 -0
  61. data/lib/badline/kernal_trap/ieee.rb +148 -0
  62. data/lib/badline/kernal_trap/ieee_layout.rb +113 -0
  63. data/lib/badline/kernal_trap/keyed_state.rb +4 -4
  64. data/lib/badline/kernal_trap/routine.rb +3 -53
  65. data/lib/badline/kernal_trap/serial.rb +4 -102
  66. data/lib/badline/kernal_trap/steps.rb +64 -0
  67. data/lib/badline/kernal_trap.rb +4 -0
  68. data/lib/badline/machine/keyboard_buffer.rb +8 -0
  69. data/lib/badline/machine/settling.rb +1 -1
  70. data/lib/badline/machine.rb +37 -11
  71. data/lib/badline/media/extensions.rb +5 -2
  72. data/lib/badline/media/pet_media.rb +40 -0
  73. data/lib/badline/media/program.rb +14 -2
  74. data/lib/badline/media/true_drive.rb +7 -5
  75. data/lib/badline/media/vic20_media.rb +2 -2
  76. data/lib/badline/media.rb +36 -16
  77. data/lib/badline/options/family.rb +17 -6
  78. data/lib/badline/options/help.rb +23 -5
  79. data/lib/badline/options/option.rb +2 -1
  80. data/lib/badline/options/table.rb +28 -4
  81. data/lib/badline/options/validation.rb +117 -14
  82. data/lib/badline/options.rb +65 -21
  83. data/lib/badline/pet/bus/expansion.rb +106 -0
  84. data/lib/badline/pet/bus.rb +204 -0
  85. data/lib/badline/pet/canvas.rb +97 -0
  86. data/lib/badline/pet/cassettes.rb +63 -0
  87. data/lib/badline/pet/characters.rb +26 -0
  88. data/lib/badline/pet/cpu.rb +10 -0
  89. data/lib/badline/pet/crtc_video.rb +142 -0
  90. data/lib/badline/pet/discrete_video.rb +83 -0
  91. data/lib/badline/pet/ieee_ports.rb +66 -0
  92. data/lib/badline/pet/ieee_traps.rb +75 -0
  93. data/lib/badline/pet/keyboard_ports.rb +74 -0
  94. data/lib/badline/pet/keyed_modules.rb +85 -0
  95. data/lib/badline/pet/keyed_parts.rb +123 -0
  96. data/lib/badline/pet/keyed_state.rb +42 -0
  97. data/lib/badline/pet/model.rb +113 -0
  98. data/lib/badline/pet/rom_sets.rb +65 -0
  99. data/lib/badline/pet/sound.rb +128 -0
  100. data/lib/badline/pet/via.rb +10 -0
  101. data/lib/badline/pet/via_ports.rb +19 -0
  102. data/lib/badline/pet.rb +226 -0
  103. data/lib/badline/plus4/acia/frames.rb +55 -0
  104. data/lib/badline/plus4/acia.rb +276 -16
  105. data/lib/badline/plus4/bus.rb +181 -45
  106. data/lib/badline/plus4/keyed_modules.rb +22 -5
  107. data/lib/badline/plus4/keyed_parts.rb +33 -4
  108. data/lib/badline/plus4/keyed_state.rb +10 -5
  109. data/lib/badline/plus4/ram_expansion.rb +145 -0
  110. data/lib/badline/plus4/sid_card.rb +95 -0
  111. data/lib/badline/plus4/sound_mix.rb +51 -0
  112. data/lib/badline/plus4/tcbm_drive.rb +134 -0
  113. data/lib/badline/plus4/user_port.rb +11 -2
  114. data/lib/badline/plus4.rb +104 -22
  115. data/lib/badline/roms/README +146 -0
  116. data/lib/badline/roms/dos1551.rom +0 -0
  117. data/lib/badline/roms/pet/basic1.rom +0 -0
  118. data/lib/badline/roms/pet/basic2.rom +0 -0
  119. data/lib/badline/roms/pet/basic4.rom +0 -0
  120. data/lib/badline/roms/pet/characters1.rom +0 -0
  121. data/lib/badline/roms/pet/characters2.rom +0 -0
  122. data/lib/badline/roms/pet/editor1.rom +0 -0
  123. data/lib/badline/roms/pet/editor2-b.rom +0 -0
  124. data/lib/badline/roms/pet/editor2-n.rom +0 -0
  125. data/lib/badline/roms/pet/editor4-40-n-50hz.rom +0 -0
  126. data/lib/badline/roms/pet/editor4-40-n-60hz.rom +0 -0
  127. data/lib/badline/roms/pet/editor4-80-b-50hz-0283.rom +0 -0
  128. data/lib/badline/roms/pet/editor4-80-b-50hz.rom +0 -0
  129. data/lib/badline/roms/pet/editor4-80-b-60hz.rom +0 -0
  130. data/lib/badline/roms/pet/editor4-b.rom +0 -0
  131. data/lib/badline/roms/pet/editor4-n.rom +0 -0
  132. data/lib/badline/roms/pet/kernal1.rom +0 -0
  133. data/lib/badline/roms/pet/kernal2.rom +0 -0
  134. data/lib/badline/roms/pet/kernal4.rom +0 -0
  135. data/lib/badline/snapshot/container.rb +2 -0
  136. data/lib/badline/snapshot/field_doc/markdown.rb +1 -1
  137. data/lib/badline/snapshot/field_doc.rb +21 -6
  138. data/lib/badline/snapshot/image.rb +14 -7
  139. data/lib/badline/snapshot/pet_setup.rb +71 -0
  140. data/lib/badline/snapshot/plus4_setup.rb +52 -10
  141. data/lib/badline/snapshot/storage_setup.rb +7 -1
  142. data/lib/badline/snapshot.rb +9 -5
  143. data/lib/badline/storage/d80_image.rb +48 -0
  144. data/lib/badline/storage/d82_image.rb +21 -0
  145. data/lib/badline/storage/g64_image.rb +1 -1
  146. data/lib/badline/storage/tap.rb +16 -3
  147. data/lib/badline/storage.rb +2 -0
  148. data/lib/badline/support/pet_checkpoint.rb +38 -0
  149. data/lib/badline/timing.rb +5 -4
  150. data/lib/badline/version.rb +1 -1
  151. data/lib/badline/vic20/attachments.rb +7 -2
  152. data/lib/badline/vic20/bus/keyed_state.rb +5 -4
  153. data/lib/badline/vic20/bus.rb +5 -0
  154. data/lib/badline/vic20.rb +1 -1
  155. metadata +69 -1
@@ -20,6 +20,14 @@ module Badline
20
20
  # ($D86E).
21
21
  PLUS4_LAYOUT = Layout.new(address: 0x0527, count: 0xef, capacity: 10)
22
22
 
23
+ # The PET's, under BASIC 2 and BASIC 4. Every editor's GETIN takes
24
+ # ten keys from it, though the CRTC editors' keyboard scans stop at
25
+ # nine (XMAX).
26
+ PET_LAYOUT = Layout.new(address: 0x026f, count: 0x9e, capacity: 10)
27
+
28
+ # The PET's under BASIC 1, outside the zero page.
29
+ PET_BASIC1_LAYOUT = Layout.new(address: 0x020f, count: 0x020d, capacity: 10)
30
+
23
31
  def type_text(text)
24
32
  codes = text.bytes.map { |b| ascii_to_petscii(b) }
25
33
  on_init { @pending_keys = codes }
@@ -4,7 +4,7 @@ module Badline
4
4
  module Machine
5
5
  # Brings the machine to the point a snapshot file is saved at: the main
6
6
  # CPU between instructions, or jammed, with no REU transfer holding the
7
- # bus. C64, Vic20, C128 and Plus4 each include it, and answer
7
+ # bus. C64, Vic20, C128, Plus4 and PET each include it, and answer
8
8
  # #settled_for_snapshot? and #settle_chips_for_snapshot, which brings
9
9
  # what each chip defers up to the cycle without running one.
10
10
  module Settling
@@ -8,8 +8,9 @@ module Badline
8
8
  # = Machine
9
9
  #
10
10
  # The machines badline builds by family, as the command line's
11
- # subcommand names them: the C64, Badline::C64, the VIC-20, Vic20, and the
12
- # C128 in C64 mode, C128, and the 264 series, Plus4.
11
+ # subcommand names them: the C64, Badline::C64, the VIC-20, Vic20, the
12
+ # C128 in C64 mode, C128, the 264 series, Plus4, and the PET and CBM,
13
+ # PET.
13
14
  #
14
15
  # A machine answers what the front end, Media, the runners and the
15
16
  # snapshots call on it:
@@ -57,23 +58,31 @@ module Badline
57
58
  # and +capture_output+, and besides +model_label+, +cartridge_slots+ and
58
59
  # +detach_cartridges+ for its two cartridges.
59
60
  #
61
+ # The PET answers the identity, clocking, lifecycle, video, sound and
62
+ # keyboard parts, with no joysticks, RESTORE or control ports, and of
63
+ # the rest +ram+, +load_prg+, +type_text+, +mount+, +unmount+,
64
+ # +mounted?+, +datasette+, +true_drive+, nil, +install_debug_register+
65
+ # and +capture_output+, and besides +model_label+ and +ram_kb+.
66
+ #
60
67
  # Each machine includes Machine::Clocking for the clocking part.
61
68
  module Machine
62
69
  # Media the machine named doesn't take.
63
70
  class Unsupported < ArgumentError; end
64
71
 
65
- # A new machine of `family`, :c64, :vic20, :c128 or :plus4, the model
66
- # of it `model` names. A C64's model is one of Model::ALL, with its SID
72
+ # A new machine of `family`, :c64, :vic20, :c128, :plus4 or :pet, the
73
+ # model of it `model` names. A C64's model is one of Model::ALL, with its SID
67
74
  # `sid_model` when not nil and an REU of `reu` K when not nil. A
68
75
  # VIC-20's is "pal", with the RAM expansion `ram` names
69
76
  # (Vic20::Bus::RAM_CONFIGURATIONS), unexpanded when nil. A C128's is
70
77
  # one of C128::Model::ALL, with its SID `sid_model` when not nil, built
71
78
  # for C64 mode. A Plus/4's is one of Plus4::Model::ALL or c116, with
72
- # the model's own RAM.
79
+ # the model's own RAM. A PET's is one of PET::Model::ALL, with its own
80
+ # RAM and ROMs, its CRTC's editor the 50 Hz one.
73
81
  def self.build(family, model:, sid_model: nil, reu: nil, ram: nil)
74
82
  return vic20(model, ram) if family == :vic20
75
83
  return c128(model, sid_model, :c64) if family == :c128
76
84
  return Plus4.new(model:) if family == :plus4
85
+ return PET.new(model:) if family == :pet
77
86
  raise ArgumentError, "no machine family named #{family}" unless family == :c64
78
87
 
79
88
  profile = Model.named(model)
@@ -89,11 +98,12 @@ module Badline
89
98
  # only C64 mode runs: a .sid tune or a program that loads at the C64's
90
99
  # BASIC start. A VIC-20 without RAM named gets the expansion the media
91
100
  # needs (Media::Vic20Media.ram_for) and yields a line saying so. Raises
92
- # Unsupported for media a VIC-20 or a Plus/4 doesn't take.
101
+ # Unsupported for media a VIC-20, a Plus/4 or a PET doesn't take.
93
102
  def self.for_options(options, media, &)
94
103
  family = options.family
95
104
  return vic20_for(media, options.model, options.ram, &) if family == :vic20
96
- return plus4_for(media, options.model, options.ram_kb) if family == :plus4
105
+ return plus4_for(media, options) if family == :plus4
106
+ return pet_for(media, options) if family == :pet
97
107
 
98
108
  sid_model = options.sid_model || Media.sid_model(media, otherwise: nil)
99
109
  return build(:c64, model: options.model, sid_model:, reu: options.reu) unless family == :c128
@@ -127,16 +137,32 @@ module Badline
127
137
  end
128
138
  private_class_method :vic20_for
129
139
 
130
- # A Plus/4 with `ram_kb` K of RAM (Plus4::Model::RAM_SIZES), or with
131
- # the model's own when nil.
132
- def self.plus4_for(media, model, ram_kb)
140
+ # A Plus/4 with the RAM --ram names (Plus4::Model::RAM_SIZES), or with
141
+ # the model's own without it, the true drive --drive-type names, the
142
+ # SID card --sid-card names, where --sid-card-address puts it, and the
143
+ # RAM expansion --ram-expansion names.
144
+ def self.plus4_for(media, options)
133
145
  unsupported = !media.nil? && Media::Vic20Media::UNSUPPORTED.include?(File.extname(media).downcase)
134
146
  raise Unsupported, "doesn't go in a Plus/4" if unsupported
135
147
 
136
- Plus4.new(model:, ram: ram_kb)
148
+ Plus4.new(model: options.model, ram: options.ram_kb, true_drive_model: options.drive_type,
149
+ sid_card: options.sid_card, sid_card_address: options.sid_card_address || 0xfd40,
150
+ ram_expansion: options.ram_expansion)
137
151
  end
138
152
  private_class_method :plus4_for
139
153
 
154
+ # A PET with the RAM --ram names (PET::Model::RAM_SIZES), or with the
155
+ # model's own without it, the editor at the frame rate --60hz or
156
+ # --editor asks for, and the ROMs --basic and --editor fit it with.
157
+ def self.pet_for(media, options)
158
+ unsupported = !media.nil? && Media::PETMedia::UNSUPPORTED.include?(File.extname(media).downcase)
159
+ raise Unsupported, "doesn't go in a PET" if unsupported
160
+
161
+ PET.new(model: options.model, ram_kb: options.ram_kb, refresh_hz: options.refresh_hz, basic: options.basic,
162
+ editor: options.editor)
163
+ end
164
+ private_class_method :pet_for
165
+
140
166
  def self.c64_media?(media)
141
167
  return false if media.nil? || !File.file?(media)
142
168
 
@@ -7,6 +7,8 @@ module Badline
7
7
  # It loads on its own, for Options.
8
8
  #
9
9
  # - :disk, a disk image that the traps mount and a true drive reads
10
+ # - :ieee_disk, an 8050's or 8250's disk image, for a PET's IEEE-488
11
+ # drive
10
12
  # - :gcr, a disk's raw GCR, which only a true drive reads
11
13
  # - :archive, a .t64, which the traps mount read-only
12
14
  # - :tape, :cartridge and :tune
@@ -14,7 +16,8 @@ module Badline
14
16
  module Extensions
15
17
  KINDS = {
16
18
  ".d64" => :disk, ".d71" => :disk, ".d81" => :disk, ".g64" => :gcr, ".g71" => :gcr, ".t64" => :archive,
17
- ".tap" => :tape, ".crt" => :cartridge, ".sid" => :tune, ".m3u" => :disk_list, ".vfl" => :disk_list
19
+ ".d80" => :ieee_disk, ".d82" => :ieee_disk, ".tap" => :tape, ".crt" => :cartridge, ".sid" => :tune,
20
+ ".m3u" => :disk_list, ".vfl" => :disk_list
18
21
  }.freeze
19
22
 
20
23
  # The kind of the medium at `path`, by its extension.
@@ -27,7 +30,7 @@ module Badline
27
30
  DISKS = of(%i[disk gcr])
28
31
 
29
32
  # What goes in device 8 through the traps.
30
- MOUNTABLE = of(%i[disk archive])
33
+ MOUNTABLE = of(%i[disk archive ieee_disk])
31
34
 
32
35
  # What goes in device 8, a true drive's or the traps', and the lists
33
36
  # of disks to put there.
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Badline
4
+ module Media
5
+ # What a PET does with media of its own (Media.attach). Disks of every
6
+ # kind, .d80 and .d82 among them, directories and .t64 archives mount
7
+ # on device 8 through the traps on the KERNAL's IEEE-488 primitives
8
+ # (PET::IEEETraps), programs load at the start of BASIC, $0401
9
+ # (Program), and tapes play on the datasette at cassette port #1. There
10
+ # is no cartridge port and no SID, and the true drives are serial ones.
11
+ module PETMedia
12
+ # What a PET doesn't take.
13
+ UNSUPPORTED = Extensions.of(%i[tune cartridge gcr])
14
+
15
+ # What loads and runs the first program on the disk in device 8.
16
+ AUTOSTART = %(load"*",8\rrun\r)
17
+
18
+ # What loads and runs the first program on the tape in cassette #1.
19
+ TAPE_AUTOSTART = "load\rrun\r"
20
+
21
+ class << self
22
+ # A tape made for another machine plays all the same, and says so.
23
+ def tape_message(tape, message)
24
+ tape.platform == Storage::TAP::PET_PLATFORM ? message : "#{message}, a tape for another machine than the PET"
25
+ end
26
+
27
+ # BASIC 2 and 4 load the first program off the disk and run it.
28
+ # BASIC 1's LOAD finds no device on the IEEE-488 bus, so the first
29
+ # program goes in as a program file does, once the KERNAL has
30
+ # booted.
31
+ def disk_autostart(machine, storage)
32
+ return machine.type_text(AUTOSTART) unless machine.model.basic1?
33
+
34
+ data = storage.read_file("*")
35
+ machine.on_init { Program.load(machine, data, autostart: true) } if data
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -2,12 +2,16 @@
2
2
 
3
3
  module Badline
4
4
  module Media
5
- # A program loading into a C64, a C128 or a 264 series machine once it
6
- # has booted (Media.attach). The VIC-20 has its own (Vic20Basic).
5
+ # A program loading into a C64, a C128, a 264 series machine or a PET
6
+ # once it has booted (Media.attach). The VIC-20 has its own
7
+ # (Vic20Basic).
7
8
  module Program
8
9
  # Where BASIC 3.5 starts on the 264 series.
9
10
  PLUS4_BASIC_START = 0x1001
10
11
 
12
+ # Where BASIC starts on every PET.
13
+ PET_BASIC_START = 0x0401
14
+
11
15
  class << self
12
16
  # Loads the program where it says, and RUNs one that loads at the
13
17
  # start of BASIC.
@@ -30,12 +34,20 @@ module Badline
30
34
  # Where BASIC starts, the pointer to the end of its text and the
31
35
  # KERNAL's end address (EAL). BASIC 7.0 starts at $1C01 and keeps
32
36
  # the end of its text at $1210, and the 264 KERNAL keeps EAL at $9D.
37
+ # PET BASIC 2 and 4 keep the end of their text at $2A and EAL at
38
+ # $C9, and BASIC 1 at $7C and $E5.
33
39
  def basic(computer)
34
40
  return [PLUS4_BASIC_START, 0x2d, KernalTrap::PLUS4_ZERO_PAGE.end_address] if computer.family == :plus4
41
+ return pet_basic(computer) if computer.family == :pet
35
42
  return [0x1c01, 0x1210, 0xae] if computer.family == :c128 && computer.mode == :c128
36
43
 
37
44
  [BASIC_START, 0x2d, 0xae]
38
45
  end
46
+
47
+ def pet_basic(computer)
48
+ model = computer.model
49
+ [PET_BASIC_START, model.basic1? ? 0x7c : 0x2a, model.trap_layout.zero_page.end_address]
50
+ end
39
51
  end
40
52
  end
41
53
  end
@@ -3,9 +3,10 @@
3
3
  module Badline
4
4
  module Media
5
5
  # Device 8 as a true drive instead of the KERNAL traps: a 1541, or on
6
- # the C128 its 1571, or a 1581. Once a true drive is plugged in as
7
- # device 8, disk media go into it rather than into the traps, so a LOAD
8
- # runs the DOS and every byte crosses the serial bus. A .g64 holds the
6
+ # the C128 its 1571, or on the Plus/4 a 1551 if it asks for one, or a
7
+ # 1581. Once a true drive is plugged in as device 8, disk media go into
8
+ # it rather than into the traps, so a LOAD runs the DOS and every byte
9
+ # crosses the serial bus or TCBM. A .g64 holds the
9
10
  # disk's raw GCR, which only a true drive reads, so it plugs one in
10
11
  # when there's none yet. The 1541 reads only .d64 and .g64 images, the
11
12
  # 1571 .d71 and .g71 as well, and the 1581 only .d81, so a .d81 swaps
@@ -52,9 +53,10 @@ module Badline
52
53
  raise Error, "#{path} is not a #{types.join(', ')} or .d81 image, which the #{name} and the 1581 read"
53
54
  end
54
55
 
55
- (drive || computer.plug_true_drive).insert_image(path, read_only:)
56
+ drive ||= computer.plug_true_drive
57
+ drive.insert_image(path, read_only:)
56
58
  computer.unmount
57
- "Inserted #{path} in the #{name} as device 8"
59
+ "Inserted #{path} in the #{drive.model_name} as device 8"
58
60
  end
59
61
 
60
62
  private
@@ -61,11 +61,11 @@ module Badline
61
61
 
62
62
  # Loads the program, `bytes` from the file at `path`, as Vic20Basic
63
63
  # has it once the KERNAL has booted, or attaches the cartridge it's
64
- # a part of (Vic20Cartridge), and says which.
64
+ # a part of (Vic20Cartridge), named after the file, and says which.
65
65
  def attach_program(machine, path, bytes, autostart:)
66
66
  chips = Vic20Cartridge.chips(path, bytes)
67
67
  if chips
68
- machine.attach_cartridge(chips)
68
+ machine.attach_cartridge(chips, File.basename(path, File.extname(path)))
69
69
  return "Attached cartridge #{path}"
70
70
  end
71
71
 
data/lib/badline/media.rb CHANGED
@@ -11,6 +11,7 @@ require "badline/media/vic20_basic"
11
11
  require "badline/media/vic20_cartridge"
12
12
  require "badline/media/vic20_media"
13
13
  require "badline/media/plus4_media"
14
+ require "badline/media/pet_media"
14
15
  require "badline/media/tune"
15
16
  require "badline/media/program"
16
17
 
@@ -25,7 +26,9 @@ module Badline
25
26
  ".d64" => Storage::D64Image,
26
27
  ".d71" => Storage::D71Image,
27
28
  ".d81" => Storage::D81Image,
28
- ".t64" => Storage::T64
29
+ ".t64" => Storage::T64,
30
+ ".d80" => Storage::D80Image,
31
+ ".d82" => Storage::D82Image
29
32
  }.freeze
30
33
 
31
34
  class << self
@@ -48,8 +51,10 @@ module Badline
48
51
  # disk autostart of its own, and takes no .sid tunes, and the 264
49
52
  # series loads programs at the start of its BASIC (Program), takes
50
53
  # .crt cartridges and raw .bin ROM images in its two cartridges'
51
- # slots (Plus4Media), and no .sid tunes either. The
52
- # C128 in C64 mode takes a C64's.
54
+ # slots (Plus4Media), and no .sid tunes either. The PET mounts .d80
55
+ # and .d82 disks too, which no other machine takes, and has no
56
+ # cartridges, tunes or true drives (PETMedia). The C128 in C64 mode
57
+ # takes a C64's.
53
58
  def attach(computer, path, autostart: true, subtune: nil, **)
54
59
  path = DiskList.disk(path)
55
60
  refuse_unsupported(computer, path)
@@ -99,7 +104,7 @@ module Badline
99
104
  return :cartridge if computer.family == :plus4 && Plus4Media.rom_image?(path)
100
105
 
101
106
  kind = Extensions.kind(path)
102
- %i[disk archive].include?(kind) ? :storage : kind
107
+ %i[disk archive ieee_disk].include?(kind) ? :storage : kind
103
108
  end
104
109
 
105
110
  # What device 8 serves through the traps for a host directory, a disk
@@ -120,14 +125,21 @@ module Badline
120
125
 
121
126
  private
122
127
 
123
- # The VIC-20 and the 264 series have no SID to play a .sid tune on.
128
+ # The VIC-20 and the 264 series have no SID to play a .sid tune on,
129
+ # and only the PET has the IEEE-488 drive a .d80 or .d82 goes in.
124
130
  def refuse_unsupported(computer, path)
125
- return unless Vic20Media::UNSUPPORTED.include?(File.extname(path).downcase)
126
-
127
- case computer.family
128
- when :vic20 then raise ArgumentError, "#{path} doesn't go in a VIC-20"
129
- when :plus4 then raise ArgumentError, "#{path} doesn't go in a Plus/4"
131
+ family = computer.family
132
+ if Extensions.kind(path) == :ieee_disk && family != :pet
133
+ raise ArgumentError, "#{path} needs a PET's IEEE-488 drive"
130
134
  end
135
+
136
+ refused, name = case family
137
+ when :vic20 then [Vic20Media::UNSUPPORTED, "a VIC-20"]
138
+ when :plus4 then [Vic20Media::UNSUPPORTED, "a Plus/4"]
139
+ when :pet then [PETMedia::UNSUPPORTED, "a PET"]
140
+ else [[], ""]
141
+ end
142
+ raise ArgumentError, "#{path} doesn't go in #{name}" if refused.include?(File.extname(path).downcase)
131
143
  end
132
144
 
133
145
  def attach_kind(computer, path, autostart:, subtune:, **options)
@@ -143,7 +155,7 @@ module Badline
143
155
  end
144
156
  end
145
157
 
146
- def disk?(path) = File.directory?(path) || Extensions.kind(path) == :disk
158
+ def disk?(path) = File.directory?(path) || %i[disk ieee_disk].include?(Extensions.kind(path))
147
159
 
148
160
  def attach_true_drive(computer, path, disk, autostart:)
149
161
  message = TrueDrive.insert(computer, path, read_only: disk.fetch(:read_only, false))
@@ -154,7 +166,11 @@ module Badline
154
166
  def mount(computer, path, disk, autostart:)
155
167
  storage = open_storage(path, disk)
156
168
  computer.mount(storage)
157
- computer.type_text(disk_autostart(computer) { storage.read_file("*") }) if autostart
169
+ if autostart && computer.family == :pet
170
+ PETMedia.disk_autostart(computer, storage)
171
+ elsif autostart
172
+ computer.type_text(disk_autostart(computer) { storage.read_file("*") })
173
+ end
158
174
  "Mounted #{path} as device 8"
159
175
  end
160
176
 
@@ -170,7 +186,9 @@ module Badline
170
186
  # (Plus4Media.cartridge_chips).
171
187
  def attach_cartridge(computer, path, options)
172
188
  case computer.family
173
- when :vic20 then computer.attach_cartridge(Storage::CRTFile.new(path, machine: :vic20).chips)
189
+ when :vic20
190
+ crt = Storage::CRTFile.new(path, machine: :vic20)
191
+ computer.attach_cartridge(crt.chips, crt.name.empty? ? File.basename(path, File.extname(path)) : crt.name)
174
192
  when :plus4 then computer.attach_cartridge(Plus4Media.cartridge_chips(path, slot: options.fetch(:slot, nil)))
175
193
  else
176
194
  computer.attach_cartridge(C64::Cartridge.from_file(path, **options))
@@ -178,17 +196,19 @@ module Badline
178
196
  "Attached cartridge #{path}"
179
197
  end
180
198
 
181
- # A VIC-20 or a 264 says when the tape was made for another machine
182
- # (Vic20Media.tape_message, Plus4Media.tape_message).
199
+ # A VIC-20, a 264 or a PET says when the tape was made for another
200
+ # machine (Vic20Media.tape_message, Plus4Media.tape_message,
201
+ # PETMedia.tape_message).
183
202
  def attach_tape(computer, path, autostart:)
184
203
  tape = Storage::TAP.new(path)
185
204
  computer.datasette.insert(tape)
186
205
  computer.datasette.play!
187
- computer.type_text(TAPE_AUTOSTART) if autostart
206
+ computer.type_text(computer.family == :pet ? PETMedia::TAPE_AUTOSTART : TAPE_AUTOSTART) if autostart
188
207
  message = "Inserted #{path} in the datasette"
189
208
  case computer.family
190
209
  when :vic20 then Vic20Media.tape_message(tape, message)
191
210
  when :plus4 then Plus4Media.tape_message(tape, message)
211
+ when :pet then PETMedia.tape_message(tape, message)
192
212
  else message
193
213
  end
194
214
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "badline/storage/p00"
4
+ require "badline/storage/tap"
4
5
 
5
6
  module Badline
6
7
  class Options
@@ -12,7 +13,7 @@ module Badline
12
13
 
13
14
  private
14
15
 
15
- # Takes `sid`, `c64`, `vic20`, `c128` or `plus4` when given first.
16
+ # Takes `sid`, `c64`, `vic20`, `c128`, `plus4` or `pet` when given first.
16
17
  def subcommand(args)
17
18
  case args.first
18
19
  when "sid" then @sid_command = true
@@ -20,6 +21,7 @@ module Badline
20
21
  when "vic20" then @family = :vic20
21
22
  when "c128" then @family = :c128
22
23
  when "plus4" then @family = :plus4
24
+ when "pet" then @family = :pet
23
25
  else return
24
26
  end
25
27
  @family_named = !@sid_command
@@ -31,19 +33,28 @@ module Badline
31
33
  when :vic20 then VIC20_MODELS
32
34
  when :c128 then C128_MODELS
33
35
  when :plus4 then PLUS4_MODELS
36
+ when :pet then PET_MODELS
34
37
  else MODELS
35
38
  end
36
39
  end
37
40
 
38
41
  # Without a family named, a program that loads at C128_BASIC_START is
39
- # the C128's.
42
+ # the C128's, and an 8050's or 8250's disk or a PET tape the PET's. A
43
+ # program that loads where PET BASIC starts could be a VIC-20's too.
40
44
  def pick_family
41
- return if @family_named || @sid_command || @media_path.nil?
45
+ return if @family_named || @sid_command || @media_path.nil? || !File.file?(@media_path)
42
46
 
43
- program = Media::Extensions::PROGRAMS.include?(File.extname(@media_path).downcase)
44
- return unless program && File.file?(@media_path)
47
+ if pet_media?
48
+ @family = :pet
49
+ elsif Media::Extensions::PROGRAMS.include?(File.extname(@media_path).downcase)
50
+ @family = :c128 if Storage::P00.load_address(@media_path) == C128_BASIC_START
51
+ end
52
+ end
45
53
 
46
- @family = :c128 if Storage::P00.load_address(@media_path) == C128_BASIC_START
54
+ # Whether the media is an 8050's or 8250's disk or a PET tape.
55
+ def pet_media?
56
+ kind = Media::Extensions.kind(@media_path)
57
+ kind == :ieee_disk || (kind == :tape && Storage::TAP.platform_of(@media_path) == Storage::TAP::PET_PLATFORM)
47
58
  end
48
59
  end
49
60
  end
@@ -49,7 +49,8 @@ module Badline
49
49
  # wrapped as the banner is.
50
50
  def media_kinds
51
51
  text = "Media can be #{listed(Media::Extensions::PROGRAMS)} program, #{listed(%i[disk])} disk image, " \
52
- "#{listed(%i[gcr])} disk image for a true drive, #{listed(%i[disk_list])} list of disk images, " \
52
+ "#{listed(%i[ieee_disk])} disk image for a PET, #{listed(%i[gcr])} disk image for a true drive, " \
53
+ "#{listed(%i[disk_list])} list of disk images, " \
53
54
  "#{listed(%i[archive])} tape archive, #{listed(%i[tape])} tape, #{listed(%i[cartridge])} " \
54
55
  "cartridge, #{listed(%i[tune])} tune, #{listed(%w[.vsf])} snapshot, or a directory to mount as device 8."
55
56
  wrap(text)
@@ -84,6 +85,7 @@ module Badline
84
85
  #{@program} vic20 [options] [media]
85
86
  #{@program} c128 [options] [media]
86
87
  #{@program} plus4 [options] [media]
88
+ #{@program} pet [options] [media]
87
89
  #{@program} --headless [options] tune.sid
88
90
  #{@program} [options] tune.sid --audio-out FILE
89
91
  #{@program} sid [options] FILE|DIR...
@@ -93,6 +95,7 @@ module Badline
93
95
  vic20 Run a PAL VIC-20, with the RAM --ram names
94
96
  c128 Run a C128 in C128 mode, the one --model names
95
97
  plus4 Run a Plus/4 or a C16, the one --model names
98
+ pet Run a PET or a CBM, the one --model names
96
99
  sid Play .sid tunes and directories of them
97
100
 
98
101
  #{media_kinds}
@@ -111,8 +114,22 @@ module Badline
111
114
  The Plus/4 and the C16 take programs, disks, tapes, and cartridges as
112
115
  .crt files or raw .bin ROM images. A .bin goes in cartridge 1, its
113
116
  low slot for up to 16K and both slots for 32K, and --c1lo, --c1hi,
114
- --c2lo and --c2hi put one in the slot they name. There Escape is ESC,
115
- Page Down RUN/STOP and F4 HELP.
117
+ --c2lo and --c2hi put one in the slot they name. Their --true-drive
118
+ makes device 8 an emulated 1551, on the parallel TCBM cable, and
119
+ --drive-type 1541 a 1541 on the serial bus instead. There Escape is
120
+ ESC, Page Down RUN/STOP and F4 HELP.
121
+
122
+ The PET and the CBM take programs, disks, .d80 and .d82 among them,
123
+ and tapes, and a .d80, a .d82 or a PET tape starts one without
124
+ `pet`. Their keys type what the host's keys type, Alt with a key
125
+ presses the PET's SHIFT and the key its unshifted character is on,
126
+ and the pause menu's KEYBOARD page says where the rest are. --basic
127
+ and --editor fit the upgrades Commodore sold, as in --model 2001
128
+ --basic 2. BASIC 1 can't LOAD from a disk drive, though a disk still
129
+ starts its first program, and BASIC 2 can. The 8032 and the 8096
130
+ have two 50 Hz editors: 4-80-b-50hz, the default, and
131
+ 4-80-b-50hz-0283, another chip's, with 64-cycle lines and 313 lines
132
+ a frame.
116
133
 
117
134
  --headless plays a .sid tune on the host's audio device without the
118
135
  window, and --audio-out renders it to 16-bit PCM instead. The
@@ -134,8 +151,9 @@ module Badline
134
151
  --at and --script run events once a number of frames has run, as
135
152
  in --at 3500:key=space or --at 250,500:screenshot=shot%05d.bmp.
136
153
  key=NAME presses a key (space, return, a, f1, run_stop, restore, and
137
- on the C128 esc, help, keypad1 and the rest, and on the Plus/4
138
- esc, help and f1 to f3) or a joystick's
154
+ on the C128 esc, help, keypad1 and the rest, on the Plus/4
155
+ esc, help and f1 to f3, and on the PET rvs, escape and kp1) or a
156
+ joystick's
139
157
  direction or fire (joy1-up, joy2-fire) for #{Event::HOLD} frames, and
140
158
  pushes the C128's caps_lock or forty_eighty, which lock. type=TEXT
141
159
  types it, with \\n for RETURN. insert=FILE swaps in a disk, a list's
@@ -4,7 +4,8 @@ module Badline
4
4
  class Options
5
5
  # One option of the table: its flags and value as the help shows them
6
6
  # (`-s, --subtune N`), what it does, the help section it's listed in, the
7
- # mode it needs (:window, :headless or :either), and the build that
7
+ # mode it needs (:window, :headless, :either, or :any_window for the
8
+ # emulator's window or the SID player's), and the build that
8
9
  # takes it (:native, :ruby or :both).
9
10
  class Option
10
11
  attr_reader :usage, :name, :short, :value, :text, :section, :needs, :build
@@ -18,6 +18,13 @@ module Badline
18
18
  # another name for the C16.
19
19
  PLUS4_MODELS = %w[plus4 plus4ntsc c16 c16ntsc c116].freeze
20
20
 
21
+ # The PETs and CBMs, as PET::Model names them, the 8032 first, the
22
+ # default.
23
+ PET_MODELS = %w[8032 8096 4032 3032 3032b 2001].freeze
24
+
25
+ # The true drives --drive-type names for the Plus/4.
26
+ PLUS4_DRIVE_TYPES = %w[1541 1551].freeze
27
+
21
28
  # The VIC-20 RAM expansions --ram takes, in the order the help lists
22
29
  # them.
23
30
  RAM_NAMES = %w[unexpanded 3k 8k 16k 24k 32k all].freeze
@@ -39,18 +46,29 @@ module Badline
39
46
  Option.new("--sound", "Play the SID through the host's audio device (F10 mutes)",
40
47
  section: "Window options", needs: :window),
41
48
  Option.new("--no-sound", "Don't play the SID", section: "Window options", needs: :window, build: :native),
42
- Option.new("--true-drive", "Put a true 1541 on device 8 instead of the KERNAL traps, a 1571 on the C128",
49
+ Option.new("--true-drive", "Put a true 1541 on device 8 instead of the KERNAL traps, a 1571 on the C128, " \
50
+ "a 1551 on the Plus/4",
51
+ section: "Window options", needs: :window),
52
+ Option.new("--drive-type MODEL", "The Plus/4's true drive: 1541 or 1551 (default: 1551); implies --true-drive",
43
53
  section: "Window options", needs: :window),
44
54
  Option.new("--reu SIZE", "Plug in an REU of SIZE K: 128, 256, 512 (a 1750) or up to 16384",
45
55
  section: "Window options", needs: :window),
46
56
  Option.new("--model NAME", "C64 to run: #{MODELS.join(', ')} (default: #{MODELS.first}); VIC-20: pal; " \
47
- "C128: #{C128_MODELS.join(', ')}; Plus/4: #{PLUS4_MODELS.join(', ')}",
57
+ "C128: #{C128_MODELS.join(', ')}; Plus/4: #{PLUS4_MODELS.join(', ')}; " \
58
+ "PET: #{PET_MODELS.join(', ')}",
48
59
  section: "Window options", needs: :window),
49
60
  Option.new("--ntsc", "Run an NTSC C64, as --model ntsc does", section: "Window options", needs: :window),
50
61
  Option.new("--c64", "Start the C128 in C64 mode, holding C= at power-on",
51
62
  section: "Window options", needs: :window),
52
63
  Option.new("--ram SIZE", "VIC-20 RAM expansion: #{RAM_NAMES.join(', ')} (default: unexpanded); " \
53
- "Plus/4 RAM: 16k, 32k or 64k (default: the model's own)",
64
+ "Plus/4 RAM: 16k, 32k or 64k; PET RAM: 4k, 8k, 16k or 32k (default: the model's own)",
65
+ section: "Window options", needs: :window),
66
+ Option.new("--60hz", "Run a CRTC PET's 60 Hz editor instead of its 50 Hz one",
67
+ section: "Window options", needs: :window),
68
+ Option.new("--basic VERSION", "Fit a PET with BASIC 1, 2 or 4, as its board takes (default: its own)",
69
+ section: "Window options", needs: :window),
70
+ Option.new("--editor NAME", "Fit a PET with an editor ROM its board and BASIC take: " \
71
+ "#{PET::ROMSets::EDITORS.keys.join(', ')}",
54
72
  section: "Window options", needs: :window),
55
73
  Option.new("--c1lo FILE", "Put a .bin ROM image in the Plus/4's cartridge 1, low slot ($8000)",
56
74
  section: "Window options", needs: :window),
@@ -60,6 +78,12 @@ module Badline
60
78
  section: "Window options", needs: :window),
61
79
  Option.new("--c2hi FILE", "Put a .bin ROM image in cartridge 2's high slot ($C000)",
62
80
  section: "Window options", needs: :window),
81
+ Option.new("--sid-card MODEL", "Fit the Plus/4 or C16 with a SID card at $FD40: 6581 or 8580",
82
+ section: "Window options", needs: :window),
83
+ Option.new("--sid-card-address ADDRESS", "Put the SID card at fd40 (the default) or fe80",
84
+ section: "Window options", needs: :window),
85
+ Option.new("--ram-expansion NAME", "Fit the Plus/4 or C16 with a RAM expansion: hannes256, hannes1m or csory256",
86
+ section: "Window options", needs: :window),
63
87
  Option.new("--no-vsync", "Pace frames by the timer or the sound instead of the display",
64
88
  section: "Window options", needs: :window),
65
89
  Option.new("--verbose", "Print the display, sound and gamepad setup and the frame timing",
@@ -81,7 +105,7 @@ module Badline
81
105
  section: "Options without the window", needs: :headless),
82
106
  Option.new("--no-tui", "Play without the interactive display, even on a terminal",
83
107
  section: "Options without the window", needs: :headless),
84
- Option.new("--frames N", "Quit after N frames", section: "Testing options", needs: :window),
108
+ Option.new("--frames N", "Quit after N frames", section: "Testing options", needs: :any_window),
85
109
  Option.new("--unpaced", "Run as fast as it can, without vsync or pacing",
86
110
  section: "Testing options", needs: :window),
87
111
  Option.new("--screenshot FILE", "Save the last frame as a .bmp",