SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Kernal 64
A Commodore 64 Scala emulator
2015
Alessandro Abbruzzetti
abbruzze@gmail.com
What we are not talking about
• Scala type system
• Scala DSL
• Libraries and frameworks
• Plug & play components
• Category theory
• Akka, actors, futures, reactiveness, etc.
What we’re talking about /1
• ”In computing, an emulator is hardware or
software (or both) that enables one computer
system (called the host) to behave like another
computer system (called the guest). An emulator
typically enables the host system to run software
or use peripheral devices designed for the guest
system.
Emulation refers to the ability of a computer
program in an electronic device
to emulate (imitate) another program or device.”
What we’re talking about /2
An emulator:
• needs always the original software of the
emulated system (often, obtained with a
dumping method)
• can be useful to:
– combat obsolescence
– have better graphics quality than original hardware
– allow users to play games for discontinued consoles
– add features original hardware didn't have
Why emulate a Commodore 64 ?
• Because it is not easy
• Because it is funny
• Because there is a huge amount of available
software for it
• Because, still today, there is an active
community of developers and internet sites
• Because of the demoscene (http://csdb.dk)
The Commodore 64 !
Do you remember ?
Startup screen.
Ready (for what ?)
GEOS OS
Commodore 64 History /1
• The Commodore 64 is an 8-bit home computer introduced
in January 1982 by Commodore International. It is listed in
the ”Guinness Book of World Records” as the highest-
selling single computer model of all time with independent
estimates placing the number sold between 10 and 17
million units. More C64s have been sold than any other
single computer system, even to this day.
• Approximately 10,000 commercial software titles have
been made for the Commodore 64 including development
tools, office productivity applications, and games
• At its peak, GEOS (Graphic Environment Operating System)
was the third most popular microcomputer operating
system in the world (trailing only MS-DOS and Mac OS)
Why Scala ?
1. Because does not exist a C64 emulator
written in Scala
2. Because I love Scala and its ecosystem
3. Because an emulator written in C/C++ can
take advantage of low level operations and ...
4. Because I was curious about a Scala
implementation’s performance
Kernal64 – A Commodore 64 emulator
written in the Scala language
It emulates:
• all the main hardware chipset and the
memory (RAM/ROM)
• all the ”internal” I/O devices, like the
keyboard, the monitor, the joysticks, the audio
device,...
• some external I/O device, like the floppy drive,
the magnetic tape data storage device, the
printer, the cartridges,...
Commodore 64 technical information
Introduced January 1982
Released September 1982
End of production 1993
How many ~17 million
Price US $595
CPU MOS 6510, ~1MHz
Sound SID 6581, 3 channels of
sound/ 9 octaves, 4
waveforms
RAM 64K
Display 25 X 40 text
320 X 200, 16 colors max
Ports TV, Tape interfarce, User port,
2 joysticks, cartridge port
serial peripheral port
Peripherals cassette recorder, printer,
modem,external 170K floppy
drive
OS ROM BASIC V2.0 (Microsoft)
Where to start from
• Internet is the main source of information
• A real machine would be welcome
• 99% of C64 related information is available,
but, that 1% cannot be neglected in order to
have a reliable and accurate emulator
• Every component is hard to emulate, but the
VIC (Video Interface Controller) and the Disk
Drive are the hardest ones
• The circuit diagram is mandatory
Perhiperals Overview
Expansion Port
UserPort
Control Port Serial Bus
Cassette Port
PAL/NTSC
Ok, let’s start digging into details...
Commodore 64 Circuit Diagram
Commodore 64 Circuit Diagram
CPU6510
CIA16526CIA26526
VIC
SID
PLA
CHAR
ROM
KERNAL
&BASIC
ROM
RAM
EXPANSION PORT
USERPORTControlportsKeyboard
Serial
bus
C2N
C64 Emulator Block Diagram
6510
C2N
Serial
bus
Key
board
Control
Port #1
Control
Port #2
User
Port
CIA
#1
CIA
#2
clk
clk
clk
DRAM
CHAR
ROM
BASIC
ROM
KERNAL
ROM
PLA
SID
VIC
II
clk
clk
clk
Clock clk
985248 Hz
Expansion Port
nmi irq
rdy
ba
dma
ba
COLOR
RAM
exrom game
Audio
Contr.
CRT
Object Hierarchy
C64Component
C64 Clock CPU_6510
Expansion
Port
IEC
bus
Datassette
CIA
Control
Port
CIA1 CIA2
C1541 VIA
VIA
IECbus
VIA
DiskCtr
Key
board
MPS
803
SIDVIC
Others
RAMs/
ROMs
Memory
Memory Layout/1
RAM RAM RAM RAM
$0000 $A000 $C000 $E000 $FFFF
BASIC
ROM
CHAR
ROM
$D000
I/O
COLOR
RAM
KERNAL
ROM
• 64K RAM
• 8K BASIC ROM
• 8K KERNAL ROM
• 4K CHARACTERS ROM
• 1000 nibbles COLOR RAM
the operating system
Memory Layout/2
CHARACTERS ROM
VIC-II
$D000
SID COLOR RAM
CIA1
CIA2
I/O1
I/O2
$D400 $D800 $DC00/
$DD00
$DE00/
$DF00
Video
Controller
Audio
Controller
Color
RAM
Complex
Interface
Adapters
I/O
Open
Address
Space
The Memory trait
trait Memory {
val isRom: Boolean
val length: Int
val startAddress: Int
lazy val endAddress = startAddress + length
val name: String
def init
def isActive: Boolean
def read(address: Int, chipID: ChipID.ID = ChipID.CPU): Int
def write(address: Int, value: Int, chipID: ChipID.ID = ChipID.CPU)
}
The BridgeMemory class
abstract class BridgeMemory extends Memory {
private[this] var bridges : List[(Int,Int,Memory)] = Nil
...
def addBridge(m:Memory) { … }
@inline private def select(address:Int) : Memory = { … }
final def read(address: Int, chipID: ChipID.ID = ChipID.CPU): Int =
select(address).read(address,chipID)
final def write(address: Int, value: Int, chipID: ChipID.ID = ChipID.CPU) =
select(address).write(address,value,chipID)
}
Memory implementation /1
6510 Memory
BASIC ROM
VIC CIA1 CIA2RAM
Read $A000 Write$D000 Read $DC00
CHAR ROM
Notactive
Notactive
I/O Bridge
Composite pattern
PLA
Memory implementation /2
• Advantages
– Modularity
– Isolation
– Ease of modification
• Disadvantages
– Performance bottleneck
Clock
Clock frequency
φ1 φ2
𝑇 =
1
𝑓
=
1
985248
≃ 1μ𝑠
• Clock frequency is 985248 Hz
• During φ1 phase the VIC chip accesses the bus
• During φ2 phase the 6510 chip accesses the bus
• To emulate the real speed of the C64 the emulator will be able to
process about a million cycles per second
Clock – one thread model
• The emulator has a single source of
synchronization, the clock, like real HW
• The clock is managed by one thread
• If the thread is preempted by the host cpu,
the emulator slows down
• Multithread model is very difficult to realize
(the C64 6510 cpu running on T1 and the 1541
disk drive 6502 cpu runing on T2)
Emulator main loop /1
cycles/sec
Δ
delay
985248 reference
cycles
Core
sequence
Clock’s Thread Loop
calibration
Emulator main loop /2
1. Scheduler
2. VIC φ1
3. Bus devices
I. Disk drives
II. Printer
4. CPU φ2
A clock cycle is consumed by every component that needs it
Scheduler
It manages a linked list of ordered future events.
The time, in the emulator’s world, is discrete and its value is
determined by the number of elapsed cycles.
when
what to
do
next
cycles time0 x
Function2[Long] → Unit
Clock ins and outs
class Clock private
(errorHandler:Option[(Throwable) =>Unit],
name:String = "Clock")(mainLoop: (Long) => Unit) extends
Thread(name) with C64Component {
private class ClockEvent (val id : String,
val when : Long,
val execute: (Long) => Unit)
private class EventList(val e:ClockEvent,
var next:EventList = null)
private[this] var events : EventList = null
private[this] var cycles = 0L
}
CPU
6510 opcodes & cycles
6510 opcode execution flow
Fetch
MEMORY
RDY?
Decode
Execute
INT?
op1 ... opN
Interrupt
Handler
RDY?
no
no
• PC
• A
• X
• Y
• SP
• FLAGS micro program
Main components
Main component – CPU 6510
• PC
• A
• X
• Y
• SP
• FLAGSLDA1
Current
state
LDAn
...
STA1
...
STAk
...
RTS1
...
RTSm
Function1[Unit]
micro states
Ready
signalMEMORY
R/W
IRQs
Main component – CIA 6526
Scheduler
events
Timer A Timer B
State machine - control Logic
Data Port
External devices
MEMORY
I/O
mapped
TOD
Main component – SID 6581
javax.sound.
sampled.AudioDriver
44kHz sampling,
mono
MEMORY
I/O
mapped
ReSID library Scheduler
Main component – VIC 6567(9)
RASTER
MANAGEMENT
PAL = 312 lines
Video Matrix
Management
Sprites
Management
Graphics Data
Sequencer
Sprites Data
Sequencer
MUX
Sprite priorities and collision detection
Border Unit
IRQ MANAGEMENT
(lightpen,collisions,
raster)
JPanel +
java.awt.image.
MemoryImageSource
16K
Bank
I/O
mapped
COLOR
RAM
Display
Motor &
R/W
logic
1541 Block Diagram
IEC BUS
ATN
CLK
DAT
PLA
2K
RAM
DOS
ROM
IRQ
SO
GCR (Group code recording)
D64
dump
1541 – floppy disk layout
300 RPM
1541 – disk zones
Exchanging data with drive C1541
C1541
Drive
C64
CIA2
PortBPortA
IEC Bus
CPU
6510CPU
6502
User Port
clock
data
0 0 1 0
VIAIECBus
CIA2 data port A spec.
Address range: $DD00-$DDFF, 56576-56831 Tasks: Serial bus, RS-232, VIC memory, NMI control
Address
Hex
Address
Dec
Register Function Remark
$DD00 56576
0
PRA
Data Port A
•Bit 0..1: Select the position of the VIC-memory
%00, 0: Bank 3: $C000-$FFFF, 49152-65535
• %01, 1: Bank 2: $8000-$BFFF, 32768-49151
• %10, 2: Bank 1: $4000-$7FFF, 16384-32767
• %11, 3: Bank 0: $0000-$3FFF, 0-16383 (standard)
Bit 2: RS-232: TXD Output, userport: Data PA 2 (pin M)
Bit 3..5: serial bus Output (0=High/Inactive,
1=Low/Active)
•Bit 3: ATN OUT
•Bit 4: CLOCK OUT
•Bit 5: DATA OUT
Bit 6..7: serial bus Input (0=Low/Active,
1=High/Inactive)
•Bit 6: CLOCK IN
•Bit 7: DATA IN
... ... ... ... …
CIA2 port A implementation
class PortAConnector(mem:BankedMemory,bus:IECBus,rs232:RS232) extends Connector with
IECBusListener {
…
val busid = "CIA2_PortA"
import IECBus.bus._
final def read : Int =
(~((clk << 6) | (data << 7)) & 0xC0) | (latch & 0x3C) | bank |
rs232.getTXD << 2
final protected def performWrite(data:Int) = {
val value = data | ~ddr
bank = value & 3
mem.setBank(bank)
bus.setLine(busid,if ((value & 8) > 0) GROUND else VOLTAGE, // ATN
if ((value & 32) > 0) GROUND else VOLTAGE, // DATA
if ((value & 16) > 0) GROUND else VOLTAGE) // CLOCK
if ((ddr & 4) > 0) rs232.setTXD((data >> 2) & 1)
}
}
RAM
$0000
$DD00
$FFFF
Let’s connect to BBS via Internet!
http://cbbsoutpost.servebbs.com/
• Bulletin Board System are still alive.
• BBS now use the telnet protocol instead of
modems
• SwiftLink cartridge implementation
Scala performance notes
• Avoid private val/var x when possible, use
private[this] val/var x instead
• Use @inline annotation
• Avoid for loops. Use while loops instead
• Avoid by name parameters
DEMO
• Turrican II (1991 by Rainbow Arts)
• Comaland (Censor Design, Oxyron), a demo
from X’2014 Demo Competition (it won the
compo!)
def Q&A(q:Query) : Option[Answer]
THANK YOU! 2015

Weitere ähnliche Inhalte

Was ist angesagt?

OzKFest 2015 - (Solid) State of the Nation
OzKFest 2015 - (Solid) State of the NationOzKFest 2015 - (Solid) State of the Nation
OzKFest 2015 - (Solid) State of the Nationapple2europlus
 
Putting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internetPutting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internetAndrew Roughan
 
New Commodore 64 Network Game Developments
New Commodore 64 Network Game DevelopmentsNew Commodore 64 Network Game Developments
New Commodore 64 Network Game DevelopmentsLeif Bloomquist
 
Kernel Recipes 2013 - Overview display in the Linux kernel
Kernel Recipes 2013 - Overview display in the Linux kernelKernel Recipes 2013 - Overview display in the Linux kernel
Kernel Recipes 2013 - Overview display in the Linux kernelAnne Nicolas
 
ELC North America 2021 Introduction to pin muxing and gpio control under linux
ELC  North America 2021 Introduction to pin muxing and gpio control under linuxELC  North America 2021 Introduction to pin muxing and gpio control under linux
ELC North America 2021 Introduction to pin muxing and gpio control under linuxNeil Armstrong
 
ELC-E 2019 Device tree, past, present, future
ELC-E 2019 Device tree, past, present, futureELC-E 2019 Device tree, past, present, future
ELC-E 2019 Device tree, past, present, futureNeil Armstrong
 
Interfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the WorldInterfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the WorldOmer Kilic
 
Linux Conference Australia 2018 : Device Tree, past, present, future
Linux Conference Australia 2018 : Device Tree, past, present, futureLinux Conference Australia 2018 : Device Tree, past, present, future
Linux Conference Australia 2018 : Device Tree, past, present, futureNeil Armstrong
 
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Neil Armstrong
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaAnne Nicolas
 
Interacting with Intel Edison
Interacting with Intel EdisonInteracting with Intel Edison
Interacting with Intel EdisonFITC
 
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...Neil Armstrong
 
Lee 2020 what the clock !
Lee 2020  what the clock !Lee 2020  what the clock !
Lee 2020 what the clock !Neil Armstrong
 
uRock @ Jserv Course Final
uRock @ Jserv Course Final uRock @ Jserv Course Final
uRock @ Jserv Course Final 宗凡 楊
 

Was ist angesagt? (20)

OzKFest 2015 - (Solid) State of the Nation
OzKFest 2015 - (Solid) State of the NationOzKFest 2015 - (Solid) State of the Nation
OzKFest 2015 - (Solid) State of the Nation
 
Putting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internetPutting an Apple IIgs BBS on the internet
Putting an Apple IIgs BBS on the internet
 
A2 Video Streamer
A2 Video StreamerA2 Video Streamer
A2 Video Streamer
 
Asus Tinker Board
Asus Tinker BoardAsus Tinker Board
Asus Tinker Board
 
Asus Tinker Board
Asus Tinker BoardAsus Tinker Board
Asus Tinker Board
 
New Commodore 64 Network Game Developments
New Commodore 64 Network Game DevelopmentsNew Commodore 64 Network Game Developments
New Commodore 64 Network Game Developments
 
Kernel Recipes 2013 - Overview display in the Linux kernel
Kernel Recipes 2013 - Overview display in the Linux kernelKernel Recipes 2013 - Overview display in the Linux kernel
Kernel Recipes 2013 - Overview display in the Linux kernel
 
ELC North America 2021 Introduction to pin muxing and gpio control under linux
ELC  North America 2021 Introduction to pin muxing and gpio control under linuxELC  North America 2021 Introduction to pin muxing and gpio control under linux
ELC North America 2021 Introduction to pin muxing and gpio control under linux
 
ELC-E 2019 Device tree, past, present, future
ELC-E 2019 Device tree, past, present, futureELC-E 2019 Device tree, past, present, future
ELC-E 2019 Device tree, past, present, future
 
Interfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the WorldInterfacing the Raspberry Pi to the World
Interfacing the Raspberry Pi to the World
 
Linux Conference Australia 2018 : Device Tree, past, present, future
Linux Conference Australia 2018 : Device Tree, past, present, futureLinux Conference Australia 2018 : Device Tree, past, present, future
Linux Conference Australia 2018 : Device Tree, past, present, future
 
It's game time
It's game timeIt's game time
It's game time
 
Hardware Hacks
Hardware HacksHardware Hacks
Hardware Hacks
 
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
 
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimediaEmbedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
Embedded Recipes 2019 - Pipewire a new foundation for embedded multimedia
 
Interacting with Intel Edison
Interacting with Intel EdisonInteracting with Intel Edison
Interacting with Intel Edison
 
Linux Audio Drivers. ALSA
Linux Audio Drivers. ALSALinux Audio Drivers. ALSA
Linux Audio Drivers. ALSA
 
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...
ELC-E 2016 Neil Armstrong - No, it's never too late to upstream your legacy l...
 
Lee 2020 what the clock !
Lee 2020  what the clock !Lee 2020  what the clock !
Lee 2020 what the clock !
 
uRock @ Jserv Course Final
uRock @ Jserv Course Final uRock @ Jserv Course Final
uRock @ Jserv Course Final
 

Andere mochten auch (6)

Breve storia dei Videogames
Breve storia dei VideogamesBreve storia dei Videogames
Breve storia dei Videogames
 
Sesso e videogiochi
Sesso e videogiochiSesso e videogiochi
Sesso e videogiochi
 
Dal bit al simulacro
Dal bit al simulacroDal bit al simulacro
Dal bit al simulacro
 
Fondamenti di level design
Fondamenti di level designFondamenti di level design
Fondamenti di level design
 
Introduzione al Game Design
Introduzione al Game DesignIntroduzione al Game Design
Introduzione al Game Design
 
La storia dei videogiochi
La storia dei videogiochiLa storia dei videogiochi
La storia dei videogiochi
 

Ähnlich wie Alessandro Abbruzzetti - Kernal64

Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advancedImran Sheikh
 
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)byteLAKE
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)Gustavo Rene Antunez
 
