OpenCores
URL https://opencores.org/ocsvn/i650/i650/trunk

Subversion Repositories i650

[/] [i650/] [trunk/] [rtl/] [operator_ctl.v] - Blame information for rev 27

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 eightycc
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// IBM 650 Reconstruction in Verilog (i650)
4
// 
5
// This file is part of the IBM 650 Reconstruction in Verilog (i650) project
6
// http:////www.opencores.org/project,i650
7
//
8
// Description: Operator console and external control interface.
9
// 
10
// Additional Comments: See US 2959351, Fig. 75, 76, 76 and 77. Also implements
11
//  a simple command-based control interface.
12
//
13
// Copyright (c) 2015 Robert Abeles
14
//
15
// This source file is free software; you can redistribute it
16
// and/or modify it under the terms of the GNU Lesser General
17
// Public License as published by the Free Software Foundation;
18
// either version 2.1 of the License, or (at your option) any
19
// later version.
20
//
21
// This source is distributed in the hope that it will be
22
// useful, but WITHOUT ANY WARRANTY; without even the implied
23
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
24
// PURPOSE.  See the GNU Lesser General Public License for more
25
// details.
26
//
27
// You should have received a copy of the GNU Lesser General
28
// Public License along with this source; if not, download it
29
// from http://www.opencores.org/lgpl.shtml
30
//////////////////////////////////////////////////////////////////////////////////
31
`include "defines.v"
32
 
33
module operator_ctl (
34 11 eightycc
      input rst, clk,
35 7 eightycc
      input ap, dp,
36 16 eightycc
      input dx, d0, d1, d2, d3, d4, d5, d6, d9, d10,
37
      input wu, wl, hp,
38 7 eightycc
      input [0:3] early_idx, ontime_idx,
39
 
40 15 eightycc
      input [0:6] cmd_digit_in, io_buffer_in, gs_in, acc_ontime, dist_ontime,
41
                  prog_ontime,
42 7 eightycc
      input [0:5] command,
43 22 eightycc
      input restart_reset,
44 7 eightycc
 
45 11 eightycc
      output reg[0:6] data_out, addr_out, console_out,
46 15 eightycc
      output [0:6] display_digit,
47 21 eightycc
      output reg console_to_addr, acc_ri_console,
48 7 eightycc
      output reg[0:14] gs_ram_addr,
49 10 eightycc
      output reg read_gs, write_gs,
50 7 eightycc
      output reg pgm_start, pgm_stop, err_reset, err_sense_reset,
51
      output run_control, half_or_pgm_stop, ri_storage, ro_storage,
52 23 eightycc
             storage_control, err_restart_sw, ovflw_stop_sw, ovflw_sense_sw,
53 27 eightycc
             pgm_stop_sw,
54 16 eightycc
      output reg man_pgm_reset, man_acc_reset, hard_reset,
55
      output set_8000, reset_8000,
56 7 eightycc
 
57
      output reg[0:6] cmd_digit_out,
58 22 eightycc
      output reg busy, digit_ready, restart_reset_busy,
59 7 eightycc
      output reg punch_card, read_card, card_digit_ready
60
   );
61
 
62
   //-----------------------------------------------------------------------------
63 12 eightycc
   // Operator console switch settings and their control signals.
64 7 eightycc
   //-----------------------------------------------------------------------------
65
   reg pgm_sw_stop, pgm_sw_run,
66
       half_cycle_sw_run, half_cycle_sw_half,
67
       ctl_sw_addr_stop, ctl_sw_run, ctl_sw_manual,
68
       disp_sw_lacc, disp_sw_uacc, disp_sw_dist, disp_sw_pgm,
69
       disp_sw_ri, disp_sw_ro,
70
       ovflw_sw_stop, ovflw_sw_sense, err_sw_stop, err_sw_sense;
71
   reg [0:6] storage_entry_sw [0:15];
72
   reg [0:6] addr_sel_sw [0:3];
73
   assign run_control = disp_sw_lacc | disp_sw_uacc | disp_sw_dist | disp_sw_pgm;
74
   assign half_or_pgm_stop = half_cycle_sw_half | pgm_stop;
75
   assign ri_storage = disp_sw_ri;
76
   assign ro_storage = disp_sw_ro;
77
   assign storage_control = run_control | disp_sw_ro;
78 15 eightycc
   assign display_digit = (disp_sw_lacc | disp_sw_uacc)? acc_ontime
79
                        : (disp_sw_dist | disp_sw_ri | disp_sw_ro)? dist_ontime
80
                        : disp_sw_pgm? prog_ontime
81
                        : `biq_blank;
82 16 eightycc
   assign set_8000 = man_pgm_reset & (ctl_sw_addr_stop | ctl_sw_run);
83
   assign reset_8000 = man_pgm_reset & ctl_sw_manual;
84 23 eightycc
   assign err_restart_sw = err_sw_sense;
85
   assign ovflw_stop_sw  = ovflw_sw_stop;
