forked from dhansel/Altair8800
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog_examples.cpp
More file actions
55 lines (44 loc) · 1.2 KB
/
Copy pathprog_examples.cpp
File metadata and controls
55 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Arduino.h>
#include "config.h"
#if defined(__AVR_ATmega2560__)
// not enough room in MEGA to store ASM examples (or PS2 assembler anyways)
#include "prog_examples_basic_mega.h"
const char * const asm_programs[] = {};
#define READ_EX_BYTE(pv,pi,pc) pgm_read_byte(((const char*) pgm_read_word(pv+(pi)))+(pc))
#else
#include "prog_examples_basic_due.h"
#include "prog_examples_asm.h"
#define READ_EX_BYTE(pv,pi,pc) ((byte) pv[pi][pc])
#endif
static byte prog_idx = 0;
static uint16_t prog_ctr = 0;
static byte NULs = 0;
bool prog_examples_read_start(byte idx)
{
if( idx < sizeof(basic_programs)/sizeof(char *) ||
idx >= 0x80 && idx < 0x80+(sizeof(asm_programs)/sizeof(char *)) )
{
prog_idx = idx;
prog_ctr = 0;
NULs = 0;
return true;
}
else
return false;
}
bool prog_examples_read_next(byte dev, byte *b)
{
if( NULs>0 )
{
NULs--;
*b = 0;
return true;
}
else if( prog_idx < 0x80 )
*b = READ_EX_BYTE(basic_programs, prog_idx, prog_ctr);
else
*b = READ_EX_BYTE(asm_programs, prog_idx-0x80, prog_ctr);
if( *b=='\r' ) NULs = config_serial_playback_example_nuls(dev);
if( *b>0 ) prog_ctr++;
return *b != 0;
}