; $VER: Uninstall RGB2RTG 0.76-1 (17.10.2026)
;
; Removes RGB2RTG and puts back every damn thing the installer changed: the
; kernel lines in config.txt (from the #RGB2RTG-WAS: lines it left there),
; the RGB2RTG block in config.txt, the RTG driver (from its .pre-rgb2rtg
; copy), the desktop menu (Workbench's menu bar on a plain AmigaOS 3.x),
; S:User-Startup and the HDMI driver for AHI (AHI's units get their modes
; back).
; Same text rule as Install: lines up to 44 characters, about 11 per window.

(set @app-name "RGB2RTG")
(welcome "Remove RGB2RTG")

(if (= 0 (askbool
           (prompt "Remove RGB2RTG from this Amiga?\n\n"
                   "This puts back your previous\n"
                   "kernel line in config.txt and\n"
                   "RTG driver, and removes the\n"
                   "RGB2RTG menu.")
           (help "Only what the installer added is removed: the kernel= lines\n"
                 "and the RGB2RTG block in config.txt, VideoCore.card (the one\n"
                 "you had comes back from VideoCore.card.pre-rgb2rtg), the\n"
                 "RGB2RTG title in the desktop menu, its lines in\n"
                 "S:User-Startup and WHDLoad's scripts, the settings\n"
                 "(ENVARC:RGB2RTG.prefs, and games' own in ENVARC:RGB2RTG), the\n"
                 "HDMI driver for AHI (AHI's units get their modes back) and\n"
                 "C:rgb2rtg. The kernel file stays on the boot partition;\n"
                 "nothing uses it once config.txt stops pointing at it.")
           (default 0)))
  (exit "Nothing was changed." (quiet)))

(set #tool "C:rgb2rtg")
(if (= 0 (exists #tool (noreq)))
  (set #tool "Files/C/rgb2rtg"))
; unpacked on the Amiga, the package's copy may have no e bit at all (see Install)
(run (cat "Protect " #tool " +e >NIL:") (safe))

; config.txt first, and I mean it: if it cannot go back, nothing else may -
; the RTG driver belongs with the kernel config.txt starts (an Emu68 1.0.x
; kernel with this VideoCore 1.5 can crash at boot).
(set #cfg (run (cat #tool " UNINSTALL CONFIG >NIL:")))
(if (<> #cfg 0)
  (abort "config.txt could not be changed.\n\n"
         "Open the Emu68 boot partition\n"
         "once (EMU68 on CaffeineOS; on\n"
         "AmigaOS 3.2 mount it first) and\n"
         "check it is not read-only. In a\n"
         "Shell, C:rgb2rtg UNINSTALL CONFIG\n"
         "says why. Then run Uninstall\n"
         "again.\n\n"
         "Nothing was changed."))

(run (cat #tool " UNMENU >NIL:"))
(run (cat #tool " UNINSTALL MONITOR >NIL:"))    ; the monitor icon, if Install had the gall to change it
(run (cat #tool " UNINSTALL AHI >NIL:"))        ; AHI's units off the HDMI driver, which goes with its modes

; the RTG driver it replaced comes back, and its copy goes: the next install
; then keeps whatever driver is there by then
(if (= 1 (exists "SYS:Libs/Picasso96/VideoCore.card.pre-rgb2rtg" (noreq)))
  ((copyfiles (source "SYS:Libs/Picasso96/VideoCore.card.pre-rgb2rtg") (dest "SYS:Libs/Picasso96")
     (newname "VideoCore.card") (optional "force") (nogauge))
   (delete "SYS:Libs/Picasso96/VideoCore.card.pre-rgb2rtg" (optional "force"))))
; the same damn driver as Emu68-VC4.card, for a monitor with that BoardType (0.75-dev66)
(if (= 1 (exists "SYS:Libs/Picasso96/Emu68-VC4.card.pre-rgb2rtg" (noreq)))
  ((copyfiles (source "SYS:Libs/Picasso96/Emu68-VC4.card.pre-rgb2rtg") (dest "SYS:Libs/Picasso96")
     (newname "Emu68-VC4.card") (optional "force") (nogauge))
   (delete "SYS:Libs/Picasso96/Emu68-VC4.card.pre-rgb2rtg" (optional "force"))))

(delete "ENVARC:RGB2RTG.prefs" (optional "force"))
(delete "ENV:RGB2RTG.prefs" (optional "force"))
; games' own settings (the Settings window's Settings for), a drawer each
(run "Delete >NIL: ENVARC:RGB2RTG ENV:RGB2RTG ALL QUIET FORCE")
(delete "C:rgb2rtg" (optional "force"))

(exit "RGB2RTG has been removed.\n\n"
      "POWER CYCLE the Amiga to start\n"
      "your previous kernel."
      (quiet))
