44 < meta charset ="utf-8 ">
55 < title > Gameboy Emulator</ title >
66 < style >
7- canvas {
8- background-color : black;
7+ body {
8+ margin : 0 ;
9+ padding : 20px ;
10+ display : flex;
11+ flex-direction : column;
12+ align-items : center;
13+ background-color : # 2c2c2c ;
14+ font-family : sans-serif;
15+ }
16+
17+ .gameboy-container {
18+ position : relative;
19+ width : 313px ;
20+ height : 515px ;
21+ z-index : 2 ;
22+ }
23+
24+ .screen-container {
25+ position : absolute;
26+ top : 13% ;
27+ left : 24% ;
28+ width : 160px ;
29+ height : 144px ;
30+ image-rendering : pixelated;
31+ z-index : 2 ;
32+ }
33+
34+ .gameboy-frame {
35+ position : absolute;
36+ top : 0 ;
37+ left : 0 ;
38+ width : 100% ;
39+ height : 100% ;
40+ z-index : -1 ;
41+ pointer-events : none;
42+ }
43+
44+ .file-input-label {
45+ margin : 20px 0 ;
46+ padding : 10px 20px ;
47+ background-color : # 4CAF50 ;
48+ color : white;
49+ border-radius : 5px ;
50+ cursor : pointer;
51+ transition : background-color 0.3s ;
52+ }
53+
54+ .file-input-label : hover {
55+ background-color : # 45a049 ;
56+ }
57+
58+ # rom-input {
59+ display : none;
60+ }
61+
62+ h1 {
63+ color : # fff ;
64+ text-shadow : 2px 2px # 000 ;
65+ margin-bottom : 30px ;
966 }
1067 </ style >
1168</ head >
1269< body id ="emulator-body ">
70+ < h1 > RustBoy 🦀</ h1 >
71+
72+ < label class ="file-input-label " for ="rom-input ">
73+ Load ROM
74+ </ label >
1375< input type ="file " id ="rom-input "/>
14- < canvas id ="screen " width ="160 " height ="144 "> </ canvas >
76+
77+ < div class ="gameboy-container " id ="gameboy-container ">
78+ < img src ="gameboy.png " class ="gameboy-frame " alt ="GameBoy Frame ">
79+ < div class ="screen-container " id ="screen-container ">
80+ </ div >
81+ </ div >
82+
1583< script type ="module ">
1684 import initSync , { run } from './pkg/rustboy.js' ;
1785
2189
2290 const romInput = document . getElementById ( "rom-input" ) ;
2391 romInput . addEventListener ( "change" , ( event ) => {
92+ console . log ( "Loading ROM..." ) ;
2493 const file = event . target . files [ 0 ] ;
2594 if ( ! file ) return ;
2695
2796 const reader = new FileReader ( ) ;
2897 reader . onload = async ( ) => {
2998 const arrayBuffer = reader . result ;
30- // Convert ArrayBuffer to Uint8Array so it can be passed to wasm.
3199 const romData = new Uint8Array ( arrayBuffer ) ;
32100 await run (
33101 false , // headless
47115 main ( ) ;
48116</ script >
49117</ body >
50- </ html >
118+ </ html >
0 commit comments