System unit and ip cycle
System unit and ip cycleSystem unit and ip cycle
System unit and ip cycleAtif Nauman
 
Cyclone II FPGA Overview
Cyclone II FPGA OverviewCyclone II FPGA Overview
Cyclone II FPGA OverviewPremier Farnell
 
Rico board
Rico boardRico board
Rico boardmyirtech
 
Renaissance of sparc UKOUG 2014
Renaissance of sparc UKOUG 2014Renaissance of sparc UKOUG 2014
Renaissance of sparc UKOUG 2014Philippe Fierens
 
Sparc t4 2 system technical overview
Sparc t4 2 system technical overviewSparc t4 2 system technical overview
Sparc t4 2 system technical overviewsolarisyougood
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.pptMrZeke1
 
PC Components_Hardware_Software_CSS11.ppt
PC Components_Hardware_Software_CSS11.pptPC Components_Hardware_Software_CSS11.ppt
PC Components_Hardware_Software_CSS11.pptRiannel Tecson
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.pptVida533595
 
Ahsan by computer component information
Ahsan by computer component informationAhsan by computer component information
Ahsan by computer component informationAhsanUbaidi
 
PC Components.pptx
PC Components.pptxPC Components.pptx
PC Components.pptxElmerPogoy
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.pptRoyTari
 
