izapple2/cardParallelPrinter.go

67 lines
1.8 KiB
Go
Raw Permalink Normal View History

package izapple2
import (
"os"
)
/*
Apple II Parallel Printer Interface card.
See:
https://mirrors.apple2.org.za/Apple%20II%20Documentation%20Project/Interface%20Cards/Parallel/Apple%20II%20Parallel%20Printer%20Interface%20Card/
*/
// CardParallelPrinter represents a Parallel Printer Interface card
type CardParallelPrinter struct {
cardBase
2024-01-06 20:48:23 +00:00
file *os.File
ascii bool
}
2024-01-06 20:48:23 +00:00
func newCardParallelPrinterBuilder() *cardBuilder {
return &cardBuilder{
name: "Parallel Printer Interface",
2024-02-08 21:17:14 +00:00
description: "Card to dump to a file what would be printed to a parallel printer",
2024-01-06 20:48:23 +00:00
defaultParams: &[]paramSpec{
{"file", "File to store the printed code", "printer.out"},
{"ascii", "Remove the 7 bit. Useful for normal text printing, but breaks graphics printing ", "false"},
},
buildFunc: func(params map[string]string) (Card, error) {
var c CardParallelPrinter
c.ascii = paramsGetBool(params, "ascii")
filepath := paramsGetPath(params, "file")
f, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
c.file = f
2024-03-24 19:15:16 +00:00
err = c.loadRomFromResource("<internal>/Apple II Parallel Printer Interface Card ROM fixed.bin", cardRomSimple)
2024-01-06 20:48:23 +00:00
if err != nil {
return nil, err
}
return &c, nil
},
}
2024-01-06 20:48:23 +00:00
}
2024-01-06 20:48:23 +00:00
func (c *CardParallelPrinter) assign(a *Apple2, slot int) {
2022-08-05 17:43:17 +00:00
c.addCardSoftSwitchW(0, func(value uint8) {
c.printByte(value)
}, "PARALLELDEVW")
c.addCardSoftSwitchR(4, func() uint8 {
return 0xff // TODO: What are the bit values?
}, "PARALLELSTATUSR")
c.cardBase.assign(a, slot)
}
func (c *CardParallelPrinter) printByte(value uint8) {
2024-01-06 20:48:23 +00:00
if c.ascii {
// As text the MSB has to be removed, but if done, graphics modes won't work
value = value & 0x7f // Remove the MSB bit
}
c.file.Write([]byte{value})
}