Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ASOPT=--warn -mcpu=arm1176jzf-s
# available
CCOPT=-O6 -ffreestanding -marm -mcpu=arm1176jzf-s -std=c99 -fpack-struct -Wno-packed-bitfield-compat

CFLAGS=-DSQ_CONFIG_DONE=1 -DNO_ISNAN=1 -fshort-wchar -DTYPE_LOWLEVEL -DTARGET_RPI -DLIB_HUB -DLIB_HID -DLIB_KBD -DFINAL -Iusb -Isqueak -Ibcm2835 -Ilib
CFLAGS=-DSQ_CONFIG_DONE=1 -DSQUEAK_BUILTIN_PLUGIN=1 -DNO_ISNAN=1 -fshort-wchar -DTYPE_LOWLEVEL -DTARGET_RPI -DLIB_HUB -DLIB_HID -DLIB_KBD -DFINAL -Iusb -Isqueak -Ibcm2835 -Ilib

BUILDDIR=build

Expand Down
66 changes: 66 additions & 0 deletions bcm2835/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* config.h. Generated automatically by configure. */
/* config.h.in -- template for config.h -*- C -*-
*
* Copyright (C) 1996-2002 Ian Piumarta and other authors/contributors
* as listed elsewhere in this file.
* All rights reserved.
*
* This file is part of Unix Squeak.
*
* This file is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You may use and/or distribute this file ONLY as part of Squeak, under
* the terms of the Squeak License as described in `LICENSE' in the base of
* this distribution, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment to the original author(s) (and any
* other contributors mentioned herein) in the product documentation
* would be appreciated but is not required.
*
* 2. This notice must not be removed or altered in any source distribution.
*
* Using (or modifying this file for use) in any context other than Squeak
* changes these copyright conditions. Read the file `COPYING' in the
* directory `platforms/unix/doc' before proceeding with any such use.
*
* You are not allowed to distribute a modified version of this file
* under its original name without explicit permission to do so. If
* you change it, rename it.
*/

/* Author: Ian.Piumarta@INRIA.Fr
*
* Last edited: 2002-11-30 16:00:59 by piumarta on calvin.inria.fr
*/

/* typedefs */

/* #undef size_t */
/* #undef socklen_t */

#define squeakInt64 long long

/* architecture */

#define OS_TYPE "unix"

#define VM_HOST "armv6l-none-eabi"
#define VM_HOST_CPU "armv6l"
/* #undef VM_HOST_VENDOR */
#define VM_HOST_OS "none-eabi"

#undef WORDS_BIGENDIAN
#undef DOUBLE_WORD_ALIGNMENT
#define DOUBLE_WORD_ORDER 1

/* other configured variables */

#define SQ_VERSION "3.4-5170"
#define VM_VERSION "3.4-1"
#define VM_LIBDIR "/usr/local/lib/squeak/3.4-1"
#define VM_MODULE_PREFIX ""
/* #undef VM_DLSYM_PREFIX */
8 changes: 4 additions & 4 deletions bcm2835/sqPlatformSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#undef sqImageFileWrite
#undef sqAllocateMemory

#undef ioMSecs
#undef ioLowResMSecs
#undef ioMicroMSecs