Morello Technology Demonstrator Hardware Overview - Mark Inskip, Arm
Morello Technology Demonstrator Hardware Overview - Mark Inskip, ArmMorello Technology Demonstrator Hardware Overview - Mark Inskip, Arm
Morello Technology Demonstrator Hardware Overview - Mark Inskip, ArmKTN
 

Ähnlich wie Alessandro Abbruzzetti - Kernal64 (20)

Micro controller & Micro processor
Micro controller & Micro processorMicro controller & Micro processor
Micro controller & Micro processor
 
Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advanced
 
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)
CFD acceleration with FPGA (byteLAKE's presentation from PPAM 2019)
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)
 
System unit and ip cycle
System unit and ip cycleSystem unit and ip cycle
System unit and ip cycle
 
Cyclone II FPGA Overview
Cyclone II FPGA OverviewCyclone II FPGA Overview
Cyclone II FPGA Overview
 
Rico board
Rico boardRico board
Rico board
 
Renaissance of sparc UKOUG 2014
Renaissance of sparc UKOUG 2014Renaissance of sparc UKOUG 2014
Renaissance of sparc UKOUG 2014
 
Sparc t4 2 system technical overview
Sparc t4 2 system technical overviewSparc t4 2 system technical overview
Sparc t4 2 system technical overview
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.ppt
 
