SlideShare a Scribd company logo
GameBoy Emulator 實作
背景瞭解GB CPU 
• 特製簡化Z80 CPU (現在x86系列的開宗淵源) 
– 部分指令集移除.部分opcode有變動.部分行為有 
變動 
• Z80 1976… 38年了(GB Z80 1989 , 25年) 
• 8 bits CPU ….(現在中低階微控設備,還是很多) 
• Program Counter (PC) 定址能力16bits 
(64KB),16條(0~0xfffe 共0xffff個位置) 
• FFFF * (每個address 1byte) / 1024 = 64KBytes
GB Z80 
• Flag : ZNHC 
Zero ,Carry , Half carry , Subtract(Negative) 
• PC .SP (16bits) 
• A,B,C,D,E,H,L ( 8bits) 
• A.F(flag) , BC DE HL 可以各自結合成16bits 
reg
背景瞭解MBC 
• Memory bank controller 
• 64KB ?? 好小…怎麼辦? 
• Address還是一樣只能從0~ 0xFFFE 
• 但內容可以切換 
• 透過寫入理論上唯讀的ROM區,對記憶體內 
容進行切換.(像火車軌道選擇開關) 
• 透過MBC管理,突破64KB記憶體限制 
• GB卡帶有MBC 1.2.3.5,各有其特性.
背景瞭解 
Special Register.Flag.Memory關係 
• Memory除了可以記錄資料外,也可以當成功 
能狀態切換與顯示端口. 
• Flag : 狀態顯示 
– Address 0xFF41 LCD狀態,程式可以透過讀取此位 
址內容之道LCD在哪個狀態(VBLANK,HBLANK…) , 
0xFF00遊戲手把各按鍵狀態 
• Special Register : 對特定記憶址寫入,可以透 
過其每位元bits的0或是1設定一些硬體功能, 
每組的設定方式都不盡然相同.
背景瞭解 
• CPU.APU.GPU.MEM.IO.SCREEN 
• CPU跟MEM溝通來控制幾乎所有的硬體功能 
• 實作上CPU跟MEM是切開的兩大介面和部分 
• CPU只管讀取從PC位置讀取到的指令,把資 
料寫回到MEM,或是作一些運算操作,剩下都 
不管. 
• MEM跟GPU(graphics處理單位)和APU(audio 
處理單位).IO有實際功能的連動
GPU 
• GPU 圖像處理單元,處理畫面背景.SPRITE的 
rendering 
• 遊戲畫面由背景(或是再加上window overlay) 
與Sprite兩大部分構成 
• 背景由back ground map 與title構成 
• Sprite由OAM與TITLE構成 
• Vram包括bg map與title兩個部分
title 
• Title size最基本單位為8x8的block 
• 以array的型態存放在VRAM某段位置 
• 構成畫面的最基本單位 
• 色彩由調色盤定義palette (某address的value)
Title map 
• 一個map資料負責塞入title的編號,構成一個 
背景 
• GB的bg為256x256大小(由32x32個title構成) 
• 螢幕為160x144 pixel 
• 所以螢幕只能呈現這256x256大小中 
160x144個pixel
window 
• 覆蓋在background上的畫面 
• 通常用在特定區域的覆蓋 
• Window來至於bg (bg通常不會只有一組,可 
切換)
OAM 
• 物件(sprite)屬性資料記憶體 
• 一個OAM負責描繪一個SPRITE的特性 
• OAM裡面包括SPRITE使用的TITLE.出現位置. 
使用哪個PALETTE.畫面上下的前後優先權
GPU與MEM 
• Gpu負責把MEM(VRAM內的bg title map . 
Title set. OAM)內的相關資料rendering到螢 
幕上,由硬體處理,很快,軟體需要自己去記算
LCD Status Period 
• 四個周期循環 
• HBLANK 
• Scane Line to buffer (OAM lock) 
• Scanline Iine to buffer (OAM & VRAM lock) 
• VBLANK 
• 由cpu的cycle累加計算來切換模擬出status 
• 為timing的一個重要處理 
• Period計算如果有問題,影響到很多處理
STEP 
• Step 1 抓opcode,pc++ 
• Step 2 處理opcode 
• Step 3檢查是否有中斷,如果有改變pc位置 
• Step 4 timing (哪個period做哪些動作) 
• Step 5 GPU.APU 處理 
• Loop to step 1
JSGB 
JavaScript project 
• http://www.codebase.es/jsgb/ 
• https://github.com/bleepbloop/JsGB 
• 觀念與timing作法參考
BGB 
• http://bgb.bircd.org 
• Debug 
• Trace 
• 驗證
Image filter 
• 遊戲解析度低,需要放大,由於是動態畫面 
(59.X fps),需要高速演算法(如果不借助硬體 
加速) 
• 需要在畫質與計算速度上找到CP值高且可 
接受的平衡 
• HQ2X 
• Scale2x  使用此 
http://scale2x.sourceforge.net

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

