-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_bin.c
109 lines (94 loc) · 2.52 KB
/
gen_bin.c
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* This file helps with hand assembling programs or generating rom images.
* I wrote it for use with the first few videos in ben eater's 6502 computer
* series, with a design similar to his python script for the same purpose.
*
* It fills memory with nop instructions, Copies the hand assembled code in prog
* into the beginning of the EEPROM image and points the reset vector to the
* start of ROM.
*
* Use:
* - gcc gen_bin.c
* - ./a.out > prog.bin
* - hexdump -C prog.bin
* - minipro -p AT28C256 -w prog.bin
*/
#include <stdio.h>
// NOP
char prog[] =
{
0xea, // nop
};
// prog1 - test write to VIA outputs
//char prog[] =
//{
// 0xa9, 0x42, // lda 0x42
// 0x8d, 0x00, 0x60 // sta 0x6000
//};
// prog2 - alternate blink odd/even VIA outputs.
//char prog[] =
//{
// 0xa9, 0xff, // lda 0xff
// 0x8d, 0x02, 0x60, // sta 0x6002
// 0xa9, 0xaa, // lda 0xaa
// 0x8d, 0x00, 0x60 // sta 0x6000
// 0xa9, 0x55, // lda 0x55
// 0x8d, 0x00, 0x60 // sta 0x6000
// 0x4c, 0x05, 0x80, // jmp 0x8005
//};
// prog3 - chasing lights VIA outputs.
//char prog[] =
//{
// 0xa9, 0xff, // lda 0xff
// 0x8d, 0x02, 0x60, // sta 0x6002
// 0xa9, 0x01, // lda 0x01
// 0x8d, 0x00, 0x60, // sta 0x6000
// 0x2a, // rol
// 0x4c, 0x07, 0x80, // jmp 0x8005
//};
// prog4 - bouncing lights VIA outputs.
//char prog[] =
//{
// 0xa9, 0xff, // lda 0xff
// 0x8d, 0x02, 0x60, // sta 0x6002
// 0x18, // clc
// 0xa9, 0x01, // lda 0x01
// 0x8d, 0x00, 0x60, // sta 0x6000
// 0x2a, // rol
// 0x90, -6, // bcc -6
// 0x18, // clc
// 0xa9, 0x80, // lda 0x80
// 0x8d, 0x00, 0x60, // sta 0x6000
// 0x6a, // ror
// 0x90, -6, // bcc -6
// 0x4c, 0x05, 0x80, // jmp 0x8005
//};
int main(int argc, char** argv)
{
static const unsigned int ROM_SIZE = 0x8000;
static const unsigned int ROM_START = 0x8000;
static const unsigned int RESET_VECTOR_ADDR = 0xFFFC;
static const unsigned int START_ADDR = ROM_START;
char mem[ROM_SIZE];
int i;
// Initially fill memory with NOOP
for(i = 0; i<ROM_SIZE; i++)
{
mem[i]=0xea;
}
// Set reset vector LSB
mem[RESET_VECTOR_ADDR-ROM_START] = START_ADDR & 0x00FF;
// Set reset vector MSB
mem[(RESET_VECTOR_ADDR-ROM_START)+1]=(START_ADDR >> 8) & 0x00FF;
// Copy program into start of ROM
for( i=0; i<sizeof(prog); ++i )
{
mem[i]=prog[i];
}
// Dump ROM image raw to stdout
for(i = 0; i<ROM_SIZE; i++)
{
printf("%c", mem[i]);
}
return 0;
}