Add color output support.
Will Haldean Brown
8 years ago
86 | 86 |
this flag, as some implementations of ncurses
|
87 | 87 |
will clear the display when the emulator exits.
|
88 | 88 |
|
|
89 |
When outputting characters, you can control the
|
|
90 |
``paint'' with which the characters are drawn. You can
|
|
91 |
do so by modifying the PAINT flag at location 0xFEE8.
|
|
92 |
Paints are an OR-ing of a color (bottom 4 bits) and a
|
|
93 |
style (top 4 bits). Supported colors are:
|
|
94 |
|
|
95 |
PAINT_BLACK 0x00
|
|
96 |
PAINT_RED 0x01
|
|
97 |
PAINT_GREEN 0x02
|
|
98 |
PAINT_YELLOW 0x03
|
|
99 |
PAINT_BLUE 0x04
|
|
100 |
PAINT_MAGENTA 0x05
|
|
101 |
PAINT_CYAN 0x06
|
|
102 |
PAINT_WHITE 0x07
|
|
103 |
|
|
104 |
Supported styles are:
|
|
105 |
|
|
106 |
PAINT_DIM 0x20
|
|
107 |
PAINT_UNDERLINE 0x40
|
|
108 |
PAINT_BOLD 0x80
|
|
109 |
|
|
110 |
Thus, as an example, an underlined, bold green character
|
|
111 |
would have paint 0xC2.
|
|
112 |
|
89 | 113 |
I/O devices:
|
90 | 114 |
|
91 | |
The character output device is mapped to FF00. Any
|
|
115 |
The character output device is mapped to 0xFF00. Any
|
92 | 116 |
character written to FF00 is immediately echoed to the
|
93 | 117 |
terminal.
|
94 | 118 |
|
95 | |
The character input device is mapped to FF01. When a
|
|
119 |
The character input device is mapped to 0xFF01. When a
|
96 | 120 |
character is available on standard in, an interrupt is
|
97 | 121 |
raised and FF01 is set to the character that was
|
98 | 122 |
received. Note that one character is delivered per
|
10 | 10 |
#define VTERM_COLS 40
|
11 | 11 |
|
12 | 12 |
uint8_t io_modeflags = 0x00;
|
|
13 |
uint8_t io_supports_paint;
|
13 | 14 |
|
14 | 15 |
WINDOW *window = NULL;
|
15 | 16 |
|
|
23 | 24 |
noecho();
|
24 | 25 |
nodelay(stdscr, TRUE);
|
25 | 26 |
keypad(stdscr, TRUE);
|
|
27 |
|
|
28 |
io_supports_paint = (has_colors() != FALSE);
|
|
29 |
if (io_supports_paint) {
|
|
30 |
start_color();
|
|
31 |
for (int i = 0; i < 8; i++) {
|
|
32 |
init_pair(i, i, COLOR_BLACK);
|
|
33 |
}
|
|
34 |
}
|
26 | 35 |
}
|
27 | 36 |
|
28 | 37 |
void finish_io() {
|
|
58 | 67 |
}
|
59 | 68 |
}
|
60 | 69 |
|
|
70 |
void update_paint(uint8_t paint) {
|
|
71 |
wattrset(window,
|
|
72 |
COLOR_PAIR(paint & 0x0F) |
|
|
73 |
(paint & IO_PAINT_DIM ? A_DIM : 0) |
|
|
74 |
(paint & IO_PAINT_UNDERLINE ? A_UNDERLINE : 0) |
|
|
75 |
(paint & IO_PAINT_BOLD ? A_BOLD : 0));
|
|
76 |
}
|
|
77 |
|
61 | 78 |
void update_vterm(cpu *m, uint16_t dirty) {
|
62 | 79 |
uint16_t offset = dirty - IO_VTERM_START;
|
63 | 80 |
if (offset >= 1000) {
|
|
89 | 106 |
}
|
90 | 107 |
} else if (addr == IO_MODEFLAGS) {
|
91 | 108 |
update_modeflags(io_modeflags, m->mem[IO_MODEFLAGS]);
|
|
109 |
} else if (addr == IO_PAINT) {
|
|
110 |
update_paint(m->mem[addr]);
|
92 | 111 |
} else if (IO_VTERM_START <= addr && addr < IO_VTERM_END) {
|
93 | 112 |
update_vterm(m, addr);
|
94 | 113 |
}
|
4 | 4 |
#define IO_PUTCHAR 0xFF00
|
5 | 5 |
#define IO_GETCHAR 0xFF01
|
6 | 6 |
#define IO_MODEFLAGS 0xFF02
|
|
7 |
#define IO_PAINT 0xFEE8
|
7 | 8 |
|
8 | 9 |
#define IO_VTERM_START 0xFB00
|
9 | 10 |
#define IO_VTERM_END 0xFF00
|
|
11 | 12 |
#define IO_MODEFLAG_VTERM 0x01
|
12 | 13 |
#define IO_MODEFLAG_WAIT_HALT 0x02
|
13 | 14 |
|
|
15 |
#define IO_PAINT_BLACK 0x00
|
|
16 |
#define IO_PAINT_RED 0x01
|
|
17 |
#define IO_PAINT_GREEN 0x02
|
|
18 |
#define IO_PAINT_YELLOW 0x03
|
|
19 |
#define IO_PAINT_BLUE 0x04
|
|
20 |
#define IO_PAINT_MAGENTA 0x05
|
|
21 |
#define IO_PAINT_CYAN 0x06
|
|
22 |
#define IO_PAINT_WHITE 0x07
|
|
23 |
|
|
24 |
// bitwise-OR these with one of the colors to modify them
|
|
25 |
#define IO_PAINT_DIM 0x20
|
|
26 |
#define IO_PAINT_UNDERLINE 0x40
|
|
27 |
#define IO_PAINT_BOLD 0x80
|
|
28 |
|
14 | 29 |
void init_io();
|
15 | 30 |
void finish_io();
|
16 | 31 |
void handle_io(cpu *m);
|
|
0 |
lda #$01
|
|
1 |
sta $FF02
|
|
2 |
|
|
3 |
lda #$00
|
|
4 |
sta $FEE8
|
|
5 |
|
|
6 |
lda #$41
|
|
7 |
ldx #$00
|
|
8 |
ldy #$08
|
|
9 |
|
|
10 |
loop
|
|
11 |
sta $FB00,X
|
|
12 |
inx
|
|
13 |
sta $FB00,X
|
|
14 |
inx
|
|
15 |
sta $FB00,X
|
|
16 |
inx
|
|
17 |
|
|
18 |
inc $FEE8
|
|
19 |
cpy $FEE8
|
|
20 |
bne loop
|
|
21 |
|
|
22 |
wai
|