izapple2/apple2main.go

411 lines
9.2 KiB
Go
Raw Normal View History

2020-10-03 21:38:26 +00:00
package izapple2
2019-01-26 17:57:03 +00:00
2019-04-13 18:29:31 +00:00
import (
2019-04-15 21:13:05 +00:00
"flag"
2019-04-13 18:29:31 +00:00
)
2019-10-12 19:37:37 +00:00
const defaultInternal = "<default>"
2020-10-07 07:37:13 +00:00
// MainApple is a device independent main. Video, keyboard and speaker won't be defined
func MainApple() *Apple2 {
2019-04-15 21:13:05 +00:00
romFile := flag.String(
"rom",
2019-10-12 19:37:37 +00:00
defaultInternal,
2019-04-15 21:13:05 +00:00
"main rom file")
2019-05-09 22:09:15 +00:00
disk2Slot := flag.Int(
"disk2Slot",
6,
"slot for the disk driver. -1 for none.")
2019-04-15 21:13:05 +00:00
diskImage := flag.String(
"disk",
2022-03-08 19:11:26 +00:00
defaultInternal,
2019-04-15 21:13:05 +00:00
"file to load on the first disk drive")
2020-04-12 23:29:04 +00:00
diskBImage := flag.String(
"diskb",
"",
"file to load on the second disk drive")
2019-10-02 21:39:39 +00:00
hardDiskImage := flag.String(
"hd",
"",
"file to load on the boot hard disk (slot 7)")
2019-10-02 21:39:39 +00:00
hardDiskSlot := flag.Int(
"hdSlot",
-1,
"slot for the hard drive if present. -1 for none.")
2022-10-24 21:09:06 +00:00
fujinetSlot := flag.Int(
"fujinet",
-1,
"slot for the smatport card hosting the Fujinet. -1 for none.")
smartPortImage := flag.String(
"disk35",
"",
"file to load on the SmartPort disk (slot 5)")
2019-05-04 17:49:11 +00:00
cpuClock := flag.Float64(
"mhz",
2019-11-07 22:20:14 +00:00
CPUClockMhz,
2019-05-05 11:25:45 +00:00
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
2019-04-21 16:18:43 +00:00
charRomFile := flag.String(
"charRom",
2019-10-12 19:37:37 +00:00
defaultInternal,
2019-06-02 21:18:35 +00:00
"rom file for the character generator")
languageCardSlot := flag.Int(
"languageCardSlot",
0,
"slot for the 16kb language card. -1 for none")
saturnCardSlot := flag.Int(
"saturnCardSlot",
-1,
"slot for the 256kb Saturn card. -1 for none")
vidHDCardSlot := flag.Int(
"vidHDSlot",
2,
2019-11-22 22:27:25 +00:00
"slot for the VidHD card, only for //e models. -1 for none")
2019-11-12 22:47:48 +00:00
fastChipCardSlot := flag.Int(
"fastChipSlot",
3,
"slot for the FASTChip accelerator card, -1 for none")
memoryExpansionCardSlot := flag.Int(
"memoryExpSlot",
-1,
"slot for the Memory Expansion card with 1GB. -1 for none")
parallelPrinterSlot := flag.Int(
"printer",
1,
"slot for the Parallel Printer Interface. -1 for none")
ramWorksKb := flag.Int(
"ramworks",
8192,
"memory to use with RAMWorks card, 0 for no card, max is 16384")
2019-11-12 22:47:48 +00:00
thunderClockCardSlot := flag.Int(
"thunderClockCardSlot",
2021-01-24 22:25:52 +00:00
-1,
2019-11-12 22:47:48 +00:00
"slot for the ThunderClock Plus card. -1 for none")
consoleCardSlot := flag.Int(
"consoleCardSlot",
-1,
"slot for the host console card. -1 for none")
2021-01-24 22:25:52 +00:00
mouseCardSlot := flag.Int(
"mouseCardSlot",
4,
"slot for the Mouse card. -1 for none")
videxCardSlot := flag.Int(
"videxCardSlot",
3,
"slot for the Videx Videoterm 80 columns card. For pre-2e models. -1 for none")
2022-03-08 19:11:26 +00:00
swyftCard := flag.Bool(
"swyftCard",
false,
"activate a Swyft Card in slot 3. Load the tutorial disk if none provided")
nsc := flag.Int(
"nsc",
-1,
"add a DS1216 No-Slot-Clock on the main ROM (use 0) or a slot ROM. -1 for none")
rgbCard := flag.Bool(
"rgb",
true,
"emulate the RGB modes of the 80col RGB card for DHGR")
2021-10-12 10:26:40 +00:00
romX := flag.Bool(
"romx",
false,
"emulate a RomX")
fastDisk := flag.Bool(
"fastDisk",
true,
"set fast mode when the disks are spinning")
2019-04-15 21:13:05 +00:00
panicSS := flag.Bool(
2019-11-01 17:48:39 +00:00
"panicSS",
2019-04-15 21:13:05 +00:00
false,
"panic if a not implemented softswitch is used")
traceCPU := flag.Bool(
"traceCpu",
false,
"dump to the console the CPU execution operations")
traceSS := flag.Bool(
"traceSS",
false,
"dump to the console the sofswitches calls")
2020-08-30 19:11:43 +00:00
traceSSReg := flag.Bool(
"traceSSReg",
false,
"dump to the console the sofswitch registrations")
2019-11-01 17:48:39 +00:00
traceHD := flag.Bool(
"traceHD",
false,
2022-10-24 21:09:06 +00:00
"dump to the console the hd accesses")
traceSP := flag.Bool(
"traceSP",
false,
"dump to the console the smarport commands")
2019-10-12 19:37:37 +00:00
model := flag.String(
"model",
2019-11-03 23:23:03 +00:00
"2enh",
"set base model. Models available 2plus, 2e, 2enh, base64a")
profile := flag.Bool(
"profile",
false,
"generate profile trace to analyse with pprof")
2020-06-07 16:23:39 +00:00
traceMLI := flag.Bool(
"traceMLI",
false,
"dump to the console the calls to ProDOS machine language interface calls to $BF00")
2021-04-02 18:39:37 +00:00
tracePascal := flag.Bool(
"tracePascal",
false,
"dump to the console the calls to the Apple Pascal BIOS")
forceCaps := flag.Bool(
"forceCaps",
false,
"force all letters to be uppercased (no need for caps lock!)")
sequencerDisk2 := flag.Bool(
"sequencer",
2021-05-09 17:48:54 +00:00
false,
"use the sequencer based Disk II card")
traceBBC := flag.Bool(
"traceBBC",
false,
"trace BBC MOS API calls used with Applecorn, skip console I/O calls")
traceBBCFull := flag.Bool(
"traceBBCFull",
false,
"trace BBC MOS API calls used with Applecorn")
2020-06-07 16:23:39 +00:00
2019-04-15 21:13:05 +00:00
flag.Parse()
2020-10-03 21:00:04 +00:00
// Process a filename with autodetection
filename := flag.Arg(0)
diskImageFinal := *diskImage
hardDiskImageFinal := *hardDiskImage
if filename != "" {
2022-01-28 18:25:52 +00:00
// Try loading as diskette
_, err := LoadDiskette(filename)
if err == nil {
2020-10-03 21:00:04 +00:00
diskImageFinal = filename
} else {
hardDiskImageFinal = filename
}
}
2022-03-08 19:11:26 +00:00
// Resolve what is the default disk to use if not specified
if diskImageFinal == defaultInternal {
if *swyftCard {
diskImageFinal = "<internal>/SwyftWare_-_SwyftCard_Tutorial.woz"
} else {
diskImageFinal = "<internal>/dos33.dsk"
}
}
2020-08-30 19:11:43 +00:00
a := newApple2()
2021-04-02 18:39:37 +00:00
a.setup(*cpuClock, *fastDisk)
2020-08-30 19:11:43 +00:00
a.io.setTrace(*traceSS)
a.io.setTraceRegistrations(*traceSSReg)
a.io.setPanicNotImplemented(*panicSS)
a.setProfiling(*profile)
2020-11-03 01:26:56 +00:00
a.SetForceCaps(*forceCaps)
2021-04-02 18:39:37 +00:00
if *traceMLI {
a.addTracer(newTraceProDOS(a))
}
if *tracePascal {
a.addTracer(newTracePascal(a))
}
if *traceBBC {
2021-07-23 15:23:24 +00:00
a.addTracer(newTraceApplecorn(a, true))
}
if *traceBBCFull {
2021-07-23 15:23:24 +00:00
a.addTracer(newTraceApplecorn(a, false))
}
2020-08-30 19:11:43 +00:00
2022-02-21 22:05:53 +00:00
initModel(a, *model, *romFile, *charRomFile)
a.cpu.SetTrace(*traceCPU)
// Disable incompatible cards
2019-10-12 19:37:37 +00:00
switch *model {
case "2plus":
2019-11-22 22:27:25 +00:00
*vidHDCardSlot = -1
2019-10-12 19:37:37 +00:00
case "2e":
2022-02-21 22:05:53 +00:00
*videxCardSlot = -1
2019-10-20 22:06:28 +00:00
case "2enh":
2022-02-21 22:05:53 +00:00
*videxCardSlot = -1
2019-10-12 19:37:37 +00:00
case "base64a":
2019-11-22 22:27:25 +00:00
*vidHDCardSlot = -1
*videxCardSlot = -1 // The videx firmware crashes the BASE64A, probably by use of ANN0
2019-10-12 19:37:37 +00:00
default:
panic("Model not supported")
}
2019-10-12 19:37:37 +00:00
// Externsion cards
if *languageCardSlot >= 0 {
a.AddLanguageCard(*languageCardSlot)
}
if *saturnCardSlot >= 0 {
a.AddSaturnCard(*saturnCardSlot)
}
if *parallelPrinterSlot >= 0 {
a.AddParallelPrinter(*parallelPrinterSlot)
}
if *memoryExpansionCardSlot >= 0 {
2020-10-14 19:54:51 +00:00
a.AddMemoryExpansionCard(*memoryExpansionCardSlot)
}
if *thunderClockCardSlot > 0 {
a.AddThunderClockPlusCard(*thunderClockCardSlot)
}
2019-11-12 22:47:48 +00:00
if *vidHDCardSlot >= 0 {
a.AddVidHD(*vidHDCardSlot)
}
if *consoleCardSlot >= 0 {
a.AddCardInOut(*consoleCardSlot)
2021-01-24 22:25:52 +00:00
}
if *mouseCardSlot > 0 {
a.AddMouseCard(*mouseCardSlot)
}
if *videxCardSlot > 0 {
a.AddVidexCard(*videxCardSlot)
}
2022-03-08 19:11:26 +00:00
if *swyftCard {
if !a.isApple2e {
panic("SwyftCard available only on Apple IIe or better")
}
a.AddSwyftCard()
}
if *smartPortImage != "" {
2022-10-24 21:09:06 +00:00
err := a.AddSmartPortDisk(5, *smartPortImage, *traceHD, *traceSP)
if err != nil {
panic(err)
}
}
2022-10-24 21:09:06 +00:00
if *fujinetSlot >= 0 {
a.AddFujinet(*fujinetSlot, *traceSP)
}
2019-11-12 22:47:48 +00:00
if *fastChipCardSlot >= 0 {
a.AddFastChip(*fastChipCardSlot)
}
2019-10-02 21:39:39 +00:00
if *disk2Slot > 0 {
if *sequencerDisk2 {
2022-02-25 23:05:09 +00:00
err := a.AddDisk2Sequencer(*disk2Slot, diskImageFinal, *diskBImage, nil)
2021-05-09 17:48:54 +00:00
if err != nil {
panic(err)
}
} else {
2022-02-25 23:05:09 +00:00
err := a.AddDisk2(*disk2Slot, diskImageFinal, *diskBImage, nil)
2021-05-09 17:48:54 +00:00
if err != nil {
panic(err)
}
2019-10-05 23:26:00 +00:00
}
2019-05-09 22:09:15 +00:00
}
2020-10-03 21:00:04 +00:00
if hardDiskImageFinal != "" {
2019-10-02 21:39:39 +00:00
if *hardDiskSlot <= 0 {
// If there is a hard disk image, but no slot assigned, use slot 7.
*hardDiskSlot = 7
}
2022-10-24 21:09:06 +00:00
err := a.AddSmartPortDisk(*hardDiskSlot, hardDiskImageFinal, *traceHD, *traceSP)
2019-10-05 23:26:00 +00:00
if err != nil {
panic(err)
}
2019-10-02 21:39:39 +00:00
}
2019-05-18 21:40:59 +00:00
if *ramWorksKb != 0 {
if *ramWorksKb%64 != 0 {
panic("Ramworks size must be a multiple of 64")
}
a.AddRAMWorks(*ramWorksKb / 64)
}
if *rgbCard {
a.AddRGBCard()
}
if *nsc == 0 {
a.AddNoSlotClock()
} else if *nsc > 0 {
err := a.AddNoSlotClockInCard(*nsc)
if err != nil {
panic(err)
}
}
2021-10-12 10:26:40 +00:00
if *romX {
err := a.AddRomX()
if err != nil {
panic(err)
}
}
2020-10-14 19:54:51 +00:00
// a.AddCardLogger(4)
2019-05-18 21:40:59 +00:00
return a
2019-01-26 17:57:03 +00:00
}
2022-02-21 22:05:53 +00:00
func initModel(a *Apple2, model string, romFile string, charRomFile string) {
var charGenMap charColumnMap
initialCharGenPage := 0
switch model {
case "2plus":
setApple2plus(a)
if romFile == defaultInternal {
romFile = "<internal>/Apple2_Plus.rom"
}
if charRomFile == defaultInternal {
charRomFile = "<internal>/Apple2rev7CharGen.rom"
}
charGenMap = charGenColumnsMap2Plus
case "2e":
setApple2e(a)
if romFile == defaultInternal {
romFile = "<internal>/Apple2e.rom"
}
if charRomFile == defaultInternal {
charRomFile = "<internal>/Apple IIe Video Unenhanced - 342-0133-A - 2732.bin"
}
charGenMap = charGenColumnsMap2e
case "2enh":
setApple2eEnhanced(a)
if romFile == defaultInternal {
romFile = "<internal>/Apple2e_Enhanced.rom"
}
if charRomFile == defaultInternal {
charRomFile = "<internal>/Apple IIe Video Enhanced - 342-0265-A - 2732.bin"
}
charGenMap = charGenColumnsMap2e
case "base64a":
setBase64a(a)
if romFile == defaultInternal {
err := loadBase64aRom(a)
if err != nil {
panic(err)
}
romFile = ""
}
if charRomFile == defaultInternal {
charRomFile = "<internal>/BASE64A_ROM7_CharGen.BIN"
initialCharGenPage = 1
}
charGenMap = charGenColumnsMapBase64a
default:
panic("Model not supported")
}
2022-03-08 19:11:26 +00:00
// Load ROM
2022-02-21 22:05:53 +00:00
if romFile != "" {
err := a.LoadRom(romFile)
if err != nil {
panic(err)
}
}
2022-03-08 19:11:26 +00:00
// Load character generator
2022-02-21 22:05:53 +00:00
cg, err := newCharacterGenerator(charRomFile, charGenMap, a.isApple2e)
if err != nil {
panic(err)
}
cg.setPage(initialCharGenPage)
a.cg = cg
}