izapple2/apple2main.go

308 lines
6.7 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"
"os"
"github.com/ivanizag/izapple2/storage"
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",
"<internal>/dos33.dsk",
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.")
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",
2020-08-12 20:50:40 +00:00
1,
"slot for the Memory Expansion card with 1GB. -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",
2020-08-12 20:50:40 +00:00
4,
2019-11-12 22:47:48 +00:00
"slot for the ThunderClock Plus card. -1 for none")
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")
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,
"dump to the console the hd/smarport commands")
2019-04-21 16:18:43 +00:00
dumpChars := flag.Bool(
"dumpChars",
false,
"shows the character map")
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")
forceCaps := flag.Bool(
"forceCaps",
false,
"force all letters to be uppercased (no need for caps lock!)")
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 != "" {
if storage.IsDiskette(filename) {
2020-10-03 21:00:04 +00:00
diskImageFinal = filename
} else {
hardDiskImageFinal = filename
}
}
2020-08-30 19:11:43 +00:00
a := newApple2()
2020-10-16 13:05:38 +00:00
a.setup(*cpuClock, *fastDisk, *traceMLI)
2020-08-30 19:11:43 +00:00
a.io.setTrace(*traceSS)
a.io.setTraceRegistrations(*traceSSReg)
a.io.setPanicNotImplemented(*panicSS)
a.setProfiling(*profile)
a.setForceCaps(*forceCaps)
2020-08-30 19:11:43 +00:00
2019-10-12 19:37:37 +00:00
var charGenMap charColumnMap
initialCharGenPage := 0
switch *model {
case "2plus":
2020-08-30 19:11:43 +00:00
setApple2plus(a)
2019-10-12 19:37:37 +00:00
if *romFile == defaultInternal {
*romFile = "<internal>/Apple2_Plus.rom"
}
if *charRomFile == defaultInternal {
*charRomFile = "<internal>/Apple2rev7CharGen.rom"
}
charGenMap = charGenColumnsMap2Plus
2019-11-22 22:27:25 +00:00
*vidHDCardSlot = -1
2019-10-12 19:37:37 +00:00
case "2e":
2020-08-30 19:11:43 +00:00
setApple2e(a)
2019-10-20 22:06:28 +00:00
if *romFile == defaultInternal {
*romFile = "<internal>/Apple2e.rom"
}
if *charRomFile == defaultInternal {
*charRomFile = "<internal>/Apple IIe Video Unenhanced - 342-0133-A - 2732.bin"
}
a.isApple2e = true
charGenMap = charGenColumnsMap2e
case "2enh":
2020-08-30 19:11:43 +00:00
setApple2eEnhanced(a)
2019-10-12 19:37:37 +00:00
if *romFile == defaultInternal {
*romFile = "<internal>/Apple2e_Enhanced.rom"
}
if *charRomFile == defaultInternal {
*charRomFile = "<internal>/Apple IIe Video Enhanced - 342-0265-A - 2732.bin"
}
a.isApple2e = true
charGenMap = charGenColumnsMap2e
case "base64a":
2020-08-30 19:11:43 +00:00
setBase64a(a)
2019-10-12 19:37:37 +00:00
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
2019-11-22 22:27:25 +00:00
*vidHDCardSlot = -1
2019-10-12 19:37:37 +00:00
default:
panic("Model not supported")
}
a.cpu.SetTrace(*traceCPU)
2019-10-12 19:37:37 +00:00
// Load ROM if not loaded already
if *romFile != "" {
err := a.LoadRom(*romFile)
2019-10-05 23:26:00 +00:00
if err != nil {
panic(err)
}
}
2019-10-12 19:37:37 +00:00
// Load character generator if it loaded already
cg, err := newCharacterGenerator(*charRomFile, charGenMap)
if err != nil {
panic(err)
}
2019-10-12 19:37:37 +00:00
cg.setPage(initialCharGenPage)
a.cg = cg
// Externsion cards
if *languageCardSlot >= 0 {
a.AddLanguageCard(*languageCardSlot)
}
if *saturnCardSlot >= 0 {
a.AddSaturnCard(*saturnCardSlot)
}
if *memoryExpansionCardSlot >= 0 {
2020-10-14 19:54:51 +00:00
a.AddMemoryExpansionCard(*memoryExpansionCardSlot)
}
if *thunderClockCardSlot > 0 {
err := a.AddThunderClockPlusCard(*thunderClockCardSlot,
"<internal>/ThunderclockPlusROM.bin")
2019-10-05 23:26:00 +00:00
if err != nil {
panic(err)
}
}
2019-11-12 22:47:48 +00:00
if *vidHDCardSlot >= 0 {
a.AddVidHD(*vidHDCardSlot)
}
if *smartPortImage != "" {
err := a.AddSmartPortDisk(5, *smartPortImage, *traceHD)
if err != nil {
panic(err)
}
}
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 {
2020-10-14 19:54:51 +00:00
err := a.AddDisk2(*disk2Slot, diskImageFinal, *diskBImage)
2019-10-05 23:26:00 +00:00
if err != nil {
panic(err)
}
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
}
2020-10-03 21:00:04 +00:00
err := a.AddSmartPortDisk(*hardDiskSlot, hardDiskImageFinal, *traceHD)
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)
}
}
2020-10-24 22:22:52 +00:00
// a.AddRomX()
2020-10-14 19:54:51 +00:00
// a.AddCardInOut(2)
// a.AddCardLogger(4)
2019-05-18 21:40:59 +00:00
if *dumpChars {
a.cg.Dump()
os.Exit(0)
return nil
}
return a
2019-01-26 17:57:03 +00:00
}