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-06-01 15:11:25 +00:00
|
|
|
"os"
|
2020-10-17 18:10:48 +00:00
|
|
|
|
|
|
|
"github.com/ivanizag/izapple2/storage"
|
2019-04-13 18:29:31 +00:00
|
|
|
)
|
2019-02-16 19:15:41 +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
|
2019-06-01 15:11:25 +00:00
|
|
|
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,
|
2019-05-17 21:28:20 +00:00
|
|
|
"slot for the disk driver. -1 for none.")
|
2019-04-15 21:13:05 +00:00
|
|
|
diskImage := flag.String(
|
|
|
|
"disk",
|
2019-06-01 18:06:44 +00:00
|
|
|
"<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",
|
|
|
|
"",
|
2020-08-11 21:53:05 +00:00
|
|
|
"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.")
|
2020-08-11 21:53:05 +00:00
|
|
|
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")
|
2019-05-17 21:28:20 +00:00
|
|
|
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")
|
2019-11-10 13:20:31 +00:00
|
|
|
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")
|
2020-03-08 22:39:25 +00:00
|
|
|
memoryExpansionCardSlot := flag.Int(
|
|
|
|
"memoryExpSlot",
|
2020-08-12 20:50:40 +00:00
|
|
|
1,
|
2020-03-08 22:39:25 +00:00
|
|
|
"slot for the Memory Expansion card with 1GB. -1 for none")
|
2020-08-10 18:52:17 +00:00
|
|
|
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")
|
2020-09-01 15:46:30 +00:00
|
|
|
nsc := flag.Int(
|
2020-08-16 13:30:44 +00:00
|
|
|
"nsc",
|
2020-09-01 15:46:30 +00:00
|
|
|
-1,
|
|
|
|
"add a DS1216 No-Slot-Clock on the main ROM (use 0) or a slot ROM. -1 for none")
|
2020-08-06 16:35:34 +00:00
|
|
|
rgbCard := flag.Bool(
|
|
|
|
"rgb",
|
|
|
|
true,
|
|
|
|
"emulate the RGB modes of the 80col RGB card for DHGR")
|
2019-05-10 16:07:36 +00:00
|
|
|
fastDisk := flag.Bool(
|
|
|
|
"fastDisk",
|
|
|
|
true,
|
2019-11-10 13:20:31 +00:00
|
|
|
"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,
|
2019-11-10 13:20:31 +00:00
|
|
|
"panic if a not implemented softswitch is used")
|
2019-09-24 21:32:03 +00:00
|
|
|
traceCPU := flag.Bool(
|
|
|
|
"traceCpu",
|
|
|
|
false,
|
2019-11-10 13:20:31 +00:00
|
|
|
"dump to the console the CPU execution operations")
|
2019-09-24 21:32:03 +00:00
|
|
|
traceSS := flag.Bool(
|
|
|
|
"traceSS",
|
|
|
|
false,
|
2019-11-10 13:20:31 +00:00
|
|
|
"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,
|
2020-08-11 21:53:05 +00:00
|
|
|
"dump to the console the hd/smarport commands")
|
2019-04-21 16:18:43 +00:00
|
|
|
dumpChars := flag.Bool(
|
|
|
|
"dumpChars",
|
|
|
|
false,
|
2019-11-10 13:20:31 +00:00
|
|
|
"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",
|
2019-11-10 13:20:31 +00:00
|
|
|
"set base model. Models available 2plus, 2e, 2enh, base64a")
|
2020-01-11 16:23:34 +00:00
|
|
|
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,
|
2020-08-06 16:35:34 +00:00
|
|
|
"dump to the console the calls to ProDOS machine language interface calls to $BF00")
|
2020-11-02 19:17:00 +00:00
|
|
|
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 != "" {
|
2020-10-17 18:10:48 +00:00
|
|
|
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)
|
2020-11-02 19:17:00 +00:00
|
|
|
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")
|
|
|
|
}
|
2019-09-24 21:32:03 +00:00
|
|
|
|
|
|
|
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-06-09 15:36:29 +00:00
|
|
|
}
|
2019-10-12 19:37:37 +00:00
|
|
|
cg.setPage(initialCharGenPage)
|
|
|
|
a.cg = cg
|
|
|
|
|
|
|
|
// Externsion cards
|
2019-05-17 21:28:20 +00:00
|
|
|
if *languageCardSlot >= 0 {
|
|
|
|
a.AddLanguageCard(*languageCardSlot)
|
|
|
|
}
|
|
|
|
if *saturnCardSlot >= 0 {
|
|
|
|
a.AddSaturnCard(*saturnCardSlot)
|
|
|
|
}
|
2020-03-08 22:39:25 +00:00
|
|
|
if *memoryExpansionCardSlot >= 0 {
|
2020-10-14 19:54:51 +00:00
|
|
|
a.AddMemoryExpansionCard(*memoryExpansionCardSlot)
|
2020-03-08 22:39:25 +00:00
|
|
|
}
|
2019-09-28 11:37:42 +00:00
|
|
|
if *thunderClockCardSlot > 0 {
|
2020-03-08 22:39:25 +00:00
|
|
|
err := a.AddThunderClockPlusCard(*thunderClockCardSlot,
|
|
|
|
"<internal>/ThunderclockPlusROM.bin")
|
2019-10-05 23:26:00 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-09-28 11:37:42 +00:00
|
|
|
}
|
2019-11-12 22:47:48 +00:00
|
|
|
if *vidHDCardSlot >= 0 {
|
2019-11-10 13:20:31 +00:00
|
|
|
a.AddVidHD(*vidHDCardSlot)
|
|
|
|
}
|
2020-08-11 21:53:05 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-08-10 18:52:17 +00:00
|
|
|
if *ramWorksKb != 0 {
|
|
|
|
if *ramWorksKb%64 != 0 {
|
|
|
|
panic("Ramworks size must be a multiple of 64")
|
|
|
|
}
|
|
|
|
a.AddRAMWorks(*ramWorksKb / 64)
|
|
|
|
}
|
|
|
|
|
2020-08-06 16:35:34 +00:00
|
|
|
if *rgbCard {
|
|
|
|
a.AddRGBCard()
|
|
|
|
}
|
|
|
|
|
2020-09-01 15:46:30 +00:00
|
|
|
if *nsc == 0 {
|
2020-08-16 13:30:44 +00:00
|
|
|
a.AddNoSlotClock()
|
2020-09-01 15:46:30 +00:00
|
|
|
} else if *nsc > 0 {
|
|
|
|
err := a.AddNoSlotClockInCard(*nsc)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-08-16 13:30:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-06-09 21:54:27 +00:00
|
|
|
if *dumpChars {
|
|
|
|
a.cg.Dump()
|
|
|
|
os.Exit(0)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-01 15:11:25 +00:00
|
|
|
return a
|
2019-01-26 17:57:03 +00:00
|
|
|
}
|