Subversion Repositories pentevo

Rev

Rev 356 | Rev 512 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. `include "../include/tune.v"
  2.  
  3. // Pentevo project (c) NedoPC 2011
  4. //
  5. // address generation module for video data fetching
  6.  
  7. module video_addrgen(
  8.  
  9.         input  wire        clk, // 28 MHz clock
  10.  
  11.  
  12.         output reg  [20:0] video_addr, // DRAM arbiter signals
  13.         input  wire        video_next, //
  14.  
  15.  
  16.         input  wire        line_start, // some video sync signals
  17.         input  wire        int_start,  //
  18.         input  wire        vpix,       //
  19.  
  20.         input  wire        scr_page, // which screen to use
  21.  
  22.  
  23.         input  wire        mode_atm_n_pent, // decoded modes
  24.         input  wire        mode_zx,         //
  25.         input  wire        mode_p_16c,      //
  26.         input  wire        mode_p_hmclr,    //
  27.                                             //
  28.         input  wire        mode_a_hmclr,    //
  29.         input  wire        mode_a_16c,      //
  30.         input  wire        mode_a_text,     //
  31.  
  32.         output wire [ 2:0] typos // Y position in text mode symbols
  33. );
  34.  
  35.         wire mode_ag;
  36.  
  37.         assign mode_ag = mode_a_16c | mode_a_hmclr;
  38.  
  39.  
  40.  
  41.         wire line_init, frame_init;
  42.  
  43.         wire gnext,tnext,ldaddr;
  44.  
  45.         reg line_start_r;
  46.         reg frame_init_r;
  47.         reg line_init_r;
  48.  
  49.         always @(posedge clk)
  50.                 line_start_r <= line_start;
  51.  
  52.         assign line_init  = line_start_r & vpix;
  53.         assign frame_init = int_start;
  54.  
  55.         reg [13:0] gctr;
  56.  
  57.         reg [7:0] tyctr; // text Y counter
  58.         reg [6:0] txctr; // text X counter
  59.  
  60.  
  61.         always @(posedge clk)
  62.                 frame_init_r <= frame_init;
  63.  
  64.         always @(posedge clk)
  65.                 line_init_r <= line_init;
  66.  
  67.  
  68.         assign gnext = video_next | frame_init_r;
  69.         assign tnext = video_next | line_init_r;
  70.         assign ldaddr = mode_a_text ? tnext : gnext;
  71.  
  72.         // gfx counter
  73.         always @(posedge clk)
  74.         if( frame_init )
  75.                 gctr <= 0;
  76.         else if( gnext )
  77.                 gctr <= gctr + 1;
  78.  
  79.  
  80.         // text counters
  81.         always @(posedge clk)
  82.         if( frame_init )
  83.                 tyctr <= 8'b0011_0111;
  84.         else if( line_init )
  85.                 tyctr <= tyctr + 1;
  86.  
  87.         always @(posedge clk)
  88.         if( line_init )
  89.                 txctr <= 7'b000_0000;
  90.         else if( tnext )
  91.                 txctr <= txctr + 1;
  92.  
  93.  
  94.         assign typos = tyctr[2:0];
  95.  
  96.  
  97. // zx mode:
  98. // [0] - attr or pix
  99. // [4:1] - horiz pos 0..15 (words)
  100. // [12:5] - vert pos
  101.  
  102.         wire [20:0] addr_zx;   // standard zx mode
  103.         wire [20:0] addr_phm;  // pentagon hardware multicolor
  104.         wire [20:0] addr_p16c; // pentagon 16c
  105.  
  106.         wire [20:0] addr_ag; // atm gfx: 16c (x320) or hard multicolor (x640) - same sequence!
  107.  
  108.         wire [20:0] addr_at; // atm text
  109.  
  110.         wire [11:0] addr_zx_pix;
  111.         wire [11:0] addr_zx_attr;
  112.         wire [11:0] addr_zx_p16c;
  113.  
  114.  
  115.         assign addr_zx_pix  = { gctr[12:11], gctr[7:5], gctr[10:8], gctr[4:1] };
  116.  
  117.         assign addr_zx_attr = { 3'b110, gctr[12:8], gctr[4:1] };
  118.  
  119.         assign addr_zx_p16c = { gctr[13:12], gctr[8:6], gctr[11:9], gctr[5:2] };
  120.  
  121.  
  122.         assign addr_zx =   { 6'b000001, scr_page, 2'b10, ( gctr[0] ? addr_zx_attr : addr_zx_pix ) };
  123.  
  124.         assign addr_phm =  { 6'b000001, scr_page, 1'b1, gctr[0], addr_zx_pix };
  125.  
  126.         assign addr_p16c = { 6'b000001, scr_page, ~gctr[0], gctr[1], addr_zx_p16c };
  127.  
  128.  
  129.         assign addr_ag = { 5'b00000, ~gctr[0], scr_page, 1'b1, gctr[1], gctr[13:2] };
  130.  
  131. //      assign addr_at = { 5'b00000, ~txctr[0], scr_page, 1'b1, (^txctr[1:0]), 2'b00, tyctr[7:3], txctr[6:2] };
  132.         assign addr_at = { 5'b00000, ~txctr[0], scr_page, 1'b1, txctr[1], 2'b00, tyctr[7:3], txctr[6:2] };
  133.  
  134.  
  135.         always @(posedge clk) if( ldaddr )
  136.         begin
  137.                 video_addr <=
  138.                         ( {21{mode_zx     }} & addr_zx  )  |
  139.                         ( {21{mode_p_16c  }} & addr_p16c)  |
  140.                         ( {21{mode_p_hmclr}} & addr_phm )  |
  141.                         ( {21{mode_ag     }} & addr_ag  )  |
  142.                         ( {21{mode_a_text }} & addr_at  )  ;
  143.  
  144.         end
  145.  
  146.  
  147. endmodule
  148.  
  149.