20141209 gbemu

  • 2. 背景瞭解GB CPU • 特製簡化Z80 CPU (現在x86系列的開宗淵源) – 部分指令集移除.部分opcode有變動.部分行為有 變動 • Z80 1976… 38年了(GB Z80 1989 , 25年) • 8 bits CPU ….(現在中低階微控設備,還是很多) • Program Counter (PC) 定址能力16bits (64KB),16條(0~0xfffe 共0xffff個位置) • FFFF * (每個address 1byte) / 1024 = 64KBytes
  • 3. GB Z80 • Flag : ZNHC Zero ,Carry , Half carry , Subtract(Negative) • PC .SP (16bits) • A,B,C,D,E,H,L ( 8bits) • A.F(flag) , BC DE HL 可以各自結合成16bits reg
  • 4. 背景瞭解MBC • Memory bank controller • 64KB ?? 好小…怎麼辦? • Address還是一樣只能從0~ 0xFFFE • 但內容可以切換 • 透過寫入理論上唯讀的ROM區,對記憶體內 容進行切換.(像火車軌道選擇開關) • 透過MBC管理,突破64KB記憶體限制 • GB卡帶有MBC 1.2.3.5,各有其特性.
  • 5. 背景瞭解 Special Register.Flag.Memory關係 • Memory除了可以記錄資料外,也可以當成功 能狀態切換與顯示端口. • Flag : 狀態顯示 – Address 0xFF41 LCD狀態,程式可以透過讀取此位 址內容之道LCD在哪個狀態(VBLANK,HBLANK…) , 0xFF00遊戲手把各按鍵狀態 • Special Register : 對特定記憶址寫入,可以透 過其每位元bits的0或是1設定一些硬體功能, 每組的設定方式都不盡然相同.
  • 6. 背景瞭解 • CPU.APU.GPU.MEM.IO.SCREEN • CPU跟MEM溝通來控制幾乎所有的硬體功能 • 實作上CPU跟MEM是切開的兩大介面和部分 • CPU只管讀取從PC位置讀取到的指令,把資 料寫回到MEM,或是作一些運算操作,剩下都 不管. • MEM跟GPU(graphics處理單位)和APU(audio 處理單位).IO有實際功能的連動
  • 7. GPU • GPU 圖像處理單元,處理畫面背景.SPRITE的 rendering • 遊戲畫面由背景(或是再加上window overlay) 與Sprite兩大部分構成 • 背景由back ground map 與title構成 • Sprite由OAM與TITLE構成 • Vram包括bg map與title兩個部分
  • 8. title • Title size最基本單位為8x8的block • 以array的型態存放在VRAM某段位置 • 構成畫面的最基本單位 • 色彩由調色盤定義palette (某address的value)
  • 9. Title map • 一個map資料負責塞入title的編號,構成一個 背景 • GB的bg為256x256大小(由32x32個title構成) • 螢幕為160x144 pixel • 所以螢幕只能呈現這256x256大小中 160x144個pixel
  • 10. window • 覆蓋在background上的畫面 • 通常用在特定區域的覆蓋 • Window來至於bg (bg通常不會只有一組,可 切換)
  • 11. OAM • 物件(sprite)屬性資料記憶體 • 一個OAM負責描繪一個SPRITE的特性 • OAM裡面包括SPRITE使用的TITLE.出現位置. 使用哪個PALETTE.畫面上下的前後優先權
  • 12. GPU與MEM • Gpu負責把MEM(VRAM內的bg title map . Title set. OAM)內的相關資料rendering到螢 幕上,由硬體處理,很快,軟體需要自己去記算
  • 13. LCD Status Period • 四個周期循環 • HBLANK • Scane Line to buffer (OAM lock) • Scanline Iine to buffer (OAM & VRAM lock) • VBLANK • 由cpu的cycle累加計算來切換模擬出status • 為timing的一個重要處理 • Period計算如果有問題,影響到很多處理
  • 14. STEP • Step 1 抓opcode,pc++ • Step 2 處理opcode • Step 3檢查是否有中斷,如果有改變pc位置 • Step 4 timing (哪個period做哪些動作) • Step 5 GPU.APU 處理 • Loop to step 1
  • 15. JSGB JavaScript project • http://www.codebase.es/jsgb/ • https://github.com/bleepbloop/JsGB • 觀念與timing作法參考
  • 16. BGB • http://bgb.bircd.org • Debug • Trace • 驗證
  • 17. Image filter • 遊戲解析度低,需要放大,由於是動態畫面 (59.X fps),需要高速演算法(如果不借助硬體 加速) • 需要在畫質與計算速度上找到CP值高且可 接受的平衡 • HQ2X • Scale2x  使用此 http://scale2x.sourceforge.net