86
   assign ovflw_sense_sw = ovflw_sw_sense;
87 27 eightycc
   assign pgm_stop_sw = pgm_sw_stop;
88 7 eightycc
 
89 12 eightycc
   //-----------------------------------------------------------------------------
90
   // Calculate the RAM address of the general storage word at address gs_addr_.
91
   //-----------------------------------------------------------------------------
92 7 eightycc
   reg [0:6] gs_addr_th, gs_addr_h, gs_addr_t, gs_addr_u;
93 9 eightycc
   wire [0:14] gs_band_addr;
94 10 eightycc
   wire [0:9] gs_word_offset;
95 9 eightycc
   ram_band_addr rba(gs_addr_th, gs_addr_h, gs_addr_t, gs_band_addr);
96 7 eightycc
   ram_word_offset rwo(gs_addr_t, gs_addr_u, gs_word_offset);
97
   wire [0:14] gs_word_addr = gs_band_addr + gs_word_offset;
98
 
99 12 eightycc
   //-----------------------------------------------------------------------------
100
   // Operator console state machine
101
   //-----------------------------------------------------------------------------
102
   reg do_power_on_reset, do_reset_console, do_err_reset, do_err_sense_reset,
103
       do_pgm_reset, do_acc_reset, do_hard_reset, do_clear_drum;
104
   reg [0:5] state;
105
 
106 7 eightycc
   `define state_idle                  6'd0
107
 
108
   `define state_reset_console_1       6'd1
109
   `define state_reset_console_2       6'd2
110
   `define state_pgm_reset_1           6'd3
111
   `define state_pgm_reset_2           6'd4
112
   `define state_acc_reset_1           6'd5
113
   `define state_acc_reset_2           6'd6
114
   `define state_err_reset_1           6'd7
115
   `define state_err_reset_2           6'd8
116
   `define state_err_sense_reset_1     6'd9
117
   `define state_err_sense_reset_2     6'd10
118 11 eightycc
   `define state_hard_reset_1          6'd11
119 7 eightycc
 
120 11 eightycc
   `define state_storage_entry_sw_1    6'd12
121
   `define state_storage_entry_sw_2    6'd13
122
   `define state_addr_sel_sw_1         6'd14
123
   `define state_addr_sel_sw_2         6'd15
124 7 eightycc
 
125 11 eightycc
   `define state_xfer_key_1            6'd16
126
   `define state_xfer_key_2            6'd17
127
   `define state_pgm_start_key_1       6'd18
128
   `define state_pgm_start_key_2       6'd19
129
   `define state_pgm_stop_key_1        6'd20
130
   `define state_pgm_stop_key_2        6'd21
131 7 eightycc
 
132 11 eightycc
   `define state_read_gs_1             6'd30
133
   `define state_read_gs_2             6'd31
134
   `define state_read_gs_3             6'd32
135
   `define state_read_gs_4             6'd33
136
   `define state_read_gs_5             6'd34
137 12 eightycc
   `define state_read_gs_6             6'd35
138 13 eightycc
   `define state_write_gs_1            6'd36
139
   `define state_write_gs_2            6'd37
140
   `define state_write_gs_3            6'd38
141
   `define state_write_gs_4            6'd39
142
   `define state_write_gs_5            6'd40
143 16 eightycc
   `define state_read_acc_1            6'd41
144
   `define state_read_acc_2            6'd42
145
   `define state_read_acc_3            6'd43
146
   `define state_read_dist_1           6'd44
147
   `define state_read_dist_2           6'd45
148
   `define state_read_dist_3           6'd46
149
   `define state_read_prog_1           6'd47
150
   `define state_read_prog_2           6'd48
151
   `define state_read_prog_3           6'd49
152 21 eightycc
   `define state_write_acc_1           6'd50
153
   `define state_write_acc_2           6'd51
154
   `define state_write_acc_3           6'd52
155
   `define state_clear_drum_1          6'd53
156
   `define state_clear_drum_2          6'd54
157
   `define state_clear_drum_3          6'd55
158
   `define state_load_gs_1             6'd56
159
   `define state_load_gs_2             6'd57
160
   `define state_dump_gs_1             6'd58
161
   `define state_dump_gs_2             6'd59
162
   `define state_dump_gs_3             6'd60
163
   `define state_dump_gs_4             6'd61
164 7 eightycc
 
165 27 eightycc
   always @(posedge dp, posedge rst)
166 7 eightycc
      if (rst) begin
167
         console_to_addr  <= 0;
168
         pgm_start        <= 0;
169
         pgm_stop         <= 0;
170
         err_reset        <= 0;
171
         err_sense_reset  <= 0;
172
         man_pgm_reset    <= 0;
173
         man_acc_reset    <= 0;
174 11 eightycc
         hard_reset       <= 0;
175 7 eightycc
 
176
         // reset console switches
177
         pgm_sw_stop      <= 0;
178
         pgm_sw_run       <= 1;
