1 /*
2  * viciivsid-timing.c - Timing related settings for the MOS 6569 (VIC-II) emulation.
3  *
4  * Written by
5  *  Andreas Boose <viceteam@t-online.de>
6  *  Gunnar Ruthenberg <Krill.Plush@gmail.com>
7  *
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #include "vice.h"
29 
30 #include "archdep.h"
31 #include "c64.h"
32 #include "machine.h"
33 #include "resources.h"
34 #include "vicii-sprites.h"
35 #include "vicii-timing.h"
36 #include "vicii.h"
37 #include "viciitypes.h"
38 
39 /* Number of cycles per line.  */
40 #define VICII_PAL_CYCLES_PER_LINE      C64_PAL_CYCLES_PER_LINE
41 #define VICII_NTSC_CYCLES_PER_LINE     C64_NTSC_CYCLES_PER_LINE
42 #define VICII_NTSCOLD_CYCLES_PER_LINE  C64_NTSCOLD_CYCLES_PER_LINE
43 #define VICII_PALN_CYCLES_PER_LINE     C64_PALN_CYCLES_PER_LINE
44 
45 /* Cycle # at which sprite DMA is set.  */
46 #define VICII_PAL_SPRITE_FETCH_CYCLE       54
47 #define VICII_NTSC_SPRITE_FETCH_CYCLE      55
48 #define VICII_NTSCOLD_SPRITE_FETCH_CYCLE   55
49 #define VICII_PALN_SPRITE_FETCH_CYCLE      55
50 
51 #define VICII_PAL_SPRITE_WRAP_X     504
52 #define VICII_NTSC_SPRITE_WRAP_X    520
53 #define VICII_NTSCOLD_SPRITE_WRAP_X 512
54 #define VICII_PALN_SPRITE_WRAP_X    520
55 
56 /* Cycle # at which the current raster line is re-drawn.  It is set to
57    `VICII_CYCLES_PER_LINE', so this actually happens at the very beginning
58    (i.e. cycle 0) of the next line.  */
59 #define VICII_PAL_DRAW_CYCLE       VICII_PAL_CYCLES_PER_LINE
60 #define VICII_NTSC_DRAW_CYCLE      VICII_NTSC_CYCLES_PER_LINE
61 #define VICII_NTSCOLD_DRAW_CYCLE   VICII_NTSCOLD_CYCLES_PER_LINE
62 #define VICII_PALN_DRAW_CYCLE      VICII_PALN_CYCLES_PER_LINE
63 
64 /* Common parameters for all video standards */
65 #define VICII_25ROW_START_LINE    0x33
66 #define VICII_25ROW_STOP_LINE     0xfb
67 #define VICII_24ROW_START_LINE    0x37
68 #define VICII_24ROW_STOP_LINE     0xf7
69 
70 /* Bad line range.  */
71 #define VICII_FIRST_DMA_LINE      0x30
72 #define VICII_LAST_DMA_LINE       0xf7
73 
74 
vicii_timing_set(machine_timing_t * machine_timing)75 void vicii_timing_set(machine_timing_t *machine_timing)
76 {
77     int mode;
78 
79     resources_get_int("MachineVideoStandard", &mode);
80 
81     switch (mode) {
82         case MACHINE_SYNC_NTSC:
83             vicii.screen_height = VICII_NTSC_SCREEN_HEIGHT;
84             vicii.screen_leftborderwidth = VICII_SCREEN_NTSC_NORMAL_LEFTBORDERWIDTH;
85             vicii.screen_rightborderwidth = VICII_SCREEN_NTSC_NORMAL_RIGHTBORDERWIDTH;
86             vicii.first_displayed_line = VICII_NTSC_NORMAL_FIRST_DISPLAYED_LINE;
87             vicii.last_displayed_line = VICII_NTSC_NORMAL_LAST_DISPLAYED_LINE;
88             vicii.cycles_per_line = VICII_NTSC_CYCLES_PER_LINE;
89             vicii.draw_cycle = VICII_NTSC_DRAW_CYCLE;
90             vicii.sprite_fetch_cycle = VICII_NTSC_SPRITE_FETCH_CYCLE;
91             vicii.sprite_wrap_x = VICII_NTSC_SPRITE_WRAP_X;
92             break;
93         case MACHINE_SYNC_NTSCOLD:
94             vicii.screen_height = VICII_NTSCOLD_SCREEN_HEIGHT;
95             vicii.screen_leftborderwidth = VICII_SCREEN_NTSCOLD_NORMAL_LEFTBORDERWIDTH;
96             vicii.screen_rightborderwidth = VICII_SCREEN_NTSCOLD_NORMAL_RIGHTBORDERWIDTH;
97             vicii.first_displayed_line = VICII_NTSCOLD_NORMAL_FIRST_DISPLAYED_LINE;
98             vicii.last_displayed_line = VICII_NTSCOLD_NORMAL_LAST_DISPLAYED_LINE;
99             vicii.cycles_per_line = VICII_NTSCOLD_CYCLES_PER_LINE;
100             vicii.draw_cycle = VICII_NTSCOLD_DRAW_CYCLE;
101             vicii.sprite_fetch_cycle = VICII_NTSCOLD_SPRITE_FETCH_CYCLE;
102             vicii.sprite_wrap_x = VICII_NTSCOLD_SPRITE_WRAP_X;
103             break;
104         case MACHINE_SYNC_PALN:
105             vicii.screen_height = VICII_PALN_SCREEN_HEIGHT;
106             vicii.screen_leftborderwidth = VICII_SCREEN_PALN_NORMAL_LEFTBORDERWIDTH;
107             vicii.screen_rightborderwidth = VICII_SCREEN_PALN_NORMAL_RIGHTBORDERWIDTH;
108             vicii.first_displayed_line = VICII_PALN_NORMAL_FIRST_DISPLAYED_LINE;
109             vicii.last_displayed_line = VICII_PALN_NORMAL_LAST_DISPLAYED_LINE;
110             vicii.cycles_per_line = VICII_PALN_CYCLES_PER_LINE;
111             vicii.draw_cycle = VICII_PALN_DRAW_CYCLE;
112             vicii.sprite_fetch_cycle = VICII_PALN_SPRITE_FETCH_CYCLE;
113             vicii.sprite_wrap_x = VICII_PALN_SPRITE_WRAP_X;
114             break;
115         case MACHINE_SYNC_PAL:
116         default:
117             vicii.screen_height = VICII_PAL_SCREEN_HEIGHT;
118             vicii.screen_leftborderwidth = VICII_SCREEN_PAL_NORMAL_LEFTBORDERWIDTH;
119             vicii.screen_rightborderwidth = VICII_SCREEN_PAL_NORMAL_RIGHTBORDERWIDTH;
120             vicii.first_displayed_line = VICII_PAL_NORMAL_FIRST_DISPLAYED_LINE;
121             vicii.last_displayed_line = VICII_PAL_NORMAL_LAST_DISPLAYED_LINE;
122             vicii.cycles_per_line = VICII_PAL_CYCLES_PER_LINE;
123             vicii.draw_cycle = VICII_PAL_DRAW_CYCLE;
124             vicii.sprite_fetch_cycle = VICII_PAL_SPRITE_FETCH_CYCLE;
125             vicii.sprite_wrap_x = VICII_PAL_SPRITE_WRAP_X;
126             break;
127     }
128 
129     vicii.first_dma_line = VICII_FIRST_DMA_LINE;
130     vicii.last_dma_line = VICII_LAST_DMA_LINE;
131     vicii.row_25_start_line = VICII_25ROW_START_LINE;
132     vicii.row_25_stop_line = VICII_25ROW_STOP_LINE;
133     vicii.row_24_start_line = VICII_24ROW_START_LINE;
134     vicii.row_24_stop_line = VICII_24ROW_STOP_LINE;
135 
136     vicii.raster.display_xstart = VICII_40COL_START_PIXEL;
137     vicii.raster.display_xstop = VICII_40COL_STOP_PIXEL;
138 
139     vicii_sprites_init_sprline();
140 }
141