typedef struct _rpiImageFile {
unsigned char *base;
Expand All @@ -16,6 +19,7 @@ typedef struct _rpiImageFile {
} rpiImageFile;

#define sqImageFile rpiImageFile *
#define squeakFileOffsetType unsigned int

void sqImageFileClose(sqImageFile f);
sqImageFile sqImageFileOpen(char *fileName, char *mode);
Expand All @@ -25,8 +29,4 @@ void sqImageFileSeek(sqImageFile f, int pos);
int sqImageFileWrite(void *ptr, int elementSize, int count, sqImageFile f);
void * sqAllocateMemory(int minHeapSize, int desiredHeapSize);

#undef ioMSecs
#undef ioLowResMSecs
#undef ioMicroMSecs

#define ScreenDepth 32
7 changes: 6 additions & 1 deletion bcm2835/sqRpiDisplay.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "sq.h"
#include "sqRpiDisplay.h"

#include "framebuffer.h"
#include "types.h"
#include "barrier.h"
Expand Down Expand Up @@ -123,8 +125,11 @@ int ioSetFullScreen(int fullScreen) {
return 0;
}

int ioScreenDepth(void) {
return ScreenDepth;
}

int ioHasDisplayDepth(int depth) {
printf("%s depth=%i\n", __PRETTY_FUNCTION__, depth);
if (depth == ScreenDepth) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions bcm2835/sqRpiDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __RPI_DISPLAY
#define __RPI_DISPLAY

void moveCursor(int x, int y);

#endif
155 changes: 152 additions & 3 deletions bcm2835/sqRpiHid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "sq.h"
#include "sqRpiDisplay.h"

#include "keyboard.h"
#include "mouse.h"
#include "timer.h" // watchdog
Expand All @@ -16,6 +18,18 @@ extern int interruptCheckCounter;
extern int interruptKeycode;
extern int interruptPending; /* set to true by RecordKeystroke if interrupt key is pressed */

/*** Variables -- Event Recording ***/
#define MillisecondClockMask 536870911
#define MAX_EVENT_BUFFER 64
static sqInputEvent eventBuffer[MAX_EVENT_BUFFER];
static int eventBufferGet = 0;
static int eventBufferPut = 0;

static char lastKeys[255];
static int lastMouseX = 0;
static int lastMouseY = 0;
static int lastMouseButton = 0;

void RecordKeystroke(unsigned char key, struct KeyboardModifiers modifiers) {
int keystate;

Expand All @@ -33,7 +47,7 @@ void RecordKeystroke(unsigned char key, struct KeyboardModifiers modifiers) {
if (modifiers.LeftGui || modifiers.RightGui) {
keyModifier = 1 << 11;
}
keystate = (keyModifier) | (key & 0xff);
keystate = (keyModifier << 8) | (key & 0xff);

if (keystate == interruptKeycode) {
/* Note: interrupt key is "meta"; it not reported as a keystroke */
Expand Down Expand Up @@ -76,6 +90,143 @@ int ioPeekKeystroke(void) {
return ioGetKeystrokeAndAdvance(false);
}

sqInputEvent *nextEventPut(void) {
sqInputEvent *evt;
evt = eventBuffer + eventBufferPut;
eventBufferPut = (eventBufferPut + 1) % MAX_EVENT_BUFFER;
if (eventBufferGet == eventBufferPut) {
/* buffer overflow; drop the last event */
eventBufferGet = (eventBufferGet + 1) % MAX_EVENT_BUFFER;
}
return evt;
}

void rpiProcessMouseEvents(void) {
int mouseCount = MouseCount();
if (mouseCount == 0) {
return;
}

uint32_t mouse = MouseGetAddress(0);
int position = MouseGetPosition(mouse);
int posX = (position >> 16) & 0xffff;
int posY = position & 0xffff;

int mouseButtons = MouseGetButtons(mouse);
int buttonState = 0;
if (mouseButtons & 0x01) {
buttonState |= RedButtonBit;
}
if (mouseButtons & 0x02) {
buttonState |= BlueButtonBit;
}
if (mouseButtons & 0x04) {
buttonState |= YellowButtonBit;
}

if (posX != lastMouseX || posY != lastMouseY || buttonState != lastMouseButton) {
lastMouseX = posX;
lastMouseY = posY;
lastMouseButton = buttonState;
moveCursor(lastMouseX, lastMouseY);

sqMouseEvent *event = (sqMouseEvent*) nextEventPut();

/* first the basics */
event->type = EventTypeMouse;
event->timeStamp = ioMSecs() & MillisecondClockMask;
event->x = lastMouseX;
event->y = lastMouseY;
/* then the buttons */
event->buttons = lastMouseButton & 0x07;
/* then the modifiers */
event->modifiers = 0; //buttonState >> 3;
/* clean up reserved */
event->reserved1 = 0;
}
}

void rpiRegisterKeyboardEvent(int keyCode, int pressCode, int modifiers) {
sqKeyboardEvent *evt = (sqKeyboardEvent*) nextEventPut();
/* first the basics */
evt->type = EventTypeKeyboard;
evt->timeStamp = ioMSecs() & MillisecondClockMask;
/* now the key code */
/* press code must differentiate */
evt->charCode = keyCode;
evt->pressCode = pressCode;
evt->modifiers = modifiers;

evt->reserved1=evt->reserved2=evt->reserved3= 0;
}

void rpiProcessKeyboardEvents(void) {
int keyboardCount = KeyboardCount();
if (keyboardCount == 0) {
return;
}

uint32_t keyboard = KeyboardGetAddress(0);
int keysDown = KeyboardGetKeyDownCount(keyboard);

struct KeyboardModifiers keyModifiers = KeyboardGetModifiers(keyboard);
int modifiers = 0;
if (keyModifiers.LeftControl || keyModifiers.RightControl) {
modifiers |= CtrlKeyBit;
}
if (keyModifiers.LeftShift || keyModifiers.RightShift) {
modifiers |= ShiftKeyBit;
}
if (keyModifiers.LeftAlt || keyModifiers.RightAlt) {
modifiers |= OptionKeyBit;
}
if (keyModifiers.LeftGui || keyModifiers.RightGui) {
modifiers |= CommandKeyBit;
}

char theseKeys[keysDown];

for (int i=0; i<keysDown; i++) {
int keyCode = KeyboardGetKeyDown(keyboard, i);
unsigned char key = (keyModifiers.LeftShift || keyModifiers.RightShift ? KeysShift[keyCode] : KeysNormal[keyCode]);
theseKeys[i] = key;

if (lastKeys[key] == 0) {
lastKeys[key] = 1;
rpiRegisterKeyboardEvent(key, EventKeyDown, modifiers);
rpiRegisterKeyboardEvent(key, EventKeyChar, modifiers);
}
}

for (int i=0; i<255; i++) {
if (lastKeys[i] != 0) {
bool matched = false;
for (int j=0; j<keysDown; j++) {
if (theseKeys[j] == i) {
matched = true;
}
}

if (matched == false) {
lastKeys[i] = 0;
rpiRegisterKeyboardEvent(i, EventKeyUp, modifiers);
}
}
}
}

int ioGetNextEvent(sqInputEvent *evt) {
ioProcessEvents();
rpiProcessMouseEvents();
rpiProcessKeyboardEvents();

if (eventBufferGet == eventBufferPut) {
return false;
}
*evt = eventBuffer[eventBufferGet];
eventBufferGet = (eventBufferGet+1) % MAX_EVENT_BUFFER;
return true;
}

int ioProcessEvents(void) {
//printf("%s\n", __PRETTY_FUNCTION__);
Expand Down Expand Up @@ -109,8 +260,6 @@ int ioProcessEvents(void) {
for (int mouseIndex=0; mouseIndex<mouseCount; mouseIndex++) {
uint32_t mouse = MouseGetAddress(mouseIndex);
MousePoll(mouse);
//int position = MouseGetPosition(mouse);
//printf("mouse: x=%i, y=%i\n", ((position>>16)&0xffff), (position&0xffff));
}

watchdog_reset();
Expand Down
7 changes: 0 additions & 7 deletions bcm2835/sqRpiMinimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ int ioExit(void) {
while(1) __asm__("nop");
}


/*** Directory ***/

int dir_Delimitor(void) {
return '/';
}

/*** System Attributes ***/
extern char vmPath[];
extern char shortImageName[];
Expand Down
Loading