179 11 eightycc
         half_cycle_sw_run <= 1;
180
         half_cycle_sw_half <= 0;
181 7 eightycc
         ctl_sw_addr_stop <= 0;
182
         ctl_sw_run       <= 1;
183
         ctl_sw_manual    <= 0;
184
         disp_sw_lacc     <= 0;
185
         disp_sw_uacc     <= 0;
186
         disp_sw_dist     <= 1;
187 22 eightycc
         disp_sw_pgm      <= 0;
188 7 eightycc
         disp_sw_ri       <= 0;
189
         disp_sw_ro       <= 0;
190
         ovflw_sw_stop    <= 1;
191
         ovflw_sw_sense   <= 0;
192
         err_sw_stop      <= 1;
193
         err_sw_sense     <= 0;
194
 
195
         state         <= `state_idle;
196
         busy          <= 1;
197
         digit_ready   <= 0;
198
         cmd_digit_out <= `biq_blank;
199 22 eightycc
         restart_reset_busy <= 0;
200 7 eightycc
 
201
         do_power_on_reset  <= 1;
202
         do_reset_console   <= 0;
203
         do_err_reset       <= 0;
204
         do_err_sense_reset <= 0;
205
         do_pgm_reset       <= 0;
206
         do_acc_reset       <= 0;
207 11 eightycc
         do_hard_reset      <= 0;
208
         do_clear_drum      <= 0;
209 7 eightycc
 
210
         gs_ram_addr        <= 15'd0;
211 9 eightycc
         read_gs            <= 0;
212 10 eightycc
         write_gs           <= 0;
213 21 eightycc
         acc_ri_console     <= 0;
214 11 eightycc
         console_out        <= `biq_blank;
215 27 eightycc
      end else begin
216 7 eightycc
         case (state)
217
            `state_idle: begin
218
               case (command)
219
                  `cmd_none: begin
220 22 eightycc
                     if (restart_reset) begin
221
                        do_pgm_reset       <= 1;
222
                        do_acc_reset       <= 1;
223
                        do_err_reset       <= 1;
224
                        restart_reset_busy <= 1;
225
                     end else if (do_power_on_reset) begin
226 7 eightycc
                        do_power_on_reset  <= 0;
227
                        do_reset_console   <= 1;
228
                        do_pgm_reset       <= 1;
229
                        do_acc_reset       <= 1;
230
                        do_err_reset       <= 1;
231
                        do_err_sense_reset <= 1;
232 11 eightycc
                        do_hard_reset      <= 1;
233
                        do_clear_drum      <= 1;
234
                     end else if (do_hard_reset) begin
235 22 eightycc
                        do_hard_reset      <= 0;
236
                        hard_reset         <= 1;
237 11 eightycc
                        state <= `state_hard_reset_1;
238 7 eightycc
                     end else if (do_reset_console) begin
239
                        do_reset_console   <= 0;
240
                        state <= `state_reset_console_1;
241
                     end else if (do_pgm_reset) begin
242
                        do_pgm_reset       <= 0;
243
                        state <= `state_pgm_reset_1;
244
                     end else if (do_acc_reset) begin
245
                        do_acc_reset       <= 0;
246
                        man_acc_reset      <= 1;
247
                        state <= `state_acc_reset_1;
248
                     end else if (do_err_reset) begin
249
                        do_err_reset       <= 0;
250
                        err_reset          <= 1;
251
                        state <= `state_err_reset_1;
252
                     end else if (do_err_sense_reset) begin
253
                        do_err_sense_reset <= 0;
254 22 eightycc
                        err_sense_reset    <= 1;
255 7 eightycc
                        state <= `state_err_sense_reset_1;
256 21 eightycc
                     end else if (do_clear_drum) begin
257 22 eightycc
                        do_clear_drum      <= 0;
258 21 eightycc
                        state <= `state_clear_drum_1;
259 7 eightycc
                     end else begin
260
                        busy <= 0;
261
                        digit_ready <= 0;
262 22 eightycc
                        restart_reset_busy <= 0;
263 7 eightycc
                     end
264
                  end
265
 
266
                  `cmd_pgm_sw_stop: begin
267
                     busy <= 1;
268
                     pgm_sw_stop <= 1;
269
                     pgm_sw_run  <= 0;
270
                  end
271
 
272
                  `cmd_pgm_sw_run: begin
273
                     busy <= 1;
274
                     pgm_sw_stop <= 0;
275
                     pgm_sw_run  <= 1;
276
                  end
277
 
278
                  `cmd_half_cycle_sw_run: begin
279
                     busy <= 1;
280
                     half_cycle_sw_run  <= 1;
281
                     half_cycle_sw_half <= 0;
282
                  end
283
 
284
                  `cmd_half_cycle_sw_half: begin
285
                     busy <= 1;
286
                     half_cycle_sw_run  <= 0;
287
                     half_cycle_sw_half <= 1;
288
                  end
289
 
