-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathpanel.c
3350 lines (2980 loc) · 121 KB
/
panel.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* PANEL.C (C) Copyright Roger Bowler, 1999-2012 */
/* (C) Copyright TurboHercules, SAS 2010-2011 */
/* Hercules Control Panel Commands */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/* z/Architecture support - (C) Copyright Jan Jaeger, 1999-2012 */
/* Modified for New Panel Display =NP= */
/*-------------------------------------------------------------------*/
/* This module is the control panel for the ESA/390 emulator. */
/* It provides a command interface into hercules, and it displays */
/* messages that are issued by various hercules components. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* breakpoint command contributed by Dan Horak */
/* devinit command contributed by Jay Maynard */
/* New Panel Display contributed by Dutch Owen */
/* HMC system console commands contributed by Jan Jaeger */
/* Set/reset bad frame indicator command by Jan Jaeger */
/* attach/detach/define commands by Jan Jaeger */
/* Panel refresh rate triva by Reed H. Petty */
/* 64-bit address support by Roger Bowler */
/* Display subchannel command by Nobumichi Kozawa */
/* External GUI logic contributed by "Fish" (David B. Trout) */
/* Socket Devices originally designed by Malcolm Beattie; */
/* actual implementation by "Fish" (David B. Trout). */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#define _PANEL_C_
#define _HENGINE_DLL_
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
#include "history.h"
#include "fillfnam.h"
#include "hconsole.h"
#define PANEL_MAX_ROWS (256)
#define PANEL_MAX_COLS (256)
int redraw_msgs; /* 1=Redraw message area */
int redraw_cmd; /* 1=Redraw command line */
int redraw_status; /* 1=Redraw status line */
/*=NP================================================================*/
/* Global data for new panel display */
/* (Note: all NPD mods are identified by the string =NP= */
/*===================================================================*/
static int NPDup = 0; /* 1 = new panel is up */
static int NPDinit = 0; /* 1 = new panel initialized */
static int NPhelpup = 0; /* 1 = help panel showing */
static int NPhelppaint = 1; /* 1 = help pnl s/b painted */
static int NPhelpdown = 0; /* 1 = help pnl coming down */
static int NPregdisp = 0; /* which regs are displayed: */
/* 0=gpr, 1=cr, 2=ar, 3=fpr */
static int NPcmd = 0; /* 1 = NP in command mode */
static int NPdataentry = 0; /* 1 = NP in data-entry mode */
static int NPdevsel = 0; /* 1 = device being selected */
static char NPpending; /* pending data entry cmd */
static char NPentered[256]; /* Data which was entered */
static char NPprompt1[40]; /* Left bottom screen prompt */
static char NPoldprompt1[40]; /* Left bottom screen prompt */
static char NPprompt2[40]; /* Right bottom screen prompt*/
static char NPoldprompt2[40]; /* Right bottom screen prompt*/
static char NPsel2; /* dev sel part 2 cmd letter */
static char NPdevice; /* Which device is selected */
static int NPasgn; /* Index to dev being init'ed*/
static int NPlastdev; /* Number of devices */
static int NPcpugraph_ncpu; /* Number of CPUs to display */
static char *NPregnum[] = {" 0"," 1"," 2"," 3"," 4"," 5"," 6"," 7",
" 8"," 9","10","11","12","13","14","15"
};
static char *NPregnum64[] = {"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "A", "B", "C", "D", "E", "F"
};
/* Boolean fields; redraw the corresponding data field if false */
static int NPcpunum_valid,
NPcpupct_valid,
NPpsw_valid,
NPpswstate_valid,
NPregs_valid,
NPaddr_valid,
NPdata_valid,
NPmips_valid,
NPsios_valid,
NPdevices_valid,
NPcpugraph_valid;
/* Current CPU states */
//static U16 NPcpunum;
//static int NPcpupct;
static int NPpswmode;
static int NPpswzhost;
static QWORD NPpsw;
static char NPpswstate[16];
static int NPregmode;
static int NPregzhost;
static U64 NPregs64[16];
static U32 NPregs[16];
static U32 NPaddress;
static U32 NPdata;
static U32 NPmips;
static U32 NPsios;
static int NPcpugraph;
static int NPcpugraphpct[ MAX_CPU_ENGS ];
/* Current device states */
#define NP_MAX_DEVICES (PANEL_MAX_ROWS - 3)
static int NPonline[NP_MAX_DEVICES];
static U16 NPdevnum[NP_MAX_DEVICES];
static int NPbusy[NP_MAX_DEVICES];
static U16 NPdevtype[NP_MAX_DEVICES];
static int NPopen[NP_MAX_DEVICES];
static char NPdevnam[NP_MAX_DEVICES][128];
static short NPcurrow, NPcurcol;
static int NPcolorSwitch;
static short NPcolorFore;
static short NPcolorBack;
static int NPdatalen;
static char *NPhelp[] = {
/* 1 2 3 4 5 6 7 8 */
/* Line ....+....0....+....0....+....0....+....0....+....0....+....0....+....0....+....0 */
/* 1 */ "All commands consist of one character keypresses. The various commands are",
/* 2 */ "highlighted onscreen by bright white versus the gray of other lettering.",
/* 3 */ "Disabled buttons, commands and areas are not shown when operating without",
/* 4 */ "defined CPUs (device server only mode).",
/* 5 */ " ",
/* 6 */ "Press the escape key to terminate the control panel and go to command mode.",
/* 7 */ " ",
/* 8 */ "Display Controls: G - General purpose regs C - Control regs",
/* 9 */ " A - Access registers F - Floating Point regs",
/* 10 */ " I - Display main memory at ADDRESS",
/* 11 */ "CPU controls: L - IPL S - Start CPU",
/* 12 */ " E - External interrupt P - Stop CPU",
/* 13 */ " W - Exit Hercules T - Restart interrupt",
/* 14 */ "Storage update: R - Enter ADDRESS to be updated",
/* 15 */ " D - Enter DATA to be updated at ADDRESS",
/* 16 */ " O - place DATA value at ADDRESS",
/* 17 */ " ",
/* 18 */ "Peripherals: N - enter a new name for the device file assignment",
/* 19 */ " U - send an I/O attention interrupt",
/* 20 */ " ",
/* 21 */ "In the display of the first 26 devices, a green device letter means the device",
/* 22 */ "is online, a highlighted device address means the device is busy, and a green",
/* 23 */ "model number means the attached file is open to the device.",
/* 24 */ " ",
/* 25 */ " Press Escape to return to control panel operations",
"" };
///////////////////////////////////////////////////////////////////////
#define MSG_SIZE PANEL_MAX_COLS /* Size of one message */
#define MAX_MSGS 2048 /* Number of slots in buffer */
//#define MAX_MSGS 300 /* (for testing scrolling) */
#define MSG_LINES (cons_rows - 2) /* #lines in message area */
#define SCROLL_LINES (MSG_LINES - numkept) /* #of scrollable lines */
#define CMD_SIZE 256 /* cmdline buffer size */
#define DEV_LINE 3 /* Line to start devices */
#define PSW_LINE 2 /* Line to place PSW */
#define REGS_LINE 5 /* Line to place REGS */
#define ADDR_LINE 15 /* Line to place Addr/data */
#define BUTTONS_LINE 17 /* Line to place Buttons */
#define CPU_GRAPH_LINE 20 /* Line to start CPU Graph */
///////////////////////////////////////////////////////////////////////
static int cons_rows = 0; /* console height in lines */
static int cons_cols = 0; /* console width in chars */
static short cur_cons_row = 0; /* current console row */
static short cur_cons_col = 0; /* current console column */
static const char *cons_term = NULL; /* TERM env value */
static char cmdins = 1; /* 1==insert mode, 0==overlay*/
static char cmdline[CMD_SIZE+1]; /* Command line buffer */
static int cmdlen = 0; /* cmdline data len in bytes */
static int cmdoff = 0; /* cmdline buffer cursor pos */
static int cursor_on_cmdline = 1; /* bool: cursor on cmdline */
static char saved_cmdline[CMD_SIZE+1]; /* Saved command */
static int saved_cmdlen = 0; /* Saved cmdline data len */
static int saved_cmdoff = 0; /* Saved cmdline buffer pos */
static short saved_cons_row = 0; /* Saved console row */
static short saved_cons_col = 0; /* Saved console column */
static int cmdcols = 0; /* visible cmdline width cols*/
static int cmdcol = 0; /* cols cmdline scrolled righ*/
static FILE *confp = NULL; /* Console file pointer */
///////////////////////////////////////////////////////////////////////
#define CMD_PREFIX_HERC "herc =====> "
#define CMD_PREFIX_LEN (strlen(CMD_PREFIX_HERC))
#define CMDLINE_ROW ((short)(cons_rows-1))
#define CMDLINE_COL ((short)(CMD_PREFIX_LEN+1))
///////////////////////////////////////////////////////////////////////
#define ADJ_SCREEN_SIZE() \
do { \
int rows, cols; \
get_dim (&rows, &cols); \
if (rows != cons_rows || cols != cons_cols) { \
cons_rows = rows; \
cons_cols = cols; \
cmdcols = cons_cols - CMDLINE_COL; \
redraw_msgs = redraw_cmd = redraw_status = 1; \
NPDinit = 0; \
clr_screen(); \
} \
} while (0)
#define ADJ_CMDCOL() /* (called after modifying cmdoff) */ \
do { \
if (cmdoff-cmdcol > cmdcols) { /* past right edge of screen */ \
cmdcol = cmdoff-cmdcols; \
} else if (cmdoff < cmdcol) { /* past left edge of screen */ \
cmdcol = cmdoff; \
} \
} while (0)
#define PUTC_CMDLINE() \
do { \
ASSERT(cmdcol <= cmdlen); \
for (i=0; cmdcol+i < cmdlen && i < cmdcols; i++) \
draw_char (cmdline[cmdcol+i]); \
} while (0)
///////////////////////////////////////////////////////////////////////
typedef struct _PANMSG /* Panel message control block structure */
{
struct _PANMSG* next; /* --> next entry in chain */
struct _PANMSG* prev; /* --> prev entry in chain */
int msgnum; /* msgbuf 0-relative entry# */
char msg[MSG_SIZE]; /* text of panel message */
}
PANMSG; /* Panel message control block structure */
static PANMSG* msgbuf = NULL; /* Circular message buffer */
static PANMSG* topmsg = NULL; /* message at top of screen */
static PANMSG* curmsg = NULL; /* newest message */
static int wrapped = 0; /* wrapped-around flag */
static int numkept = 0; /* count of kept messages */
static int npquiet = 0; /* screen updating flag */
///////////////////////////////////////////////////////////////////////
static char *lmsbuf = NULL; /* xxx */
static int lmsndx = 0; /* xxx */
static int lmsnum = -1; /* xxx */
static int lmscnt = -1; /* xxx */
static int lmsmax = LOG_DEFSIZE/2; /* xxx */
static int keybfd = -1; /* Keyboard file descriptor */
static REGS copyregs, copysieregs; /* Copied regs */
/*-------------------------------------------------------------------*/
/* Screen manipulation primitives */
/*-------------------------------------------------------------------*/
static void beep()
{
console_beep( confp );
}
static PANMSG* oldest_msg()
{
return (wrapped) ? curmsg->next : msgbuf;
}
static PANMSG* newest_msg()
{
return curmsg;
}
static int lines_scrolled()
{
/* return # of lines 'up' from current line that we're scrolled. */
if (topmsg->msgnum <= curmsg->msgnum)
return curmsg->msgnum - topmsg->msgnum;
return MAX_MSGS - (topmsg->msgnum - curmsg->msgnum);
}
static int visible_lines()
{
return (lines_scrolled() + 1);
}
static int is_currline_visible()
{
return (visible_lines() <= SCROLL_LINES);
}
static int lines_remaining()
{
return (SCROLL_LINES - visible_lines());
}
static void scroll_up_lines( int numlines )
{
int i;
for (i=0; i < numlines && topmsg != oldest_msg(); i++)
topmsg = topmsg->prev;
}
static void scroll_down_lines( int numlines )
{
int i;
for (i=0; i < numlines && topmsg != newest_msg(); i++)
{
if (topmsg != newest_msg())
topmsg = topmsg->next;
}
}
static void page_up()
{
scroll_up_lines( SCROLL_LINES - 1 );
}
static void page_down()
{
scroll_down_lines( SCROLL_LINES - 1 );
}
static void scroll_to_top_line()
{
topmsg = oldest_msg();
}
static void scroll_to_bottom_line()
{
while (topmsg != newest_msg())
scroll_down_lines( 1 );
}
static void scroll_to_bottom_screen()
{
scroll_to_bottom_line();
page_up();
}
static void do_panel_command( void* cmd )
{
if (!is_currline_visible())
scroll_to_bottom_screen();
if (cmd != (void*) cmdline)
STRLCPY( cmdline, cmd );
panel_command( cmdline );
// Reset global variables
cmdline[0] = 0;
cmdlen = 0;
cmdoff = 0;
ADJ_CMDCOL();
}
static void do_prev_history()
{
if (history_prev() != -1)
{
STRLCPY( cmdline, historyCmdLine );
cmdlen = (int)strlen(cmdline);
cmdoff = cmdlen < cmdcols ? cmdlen : 0;
ADJ_CMDCOL();
}
}
static void do_next_history()
{
if (history_next() != -1)
{
STRLCPY( cmdline, historyCmdLine );
cmdlen = (int)strlen(cmdline);
cmdoff = cmdlen < cmdcols ? cmdlen : 0;
ADJ_CMDCOL();
}
}
static void clr_screen ()
{
clear_screen (confp);
}
static void get_dim (int *y, int *x)
{
get_console_dim( confp, y, x);
if (*y > PANEL_MAX_ROWS)
*y = PANEL_MAX_ROWS;
if (*x > PANEL_MAX_COLS)
*x = PANEL_MAX_COLS;
#if defined(WIN32) && !defined( _MSVC_ )
/* If running from a cygwin command prompt we do
* better with one less row.
*/
if (!cons_term || !*cons_term || strcmp(cons_term, "xterm"))
(*y)--;
#endif // defined(WIN32) && !defined( _MSVC_ )
}
static void set_color (short fg, short bg)
{
set_screen_color (confp, fg, bg);
}
static void set_pos (short y, short x)
{
cur_cons_row = y;
cur_cons_col = x;
y = y < 1 ? 1 : y > cons_rows ? cons_rows : y;
x = x < 1 ? 1 : x > cons_cols ? cons_cols : x;
set_screen_pos (confp, y, x);
}
static int is_cursor_on_cmdline()
{
#if defined(OPTION_EXTCURS)
get_cursor_pos( keybfd, confp, &cur_cons_row, &cur_cons_col );
cursor_on_cmdline =
(1
&& cur_cons_row == CMDLINE_ROW
&& cur_cons_col >= CMDLINE_COL
&& cur_cons_col <= CMDLINE_COL + cmdcols
);
#else // !defined(OPTION_EXTCURS)
cursor_on_cmdline = 1;
#endif // defined(OPTION_EXTCURS)
return cursor_on_cmdline;
}
static void cursor_cmdline_home()
{
cmdoff = 0;
ADJ_CMDCOL();
set_pos( CMDLINE_ROW, CMDLINE_COL );
}
static void cursor_cmdline_end()
{
cmdoff = cmdlen;
ADJ_CMDCOL();
set_pos( CMDLINE_ROW, CMDLINE_COL + cmdoff - cmdcol );
}
static void save_command_line()
{
memcpy( saved_cmdline, cmdline, sizeof(saved_cmdline) );
saved_cmdlen = cmdlen;
saved_cmdoff = cmdoff;
saved_cons_row = cur_cons_row;
saved_cons_col = cur_cons_col;
}
static void restore_command_line()
{
memcpy( cmdline, saved_cmdline, sizeof(cmdline) );
cmdlen = saved_cmdlen;
cmdoff = saved_cmdoff;
cur_cons_row = saved_cons_row;
cur_cons_col = saved_cons_col;
}
static void draw_text( const char* text )
{
int len;
char *short_text;
if (cur_cons_row < 1 || cur_cons_row > cons_rows
|| cur_cons_col < 1 || cur_cons_col > cons_cols)
return;
len = (int)strlen(text);
if ((cur_cons_col + len - 1) <= cons_cols)
fprintf (confp, "%s", text);
else
{
len = cons_cols - cur_cons_col + 1;
if ((short_text = strdup(text)) == NULL)
return;
short_text[len] = '\0';
fprintf (confp, "%s", short_text);
free (short_text);
}
cur_cons_col += len;
}
static void write_text (char *text, int size)
{
if (cur_cons_row < 1 || cur_cons_row > cons_rows
|| cur_cons_col < 1 || cur_cons_col > cons_cols)
return;
if (cons_cols - cur_cons_col + 1 < size)
size = cons_cols - cur_cons_col + 1;
fwrite (text, size, 1, confp);
cur_cons_col += size;
}
static void draw_char (int c)
{
if (cur_cons_row < 1 || cur_cons_row > cons_rows
|| cur_cons_col < 1 || cur_cons_col > cons_cols)
return;
fputc (c, confp);
cur_cons_col++;
}
static void draw_fw (U32 fw)
{
char buf[9];
MSGBUF (buf, "%8.8X", fw);
draw_text (buf);
}
static void draw_dw (U64 dw)
{
char buf[17];
MSGBUF (buf, "%16.16"PRIX64, dw);
draw_text (buf);
}
static void fill_text (char c, short x)
{
char buf[PANEL_MAX_COLS+1];
int len;
if (x > PANEL_MAX_COLS) x = PANEL_MAX_COLS;
len = x + 1 - cur_cons_col;
if (len <= 0) return;
memset( buf, c, len );
buf[len] = '\0';
draw_text (buf);
}
static void draw_button (short bg, short fg, short hfg, char *left, char *mid, char *right)
{
set_color (fg, bg);
draw_text (left);
set_color (hfg, bg);
draw_text (mid);
set_color (fg, bg);
draw_text (right);
}
void set_console_title ( char *status )
{
char title[256];
if ( sysblk.daemon_mode ) return;
redraw_status = 1;
if ( !sysblk.pantitle && ( !status || strlen(status) == 0 ) ) return;
if ( !sysblk.pantitle )
{
char msgbuf[256];
char sysname[16] = { 0 };
char sysplex[16] = { 0 };
char systype[16] = { 0 };
char lparnam[16] = { 0 };
memset( msgbuf, 0, sizeof(msgbuf) );
STRLCAT( systype, str_systype() );
STRLCAT( sysname, str_sysname() );
STRLCAT( sysplex, str_sysplex() );
STRLCAT( lparnam, str_lparname() );
if ( strlen(lparnam)+strlen(systype)+strlen(sysname)+strlen(sysplex) > 0 )
{
if ( strlen(lparnam) > 0 )
{
STRLCAT( msgbuf, lparnam );
if ( strlen(systype)+strlen(sysname)+strlen(sysplex) > 0 )
STRLCAT( msgbuf, " - " );
}
if ( strlen(systype) > 0 )
{
STRLCAT( msgbuf, systype );
if ( strlen(sysname)+strlen(sysplex) > 0 )
STRLCAT( msgbuf, " * " );
}
if ( strlen(sysname) > 0 )
{
STRLCAT( msgbuf, sysname );
if ( strlen(sysplex) > 0 )
STRLCAT( msgbuf, " * " );
}
if ( strlen(sysplex) > 0 )
{
STRLCAT( msgbuf, sysplex );
}
MSGBUF( title, "%s - System Status: %s", msgbuf, status );
}
else
{
MSGBUF( title, "System Status: %s", status );
}
}
else
{
if ( !status || strlen(status) == 0 )
MSGBUF( title, "%s", sysblk.pantitle );
else
MSGBUF( title, "%s - System Status: %s", sysblk.pantitle, status );
}
#if defined( _MSVC_ )
w32_set_console_title( title );
#else /*!defined(_MSVC_) */
/* For Unix systems we set the window title by sending a special
escape sequence (depends on terminal type) to the console.
See http://www.faqs.org/docs/Linux-mini/Xterm-Title.html */
if (!cons_term || !*cons_term) return;
if (strcmp(cons_term,"xterm")==0
|| strcmp(cons_term,"rxvt")==0
|| strcmp(cons_term,"dtterm")==0
|| strcmp(cons_term,"screen")==0)
{
fprintf( confp, "%c]0;%s%c", '\033', title, '\007' );
}
#endif /*!defined(_MSVC_) */
}
/*=NP================================================================*/
/* Initialize the NP data */
/*===================================================================*/
static void NP_init()
{
NPdataentry = 0;
STRLCPY( NPprompt1, "" );
STRLCPY( NPprompt2, "" );
}
/*=NP================================================================*/
/* This draws the initial screen template */
/*===================================================================*/
static void NP_screen_redraw (REGS *regs)
{
int i, line;
char buf[1024];
/* Force all data to be redrawn */
NPcpunum_valid = NPcpupct_valid = NPpsw_valid =
NPpswstate_valid = NPregs_valid = NPaddr_valid =
NPdata_valid = NPdevices_valid = NPcpugraph_valid =
NPmips_valid = NPsios_valid = 0;
#if defined(_FEATURE_SIE)
if(regs->sie_active)
regs = GUESTREGS;
#endif /*defined(_FEATURE_SIE)*/
/*
* Draw the static parts of the NP screen
*/
set_color (COLOR_LIGHT_GREY, COLOR_BLACK );
clr_screen ();
/* Line 1 - title line */
set_color (COLOR_WHITE, COLOR_BLUE );
set_pos (1, 1);
draw_text (" Hercules");
if (sysblk.hicpu)
{
fill_text (' ', 16);
draw_text ("CPU: %");
fill_text (' ', 30);
draw_text (get_arch_name( NULL ));
}
set_color (COLOR_LIGHT_GREY, COLOR_BLUE);
fill_text (' ', 38);
draw_text ("| ");
set_color (COLOR_WHITE, COLOR_BLUE);
#if defined( OPTION_SHARED_DEVICES )
/* Center "Peripherals" on the right-hand-side */
i = 40 + MSGBUF(buf,
"Peripherals [Shared Port %u]",
sysblk.shrdport);
if ((cons_cols < i) || !sysblk.shrdport)
i = 52, buf[11] = 0; /* Truncate string */
if (cons_cols > i) /* Center string */
fill_text (' ', 40 + ((cons_cols - i) / 2));
draw_text (buf);
fill_text (' ', (short)cons_cols);
#endif
/* Line 2 - peripheral headings */
set_pos (2, 41);
set_color (COLOR_WHITE, COLOR_BLACK);
draw_char ('U');
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
draw_text(" Addr Modl Type Assig");
set_color (COLOR_WHITE, COLOR_BLACK);
draw_char ('n');
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
draw_text("ment");
if (sysblk.hicpu)
{
/* PSW_LINE = PSW */
NPpswmode = (regs->arch_mode == ARCH_900_IDX);
NPpswzhost =
#if defined(_FEATURE_SIE)
!NPpswmode && SIE_MODE(regs) && HOSTREGS->arch_mode == ARCH_900_IDX;
#else
0;
#endif /*defined(_FEATURE_SIE)*/
set_pos (PSW_LINE+1, NPpswmode || NPpswzhost ? 19 : 10);
draw_text ("PSW");
/* Register area */
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
NPregmode = (regs->arch_mode == ARCH_900_IDX && (NPregdisp == 0 || NPregdisp == 1));
NPregzhost =
#if defined(_FEATURE_SIE)
(regs->arch_mode != ARCH_900_IDX
&& SIE_MODE(regs) && HOSTREGS->arch_mode == ARCH_900_IDX
&& (NPregdisp == 0 || NPregdisp == 1));
#else
0;
#endif /*defined(_FEATURE_SIE)*/
if (NPregmode == 1 || NPregzhost)
{
for (i = 0; i < 8; i++)
{
set_pos (REGS_LINE+i, 1);
draw_text (NPregnum64[i*2]);
set_pos (REGS_LINE+i, 20);
draw_text (NPregnum64[i*2+1]);
}
}
else
{
for (i = 0; i < 4; i++)
{
set_pos (i*2+(REGS_LINE+1),9);
draw_text (NPregnum[i*4]);
set_pos (i*2+(REGS_LINE+1),18);
draw_text (NPregnum[i*4+1]);
set_pos (i*2+(REGS_LINE+1),27);
draw_text (NPregnum[i*4+2]);
set_pos (i*2+(REGS_LINE+1),36);
draw_text (NPregnum[i*4+3]);
}
}
/* Register selection */
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
set_pos ((REGS_LINE+8), 6);
draw_text ("GPR");
set_pos ((REGS_LINE+8), 14);
draw_text ("CR");
set_pos ((REGS_LINE+8), 22);
draw_text ("AR");
set_pos ((REGS_LINE+8), 30);
draw_text ("FPR");
/* Address and data */
set_pos (ADDR_LINE, 2);
draw_text ("ADD");
set_color (COLOR_WHITE, COLOR_BLACK);
draw_char ('R');
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
draw_text ("ESS:");
set_pos (ADDR_LINE, 22);
set_color (COLOR_WHITE, COLOR_BLACK);
draw_char ('D');
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
draw_text ("ATA:");
}
else
{
set_pos (8, 12);
set_color (COLOR_LIGHT_RED, COLOR_BLACK);
draw_text ("No CPUs defined");
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
}
/* separator */
set_pos (ADDR_LINE+1, 1);
fill_text ('-', 38);
/* Buttons */
if (sysblk.hicpu)
{
set_pos (BUTTONS_LINE, 16);
draw_button(COLOR_BLUE, COLOR_LIGHT_GREY, COLOR_WHITE, " ST", "O", " " );
set_pos (BUTTONS_LINE, 24);
draw_button(COLOR_BLUE, COLOR_LIGHT_GREY, COLOR_WHITE, " D", "I", "S " );
set_pos (BUTTONS_LINE, 32);
draw_button(COLOR_BLUE, COLOR_LIGHT_GREY, COLOR_WHITE, " RS", "T", " " );
}
if (sysblk.hicpu)
{
set_pos ((BUTTONS_LINE+1), 3);
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
draw_text ("MIPS");
}
if (0
|| sysblk.hicpu
#if defined( OPTION_SHARED_DEVICES )
|| sysblk.shrdport
#endif
)
{
set_pos ((BUTTONS_LINE+1), 10);
draw_text ("IO/s");
}
if (sysblk.hicpu)
{
set_pos ((BUTTONS_LINE+2), 2);
draw_button(COLOR_GREEN, COLOR_LIGHT_GREY, COLOR_WHITE, " ", "S", "TR ");
set_pos ((BUTTONS_LINE+2), 9);
draw_button(COLOR_RED, COLOR_LIGHT_GREY, COLOR_WHITE, " ST", "P", " " );
set_pos ((BUTTONS_LINE+2), 16);
draw_button(COLOR_BLUE, COLOR_LIGHT_GREY, COLOR_WHITE, " ", "E", "XT ");
set_pos ((BUTTONS_LINE+2), 24);
draw_button(COLOR_BLUE, COLOR_LIGHT_GREY, COLOR_WHITE, " IP", "L", " " );
}
set_pos ((BUTTONS_LINE+2), 32);
draw_button(COLOR_RED, COLOR_LIGHT_GREY, COLOR_WHITE, " P", "W", "R " );
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
/* CPU busy graph */
line = CPU_GRAPH_LINE; // this is where the dashes start
NPcpugraph_ncpu = MIN(cons_rows - line - 1, sysblk.hicpu);
set_pos (line++, 1);
fill_text ('-', 38);
if (sysblk.hicpu)
{
NPcpugraph = 1;
NPcpugraph_valid = 0;
for (i = 0; i < NPcpugraph_ncpu; i++)
{
MSGBUF (buf, "%s%02X ", PTYPSTR(i), i);
set_pos (line++, 1);
draw_text (buf);
}
}
else
NPcpugraph = 0;
/* Vertical separators */
for (i = 2; i <= cons_rows; i++)
{
set_pos (i , 39);
draw_char ('|');
}
/* Last line : horizontal separator */
if (cons_rows >= 24)
{
set_pos (cons_rows, 1);
fill_text ('-', 38);
draw_char ('|');
fill_text ('-', cons_cols);
}
/* positions the cursor */
set_pos (cons_rows, cons_cols);
}
static char *format_int(uint64_t ic)
{
static char obfr[32]; /* Enough for displaying 2^64-1 */
char grps[7][4]; /* 7 groups of 3 digits */
int maxg=0;
int i;
STRLCPY( grps[0], "0" );
while(ic>0)
{
int grp;
grp=ic%1000;
ic/=1000;
if(ic==0)
{
MSGBUF(grps[maxg],"%u",grp);
}
else
{
MSGBUF(grps[maxg],"%3.3u",grp);
}
maxg++;
}
if(maxg) maxg--;
obfr[0]=0;
for(i=maxg;i>=0;i--)
{
STRLCAT( obfr, grps[i] );
if(i)
{
STRLCAT( obfr, "," );
}
}
return obfr;
}
/*=NP================================================================*/
/* This refreshes the screen with new data every cycle */
/*===================================================================*/
static void NP_update(REGS *regs)
{
int i, n;
int mode, zhost;
int cpupct_total;
QWORD curr_psw;
U32 addr, aaddr;
DEVBLK *dev;
int online, busy, open;
char *devclass;
char devnam[MAX_PATH];
char buf[1024];
if (NPhelpup == 1)
{
if (NPhelpdown == 1)
{
NP_init();
NP_screen_redraw(regs);
NPhelpup = 0;
NPhelpdown = 0;
NPhelppaint = 1;
}
else
{
if (NPhelppaint)
{
set_color (COLOR_LIGHT_GREY, COLOR_BLACK);
clr_screen ();
for (i = 0; *NPhelp[i]; i++)
{
set_pos (i+1, 1);
draw_text (NPhelp[i]);
}
NPhelppaint = 0;
}
return;
}
}
#if defined(_FEATURE_SIE)
if(SIE_MODE(regs))
regs = HOSTREGS;
#endif /*defined(_FEATURE_SIE)*/
/* percent CPU busy */
if (sysblk.hicpu)
{
cpupct_total = 0;
n = 0;
for ( i = 0; i < sysblk.maxcpu; i++ )
if ( IS_CPU_ONLINE(i) )
if ( sysblk.regs[i]->cpustate == CPUSTATE_STARTED )
{
n++;
cpupct_total += sysblk.regs[i]->cpupct;
}
set_color (COLOR_WHITE, COLOR_BLUE);
set_pos (1, 22);
MSGBUF(buf, "%3d", (n > 0 ? cpupct_total/n : 0));
draw_text (buf);
}
if (sysblk.hicpu)