PC Components_Hardware_Software_CSS11.ppt
PC Components_Hardware_Software_CSS11.pptPC Components_Hardware_Software_CSS11.ppt
PC Components_Hardware_Software_CSS11.ppt
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.ppt
 
Ahsan by computer component information
Ahsan by computer component informationAhsan by computer component information
Ahsan by computer component information
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.ppt
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.ppt
 
PC Components.pptx
PC Components.pptxPC Components.pptx
PC Components.pptx
 
PC Components.ppt
PC Components.pptPC Components.ppt
PC Components.ppt
 
SoC FPGA Technology
SoC FPGA TechnologySoC FPGA Technology
SoC FPGA Technology
 
AMD K6
AMD K6AMD K6
AMD K6
 
Morello Technology Demonstrator Hardware Overview - Mark Inskip, Arm
Morello Technology Demonstrator Hardware Overview - Mark Inskip, ArmMorello Technology Demonstrator Hardware Overview - Mark Inskip, Arm
Morello Technology Demonstrator Hardware Overview - Mark Inskip, Arm
 

Mehr von Scala Italy

Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsScala Italy
 
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaScala Italy
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Scala Italy
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesScala Italy
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaScala Italy
 
Daniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaDaniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaScala Italy
 
Mirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsMirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsScala Italy
 