290
                  `cmd_ctl_sw_addr_stop: begin
291
                     busy <= 1;
292
                     ctl_sw_addr_stop <= 1;
293
                     ctl_sw_run       <= 0;
294
                     ctl_sw_manual    <= 0;
295
                  end
296
 
297
                  `cmd_ctl_sw_run: begin
298
                     busy <= 1;
299
                     ctl_sw_addr_stop <= 0;
300
                     ctl_sw_run       <= 1;
301
                     ctl_sw_manual    <= 0;
302
                  end
303
 
304
                  `cmd_ctl_sw_manual: begin
305
                     busy <= 1;
306
                     ctl_sw_addr_stop <= 0;
307
                     ctl_sw_run       <= 0;
308
                     ctl_sw_manual    <= 1;
309
                  end
310
 
311
                  `cmd_disp_sw_lacc: begin
312
                     busy <= 1;
313
                     disp_sw_lacc <= 1;
314
                     disp_sw_uacc <= 0;
315
                     disp_sw_dist <= 0;
316 22 eightycc
                     disp_sw_pgm  <= 0;
317 7 eightycc
                     disp_sw_ri   <= 0;
318
                     disp_sw_ro   <= 0;
319
                  end
320
 
321
                  `cmd_disp_sw_uacc: begin
322
                     busy <= 1;
323
                     disp_sw_lacc <= 0;
324
                     disp_sw_uacc <= 1;
325
                     disp_sw_dist <= 0;
326
                     disp_sw_pgm <= 0;
327
                     disp_sw_ri   <= 0;
328
                     disp_sw_ro   <= 0;
329
                  end
330
 
331
                  `cmd_disp_sw_dist: begin
332
                     busy <= 1;
333
                     disp_sw_lacc <= 0;
334
                     disp_sw_uacc <= 0;
335
                     disp_sw_dist <= 1;
336
                     disp_sw_pgm <= 0;
337
                     disp_sw_ri   <= 0;
338
                     disp_sw_ro   <= 0;
339
                  end
340
 
341
                  `cmd_disp_sw_prog: begin
342
                     busy <= 1;
343
                     disp_sw_lacc <= 0;
344
                     disp_sw_uacc <= 0;
345
                     disp_sw_dist <= 0;
346
                     disp_sw_pgm <= 1;
347
                     disp_sw_ri   <= 0;
348
                     disp_sw_ro   <= 0;
349
                  end
350
 
351
                  `cmd_disp_sw_ri: begin
352
                     busy <= 1;
353
                     disp_sw_lacc <= 0;
354
                     disp_sw_uacc <= 0;
355
                     disp_sw_dist <= 0;
356
                     disp_sw_pgm <= 0;
357
                     disp_sw_ri   <= 1;
358
                     disp_sw_ro   <= 0;
359
                  end
360
 
361
                  `cmd_disp_sw_ro: begin
362
                     busy <= 1;
363
                     disp_sw_lacc <= 0;
364
                     disp_sw_uacc <= 0;
365
                     disp_sw_dist <= 0;
366
                     disp_sw_pgm <= 0;
367
                     disp_sw_ri   <= 0;
368
                     disp_sw_ro   <= 1;
369
                  end
370
 
371
                  `cmd_ovflw_sw_stop: begin
372
                     busy <= 1;
373
                     ovflw_sw_stop  <= 1;
374
                     ovflw_sw_sense <= 0;
375
                  end
376
 
377
                  `cmd_ovflw_sw_sense: begin
378
                     busy <= 1;
379
                     ovflw_sw_stop  <= 0;
380
                     ovflw_sw_sense <= 1;
381
                  end
382
 
383
                  `cmd_err_sw_stop: begin
384
                     busy <= 1;
385
                     err_sw_stop  <= 1;
386
                     err_sw_sense <= 0;
387
                  end
388
 
389
                  `cmd_err_sw_sense: begin
390
                     busy <= 1;
391
                     err_sw_stop  <= 0;
392
                     err_sw_sense <= 1;
393
                  end
394
 
395
                  `cmd_storage_entry_sw: begin
396
                     busy <= 1;
397
                     state <= `state_storage_entry_sw_1;
398
                  end
399
 
400
                  `cmd_addr_sel_sw: begin
401
                     busy <= 1;
402
                     state <= `state_addr_sel_sw_1;
403
                  end
404
 
405
                  `cmd_xfer_key: begin
406
                     if (ctl_sw_manual) begin
407
                        busy <= 1;
408
                        state <= `state_xfer_key_1;
409
                     end
410
                  end
411
 
412
                  `cmd_pgm_start_key: begin
413
                     busy <= 1;
414
                     state <= `state_pgm_start_key_1;
415
                  end
416
 
417
                  `cmd_pgm_stop_key: begin
418
                     busy <= 1;
419
                     pgm_stop <= 1;
420
                     state <= `state_pgm_stop_key_1;
421
                  end
422
 
423
                  `cmd_pgm_reset_key: begin
