git.haldean.org x6502 / 1bf1257
Add color output support. Will Haldean Brown 7 years ago
4 changed file(s) with 83 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
8686 this flag, as some implementations of ncurses
8787 will clear the display when the emulator exits.
8888
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
89113 I/O devices:
90114
91 The character output device is mapped to FF00. Any
115 The character output device is mapped to 0xFF00. Any
92116 character written to FF00 is immediately echoed to the
93117 terminal.
94118
95 The character input device is mapped to FF01. When a
119 The character input device is mapped to 0xFF01. When a
96120 character is available on standard in, an interrupt is
97121 raised and FF01 is set to the character that was
98122 received. Note that one character is delivered per
1010 #define VTERM_COLS 40
1111
1212 uint8_t io_modeflags = 0x00;
13 uint8_t io_supports_paint;
1314
1415 WINDOW *window = NULL;
1516
2324 noecho();
2425 nodelay(stdscr, TRUE);
2526 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 }
2635 }
2736
2837 void finish_io() {
5867 }
5968 }
6069
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
6178 void update_vterm(cpu *m, uint16_t dirty) {
6279 uint16_t offset = dirty - IO_VTERM_START;
6380 if (offset >= 1000) {
89106 }
90107 } else if (addr == IO_MODEFLAGS) {
91108 update_modeflags(io_modeflags, m->mem[IO_MODEFLAGS]);
109 } else if (addr == IO_PAINT) {
110 update_paint(m->mem[addr]);
92111 } else if (IO_VTERM_START <= addr && addr < IO_VTERM_END) {
93112 update_vterm(m, addr);
94113 }
44 #define IO_PUTCHAR 0xFF00
55 #define IO_GETCHAR 0xFF01
66 #define IO_MODEFLAGS 0xFF02
7 #define IO_PAINT 0xFEE8
78
89 #define IO_VTERM_START 0xFB00
910 #define IO_VTERM_END 0xFF00
1112 #define IO_MODEFLAG_VTERM 0x01
1213 #define IO_MODEFLAG_WAIT_HALT 0x02
1314
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
1429 void init_io();
1530 void finish_io();
1631 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