Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
fake_rom.c
Go to the documentation of this file.
1 /* RC2014 and generic Z80 SBC emulator
2  Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3  Copyright (C)2020 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18 
19 #include "xemu/emutools.h"
20 #include "hardware.h"
21 #include "fake_rom.h"
22 #include "console.h"
23 #include "uart.h"
24 
25 
26 
27 static inline void start_shell ( const char *reason, int code )
28 {
29  if (reason) {
30  if (code != -1)
31  conprintf("ABORT: %s %d\r\n", reason, code);
32  else
33  conprintf("ABORT: %s\r\n", reason);
34  }
35  Z80_PC = 2;
36  Z80_SP = 0xFFFF;
37 }
38 
39 
40 static void api_call ( Uint8 sysnum )
41 {
42  switch (sysnum) {
43  case 0:
44  conputs("System RESET requested via API call.\r\n");
45  Z80_PC = 0;
46  break;
47  case 1:
48  {
49  int r = console_input();
50  if (!r)
51  Z80_PC = 0x30; // still waiting for character, loop back to the api call RST
52  else
53  Z80_A = r;
54  }
55  break;
56  case 2:
58  break;
59  case 7:
60  conputs("\r\n");
61  break;
62  default:
63  start_shell("Unknown/not-yet implemented API call C=", Z80_C);
64  break;
65  }
66 }
67 
68 
69 void xrcrom_rst ( int n )
70 {
72  switch (n) {
73  case 0: // RST 00
74  conputs("RESET, Xemu/RC2014 internal ROM\r\n(C)2020 LGB Gabor Lenart, part of the Xemu project.\r\n");
75  start_shell(NULL, -1);
76  break;
77  case 6: // RST 30
78  api_call(Z80_C);
79  break;
80  case 1: // RST 08
81  case 2: // RST 10
82  case 3: // RST 18
83  case 4: // RST 20
84  case 5: // RST 28
85  case 7: // RST 38
86  start_shell("not implemented rst handler", n * 8);
87  break;
88  default:
89  start_shell("UNKNOWN rst handler", n);
90  break;
91  }
93  DEBUGPRINT("TIMING: %d I/O cycles" NL, io_cycles);
94 }
95 
96 
97 static void shell_execute ( char *cmd )
98 {
99  conprintf("?%s\r\n", cmd);
100 }
101 
102 
103 static char command_buffer[127];
104 static int shell_mode;
105 
106 void xrcrom_begin ( void )
107 {
108  command_buffer[0] = 0;
109  console_output('*');
110  shell_mode = 0;
111 }
112 
113 void xrcrom_run ( void )
114 {
115  int r = console_input();
116  Z80_PC = 4;
117  if (r == 0)
118  return;
119  int command_size = strlen(command_buffer);
120  if ((r == 8 || r == 127) && command_size) {
121  conputs("\010 \010");
122  command_buffer[command_size - 1] = 0;
123  return;
124  }
125  if (command_size < 30 && r >= 32 && r < 127) {
126  command_buffer[command_size] = r;
127  command_buffer[command_size + 1] = 0;
128  console_output(r);
129  return;
130  }
131  if ((r == 13 || r == 10) && command_size) {
132  conputs("\r\n");
133  shell_execute(command_buffer);
134  start_shell(NULL, -1);
135  return;
136  }
137 }
console_input
int console_input(void)
Definition: console.c:157
Z80_A
#define Z80_A
Definition: z80ex.h:75
console_io_traffic
int console_io_traffic
Definition: console.c:66
emutools.h
fake_rom.h
Z80_SP
#define Z80_SP
Definition: z80ex.h:117
xrcrom_rst
void xrcrom_rst(int n)
Definition: fake_rom.c:69
hardware.h
Uint8
uint8_t Uint8
Definition: fat32.c:51
xrcrom_run
void xrcrom_run(void)
Definition: fake_rom.c:113
uart.h
DEBUGPRINT
#define DEBUGPRINT(...)
Definition: emutools_basicdefs.h:171
conprintf
#define conprintf(...)
Definition: console.h:28
cpu_cycles_per_uart_transfer
int cpu_cycles_per_uart_transfer
Definition: uart.c:26
NL
#define NL
Definition: fat32.c:37
compress_sd_image.r
def r
Definition: compress_sd_image.py:76
Z80_C
#define Z80_C
Definition: z80ex.h:80
io_cycles
int io_cycles
Definition: hardware.c:35
Z80_PC
#define Z80_PC
Definition: z80ex.h:121
console.h
xrcrom_begin
void xrcrom_begin(void)
Definition: fake_rom.c:106
conputs
void conputs(const char *s)
Definition: console.c:140
console_output
void console_output(Uint8 data)
Definition: console.c:106