Phil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionPhil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionScala Italy
 
Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scala Italy
 
Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala Italy
 
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Scala Italy
 
Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Scala Italy
 
Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala Italy
 

Mehr von Scala Italy (13)

Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on ScalaAndrea Lattuada, Gabriele Petronella - Building startups on Scala
Andrea Lattuada, Gabriele Petronella - Building startups on Scala
 
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
Stefano Rocco, Roberto Bentivoglio - Scala in increasingly demanding environm...
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservices
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Daniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to AkkaDaniela Sfregola - Intro to Akka
Daniela Sfregola - Intro to Akka
 
Mirco Dotta - Akka Streams
Mirco Dotta - Akka StreamsMirco Dotta - Akka Streams
Mirco Dotta - Akka Streams
 
Phil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a functionPhil Calçado - Your microservice as a function
Phil Calçado - Your microservice as a function
 
Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)Scalatra - Massimiliano Dessì (Energeya)
Scalatra - Massimiliano Dessì (Energeya)
 
Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)Scala: the language of languages - Mario Fusco (Red Hat)
Scala: the language of languages - Mario Fusco (Red Hat)
 
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
Reflection in Scala Whats, Whys and Hows - Walter Cazzola (Dipartimento di In...
 
Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)
 
Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)Scala in pratica - Stefano Rocco (MoneyFarm)
Scala in pratica - Stefano Rocco (MoneyFarm)
 

