2023-01-07 07:15:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
#include <hardware/timer.h>
|
|
|
|
#include "common/config.h"
|
|
|
|
#include "vga/vgabuf.h"
|
|
|
|
#include "vga/render.h"
|
|
|
|
#include "vga/character_rom.h"
|
|
|
|
#include "vga/vgaout.h"
|
2023-01-17 01:36:00 +00:00
|
|
|
#include "pico_hal.h"
|
2023-01-07 07:15:21 +00:00
|
|
|
|
|
|
|
uint16_t text_fore;
|
|
|
|
uint16_t text_back;
|
|
|
|
uint16_t text_border;
|
|
|
|
|
2023-01-29 15:50:12 +00:00
|
|
|
compat_t machinefont = MACHINE_II;
|
2023-01-17 01:36:00 +00:00
|
|
|
bool userfont = false;
|
|
|
|
|
|
|
|
// Initialize the character generator ROM
|
|
|
|
void switch_font() {
|
2023-01-29 15:50:12 +00:00
|
|
|
switch(current_machine) {
|
2023-01-17 01:36:00 +00:00
|
|
|
default:
|
2023-01-29 15:50:12 +00:00
|
|
|
case MACHINE_II:
|
2023-01-17 01:36:00 +00:00
|
|
|
memcpy(character_rom, default_character_rom, 2048);
|
|
|
|
break;
|
2023-02-01 00:32:47 +00:00
|
|
|
case MACHINE_PRAVETZ:
|
|
|
|
memcpy(character_rom, pravetz_character_rom, 2048);
|
|
|
|
break;
|
2023-01-29 15:50:12 +00:00
|
|
|
case MACHINE_IIE:
|
2023-01-17 01:36:00 +00:00
|
|
|
memcpy(character_rom, appleiie_character_rom, 2048);
|
|
|
|
break;
|
2023-01-29 15:50:12 +00:00
|
|
|
case MACHINE_IIGS:
|
2023-01-17 01:36:00 +00:00
|
|
|
memcpy(character_rom, appleiigs_character_rom, 2048);
|
|
|
|
break;
|
|
|
|
}
|
2023-01-29 15:50:12 +00:00
|
|
|
machinefont = current_machine;
|
2023-01-17 01:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void load_font() {
|
|
|
|
int file = pico_open("font", LFS_O_RDONLY);
|
|
|
|
int br = 0;
|
|
|
|
|
|
|
|
userfont = false;
|
|
|
|
|
|
|
|
if(file < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
br = pico_read(file, character_rom, 2048);
|
|
|
|
if(br == 2048) {
|
|
|
|
userfont = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pico_close(file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-01 00:32:47 +00:00
|
|
|
uint16_t status_timeout = 900;
|
|
|
|
uint8_t status_line[81];
|
|
|
|
|
|
|
|
void update_status_right(const char *str) {
|
|
|
|
uint i, len;
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
len = strlen(str);
|
|
|
|
} else {
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len < 80) {
|
|
|
|
memset(status_line, ' ', 80 - len);
|
|
|
|
} else {
|
|
|
|
len = 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
status_line[(80-len) + i] = str[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
status_timeout = 900;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_status_left(const char *str) {
|
|
|
|
uint i, len;
|
|
|
|
|
|
|
|
if(str != NULL) {
|
|
|
|
len = strlen(str);
|
|
|
|
} else {
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(len < 80) {
|
|
|
|
memset(status_line + len, ' ', 80 - len);
|
|
|
|
} else {
|
|
|
|
len = 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
status_line[i] = str[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
status_timeout = 900;
|
|
|
|
}
|
|
|
|
|
2023-01-07 07:15:21 +00:00
|
|
|
void render_init() {
|
|
|
|
int i;
|
2023-01-17 01:36:00 +00:00
|
|
|
|
|
|
|
load_font();
|
|
|
|
if(!userfont)
|
|
|
|
switch_font();
|
|
|
|
|
|
|
|
if((soft_switches & SOFTSW_MODE_MASK) == 0)
|
|
|
|
soft_switches |= SOFTSW_TEST;
|
|
|
|
terminal_tbcolor = 0xf0;
|
2023-01-08 05:35:06 +00:00
|
|
|
terminal_border = 0x00;
|
2023-01-07 07:15:21 +00:00
|
|
|
|
2023-02-01 00:32:47 +00:00
|
|
|
memcpy(videx_character_rom, appleiie_character_rom, 2048);
|
|
|
|
memset(status_line, 0, sizeof(status_line));
|
|
|
|
|
2023-01-07 07:15:21 +00:00
|
|
|
render_test_init();
|
|
|
|
}
|
|
|
|
|
2023-02-01 00:32:47 +00:00
|
|
|
// Skip 48 lines to center vertically
|
|
|
|
void __time_critical_func(render_border)(uint count) {
|
2023-01-29 15:50:12 +00:00
|
|
|
struct vga_scanline *sl = vga_prepare_scanline();
|
|
|
|
uint sl_pos = 0;
|
|
|
|
|
|
|
|
while(sl_pos < VGA_WIDTH/16) {
|
|
|
|
sl->data[sl_pos] = (text_border|THEN_EXTEND_7) | ((text_border|THEN_EXTEND_7) << 16); // 8 pixels per word
|
|
|
|
sl_pos++;
|
|
|
|
}
|
2023-01-17 01:36:00 +00:00
|
|
|
|
2023-01-29 15:50:12 +00:00
|
|
|
sl->length = sl_pos;
|
2023-02-01 00:32:47 +00:00
|
|
|
sl->repeat_count = count - 1;
|
2023-01-29 15:50:12 +00:00
|
|
|
vga_submit_scanline(sl);
|
|
|
|
}
|
2023-01-07 07:15:21 +00:00
|
|
|
|
2023-01-29 15:50:12 +00:00
|
|
|
uint32_t screentimeout = 0;
|
|
|
|
uint32_t testdone = 0;
|
2023-01-07 07:15:21 +00:00
|
|
|
|
2023-01-29 15:50:12 +00:00
|
|
|
void __noinline __time_critical_func(render_loop)() {
|
|
|
|
while(current_mode == MODE_VGACARD) {
|
|
|
|
config_handler();
|
2023-02-01 00:32:47 +00:00
|
|
|
if((busactive == 0) && (screentimeout > (15 * 60))) {
|
|
|
|
vga_prepare_frame();
|
|
|
|
render_border(480);
|
|
|
|
memset(status_line, 0, sizeof(status_line));
|
|
|
|
status_timeout = 0;
|
|
|
|
vga_dpms_sleep();
|
|
|
|
while(busactive == 0);
|
|
|
|
vga_dpms_wake();
|
2023-01-29 15:50:12 +00:00
|
|
|
} else {
|
|
|
|
if(busactive == 0) {
|
|
|
|
screentimeout++;
|
2023-02-01 00:32:47 +00:00
|
|
|
if(screentimeout == 5) {
|
|
|
|
update_status_right("Going to sleep...");
|
|
|
|
}
|
2023-01-29 15:50:12 +00:00
|
|
|
} else {
|
2023-02-01 00:32:47 +00:00
|
|
|
if(screentimeout >= 5) {
|
|
|
|
// Clear the sleep mode message
|
|
|
|
memset(status_line, 0, sizeof(status_line));
|
|
|
|
status_timeout = 0;
|
|
|
|
}
|
2023-01-29 15:50:12 +00:00
|
|
|
screentimeout = 0;
|
|
|
|
}
|
|
|
|
busactive = 0;
|
|
|
|
|
|
|
|
if(!userfont && (machinefont != current_machine)) {
|
|
|
|
switch_font();
|
2023-01-07 07:15:21 +00:00
|
|
|
}
|
2023-01-29 15:50:12 +00:00
|
|
|
|
|
|
|
update_text_flasher();
|
|
|
|
|
|
|
|
text_fore = lores_palette[TERMINAL_FORE];
|
|
|
|
text_back = lores_palette[TERMINAL_BACK];
|
|
|
|
text_border = lores_palette[TERMINAL_BORDER];
|
|
|
|
|
|
|
|
if(soft_switches & SOFTSW_TEST) {
|
|
|
|
render_testpattern();
|
|
|
|
// Automatically dismiss the test pattern when the Apple II is seen.
|
|
|
|
if(((soft_switches & SOFTSW_MODE_MASK) != 0) && (testdone == 0)) {
|
|
|
|
soft_switches &= ~SOFTSW_TEST;
|
|
|
|
testdone = 1;
|
|
|
|
render_about_init();
|
2023-01-07 07:15:21 +00:00
|
|
|
}
|
2023-01-29 15:50:12 +00:00
|
|
|
#if 0
|
|
|
|
} else if(soft_switches & SOFTSW_VIDEX) {
|
|
|
|
render_videx();
|
|
|
|
} else if(soft_switches & SOFTSW_SHR) {
|
|
|
|
render_shr();
|
|
|
|
#endif
|
|
|
|
} else {
|
2023-02-01 00:32:47 +00:00
|
|
|
vga_prepare_frame();
|
|
|
|
|
|
|
|
render_border(24);
|
|
|
|
if(status_line[0] != 0) {
|
|
|
|
render_status_line();
|
|
|
|
render_border(16);
|
|
|
|
} else {
|
|
|
|
render_border(32);
|
|
|
|
}
|
|
|
|
|
2023-01-29 15:50:12 +00:00
|
|
|
switch(soft_switches & SOFTSW_MODE_MASK) {
|
|
|
|
case 0:
|
|
|
|
if(soft_switches & SOFTSW_DGR) {
|
|
|
|
render_dgr();
|
|
|
|
} else {
|
|
|
|
render_lores();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SOFTSW_MIX_MODE:
|
|
|
|
if((soft_switches & (SOFTSW_80COL | SOFTSW_DGR)) == (SOFTSW_80COL | SOFTSW_DGR)) {
|
|
|
|
render_mixed_dgr();
|
|
|
|
} else {
|
|
|
|
render_mixed_lores();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SOFTSW_HIRES_MODE:
|
|
|
|
if(soft_switches & SOFTSW_DGR) {
|
|
|
|
render_dhgr();
|
|
|
|
} else {
|
|
|
|
render_hires();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SOFTSW_HIRES_MODE|SOFTSW_MIX_MODE:
|
|
|
|
if((soft_switches & (SOFTSW_80COL | SOFTSW_DGR)) == (SOFTSW_80COL | SOFTSW_DGR)) {
|
|
|
|
render_mixed_dhgr();
|
|
|
|
} else {
|
|
|
|
render_mixed_hires();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
render_text();
|
|
|
|
break;
|
2023-01-07 07:15:21 +00:00
|
|
|
}
|
2023-02-01 00:32:47 +00:00
|
|
|
|
|
|
|
render_border(48);
|
2023-01-07 07:15:21 +00:00
|
|
|
}
|
2023-02-01 00:32:47 +00:00
|
|
|
}
|
2023-01-07 07:15:21 +00:00
|
|
|
}
|
|
|
|
}
|