|
|
1.1 root 1: /*
1.1.1.5 root 2: Hatari - video.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
1.1 root 6:
1.1.1.7 root 7: Video hardware handling. This code handling all to do with the video chip.
8: So, we handle VBLs, HBLs, copying the ST screen to a buffer to simulate the
9: TV raster trace, border removal, palette changes per HBL, the 'video address
10: pointer' etc...
1.1 root 11: */
1.1.1.11 root 12:
13: /* 2007/03/xx [NP] Support for cycle precise border removal / hardware scrolling by using */
14: /* Cycles_GetCounterOnWriteAccess (support left/right border and lines with*/
15: /* length of +26, +2, -2, +44, -106 bytes). */
16: /* Add support for 'Enchanted Lands' second removal of right border. */
17: /* More precise support for reading video counter $ff8205/07/09. */
18: /* 2007/04/14 [NP] Precise reloading of $ff8201/03 into $ff8205/07/09 at line 310 on cycle */
19: /* RESTART_VIDEO_COUNTER_CYCLE (ULM DSOTS Demo). */
20: /* 2007/04/16 [NP] Better Video_CalculateAddress. We must substract a "magic" 12 cycles to */
21: /* Cycles_GetCounterOnReadAccess(CYCLES_COUNTER_VIDEO) to get a correct */
22: /* value (No Cooper's video synchro protection is finaly OK :) ). */
23: /* 2007/04/17 [NP] - Switch to 60 Hz to remove top border on line 33 should occur before */
24: /* LINE_REMOVE_TOP_CYCLE (a few cycles before the HBL) */
25: /* 2007/04/23 [NP] - Slight change in Video_StoreResolution to ignore hi res if the line */
26: /* has left/right border removed -> assume of lo res line. */
27: /* - Handle simultaneous removal of right border and bottom border with */
28: /* the same long switch to 60 Hz (Sync Screen in SNY II). */
29: /* 2007/05/06 [NP] More precise tests for top border's removal. */
1.1.1.15 root 30: /* 2007/05/11 [NP] Add support for med res overscan (No Cooper Greetings). */
1.1.1.11 root 31: /* 2007/05/12 [NP] - LastCycleSync50 and LastCycleSync60 for better top border's removal */
32: /* in Video_EndHBL. */
33: /* - Use VideoOffset in Video_CopyScreenLineColor to handle missing planes */
1.1.1.15 root 34: /* depending on line (med/lo and borders). */
1.1.1.11 root 35: /* 2007/09/25 [NP] Replace printf by calls to HATARI_TRACE. */
36: /* 2007/10/02 [NP] Use the new int.c to add interrupts with INT_CPU_CYCLE / INT_MFP_CYCLE. */
37: /* 2007/10/23 [NP] Add support for 0 byte line (60/50 switch at cycle 56). Allow 5 lines */
38: /* hardscroll (e.g. SHFORSTV.EXE by Paulo Simmoes). */
1.1.1.15 root 39: /* 2007/10/31 [NP] Use BORDERMASK_LEFT_OFF_MED when left border is removed with hi/med */
1.1.1.11 root 40: /* switch (ST CNX in PYM). */
41: /* 2007/11/02 [NP] Add support for 4 pixel hardware scrolling ("Let's Do The Twist" by */
42: /* ST CNX in Punish Your Machine). */
1.1.1.15 root 43: /* 2007/11/05 [NP] Depending on the position of the med res switch, the planes will be */
44: /* shifted when doing med res overscan (Best Part Of the Creation in PYM */
1.1.1.11 root 45: /* or No Cooper Greetings). */
1.1.1.15 root 46: /* 2007/11/30 [NP] A hi/med switch to remove the left border can be either used to initiate*/
47: /* a right hardware scrolling in low res (St Cnx) or a complete med res */
1.1.1.11 root 48: /* overscan line (Dragonnels Reset Part). */
49: /* Use bit 0-15, 16-19 and 20-23 in ScreenBorderMask[] to track border */
50: /* trick, STF hardware scrolling and plane shifting. */
51: /* 2007/12/22 [NP] Very precise values for VBL_VIDEO_CYCLE_OFFSET, HBL_VIDEO_CYCLE_OFFSET */
52: /* TIMERB_VIDEO_CYCLE_OFFSET and RESTART_VIDEO_COUNTER_CYCLE. These values */
53: /* were calculated using sttiming.s on a real STF and should give some very*/
54: /* accurate results (also uses 56 cycles instead of 44 to process an */
1.1.1.13 root 55: /* HBL/VBL/MFP exception). */
1.1.1.11 root 56: /* 2007/12/29 [NP] Better support for starting line 2 bytes earlier (if the line starts in */
57: /* 60 Hz and goes back to 50 Hz later), when combined with top border */
58: /* removal (Mindbomb Demo - D.I. No Shit). */
59: /* 2007/12/30 [NP] Slight improvement of VideoAdress in Video_CalculateAddress when reading*/
60: /* during the top border. */
61: /* Correct the case where removing top border on line 33 could also be */
62: /* interpreted as a right border removal (which is not possible since the */
63: /* display is still off at that point). */
64: /* 2008/01/03 [NP] Better handling of nStartHBL and nEndHBL when switching freq from */
65: /* 50 to 60 Hz. Allows emulation of a "short" 50 Hz screen of 171 lines */
66: /* and a more precise removal of bottom border in 50 and 60 Hz. */
67: /* 2008/01/04 [NP] More generic detection for removing 2 bytes to the right of the line */
68: /* when switching from 60 to 50 Hz (works even with a big number of cycles */
69: /* between the freq changes) (Phaleon's Menus). */
70: /* 2008/01/06 [NP] More generic detection for stopping the display in the middle of a line */
71: /* with a hi / lo res switch (-106 bytes per line). Although switch to */
72: /* hi res should occur at cycle 160, some demos use 164 (Phaleon's Menus). */
73: /* 2008/01/06 [NP] Better bottom border's removal in 50 Hz : switch to 60 Hz must occur */
74: /* before cycle LINE_REMOVE_BOTTOM_CYCLE on line 263 and switch back to 50 */
75: /* Hz must occur after LINE_REMOVE_BOTTOM_CYCLE on line 263 (this means */
76: /* we can already be in 50 Hz when Video_EndHBL is called and still remove */
77: /* the bottom border). This is similar to the tests used to remove the */
78: /* top border. */
79: /* 2008/01/12 [NP] In Video_SetHBLPaletteMaskPointers, consider that if a color's change */
80: /* occurs after cycle LINE_END_CYCLE_NO_RIGHT, then it's related to the */
81: /* next line. */
82: /* FIXME : it would be better to handle all color changes through spec512.c*/
83: /* and drop the 16 colors palette per line. */
84: /* FIXME : we should use Cycles_GetCounterOnWriteAccess, but it doesn't */
85: /* support multiple accesses like move.l or movem. */
86: /* 2008/01/12 [NP] Handle 60 Hz switch during the active display of the last line to remove*/
87: /* the bottom border : this should also shorten line by 2 bytes (F.N.I.L. */
88: /* Demo by TNT). */
89: /* 2008/01/15 [NP] Don't do 'left+2' if switch back to 50 Hz occurs when line is not active*/
90: /* (after cycle LINE_END_CYCLE_60) (XXX International Demos). */
91: /* 2008/01/31 [NP] Improve left border detection : allow switch to low res on cycle <= 28 */
92: /* instead of <= 20 (Vodka Demo Main Menu). */
93: /* 2008/02/02 [NP] Added 0 byte line detection when switching hi/lo res at position 28 */
94: /* (Lemmings screen in Nostalgic-o-demo). */
95: /* 2008/02/03 [NP] On STE, write to video counter $ff8205/07/09 should only be applied */
96: /* immediatly if display has not started for the line (before cycle */
97: /* LINE_END_CYCLE_50). If write occurs after, the change to pVideoRaster */
98: /* should be delayed to the end of the line, after processing the current */
99: /* line with Video_CopyScreenLineColor (Stardust Tunnel Demo). */
100: /* 2008/02/04 [NP] The problem is similar when writing to hwscroll $ff8264, we must delay */
101: /* the change until the end of the line if display was already started */
102: /* (Mindrewind by Reservoir Gods). */
103: /* 2008/02/06 [NP] On STE, when left/right borders are off and hwscroll > 0, we must read */
104: /* 6 bytes less than the expected value (E605 by Light). */
105: /* 2008/02/17 [NP] In Video_CopyScreenLine, LineWidth*2 bytes should be added after */
106: /* pNewVideoRaster is copied to pVideoRaster (Braindamage Demo). */
107: /* When reading a byte at ff8205/07/09, all video address bytes should be */
108: /* updated in Video_ScreenCounter_ReadByte, not just the byte that was */
109: /* read. Fix programs that just modify one byte in the video address */
110: /* counter (e.g. sub #1,$ff8207 in Braindamage Demo). */
111: /* 2008/02/19 [NP] In Video_CalculateAddress, use pVideoRaster instead of VideoBase to */
112: /* determine the video address when display is off in the upper part of */
113: /* the screen (in case ff8205/07/09 were modified on STE). */
114: /* 2008/02/20 [NP] Better handling in Video_ScreenCounter_WriteByte by changing only one */
115: /* byte and keeping the other (Braindamage End Part). */
116: /* 2008/03/08 [NP] Use M68000_INT_VIDEO when calling M68000_Exception(). */
117: /* 2008/03/13 [NP] On STE, LineWidth value in $ff820f is added to the shifter counter just */
118: /* when display is turned off on a line (when right border is started, */
119: /* which is usually on cycle 376). */
120: /* This means a write to $ff820f should be applied immediatly only if it */
121: /* occurs before cycle LineEndCycle. Else, it is stored in NewLineWidth */
122: /* and used after Video_CopyScreenLine has processed the current line */
123: /* (improve the bump mapping part in Pacemaker by Paradox). */
124: /* LineWidth should be added to pVideoRaster before checking the possible */
125: /* modification of $ff8205/07/09 in Video_CopyScreenLine. */
126: /* 2008/03/14 [NP] Rename ScanLineSkip to LineWidth (more consistent with STE docs). */
127: /* On STE, better support for writing to video counter, line width and */
128: /* hw scroll. If write to register occurs just at the start of a new line */
129: /* but before Video_EndHBL (because the move started just before cycle 512)*/
130: /* then the new value should not be set immediatly but stored and set */
131: /* during Video_EndHBL (fix the bump mapping part in Pacemaker by Paradox).*/
1.1.1.12 root 132: /* 2008/03/25 [NP] On STE, when bSteBorderFlag is true, we should add 16 pixels to the left*/
133: /* border, not to the right one (Just Musix 2 Menu by DHS). */
134: /* 2008/03/26 [NP] Clear the rest of the border when using border tricks left+2, left+8 */
135: /* or right-106 (remove garbage pixels when hatari resolution changes). */
136: /* 2008/03/29 [NP] Function Video_SetSystemTimings to use different values depending on */
137: /* the machine type. On STE, top/bottom border removal can occur at cycle */
138: /* 500 instead of 504 on STF. */
1.1.1.13 root 139: /* 2008/04/02 [NP] Correct a rare case in Video_Sync_WriteByte at the end of line 33 : */
140: /* nStartHBL was set to 33 instead of 64, which gave a wrong address in */
141: /* Video_CalculateAddress. */
142: /* 2008/04/04 [NP] The value of RestartVideoCounterCycle is slightly different between */
143: /* an STF and an STE. */
144: /* 2008/04/05 [NP] The value of VblVideoCycleOffset is different of 4 cycles between */
145: /* STF and STE (fix end part in Pacemaker by Paradox). */
146: /* 2008/04/09 [NP] Preliminary support for lines using different frequencies in the same */
147: /* screen. In Video_InterruptHandler_EndLine, if the current freq is 50 Hz,*/
148: /* then next int should be scheduled in 512 cycles ; if freq is 60 Hz, */
149: /* next int should be in 508 cycles (used by timer B event count mode). */
150: /* 2008/04/10 [NP] Update LineEndCycle after changing freq to 50 or 60 Hz. */
151: /* Set EndLine interrupt to happen 28 cycles after LineEndCycle. This way */
152: /* Timer B occurs at cycle 404 in 50 Hz, or cycle 400 in 60 Hz (improve */
153: /* flickering bottom border in B.I.G. Demo screen 1). */
154: /* 2008/04/12 [NP] In the case of a 'right-2' line, we should not change the EndLine's int */
155: /* position when switching back to 50 Hz ; the int should happen at */
156: /* position LINE_END_CYCLE_60 + 28 (Anomaly Demo main menu). */
157: /* 2008/05/31 [NP] Ignore consecutives writes of the same value in the freq/res register. */
158: /* Only the 1st write matters, else this could confuse the code to remove */
159: /* top/bottom border (fix OSZI.PRG demo by ULM). */
160: /* 2008/06/07 [NP] In Video_SetHBLPaletteMaskPointers, use LineStartCycle instead of the */
161: /* 50 Hz constant SCREEN_START_CYCLE. */
162: /* Rename SCREEN_START_HBL_xxx to VIDEO_START_HBL_xxx. */
163: /* Rename SCREEN_END_HBL_xxx to VIDEO_END_HBL_xxx. */
164: /* Rename SCREEN_HEIGHT_HBL_xxx to VIDEO_HEIGHT_HBL_xxx. */
165: /* Use VIDEO_HEIGHT_BOTTOM_50HZ instead of OVERSCAN_BOTTOM. */
166: /* 2008/06/16 [NP] When Hatari is configured to display the screen's borders, 274 lines */
167: /* will be rendered on screen, but if the shifter is in 60 Hz, the last */
168: /* 16 lines will never be used, which can leave some bad pixels on */
169: /* screen. We clear the remaining lines before calling 'Screen_Draw'. */
170: /* (in FNIL by Delta Force, fix flickering gfx in the bottom border of the */
171: /* F2 screen : last 16 lines were the ones from the menu where bottom */
172: /* border was removed ). */
173: /* 2008/06/26 [NP] Improve STE scrolling : handle $ff8264 (no prefetch) and $ff8265 */
174: /* (prefetch). See Video_HorScroll_Write for details on both registers. */
175: /* More generic support for starting display 16 pixels earlier on STE */
176: /* by writing to $ff8265 and settting $ff8264=0 just after. */
177: /* (fix Digiworld 2 by ICE, which uses $ff8264 for horizontal scroll). */
178: /* 2008/07/07 [NP] Ignore other 50/60 Hz switches once the right border was removed, keep */
179: /* the timer B to occur at pos 460+28 (fix Oxygene screen in Transbeauce 2)*/
180: /* 2008/07/14 [NP] When removing only left border in 60Hz, line size is 26+158 bytes */
181: /* instead of 26+160 bytes in 50 Hz (HigResMode demo by Paradox). */
182: /* 2008/07/19 [NP] If $ff8260==3 (which is not a valid resolution mode), we use 0 instead */
183: /* (low res) (fix Omegakul screen in old Omega Demo from 1988). */
184: /* 2008/09/05 [NP] No need to test 60/50 switch if HblCounterVideo < nStartHBL (display */
185: /* has not started yet). */
186: /* 2008/09/25 [NP] Use nLastVisibleHbl to store the number of the last hbl line that should*/
187: /* be copied to the emulator's screen buffer. */
188: /* On STE, allow to change immediatly video address, hw scroll and */
189: /* linewidth when nHBL>=nLastVisibleHbl instead of nHBL>=nEndHBL */
190: /* (fix Power Rise / Xtrem D demo). */
191: /* 2008/11/15 [NP] For STE registers, add in the TRACE call if the write is delayed or */
192: /* not (linewidth, hwscroll, video address). */
193: /* On STE, allow to change linewdith, hwscroll and video address with no */
194: /* delay as soon as nHBL >= nEndHBL (revert previous changes). Power Rise */
195: /* is still working due to NewHWScrollCount=-1 when setting immediate */
196: /* hwscroll. Fix regression in Braindamage. */
1.1.1.14 root 197: /* 2008/11/29 [NP] Increment jitter's index for HBL and VBL each time a possible interrupt */
198: /* occurs. Each interrupt can have a jitter between 0, 4 and 8 cycles ; the*/
199: /* jitter follows a predefined pattern of 5 values. The HBL and the VBL */
200: /* have their own pattern. See InterruptAddJitter() in uae-cpu/newcpu.c */
201: /* (fix Fullscreen tunnel in Suretrip 49% by Checkpoint and digi sound in */
202: /* Swedish New Year's TCB screen). */
203: /* 2008/12/10 [NP] Enhance support for 0 byte line. The 60/50 Hz switch can happen at */
204: /* cycles 56/64, but also at 58/66 (because access to $ff820a doesn't */
205: /* require to be on a 4 cycles boundary). As hatari doesn't handle */
206: /* multiple of 2 cycles, we allow cycles 56/64 and 60/68 (fix nosync.tos */
207: /* that uses the STOP instruction to produce a 0 byte line on the first */
208: /* displayed line (found on atari-forum.com)). */
1.1.1.17 root 209: /* 2008/12/26 [NP] When reading $ff8260 on STF, set unused bits to 1 instead of 0 */
1.1.1.14 root 210: /* (fix wrong TOS resolution in Awesome Menu Disk 16). */
211: /* Set unused bit to 1 when reading $ff820a too. */
212: /* 2009/01/16 [NP] Handle special case when writing only in upper byte of a color reg. */
213: /* 2009/01/21 [NP] Implement STE horizontal scroll for medium res (fixes cool_ste.prg). */
214: /* Take the current res into account in Video_CopyScreenLineColor to */
1.1.1.15 root 215: /* allow mixing low/med res with horizontal scroll on STE. */
216: /* 2009/01/24 [NP] Better detection of 'right-2' when freq is changed to 60 Hz and */
217: /* restored to 50 after the end of the current line (fixes games menu on */
218: /* BBC compil 10). */
219: /* 2009/01/31 [NP] Handle a rare case where 'move.b #8,$fffa1f' to start the timer B is */
220: /* done just a few cycles before the actual signal for end of line. In that*/
221: /* case we must ensure that the write was really effective before the end */
222: /* of line (else no interrupt should be made) (fix Pompey Pirate Menu #57).*/
223: /* 2009/02/08 [NP] Handle special case for simultaneous HBL exceptions (fixes flickering in*/
224: /* Monster Business and Super Monaco GP). */
225: /* 2009/02/25 [NP] Ignore other 50/60 Hz switches after display was stopped in the middle */
226: /* of the line with a hi/lo switch. Correct missing end of line timer B */
227: /* interrupt in that case (fix flickering Dragon Ball part in Blood disk 2 */
228: /* by Holocaust). */
229: /* 2008/02/02 [NP] Added 0 byte line detection in STE mode when switching hi/lo res */
230: /* at position 32 (Lemmings screen in Nostalgic-o-demo). */
231: /* 2009/03/28 [NP] Depending on bit 3 of MFP's AER, timer B will count end of line events */
232: /* (bit=0) or start of line events (bit=1) (fix Seven Gates Of Jambala). */
233: /* 2009/04/02 [NP] Add another method to obtain a 0 byte line, by switching to hi/lo res */
234: /* at position 500/508 (fix the game No Buddies Land). */
235: /* 2009/04/xx [NP] Rewrite of many parts : add SHIFTER_FRAME structure, better accuracy */
236: /* when mixing 50/60 Hz lines and reading $ff8209, better emulation of */
237: /* HBL and Timer B position when changing freq/res, better emulation of */
238: /* freq changes for top/bottom/right borders. */
239: /* 2009/07/16 [NP] In Video_SetHBLPaletteMaskPointers, if LineCycle>460 we consider the */
240: /* color's change should be applied to next line (used when spec512 mode */
241: /* if off). */
1.1.1.16 root 242: /* 2009/10/31 [NP] Depending on the overscan mode, the displayed lines must be shifted */
243: /* left or right (fix Spec 512 images in the Overscan Demos, fix pixels */
244: /* alignment in screens mixing normal lines and overscan lines). */
245: /* 2009/12/02 [NP] If we switch hi/lo around position 464 (as in Enchanted Lands) and */
246: /* right border was not removed, then we get an empty line on the next */
247: /* HBL (fix Pax Plax Parralax in Beyond by Kruz). */
248: /* 2009/12/06 [NP] Add support for STE 224 bytes overscan without stabiliser by switching */
249: /* hi/lo at cycle 504/4 to remove left border (fix More Or Less Zero and */
250: /* Cernit Trandafir by DHS, as well as Save The Earth by Defence Force). */
251: /* 2009/12/13 [NP] Improve STE 224 bytes lines : correctly set leftmost 16 pixels to color */
252: /* 0 and correct small glitches when combined with hscroll ($ff8264). */
253: /* 2009/12/13 [NP] Line scrolling caused by hi/lo switch (STF_PixelScroll) should be */
254: /* applied after STE's hardware scrolling, else in overscan 4 color 0 */
255: /* pixels will appear in the right border (because overscan shift the */
256: /* whole displayed area 4 pixels to the left) (fix possible regression on */
257: /* STE introduced on 2009/10/31). */
258: /* 2010/01/10 [NP] In Video_CalculateAddress, take bSteBorderFlag into account (+16 pixels */
259: /* in left border on STE). */
260: /* 2010/01/10 [NP] In Video_CalculateAddress, take HWScrollPrefetch into account (shifter */
261: /* starts 16 pixels earlier) (fix EPSS demo by Unit 17). */
262: /* 2010/02/05 [NP] In Video_CalculateAddress, take STE's LineWidth into account when */
263: /* display is disabled in the right border (fix flickering in Utopos). */
264: /* 2010/02/07 [NP] Better support for modifying $ff8205/07/09 while display is on */
265: /* (fix EPSS demo by Unit 17). */
266: /* 2010/04/12 [NP] Improve timings when writing to $ff8205/07/09 when hscroll is used, */
267: /* using Video_GetMMUStartCycle (fix Pacemaker's Bump Part by Paradox). */
268: /* 2010/05/02 [NP] In Video_ConvertPosition, handle the case where we read the position */
269: /* between the last HBL and the start of the next VBL. During 64 cycles */
270: /* FrameCycles can be >= CYCLES_PER_FRAME (harmless fix, only useful when */
271: /* using --trace to get correct positions in the logs). */
272: /* 2010/05/04 [NP] Improve Video_ConvertPosition, use CyclesPerVBL instead of evaluating */
273: /* CYCLES_PER_FRAME (whose value could have changed this the start of the */
274: /* VBL). */
275: /* 2010/05/15 [NP] In Video_StartInterrupts() when running in monochrome (224 cycles per */
276: /* line), the VBL could sometimes be delayed by 160 cycles (divs) and */
277: /* hbl/timer B interrupts for line 0 were not called, which could cause an */
278: /* assert/crash in Hatari when setting timer B on line 2. */
279: /* If we detect VBL was delayed too much, we add hbl/timer b in the next */
280: /* 4 cycles. */
1.1.1.17 root 281: /* 2010/07/05 [NP] When removing left border, allow up to 32 cycles between hi and low */
282: /* res switching (fix Megabeer by Invizibles). */
283: /* 2010/11/01 [NP] On STE, the 224 bytes overscan will shift the screen 8 pixels to the */
284: /* left. */
285: /* For 230 bytes overscan, handle scrolling prefetching when computing */
286: /* pVideoRaster for the next line. */
287: /* 2010/12/12 [NP] In Video_CopyScreenLineColor, use pVideoRasterEndLine to improve */
288: /* STE's horizontal scrolling for any line's length (160, 224, 230, ...). */
289: /* Fix the last 16 pixels for 224 bytes overscan (More Or Less Zero and */
290: /* Cernit Trandafir by DHS, Save The Earth by Defence Force). */
291: /* 2011/04/03 [NP] Call DmaSnd_HBL_Update() on each HBL to handle programs that modify */
292: /* the samples data while those data are played by the DMA sound. */
293: /* (fixes the game Power Up Plus and the demo Mental Hangover). */
1.1.1.18 root 294: /* 2011/07/30 [NP] Add blank line detection in STF mode when switching 60/50 Hz at cycle */
295: /* 28. The shifter will still read bytes and border removal is possible, */
296: /* but the line will be blank (we use color 0 for now, but the line should */
297: /* be black). */
298: /* (fix spectrum 512 part in Overscan Demo and shforstv by Paulo Simoes */
299: /* by removing "parasite" pixels on the 1st line). */
300: /* 2011/11/17 [NP] Improve timings used for the 0 byte line when switching hi/lo at the */
301: /* end of the line. The hi/lo switch can be at 496/508 or 500/508 */
302: /* (fix NGC screen in Delirious Demo IV). */
303: /* 2011/11/18 [NP] Add support for another method to do 4 pixel hardware scrolling by doing*/
304: /* a med/lo switch after the hi/lo switch to remove left border */
305: /* (fix NGC screen in Delirious Demo IV). */
306: /* 2011/11/19 [NP] The 0 byte line obtained by switching hi/lo at the end of the line has */
307: /* no video signal at all (blank). In that case, the screen is shifted one */
308: /* line down, and bottom border removal will happen one line later too */
309: /* (fix NGC screen in Delirious Demo IV). */
1.1.1.19 root 310: /* 2012/01/11 [NP] Don't remove left border when the hi/lo switch is made at cycle >= 12 */
311: /* (fix 'Kill The Beast 2' in the Vodka Demo) */
1.1.1.20! root 312: /* 2012/05/19 [NP] Allow bottom border to be removed when switch back to 50 Hz is made at */
! 313: /* cycle 504 and more (instead of 508 and more). Same for top border */
! 314: /* (fix 'Musical Wonders 1990' by Offbeat). */
1.1.1.11 root 315:
1.1.1.12 root 316:
1.1.1.15 root 317: const char Video_fileid[] = "Hatari video.c : " __DATE__ " " __TIME__;
1.1 root 318:
1.1.1.7 root 319: #include <SDL_endian.h>
1.1.1.4 root 320:
1.1 root 321: #include "main.h"
1.1.1.6 root 322: #include "configuration.h"
1.1.1.10 root 323: #include "cycles.h"
1.1 root 324: #include "fdc.h"
1.1.1.16 root 325: #include "cycInt.h"
1.1.1.8 root 326: #include "ioMem.h"
1.1.1.4 root 327: #include "keymap.h"
1.1 root 328: #include "m68000.h"
329: #include "memorySnapShot.h"
330: #include "mfp.h"
1.1.1.11 root 331: #include "printer.h"
1.1 root 332: #include "screen.h"
1.1.1.13 root 333: #include "screenSnapShot.h"
1.1 root 334: #include "shortcut.h"
335: #include "sound.h"
1.1.1.17 root 336: #include "dmaSnd.h"
1.1 root 337: #include "spec512.h"
338: #include "stMemory.h"
339: #include "vdi.h"
340: #include "video.h"
341: #include "ymFormat.h"
1.1.1.11 root 342: #include "falcon/videl.h"
343: #include "falcon/hostscreen.h"
1.1.1.16 root 344: #include "avi_record.h"
1.1.1.4 root 345:
346:
1.1.1.11 root 347: /* The border's mask allows to keep track of all the border tricks */
348: /* applied to one video line. The masks for all lines are stored in the array */
349: /* ScreenBorderMask[]. */
350: /* - bits 0-15 are used to describe the border tricks. */
351: /* - bits 20-23 are used to store the bytes offset to apply for some particular */
1.1.1.15 root 352: /* tricks (for example med res overscan can shift display by 0 or 2 bytes */
353: /* depending on when the switch to med res is done after removing the left */
1.1.1.11 root 354: /* border). */
355:
1.1.1.14 root 356: #define BORDERMASK_NONE 0x00 /* no effect on this line */
1.1.1.11 root 357: #define BORDERMASK_LEFT_OFF 0x01 /* removal of left border with hi/lo res switch -> +26 bytes */
358: #define BORDERMASK_LEFT_PLUS_2 0x02 /* line starts earlier in 60 Hz -> +2 bytes */
359: #define BORDERMASK_STOP_MIDDLE 0x04 /* line ends in hires at cycle 160 -> -106 bytes */
360: #define BORDERMASK_RIGHT_MINUS_2 0x08 /* line ends earlier in 60 Hz -> -2 bytes */
361: #define BORDERMASK_RIGHT_OFF 0x10 /* removal of right border -> +44 bytes */
362: #define BORDERMASK_RIGHT_OFF_FULL 0x20 /* full removal of right border and next left border -> +22 bytes */
1.1.1.15 root 363: #define BORDERMASK_OVERSCAN_MED_RES 0x40 /* some borders were removed and the line is in med res instead of low res */
1.1.1.11 root 364: #define BORDERMASK_EMPTY_LINE 0x80 /* 60/50 Hz switch prevents the line to start, video counter is not incremented */
1.1.1.15 root 365: #define BORDERMASK_LEFT_OFF_MED 0x100 /* removal of left border with hi/med res switch -> +26 bytes (for 4 pixels hardware scrolling) */
1.1.1.16 root 366: #define BORDERMASK_LEFT_OFF_2_STE 0x200 /* shorter removal of left border with hi/lo res switch -> +20 bytes (STE only)*/
1.1.1.18 root 367: #define BORDERMASK_BLANK_LINE 0x400 /* 60/50 Hz switch blanks the rest of the line, but video counter is still incremented */
1.1.1.11 root 368:
369:
370: int STRes = ST_LOW_RES; /* current ST resolution */
371: int TTRes; /* TT shifter resolution mode */
1.1.1.13 root 372: int nFrameSkips; /* speed up by skipping video frames */
1.1.1.9 root 373:
1.1.1.13 root 374: bool bUseHighRes; /* Use hi-res (ie Mono monitor) */
1.1 root 375: int OverscanMode; /* OVERSCANMODE_xxxx for current display frame */
1.1.1.17 root 376: Uint16 HBLPalettes[HBL_PALETTE_LINES]; /* 1x16 colour palette per screen line, +1 line just incase write after line 200 */
1.1.1.8 root 377: Uint16 *pHBLPalettes; /* Pointer to current palette lists, one per HBL */
1.1.1.17 root 378: Uint32 HBLPaletteMasks[HBL_PALETTE_MASKS]; /* Bit mask of palette colours changes, top bit set is resolution change */
1.1.1.9 root 379: Uint32 *pHBLPaletteMasks;
1.1.1.15 root 380: int nScreenRefreshRate = 50; /* 50 or 60 Hz in color, 71 Hz in mono */
1.1.1.8 root 381: Uint32 VideoBase; /* Base address in ST Ram for screen (read on each VBL) */
1.1.1.9 root 382:
1.1.1.11 root 383: int nVBLs; /* VBL Counter */
384: int nHBL; /* HBL line */
385: int nStartHBL; /* Start HBL for visible screen */
386: int nEndHBL; /* End HBL for visible screen */
1.1.1.10 root 387: int nScanlinesPerFrame = 313; /* Number of scan lines per frame */
388: int nCyclesPerLine = 512; /* Cycles per horizontal line scan */
1.1.1.13 root 389: static int nFirstVisibleHbl = FIRST_VISIBLE_HBL_50HZ; /* The first line of the ST screen that is copied to the PC screen buffer */
390: static int nLastVisibleHbl = FIRST_VISIBLE_HBL_50HZ+NUM_VISIBLE_LINES; /* The last line of the ST screen that is copied to the PC screen buffer */
1.1.1.16 root 391: static int CyclesPerVBL = 313*512; /* Number of cycles per VBL */
1.1.1.10 root 392:
1.1.1.13 root 393: static Uint8 HWScrollCount; /* HW scroll pixel offset, STE only (0...15) */
394: static int NewHWScrollCount = -1; /* Used in STE mode when writing to the scrolling registers $ff8264/65 */
395: static Uint8 HWScrollPrefetch; /* 0 when scrolling with $ff8264, 1 when scrolling with $ff8265 */
396: static int NewHWScrollPrefetch = -1; /* Used in STE mode when writing to the scrolling registers $ff8264/65 */
397: static Uint8 LineWidth; /* Scan line width add, STe only (words, minus 1) */
398: static int NewLineWidth = -1; /* Used in STE mode when writing to the line width register $ff820f */
1.1.1.16 root 399: static int VideoCounterDelayedOffset = 0; /* Used in STE mode when changing video counter while display is on */
400: static Uint8 *pVideoRasterDelayed = NULL; /* Used in STE mode when changing video counter while display is off in the right border */
1.1.1.13 root 401: static Uint8 *pVideoRaster; /* Pointer to Video raster, after VideoBase in PC address space. Use to copy data on HBL */
1.1.1.15 root 402: static bool bSteBorderFlag; /* true when screen width has been switched to 336 (e.g. in Obsession) */
1.1.1.13 root 403: static int NewSteBorderFlag = -1; /* New value for next line */
404: static bool bTTColorsSync, bTTColorsSTSync; /* whether TT colors need convertion to SDL */
1.1 root 405:
1.1.1.17 root 406: static int LastCycleScroll8264; /* value of Cycles_GetCounterOnWriteAccess last time ff8264 was set for the current VBL */
407: static int LastCycleScroll8265; /* value of Cycles_GetCounterOnWriteAccess last time ff8265 was set for the current VBL */
408:
409: static int LineRemoveTopCycle = LINE_REMOVE_TOP_CYCLE_STF;
410: static int LineRemoveBottomCycle = LINE_REMOVE_BOTTOM_CYCLE_STF;
411: static int RestartVideoCounterCycle = RESTART_VIDEO_COUNTER_CYCLE_STF;
412: static int VblVideoCycleOffset = VBL_VIDEO_CYCLE_OFFSET_STF;
1.1.1.13 root 413:
1.1.1.15 root 414: int LastCycleHblException; /* value of Cycles_GetCounter last time a level 2 interrupt was executed by the CPU */
415:
1.1.1.13 root 416: int LineTimerBCycle = LINE_END_CYCLE_50 + TIMERB_VIDEO_CYCLE_OFFSET; /* position of the Timer B interrupt on active lines */
1.1.1.15 root 417: int TimerBEventCountCycleStart = -1; /* value of Cycles_GetCounterOnWriteAccess last time timer B was started for the current VBL */
1.1 root 418:
1.1.1.20! root 419: int HblJitterIndex = 0;
! 420: const int HblJitterArray[] = {
! 421: 8,4,4,0,0 /* measured on STF */
! 422: };
! 423: const int HblJitterArrayPending[] = {
! 424: 4,4,4,4,4 // { 8,8,12,8,12 }; /* measured on STF, not always accurate */
! 425: };
! 426: int VblJitterIndex = 0;
! 427: const int VblJitterArray[] = {
! 428: 8,0,4,0,4 /* measured on STF */
! 429: };
! 430: const int VblJitterArrayPending[] = {
! 431: 8,8,12,8,12 /* not verified on STF, use the same as HBL */
! 432: };
1.1.1.14 root 433:
1.1.1.18 root 434: int BlankLines = 0; /* Number of empty line with no signal (by switching hi/lo near cycles 500) */
1.1.1.12 root 435:
1.1.1.15 root 436:
437: typedef struct
438: {
439: int VBL; /* VBL for this Pos (or -1 if Pos not defined for now) */
440: int FrameCycles; /* Number of cycles since this VBL */
441: int HBL; /* HBL in the VBL */
442: int LineCycles; /* cycles in the HBL */
443: } SHIFTER_POS;
444:
445:
446: typedef struct
447: {
448: int StartCycle; /* first cycle of this line, as returned by Cycles_GetCounter */
449:
450: Uint32 BorderMask; /* borders' states for this line */
451: int DisplayPixelShift; /* number of pixels to shift the whole line (<0 shift to the left, >0 shift to the right) */
452: /* On STF, this is obtained when switching hi/med for a variable number of cycles, */
453: /* but just removing left border will shift the line too. */
454:
455: int DisplayStartCycle; /* cycle where display starts for this line (0-512) : 0, 52 or 56 */
456: int DisplayEndCycle; /* cycle where display ends for this line (0-512) : 0, 160, 372, 376, 460 or 512 */
457: int DisplayBytes; /* how many bytes to display for this line */
458:
459: } SHIFTER_LINE;
460:
461:
462: typedef struct
463: {
464: int HBL_CyclePos; /* cycle position for the HBL int (depends on freq/res) */
465: int TimerB_CyclePos; /* cycle position for the Timer B int (depends on freq/res) */
466:
467: int Freq; /* value of ff820a & 2, or -1 if not set */
468: int Res; /* value of ff8260 & 3, or -1 if not set */
469: SHIFTER_POS FreqPos50; /* position of latest freq change to 50 Hz*/
470: SHIFTER_POS FreqPos60; /* position of latest freq change to 60 Hz*/
471: SHIFTER_POS ResPosLo; /* position of latest change to low res */
472: SHIFTER_POS ResPosMed; /* position of latest change to med res */
473: SHIFTER_POS ResPosHi; /* position of latest change to high res */
474:
475: SHIFTER_POS Scroll8264Pos; /* position of latest write to $ff8264 */
476: SHIFTER_POS Scroll8265Pos; /* position of latest write to $ff8265 */
477:
478: SHIFTER_LINE ShifterLines[ MAX_SCANLINES_PER_FRAME ];
479: } SHIFTER_FRAME;
480:
481:
482: SHIFTER_FRAME ShifterFrame;
483:
484:
485:
486: /*--------------------------------------------------------------*/
487: /* Local functions prototypes */
488: /*--------------------------------------------------------------*/
489:
490: static void Video_SetSystemTimings ( void );
491:
492: static Uint32 Video_CalculateAddress ( void );
1.1.1.16 root 493: static int Video_GetMMUStartCycle ( int DisplayStartCycle );
1.1.1.15 root 494: static void Video_WriteToShifter ( Uint8 Res );
495: static void Video_Sync_SetDefaultStartEnd ( Uint8 Freq , int HblCounterVideo , int LineCycles );
496:
497: static int Video_HBL_GetPos ( void );
1.1.1.18 root 498: static int Video_TimerB_GetDefaultPos ( void );
1.1.1.15 root 499: static void Video_EndHBL ( void );
500: static void Video_StartHBL ( void );
501:
502: static void Video_StoreFirstLinePalette(void);
503: static void Video_StoreResolution(int y);
504: static void Video_CopyScreenLineMono(void);
505: static void Video_CopyScreenLineColor(void);
506: static void Video_CopyVDIScreen(void);
507: static void Video_SetHBLPaletteMaskPointers(void);
508:
509: static void Video_UpdateTTPalette(int bpp);
510: static void Video_DrawScreen(void);
511:
512: static void Video_ResetShifterTimings(void);
513: static void Video_InitShifterLines(void);
514: static void Video_ClearOnVBL(void);
515:
516: static void Video_AddInterrupt ( int Pos , interrupt_id Handler );
517: static void Video_AddInterruptHBL ( int Pos );
518:
519: static void Video_ColorReg_WriteWord(Uint32 addr);
520:
521:
1.1 root 522: /*-----------------------------------------------------------------------*/
1.1.1.11 root 523: /**
524: * Save/Restore snapshot of local variables('MemorySnapShot_Store' handles type)
525: */
1.1.1.13 root 526: void Video_MemorySnapShot_Capture(bool bSave)
1.1 root 527: {
1.1.1.11 root 528: /* Save/Restore details */
529: MemorySnapShot_Store(&TTRes, sizeof(TTRes));
530: MemorySnapShot_Store(&bUseHighRes, sizeof(bUseHighRes));
531: MemorySnapShot_Store(&nVBLs, sizeof(nVBLs));
532: MemorySnapShot_Store(&nHBL, sizeof(nHBL));
533: MemorySnapShot_Store(&nStartHBL, sizeof(nStartHBL));
534: MemorySnapShot_Store(&nEndHBL, sizeof(nEndHBL));
535: MemorySnapShot_Store(&OverscanMode, sizeof(OverscanMode));
536: MemorySnapShot_Store(HBLPalettes, sizeof(HBLPalettes));
537: MemorySnapShot_Store(HBLPaletteMasks, sizeof(HBLPaletteMasks));
538: MemorySnapShot_Store(&VideoBase, sizeof(VideoBase));
539: MemorySnapShot_Store(&LineWidth, sizeof(LineWidth));
540: MemorySnapShot_Store(&HWScrollCount, sizeof(HWScrollCount));
541: MemorySnapShot_Store(&pVideoRaster, sizeof(pVideoRaster));
542: MemorySnapShot_Store(&nScanlinesPerFrame, sizeof(nScanlinesPerFrame));
543: MemorySnapShot_Store(&nCyclesPerLine, sizeof(nCyclesPerLine));
544: MemorySnapShot_Store(&nFirstVisibleHbl, sizeof(nFirstVisibleHbl));
545: MemorySnapShot_Store(&bSteBorderFlag, sizeof(bSteBorderFlag));
1.1.1.14 root 546: MemorySnapShot_Store(&HblJitterIndex, sizeof(HblJitterIndex));
547: MemorySnapShot_Store(&VblJitterIndex, sizeof(VblJitterIndex));
1.1.1.15 root 548: MemorySnapShot_Store(&ShifterFrame, sizeof(ShifterFrame));
549: }
550:
551:
552: /*-----------------------------------------------------------------------*/
553: /**
554: * Reset video chip
555: */
556: void Video_Reset(void)
557: {
558: /* NOTE! Must reset all of these register type things here!!!! */
1.1.1.19 root 559: Video_Reset_Glue();
1.1.1.15 root 560:
561: /* Set system specific timings */
562: Video_SetSystemTimings();
563:
564: /* Reset VBL counter */
565: nVBLs = 0;
566: /* Reset addresses */
567: VideoBase = 0L;
568:
569: /* Reset shifter's state variables */
570: ShifterFrame.Freq = -1;
571: ShifterFrame.Res = -1;
572: ShifterFrame.FreqPos50.VBL = -1;
573: ShifterFrame.FreqPos60.VBL = -1;
574: ShifterFrame.ResPosLo.VBL = -1;
575: ShifterFrame.ResPosMed.VBL = -1;
576: ShifterFrame.ResPosHi.VBL = -1;
577: ShifterFrame.Scroll8264Pos.VBL = -1;
578: ShifterFrame.Scroll8265Pos.VBL = -1;
579:
580: Video_InitShifterLines ();
581:
582: /* Reset STE screen variables */
583: LineWidth = 0;
584: HWScrollCount = 0;
585: bSteBorderFlag = false;
586:
587: NewLineWidth = -1; /* cancel pending modifications set before the reset */
588: NewHWScrollCount = -1;
589:
1.1.1.16 root 590: VideoCounterDelayedOffset = 0;
591: pVideoRasterDelayed = NULL;
592:
1.1.1.15 root 593: /* Reset jitter indexes */
594: HblJitterIndex = 0;
595: VblJitterIndex = 0;
596:
597: /* Clear framecycles counter */
598: Cycles_SetCounter(CYCLES_COUNTER_VIDEO, 0);
599:
600: /* Clear ready for new VBL */
601: Video_ClearOnVBL();
602: }
603:
604:
605: /*-----------------------------------------------------------------------*/
606: /**
607: * Reset the GLUE chip responsible for generating the H/V sync signals.
608: * When the 68000 RESET instruction is called, frequency and resolution
609: * should be reset to 0.
610: */
611: void Video_Reset_Glue(void)
612: {
1.1.1.20! root 613: Uint8 VideoShifterByte;
! 614:
1.1.1.19 root 615: IoMem_WriteByte(0xff820a,0); /* Video frequency */
616:
617: /* Are we in high-res? */
618: if (bUseHighRes)
619: VideoShifterByte = ST_HIGH_RES; /* Mono monitor */
620: else
621: VideoShifterByte = ST_LOW_RES;
622: if (bUseVDIRes)
623: VideoShifterByte = VDIRes;
624:
625: IoMem_WriteByte(0xff8260, VideoShifterByte);
1.1 root 626: }
627:
1.1.1.8 root 628:
1.1 root 629: /*-----------------------------------------------------------------------*/
1.1.1.12 root 630: /*
631: * Set specific video timings, depending on the system being emulated.
632: */
1.1.1.15 root 633: static void Video_SetSystemTimings(void)
1.1.1.12 root 634: {
1.1.1.19 root 635: if ( ConfigureParams.System.nMachineType == MACHINE_ST )
636: {
637: LineRemoveTopCycle = LINE_REMOVE_TOP_CYCLE_STF;
638: LineRemoveBottomCycle = LINE_REMOVE_BOTTOM_CYCLE_STF;
639: RestartVideoCounterCycle = RESTART_VIDEO_COUNTER_CYCLE_STF;
640: VblVideoCycleOffset = VBL_VIDEO_CYCLE_OFFSET_STF;
641: }
1.1.1.20! root 642: else /* STE, TT */
1.1.1.19 root 643: {
644: LineRemoveTopCycle = LINE_REMOVE_TOP_CYCLE_STE;
645: LineRemoveBottomCycle = LINE_REMOVE_BOTTOM_CYCLE_STE;
646: RestartVideoCounterCycle = RESTART_VIDEO_COUNTER_CYCLE_STE;
647: VblVideoCycleOffset = VBL_VIDEO_CYCLE_OFFSET_STE;
648: }
1.1.1.12 root 649: }
650:
651:
652: /*-----------------------------------------------------------------------*/
1.1.1.11 root 653: /**
1.1.1.15 root 654: * Convert the elapsed number of cycles since the start of the VBL
655: * into the corresponding HBL number and the cycle position in the current
656: * HBL. We use the starting cycle position of the closest HBL to compute
657: * the cycle position on the line (this allows to mix lines with different
658: * values for nCyclesPerLine).
659: * We can have 2 cases on the limit where the real video line count can be
660: * different from nHBL :
661: * - when reading video address between cycle 0 and 12, LineCycle will be <0,
662: * so we need to use the data from line nHBL-1
663: * - if LineCycle >= nCyclesPerLine, this means the HBL int was not processed
664: * yet, so the video line number is in fact nHBL+1
665: */
666:
667: void Video_ConvertPosition ( int FrameCycles , int *pHBL , int *pLineCycles )
668: {
1.1.1.16 root 669: if ( 0 && FrameCycles >= CyclesPerVBL ) /* rare case between end of last hbl and start of next VBL (during 64 cycles) */
1.1.1.15 root 670: {
1.1.1.16 root 671: *pHBL = ( FrameCycles - CyclesPerVBL ) / nCyclesPerLine;
672: *pLineCycles = ( FrameCycles - CyclesPerVBL ) % nCyclesPerLine;
673: //fprintf ( stderr , "out of vbl FrameCycles %d CyclesPerVBL %d nHBL=%d %d %d\n" , FrameCycles , CyclesPerVBL, nHBL , *pHBL , *pLineCycles );
1.1.1.15 root 674: }
1.1.1.16 root 675:
676: else /* most common case */
1.1.1.15 root 677: {
1.1.1.16 root 678: *pHBL = nHBL;
679: *pLineCycles = FrameCycles - ShifterFrame.ShifterLines[ nHBL ].StartCycle;
1.1.1.15 root 680:
1.1.1.16 root 681: if ( *pLineCycles < 0 ) /* reading from the previous video line */
682: {
683: *pHBL = nHBL-1;
684: *pLineCycles = FrameCycles - ShifterFrame.ShifterLines[ nHBL-1 ].StartCycle;
685: }
686:
687: else if ( *pLineCycles >= nCyclesPerLine ) /* reading on the next line, but HBL int was delayed */
688: {
689: *pHBL = nHBL+1;
690: *pLineCycles -= nCyclesPerLine;
691: }
692: }
1.1.1.15 root 693:
694: if ( *pLineCycles < 0 )
695: fprintf ( stderr , "bug nHBL=%d %d %d\n" , nHBL , *pHBL , *pLineCycles );
696:
697: //if ( ( *pHBL != FrameCycles / nCyclesPerLine ) || ( *pLineCycles != FrameCycles % nCyclesPerLine ) )
698: // LOG_TRACE ( TRACE_VIDEO_ADDR , "conv pos %d %d - %d %d\n" , *pHBL , FrameCycles / nCyclesPerLine , *pLineCycles , FrameCycles % nCyclesPerLine );
699: // LOG_TRACE ( TRACE_VIDEO_ADDR , "conv pos %d %d %d\n" , FrameCycles , *pHBL , *pLineCycles );
700: }
701:
702:
703: void Video_GetPosition ( int *pFrameCycles , int *pHBL , int *pLineCycles )
704: {
705: *pFrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO);
706: Video_ConvertPosition ( *pFrameCycles , pHBL , pLineCycles );
707: }
708:
709:
710: void Video_GetPosition_OnWriteAccess ( int *pFrameCycles , int *pHBL , int *pLineCycles )
711: {
712: *pFrameCycles = Cycles_GetCounterOnWriteAccess(CYCLES_COUNTER_VIDEO);
713: Video_ConvertPosition ( *pFrameCycles , pHBL , pLineCycles );
714: }
715:
716:
717: void Video_GetPosition_OnReadAccess ( int *pFrameCycles , int *pHBL , int *pLineCycles )
718: {
719: *pFrameCycles = Cycles_GetCounterOnReadAccess(CYCLES_COUNTER_VIDEO);
720: Video_ConvertPosition ( *pFrameCycles , pHBL , pLineCycles );
721: }
722:
723:
724: /*-----------------------------------------------------------------------*/
725: /**
1.1.1.11 root 726: * Calculate and return video address pointer.
727: */
1.1.1.15 root 728: static Uint32 Video_CalculateAddress ( void )
1.1 root 729: {
1.1.1.15 root 730: int FrameCycles, HblCounterVideo, LineCycles;
731: int X, NbBytes;
1.1.1.11 root 732: Uint32 VideoAddress; /* Address of video display in ST screen space */
733: int nSyncByte;
734: int LineBorderMask;
735: int PrevSize;
736: int CurSize;
1.1.1.15 root 737: int LineStartCycle , LineEndCycle;
1.1.1.11 root 738:
739: /* Find number of cycles passed during frame */
740: /* We need to substract '12' for correct video address calculation */
1.1.1.15 root 741: FrameCycles = Cycles_GetCounterOnReadAccess(CYCLES_COUNTER_VIDEO) - 12;
1.1.1.11 root 742:
743: /* Now find which pixel we are on (ignore left/right borders) */
1.1.1.15 root 744: Video_ConvertPosition ( FrameCycles , &HblCounterVideo , &LineCycles );
745: X = LineCycles;
1.1.1.11 root 746:
747: nSyncByte = IoMem_ReadByte(0xff820a) & 2; /* only keep bit 1 */
748: if (nSyncByte) /* 50 Hz */
749: {
750: LineStartCycle = LINE_START_CYCLE_50;
751: LineEndCycle = LINE_END_CYCLE_50;
752: }
753: else /* 60 Hz */
754: {
755: LineStartCycle = LINE_START_CYCLE_60;
756: LineEndCycle = LINE_END_CYCLE_60;
757: }
758:
759:
760: /* Top of screen is usually 63 lines from VBL in 50 Hz */
1.1.1.15 root 761: if ( HblCounterVideo < nStartHBL )
1.1.1.11 root 762: {
763: /* pVideoRaster was set during Video_ClearOnVBL using VideoBase */
764: /* and it could also have been modified on STE by writing to ff8205/07/09 */
1.1.1.15 root 765: /* So, we should not use ff8201/ff8203 which are reloaded in ff8205/ff8207 only once per VBL */
766: /* but use pVideoRaster - STRam instead to get current shifter video address */
1.1.1.11 root 767: VideoAddress = pVideoRaster - STRam;
768: }
769:
1.1.1.15 root 770: else if (FrameCycles > RestartVideoCounterCycle)
1.1.1.11 root 771: {
772: /* This is where ff8205/ff8207 are reloaded with the content of ff8201/ff8203 on a real ST */
773: /* (used in ULM DSOTS demos). VideoBase is also reloaded in Video_ClearOnVBL to be sure */
774: VideoBase = (Uint32)IoMem_ReadByte(0xff8201)<<16 | (Uint32)IoMem_ReadByte(0xff8203)<<8;
775: if (ConfigureParams.System.nMachineType != MACHINE_ST)
776: {
1.1.1.20! root 777: /* on STe 2 aligned, on TT 8 aligned. We do STe. */
1.1.1.11 root 778: VideoBase |= IoMem_ReadByte(0xff820d) & ~1;
779: }
780:
781: VideoAddress = VideoBase;
782: }
783:
784: else
785: {
786: VideoAddress = pVideoRaster - STRam; /* pVideoRaster is updated by Video_CopyScreenLineColor */
787:
788: /* Now find which pixel we are on (ignore left/right borders) */
1.1.1.15 root 789: // X = ( Cycles_GetCounterOnReadAccess(CYCLES_COUNTER_VIDEO) - 12 ) % nCyclesPerLine;
1.1.1.11 root 790:
791: /* Get real video line count (can be different from nHBL) */
1.1.1.15 root 792: // HblCounterVideo = ( Cycles_GetCounterOnReadAccess(CYCLES_COUNTER_VIDEO) - 12 ) / nCyclesPerLine;
1.1.1.11 root 793:
794: /* Correct the case when read overlaps end of line / start of next line */
795: /* Video_CopyScreenLineColor was not called yet to update VideoAddress */
796: /* so we need to determine the size of the previous line to get the */
797: /* correct value of VideoAddress. */
798: PrevSize = 0;
799: if ( HblCounterVideo < nHBL )
800: X = 0;
801: else if ( ( HblCounterVideo > nHBL ) /* HblCounterVideo = nHBL+1 */
802: && ( nHBL >= nStartHBL ) ) /* if nHBL was not visible, PrevSize = 0 */
803: {
1.1.1.15 root 804: LineBorderMask = ShifterFrame.ShifterLines[ HblCounterVideo-1 ].BorderMask; /* get border mask for nHBL */
1.1.1.11 root 805: PrevSize = BORDERBYTES_NORMAL; /* normal line */
806:
807: if (LineBorderMask & BORDERMASK_LEFT_OFF)
808: PrevSize += BORDERBYTES_LEFT;
809: else if (LineBorderMask & BORDERMASK_LEFT_PLUS_2)
810: PrevSize += 2;
811:
812: if (LineBorderMask & BORDERMASK_STOP_MIDDLE)
813: PrevSize -= 106;
814: else if (LineBorderMask & BORDERMASK_RIGHT_MINUS_2)
815: PrevSize -= 2;
816: else if (LineBorderMask & BORDERMASK_RIGHT_OFF)
817: PrevSize += BORDERBYTES_RIGHT;
818:
819: if (LineBorderMask & BORDERMASK_EMPTY_LINE)
820: PrevSize = 0;
821: }
822:
823:
1.1.1.15 root 824: LineBorderMask = ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask;
1.1.1.11 root 825:
826: CurSize = BORDERBYTES_NORMAL; /* normal line */
827:
828: if (LineBorderMask & BORDERMASK_LEFT_OFF)
829: CurSize += BORDERBYTES_LEFT;
830: else if (LineBorderMask & BORDERMASK_LEFT_PLUS_2)
831: CurSize += 2;
1.1.1.16 root 832: else if (bSteBorderFlag) /* bigger line by 8 bytes on the left (STE specific) */
833: CurSize += 8;
834: else if ( ( HWScrollCount > 0 ) && ( HWScrollPrefetch == 1 ) )
835: CurSize += 8; /* 8 more bytes are loaded when scrolling with prefetching */
1.1.1.11 root 836:
837: if (LineBorderMask & BORDERMASK_STOP_MIDDLE)
838: CurSize -= 106;
839: else if (LineBorderMask & BORDERMASK_RIGHT_MINUS_2)
840: CurSize -= 2;
841: else if (LineBorderMask & BORDERMASK_RIGHT_OFF)
842: CurSize += BORDERBYTES_RIGHT;
843: if (LineBorderMask & BORDERMASK_RIGHT_OFF_FULL)
844: CurSize += BORDERBYTES_RIGHT_FULL;
845:
846: if ( LineBorderMask & BORDERMASK_LEFT_PLUS_2)
847: LineStartCycle = LINE_START_CYCLE_60;
848: else if ( LineBorderMask & BORDERMASK_LEFT_OFF )
1.1.1.15 root 849: LineStartCycle = LINE_START_CYCLE_71;
1.1.1.16 root 850: else if ( bSteBorderFlag )
851: LineStartCycle -= 16; /* display starts 16 pixels earlier */
852: else if ( ( HWScrollCount > 0 ) && ( HWScrollPrefetch == 1 ) )
853: LineStartCycle -= 16; /* shifter starts reading 16 pixels earlier when scrolling with prefetching */
1.1.1.11 root 854:
855: LineEndCycle = LineStartCycle + CurSize*2;
856:
857:
858: if ( X < LineStartCycle )
1.1.1.16 root 859: X = LineStartCycle; /* display is disabled in the left border */
1.1.1.11 root 860: else if ( X > LineEndCycle )
1.1.1.16 root 861: {
862: X = LineEndCycle; /* display is disabled in the right border */
863: /* On STE, the Shifter skips the given amount of words as soon as display is disabled */
864: /* (LineWidth is 0 on STF */
865: VideoAddress += LineWidth*2;
866: }
1.1.1.11 root 867:
868: NbBytes = ( (X-LineStartCycle)>>1 ) & (~1); /* 2 cycles per byte */
869:
870:
871: /* when left border is open, we have 2 bytes less than theorical value */
872: /* (26 bytes in left border, which is not a multiple of 4 cycles) */
873: if ( LineBorderMask & BORDERMASK_LEFT_OFF )
874: NbBytes -= 2;
875:
876: if ( LineBorderMask & BORDERMASK_EMPTY_LINE )
877: NbBytes = 0;
878:
1.1.1.16 root 879: /* Add line cycles if we have not reached end of screen yet */
1.1.1.18 root 880: if ( HblCounterVideo < nEndHBL + BlankLines )
1.1.1.11 root 881: VideoAddress += PrevSize + NbBytes;
882: }
883:
1.1.1.16 root 884: LOG_TRACE(TRACE_VIDEO_ADDR , "video base=%x raster=%x addr=%x video_cyc=%d "
885: "line_cyc=%d/X=%d @ nHBL=%d/video_hbl=%d %d<->%d pc=%x instr_cyc=%d\n",
886: VideoBase, (int)(pVideoRaster - STRam), VideoAddress,
887: Cycles_GetCounter(CYCLES_COUNTER_VIDEO), LineCycles, X, nHBL,
888: HblCounterVideo, LineStartCycle, LineEndCycle, M68000_GetPC(), CurrentInstrCycles);
1.1.1.11 root 889:
890: return VideoAddress;
891: }
892:
893:
894: /*-----------------------------------------------------------------------*/
895: /**
1.1.1.16 root 896: * Calculate the cycle where the STF/STE's MMU starts reading
897: * data to send them to the shifter.
898: * On STE, if hscroll is used, prefetch will cause this position to
899: * happen 16 cycles earlier.
900: * This function should use the same logic as in Video_CalculateAddress.
901: * NOTE : this function is not completly accurate, as even when there's
902: * no hscroll (on STF) the mmu starts reading 16 cycles before display starts.
903: * But it's good enough to emulate writing to ff8205/07/09 on STE.
904: */
905: static int Video_GetMMUStartCycle ( int DisplayStartCycle )
906: {
907: if ( bSteBorderFlag )
908: DisplayStartCycle -= 16; /* display starts 16 pixels earlier */
909: else if ( ( HWScrollCount > 0 ) && ( HWScrollPrefetch == 1 ) )
910: DisplayStartCycle -= 16; /* shifter starts reading 16 pixels earlier when scrolling with prefetching */
911:
912: return DisplayStartCycle;
913: }
914:
915:
916: /*-----------------------------------------------------------------------*/
917: /**
1.1.1.11 root 918: * Write to VideoShifter (0xff8260), resolution bits
919: */
1.1.1.15 root 920: static void Video_WriteToShifter ( Uint8 Res )
1.1 root 921: {
1.1.1.15 root 922: int FrameCycles, HblCounterVideo, LineCycles;
1.1.1.11 root 923:
1.1.1.15 root 924: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.11 root 925:
1.1.1.15 root 926: LOG_TRACE(TRACE_VIDEO_RES ,"shifter=0x%2.2X video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n",
927: Res, FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.11 root 928:
929:
1.1.1.13 root 930: /* Ignore consecutive writes of the same value */
1.1.1.15 root 931: if ( Res == ShifterFrame.Res )
1.1.1.13 root 932: return; /* do nothing */
933:
1.1.1.15 root 934:
935: if ( Res == 0x02 ) /* switch to high res */
936: {
937: if ( LineCycles < ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle ) /* start could be 0,52,56 */
938: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_71;
939:
940: if ( ( LineCycles < ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle ) /* end could be 160,372,376,460 */
941: && ( LineCycles < LINE_END_CYCLE_71 ) )
942: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_71;
943: }
944: else /* switch to lo/med res */
945: {
946: /* In lo/med res, display start/end depends on the freq register in $ff820a */
947: Video_Sync_SetDefaultStartEnd ( IoMem[0xff820a] & 2 , HblCounterVideo , LineCycles );
948: }
949:
950:
1.1.1.11 root 951: /* Remove left border : +26 bytes */
1.1.1.15 root 952: /* This can be done with a hi/lo res switch or a hi/med res switch */
953: if ( ( ShifterFrame.Res == 0x02 ) && ( Res == 0x00 ) /* switched from hi res to lo res */
1.1.1.16 root 954: // && ( LineCycles >= 12 ) /* switch back to low res should be after cycle 8 */
1.1.1.19 root 955: && ( ( ShifterFrame.ResPosHi.LineCycles < 12 ) || ( ShifterFrame.ResPosHi.LineCycles >= 504 ) ) /* switch to hi between 504 and 8 */
1.1.1.15 root 956: && ( LineCycles <= (LINE_START_CYCLE_71+28) )
1.1.1.17 root 957: && ( FrameCycles - ShifterFrame.ResPosHi.FrameCycles <= 32 ) )
1.1.1.15 root 958: {
1.1.1.20! root 959: if ( ( ( ConfigureParams.System.nMachineType == MACHINE_STE ) /* special case for 504/4 and 508/4 on STE -> add 20 bytes to left border */
1.1.1.17 root 960: || ( ConfigureParams.System.nMachineType == MACHINE_MEGA_STE ) )
1.1.1.20! root 961: && ( ( ( ShifterFrame.ResPosHi.LineCycles == 504 ) && ( LineCycles == 4 ) )
! 962: || ( ( ShifterFrame.ResPosHi.LineCycles == 508 ) && ( LineCycles == 4 ) ) ) )
1.1.1.16 root 963: {
964: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_LEFT_OFF_2_STE;
965: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_71+16; /* starts 16 pixels later */
1.1.1.17 root 966: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = -8; /* screen is shifted 8 pixels to the left */
1.1.1.16 root 967: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect remove left 2 ste %d<->%d\n" ,
968: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
969: }
970: else /* other case for STF/STE -> add 26 bytes */
971: {
972: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_LEFT_OFF;
973: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_71;
974: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = -4; /* screen is shifted 4 pixels to the left */
975: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect remove left %d<->%d\n" ,
976: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
977: }
1.1.1.15 root 978: }
979:
980: if ( ( ShifterFrame.Res == 0x02 ) && ( Res == 0x01 ) /* switched from hi res to med res */
981: && ( LineCycles <= (LINE_START_CYCLE_71+20) )
982: && ( FrameCycles - ShifterFrame.ResPosHi.FrameCycles <= 30 ) )
983: {
984: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_LEFT_OFF_MED; /* a later switch to low res might gives right scrolling */
985: /* By default, this line will be in med res, except if we detect hardware scrolling later */
986: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_OVERSCAN_MED_RES | ( 2 << 20 );
987: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_71;
988: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect remove left med %d<->%d\n" ,
989: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
990: }
991:
992: /* Empty line switching res on STF : switch to hi res on cycle 28, then go back to med/lo res */
993: /* This creates a 0 byte line, the video counter won't change for this line */
994: else if ( ( ShifterFrame.Res == 0x02 ) /* switched from hi res */
995: && ( FrameCycles - ShifterFrame.ResPosHi.FrameCycles <= 16 )
996: && ( ShifterFrame.ResPosHi.LineCycles == LINE_EMPTY_CYCLE_71_STF )
997: && ( ConfigureParams.System.nMachineType == MACHINE_ST ) )
998: {
999: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_EMPTY_LINE;
1000: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = 0;
1001: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = 0;
1002: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect empty line res %d<->%d\n" ,
1003: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1004: }
1005:
1006: /* Empty line switching res on STE (switch is 4 cycles later than on STF) */
1007: else if ( ( ShifterFrame.Res == 0x02 ) /* switched from hi res */
1008: && ( FrameCycles - ShifterFrame.ResPosHi.FrameCycles <= 16 )
1009: && ( ShifterFrame.ResPosHi.LineCycles == LINE_EMPTY_CYCLE_71_STE )
1.1.1.17 root 1010: && ( ( ConfigureParams.System.nMachineType == MACHINE_STE )
1011: || ( ConfigureParams.System.nMachineType == MACHINE_MEGA_STE ) ) )
1.1.1.15 root 1012: {
1013: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_EMPTY_LINE;
1014: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = 0;
1015: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = 0;
1016: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect empty line res %d<->%d\n" ,
1017: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1018: }
1019:
1020: /* Empty line switching res on STF : switch to hi res just before the HBL then go back to lo/med res */
1.1.1.19 root 1021: /* Next HBL will be an empty line (used in 'No Buddies Land' and 'Delirious Demo IV / NGC') */
1.1.1.15 root 1022: else if ( ( ShifterFrame.Res == 0x02 ) /* switched from hi res */
1.1.1.18 root 1023: && ( ( ShifterFrame.ResPosHi.LineCycles == 500-4 ) || ( ShifterFrame.ResPosHi.LineCycles == 500 ) )
1.1.1.15 root 1024: && ( LineCycles == 508 ) )
1025: {
1.1.1.16 root 1026: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].BorderMask |= BORDERMASK_EMPTY_LINE;
1027: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayStartCycle = 0;
1028: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayEndCycle = 0;
1.1.1.18 root 1029: BlankLines++; /* no video signal at all for this line */
1.1.1.16 root 1030: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect empty line res 2 %d<->%d for nHBL=%d\n" ,
1031: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayEndCycle , nHBL+1 );
1.1.1.15 root 1032: }
1033:
1034: /* Start right border near middle of the line : -106 bytes */
1035: /* Switch to hi res just before the start of the right border in hi res, then go back to lo/mid res */
1036: if ( ( ShifterFrame.Res == 0x02 ) /* switched from hi res */
1037: && ( ShifterFrame.ResPosHi.HBL == HblCounterVideo ) /* switch during the same line */
1038: && ( ShifterFrame.ResPosHi.LineCycles <= LINE_END_CYCLE_71+4 ) /* switched to hi res before cycle 164 */
1039: && ( LineCycles >= LINE_END_CYCLE_71+4 ) ) /* switch to lo res after cycle 164 */
1040: {
1041: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_STOP_MIDDLE;
1042: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_71;
1043: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect stop middle %d<->%d\n" ,
1044: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1045: }
1046:
1047: /* Remove right border a second time after removing it a first time. Display will */
1048: /* stop at cycle 512 instead of 460. */
1049: /* This removes left border on next line too (used in 'Enchanted Lands') */
1.1.1.16 root 1050: /* If right border was not removed, then we will get an empty line for the next HBL (used in Beyond by Kruz) */
1051: if ( ( ShifterFrame.Res == 0x02 ) /* switched from hi res */
1052: && ( LineCycles > LINE_END_CYCLE_50_2 ) /* switch to low just after end of right border */
1053: && ( ShifterFrame.ResPosHi.LineCycles <= LINE_END_CYCLE_50_2 ) /* switch to hi just before end of right border */
1054: && ( FrameCycles - ShifterFrame.ResPosHi.FrameCycles <= 20 ) )
1055: {
1056: if ( ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask & BORDERMASK_RIGHT_OFF ) /* Enchanted Lands */
1057: {
1058: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_RIGHT_OFF_FULL;
1059: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_FULL;
1060: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].BorderMask |= BORDERMASK_LEFT_OFF; /* no left border on next line */
1061: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayStartCycle = LINE_START_CYCLE_71;
1062: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect remove right full %d<->%d\n" ,
1063: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1064: }
1065: else /* Pax Plax Parralax in Beyond by Kruz */
1066: {
1067: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].BorderMask = BORDERMASK_EMPTY_LINE;
1068: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayStartCycle = 0;
1069: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayEndCycle = 0;
1070: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect empty line res 3 %d<->%d for nHBL=%d\n" ,
1071: ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo+1 ].DisplayEndCycle , nHBL+1 );
1072: }
1.1.1.15 root 1073: }
1074:
1075: /* If left border is opened and we switch to medium resolution during the next cycles, */
1076: /* then we assume a med res overscan line instead of a low res overscan line. */
1077: /* Note that in that case, the switch to med res can shift the display by 0-3 words */
1.1.1.11 root 1078: /* Used in 'No Cooper' greetings by 1984 and 'Punish Your Machine' by Delta Force */
1.1.1.15 root 1079: if ( ( ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask & BORDERMASK_LEFT_OFF )
1080: && ( Res == 0x01 ) )
1.1.1.11 root 1081: {
1.1.1.18 root 1082: if ( ( LineCycles == LINE_LEFT_MED_CYCLE_1 ) /* 'No Cooper' timing */
1083: || ( LineCycles == LINE_LEFT_MED_CYCLE_1+16 ) ) /* 'No Cooper' timing while removing bottom border */
1.1.1.11 root 1084: {
1.1.1.15 root 1085: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect med res overscan offset 0 byte\n" );
1086: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_OVERSCAN_MED_RES | ( 0 << 20 );
1.1.1.11 root 1087: }
1.1.1.15 root 1088: else if ( LineCycles == LINE_LEFT_MED_CYCLE_2 ) /* 'Best Part Of The Creation / PYM' timing */
1.1.1.11 root 1089: {
1.1.1.15 root 1090: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect med res overscan offset 2 bytes\n" );
1091: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_OVERSCAN_MED_RES | ( 2 << 20 );
1.1.1.11 root 1092: }
1093: }
1094:
1.1.1.15 root 1095: /* If left border was opened with a hi/med res switch we need to check */
1096: /* if the switch to low res can trigger a right hardware scrolling. */
1097: /* We store the pixels count in DisplayPixelShift */
1098: if ( ( ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask & BORDERMASK_LEFT_OFF_MED )
1099: && ( Res == 0x00 ) && ( LineCycles <= LINE_SCROLL_1_CYCLE_50 ) )
1.1.1.11 root 1100: {
1.1.1.15 root 1101: /* The hi/med switch was a switch to do low res hardware scrolling, */
1102: /* so we must cancel the med res overscan bit. */
1103: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask &= (~BORDERMASK_OVERSCAN_MED_RES);
1.1.1.11 root 1104:
1.1.1.15 root 1105: if ( LineCycles == LINE_SCROLL_13_CYCLE_50 ) /* cycle 20 */
1.1.1.11 root 1106: {
1.1.1.15 root 1107: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 13 pixels right scroll\n" );
1108: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 13;
1.1.1.11 root 1109: }
1.1.1.15 root 1110: else if ( LineCycles == LINE_SCROLL_9_CYCLE_50 ) /* cycle 24 */
1.1.1.11 root 1111: {
1.1.1.15 root 1112: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 9 pixels right scroll\n" );
1113: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 9;
1.1.1.11 root 1114: }
1.1.1.15 root 1115: else if ( LineCycles == LINE_SCROLL_5_CYCLE_50 ) /* cycle 28 */
1.1.1.11 root 1116: {
1.1.1.15 root 1117: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 5 pixels right scroll\n" );
1118: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 5;
1.1.1.11 root 1119: }
1.1.1.15 root 1120: else if ( LineCycles == LINE_SCROLL_1_CYCLE_50 ) /* cycle 32 */
1.1.1.11 root 1121: {
1.1.1.15 root 1122: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 1 pixel right scroll\n" );
1123: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 1;
1.1.1.11 root 1124: }
1125: }
1126:
1.1.1.18 root 1127: #define SCROLL2_4PX
1128: #ifdef SCROLL2_4PX
1129: /* Left border was removed with a hi/lo switch, then a med res switch was made */
1130: /* Depending on the low res switch, the screen will be shifted as a low res overscan line */
1131: /* This is a different method than the one used by ST Connexion with only 3 res switches */
1132: /* (so we must cancel the med res overscan bit) */
1133: if ( ( ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask & BORDERMASK_OVERSCAN_MED_RES )
1134: && ( ( ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask & ( 0xf << 20 ) ) == 0 )
1135: && ( Res == 0x00 ) && ( LineCycles <= 40 ) )
1136: {
1137: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask &= (~BORDERMASK_OVERSCAN_MED_RES); /* cancel mid res */
1138:
1139: if ( LineCycles == 28 )
1140: {
1141: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 13 pixels right scroll 2\n" );
1142: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 13;
1143: }
1144: else if ( LineCycles == 32 )
1145: {
1146: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 9 pixels right scroll 2\n" );
1147: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 9;
1148: }
1149: else if ( LineCycles == 36 )
1150: {
1151: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 5 pixels right scroll 2\n" );
1152: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 5;
1153: }
1154: else if ( LineCycles == 40 )
1155: {
1156: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect 1 pixel right scroll 2\n" );
1157: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayPixelShift = 1;
1158: }
1159: }
1160: #endif
1161:
1.1.1.15 root 1162:
1163: /* Update HBL's position only if display has not reached pos LINE_START_CYCLE_50 */
1164: /* and HBL interrupt was already handled at the beginning of this line. */
1165: /* This also changes the number of cycles per line. */
1166: if ( ( LineCycles <= LINE_START_CYCLE_50 ) && ( HblCounterVideo == nHBL ) )
1167: {
1168: nCyclesPerLine = Video_HBL_GetPos();
1169: Video_AddInterruptHBL ( nCyclesPerLine );
1170: }
1171:
1172:
1173: /* Update Timer B's position */
1174: LineTimerBCycle = Video_TimerB_GetPos ( HblCounterVideo );
1175: Video_AddInterruptTimerB ( LineTimerBCycle );
1176:
1177:
1178: ShifterFrame.Res = Res;
1179: if ( Res == 0x02 ) /* high res */
1180: {
1181: ShifterFrame.ResPosHi.VBL = nVBLs;
1182: ShifterFrame.ResPosHi.FrameCycles = FrameCycles;
1183: ShifterFrame.ResPosHi.HBL = HblCounterVideo;
1184: ShifterFrame.ResPosHi.LineCycles = LineCycles;
1185: }
1186: else if ( Res == 0x01 ) /* med res */
1187: {
1188: ShifterFrame.ResPosMed.VBL = nVBLs;
1189: ShifterFrame.ResPosMed.FrameCycles = FrameCycles;
1190: ShifterFrame.ResPosMed.HBL = HblCounterVideo;
1191: ShifterFrame.ResPosMed.LineCycles = LineCycles;
1192: }
1193: else /* low res */
1194: {
1195: ShifterFrame.ResPosLo.VBL = nVBLs;
1196: ShifterFrame.ResPosLo.FrameCycles = FrameCycles;
1197: ShifterFrame.ResPosLo.HBL = HblCounterVideo;
1198: ShifterFrame.ResPosLo.LineCycles = LineCycles;
1199: }
1200: }
1201:
1202:
1203:
1204: /*-----------------------------------------------------------------------*/
1205: /**
1206: * Set some default values for DisplayStartCycle/DisplayEndCycle
1207: * when changing frequency in lo/med res (testing orders are important
1208: * because the line can already have some borders changed).
1209: * This is necessary as some freq changes can modify start/end
1210: * even if they're not made at the exact borders' positions.
1211: * These values will be modified later if some borders are changed.
1212: */
1213: static void Video_Sync_SetDefaultStartEnd ( Uint8 Freq , int HblCounterVideo , int LineCycles )
1214: {
1215: if ( Freq == 0x02 ) /* switch to 50 Hz */
1216: {
1217: if ( ( LineCycles <= ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle ) /* start could be 0,52,56 */
1218: && ( ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle == LINE_START_CYCLE_60 ) )
1219: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_50;
1220:
1221: if ( ( LineCycles <= ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle ) /* end could be 160,372,376,460 */
1222: && ( ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle < LINE_END_CYCLE_50 ) )
1223: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_50;
1224: }
1225:
1226: else /* switch to 60 Hz */
1227: {
1228: if ( LineCycles < ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle ) /* start could be 0,52,56 */
1229: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = LINE_START_CYCLE_60;
1230:
1231: if ( ( LineCycles < ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle ) /* end could be 160,372,376,460 */
1232: && ( ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle <= LINE_END_CYCLE_50 ) )
1233: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_60;
1234: }
1235:
1236: //fprintf ( stderr , "sync default pos %d %d\n", ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1.1.1.11 root 1237: }
1238:
1239:
1240: /*-----------------------------------------------------------------------*/
1241: /**
1242: * Write to VideoSync (0xff820a), Hz setting
1243: */
1.1.1.15 root 1244: void Video_Sync_WriteByte ( void )
1.1 root 1245: {
1.1.1.15 root 1246: int FrameCycles, HblCounterVideo, LineCycles;
1247: Uint8 Freq;
1.1.1.11 root 1248:
1249:
1.1.1.15 root 1250: if ( bUseVDIRes )
1251: return; /* no 50/60 Hz freq in VDI mode */
1.1.1.11 root 1252:
1253:
1.1.1.15 root 1254: /* We're only interested in bit 1 (50/60Hz) */
1255: Freq = IoMem[0xff820a] & 2;
1.1.1.11 root 1256:
1.1.1.15 root 1257: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
1258:
1259: LOG_TRACE(TRACE_VIDEO_SYNC ,"sync=0x%2.2X video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n",
1260: Freq, FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.11 root 1261:
1.1.1.13 root 1262: /* Ignore consecutive writes of the same value */
1.1.1.15 root 1263: if ( Freq == ShifterFrame.Freq )
1.1.1.13 root 1264: return; /* do nothing */
1265:
1.1.1.15 root 1266: /* Ignore freq changes if we are in high res */
1267: /* 2009/04/26 : don't ignore for now (see ST Cnx in Punish Your Machine) */
1268: // if ( ShifterFrame.Res == 0x02 )
1269: // return; /* do nothing */
1270:
1271: /* Set some default values for DisplayStartCycle/DisplayEndCycle before checking for border removal */
1272: Video_Sync_SetDefaultStartEnd ( Freq , HblCounterVideo , LineCycles );
1273:
1274:
1275: if ( ( ShifterFrame.Freq == 0x00 ) && ( Freq == 0x02 ) /* switched from 60 Hz to 50 Hz ? */
1276: // && ( ShifterFrame.FreqPos60.VBL == nVBLs ) /* switched during the same VBL */
1277: && ( HblCounterVideo >= nStartHBL ) /* only if display is on */
1.1.1.18 root 1278: && ( HblCounterVideo < nEndHBL + BlankLines ) ) /* only if display is on */
1.1.1.15 root 1279: {
1.1.1.18 root 1280: /* Blank line switching freq on STF : switch to 60 Hz on cycle 28, then go back to 50 Hz on cycle 36 */
1281: /* This creates a blank line where no signal is displayed, but the video counter will still change for this line */
1282: /* This blank line can be combined with left/right border changes */
1283: if ( ( FrameCycles - ShifterFrame.FreqPos60.FrameCycles <= 16 )
1284: && ( ShifterFrame.FreqPos60.LineCycles == LINE_EMPTY_CYCLE_71_STF )
1285: && ( ConfigureParams.System.nMachineType == MACHINE_ST ) )
1286: {
1287: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_BLANK_LINE;
1288: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect blank line freq\n" );
1289: }
1290:
1.1.1.15 root 1291: /* Add 2 bytes to left border : switch to 60 Hz before LINE_START_CYCLE_60 to force an early start */
1292: /* of the DE signal, then go back to 50 Hz. Note that depending on where the 50 Hz switch is made */
1293: /* the HBL signal will be at position 508 (60 Hz line) or 512 (50 Hz line) */
1294: /* Obtaining a +2 line with 512 cycles requires a 2 cycles precision and is "wake up" state dependant */
1295: if ( ( ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle == LINE_START_CYCLE_60 )
1296: && ( LineCycles >= LINE_START_CYCLE_50 ) /* The line started in 60 Hz and continues in 50 Hz */
1297: && ( LineCycles <= ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle ) ) /* change when line is active */
1.1.1.11 root 1298: {
1.1.1.15 root 1299: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_LEFT_PLUS_2;
1300: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_50;
1301: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect left+2 %d<->%d\n" ,
1302: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1.1.1.11 root 1303: }
1304:
1.1.1.15 root 1305: /* Empty line switching freq : start the line in 50 Hz, change to 60 Hz at the exact place */
1306: /* where display is enabled in 50 Hz, then go back to 50 Hz. */
1307: /* Due to 4 cycles precision instead of 2, we must accept a 60 Hz switch at pos 56 or 56+4 */
1308: else if ( ( FrameCycles - ShifterFrame.FreqPos60.FrameCycles <= 24 )
1309: && ( ( ShifterFrame.FreqPos60.LineCycles == LINE_START_CYCLE_50 ) || ( ShifterFrame.FreqPos60.LineCycles == LINE_START_CYCLE_50+4 ) )
1310: && ( LineCycles > LINE_START_CYCLE_50 ) )
1311: {
1312: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_EMPTY_LINE;
1313: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle = 0;
1314: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = 0;
1315: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect empty line freq %d<->%d\n" ,
1316: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1.1.1.11 root 1317: }
1.1.1.15 root 1318:
1319: /* Remove 2 bytes to the right : start the line in 50 Hz (pos 0 or 56), change to 60 Hz before the position */
1320: /* where display is disabled in 60 Hz, then go back to 50 Hz */
1321: if ( ( LineCycles > LINE_END_CYCLE_60 ) /* back to 50 Hz after end of 60 Hz line */
1322: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle != LINE_START_CYCLE_60 ) /* start could be 0 or 56 */
1323: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle == LINE_END_CYCLE_60 ) )
1324: {
1325: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_RIGHT_MINUS_2;
1326: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect right-2 %d<->%d\n" ,
1327: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1328: }
1329:
1.1.1.11 root 1330: }
1331:
1.1.1.15 root 1332:
1333: if ( ( ShifterFrame.Freq == 0x02 && Freq == 0x00 ) /* switched from 50 Hz to 60 Hz ? */
1334: && ( HblCounterVideo >= nStartHBL ) /* only if display is on */
1.1.1.18 root 1335: && ( HblCounterVideo < nEndHBL + BlankLines ) ) /* only if display is on */
1.1.1.15 root 1336: {
1337: /* remove right border, display 44 bytes more : switch to 60 Hz at the position where */
1338: /* the line ends in 50 Hz. Some programs don't switch back to 50 Hz immediatly */
1339: /* (sync screen in SNY II), so we just check if freq changes to 60 Hz at the position where line should end in 50 Hz */
1340: if ( ( LineCycles == LINE_END_CYCLE_50 )
1341: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle == LINE_END_CYCLE_50 ) )
1342: {
1343: ShifterFrame.ShifterLines[ HblCounterVideo ].BorderMask |= BORDERMASK_RIGHT_OFF;
1.1.1.16 root 1344: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle = LINE_END_CYCLE_NO_RIGHT;
1.1.1.15 root 1345: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect remove right %d<->%d\n" ,
1346: ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayStartCycle , ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle );
1.1.1.11 root 1347: }
1348: }
1349:
1350:
1351: /* Store cycle position of freq 50/60 to check for top/bottom border removal in Video_EndHBL. */
1.1.1.15 root 1352: if ( Freq == 0x02 ) /* switch to 50 Hz */
1.1.1.11 root 1353: {
1.1.1.13 root 1354: if ( ( HblCounterVideo < VIDEO_START_HBL_50HZ ) /* nStartHBL can change only if display is not ON yet */
1355: && ( OverscanMode & OVERSCANMODE_TOP ) == 0 ) /* update only if top was not removed */
1356: nStartHBL = VIDEO_START_HBL_50HZ;
1.1.1.11 root 1357:
1.1.1.13 root 1358: if ( ( HblCounterVideo < VIDEO_END_HBL_50HZ ) /* nEndHBL can change only if display is not OFF yet */
1.1.1.11 root 1359: && ( OverscanMode & OVERSCANMODE_BOTTOM ) == 0 ) /* update only if bottom was not removed */
1.1.1.13 root 1360: nEndHBL = VIDEO_END_HBL_50HZ; /* 263 */
1.1.1.11 root 1361: }
1.1.1.15 root 1362: else if ( Freq == 0x00 ) /* switch to 60 Hz */
1.1.1.11 root 1363: {
1.1.1.13 root 1364: if ( ( HblCounterVideo < VIDEO_START_HBL_60HZ-1 ) /* nStartHBL can change only if display is not ON yet */
1.1.1.15 root 1365: || ( ( HblCounterVideo == VIDEO_START_HBL_60HZ-1 ) && ( LineCycles <= LineRemoveTopCycle ) ) )
1.1.1.13 root 1366: nStartHBL = VIDEO_START_HBL_60HZ;
1.1.1.11 root 1367:
1.1.1.13 root 1368: if ( ( HblCounterVideo < VIDEO_END_HBL_60HZ ) /* nEndHBL can change only if display is not OFF yet */
1.1.1.11 root 1369: && ( OverscanMode & OVERSCANMODE_BOTTOM ) == 0 ) /* update only if bottom was not removed */
1.1.1.13 root 1370: nEndHBL = VIDEO_END_HBL_60HZ; /* 234 */
1371: }
1372:
1.1.1.15 root 1373:
1.1.1.13 root 1374: /* If the frequence changed, we need to update the EndLine interrupt */
1.1.1.15 root 1375: /* so that it happens 28 cycles after the current DisplayEndCycle.*/
1.1.1.13 root 1376: /* We check if the change affects the current line or the next one. */
1.1.1.15 root 1377: /* We also need to check if the HBL interrupt and nCyclesPerLine need */
1378: /* to be updated first. */
1379: if ( Freq != ShifterFrame.Freq )
1380: {
1381: /* Update HBL's position only if display has not reached pos LINE_START_CYCLE_50 */
1382: /* and HBL interrupt was already handled at the beginning of this line. */
1383: /* This also changes the number of cycles per line. */
1384: if ( ( LineCycles <= LINE_START_CYCLE_50 ) && ( HblCounterVideo == nHBL ) )
1385: {
1386: nCyclesPerLine = Video_HBL_GetPos();
1387: Video_AddInterruptHBL ( nCyclesPerLine );
1388: }
1389:
1390: /* Update Timer B's position */
1391: LineTimerBCycle = Video_TimerB_GetPos ( HblCounterVideo );
1392: Video_AddInterruptTimerB ( LineTimerBCycle );
1393: }
1394:
1395:
1396: ShifterFrame.Freq = Freq;
1397: if ( Freq == 0x02 ) /* 50 Hz */
1398: {
1399: ShifterFrame.FreqPos50.VBL = nVBLs;
1400: ShifterFrame.FreqPos50.FrameCycles = FrameCycles;
1401: ShifterFrame.FreqPos50.HBL = HblCounterVideo;
1402: ShifterFrame.FreqPos50.LineCycles = LineCycles;
1403: }
1404: else
1405: {
1406: ShifterFrame.FreqPos60.VBL = nVBLs;
1407: ShifterFrame.FreqPos60.FrameCycles = FrameCycles;
1408: ShifterFrame.FreqPos60.HBL = HblCounterVideo;
1409: ShifterFrame.FreqPos60.LineCycles = LineCycles;
1410: }
1411: }
1412:
1413:
1414: /*-----------------------------------------------------------------------*/
1415: /**
1416: * Compute the cycle position where the HBL should happen on each line.
1417: * In low/med res, the position depends on the video frequency (50/60 Hz)
1418: * In high res, the position is always the same.
1419: * This position also gives the number of CPU cycles per video line.
1420: */
1421: static int Video_HBL_GetPos ( void )
1422: {
1423: int Pos;
1424:
1425: if ( ( IoMem_ReadByte ( 0xff8260 ) & 3 ) == 2 ) /* hi res */
1426: Pos = CYCLES_PER_LINE_71HZ;
1427:
1428: else /* low res or med res */
1429: {
1430: if ( IoMem_ReadByte ( 0xff820a ) & 2 ) /* 50 Hz, pos 512 */
1431: Pos = CYCLES_PER_LINE_50HZ;
1432: else /* 60 Hz, pos 508 */
1433: Pos = CYCLES_PER_LINE_60HZ;
1434: }
1435:
1436: return Pos;
1437: }
1438:
1439:
1440: /*-----------------------------------------------------------------------*/
1441: /**
1442: * Compute the cycle position where the timer B should happen on each
1443: * visible line.
1444: * We compute Timer B position for the given LineNumber, using start/end
1445: * display cycles from ShifterLines[ LineNumber ].
1446: * The position depends on the start of line / end of line positions
1447: * (which depend on the current frequency / border tricks) and
1448: * on the value of the bit 3 in the MFP's AER.
1449: * If bit is 0, timer B will count end of line events (usual case),
1450: * but if bit is 1, timer B will count start of line events (eg Seven Gates Of Jambala)
1451: */
1452: int Video_TimerB_GetPos ( int LineNumber )
1453: {
1454: int Pos;
1455:
1456: if ( ( IoMem[0xfffa03] & ( 1 << 3 ) ) == 0 ) /* we're counting end of line events */
1457: {
1458: Pos = ShifterFrame.ShifterLines[ LineNumber ].DisplayEndCycle + TIMERB_VIDEO_CYCLE_OFFSET;
1459: }
1460: else /* we're counting start of line events */
1461: {
1462: Pos = ShifterFrame.ShifterLines[ LineNumber ].DisplayStartCycle + TIMERB_VIDEO_CYCLE_OFFSET;
1463: }
1464:
1.1.1.18 root 1465: //fprintf ( stderr , "timerb pos=%d\n" , Pos );
1466: return Pos;
1467: }
1468:
1469:
1470: /*-----------------------------------------------------------------------*/
1471: /**
1472: * Compute the default cycle position where the timer B should happen
1473: * on the next line, when restarting the INTERRUPT_VIDEO_ENDLINE handler.
1474: * In low/med res, the position depends on the video frequency (50/60 Hz)
1475: * In high res, the position is always the same.
1476: */
1477: int Video_TimerB_GetDefaultPos ( void )
1478: {
1479: int Pos;
1480:
1481: if ( ( IoMem[0xfffa03] & ( 1 << 3 ) ) == 0 ) /* we're counting end of line events */
1482: {
1483: if ( ( IoMem_ReadByte ( 0xff8260 ) & 3 ) == 2 ) /* hi res */
1484: Pos = LINE_END_CYCLE_71;
1485:
1486: else /* low res or med res */
1487: {
1488: if ( IoMem_ReadByte ( 0xff820a ) & 2 ) /* 50 Hz, pos 376 */
1489: Pos = LINE_END_CYCLE_50;
1490: else /* 60 Hz, pos 372 */
1491: Pos = LINE_END_CYCLE_60;
1492: }
1493: }
1494: else /* we're counting start of line events */
1495: {
1496: if ( ( IoMem_ReadByte ( 0xff8260 ) & 3 ) == 2 ) /* hi res */
1497: Pos = LINE_START_CYCLE_71;
1498:
1499: else /* low res or med res */
1500: {
1501: if ( IoMem_ReadByte ( 0xff820a ) & 2 ) /* 50 Hz, pos 56 */
1502: Pos = LINE_START_CYCLE_50;
1503: else /* 60 Hz, pos 52 */
1504: Pos = LINE_START_CYCLE_60;
1505: }
1506: }
1507:
1508: Pos += TIMERB_VIDEO_CYCLE_OFFSET;
1509:
1510: //fprintf ( stderr , "timerb default pos=%d\n" , Pos );
1.1.1.15 root 1511: return Pos;
1512: }
1513:
1514:
1515: /*-----------------------------------------------------------------------*/
1516: /**
1517: * HBL interrupt : this occurs at the end of every line, on cycle 512 (in 50 Hz)
1518: * It takes 56 cycles to handle the 68000's exception.
1519: */
1520: void Video_InterruptHandler_HBL ( void )
1521: {
1522: int FrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO);
1523: int PendingCyclesOver;
1524: int NewHBLPos;
1525:
1526: /* How many cycle was this HBL delayed (>= 0) */
1527: PendingCyclesOver = -INT_CONVERT_FROM_INTERNAL ( PendingInterruptCount , INT_CPU_CYCLE );
1528:
1529: /* Remove this interrupt from list and re-order */
1.1.1.16 root 1530: CycInt_AcknowledgeInterrupt();
1.1.1.15 root 1531:
1.1.1.17 root 1532: /* Videl Vertical counter increment (To be removed when Videl emulation is finished) */
1533: /* VFC is incremented every half line, here, we increment it every line (should be completed) */
1534: if (ConfigureParams.System.nMachineType == MACHINE_FALCON) {
1535: vfc_counter += 1;
1536: }
1537:
1538:
1.1.1.15 root 1539: /* Increment the hbl jitter index */
1540: HblJitterIndex++;
1.1.1.20! root 1541: HblJitterIndex %= HBL_JITTER_ARRAY_SIZE;
1.1.1.15 root 1542:
1543: LOG_TRACE ( TRACE_VIDEO_HBL , "HBL %d video_cyc=%d pending_cyc=%d jitter=%d\n" ,
1544: nHBL , FrameCycles , PendingCyclesOver , HblJitterArray[ HblJitterIndex ] );
1545:
1546: /* Default cycle position for next HBL */
1547: NewHBLPos = Video_HBL_GetPos();
1548:
1549: /* Generate new HBL, if need to - there are 313 HBLs per frame in 50 Hz */
1550: if (nHBL < nScanlinesPerFrame-1)
1551: Video_AddInterruptHBL ( NewHBLPos );
1552:
1553:
1554: /* We must handle a very special case : if we had a pending HBL that becomes active */
1555: /* because SR is now <= $2100, then we must process an exception for this pending HBL. */
1556: /* But if a "real" (non pending) HBL occurs during the first 56 cycles needed by the */
1557: /* CPU to prepare the exception, we must ignore this HBL signal (instead of considering */
1558: /* this new HBL should be put in pending state to be processed later) */
1559: /* -> any HBL occuring between LastCycleHblException and LastCycleHblException+56 should be ignored */
1560: if ( ( LastCycleHblException != -1 )
1.1.1.17 root 1561: && ( ( FrameCycles - PendingCyclesOver - HblJitterArray[ HblJitterIndex ] ) - LastCycleHblException <= 56 )
1562: && ( ( M68000_GetPC() < 0x8280 ) || ( M68000_GetPC() > 0x82b0 ) ) ) /* FIXME : except for European Demos intro where 8280<pc<82b0 */
1.1.1.15 root 1563: {
1564: /* simultaneous case, don't call M68000_Exception */
1565: LOG_TRACE ( TRACE_VIDEO_HBL , "HBL %d video_cyc=%d signal ignored during pending hbl exception at cycle %d\n" ,
1566: nHBL , Cycles_GetCounter(CYCLES_COUNTER_VIDEO) , LastCycleHblException );
1567: LastCycleHblException = -1;
1568: }
1569: else
1570: {
1571: /* "normal" case, this HBL doesn't occur during the processing of a pending HBL */
1.1.1.16 root 1572: M68000_Exception(EXCEPTION_HBLANK , M68000_EXC_SRC_AUTOVEC); /* Horizontal blank interrupt, level 2! */
1.1.1.15 root 1573: }
1574:
1575:
1576: Video_EndHBL(); /* Check some borders removal and copy line to display buffer */
1577:
1.1.1.17 root 1578: DmaSnd_STE_HBL_Update(); /* Update STE DMA sound if needed */
1579:
1.1.1.15 root 1580: nHBL++; /* Increase HBL count */
1581:
1582: if (nHBL < nScanlinesPerFrame)
1583: {
1584: /* Update start cycle for next HBL */
1585: ShifterFrame.ShifterLines[ nHBL ].StartCycle = FrameCycles - PendingCyclesOver;
1586: LOG_TRACE(TRACE_VIDEO_HBL, "HBL %d start=%d %x\n", nHBL,
1587: ShifterFrame.ShifterLines[nHBL].StartCycle, ShifterFrame.ShifterLines[nHBL].StartCycle);
1588:
1589: /* Setup next HBL */
1590: Video_StartHBL();
1591: }
1592: }
1593:
1594:
1595: /*-----------------------------------------------------------------------*/
1596: /**
1597: * Check at end of each HBL to see if any Shifter hardware tricks have been attempted
1598: * and copy the line to the screen buffer.
1599: * This is the place to check if top/bottom border were removed, as well as if some
1600: * left/right border changes were not validated before.
1601: * NOTE : the tests must be made with nHBL in ascending order.
1602: */
1603: static void Video_EndHBL(void)
1604: {
1605: //
1606: // Handle top/bottom borders removal when switching freq
1607: //
1608:
1609: /* Remove top border if the switch to 60 Hz was made during this vbl before cycle */
1610: /* LineRemoveTopCycle on line 33 and if the switch to 50 Hz has not yet occured or */
1611: /* occured before the 60 Hz or occured after cycle LineRemoveTopCycle on line 33. */
1612: if ( ( nHBL == VIDEO_START_HBL_60HZ-1 ) /* last HBL before first line of a 60 Hz screen */
1613: && ( ShifterFrame.FreqPos60.VBL == nVBLs ) /* switch to 60 Hz during this VBL */
1.1.1.20! root 1614: && ( ( ShifterFrame.FreqPos60.HBL < nHBL )
! 1615: || ( ( ShifterFrame.FreqPos60.HBL == nHBL ) && ( ShifterFrame.FreqPos60.LineCycles <= LineRemoveTopCycle ) ) )
1.1.1.15 root 1616: && ( ( ShifterFrame.FreqPos50.VBL < nVBLs )
1617: || ( ShifterFrame.FreqPos50.FrameCycles < ShifterFrame.FreqPos60.FrameCycles )
1618: || ( ShifterFrame.FreqPos50.HBL > nHBL )
1.1.1.20! root 1619: || ( ( ShifterFrame.FreqPos50.HBL == nHBL ) && ( ShifterFrame.FreqPos50.LineCycles >= LineRemoveTopCycle ) ) ) )
1.1.1.15 root 1620: {
1621: /* Top border */
1622: LOG_TRACE ( TRACE_VIDEO_BORDER_V , "detect remove top\n" );
1623: OverscanMode |= OVERSCANMODE_TOP; /* Set overscan bit */
1624: nStartHBL = VIDEO_START_HBL_60HZ; /* New start screen line */
1625: pHBLPaletteMasks -= OVERSCAN_TOP; // FIXME useless ?
1626: pHBLPalettes -= OVERSCAN_TOP; // FIXME useless ?
1627: }
1628:
1629: /* Remove bottom border for a 60 Hz screen (tests are similar to the ones for top border) */
1.1.1.18 root 1630: else if ( ( nHBL == VIDEO_END_HBL_60HZ + BlankLines - 1 ) /* last displayed line in 60 Hz */
1.1.1.15 root 1631: && ( nStartHBL == VIDEO_START_HBL_60HZ ) /* screen started in 60 Hz */
1632: && ( ( OverscanMode & OVERSCANMODE_TOP ) == 0 ) /* and top border was not removed : this screen is only 60 Hz */
1633: && ( ShifterFrame.FreqPos50.VBL == nVBLs ) /* switch to 50 Hz during this VBL */
1.1.1.20! root 1634: && ( ( ShifterFrame.FreqPos50.HBL < nHBL )
! 1635: || ( ( ShifterFrame.FreqPos50.HBL == nHBL ) && ( ShifterFrame.FreqPos50.LineCycles <= LineRemoveBottomCycle ) ) )
1.1.1.15 root 1636: && ( ( ShifterFrame.FreqPos60.VBL < nVBLs )
1637: || ( ShifterFrame.FreqPos60.FrameCycles < ShifterFrame.FreqPos50.FrameCycles )
1638: || ( ShifterFrame.FreqPos60.HBL > nHBL )
1.1.1.20! root 1639: || ( ( ShifterFrame.FreqPos60.HBL == nHBL ) && ( ShifterFrame.FreqPos60.LineCycles >= LineRemoveBottomCycle ) ) ) )
1.1.1.15 root 1640: {
1641: LOG_TRACE ( TRACE_VIDEO_BORDER_V , "detect remove bottom 60Hz\n" );
1642: OverscanMode |= OVERSCANMODE_BOTTOM;
1643: nEndHBL = SCANLINES_PER_FRAME_60HZ; /* new end for a 60 Hz screen */
1644: }
1645:
1646: /* Remove bottom border for a 50 Hz screen (tests are similar to the ones for top border) */
1.1.1.18 root 1647: else if ( ( nHBL == VIDEO_END_HBL_50HZ + BlankLines - 1 ) /* last displayed line in 50 Hz */
1.1.1.15 root 1648: && ( ( OverscanMode & OVERSCANMODE_BOTTOM ) == 0 ) /* border was not already removed at line VIDEO_END_HBL_60HZ-1 */
1649: && ( ShifterFrame.FreqPos60.VBL == nVBLs ) /* switch to 60 Hz during this VBL */
1.1.1.20! root 1650: && ( ( ShifterFrame.FreqPos60.HBL < nHBL )
! 1651: || ( ( ShifterFrame.FreqPos60.HBL == nHBL ) && ( ShifterFrame.FreqPos60.LineCycles <= LineRemoveBottomCycle ) ) )
1.1.1.15 root 1652: && ( ( ShifterFrame.FreqPos50.VBL < nVBLs )
1653: || ( ShifterFrame.FreqPos50.FrameCycles < ShifterFrame.FreqPos60.FrameCycles )
1654: || ( ShifterFrame.FreqPos50.HBL > nHBL )
1.1.1.20! root 1655: || ( ( ShifterFrame.FreqPos50.HBL == nHBL ) && ( ShifterFrame.FreqPos50.LineCycles >= LineRemoveBottomCycle ) ) ) )
1.1.1.13 root 1656: {
1.1.1.15 root 1657: LOG_TRACE ( TRACE_VIDEO_BORDER_V , "detect remove bottom\n" );
1658: OverscanMode |= OVERSCANMODE_BOTTOM;
1659: nEndHBL = VIDEO_END_HBL_50HZ+VIDEO_HEIGHT_BOTTOM_50HZ; /* new end for a 50 Hz screen */
1660: }
1661:
1662:
1663: //
1664: // Check some left/right borders effects that were not detected earlier
1665: // (this is usually due to staying in 60 Hz for too long, which is often a bad
1666: // coding practice as it can distort the display on a real ST)
1667: //
1668:
1669: /* Special case when the line was not started in 60 Hz, then switched to 60 Hz */
1670: /* and was not restored to 50 Hz before the end of the line. In that case, the */
1671: /* line ends 2 bytes earlier on the right (line can start at LINE_START_CYCLE_71/50) */
1672: /* Some programs also turn to 60 Hz too early during the active display of the last */
1673: /* line to remove the bottom border (FNIL by TNT), in that case, we should also remove */
1674: /* 2 bytes to this line */
1675: if ( ( ( ShifterFrame.ShifterLines[ nHBL ].BorderMask & BORDERMASK_RIGHT_MINUS_2 ) == 0 )
1676: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle != LINE_START_CYCLE_60 ) /* start could be 0 or 56 */
1677: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle == LINE_END_CYCLE_60 ) )
1678: {
1679: ShifterFrame.ShifterLines[ nHBL ].BorderMask |= BORDERMASK_RIGHT_MINUS_2;
1680: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect late right-2 %d<->%d\n" ,
1681: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle , ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle );
1682: }
1683:
1684:
1685: /* Similar case when line started in 60 Hz but did not end at the usual LINE_END_CYCLE_60 position */
1686: /* (line can end at LINE_END_CYCLE_71/50 or have right border removed) */
1687: /* This means left border had 2 bytes more to display */
1688: if ( ( ( ShifterFrame.ShifterLines[ nHBL ].BorderMask & BORDERMASK_LEFT_PLUS_2 ) == 0 )
1689: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle == LINE_START_CYCLE_60 )
1690: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle != LINE_END_CYCLE_60 ) ) /* end could be 160, 372 or 460 */
1691: {
1692: ShifterFrame.ShifterLines[ nHBL ].BorderMask |= BORDERMASK_LEFT_PLUS_2;
1693: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "detect late left+2 %d<->%d\n" ,
1694: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle , ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle );
1695: }
1696:
1697:
1698: /* Although a 'left+2' was detected earlier, the freq was switched back to 60 Hz during DE, so the line is just */
1699: /* a normal 60 Hz line ; we must cancel the 'left+2' flag */
1700: else if ( ( ShifterFrame.ShifterLines[ nHBL ].BorderMask & BORDERMASK_LEFT_PLUS_2 )
1701: && ( ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle == LINE_END_CYCLE_60 ) )
1702: {
1703: ShifterFrame.ShifterLines[ nHBL ].BorderMask &= ~BORDERMASK_LEFT_PLUS_2;
1704: LOG_TRACE ( TRACE_VIDEO_BORDER_H , "cancel late left+2 %d<->%d\n" ,
1705: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle , ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle );
1706: }
1707:
1708:
1.1.1.13 root 1709:
1.1.1.15 root 1710: /* Store palette for very first line on screen - HBLPalettes[0] */
1711: if (nHBL == nFirstVisibleHbl-1)
1712: {
1713: /* Store ALL palette for this line into raster table for datum */
1714: Video_StoreFirstLinePalette();
1715: }
1716:
1717: if (bUseHighRes)
1718: {
1719: /* Copy for hi-res (no overscan) */
1720: if (nHBL >= nFirstVisibleHbl && nHBL < nLastVisibleHbl)
1721: Video_CopyScreenLineMono();
1722: }
1723: /* Are we in possible visible color display (including borders)? */
1724: else if (nHBL >= nFirstVisibleHbl && nHBL < nLastVisibleHbl)
1725: {
1726: /* Store resolution for every line so can check for mix low/med screens */
1727: Video_StoreResolution(nHBL-nFirstVisibleHbl);
1728:
1729: /* Copy line of screen to buffer to simulate TV raster trace
1730: * - required for mouse cursor display/game updates
1731: * Eg, Lemmings and The Killing Game Show are good examples */
1732: Video_CopyScreenLineColor();
1733: }
1734: }
1735:
1736:
1737: /*-----------------------------------------------------------------------*/
1738: /**
1739: * Set default values for the next HBL, depending on the current res/freq.
1740: * We set the number of cycles per line, as well as some default values
1741: * for display start/end cycle.
1742: */
1743: static void Video_StartHBL(void)
1744: {
1.1.1.19 root 1745: if ((IoMem_ReadByte(0xff8260) & 3) == 2) /* hi res */
1.1.1.15 root 1746: {
1747: nCyclesPerLine = CYCLES_PER_LINE_71HZ;
1748: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle = LINE_START_CYCLE_71;
1749: ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle = LINE_END_CYCLE_71;
1750: }
1751: else
1752: {
1753: if ( IoMem_ReadByte ( 0xff820a ) & 2 ) /* 50 Hz */
1754: {
1755: nCyclesPerLine = CYCLES_PER_LINE_50HZ;
1756: if ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle == -1 ) /* start not set yet */
1757: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle = LINE_START_CYCLE_50;
1758: ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle = LINE_END_CYCLE_50;
1759: }
1760: else /* 60 Hz */
1761: {
1762: nCyclesPerLine = CYCLES_PER_LINE_60HZ;
1763: if ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle == -1 ) /* start not set yet */
1764: ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle = LINE_START_CYCLE_60;
1765: ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle = LINE_END_CYCLE_60;
1766: }
1767: }
1768: }
1769:
1770:
1771: /*-----------------------------------------------------------------------*/
1772: /**
1773: * End Of Line interrupt
1774: * This interrupt is started on cycle position 404 in 50 Hz and on cycle
1775: * position 400 in 60 Hz. 50 Hz display ends at cycle 376 and 60 Hz displays
1776: * ends at cycle 372. This means the EndLine interrupt happens 28 cycles
1777: * after DisplayEndCycle.
1778: * Note that if bit 3 of MFP AER is 1, then timer B will count start of line
1779: * instead of end of line (at cycle 52+28 or 56+28)
1780: */
1781: void Video_InterruptHandler_EndLine(void)
1782: {
1783: int FrameCycles, HblCounterVideo, LineCycles;
1784: int PendingCycles = -INT_CONVERT_FROM_INTERNAL ( PendingInterruptCount , INT_CPU_CYCLE );
1785:
1786: Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
1787:
1788: LOG_TRACE ( TRACE_VIDEO_HBL , "EndLine TB %d video_cyc=%d line_cyc=%d pending_int_cnt=%d\n" ,
1789: nHBL , FrameCycles , LineCycles , PendingCycles );
1790:
1791: /* Remove this interrupt from list and re-order */
1.1.1.16 root 1792: CycInt_AcknowledgeInterrupt();
1.1.1.15 root 1793:
1794: /* Ignore HBLs in VDI mode */
1795: if (bUseVDIRes)
1796: return;
1797:
1798: /* Generate new Endline, if need to - there are 313 HBLs per frame */
1799: if (nHBL < nScanlinesPerFrame-1)
1800: {
1801: /* By default, next EndLine's int will be on line nHBL+1 at pos 376+28 or 372+28 */
1802: if ( ( IoMem[0xfffa03] & ( 1 << 3 ) ) == 0 ) /* count end of line */
1.1.1.13 root 1803: {
1.1.1.15 root 1804: /* If EndLine int is delayed too much (more than 100 cycles), nLineCycles will */
1805: /* be in the range 0..xxx instead of 400..512. In that case, we need to add */
1806: /* nCyclesPerLine to be in the range 512..x+512 */
1807: /* Maximum possible delay should be around 160 cycles on STF (DIVS) */
1808: /* In that case, HBL int will be delayed too, so we will have HblCounterVideo == nHBL+1 */
1809: if ( HblCounterVideo == nHBL+1 ) /* int happened in fact on the next line nHBL+1 */
1810: LineCycles += nCyclesPerLine;
1.1.1.13 root 1811:
1.1.1.18 root 1812: LineTimerBCycle = Video_TimerB_GetDefaultPos ();
1.1.1.13 root 1813: }
1814:
1.1.1.15 root 1815: else /* count start of line, no possible delay to handle */
1.1.1.13 root 1816: {
1.1.1.18 root 1817: LineTimerBCycle = Video_TimerB_GetDefaultPos ();
1.1.1.13 root 1818: }
1819:
1.1.1.15 root 1820: //fprintf ( stderr , "new tb %d %d %d\n" , LineTimerBCycle , nCyclesPerLine , LineTimerBCycle - LineCycles + nCyclesPerLine );
1.1.1.16 root 1821: CycInt_AddRelativeInterrupt ( LineTimerBCycle - LineCycles + nCyclesPerLine,
1.1.1.15 root 1822: INT_CPU_CYCLE, INTERRUPT_VIDEO_ENDLINE );
1.1.1.11 root 1823: }
1824:
1.1.1.15 root 1825: /* Timer B occurs at END of first visible screen line in Event Count mode */
1.1.1.18 root 1826: if ( ( nHBL >= nStartHBL ) && ( nHBL < nEndHBL + BlankLines ) )
1.1.1.11 root 1827: {
1.1.1.15 root 1828: /* Handle Timer B when using Event Count mode */
1829: /* We must ensure that the write to fffa1b to activate timer B was */
1830: /* completed before the point where the end of line signal was generated */
1831: /* (in the case of a move.b #8,$fffa1b that would happen 4 cycles */
1832: /* before end of line, the interrupt should not be generated) */
1833: if ( (MFP_TBCR == 0x08) /* Is timer in Event Count mode ? */
1834: && ( ( TimerBEventCountCycleStart == -1 ) /* timer B was started during a previous VBL */
1835: || ( TimerBEventCountCycleStart < FrameCycles-PendingCycles ) ) ) /* timer B was started before this possible interrupt */
1836: MFP_TimerB_EventCount_Interrupt(); /* we have a valid timer B interrupt */
1.1.1.11 root 1837: }
1.1 root 1838: }
1839:
1.1.1.2 root 1840:
1.1.1.15 root 1841:
1842:
1.1.1.2 root 1843: /*-----------------------------------------------------------------------*/
1.1.1.11 root 1844: /**
1845: * Store whole palette on first line so have reference to work from
1846: */
1.1.1.7 root 1847: static void Video_StoreFirstLinePalette(void)
1.1 root 1848: {
1.1.1.11 root 1849: Uint16 *pp2;
1850: int i;
1851:
1852: pp2 = (Uint16 *)&IoMem[0xff8240];
1853: for (i = 0; i < 16; i++)
1854: HBLPalettes[i] = SDL_SwapBE16(*pp2++);
1.1 root 1855:
1.1.1.11 root 1856: /* And set mask flag with palette and resolution */
1857: // FIXME ; enlever PALETTEMASK_RESOLUTION
1858:
1.1.1.15 root 1859: // if ( ShifterFrame.ShifterLines[ nFirstVisibleHbl ].BorderMask == BORDERMASK_NONE ) // no border trick, store the current res
1.1.1.11 root 1860: HBLPaletteMasks[0] = (PALETTEMASK_RESOLUTION|PALETTEMASK_PALETTE) | (((Uint32)IoMem_ReadByte(0xff8260)&0x3)<<16);
1861: // else // border removal, assume low res for the whole line
1862: // HBLPaletteMasks[0] = (PALETTEMASK_RESOLUTION|PALETTEMASK_PALETTE) | (0<<16);
1.1 root 1863: }
1864:
1.1.1.2 root 1865:
1866: /*-----------------------------------------------------------------------*/
1.1.1.11 root 1867: /**
1868: * Store resolution on each line (used to test if mixed low/medium resolutions)
1869: */
1.1.1.7 root 1870: static void Video_StoreResolution(int y)
1.1 root 1871: {
1.1.1.11 root 1872: Uint8 res;
1873: int Mask;
1.1 root 1874:
1.1.1.11 root 1875: /* Clear resolution, and set with current value */
1876: if (!(bUseHighRes || bUseVDIRes))
1877: {
1.1.1.20! root 1878: if ( y >= HBL_PALETTE_MASKS ) /* we're above the limit (res was switched to mono for more than 1 VBL in color mode ?) */
! 1879: {
! 1880: // fprintf ( stderr , "store res %d line %d hbl %d %x %x %d\n" , res , y , nHBL, Mask , HBLPaletteMasks[y] , sizeof(HBLPalettes) );
! 1881: y = HBL_PALETTE_MASKS - 1; /* store in the last palette line */
! 1882: }
! 1883:
1.1.1.11 root 1884: HBLPaletteMasks[y] &= ~(0x3<<16);
1885: res = IoMem_ReadByte(0xff8260)&0x3;
1886:
1.1.1.15 root 1887: Mask = ShifterFrame.ShifterLines[ y+nFirstVisibleHbl ].BorderMask;
1.1.1.11 root 1888:
1.1.1.15 root 1889: if ( Mask & BORDERMASK_OVERSCAN_MED_RES ) /* special case for med res to render the overscan line */
1890: res = 1; /* med res instead of low res */
1.1.1.11 root 1891: else if ( Mask != BORDERMASK_NONE ) /* border removal : assume low res for the whole line */
1892: res = 0;
1.1.1.2 root 1893:
1.1.1.11 root 1894: HBLPaletteMasks[y] |= PALETTEMASK_RESOLUTION|((Uint32)res)<<16;
1895:
1896: #if 0
1897: if ( ( Mask == BORDERMASK_NONE ) /* no border trick, store the current res */
1898: || ( res == 0 ) || ( res == 1 ) ) /* if border trick, ignore passage to hi res */
1899: HBLPaletteMasks[y] |= PALETTEMASK_RESOLUTION|((Uint32)res)<<16;
1900: else /* border removal or hi res : assume low res for the whole line */
1901: HBLPaletteMasks[y] |= (0)<<16;
1902:
1.1.1.15 root 1903: /* special case for med res to render the overscan line */
1904: if ( Mask & BORDERMASK_OVERSCAN_MED_RES )
1905: HBLPaletteMasks[y] |= PALETTEMASK_RESOLUTION|((Uint32)1)<<16; /* med res instead of low res */
1.1.1.11 root 1906: #endif
1.1 root 1907:
1.1.1.11 root 1908: // fprintf ( stderr , "store res %d line %d %x %x\n" , res , y , Mask , HBLPaletteMasks[y] );
1909: }
1.1.1.9 root 1910: }
1911:
1912:
1913: /*-----------------------------------------------------------------------*/
1.1.1.11 root 1914: /**
1915: * Copy one line of monochrome screen into buffer for conversion later.
1916: */
1917: static void Video_CopyScreenLineMono(void)
1918: {
1919: /* Copy one line - 80 bytes in ST high resolution */
1920: memcpy(pSTScreen, pVideoRaster, SCREENBYTES_MONOLINE);
1921: pVideoRaster += SCREENBYTES_MONOLINE;
1922:
1923: /* Handle STE fine scrolling (HWScrollCount is zero on ST). */
1924: if (HWScrollCount)
1925: {
1926: Uint16 *pScrollAdj;
1927: int nNegScrollCnt;
1928:
1929: pScrollAdj = (Uint16 *)pSTScreen;
1930: nNegScrollCnt = 16 - HWScrollCount;
1931:
1932: /* Shift the whole line by the given scroll count */
1933: while ((Uint8*)pScrollAdj < pSTScreen + SCREENBYTES_MONOLINE-2)
1934: {
1935: do_put_mem_word(pScrollAdj, (do_get_mem_word(pScrollAdj) << HWScrollCount)
1936: | (do_get_mem_word(pScrollAdj+1) >> nNegScrollCnt));
1937: ++pScrollAdj;
1938: }
1939:
1940: /* Handle the last 16 pixels of the line */
1941: do_put_mem_word(pScrollAdj, (do_get_mem_word(pScrollAdj) << HWScrollCount)
1942: | (do_get_mem_word(pVideoRaster) >> nNegScrollCnt));
1943:
1944: /* HW scrolling advances Shifter video counter by one */
1945: pVideoRaster += 1 * 2;
1946: }
1947:
1948: /* LineWidth is zero on ST. */
1949: /* On STE, the Shifter skips the given amount of words. */
1950: pVideoRaster += LineWidth*2;
1951:
1952: /* On STE, handle modifications of the video counter address $ff8205/07/09 */
1953: /* that occurred while the display was already ON */
1.1.1.16 root 1954: if ( VideoCounterDelayedOffset != 0 )
1.1.1.11 root 1955: {
1.1.1.16 root 1956: pVideoRaster += ( VideoCounterDelayedOffset & ~1 );
1957: VideoCounterDelayedOffset = 0;
1.1.1.11 root 1958: }
1.1.1.16 root 1959:
1960: if ( pVideoRasterDelayed != NULL )
1.1.1.11 root 1961: {
1.1.1.16 root 1962: pVideoRaster = pVideoRasterDelayed;
1963: pVideoRasterDelayed = NULL;
1.1.1.11 root 1964: }
1965:
1966: /* On STE, if we wrote to the hwscroll register, we set the */
1967: /* new value here, once the current line was processed */
1968: if ( NewHWScrollCount >= 0 )
1969: {
1970: HWScrollCount = NewHWScrollCount;
1971: NewHWScrollCount = -1;
1972: }
1973:
1974: /* On STE, if we wrote to the linewidth register, we set the */
1975: /* new value here, once the current line was processed */
1976: if ( NewLineWidth >= 0 )
1977: {
1978: LineWidth = NewLineWidth;
1979: NewLineWidth = -1;
1980: }
1981:
1982: /* Each screen line copied to buffer is always same length */
1983: pSTScreen += SCREENBYTES_MONOLINE;
1984: }
1985:
1986:
1987: /*-----------------------------------------------------------------------*/
1988: /**
1989: * Copy one line of color screen into buffer for conversion later.
1990: * Possible lines may be top/bottom border, and/or left/right borders.
1991: */
1.1.1.9 root 1992: static void Video_CopyScreenLineColor(void)
1993: {
1.1.1.15 root 1994: int LineBorderMask;
1.1.1.11 root 1995: int VideoOffset = 0;
1996: int STF_PixelScroll = 0;
1.1.1.14 root 1997: int LineRes;
1.1.1.17 root 1998: Uint8 *pVideoRasterEndLine; /* addr of the last byte copied from pVideoRaster to pSTScreen (for HWScrollCount) */
1999: int i;
1.1.1.14 root 2000:
1.1.1.15 root 2001: LineBorderMask = ShifterFrame.ShifterLines[ nHBL ].BorderMask;
1.1.1.16 root 2002: STF_PixelScroll = ShifterFrame.ShifterLines[ nHBL ].DisplayPixelShift;
1.1.1.15 root 2003:
2004: /* Get resolution for this line (in case of mixed low/med screen) */
1.1.1.20! root 2005: i = nHBL-nFirstVisibleHbl;
! 2006: if ( i >= HBL_PALETTE_MASKS )
! 2007: i = HBL_PALETTE_MASKS - 1;
! 2008: LineRes = ( HBLPaletteMasks[i] >> 16 ) & 1; /* 0=low res 1=med res */
1.1.1.11 root 2009:
1.1.1.16 root 2010: //fprintf(stderr , "copy line %d start %d end %d 0x%x 0x%x\n" , nHBL, nStartHBL, nEndHBL, LineBorderMask, pVideoRaster - STRam);
1.1.1.11 root 2011:
2012: /* If left border is opened, we need to compensate one missing word in low res (1 plan) */
1.1.1.15 root 2013: /* If overscan is in med res, the offset is variable */
2014: if ( LineBorderMask & BORDERMASK_OVERSCAN_MED_RES )
2015: VideoOffset = - ( ( LineBorderMask >> 20 ) & 0x0f ); /* No Cooper=0 PYM=-2 in med res overscan */
1.1.1.11 root 2016:
2017: else if ( LineBorderMask & BORDERMASK_LEFT_OFF )
1.1.1.18 root 2018: {
2019: #ifdef SCROLL2_4PX
2020: int ShiftPixels = 0;
2021:
2022: if ( STF_PixelScroll == 13 ) { VideoOffset = 2; ShiftPixels = 8; }
2023: else if ( STF_PixelScroll == 9 ) { VideoOffset = 0; ShiftPixels = 8; }
2024: else if ( STF_PixelScroll == 5 ) { VideoOffset = -2; ShiftPixels = 8; }
2025: else if ( STF_PixelScroll == 1 ) { VideoOffset = -4; ShiftPixels = 8; }
2026:
2027: else VideoOffset = -2; /* Normal low res left border removal without 4 pixels scrolling */
2028:
2029: STF_PixelScroll -= ShiftPixels;
2030: #else
1.1.1.14 root 2031: VideoOffset = -2; /* always 2 bytes in low res overscan */
1.1.1.18 root 2032: #endif
2033: }
1.1.1.11 root 2034:
1.1.1.16 root 2035: else if ( LineBorderMask & BORDERMASK_LEFT_OFF_2_STE )
2036: VideoOffset = -4; /* 4 first bytes of the line are not shown */
2037:
1.1.1.11 root 2038: /* Handle 4 pixels hardware scrolling ('ST Cnx' demo in 'Punish Your Machine') */
2039: /* Depending on the number of pixels, we need to compensate for some skipped words */
1.1.1.15 root 2040: else if ( LineBorderMask & BORDERMASK_LEFT_OFF_MED )
1.1.1.11 root 2041: {
1.1.1.16 root 2042: if ( STF_PixelScroll == 13 ) VideoOffset = 2;
2043: else if ( STF_PixelScroll == 9 ) VideoOffset = 0;
2044: else if ( STF_PixelScroll == 5 ) VideoOffset = -2;
2045: else if ( STF_PixelScroll == 1 ) VideoOffset = -4;
1.1.1.11 root 2046: else VideoOffset = 0; /* never used ? */
2047:
1.1.1.16 root 2048: STF_PixelScroll -= 8; /* removing left border in mid res also shifts display to the left */
1.1.1.11 root 2049: // fprintf(stderr , "scr off %d %d\n" , STF_PixelScroll , VideoOffset);
2050: }
2051:
1.1.1.13 root 2052:
1.1.1.11 root 2053: /* Is total blank line? I.e. top/bottom border? */
1.1.1.18 root 2054: if ((nHBL < nStartHBL) || (nHBL >= nEndHBL + BlankLines)
1.1.1.15 root 2055: || (LineBorderMask & BORDERMASK_EMPTY_LINE))
1.1.1.11 root 2056: {
2057: /* Clear line to color '0' */
2058: memset(pSTScreen, 0, SCREENBYTES_LINE);
2059: }
2060: else
2061: {
1.1.1.18 root 2062: /* Does have left border ? */
1.1.1.16 root 2063: if ( LineBorderMask & ( BORDERMASK_LEFT_OFF | BORDERMASK_LEFT_OFF_MED ) ) /* bigger line by 26 bytes on the left */
1.1.1.11 root 2064: {
2065: pVideoRaster += BORDERBYTES_LEFT-SCREENBYTES_LEFT+VideoOffset;
2066: memcpy(pSTScreen, pVideoRaster, SCREENBYTES_LEFT);
2067: pVideoRaster += SCREENBYTES_LEFT;
2068: }
1.1.1.16 root 2069: else if ( LineBorderMask & BORDERMASK_LEFT_OFF_2_STE ) /* bigger line by 20 bytes on the left (STE specific) */
2070: { /* bytes 0-3 are not shown, only next 16 bytes (32 pixels, 4 bitplanes) */
2071: if ( SCREENBYTES_LEFT > BORDERBYTES_LEFT_2_STE )
2072: {
2073: memset ( pSTScreen, 0, SCREENBYTES_LEFT-BORDERBYTES_LEFT_2_STE+4 ); /* clear unused pixels + bytes 0-3 */
2074: memcpy ( pSTScreen+SCREENBYTES_LEFT-BORDERBYTES_LEFT_2_STE+4, pVideoRaster+VideoOffset+4, BORDERBYTES_LEFT_2_STE-4 );
2075: }
2076: else
2077: memcpy ( pSTScreen, pVideoRaster+BORDERBYTES_LEFT_2_STE-SCREENBYTES_LEFT+VideoOffset, SCREENBYTES_LEFT );
2078:
2079: pVideoRaster += BORDERBYTES_LEFT_2_STE+VideoOffset;
2080: }
2081: else if (LineBorderMask & BORDERMASK_LEFT_PLUS_2) /* bigger line by 2 bytes on the left */
1.1.1.11 root 2082: {
1.1.1.16 root 2083: if ( SCREENBYTES_LEFT > 2 )
2084: {
2085: memset(pSTScreen,0,SCREENBYTES_LEFT-2); /* clear unused pixels */
2086: memcpy(pSTScreen+SCREENBYTES_LEFT-2, pVideoRaster, 2);
2087: }
2088: else
2089: { /* nothing to copy, left border is not large enough */
2090: }
2091:
1.1.1.11 root 2092: pVideoRaster += 2;
2093: }
1.1.1.16 root 2094: else if (bSteBorderFlag) /* bigger line by 8 bytes on the left (STE specific) */
1.1.1.12 root 2095: {
1.1.1.16 root 2096: if ( SCREENBYTES_LEFT > 4*2 )
2097: {
2098: memset(pSTScreen,0,SCREENBYTES_LEFT-4*2); /* clear unused pixels */
2099: memcpy(pSTScreen+SCREENBYTES_LEFT-4*2, pVideoRaster, 4*2);
2100: }
2101: else
2102: { /* nothing to copy, left border is not large enough */
2103: }
2104:
1.1.1.12 root 2105: pVideoRaster += 4*2;
2106: }
1.1.1.11 root 2107: else
1.1.1.16 root 2108: memset(pSTScreen,0,SCREENBYTES_LEFT); /* left border not removed, clear to color '0' */
1.1.1.11 root 2109:
2110: /* Short line due to hires in the middle ? */
2111: if (LineBorderMask & BORDERMASK_STOP_MIDDLE)
2112: {
2113: /* 106 bytes less in the line */
2114: memcpy(pSTScreen+SCREENBYTES_LEFT, pVideoRaster, SCREENBYTES_MIDDLE-106);
1.1.1.12 root 2115: memset(pSTScreen+SCREENBYTES_LEFT+SCREENBYTES_MIDDLE-106, 0, 106); /* clear unused pixels */
1.1.1.11 root 2116: pVideoRaster += (SCREENBYTES_MIDDLE-106);
2117: }
2118: else
2119: {
2120: /* normal middle part (160 bytes) */
2121: memcpy(pSTScreen+SCREENBYTES_LEFT, pVideoRaster, SCREENBYTES_MIDDLE);
2122: pVideoRaster += SCREENBYTES_MIDDLE;
2123: }
2124:
2125: /* Does have right border ? */
2126: if (LineBorderMask & BORDERMASK_RIGHT_OFF)
2127: {
2128: memcpy(pSTScreen+SCREENBYTES_LEFT+SCREENBYTES_MIDDLE, pVideoRaster, SCREENBYTES_RIGHT);
1.1.1.17 root 2129: pVideoRasterEndLine = pVideoRaster + SCREENBYTES_RIGHT;
1.1.1.16 root 2130: pVideoRaster += BORDERBYTES_RIGHT;
1.1.1.11 root 2131: }
2132: else if (LineBorderMask & BORDERMASK_RIGHT_MINUS_2)
2133: {
2134: /* Shortened line by 2 bytes */
2135: memset(pSTScreen+SCREENBYTES_LEFT+SCREENBYTES_MIDDLE-2, 0, SCREENBYTES_RIGHT+2);
2136: pVideoRaster -= 2;
1.1.1.17 root 2137: pVideoRasterEndLine = pVideoRaster;
1.1.1.11 root 2138: }
2139: else
2140: {
2141: /* Simply clear right border to '0' */
2142: memset(pSTScreen+SCREENBYTES_LEFT+SCREENBYTES_MIDDLE,0,SCREENBYTES_RIGHT);
1.1.1.17 root 2143: pVideoRasterEndLine = pVideoRaster;
1.1.1.11 root 2144: }
2145:
1.1.1.18 root 2146: /* Shifter read bytes and borders can change, but display is blank, so finally clear the line with color 0 */
2147: if (LineBorderMask & BORDERMASK_BLANK_LINE)
2148: memset(pSTScreen, 0, SCREENBYTES_LINE);
2149:
1.1.1.11 root 2150: /* Full right border removal up to the end of the line (cycle 512) */
2151: if (LineBorderMask & BORDERMASK_RIGHT_OFF_FULL)
2152: pVideoRaster += BORDERBYTES_RIGHT_FULL;
2153:
2154: /* Correct the offset for pVideoRaster from BORDERMASK_LEFT_OFF above if needed */
2155: pVideoRaster -= VideoOffset; /* VideoOffset is 0 or -2 */
2156:
2157:
2158: /* STE specific */
1.1.1.13 root 2159: if (!bSteBorderFlag && HWScrollCount) /* Handle STE fine scrolling (HWScrollCount is zero on ST) */
1.1.1.11 root 2160: {
1.1.1.13 root 2161: Uint16 *pScrollAdj; /* Pointer to actual position in line */
1.1.1.11 root 2162: int nNegScrollCnt;
1.1.1.13 root 2163: Uint16 *pScrollEndAddr; /* Pointer to end of the line */
1.1.1.11 root 2164:
2165: nNegScrollCnt = 16 - HWScrollCount;
2166: if (LineBorderMask & BORDERMASK_LEFT_OFF)
2167: pScrollAdj = (Uint16 *)pSTScreen;
1.1.1.16 root 2168: else if (LineBorderMask & BORDERMASK_LEFT_OFF_2_STE)
2169: {
2170: if ( SCREENBYTES_LEFT > BORDERBYTES_LEFT_2_STE )
1.1.1.17 root 2171: pScrollAdj = (Uint16 *)(pSTScreen+8); /* don't scroll the 8 first bytes (keep color 0)*/
1.1.1.16 root 2172: else
2173: pScrollAdj = (Uint16 *)pSTScreen; /* we render less bytes on screen than a real ST, scroll the whole line */
2174: }
1.1.1.11 root 2175: else
2176: pScrollAdj = (Uint16 *)(pSTScreen + SCREENBYTES_LEFT);
1.1.1.16 root 2177:
1.1.1.17 root 2178: /* When shifting the line to the left, we will have 'HWScrollCount' missing pixels at */
2179: /* the end of the line. We must complete these last 16 pixels with pixels from the */
2180: /* video counter last accessed value in pVideoRasterEndLine. */
2181: /* There're 2 passes : */
2182: /* - shift whole line except the last 16 pixels */
2183: /* - shift/complete the last 16 pixels */
2184:
2185: /* Addr of the last byte to shift in the 1st pass (excluding the last 16 pixels of the line) */
1.1.1.11 root 2186: if (LineBorderMask & BORDERMASK_RIGHT_OFF)
2187: pScrollEndAddr = (Uint16 *)(pSTScreen + SCREENBYTES_LINE - 8);
2188: else
2189: pScrollEndAddr = (Uint16 *)(pSTScreen + SCREENBYTES_LEFT + SCREENBYTES_MIDDLE - 8);
2190:
1.1.1.17 root 2191:
2192: if ( LineRes == 1 ) /* med res */
1.1.1.11 root 2193: {
1.1.1.15 root 2194: /* in med res, 16 pixels are 4 bytes, not 8 as in low res, so only the last 4 bytes need a special case */
1.1.1.17 root 2195: pScrollEndAddr += 2; /* 2 Uint16 = 4 bytes = 16 pixels */
1.1.1.14 root 2196:
1.1.1.17 root 2197: /* Shift the whole line to the left by the given scroll count (except the last 16 pixels) */
1.1.1.14 root 2198: while (pScrollAdj < pScrollEndAddr)
2199: {
2200: do_put_mem_word(pScrollAdj, (do_get_mem_word(pScrollAdj) << HWScrollCount)
2201: | (do_get_mem_word(pScrollAdj+2) >> nNegScrollCnt));
2202: ++pScrollAdj;
2203: }
1.1.1.17 root 2204: /* Handle the last 16 pixels of the line (complete the line with pixels from pVideoRasterEndLine) */
2205: for ( i=0 ; i<2 ; i++ )
2206: do_put_mem_word(pScrollAdj+i, (do_get_mem_word(pScrollAdj+i) << HWScrollCount)
2207: | (do_get_mem_word(pVideoRasterEndLine+i*2) >> nNegScrollCnt));
1.1.1.14 root 2208:
2209: /* Depending on whether $ff8264 or $ff8265 was used to scroll, */
2210: /* we prefetched 16 pixel (4 bytes) */
1.1.1.13 root 2211: if ( HWScrollPrefetch == 1 ) /* $ff8265 prefetches 16 pixels */
2212: pVideoRaster += 2 * 2; /* 2 bitplans */
1.1.1.14 root 2213:
2214: /* If scrolling with $ff8264, there's no prefetch, which means display starts */
2215: /* 16 pixels later but still stops at the normal point (eg we display */
2216: /* (320-16) pixels in low res). We shift the whole line 4 bytes to the right to */
2217: /* get the correct result (using memmove, as src/dest are overlapping). */
2218: else
2219: {
2220: if (LineBorderMask & BORDERMASK_RIGHT_OFF)
2221: memmove ( pSTScreen+4 , pSTScreen , SCREENBYTES_LINE - 4 );
2222: else
2223: memmove ( pSTScreen+4 , pSTScreen , SCREENBYTES_LEFT + SCREENBYTES_MIDDLE - 4 );
2224:
2225: memset ( pSTScreen , 0 , 4 ); /* first 16 pixels are color '0' */
2226: }
1.1.1.11 root 2227: }
1.1.1.14 root 2228:
1.1.1.17 root 2229: else /* low res */
1.1.1.11 root 2230: {
1.1.1.17 root 2231: /* Shift the whole line to the left by the given scroll count (except the last 16 pixels) */
1.1.1.11 root 2232: while (pScrollAdj < pScrollEndAddr)
2233: {
2234: do_put_mem_word(pScrollAdj, (do_get_mem_word(pScrollAdj) << HWScrollCount)
2235: | (do_get_mem_word(pScrollAdj+4) >> nNegScrollCnt));
2236: ++pScrollAdj;
2237: }
1.1.1.17 root 2238: /* Handle the last 16 pixels of the line (complete the line with pixels from pVideoRasterEndLine) */
2239: for ( i=0 ; i<4 ; i++ )
2240: do_put_mem_word(pScrollAdj+i, (do_get_mem_word(pScrollAdj+i) << HWScrollCount)
2241: | (do_get_mem_word(pVideoRasterEndLine+i*2) >> nNegScrollCnt));
1.1.1.13 root 2242:
2243: /* Depending on whether $ff8264 or $ff8265 was used to scroll, */
2244: /* we prefetched 16 pixel (8 bytes) */
2245: if ( HWScrollPrefetch == 1 ) /* $ff8265 prefetches 16 pixels */
2246: pVideoRaster += 4 * 2; /* 4 bitplans */
2247:
2248: /* If scrolling with $ff8264, there's no prefetch, which means display starts */
2249: /* 16 pixels later but still stops at the normal point (eg we display */
2250: /* (320-16) pixels in low res). We shift the whole line 8 bytes to the right to */
2251: /* get the correct result (using memmove, as src/dest are overlapping). */
2252: else
2253: {
2254: if (LineBorderMask & BORDERMASK_RIGHT_OFF)
2255: memmove ( pSTScreen+8 , pSTScreen , SCREENBYTES_LINE - 8 );
2256: else
2257: memmove ( pSTScreen+8 , pSTScreen , SCREENBYTES_LEFT + SCREENBYTES_MIDDLE - 8 );
2258:
2259: memset ( pSTScreen , 0 , 8 ); /* first 16 pixels are color '0' */
2260: }
1.1.1.11 root 2261:
2262: /* On STE, when we have a 230 bytes overscan line and HWScrollCount > 0 */
1.1.1.17 root 2263: /* we must read 6 bytes less than expected if scrolling is using prefetching ($ff8265) */
2264: /* (this is not the case for the 224 bytes overscan which is a multiple of 8) */
1.1.1.11 root 2265: if ( (LineBorderMask & BORDERMASK_LEFT_OFF) && (LineBorderMask & BORDERMASK_RIGHT_OFF) )
1.1.1.17 root 2266: {
2267: if ( HWScrollPrefetch == 1 )
2268: pVideoRaster -= 6; /* we don't add 8 bytes (see above), but 2 */
2269: else
2270: pVideoRaster -= 0;
2271: }
1.1.1.11 root 2272:
2273: }
2274: }
2275:
2276: /* LineWidth is zero on ST. */
2277: /* On STE, the Shifter skips the given amount of words. */
2278: pVideoRaster += LineWidth*2;
2279:
2280: /* On STE, handle modifications of the video counter address $ff8205/07/09 */
2281: /* that occurred while the display was already ON */
1.1.1.16 root 2282: if ( VideoCounterDelayedOffset != 0 )
1.1.1.11 root 2283: {
1.1.1.16 root 2284: pVideoRaster += ( VideoCounterDelayedOffset & ~1 );
2285: // fprintf ( stderr , "adjust video counter offset=%d new video=%x\n" , VideoCounterDelayedOffset , pVideoRaster-STRam );
2286: VideoCounterDelayedOffset = 0;
1.1.1.11 root 2287: }
1.1.1.16 root 2288:
2289: if ( pVideoRasterDelayed != NULL )
1.1.1.11 root 2290: {
1.1.1.16 root 2291: pVideoRaster = pVideoRasterDelayed;
2292: // fprintf ( stderr , "adjust video counter const new video=%x\n" , pVideoRaster-STRam );
2293: pVideoRasterDelayed = NULL;
1.1.1.11 root 2294: }
2295:
2296: /* On STE, if we wrote to the hwscroll register, we set the */
2297: /* new value here, once the current line was processed */
2298: if ( NewHWScrollCount >= 0 )
2299: {
2300: HWScrollCount = NewHWScrollCount;
1.1.1.13 root 2301: HWScrollPrefetch = NewHWScrollPrefetch;
1.1.1.11 root 2302: NewHWScrollCount = -1;
1.1.1.13 root 2303: NewHWScrollPrefetch = -1;
2304: }
2305:
2306: /* On STE, if we trigger the left border + 16 pixels trick, we set the */
2307: /* new value here, once the current line was processed */
2308: if ( NewSteBorderFlag >= 0 )
2309: {
2310: if ( NewSteBorderFlag == 0 )
1.1.1.15 root 2311: bSteBorderFlag = false;
1.1.1.13 root 2312: else
1.1.1.15 root 2313: bSteBorderFlag = true;
1.1.1.13 root 2314: NewSteBorderFlag = -1;
1.1.1.11 root 2315: }
2316:
2317: /* On STE, if we wrote to the linewidth register, we set the */
2318: /* new value here, once the current line was processed */
2319: if ( NewLineWidth >= 0 )
2320: {
2321: LineWidth = NewLineWidth;
2322: NewLineWidth = -1;
2323: }
1.1.1.16 root 2324:
2325:
2326: /* Handle 4 pixels hardware scrolling ('ST Cnx' demo in 'Punish Your Machine') */
2327: /* as well as scrolling occuring when removing the left border. */
2328: /* If >0, shift the line by STF_PixelScroll pixels to the right */
2329: /* If <0, shift the line by -STF_PixelScroll pixels to the left */
2330: /* This should be handled after the STE's hardware scrolling as it will scroll */
2331: /* the whole displayed area (while the STE scrolls pixels inside the displayed area) */
2332: if ( STF_PixelScroll > 0 )
2333: {
2334: Uint16 *pScreenLineEnd;
2335: int count;
2336:
2337: pScreenLineEnd = (Uint16 *) ( pSTScreen + SCREENBYTES_LINE - 2 );
1.1.1.17 root 2338: if ( LineRes == 0 ) /* low res */
2339: {
2340: for ( count = 0 ; count < ( SCREENBYTES_LINE - 8 ) / 2 ; count++ , pScreenLineEnd-- )
2341: do_put_mem_word ( pScreenLineEnd , ( ( do_get_mem_word ( pScreenLineEnd - 4 ) << 16 ) | ( do_get_mem_word ( pScreenLineEnd ) ) ) >> STF_PixelScroll );
2342: /* Handle the first 16 pixels of the line (add color 0 pixels to the extreme left) */
2343: do_put_mem_word ( pScreenLineEnd-0 , ( do_get_mem_word ( pScreenLineEnd-0 ) >> STF_PixelScroll ) );
2344: do_put_mem_word ( pScreenLineEnd-1 , ( do_get_mem_word ( pScreenLineEnd-1 ) >> STF_PixelScroll ) );
2345: do_put_mem_word ( pScreenLineEnd-2 , ( do_get_mem_word ( pScreenLineEnd-2 ) >> STF_PixelScroll ) );
2346: do_put_mem_word ( pScreenLineEnd-3 , ( do_get_mem_word ( pScreenLineEnd-3 ) >> STF_PixelScroll ) );
2347: }
2348: else /* med res */
2349: {
2350: for ( count = 0 ; count < ( SCREENBYTES_LINE - 4 ) / 2 ; count++ , pScreenLineEnd-- )
2351: do_put_mem_word ( pScreenLineEnd , ( ( do_get_mem_word ( pScreenLineEnd - 2 ) << 16 ) | ( do_get_mem_word ( pScreenLineEnd ) ) ) >> STF_PixelScroll );
2352: /* Handle the first 16 pixels of the line (add color 0 pixels to the extreme left) */
2353: do_put_mem_word ( pScreenLineEnd-0 , ( do_get_mem_word ( pScreenLineEnd-0 ) >> STF_PixelScroll ) );
2354: do_put_mem_word ( pScreenLineEnd-1 , ( do_get_mem_word ( pScreenLineEnd-1 ) >> STF_PixelScroll ) );
2355: }
1.1.1.16 root 2356: }
2357: else if ( STF_PixelScroll < 0 )
2358: {
2359: Uint16 *pScreenLineStart;
2360: int count;
2361:
2362: STF_PixelScroll = -STF_PixelScroll;
2363: pScreenLineStart = (Uint16 *)pSTScreen;
1.1.1.17 root 2364: if ( LineRes == 0 ) /* low res */
2365: {
2366: for ( count = 0 ; count < ( SCREENBYTES_LINE - 8 ) / 2 ; count++ , pScreenLineStart++ )
2367: do_put_mem_word ( pScreenLineStart , ( ( do_get_mem_word ( pScreenLineStart ) << STF_PixelScroll ) | ( do_get_mem_word ( pScreenLineStart + 4 ) >> (16-STF_PixelScroll) ) ) );
2368: /* Handle the last 16 pixels of the line (add color 0 pixels to the extreme right) */
2369: do_put_mem_word ( pScreenLineStart+0 , ( do_get_mem_word ( pScreenLineStart+0 ) << STF_PixelScroll ) );
2370: do_put_mem_word ( pScreenLineStart+1 , ( do_get_mem_word ( pScreenLineStart+1 ) << STF_PixelScroll ) );
2371: do_put_mem_word ( pScreenLineStart+2 , ( do_get_mem_word ( pScreenLineStart+2 ) << STF_PixelScroll ) );
2372: do_put_mem_word ( pScreenLineStart+3 , ( do_get_mem_word ( pScreenLineStart+3 ) << STF_PixelScroll ) );
2373: }
2374: else /* med res */
2375: {
2376: for ( count = 0 ; count < ( SCREENBYTES_LINE - 4 ) / 2 ; count++ , pScreenLineStart++ )
2377: do_put_mem_word ( pScreenLineStart , ( ( do_get_mem_word ( pScreenLineStart ) << STF_PixelScroll ) | ( do_get_mem_word ( pScreenLineStart + 2 ) >> (16-STF_PixelScroll) ) ) );
2378: /* Handle the last 16 pixels of the line (add color 0 pixels to the extreme right) */
2379: do_put_mem_word ( pScreenLineStart+0 , ( do_get_mem_word ( pScreenLineStart+0 ) << STF_PixelScroll ) );
2380: do_put_mem_word ( pScreenLineStart+1 , ( do_get_mem_word ( pScreenLineStart+1 ) << STF_PixelScroll ) );
2381: }
1.1.1.16 root 2382: }
1.1.1.11 root 2383: }
2384:
2385: /* Each screen line copied to buffer is always same length */
2386: pSTScreen += SCREENBYTES_LINE;
2387: }
2388:
2389:
2390: /*-----------------------------------------------------------------------*/
2391: /**
2392: * Copy extended GEM resolution screen
2393: */
1.1.1.9 root 2394: static void Video_CopyVDIScreen(void)
1.1 root 2395: {
1.1.1.11 root 2396: /* Copy whole screen, don't care about being exact as for GEM only */
2397: memcpy(pSTScreen, pVideoRaster, ((VDIWidth*VDIPlanes)/8)*VDIHeight);
1.1 root 2398: }
2399:
1.1.1.2 root 2400:
2401: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2402: /**
2403: * Clear raster line table to store changes in palette/resolution on a line
2404: * basic. Called once on VBL interrupt.
2405: */
1.1 root 2406: void Video_SetScreenRasters(void)
2407: {
1.1.1.11 root 2408: pHBLPaletteMasks = HBLPaletteMasks;
2409: pHBLPalettes = HBLPalettes;
2410: memset(pHBLPaletteMasks, 0, sizeof(Uint32)*NUM_VISIBLE_LINES); /* Clear array */
1.1 root 2411: }
2412:
1.1.1.2 root 2413:
2414: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2415: /**
2416: * Set pointers to HBLPalette tables to store correct colours/resolutions
2417: */
1.1.1.9 root 2418: static void Video_SetHBLPaletteMaskPointers(void)
1.1 root 2419: {
1.1.1.15 root 2420: int FrameCycles, HblCounterVideo, LineCycles;
1.1.1.11 root 2421: int Line;
2422:
2423: /* FIXME [NP] We should use Cycles_GetCounterOnWriteAccess, but it wouldn't */
2424: /* work when using multiple accesses instructions like move.l or movem */
1.1.1.15 root 2425: /* To correct this, we assume a delay of 8 cycles (should give a good approximation */
1.1.1.11 root 2426: /* of a move.w or movem.l for example) */
2427: // FrameCycles = Cycles_GetCounterOnWriteAccess(CYCLES_COUNTER_VIDEO);
2428: FrameCycles = Cycles_GetCounter(CYCLES_COUNTER_VIDEO) + 8;
2429:
2430: /* Find 'line' into palette - screen starts 63 lines down, less 29 for top overscan */
1.1.1.15 root 2431: Video_ConvertPosition ( FrameCycles , &HblCounterVideo , &LineCycles );
2432: Line = HblCounterVideo - nFirstVisibleHbl;
1.1.1.11 root 2433:
2434: /* FIXME [NP] if the color change occurs after the last visible pixel of a line */
2435: /* we consider the palette should be modified on the next line. This is quite */
2436: /* a hack, we should handle all color changes through spec512.c to have cycle */
2437: /* accuracy all the time. */
1.1.1.15 root 2438: if ( LineCycles >= LINE_END_CYCLE_NO_RIGHT )
2439: Line++;
1.1.1.11 root 2440:
2441: if (Line < 0) /* Limit to top/bottom of possible visible screen */
2442: Line = 0;
2443: if (Line >= NUM_VISIBLE_LINES)
2444: Line = NUM_VISIBLE_LINES-1;
2445:
2446: /* Store pointers */
2447: pHBLPaletteMasks = &HBLPaletteMasks[Line]; /* Next mask entry */
2448: pHBLPalettes = &HBLPalettes[16*Line]; /* Next colour raster list x16 colours */
1.1 root 2449: }
1.1.1.8 root 2450:
2451:
1.1.1.9 root 2452: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2453: /**
2454: * Set video shifter timing variables according to screen refresh rate.
2455: * Note: The following equation must be satisfied for correct timings:
2456: *
2457: * nCyclesPerLine * nScanlinesPerFrame * nScreenRefreshRate = 8 MHz
2458: */
1.1.1.10 root 2459: static void Video_ResetShifterTimings(void)
2460: {
1.1.1.11 root 2461: Uint8 nSyncByte;
1.1.1.10 root 2462:
1.1.1.11 root 2463: nSyncByte = IoMem_ReadByte(0xff820a);
1.1.1.10 root 2464:
1.1.1.19 root 2465: if ((IoMem_ReadByte(0xff8260) & 3) == 2)
1.1.1.11 root 2466: {
2467: /* 71 Hz, monochrome */
2468: nScreenRefreshRate = 71;
2469: nScanlinesPerFrame = SCANLINES_PER_FRAME_71HZ;
2470: nCyclesPerLine = CYCLES_PER_LINE_71HZ;
1.1.1.13 root 2471: nStartHBL = VIDEO_START_HBL_71HZ;
1.1.1.11 root 2472: nFirstVisibleHbl = FIRST_VISIBLE_HBL_71HZ;
1.1.1.13 root 2473: nLastVisibleHbl = FIRST_VISIBLE_HBL_71HZ + VIDEO_HEIGHT_HBL_MONO;
1.1.1.11 root 2474: }
2475: else if (nSyncByte & 2) /* Check if running in 50 Hz or in 60 Hz */
2476: {
2477: /* 50 Hz */
2478: nScreenRefreshRate = 50;
2479: nScanlinesPerFrame = SCANLINES_PER_FRAME_50HZ;
2480: nCyclesPerLine = CYCLES_PER_LINE_50HZ;
1.1.1.13 root 2481: nStartHBL = VIDEO_START_HBL_50HZ;
1.1.1.11 root 2482: nFirstVisibleHbl = FIRST_VISIBLE_HBL_50HZ;
1.1.1.13 root 2483: nLastVisibleHbl = FIRST_VISIBLE_HBL_50HZ + NUM_VISIBLE_LINES;
1.1.1.11 root 2484: }
2485: else
2486: {
2487: /* 60 Hz */
2488: nScreenRefreshRate = 60;
2489: nScanlinesPerFrame = SCANLINES_PER_FRAME_60HZ;
2490: nCyclesPerLine = CYCLES_PER_LINE_60HZ;
1.1.1.13 root 2491: nStartHBL = VIDEO_START_HBL_60HZ;
1.1.1.11 root 2492: nFirstVisibleHbl = FIRST_VISIBLE_HBL_60HZ;
1.1.1.13 root 2493: nLastVisibleHbl = FIRST_VISIBLE_HBL_60HZ + NUM_VISIBLE_LINES;
1.1.1.11 root 2494: }
2495:
2496: if (bUseHighRes)
2497: {
1.1.1.13 root 2498: nEndHBL = nStartHBL + VIDEO_HEIGHT_HBL_MONO;
1.1.1.11 root 2499: }
2500: else
2501: {
1.1.1.13 root 2502: nEndHBL = nStartHBL + VIDEO_HEIGHT_HBL_COLOR;
1.1.1.11 root 2503: }
2504:
2505: /* Reset freq changes position for the next VBL to come */
1.1.1.13 root 2506: LastCycleScroll8264 = -1;
2507: LastCycleScroll8265 = -1;
1.1.1.15 root 2508:
2509: TimerBEventCountCycleStart = -1; /* reset timer B activation cycle for this VBL */
2510:
2511: LastCycleHblException = -1;
1.1.1.18 root 2512:
2513: BlankLines = 0;
1.1.1.11 root 2514: }
1.1.1.10 root 2515:
2516:
1.1.1.11 root 2517: /*-----------------------------------------------------------------------*/
2518: /**
1.1.1.15 root 2519: * Clear the array indicating the state of each video line.
1.1.1.11 root 2520: */
1.1.1.15 root 2521: static void Video_InitShifterLines ( void )
1.1.1.11 root 2522: {
1.1.1.15 root 2523: int i;
2524:
2525: for ( i=0 ; i<MAX_SCANLINES_PER_FRAME ; i++ )
2526: {
2527: ShifterFrame.ShifterLines[i].BorderMask = 0;
2528: ShifterFrame.ShifterLines[i].DisplayPixelShift = 0;
2529: ShifterFrame.ShifterLines[i].DisplayStartCycle = -1;
2530: }
2531:
2532: ShifterFrame.ShifterLines[0].StartCycle = 0; /* 1st HBL starts at cycle 0 */
1.1.1.10 root 2533: }
2534:
2535:
2536: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2537: /**
2538: * Called on VBL, set registers ready for frame
2539: */
1.1.1.9 root 2540: static void Video_ClearOnVBL(void)
2541: {
1.1.1.11 root 2542: /* New screen, so first HBL */
2543: nHBL = 0;
2544: OverscanMode = OVERSCANMODE_NONE;
2545:
2546: Video_ResetShifterTimings();
2547:
2548: /* Get screen address pointer, aligned to 256 bytes on ST (ie ignore lowest byte) */
2549: VideoBase = (Uint32)IoMem_ReadByte(0xff8201)<<16 | (Uint32)IoMem_ReadByte(0xff8203)<<8;
2550: if (ConfigureParams.System.nMachineType != MACHINE_ST)
2551: {
1.1.1.20! root 2552: /* on STe 2 aligned, on TT 8 aligned. We do STe. */
1.1.1.11 root 2553: VideoBase |= IoMem_ReadByte(0xff820d) & ~1;
2554: }
2555: pVideoRaster = &STRam[VideoBase];
2556: pSTScreen = pFrameBuffer->pSTScreen;
2557:
2558: Video_SetScreenRasters();
1.1.1.15 root 2559: Video_InitShifterLines();
1.1.1.11 root 2560: Spec512_StartVBL();
1.1.1.15 root 2561: Video_StartHBL(); /* Init ShifterFrame.ShifterLines[0] */
1.1.1.11 root 2562: }
2563:
2564:
2565: /*-----------------------------------------------------------------------*/
2566: /**
2567: * Get width, height and bpp according to TT-Resolution
2568: */
2569: void Video_GetTTRes(int *width, int *height, int *bpp)
2570: {
2571: switch (TTRes)
2572: {
2573: case ST_LOW_RES: *width = 320; *height = 200; *bpp = 4; break;
2574: case ST_MEDIUM_RES:*width = 640; *height = 200; *bpp = 2; break;
2575: case ST_HIGH_RES: *width = 640; *height = 400; *bpp = 1; break;
2576: case TT_LOW_RES: *width = 320; *height = 480; *bpp = 8; break;
2577: case TT_MEDIUM_RES:*width = 640; *height = 480; *bpp = 4; break;
2578: case TT_HIGH_RES: *width = 1280; *height = 960; *bpp = 1; break;
2579: default:
2580: fprintf(stderr, "TT res error!\n");
2581: *width = 320; *height = 200; *bpp = 4;
2582: break;
2583: }
2584: }
2585:
2586:
2587: /*-----------------------------------------------------------------------*/
2588: /**
2589: * Convert TT palette to SDL palette
2590: */
2591: static void Video_UpdateTTPalette(int bpp)
2592: {
2593: Uint32 ttpalette, src, dst;
2594: Uint8 r,g,b, lowbyte, highbyte;
2595: Uint16 stcolor, ttcolor;
2596: int i, offset, colors;
2597:
2598: ttpalette = 0xff8400;
2599:
2600: if (!bTTColorsSTSync)
2601: {
2602: /* sync TT ST-palette to TT-palette */
2603: src = 0xff8240; /* ST-palette */
2604: offset = (IoMem_ReadWord(0xff8262) & 0x0f);
1.1.1.13 root 2605: /*fprintf(stderr, "offset: %d\n", offset);*/
1.1.1.11 root 2606: dst = ttpalette + offset * 16*SIZE_WORD;
2607:
2608: for (i = 0; i < 16; i++)
2609: {
2610: stcolor = IoMem_ReadWord(src);
2611: ttcolor = ((stcolor&0x700) << 1) | ((stcolor&0x70) << 1) | ((stcolor&0x7) << 1);
2612: IoMem_WriteWord(dst, ttcolor);
2613: src += SIZE_WORD;
2614: dst += SIZE_WORD;
2615: }
1.1.1.15 root 2616: bTTColorsSTSync = true;
1.1.1.11 root 2617: }
2618:
2619: colors = 1 << bpp;
2620: if (bpp == 1)
2621: {
2622: /* Monochrome mode... palette is hardwired (?) */
2623: HostScreen_setPaletteColor(0, 255, 255, 255);
2624: HostScreen_setPaletteColor(1, 0, 0, 0);
2625: }
2626: else
2627: {
2628: for (i = 0; i < colors; i++)
2629: {
2630: lowbyte = IoMem_ReadByte(ttpalette++);
2631: highbyte = IoMem_ReadByte(ttpalette++);
2632: r = (lowbyte & 0x0f) << 4;
2633: g = (highbyte & 0xf0);
2634: b = (highbyte & 0x0f) << 4;
2635: //printf("%d: (%d,%d,%d)\n", i,r,g,b);
2636: HostScreen_setPaletteColor(i, r,g,b);
2637: }
2638: }
2639:
2640: HostScreen_updatePalette(colors);
1.1.1.15 root 2641: bTTColorsSync = true;
1.1.1.11 root 2642: }
2643:
2644:
2645: /*-----------------------------------------------------------------------*/
2646: /**
1.1.1.13 root 2647: * Update TT palette and blit TT screen using VIDEL code.
2648: * @return true if the screen contents changed
1.1.1.11 root 2649: */
1.1.1.16 root 2650: bool Video_RenderTTScreen(void)
1.1.1.11 root 2651: {
2652: static int nPrevTTRes = -1;
2653: int width, height, bpp;
2654:
2655: Video_GetTTRes(&width, &height, &bpp);
2656: if (TTRes != nPrevTTRes)
2657: {
2658: HostScreen_setWindowSize(width, height, 8);
2659: nPrevTTRes = TTRes;
2660: if (bpp == 1) /* Assert that mono palette will be used in mono mode */
1.1.1.15 root 2661: bTTColorsSync = false;
1.1.1.11 root 2662: }
2663:
2664: /* colors need synching? */
2665: if (!(bTTColorsSync && bTTColorsSTSync))
2666: {
2667: Video_UpdateTTPalette(bpp);
2668: }
2669:
2670: /* Yes, we are abusing the Videl routines for rendering the TT modes! */
2671: if (!HostScreen_renderBegin())
1.1.1.13 root 2672: return false;
1.1.1.16 root 2673: if (nScreenZoomX * nScreenZoomY != 1)
1.1.1.11 root 2674: VIDEL_ConvertScreenZoom(width, height, bpp, width * bpp / 16);
2675: else
2676: VIDEL_ConvertScreenNoZoom(width, height, bpp, width * bpp / 16);
2677: HostScreen_renderEnd();
1.1.1.15 root 2678: HostScreen_update1(false);
1.1.1.13 root 2679:
2680: return true;
1.1.1.11 root 2681: }
2682:
2683:
2684: /*-----------------------------------------------------------------------*/
2685: /**
2686: * Draw screen (either with ST/STE shifter drawing functions or with
2687: * Videl drawing functions)
2688: */
2689: static void Video_DrawScreen(void)
2690: {
2691: /* Skip frame if need to */
1.1.1.13 root 2692: if (nVBLs % (nFrameSkips+1))
1.1.1.11 root 2693: return;
2694:
2695: /* Use extended VDI resolution?
2696: * If so, just copy whole screen on VBL rather than per HBL */
2697: if (bUseVDIRes)
2698: Video_CopyVDIScreen();
2699:
2700: /* Now draw the screen! */
2701: if (ConfigureParams.System.nMachineType == MACHINE_FALCON && !bUseVDIRes)
2702: {
1.1.1.17 root 2703: VIDEL_renderScreen();
1.1.1.11 root 2704: }
2705: else if (ConfigureParams.System.nMachineType == MACHINE_TT && !bUseVDIRes)
2706: {
1.1.1.17 root 2707: Video_RenderTTScreen();
1.1.1.11 root 2708: }
2709: else
1.1.1.13 root 2710: {
2711: /* Before drawing the screen, ensure all unused lines are cleared to color 0 */
2712: /* (this can happen in 60 Hz when hatari is displaying the screen's border) */
2713: /* pSTScreen was set during Video_CopyScreenLineColor */
1.1.1.14 root 2714: if (!bUseVDIRes && nHBL < nLastVisibleHbl)
1.1.1.13 root 2715: memset(pSTScreen, 0, SCREENBYTES_LINE * ( nLastVisibleHbl - nHBL ) );
2716:
1.1.1.17 root 2717: Screen_Draw();
1.1.1.13 root 2718: }
1.1.1.11 root 2719: }
2720:
2721:
2722: /*-----------------------------------------------------------------------*/
2723: /**
1.1.1.15 root 2724: * Start HBL, Timer B and VBL interrupts.
2725: */
2726:
2727:
2728: /**
2729: * Start HBL or Timer B interrupt at position Pos. If position Pos was
2730: * already reached, then the interrupt is set on the next line.
2731: */
2732:
2733: static void Video_AddInterrupt ( int Pos , interrupt_id Handler )
2734: {
2735: int FrameCycles , HblCounterVideo , LineCycles;
2736:
2737: if ( nHBL >= nScanlinesPerFrame )
2738: return; /* don't set a new hbl/timer B if we're on the last line, as the vbl will happen first */
2739:
2740: Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.16 root 2741: //fprintf ( stderr , "add int pos=%d handler=%d LineCycles=%d nCyclesPerLine=%d \n" , Pos , Handler , LineCycles , nCyclesPerLine );
1.1.1.15 root 2742:
2743: if ( LineCycles < Pos ) /* changed before reaching the new Pos on the current line */
1.1.1.16 root 2744: CycInt_AddRelativeInterrupt ( Pos - LineCycles , INT_CPU_CYCLE, Handler );
1.1.1.15 root 2745: else /* Pos will be applied on next line */
1.1.1.16 root 2746: CycInt_AddRelativeInterrupt ( Pos - LineCycles + nCyclesPerLine , INT_CPU_CYCLE, Handler );
1.1.1.15 root 2747: }
2748:
2749:
2750: static void Video_AddInterruptHBL ( int Pos )
2751: {
1.1.1.16 root 2752: //fprintf ( stderr , "add hbl pos=%d\n" , Pos );
1.1.1.15 root 2753: if ( !bUseVDIRes )
2754: Video_AddInterrupt ( Pos , INTERRUPT_VIDEO_HBL );
2755: }
2756:
2757:
2758: void Video_AddInterruptTimerB ( int Pos )
2759: {
1.1.1.16 root 2760: //fprintf ( stderr , "add timerb pos=%d\n" , Pos );
1.1.1.15 root 2761: if ( !bUseVDIRes )
2762: Video_AddInterrupt ( Pos , INTERRUPT_VIDEO_ENDLINE );
2763: }
2764:
2765:
2766: /**
2767: * Add some video interrupts to handle the first HBL and the first Timer B
2768: * in a new VBL. Also add an interrupt to trigger the next VBL.
2769: * This function is called from the VBL, so we use PendingCycleOver to take into account
2770: * the possible delay occurring when the VBL was executed.
1.1.1.16 root 2771: * In monochrome mode (71 Hz) a line is 224 cycles, which means if VBL is delayed
2772: * by a DIVS, FrameCycles can already be > 224 and we need to add an immediate
2773: * interrupt for hbl/timer in the next 4/8 cycles (else crash might happen as
2774: * line 0 processing would be skipped).
1.1.1.11 root 2775: */
1.1.1.15 root 2776: void Video_StartInterrupts ( int PendingCyclesOver )
1.1.1.11 root 2777: {
1.1.1.16 root 2778: int FrameCycles , HblCounterVideo , LineCycles;
2779: int Pos;
2780:
1.1.1.15 root 2781: /* HBL/Timer B are not emulated in VDI mode */
1.1.1.14 root 2782: if (!bUseVDIRes)
2783: {
1.1.1.16 root 2784: Video_GetPosition ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.15 root 2785:
1.1.1.16 root 2786: /* Set Timer B interrupt for line 0 */
2787: Pos = Video_TimerB_GetPos ( 0 );
2788: if ( Pos > FrameCycles ) /* check Pos for line 0 was not already reached */
2789: Video_AddInterruptTimerB ( Pos );
2790: else /* the VBL was delayed by more than 1 HBL, add an immediate timer B */
2791: {
2792: LOG_TRACE(TRACE_VIDEO_VBL , "VBL %d delayed too much video_cyc=%d >= pos=%d for first timer B, add immediate timer B\n" ,
2793: nVBLs , FrameCycles , Pos );
2794: CycInt_AddRelativeInterrupt ( 4 , INT_CPU_CYCLE, INTERRUPT_VIDEO_ENDLINE );
2795: }
2796:
2797: /* Set HBL interrupt for line 0 */
2798: Pos = Video_HBL_GetPos();
2799: if ( Pos > FrameCycles ) /* check Pos for line 0 was not already reached */
2800: Video_AddInterruptHBL ( Pos );
2801: else /* the VBL was delayed by more than 1 HBL, add an immediate HBL */
2802: {
2803: LOG_TRACE(TRACE_VIDEO_VBL , "VBL %d delayed too much video_cyc=%d >= pos=%d for first HBL, add immediate HBL\n" ,
2804: nVBLs , FrameCycles , Pos );
2805: CycInt_AddRelativeInterrupt ( 8 , INT_CPU_CYCLE, INTERRUPT_VIDEO_HBL ); /* use 8 instead of 4 to happen after immediate timer b */
2806: }
1.1.1.14 root 2807: }
1.1.1.15 root 2808:
2809: /* TODO replace CYCLES_PER_FRAME */
1.1.1.16 root 2810: CyclesPerVBL = CYCLES_PER_FRAME;
1.1.1.18 root 2811: /* Note: Refresh rate less than 50 Hz does not make sense! */
2812: assert(CyclesPerVBL <= CPU_FREQ/49);
2813: /* Add new VBL interrupt: */
1.1.1.16 root 2814: CycInt_AddRelativeInterrupt(CyclesPerVBL - PendingCyclesOver, INT_CPU_CYCLE, INTERRUPT_VIDEO_VBL);
1.1.1.11 root 2815: }
2816:
2817:
2818: /*-----------------------------------------------------------------------*/
2819: /**
1.1.1.15 root 2820: * VBL interrupt : set new interrupts, draw screen, generate sound,
2821: * reset counters, ...
1.1.1.11 root 2822: */
1.1.1.15 root 2823: void Video_InterruptHandler_VBL ( void )
1.1.1.11 root 2824: {
2825: int PendingCyclesOver;
1.1.1.9 root 2826:
1.1.1.11 root 2827: /* Store cycles we went over for this frame(this is our inital count) */
2828: PendingCyclesOver = -INT_CONVERT_FROM_INTERNAL ( PendingInterruptCount , INT_CPU_CYCLE ); /* +ve */
1.1.1.10 root 2829:
1.1.1.11 root 2830: /* Remove this interrupt from list and re-order */
1.1.1.16 root 2831: CycInt_AcknowledgeInterrupt();
1.1.1.9 root 2832:
1.1.1.14 root 2833: /* Increment the vbl jitter index */
2834: VblJitterIndex++;
1.1.1.20! root 2835: VblJitterIndex %= VBL_JITTER_ARRAY_SIZE;
1.1.1.14 root 2836:
1.1.1.11 root 2837: /* Set frame cycles, used for Video Address */
1.1.1.13 root 2838: Cycles_SetCounter(CYCLES_COUNTER_VIDEO, PendingCyclesOver + VblVideoCycleOffset);
1.1.1.9 root 2839:
1.1.1.11 root 2840: /* Clear any key presses which are due to be de-bounced (held for one ST frame) */
2841: Keymap_DebounceAllKeys();
1.1.1.9 root 2842:
1.1.1.11 root 2843: Video_DrawScreen();
1.1.1.9 root 2844:
1.1.1.11 root 2845: /* Check printer status */
2846: Printer_CheckIdleStatus();
2847:
2848: /* Update counter for number of screen refreshes per second */
2849: nVBLs++;
2850: /* Set video registers for frame */
2851: Video_ClearOnVBL();
1.1.1.15 root 2852:
1.1.1.17 root 2853: /* Videl Vertical counter reset (To be removed when Videl emulation is finished) */
2854: if (ConfigureParams.System.nMachineType == MACHINE_FALCON) {
2855: vfc_counter = 0;
2856: }
2857:
1.1.1.15 root 2858: /* Since we don't execute HBL functions in VDI mode, we've got to
2859: * initialize the first HBL palette here when VDI mode is enabled. */
2860: if (bUseVDIRes)
2861: Video_StoreFirstLinePalette();
2862:
2863: /* Start VBL, HBL and Timer B interrupts (this must be done after resetting
2864: * video cycle counter setting default freq values in Video_ClearOnVBL) */
2865: Video_StartInterrupts(PendingCyclesOver);
2866:
2867: /* Act on shortcut keys */
2868: ShortCut_ActKey();
2869:
1.1.1.16 root 2870: /* Record video frame is necessary */
2871: if ( bRecordingAvi )
2872: Avi_RecordVideoStream ();
2873:
1.1.1.11 root 2874: /* Store off PSG registers for YM file, is enabled */
2875: YMFormat_UpdateRecording();
2876: /* Generate 1/50th second of sound sample data, to be played by sound thread */
2877: Sound_Update_VBL();
2878:
1.1.1.15 root 2879: LOG_TRACE(TRACE_VIDEO_VBL , "VBL %d video_cyc=%d pending_cyc=%d jitter=%d\n" ,
1.1.1.14 root 2880: nVBLs , Cycles_GetCounter(CYCLES_COUNTER_VIDEO) , PendingCyclesOver , VblJitterArray[ VblJitterIndex ] );
1.1.1.11 root 2881:
1.1.1.16 root 2882: M68000_Exception(EXCEPTION_VBLANK, M68000_EXC_SRC_AUTOVEC); /* Vertical blank interrupt, level 4! */
1.1.1.11 root 2883:
2884: Main_WaitOnVbl();
1.1.1.9 root 2885: }
2886:
2887:
2888: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2889: /**
1.1.1.13 root 2890: * Write to video address base high, med and low register (0xff8201/03/0d).
2891: * On STE, when a program writes to high or med registers, base low register
2892: * is reset to zero.
1.1.1.11 root 2893: */
1.1.1.9 root 2894: void Video_ScreenBaseSTE_WriteByte(void)
2895: {
1.1.1.13 root 2896: if ( ( IoAccessCurrentAddress == 0xff8201 ) || ( IoAccessCurrentAddress == 0xff8203 ) )
2897: IoMem[0xff820d] = 0; /* Reset screen base low register */
1.1.1.8 root 2898:
1.1.1.15 root 2899: if (LOG_TRACE_LEVEL(TRACE_VIDEO_STE))
1.1.1.11 root 2900: {
1.1.1.15 root 2901: int FrameCycles, HblCounterVideo, LineCycles;
2902:
2903: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
2904:
2905: LOG_TRACE_PRINT ( "write ste video base=0x%x video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n" ,
1.1.1.13 root 2906: (IoMem[0xff8201]<<16)+(IoMem[0xff8203]<<8)+IoMem[0xff820d] ,
1.1.1.15 root 2907: FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.11 root 2908: }
1.1.1.8 root 2909: }
2910:
2911: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2912: /**
2913: * Read video address counter and update ff8205/07/09
2914: */
2915: void Video_ScreenCounter_ReadByte(void)
1.1.1.8 root 2916: {
1.1.1.11 root 2917: Uint32 addr;
1.1.1.8 root 2918:
1.1.1.11 root 2919: addr = Video_CalculateAddress(); /* get current video address */
2920: IoMem[0xff8205] = ( addr >> 16 ) & 0xff;
2921: IoMem[0xff8207] = ( addr >> 8 ) & 0xff;
2922: IoMem[0xff8209] = addr & 0xff;
1.1.1.8 root 2923: }
2924:
1.1.1.9 root 2925: /*-----------------------------------------------------------------------*/
1.1.1.11 root 2926: /**
2927: * Write to video address counter (0xff8205, 0xff8207 and 0xff8209).
2928: * Called on STE only and like with base address, you cannot set lowest bit.
1.1.1.16 root 2929: *
2930: * As Hatari processes/converts one complete video line at a time, we have 3 cases :
2931: * - If display has not started yet for this line (left border), we can change pVideoRaster now.
2932: * We must take into account that the MMU starts 16 cycles earlier when hscroll is used.
2933: * - If display has stopped for this line (right border), we will change pVideoRaster
2934: * in Video_CopyScreenLineColor using pVideoRasterDelayed once the line has been processed.
2935: * - If the write is made while display is on, then we must compute an offset of what
2936: * the new address should have been, to correctly emulate the video address at the
2937: * end of the line while taking into account the fact that the video pointer is incrementing
2938: * during the active part of the line (this is the most "tricky" case)
2939: *
2940: * To compute the new address, we must change only the byte that was modified and keep the two others ones.
1.1.1.11 root 2941: */
1.1.1.9 root 2942: void Video_ScreenCounter_WriteByte(void)
2943: {
1.1.1.11 root 2944: Uint8 AddrByte;
1.1.1.16 root 2945: Uint32 addr_cur;
2946: Uint32 addr_new = 0;
1.1.1.15 root 2947: int FrameCycles, HblCounterVideo, LineCycles;
1.1.1.13 root 2948: int Delayed;
1.1.1.16 root 2949: int MMUStartCycle;
1.1.1.11 root 2950:
1.1.1.15 root 2951: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.11 root 2952:
2953: AddrByte = IoMem[ IoAccessCurrentAddress ];
2954:
1.1.1.16 root 2955: /* Get current video address from the shifter */
2956: addr_cur = Video_CalculateAddress();
2957: /* Correct the address in case a modification of ff8205/07/09 was already delayed */
2958: addr_new = addr_cur + VideoCounterDelayedOffset;
2959: /* Correct the address in case video counter was already modified in the right border */
2960: if ( pVideoRasterDelayed != NULL )
2961: addr_new = pVideoRasterDelayed - STRam;
2962:
2963: /* addr_new should now be the same as on a real STE */
2964: /* Compute the new video address with one modified byte */
2965: if ( IoAccessCurrentAddress == 0xff8205 )
1.1.1.20! root 2966: addr_new = ( addr_new & 0x00ffff ) | ( ( AddrByte & 0x3f ) << 16 );
1.1.1.16 root 2967: else if ( IoAccessCurrentAddress == 0xff8207 )
2968: addr_new = ( addr_new & 0xff00ff ) | ( AddrByte << 8 );
2969: else if ( IoAccessCurrentAddress == 0xff8209 )
2970: addr_new = ( addr_new & 0xffff00 ) | ( AddrByte );
2971:
2972: MMUStartCycle = Video_GetMMUStartCycle ( ShifterFrame.ShifterLines[ nHBL ].DisplayStartCycle );
2973:
1.1.1.11 root 2974: /* If display has not started, we can still modify pVideoRaster */
1.1.1.16 root 2975: /* We must also check the write does not overlap the end of the line (to be sure Video_EndHBL is called first) */
2976: if ( ( ( LineCycles <= MMUStartCycle ) && ( nHBL == HblCounterVideo ) )
1.1.1.18 root 2977: || ( nHBL < nStartHBL ) || ( nHBL >= nEndHBL + BlankLines ) )
1.1.1.11 root 2978: {
1.1.1.16 root 2979: pVideoRaster = &STRam[addr_new & ~1]; /* set new video address */
2980: VideoCounterDelayedOffset = 0;
2981: pVideoRasterDelayed = NULL;
1.1.1.15 root 2982: Delayed = false;
1.1.1.11 root 2983: }
2984:
1.1.1.16 root 2985: /* Display is OFF (right border) but we can't change pVideoRaster now, we must process Video_CopyScreenLineColor first */
1.1.1.18 root 2986: else if ( ( nHBL >= nStartHBL ) && ( nHBL < nEndHBL + BlankLines ) /* line should be active */
1.1.1.16 root 2987: && ( ( LineCycles > ShifterFrame.ShifterLines[ nHBL ].DisplayEndCycle ) /* we're in the right border */
2988: || ( HblCounterVideo == nHBL+1 ) ) ) /* or the write overlaps the next line and Video_EndHBL was not called yet */
2989: {
2990: VideoCounterDelayedOffset = 0;
2991: pVideoRasterDelayed = &STRam[addr_new & ~1]; /* new value for pVideoRaster at the end of Video_CopyScreenLineColor */
2992: Delayed = true;
2993: }
2994:
2995: /* Counter is modified while display is ON, store the bytes offset for Video_CopyScreenLineColor */
2996: /* Even on a real STE, modifying video address in this case will cause artefacts */
1.1.1.11 root 2997: else
2998: {
1.1.1.16 root 2999: VideoCounterDelayedOffset = addr_new - addr_cur;
3000: pVideoRasterDelayed = NULL;
1.1.1.15 root 3001: Delayed = true;
1.1.1.11 root 3002: }
3003:
1.1.1.16 root 3004: LOG_TRACE(TRACE_VIDEO_STE , "write ste video %x val=0x%x video_old=%x video_new=%x offset=%x delayed=%s"
3005: " video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n" ,
3006: IoAccessCurrentAddress, AddrByte, addr_cur , addr_new , VideoCounterDelayedOffset , Delayed ? "yes" : "no" ,
1.1.1.15 root 3007: FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.9 root 3008: }
1.1.1.8 root 3009:
3010: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3011: /**
3012: * Read video sync register (0xff820a)
3013: */
1.1.1.8 root 3014: void Video_Sync_ReadByte(void)
3015: {
1.1.1.17 root 3016: if ( (ConfigureParams.System.nMachineType == MACHINE_ST)
3017: || (ConfigureParams.System.nMachineType == MACHINE_STE)
3018: || (ConfigureParams.System.nMachineType == MACHINE_MEGA_STE) )
1.1.1.14 root 3019: IoMem[0xff820a] |= 0xfc; /* set unused bits 2-7 to 1 */
1.1.1.8 root 3020: }
3021:
3022: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3023: /**
3024: * Read video base address low byte (0xff820d). A plain ST can only store
3025: * screen addresses rounded to 256 bytes (i.e. no lower byte).
3026: */
1.1.1.8 root 3027: void Video_BaseLow_ReadByte(void)
3028: {
1.1.1.11 root 3029: if (ConfigureParams.System.nMachineType == MACHINE_ST)
3030: IoMem[0xff820d] = 0; /* On ST this is always 0 */
1.1.1.9 root 3031:
1.1.1.11 root 3032: /* Note that you should not do anything here for STe because
3033: * VideoBase address is set in an interrupt and would be wrong
3034: * here. It's fine like this.
3035: */
1.1.1.8 root 3036: }
3037:
3038: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3039: /**
3040: * Read video line width register (0xff820f)
3041: */
1.1.1.8 root 3042: void Video_LineWidth_ReadByte(void)
3043: {
1.1.1.11 root 3044: if (ConfigureParams.System.nMachineType == MACHINE_ST)
3045: IoMem[0xff820f] = 0; /* On ST this is always 0 */
1.1.1.18 root 3046:
3047: /* If we're not in STF mode, we use the value already stored in $ff820f */
1.1.1.8 root 3048: }
3049:
3050: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3051: /**
3052: * Read video shifter mode register (0xff8260)
3053: */
1.1.1.8 root 3054: void Video_ShifterMode_ReadByte(void)
3055: {
1.1.1.11 root 3056: if (bUseHighRes)
1.1.1.14 root 3057: IoMem[0xff8260] = 2; /* If mono monitor, force to high resolution */
3058:
1.1.1.17 root 3059: if (ConfigureParams.System.nMachineType == MACHINE_ST)
3060: IoMem[0xff8260] |= 0xfc; /* On STF, set unused bits 2-7 to 1 */
1.1.1.20! root 3061: else
! 3062: IoMem[0xff8260] &= 0x03; /* Only use bits 0 and 1, unused bits 2-7 are set to 0 */
1.1.1.8 root 3063: }
3064:
1.1.1.10 root 3065: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3066: /**
3067: * Read horizontal scroll register (0xff8265)
3068: */
1.1.1.10 root 3069: void Video_HorScroll_Read(void)
3070: {
1.1.1.11 root 3071: IoMem[0xff8265] = HWScrollCount;
1.1.1.10 root 3072: }
1.1.1.8 root 3073:
3074: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3075: /**
3076: * Write video line width register (0xff820f) - STE only.
3077: * Content of LineWidth is added to the shifter counter when display is
3078: * turned off (start of the right border, usually at cycle 376)
3079: */
1.1.1.10 root 3080: void Video_LineWidth_WriteByte(void)
3081: {
1.1.1.11 root 3082: Uint8 NewWidth;
1.1.1.15 root 3083: int FrameCycles, HblCounterVideo, LineCycles;
1.1.1.13 root 3084: int Delayed;
1.1.1.11 root 3085:
1.1.1.15 root 3086: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.11 root 3087:
3088: NewWidth = IoMem_ReadByte(0xff820f);
3089:
3090: /* We must also check the write does not overlap the end of the line */
1.1.1.15 root 3091: if ( ( ( nHBL == HblCounterVideo ) && ( LineCycles <= ShifterFrame.ShifterLines[ HblCounterVideo ].DisplayEndCycle ) )
1.1.1.18 root 3092: || ( nHBL < nStartHBL ) || ( nHBL >= nEndHBL + BlankLines ) )
1.1.1.13 root 3093: {
1.1.1.11 root 3094: LineWidth = NewWidth; /* display is on, we can still change */
1.1.1.13 root 3095: NewLineWidth = -1; /* cancel 'pending' change */
1.1.1.15 root 3096: Delayed = false;
1.1.1.13 root 3097: }
1.1.1.11 root 3098: else
1.1.1.13 root 3099: {
1.1.1.11 root 3100: NewLineWidth = NewWidth; /* display is off, can't change LineWidth once in right border */
1.1.1.15 root 3101: Delayed = true;
1.1.1.13 root 3102: }
1.1.1.11 root 3103:
1.1.1.15 root 3104: LOG_TRACE(TRACE_VIDEO_STE , "write ste linewidth=0x%x delayed=%s video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n",
1.1.1.13 root 3105: NewWidth, Delayed ? "yes" : "no" ,
1.1.1.15 root 3106: FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.10 root 3107: }
3108:
3109: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3110: /**
3111: * Write to video shifter palette registers (0xff8240-0xff825e)
1.1.1.14 root 3112: *
3113: * Note that there's a special "strange" case when writing only to the upper byte
3114: * of the color reg (instead of writing 16 bits at once with .W/.L).
3115: * In that case, the byte written to address x is automatically written
3116: * to address x+1 too (but we shouldn't copy x in x+1 after masking x ; we apply the mask at the end)
3117: * So : move.w #0,$ff8240 -> color 0 is now $000
3118: * move.b #7,$ff8240 -> color 0 is now $707 !
3119: * move.b #$55,$ff8241 -> color 0 is now $755 ($ff8240 remains unchanged)
3120: * move.b #$71,$ff8240 -> color 0 is now $171 (bytes are first copied, then masked)
1.1.1.11 root 3121: */
1.1.1.8 root 3122: static void Video_ColorReg_WriteWord(Uint32 addr)
3123: {
1.1.1.15 root 3124: if (!bUseHighRes && !bUseVDIRes) /* Don't store if hi-res or VDI resolution */
1.1.1.11 root 3125: {
3126: int idx;
3127: Uint16 col;
3128: Video_SetHBLPaletteMaskPointers(); /* Set 'pHBLPalettes' etc.. according cycles into frame */
3129: col = IoMem_ReadWord(addr);
1.1.1.14 root 3130:
3131: /* Handle special case when writing only to the upper byte of the color reg */
3132: if ( ( nIoMemAccessSize == SIZE_BYTE ) && ( ( IoAccessCurrentAddress & 1 ) == 0 ) )
3133: col = ( IoMem_ReadByte(addr) << 8 ) + IoMem_ReadByte(addr); /* copy upper byte into lower byte */
3134:
1.1.1.11 root 3135: if (ConfigureParams.System.nMachineType == MACHINE_ST)
3136: col &= 0x777; /* Mask off to ST 512 palette */
3137: else
3138: col &= 0xfff; /* Mask off to STe 4096 palette */
3139: IoMem_WriteWord(addr, col); /* (some games write 0xFFFF and read back to see if STe) */
3140: Spec512_StoreCyclePalette(col, addr); /* Store colour into CyclePalettes[] */
3141: idx = (addr-0xff8240)/2; /* words */
3142: pHBLPalettes[idx] = col; /* Set colour x */
3143: *pHBLPaletteMasks |= 1 << idx; /* And mask */
3144:
1.1.1.15 root 3145: if (LOG_TRACE_LEVEL(TRACE_VIDEO_COLOR))
1.1.1.11 root 3146: {
1.1.1.15 root 3147: int FrameCycles, HblCounterVideo, LineCycles;
3148:
3149: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
3150:
3151: LOG_TRACE_PRINT ( "write col addr=%x col=%x video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n" ,
3152: addr, col,
3153: FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.11 root 3154: }
3155:
3156: }
1.1.1.8 root 3157: }
3158:
3159: void Video_Color0_WriteWord(void)
3160: {
1.1.1.11 root 3161: Video_ColorReg_WriteWord(0xff8240);
1.1.1.8 root 3162: }
3163:
3164: void Video_Color1_WriteWord(void)
3165: {
1.1.1.11 root 3166: Video_ColorReg_WriteWord(0xff8242);
1.1.1.8 root 3167: }
3168:
3169: void Video_Color2_WriteWord(void)
3170: {
1.1.1.11 root 3171: Video_ColorReg_WriteWord(0xff8244);
1.1.1.8 root 3172: }
3173:
3174: void Video_Color3_WriteWord(void)
3175: {
1.1.1.11 root 3176: Video_ColorReg_WriteWord(0xff8246);
1.1.1.8 root 3177: }
3178:
3179: void Video_Color4_WriteWord(void)
3180: {
1.1.1.11 root 3181: Video_ColorReg_WriteWord(0xff8248);
1.1.1.8 root 3182: }
3183:
3184: void Video_Color5_WriteWord(void)
3185: {
1.1.1.11 root 3186: Video_ColorReg_WriteWord(0xff824a);
1.1.1.8 root 3187: }
3188:
3189: void Video_Color6_WriteWord(void)
3190: {
1.1.1.11 root 3191: Video_ColorReg_WriteWord(0xff824c);
1.1.1.8 root 3192: }
3193:
3194: void Video_Color7_WriteWord(void)
3195: {
1.1.1.11 root 3196: Video_ColorReg_WriteWord(0xff824e);
1.1.1.8 root 3197: }
3198:
3199: void Video_Color8_WriteWord(void)
3200: {
1.1.1.11 root 3201: Video_ColorReg_WriteWord(0xff8250);
1.1.1.8 root 3202: }
3203:
3204: void Video_Color9_WriteWord(void)
3205: {
1.1.1.11 root 3206: Video_ColorReg_WriteWord(0xff8252);
1.1.1.8 root 3207: }
3208:
3209: void Video_Color10_WriteWord(void)
3210: {
1.1.1.11 root 3211: Video_ColorReg_WriteWord(0xff8254);
1.1.1.8 root 3212: }
3213:
3214: void Video_Color11_WriteWord(void)
3215: {
1.1.1.11 root 3216: Video_ColorReg_WriteWord(0xff8256);
1.1.1.8 root 3217: }
3218:
3219: void Video_Color12_WriteWord(void)
3220: {
1.1.1.11 root 3221: Video_ColorReg_WriteWord(0xff8258);
1.1.1.8 root 3222: }
3223:
3224: void Video_Color13_WriteWord(void)
3225: {
1.1.1.11 root 3226: Video_ColorReg_WriteWord(0xff825a);
1.1.1.8 root 3227: }
3228:
3229: void Video_Color14_WriteWord(void)
3230: {
1.1.1.11 root 3231: Video_ColorReg_WriteWord(0xff825c);
1.1.1.8 root 3232: }
3233:
3234: void Video_Color15_WriteWord(void)
3235: {
1.1.1.11 root 3236: Video_ColorReg_WriteWord(0xff825e);
1.1.1.8 root 3237: }
3238:
3239:
3240: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3241: /**
3242: * Write video shifter mode register (0xff8260)
3243: */
1.1.1.8 root 3244: void Video_ShifterMode_WriteByte(void)
3245: {
1.1.1.20! root 3246: Uint8 VideoShifterByte;
! 3247:
! 3248: if (ConfigureParams.System.nMachineType == MACHINE_TT)
! 3249: {
! 3250: TTRes = IoMem_ReadByte(0xff8260) & 7;
! 3251: /* Copy to TT shifter mode register: */
! 3252: IoMem_WriteByte(0xff8262, TTRes);
! 3253: }
! 3254: else if (!bUseVDIRes) /* ST and STE mode */
1.1.1.11 root 3255: {
1.1.1.18 root 3256: /* We only care for lower 2-bits */
3257: VideoShifterByte = IoMem[0xff8260] & 3;
3258: /* 3 is not a valid resolution, use low res instead */
3259: if ( VideoShifterByte == 3 )
1.1.1.13 root 3260: {
3261: VideoShifterByte = 0;
3262: IoMem_WriteByte(0xff8260,0);
3263: }
1.1.1.18 root 3264:
1.1.1.11 root 3265: Video_WriteToShifter(VideoShifterByte);
3266: Video_SetHBLPaletteMaskPointers();
3267: *pHBLPaletteMasks &= 0xff00ffff;
3268: /* Store resolution after palette mask and set resolution write bit: */
3269: *pHBLPaletteMasks |= (((Uint32)VideoShifterByte|0x04)<<16);
3270: }
1.1.1.10 root 3271: }
3272:
3273: /*-----------------------------------------------------------------------*/
1.1.1.11 root 3274: /**
1.1.1.13 root 3275: * Handle horizontal scrolling to the left.
3276: * On STE, there're 2 registers that can scroll the line :
3277: * - $ff8264 : scroll without prefetch
1.1.1.14 root 3278: * - $ff8265 : scroll with prefetch
1.1.1.13 root 3279: * Both registers will scroll the line to the left by skipping the amount
3280: * of pixels in $ff8264 or $ff8265 (from 0 to 15).
3281: * As some pixels will be skipped, this means the shifter needs to read
3282: * 16 other pixels in advance in some internal registers to have an uninterrupted flow of pixels.
3283: *
1.1.1.14 root 3284: * These 16 pixels can be prefetched before the display starts (on cycle 56 for example) when using
1.1.1.13 root 3285: * $ff8265 to scroll the line. In that case 8 more bytes per line (low res) will be read. Most programs
3286: * are using $ff8265 to scroll the line.
3287: *
3288: * When using $ff8264, the next 16 pixels will not be prefetched before the display
3289: * starts, they will be read when the display normally starts (cycle 56). While
3290: * reading these 16 pixels, the shifter won't be able to display anything, which will
3291: * result in 16 pixels having the color 0. So, reading the 16 pixels will in fact delay
3292: * the real start of the line, which will look as if it started 16 pixels later. As the
3293: * shifter will stop the display at cycle 56+320 anyway, this means the last 16 pixels
3294: * of each line won't be displayed and you get the equivalent of a shorter 304 pixels line.
3295: * As a consequence, this register is rarely used to scroll the line.
3296: *
3297: * By writing a value > 0 in $ff8265 (to start prefetching) and immediatly after a value of 0
3298: * in $ff8264 (no scroll and no prefetch), it's possible to fill the internal registers used
3299: * for the scrolling even if scrolling is set to 0. In that case, the shifter will start displaying
3300: * each line 16 pixels earlier (as the data are already available in the internal registers).
3301: * This allows to have 336 pixels per line (instead of 320) for all the remaining lines on the screen.
3302: *
3303: * Although some programs are using this sequence :
3304: * move.w #1,$ffff8264 ; Word access!
3305: * clr.b $ffff8264 ; Byte access!
3306: * It is also possible to add 16 pixels by doing :
3307: * move.b #X,$ff8265 ; with X > 0
3308: * move.b #0,$ff8264
1.1.1.11 root 3309: * Some games (Obsession, Skulls) and demos (Pacemaker by Paradox) use this
3310: * feature to increase the resolution, so we have to emulate this bug, too!
1.1.1.13 root 3311: *
3312: * So considering a low res line of 320 pixels (160 bytes) :
3313: * - if both $ff8264/65 are 0, no scrolling happens, the shifter reads 160 bytes and displays 320 pixels (same as STF)
3314: * - if $ff8265 > 0, line is scrolled, the shifter reads 168 bytes and displays 320 pixels.
3315: * - if $ff8264 > 0, line is scrolled, the shifter reads 160 bytes and displays 304 pixels,
3316: * the display starts 16 pixels later.
3317: * - if $ff8265 > 0 and then $ff8264 = 0, there's no scrolling, the shifter reads 168 bytes and displays 336 pixels,
3318: * the display starts 16 pixels earlier.
1.1.1.11 root 3319: */
1.1.1.13 root 3320:
3321: void Video_HorScroll_Write_8264(void)
3322: {
3323: Video_HorScroll_Write();
3324: }
3325:
3326: void Video_HorScroll_Write_8265(void)
3327: {
3328: Video_HorScroll_Write();
3329: }
3330:
1.1.1.10 root 3331: void Video_HorScroll_Write(void)
3332: {
1.1.1.13 root 3333: Uint32 RegAddr;
1.1.1.11 root 3334: Uint8 ScrollCount;
1.1.1.13 root 3335: Uint8 Prefetch;
1.1.1.15 root 3336: int FrameCycles, HblCounterVideo, LineCycles;
3337: bool Add16px = false;
1.1.1.13 root 3338: static Uint8 LastVal8265 = 0;
3339: int Delayed;
3340:
1.1.1.15 root 3341: Video_GetPosition_OnWriteAccess ( &FrameCycles , &HblCounterVideo , &LineCycles );
1.1.1.10 root 3342:
1.1.1.13 root 3343: RegAddr = IoAccessCurrentAddress; /* 0xff8264 or 0xff8265 */
3344: ScrollCount = IoMem[ RegAddr ];
1.1.1.11 root 3345: ScrollCount &= 0x0f;
1.1.1.10 root 3346:
1.1.1.13 root 3347: if ( RegAddr == 0xff8264 )
3348: {
3349: Prefetch = 0; /* scroll without prefetch */
1.1.1.15 root 3350: LastCycleScroll8264 = FrameCycles;
1.1.1.11 root 3351:
1.1.1.15 root 3352: ShifterFrame.Scroll8264Pos.VBL = nVBLs;
3353: ShifterFrame.Scroll8264Pos.FrameCycles = FrameCycles;
3354: ShifterFrame.Scroll8264Pos.HBL = HblCounterVideo;
3355: ShifterFrame.Scroll8264Pos.LineCycles = LineCycles;
3356:
3357: if ( ( ScrollCount == 0 ) && ( LastVal8265 > 0 )
3358: && ( ShifterFrame.Scroll8265Pos.VBL > 0 ) /* a write to ff8265 has been made */
3359: && ( ShifterFrame.Scroll8265Pos.VBL == ShifterFrame.Scroll8264Pos.VBL ) /* during the same VBL */
3360: && ( ShifterFrame.Scroll8264Pos.FrameCycles - ShifterFrame.Scroll8265Pos.FrameCycles <= 40 ) )
1.1.1.13 root 3361: {
1.1.1.15 root 3362: LOG_TRACE(TRACE_VIDEO_BORDER_H , "detect ste left+16 pixels\n" );
3363: Add16px = true;
1.1.1.13 root 3364: }
3365: }
3366: else
1.1.1.11 root 3367: {
1.1.1.13 root 3368: Prefetch = 1; /* scroll with prefetch */
1.1.1.15 root 3369: LastCycleScroll8265 = FrameCycles;
3370:
3371: ShifterFrame.Scroll8265Pos.VBL = nVBLs;
3372: ShifterFrame.Scroll8265Pos.FrameCycles = FrameCycles;
3373: ShifterFrame.Scroll8265Pos.HBL = HblCounterVideo;
3374: ShifterFrame.Scroll8265Pos.LineCycles = LineCycles;
3375:
1.1.1.13 root 3376: LastVal8265 = ScrollCount;
1.1.1.15 root 3377: Add16px = false;
1.1.1.11 root 3378: }
1.1.1.13 root 3379:
3380:
3381: /* If the write was made before display starts on the current line, then */
3382: /* we can still change the value now. Else, the new values will be used */
3383: /* for line n+1. */
3384: /* We must also check the write does not overlap the end of the line */
1.1.1.15 root 3385: if ( ( ( LineCycles <= LINE_START_CYCLE_50 ) && ( nHBL == HblCounterVideo ) )
1.1.1.18 root 3386: || ( nHBL < nStartHBL ) || ( nHBL >= nEndHBL + BlankLines ) )
1.1.1.11 root 3387: {
1.1.1.13 root 3388: HWScrollCount = ScrollCount; /* display has not started, we can still change */
3389: HWScrollPrefetch = Prefetch;
3390: bSteBorderFlag = Add16px;
3391: NewHWScrollCount = -1; /* cancel 'pending' change */
1.1.1.15 root 3392: Delayed = false;
1.1.1.11 root 3393: }
3394: else
3395: {
1.1.1.13 root 3396: NewHWScrollCount = ScrollCount; /* display has started, can't change HWScrollCount now */
3397: NewHWScrollPrefetch = Prefetch;
3398: if ( Add16px )
3399: NewSteBorderFlag = 1;
3400: else
3401: NewSteBorderFlag = 0;
1.1.1.15 root 3402: Delayed = true;
1.1.1.11 root 3403: }
3404:
1.1.1.15 root 3405: LOG_TRACE(TRACE_VIDEO_STE , "write ste %x hwscroll=%x delayed=%s video_cyc_w=%d line_cyc_w=%d @ nHBL=%d/video_hbl_w=%d pc=%x instr_cyc=%d\n" ,
1.1.1.13 root 3406: RegAddr , ScrollCount, Delayed ? "yes" : "no" ,
1.1.1.15 root 3407: FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
1.1.1.13 root 3408: }
1.1.1.11 root 3409:
3410: /*-----------------------------------------------------------------------*/
3411: /**
3412: * Write to TT shifter mode register (0xff8262)
3413: */
3414: void Video_TTShiftMode_WriteWord(void)
3415: {
3416: TTRes = IoMem_ReadByte(0xff8262) & 7;
3417:
3418: /*fprintf(stderr, "Write to FF8262: %x, res=%i\n", IoMem_ReadWord(0xff8262), TTRes);*/
3419:
3420: /* Is it an ST compatible resolution? */
3421: if (TTRes <= 2)
3422: {
3423: IoMem_WriteByte(0xff8260, TTRes);
3424: Video_ShifterMode_WriteByte();
3425: }
3426: }
3427:
3428: /*-----------------------------------------------------------------------*/
3429: /**
3430: * Write to TT color register (0xff8400)
3431: */
3432: void Video_TTColorRegs_WriteWord(void)
3433: {
1.1.1.15 root 3434: bTTColorsSync = false;
1.1.1.11 root 3435: }
3436:
3437: /*-----------------------------------------------------------------------*/
3438: /**
1.1.1.15 root 3439: * Write to ST color register on TT (0xff8240)
1.1.1.11 root 3440: */
3441: void Video_TTColorSTRegs_WriteWord(void)
3442: {
1.1.1.15 root 3443: bTTColorsSTSync = false;
1.1.1.8 root 3444: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.