FruitMachine-Swift/FruitMachine/AppleI/Video/A1CharacterGenerator.swift
Luigi Thirty ab3c32af3d attached the Disk II ROM
peripherals
2017-08-03 00:31:12 -04:00

62 lines
2.3 KiB
Swift

//
// CharacterGenerator.swift
// FruitMachine
//
// Created by Christopher Rohl on 7/26/17.
// Copyright © 2017 Christopher Rohl. All rights reserved.
//
import Cocoa
//The character generator ROM contains 64 8x5 glyphs.
extension AppleI {
class A1CharacterGenerator: NSObject {
static let CHAR_WIDTH = 5
static let CHAR_HEIGHT = 8
var glyphs: [Glyph]
var romManager: ROMDelegate
init(romPath: String) {
glyphs = [Glyph](repeating: Glyph(inPixels: [BitmapPixelsLE555.PixelData]()), count: 64)
romManager = ROMManager(path: romPath, atAddress: 0x00, size: 512)
super.init()
for index in 0..<64 {
glyphs[index] = Glyph(inPixels: getCharacterPixels(charIndex: UInt8(index)))
}
}
private func getCharacterPixels(charIndex: UInt8) -> [BitmapPixelsLE555.PixelData] {
var pixelArray = [UInt8](repeating: 0x00, count: A1CharacterGenerator.CHAR_HEIGHT)
/* Instead of ignoring ASCII bit b6, we ignore bit b5. At the same time ASCII bit b6 must be inverted before it is fed to the character ROM. This way the entire character range from $40 to $7F will end up in the range $00 to $1F (twice of course). Now lower case characters are automatically translated into their corresponding upper case bit maps.
*/
//Don't convert the character indexes if we're populating the glyphs array.
for scanlineIndex in 0..<A1CharacterGenerator.CHAR_HEIGHT {
pixelArray[scanlineIndex] = romManager.ROM[scanlineIndex + (Int(charIndex) * A1CharacterGenerator.CHAR_HEIGHT)]
}
var glyphPixels = [BitmapPixelsLE555.PixelData]()
for charY in 0..<A1CharacterGenerator.CHAR_HEIGHT {
for charX in 0..<8 {
glyphPixels.append(pixelArray[Int(charY)] & (1 << charX) > 0 ? BitmapPixelsLE555.White : BitmapPixelsLE555.Black)
}
}
return glyphPixels
}
func asciiToAppleCharIndex(ascii: UInt8) -> UInt8 {
return (ascii & 0x1f) | (((ascii ^ 0x40) & 0x40) >> 1)
}
}
}