424 11 eightycc
                     busy <= 1;
425 7 eightycc
                     do_pgm_reset <= 1;
426
                     do_err_reset <= 1;
427
                  end
428
 
429
                  `cmd_comp_reset_key: begin
430 11 eightycc
                     busy <= 1;
431 7 eightycc
                     do_pgm_reset <= 1;
432
                     do_acc_reset <= 1;
433
                     do_err_reset <= 1;
434
                  end
435
 
436
                  `cmd_acc_reset_key: begin
437 11 eightycc
                     busy <= 1;
438 7 eightycc
                     do_acc_reset <= 1;
439
                     do_err_reset <= 1;
440
                  end
441
 
442
                  `cmd_err_reset_key: begin
443 11 eightycc
                     busy <= 1;
444 7 eightycc
                     do_err_reset <= 1;
445
                  end
446
 
447
                  `cmd_err_sense_reset_key: begin
448 11 eightycc
                     busy <= 1;
449 7 eightycc
                     do_err_sense_reset <= 1;
450
                  end
451
 
452
                  //--------------------------------------------------------------
453
                  // Read from general storage:
454
                  //    --> 4 digits address, little-endian
455
                  //    <-- 1 digit sign, 10 digits, little-endian
456
                  // 0 : Ignore if CPU not stopped
457
                  //     Accept low-order address digit
458
                  // 1 : Accept remaining address digits
459
                  // 2 : Calculate word origin in gs RAM
460
                  //     Validate address
461
                  //     console_read_gs <= 1;
462
                  // 3 : Send gs-early digit to out
463
                  //     digit_ready <= 1;
464
                  // 4 : digit_ready <= 0;
465
                  //--------------------------------------------------------------
466
                  `cmd_read_gs: begin
467
                     if (ctl_sw_manual) begin
468
                        busy <= 1;
469
                        state <= `state_read_gs_1;
470
                     end
471
                  end
472 10 eightycc
 
473 13 eightycc
                  // Write word to general storage:
474
                  //    --> 4 digits address, little-endian
475
                  //    <-- dx digit, sign digit, d1-d10
476
                  // 0: Ignore if not in manual
477
                  // 1: Readin low-order addr digit
478
                  // 2: Readin remaining addr digits
479
                  // 3: Synchronize with d10
480
                  //    digit_ready <- 1
481
                  // 4: Readin first digit
482
                  // 5: Write digit
483
                  //    Readin next digit
484
                  // 6: Cleanup
485 9 eightycc
                  `cmd_write_gs: begin
486 13 eightycc
                     if (ctl_sw_manual) begin
487
                        busy <= 1;
488
                        state <= `state_write_gs_1;
489
                     end
490 10 eightycc
                  end
491
 
492 9 eightycc
                  `cmd_read_acc: begin
493 16 eightycc
                     busy <= 1;
494
                     state <= `state_read_acc_1;
495 10 eightycc
                  end
496
 
497 9 eightycc
                  `cmd_read_dist: begin
498 16 eightycc
                     busy <= 1;
499
                     state <= `state_read_dist_1;
500 10 eightycc
                  end
501
 
502 9 eightycc
                  `cmd_read_prog: begin
503 16 eightycc
                     busy <= 1;
504
                     state <= `state_read_prog_1;
505 10 eightycc
                  end
506
 
507 21 eightycc
                  `cmd_write_acc: begin
508
                     busy <= 1;
509
                     state <= `state_write_acc_1;
510
                  end
511
 
512 10 eightycc
                  // 0 : Ignore if not in manual
513
                  //     Clear gs_ram_addr
514
                  // 1 : Synchronize with d10
515
                  //     Turn on console_write_gs
516
                  // 2 : Put a digit:
517
                  //     dx: blank
518
                  //     d0: minus
519
                  //     d1-d10: zero
520
                  //     gs_ram_addr++
521 9 eightycc
                  `cmd_clear_gs: begin
522 11 eightycc
                     if (ctl_sw_manual) begin
523
                        busy <= 1;
524
                        do_clear_drum <= 1;
525
                     end
526 10 eightycc
                  end
527
 
528 9 eightycc
                  `cmd_load_gs: begin
529 13 eightycc
                     if (ctl_sw_manual) begin
530
                        busy <= 1;
531
                        state <= `state_load_gs_1;
532
                        digit_ready <= 1;
533
                     end
534 10 eightycc
                  end
535
 
536 9 eightycc
                  `cmd_dump_gs: begin
537 15 eightycc
                     if (ctl_sw_manual) begin
538
                        busy <= 1;
539
                        state <= `state_dump_gs_1;
540
                     end
541 10 eightycc
                  end
542
 
543 9 eightycc
                  `cmd_power_on_reset: begin
544 13 eightycc
                     busy <= 1;
545
                     do_power_on_reset <= 1;
546 10 eightycc
                  end
547
 
