Skip to content

Support mobile #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.DS_Store
node_modules/
certs/
roms/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
gbajs2-mobile -- mobile porting version
======

This be forked from gbajs2 that remake to play in mobile device ( safari ) and access from outside.
======

## Preparations
* Install npm and command `npm i` to prepare server environment.
* Generate certs by `openssl req -nodes -new -x509 -keyout server.key -out server.cert` and move that files to `cert/`.
* Prepare some rom file to `roms/`.
* Write `private ip address` in `index.html` file.

## Feature List
* Available in Mobile Broswer
* Save & Load stat
* Server with DB
* Test workspace ( mobile safari, mobile chrome )

gbajs2 -- Community Fork
======

Expand All @@ -23,6 +41,7 @@ Original work by Endrift. Repo: (Archived / No longer maintained) https://github

Copyright © 2012 – 2013, Jeffrey Pfau
Copyright © 2020, Andrew Chase
Copyright © 2020, keicoon15

All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,4 @@
© 2012 – 2013 <a href="http://endrift.com/">Endrift</a>
</footer>
</body>
</html>
</html>
3 changes: 2 additions & 1 deletion js/gba.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class GameBoyAdvance {
this.rom.code + ".sav"
);
}

}
storeSavedata() {
var sram = this.mmu.save;
Expand Down Expand Up @@ -355,7 +356,7 @@ class GameBoyAdvance {
this.irq.defrost(frost.irq);
this.io.defrost(frost.io);
}
log(level, message) {}
log(level, message) { }
setLogger(logger) {
this.log = logger;
}
Expand Down
66 changes: 66 additions & 0 deletions js/keypad.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ class GameBoyAdvanceKeypad {

this.remappingKeyId = "";
}

virtualpadHandler(code, e) {
if (canVibrate) navigator.vibrate(50);

var toggle = 0;

switch (code) {
case 'START':
toggle = this.START;
break;
case 'SELECT':
toggle = this.SELECT;
break;
case 'A':
toggle = this.A;
break;
case 'B':
toggle = this.B;
break;
case 'L':
toggle = this.L;
break;
case 'R':
toggle = this.R;
break;
case 'UP':
toggle = this.UP;
break;
case 'RIGHT':
toggle = this.RIGHT;
break;
case 'DOWN':
toggle = this.DOWN;
break;
case 'LEFT':
toggle = this.LEFT;
break;
default:
return;
}

toggle = 1 << toggle;
if (e.type == "touchstart" || e.type == "mousedown") {
this.currentDown &= ~toggle;
} else {
this.currentDown |= toggle;
}
}

keyboardHandler(e) {
var toggle = 0;

Expand Down Expand Up @@ -164,6 +213,23 @@ class GameBoyAdvanceKeypad {
}
}
registerHandlers() {
if (g_bMobile) {
var childNodes = document.getElementById('virtual-pad').childNodes;
for (var i = 0; i < childNodes.length; i++) {
var childNode = childNodes[i];
if (childNode.nodeName === "BUTTON") {
var code = childNode.id;
childNode.addEventListener(
'touchstart',
this.virtualpadHandler.bind(this, code)
);
childNode.addEventListener(
'touchend',
this.virtualpadHandler.bind(this, code)
);
}
}
}
window.addEventListener(
"keydown",
this.keyboardHandler.bind(this),
Expand Down
Empty file added js/mobile.js
Empty file.
19 changes: 11 additions & 8 deletions js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ class Pointer {
}
}

class Serializer {
TAG_INT = 1;
TAG_STRING = 2;
TAG_STRUCT = 3;
TAG_BLOB = 4;
TAG_BOOLEAN = 5;
TYPE = "application/octet-stream";
class C_Serializer {
constructor() {
this.TAG_INT = 1;
this.TAG_STRING = 2;
this.TAG_STRUCT = 3;
this.TAG_BLOB = 4;
this.TAG_BOOLEAN = 5;
this.TYPE = "application/octet-stream";
}

pack(value) {
var object = new DataView(new ArrayBuffer(4));
Expand All @@ -75,7 +77,7 @@ class Serializer {
serialize(stream) {
var parts = [];
var size = 4;
for (i in stream) {
for (var i in stream) {
if (stream.hasOwnProperty(i)) {
var tag;
var head = Serializer.prefix(i);
Expand Down Expand Up @@ -289,3 +291,4 @@ class Serializer {
reader.readAsDataURL(blob);
}
}
var Serializer = new C_Serializer();
Loading