Kürzlich hochgeladen

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Kürzlich hochgeladen (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Alessandro Abbruzzetti - Kernal64

  • 1. Kernal 64 A Commodore 64 Scala emulator 2015 Alessandro Abbruzzetti abbruzze@gmail.com
  • 2. What we are not talking about • Scala type system • Scala DSL • Libraries and frameworks • Plug & play components • Category theory • Akka, actors, futures, reactiveness, etc.
  • 3. What we’re talking about /1 • ”In computing, an emulator is hardware or software (or both) that enables one computer system (called the host) to behave like another computer system (called the guest). An emulator typically enables the host system to run software or use peripheral devices designed for the guest system. Emulation refers to the ability of a computer program in an electronic device to emulate (imitate) another program or device.”
  • 4. What we’re talking about /2 An emulator: • needs always the original software of the emulated system (often, obtained with a dumping method) • can be useful to: – combat obsolescence – have better graphics quality than original hardware – allow users to play games for discontinued consoles – add features original hardware didn't have
  • 5. Why emulate a Commodore 64 ? • Because it is not easy • Because it is funny • Because there is a huge amount of available software for it • Because, still today, there is an active community of developers and internet sites • Because of the demoscene (http://csdb.dk)
  • 6. The Commodore 64 ! Do you remember ?
  • 9. Commodore 64 History /1 • The Commodore 64 is an 8-bit home computer introduced in January 1982 by Commodore International. It is listed in the ”Guinness Book of World Records” as the highest- selling single computer model of all time with independent estimates placing the number sold between 10 and 17 million units. More C64s have been sold than any other single computer system, even to this day. • Approximately 10,000 commercial software titles have been made for the Commodore 64 including development tools, office productivity applications, and games • At its peak, GEOS (Graphic Environment Operating System) was the third most popular microcomputer operating system in the world (trailing only MS-DOS and Mac OS)
  • 10. Why Scala ? 1. Because does not exist a C64 emulator written in Scala 2. Because I love Scala and its ecosystem 3. Because an emulator written in C/C++ can take advantage of low level operations and ... 4. Because I was curious about a Scala implementation’s performance
  • 11. Kernal64 – A Commodore 64 emulator written in the Scala language It emulates: • all the main hardware chipset and the memory (RAM/ROM) • all the ”internal” I/O devices, like the keyboard, the monitor, the joysticks, the audio device,... • some external I/O device, like the floppy drive, the magnetic tape data storage device, the printer, the cartridges,...
  • 12. Commodore 64 technical information Introduced January 1982 Released September 1982 End of production 1993 How many ~17 million Price US $595 CPU MOS 6510, ~1MHz Sound SID 6581, 3 channels of sound/ 9 octaves, 4 waveforms RAM 64K Display 25 X 40 text 320 X 200, 16 colors max Ports TV, Tape interfarce, User port, 2 joysticks, cartridge port serial peripheral port Peripherals cassette recorder, printer, modem,external 170K floppy drive OS ROM BASIC V2.0 (Microsoft)
  • 13. Where to start from • Internet is the main source of information • A real machine would be welcome • 99% of C64 related information is available, but, that 1% cannot be neglected in order to have a reliable and accurate emulator • Every component is hard to emulate, but the VIC (Video Interface Controller) and the Disk Drive are the hardest ones • The circuit diagram is mandatory
  • 14. Perhiperals Overview Expansion Port UserPort Control Port Serial Bus Cassette Port PAL/NTSC
  • 15. Ok, let’s start digging into details...
  • 17. Commodore 64 Circuit Diagram CPU6510 CIA16526CIA26526 VIC SID PLA CHAR ROM KERNAL &BASIC ROM RAM EXPANSION PORT USERPORTControlportsKeyboard Serial bus C2N
  • 18. C64 Emulator Block Diagram 6510 C2N Serial bus Key board Control Port #1 Control Port #2 User Port CIA #1 CIA #2 clk clk clk DRAM CHAR ROM BASIC ROM KERNAL ROM PLA SID VIC II clk clk clk Clock clk 985248 Hz Expansion Port nmi irq rdy ba dma ba COLOR RAM exrom game Audio Contr. CRT
  • 19. Object Hierarchy C64Component C64 Clock CPU_6510 Expansion Port IEC bus Datassette CIA Control Port CIA1 CIA2 C1541 VIA VIA IECbus VIA DiskCtr Key board MPS 803 SIDVIC Others RAMs/ ROMs
  • 21. Memory Layout/1 RAM RAM RAM RAM $0000 $A000 $C000 $E000 $FFFF BASIC ROM CHAR ROM $D000 I/O COLOR RAM KERNAL ROM • 64K RAM • 8K BASIC ROM • 8K KERNAL ROM • 4K CHARACTERS ROM • 1000 nibbles COLOR RAM the operating system
  • 22. Memory Layout/2 CHARACTERS ROM VIC-II $D000 SID COLOR RAM CIA1 CIA2 I/O1 I/O2 $D400 $D800 $DC00/ $DD00 $DE00/ $DF00 Video Controller Audio Controller Color RAM Complex Interface Adapters I/O Open Address Space
  • 23. The Memory trait trait Memory { val isRom: Boolean val length: Int val startAddress: Int lazy val endAddress = startAddress + length val name: String def init def isActive: Boolean def read(address: Int, chipID: ChipID.ID = ChipID.CPU): Int def write(address: Int, value: Int, chipID: ChipID.ID = ChipID.CPU) }
  • 24. The BridgeMemory class abstract class BridgeMemory extends Memory { private[this] var bridges : List[(Int,Int,Memory)] = Nil ... def addBridge(m:Memory) { … } @inline private def select(address:Int) : Memory = { … } final def read(address: Int, chipID: ChipID.ID = ChipID.CPU): Int = select(address).read(address,chipID) final def write(address: Int, value: Int, chipID: ChipID.ID = ChipID.CPU) = select(address).write(address,value,chipID) }
  • 25. Memory implementation /1 6510 Memory BASIC ROM VIC CIA1 CIA2RAM Read $A000 Write$D000 Read $DC00 CHAR ROM Notactive Notactive I/O Bridge Composite pattern PLA
  • 26. Memory implementation /2 • Advantages – Modularity – Isolation – Ease of modification • Disadvantages – Performance bottleneck
  • 27. Clock
  • 28. Clock frequency φ1 φ2 𝑇 = 1 𝑓 = 1 985248 ≃ 1μ𝑠 • Clock frequency is 985248 Hz • During φ1 phase the VIC chip accesses the bus • During φ2 phase the 6510 chip accesses the bus • To emulate the real speed of the C64 the emulator will be able to process about a million cycles per second
  • 29. Clock – one thread model • The emulator has a single source of synchronization, the clock, like real HW • The clock is managed by one thread • If the thread is preempted by the host cpu, the emulator slows down • Multithread model is very difficult to realize (the C64 6510 cpu running on T1 and the 1541 disk drive 6502 cpu runing on T2)
  • 30. Emulator main loop /1 cycles/sec Δ delay 985248 reference cycles Core sequence Clock’s Thread Loop calibration
  • 31. Emulator main loop /2 1. Scheduler 2. VIC φ1 3. Bus devices I. Disk drives II. Printer 4. CPU φ2 A clock cycle is consumed by every component that needs it
  • 32. Scheduler It manages a linked list of ordered future events. The time, in the emulator’s world, is discrete and its value is determined by the number of elapsed cycles. when what to do next cycles time0 x Function2[Long] → Unit
  • 33. Clock ins and outs class Clock private (errorHandler:Option[(Throwable) =>Unit], name:String = "Clock")(mainLoop: (Long) => Unit) extends Thread(name) with C64Component { private class ClockEvent (val id : String, val when : Long, val execute: (Long) => Unit) private class EventList(val e:ClockEvent, var next:EventList = null) private[this] var events : EventList = null private[this] var cycles = 0L }
  • 34. CPU
  • 35. 6510 opcodes & cycles
  • 36. 6510 opcode execution flow Fetch MEMORY RDY? Decode Execute INT? op1 ... opN Interrupt Handler RDY? no no • PC • A • X • Y • SP • FLAGS micro program
  • 38. Main component – CPU 6510 • PC • A • X • Y • SP • FLAGSLDA1 Current state LDAn ... STA1 ... STAk ... RTS1 ... RTSm Function1[Unit] micro states Ready signalMEMORY R/W IRQs
  • 39. Main component – CIA 6526 Scheduler events Timer A Timer B State machine - control Logic Data Port External devices MEMORY I/O mapped TOD
  • 40. Main component – SID 6581 javax.sound. sampled.AudioDriver 44kHz sampling, mono MEMORY I/O mapped ReSID library Scheduler
  • 41. Main component – VIC 6567(9) RASTER MANAGEMENT PAL = 312 lines Video Matrix Management Sprites Management Graphics Data Sequencer Sprites Data Sequencer MUX Sprite priorities and collision detection Border Unit IRQ MANAGEMENT (lightpen,collisions, raster) JPanel + java.awt.image. MemoryImageSource 16K Bank I/O mapped COLOR RAM
  • 43. Motor & R/W logic 1541 Block Diagram IEC BUS ATN CLK DAT PLA 2K RAM DOS ROM IRQ SO GCR (Group code recording) D64 dump
  • 44. 1541 – floppy disk layout 300 RPM
  • 45. 1541 – disk zones
  • 46. Exchanging data with drive C1541 C1541 Drive C64 CIA2 PortBPortA IEC Bus CPU 6510CPU 6502 User Port clock data 0 0 1 0 VIAIECBus
  • 47. CIA2 data port A spec. Address range: $DD00-$DDFF, 56576-56831 Tasks: Serial bus, RS-232, VIC memory, NMI control Address Hex Address Dec Register Function Remark $DD00 56576 0 PRA Data Port A •Bit 0..1: Select the position of the VIC-memory %00, 0: Bank 3: $C000-$FFFF, 49152-65535 • %01, 1: Bank 2: $8000-$BFFF, 32768-49151 • %10, 2: Bank 1: $4000-$7FFF, 16384-32767 • %11, 3: Bank 0: $0000-$3FFF, 0-16383 (standard) Bit 2: RS-232: TXD Output, userport: Data PA 2 (pin M) Bit 3..5: serial bus Output (0=High/Inactive, 1=Low/Active) •Bit 3: ATN OUT •Bit 4: CLOCK OUT •Bit 5: DATA OUT Bit 6..7: serial bus Input (0=Low/Active, 1=High/Inactive) •Bit 6: CLOCK IN •Bit 7: DATA IN ... ... ... ... …
  • 48. CIA2 port A implementation class PortAConnector(mem:BankedMemory,bus:IECBus,rs232:RS232) extends Connector with IECBusListener { … val busid = "CIA2_PortA" import IECBus.bus._ final def read : Int = (~((clk << 6) | (data << 7)) & 0xC0) | (latch & 0x3C) | bank | rs232.getTXD << 2 final protected def performWrite(data:Int) = { val value = data | ~ddr bank = value & 3 mem.setBank(bank) bus.setLine(busid,if ((value & 8) > 0) GROUND else VOLTAGE, // ATN if ((value & 32) > 0) GROUND else VOLTAGE, // DATA if ((value & 16) > 0) GROUND else VOLTAGE) // CLOCK if ((ddr & 4) > 0) rs232.setTXD((data >> 2) & 1) } } RAM $0000 $DD00 $FFFF
  • 49. Let’s connect to BBS via Internet! http://cbbsoutpost.servebbs.com/ • Bulletin Board System are still alive. • BBS now use the telnet protocol instead of modems • SwiftLink cartridge implementation
  • 50. Scala performance notes • Avoid private val/var x when possible, use private[this] val/var x instead • Use @inline annotation • Avoid for loops. Use while loops instead • Avoid by name parameters
  • 51. DEMO • Turrican II (1991 by Rainbow Arts) • Comaland (Censor Design, Oxyron), a demo from X’2014 Demo Competition (it won the compo!)
  • 52. def Q&A(q:Query) : Option[Answer]