-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathprog_examples.cpp
87 lines (71 loc) · 2.42 KB
/
prog_examples.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -----------------------------------------------------------------------------
// Altair 8800 Simulator
// Copyright (C) 2017 David Hansel
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program 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. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// -----------------------------------------------------------------------------
#include <Arduino.h>
#include "config.h"
#include "prog_basic.h"
#include "mem.h"
#if defined(__AVR_ATmega2560__)
#include "prog_examples_basic_mega.h"
// not enough room in MEGA to store ASM examples (or PS2 assembler anyways)
const char * const asm_programs[] = {};
byte read_asm_example(int n, int i) { return 0; }
#define NUM_ASM_PROGRAMS 0
#else
#include "prog_examples_basic_due.h"
#include "prog_examples_asm.h"
#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 < NUM_BASIC_PROGRAMS || idx >= 0x80 && idx < 0x80+NUM_ASM_PROGRAMS || idx == 0xc0 )
{
prog_idx = idx;
prog_ctr = 0;
NULs = 0;
if( idx == 0xc0 )
{
// 4k BASIC will get into an infinite loop if a full 64k RAM are
// available => purposely reduce the RAM size by 1 byte if necessary
if( mem_is_writable(0x1000, 0xFFFF) ) mem_add_rom(0xFFFF, 1, "RAMLIMIT", MEM_ROM_FLAG_TEMP);
}
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_basic_example(prog_idx, prog_ctr);
else if( prog_idx == 0xC0 )
return prog_basic_read_4k(prog_ctr++, b);
else
*b = read_asm_example(prog_idx-0x80, prog_ctr);
if( *b=='\r' ) NULs = config_serial_playback_example_nuls(dev);
if( *b>0 ) prog_ctr++;
return *b != 0;
}