548 9 eightycc
                  `cmd_reset_console: begin
549 13 eightycc
                     busy <= 1;
550
                     do_reset_console <= 1;
551 10 eightycc
                  end
552 7 eightycc
 
553 11 eightycc
                  `cmd_hard_reset: begin
554
                     busy <= 1;
555
                     do_hard_reset <= 1;
556
                  end
557
 
558 7 eightycc
               endcase;
559
            end
560
 
561
            // Reset console            
562
            `state_reset_console_1: begin
563
               if (d10) state <= `state_reset_console_2;
564
            end
565
 
566
            `state_reset_console_2: begin
567 11 eightycc
               storage_entry_sw[ontime_idx] <= dx? `biq_blank
568
                                             : d0? `biq_plus : `biq_0;
569 7 eightycc
               addr_sel_sw[ontime_idx[2:3]] <= `biq_0;
570
               if (d10) state <= `state_idle;
571
            end
572
 
573
            // Program reset key press
574
            `state_pgm_reset_1: begin
575
               if (wu & d10) begin
576
                  man_pgm_reset <= 1;
577
                  state <= `state_pgm_reset_2;
578
               end
579
            end
580
 
581
            `state_pgm_reset_2: begin
582
               if (wu & d10) begin
583
                  man_pgm_reset <= 0;
584
                  state <= `state_idle;
585
               end
586
            end
587
 
588
            // Accumulator reset key press
589
            `state_acc_reset_1: begin
590
               if (wu & d10) begin
591
                  man_acc_reset <= 1;
592
                  state <= `state_acc_reset_2;
593
               end
594
            end
595
 
596
            `state_acc_reset_2: begin
597
               if (wu & d10) begin
598
                  man_acc_reset <= 0;
599
                  state <= `state_idle;
600
               end
601
            end
602
 
603
            // Error reset key press
604
            `state_err_reset_1: begin
605
               if (wu & d10) begin
606
                  err_reset <= 1;
607
                  state <= `state_err_reset_2;
608
               end
609
            end
610
 
611
            `state_err_reset_2: begin
612
               if (wu & d10) begin
613
                  err_reset <= 0;
614
                  state <= `state_idle;
615
               end
616
            end
617
 
618
            // Error sense reset key press
619
            `state_err_sense_reset_1: begin
620
               if (wu & d10) begin
621
                  err_sense_reset <= 1;
622
                  state <= `state_err_sense_reset_2;
623
               end
624
            end
625
 
626
            `state_err_sense_reset_2: begin
627
               if (wu & d10) begin
628
                  err_sense_reset <= 0;
629
                  state <= `state_idle;
630
               end
631
            end
632
 
633 11 eightycc
            // Hard reset
634
            `state_hard_reset_1: begin
635
               hard_reset <= 0;
636
               state <= `state_idle;
637
            end
638
 
639 7 eightycc
            // Set storage entry switches
640
            `state_storage_entry_sw_1: begin
641
               if (d0) begin
642
                  state <= `state_storage_entry_sw_2;
643
                  digit_ready <= 1;
644
                  storage_entry_sw[ontime_idx] <= cmd_digit_in;
645
               end
646
            end
647
 
648
            `state_storage_entry_sw_2: begin
649
               storage_entry_sw[ontime_idx] <= cmd_digit_in;
650
               if (d10) begin
651
                  state <= `state_idle;
652
                  digit_ready <= 0;
653
               end
654
            end
655
 
656
            // Set address selection switches
657
            `state_addr_sel_sw_1: begin
658
               if (dx) begin
659
                  state <= `state_addr_sel_sw_2;
660
                  digit_ready <= 1;
661
                  addr_sel_sw[ontime_idx[2:3]] <= cmd_digit_in;
662
               end
663
            end
664
 
665
            `state_addr_sel_sw_2: begin
666
               addr_sel_sw[ontime_idx[2:3]] <= cmd_digit_in;
667
               if (d2) begin
668
                  state <= `state_idle;
669
                  digit_ready <= 0;
670
               end
671
            end
672
 
673
            // Transfer key press
674
            `state_xfer_key_1: begin
675
               if (d10) begin
676
                  console_to_addr <= 1;
677
                  state <= `state_xfer_key_2;
678
               end
679
            end
680
 
681
            `state_xfer_key_2: begin
682
               if (d10) begin
683
                  console_to_addr <= 0;
684
                  state <= `state_idle;
685
               end
686
            end
687
 
688
            // Start key press
689
            `state_pgm_start_key_1: begin
690
               if (wu & d10) begin
691
                  pgm_start <= 1;
692
                  state <= `state_pgm_start_key_2;
693
               end
694
            end
695
 
696
            `state_pgm_start_key_2: begin
697
               if (wu & d10) begin
698
                  pgm_start <= 0;
699
                  state <= `state_idle;
700
               end
701
            end
702
 
703
            // Stop key press
704
            `state_pgm_stop_key_1: begin
705
               if (hp) state <= `state_pgm_stop_key_2;
706
            end
707
 
