Skip to content

Commit

Permalink
V1.1.0 - May 23, 2020:
Browse files Browse the repository at this point in the history
- Created the Ex-Machina Autoloader. It simulates the needed keypresses
to load a demo program into Ben's computer's RAM. See README.TXT for
more info.
  • Loading branch information
Milton Maldonado Jr committed May 23, 2020
1 parent 928fb4c commit b664c3c
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 16 deletions.
17 changes: 15 additions & 2 deletions README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// SEE LICENSE AT https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
////////////////////////////////////////////////////////////////////////////////

Version 1.0.8
Version 1.1.0
May 23, 2020

INTRO
Expand Down Expand Up @@ -101,7 +101,11 @@ for that.
two ways: a "Deus ex machina" way (that "magically" transfers data between the
RAM and disk files, sort of a cheating), or a more beautiful way where a
simulated hardware could transfer RAM data from/to a simulated EEPROM (and then
its contents could be loaded/saved from disk). Maybe I will do it someday...
its contents could be loaded/saved from disk) - (EDIT) I created the
'exmachina.c' module that sort of implements this idea, but not dynamically from
disk. The program to be loaded to the RAM is hard-coded, and to change it will
require a project rebuild. This code simulates the user actions of manually
inputting the test program, and can be improved at will.

- The James Bates variant (https://www.youtube.com/watch?v=gqYFT6iecHw) and
others. I didn't check whether the simulation engine can run the Bates' version
Expand Down Expand Up @@ -191,3 +195,12 @@ hinted within brackets.
(they are older tests not related to Ben's computer simulation). You can
play with them by editing 'main.c'.

V1.1.0 - May 23, 2020:

- Created the Ex-Machina Autoloader. It simulates the needed keypresses to
load a demo program into Ben's computer's RAM. It's simply a thread that
injects fake keypresses into the engine, and is implemented into the file
'exmachina.c'. There the demo program can be changed to whatever program
the user wants, and it will work as long as it is compatible with the
Ben's computer architecture!

38 changes: 36 additions & 2 deletions src/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,12 @@ void restart_handlers(board_ctx_t *bctx)

FD_ZERO (&bctx->readfds);
FD_SET(0,&bctx->readfds);
FD_SET(bctx->pipekeys[0],&bctx->readfds);

tv.tv_sec = 0;
tv.tv_usec = 100; // 100 us

select (1,&bctx->readfds,NULL,NULL,&tv);
select (1+bctx->pipekeys[0],&bctx->readfds,NULL,NULL,&tv);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -363,6 +364,12 @@ int received_key(board_ctx_t *bctx)
return (FD_ISSET(0,&bctx->readfds));
}

////////////////////////////////////////////////////////////////////////////////
int received_key_simu(board_ctx_t *bctx)
{
return (FD_ISSET(bctx->pipekeys[0],&bctx->readfds));
}

////////////////////////////////////////////////////////////////////////////////
int read_key(board_ctx_t *bctx)
{
Expand All @@ -372,6 +379,20 @@ int read_key(board_ctx_t *bctx)
return key;
}

////////////////////////////////////////////////////////////////////////////////
int read_key_simu(board_ctx_t *bctx)
{
int key;
read(bctx->pipekeys[0], &key, sizeof(int));
return key;
}

////////////////////////////////////////////////////////////////////////////////
void board_write_key(board_ctx_t *bctx, int key)
{
write(bctx->pipekeys[1], &key, sizeof(int));
}

////////////////////////////////////////////////////////////////////////////////
void sigterm_handler(int sig){

Expand Down Expand Up @@ -1004,6 +1025,8 @@ int board_run(board_ctx_t *ctx, event_context_t *ec, board_object *board){

ctx->board = board;

pipe(ctx->pipekeys);

if (!board) return -2;

if (board->type != BOARD)
Expand Down Expand Up @@ -1090,9 +1113,20 @@ int board_run(board_ctx_t *ctx, event_context_t *ec, board_object *board){

restart_handlers(ctx);

bool_t has_key = 0;
int key;

if (received_key(ctx)){
key = read_key(ctx);
has_key = 1;
}

if (received_key_simu(ctx)){
key = read_key_simu(ctx);
has_key = 1;
}

int key = read_key(ctx);
if (has_key){

switch(key){

Expand Down
3 changes: 3 additions & 0 deletions src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef struct {
pthread_t refthread;
bool_t refresh_run;
int piperefresh[2];
int pipekeys[2];

bool_t focustable_done;
int num_focuseable_boards;
Expand Down Expand Up @@ -117,4 +118,6 @@ void board_set_refresh(board_ctx_t *ctx);

board_ctx_t *board_init(void);

void board_write_key(board_ctx_t *bctx, int key);

#endif /* BOARD_H_ */
6 changes: 6 additions & 0 deletions src/computer/computer.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ void computer_sim(){

////////////////

#include "exmachina.h"

pthread_t sim_thread;
pthread_create(&sim_thread, NULL, exmachina_thread, ctx);
pthread_detach(sim_thread);

board_run(ctx, ec, mainboard);

logger_end(ec);
Expand Down
95 changes: 95 additions & 0 deletions src/computer/exmachina.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* exmachina.c
*
* Created on: 23 de mai de 2020
* Author: milton
*/

#include <unistd.h>
#include <stdint.h>

#include "board.h"

const uint8_t demoprog[] = {

0x00, /*OUT*/ 0xE0,
0x01, /*ADD 15*/ 0x2F,
0x02, /*JC 4*/ 0x74,
0x03, /*JMP 0*/ 0x60,
0x04, /*SUB 15*/ 0x3F,
0x05, /*OUT*/ 0xE0,
0x06, /*JZ 0*/ 0x80,
0x07, /*JMP 4*/ 0x64,
0x0F, /*1*/ 0x01,
};

const int LINES_PROG = sizeof(demoprog)/2;

////////////////////////////////////////////////////////////////////////////////
void write_key(board_ctx_t *bctx, int key){

board_write_key(bctx, key);
usleep(100000);
}

////////////////////////////////////////////////////////////////////////////////
void *exmachina_thread(void *args){

board_ctx_t *bctx = args;
usleep(1000000);

uint8_t addr = 0;
uint8_t data = 0;

int i;

for (i = 0; i < LINES_PROG; i++){

uint8_t newaddr = demoprog[2*i];
uint8_t newdata = demoprog[2*i+1];

uint8_t deltaaddr = addr ^ newaddr;
if (deltaaddr & 0x01){
write_key(bctx, 'l');
}

if (deltaaddr & 0x02){
write_key(bctx, 'k');
}
if (deltaaddr & 0x04){
write_key(bctx, 'j');
}
if (deltaaddr & 0x08){
write_key(bctx, 'h');
}

uint8_t deltadata = data ^ newdata;

int j;
for (j = 0; j < 8; j++){

if (deltadata & (1 << j)){

int key = '0' + j;
write_key(bctx, key);
}
}

addr = newaddr;
data = newdata;

write_key(bctx, 'w');
write_key(bctx, 'w');
}

write_key(bctx, 'p');
write_key(bctx, KEY_F(2));

write_key(bctx, 'r');
write_key(bctx, 'r');

for (i = 0; i < 9; i++)
write_key(bctx, KEY_F(12));

return NULL;
}
13 changes: 13 additions & 0 deletions src/computer/exmachina.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* exmachina.h
*
* Created on: 23 de mai de 2020
* Author: milton
*/

#ifndef SRC_COMPUTER_EXMACHINA_H_
#define SRC_COMPUTER_EXMACHINA_H_

void *exmachina_thread(void *args);

#endif /* SRC_COMPUTER_EXMACHINA_H_ */
4 changes: 2 additions & 2 deletions src/update.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void part_destroy(void **part);
#define DESTROY(X) part_destroy((void**)&X)

#define SW_VERSION 1
#define SW_REVISION 0
#define SW_MINOR 8
#define SW_REVISION 1
#define SW_MINOR 0

#endif /* UPDATE_H_ */
20 changes: 10 additions & 10 deletions testprogram.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

0 OUT E0
1 ADD 15 2F
2 JC 4 74
3 JMP 0 60
4 SUB 15 3F
5 OUT E0
6 JZ 0 80
7 JMP 4 64
15 1 01
ADDR MNEMONIC CODE
00 OUT E0
01 ADD 15 2F
02 JC 4 74
03 JMP 0 60
04 SUB 15 3F
05 OUT E0
06 JZ 0 80
07 JMP 4 64
0F 1 01

0 comments on commit b664c3c

Please sign in to comment.