708
            `state_pgm_stop_key_2: begin
709
               if (hp) begin
710
                  pgm_stop <= 0;
711
                  state <= `state_idle;
712
               end
713
            end
714
 
715
            // Read word from general storage
716
            //    --> 4 digits address, little-endian
717
            //    <-- 1 digit sign, 10 digits, little-endian
718
            // 0 : Ignore if CPU not stopped
719 12 eightycc
            // 1 : Accept first address digit
720
            // 2 : Accept remaining address digits
721 7 eightycc
            // 2 : Calculate word origin in gs RAM
722
            //     Validate address
723
            //     console_read_gs <= 1;
724
            // 3 : Send gs-early digit to out
725
            //     digit_ready <= 1;
726
            // 4 : digit_ready <= 0;
727
            `state_read_gs_1: begin
728
               if (dx) begin
729
                  state <= `state_read_gs_2;
730
                  digit_ready <= 1;
731
                  gs_addr_u <= cmd_digit_in;
732
               end
733
            end
734
 
735
            `state_read_gs_2: begin
736
               if (d0) gs_addr_t <= cmd_digit_in;
737
               else if (d1) gs_addr_h <= cmd_digit_in;
738
               else if (d2) begin
739
                  gs_addr_th <= cmd_digit_in;
740
                  state <= `state_read_gs_3;
741
                  digit_ready <= 0;
742
               end
743
            end
744
 
745
            `state_read_gs_3: begin
746 12 eightycc
               if (d10) begin
747
                  gs_ram_addr <= gs_word_addr;
748
                  read_gs <= 1;
749
                  state <= `state_read_gs_4;
750
               end
751 7 eightycc
            end
752
 
753 10 eightycc
            `state_read_gs_4: begin
754
               state <= `state_read_gs_5;
755 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
756 10 eightycc
            end
757 12 eightycc
 
758
            `state_read_gs_5: begin
759
               digit_ready <= 1;
760
               cmd_digit_out <= gs_in;
761 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
762 12 eightycc
               if (dx) begin
763
                  state <= `state_read_gs_6;
764
                  read_gs <= 0;
765
               end
766
            end
767
 
768
            `state_read_gs_6: begin
769
               digit_ready <= 0;
770
               state <= `state_idle;
771
            end
772 11 eightycc
 
773 13 eightycc
            // Write word to general storage:
774
            //    --> 4 digits address, little-endian
775
            //    <-- dx digit, sign digit, d1-d10
776
            // 0: Ignore if not in manual
777
            // 1: Readin low-order addr digit
778
            // 2: Readin remaining addr digits
779
            // 3: Synchronize with d10
780
            //    digit_ready <- 1
781
            // 4: Readin and write digit
782
            // 5: Write digit
783
            //    Readin next digit
784
            // 6: Cleanup
785
 
786
            `state_write_gs_1: begin
787
               if (dx) begin
788
                  state <= `state_write_gs_2;
789
                  digit_ready <= 1;
790
                  gs_addr_u <= cmd_digit_in;
791
               end
792
            end
793
 
794
            `state_write_gs_2: begin
795
               if (d0) gs_addr_t <= cmd_digit_in;
796
               else if (d1) gs_addr_h <= cmd_digit_in;
797
               else if (d2) begin
798
                  gs_addr_th <= cmd_digit_in;
799
                  state <= `state_write_gs_3;
800
                  digit_ready <= 0;
801
               end
802
            end
803
 
804
            `state_write_gs_3: begin
805
               if (d10) begin
806
                  gs_ram_addr <= gs_word_addr;
807
                  digit_ready <= 1;
808
                  state <= `state_write_gs_4;
809
               end
810
            end
811
 
812
            `state_write_gs_4: begin
813
               write_gs <= 1;
814
               console_out <= cmd_digit_in;
815 16 eightycc
               if (write_gs)
816
                  gs_ram_addr <= (gs_ram_addr + 1) % 32768;
817 13 eightycc
               if (d10) begin
818
                  digit_ready <= 0;
819
                  state <= `state_write_gs_5;
820
               end
821
            end
822
 
823
            `state_write_gs_5: begin
824
               write_gs <= 0;
825
               state <= `state_idle;
826
            end
827
 
828 16 eightycc
            `state_read_acc_1: begin
829
               if (wl & d10) begin
830
                  state <= `state_read_acc_2;
831
               end
832
            end
833
 
834
            `state_read_acc_2: begin
835
               digit_ready <= 1;
836
               cmd_digit_out <= acc_ontime;
837
               if (wu & d10) begin
838
                  state <= `state_read_acc_3;
839
               end
840
            end
841
 
842
            `state_read_acc_3: begin
843
               digit_ready <= 0;
844
               state <= `state_idle;
845
            end
846
 
847
            `state_read_dist_1: begin
848
               if (d10) begin
849
                  state <= `state_read_dist_2;
850
               end
851
            end
852
 
853
            `state_read_dist_2: begin
854
               digit_ready <= 1;
855
               cmd_digit_out <= dist_ontime;
856
               if (d10) begin
857
                  state <= `state_read_dist_3;
858
               end
859
            end
860
 
861
            `state_read_dist_3: begin
862
               digit_ready <= 0;
863
               state <= `state_idle;
864
            end
865
 
866
            `state_read_prog_1: begin
867
               if (d10) begin
868
                  state <= `state_read_prog_2;
869
               end
870
            end
871
 
872
            `state_read_prog_2: begin
873
               digit_ready <= 1;
874
               cmd_digit_out <= prog_ontime;
875
               if (d10) begin
876
                  state <= `state_read_prog_3;
877
               end
878
            end
879
 
880
            `state_read_prog_3: begin
881
               digit_ready <= 0;
882
               state <= `state_idle;
883
            end
884
 
885 21 eightycc
            `state_write_acc_1: begin
886 22 eightycc
               if (wl & dx) begin
887 21 eightycc
                  console_out <= cmd_digit_in;
888
                  acc_ri_console <= 1;
889
                  digit_ready <= 1;
890
                  state <= `state_write_acc_2;
891
               end
892
            end
893
 
894
            `state_write_acc_2: begin
895
               console_out <= cmd_digit_in;
896
               if (wu & d10) begin
897
                  digit_ready <= 0;
898
                  state <= `state_write_acc_3;
899
               end
900
            end
901
 
902
            `state_write_acc_3: begin
903
               acc_ri_console <= 0;
904
               state <= `state_idle;
905
            end
906
 
907 11 eightycc
            // 0 : Ignore if not in manual
908 15 eightycc
            // 1 : Synchronize with dx
909
            //     Put first dx digit
910 11 eightycc
            // 2 : Put a digit:
911
            //     dx: blank
912
            //     d0: minus
913
            //     d1-d10: zero
914
            `state_clear_drum_1: begin
915 15 eightycc
               if (dx) begin
916 13 eightycc
                  console_out <= `biq_blank;
917
                  gs_ram_addr <= 15'd0;
918
                  write_gs <= 1;
919 11 eightycc
                  state <= `state_clear_drum_2;
920
               end
921
            end
922 10 eightycc
 
923 11 eightycc
            `state_clear_drum_2: begin
924
               console_out <= dx? `biq_blank
925
                            : d0? `biq_minus
926
                            : `biq_0;
927 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
928 11 eightycc
               if (gs_ram_addr == 15'd23999) begin
929
                  write_gs <= 0;
930
                  state <= `state_idle;
931
               end
932
            end
933
 
934 13 eightycc
            `state_load_gs_1: begin
935
               gs_ram_addr <= 15'd0;
936
               write_gs <= 1;
937
               console_out <= cmd_digit_in;
938
               state <= `state_load_gs_2;
939
            end
940
 
941
            `state_load_gs_2: begin
942 15 eightycc
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
943 13 eightycc
               console_out <= cmd_digit_in;
944 15 eightycc
               if (gs_ram_addr == 15'd23999) begin
945 13 eightycc
                  write_gs <= 0;
946
                  digit_ready <= 0;
947
                  state <= `state_idle;
948
               end
949
            end
950
 
951 15 eightycc
            `state_dump_gs_1: begin
952
               gs_ram_addr <= 15'd0;
953
               read_gs <= 1;
954
               state <= `state_dump_gs_2;
955
            end
956
 
957
            `state_dump_gs_2: begin
958
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
959
               state <= `state_dump_gs_3;
960
            end
961
 
962
            `state_dump_gs_3: begin
963
               digit_ready <= 1;
964
               gs_ram_addr <= (gs_ram_addr + 1) % 32768;
965
               cmd_digit_out <= gs_in;
966
               if (gs_ram_addr == 15'd23999) begin
967
                  state <= `state_dump_gs_4;
968
               end
969
            end
970
 
971
            `state_dump_gs_4: begin
972
               digit_ready <= 0;
973
               read_gs <= 0;
974
               state <= `state_idle;
975
            end
976
 
977 7 eightycc
         endcase;
978 20 eightycc
      end;
979 7 eightycc
 
980 20 eightycc
   always @(posedge ap)
981 11 eightycc
      if (hard_reset) begin
982 7 eightycc
         data_out <= `biq_blank;
983
         addr_out <= `biq_blank;
984
      end else begin
985
         data_out <= d10? `biq_blank : storage_entry_sw[early_idx];
986
         addr_out <= (d3 | d4 | d5 | d6)? addr_sel_sw[early_idx[2:3]] : `biq_blank;
987 20 eightycc
      end;
988 7 eightycc
 
989 20 eightycc
   always @(posedge ap)
990 11 eightycc
      if (hard_reset) begin
991 7 eightycc
         punch_card       <= 0;
992
         read_card        <= 0;
993
         card_digit_ready <= 0;
994 20 eightycc
      end;
995 7 eightycc
 
996
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.