Removing left and right borders

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Removing left and right borders

Post by joska »

I'm trying to understand how left/right border removal is working. I found some code in ST-News 5.1:

Code: Select all

; BORDERS.S
;
; The following code will effectively bust any borders present on
; your color monitor.
;
; Original source by TEX, but it was slightly mutilated by the eager
; fingers of Digital Insanity (of course)
;
; Have fun with it!

screen		equ	$a0000		; address of new screen
line		equ	(1*8)-1		; scanline where border is gone

x:		pea 	0		; supervisor on
		move	#$20,-(sp)
		trap	#1
		addq.l	#6,sp
		move.l	d0,old_stack

		move.b	#0,$fffa1d	; disable timer C and D

		move	#0,$ff8240	; black screen

		move	#2,-(sp)	; get physbase
		trap	#14
		addq.l	#2,sp
		move.l	d0,oldscr

		move.l	#screen,d0	; set screen address
		lsr.l	#8,d0
		move.b	d0,$ff8203
		lsr 	#8,d0
		move.b	d0,$ff8201

		move.l	#screen+(line+2)*160,newscr	; fill screen
		lea	screen,a0
		moveq	#-1,d1
		move	#11499,d0
clsloop:	move.l	d1,(a0)+
		dbra	d0,clsloop

; put some graphics on the screen to show the effect

		move.l	newscr,a6	; pattern on screen
		moveq	#0,d4
kgloop:		lea	box,a0		
		move	#15,d7
gzloop:		move.l	a6,a1
		add.l	#230,a6		; 230 bytes per scanline
		movem.l (a0)+,d0-d1
		move	#27,d6
gsloop:		movem.l d0-d1,(a1)
		addq.l	#8,a1
		dbra	d6,gsloop
		addq	#1,d4
		cmp	#35,d4
		beq	gr_end
		dbra	d7,gzloop
		bra	kgloop
gr_end:
		move	#37,-(sp)		; vsync
		trap	#14
		addq.l	#2,sp

		move.b	#2,$ff820a	; 50 Hz
		move.b	#0,$ff8260	; lo-res

		movem.l palette,d0-d7
		movem.l d0-d7,$ff8240

		move	#37,-(sp)		; vsync
		trap	#14
		addq.l	#2,sp

; install timer B

		move.l	#noborder,$120
		move.b	#0,$fffa1b
		move.b	#line,$fffa21
		move.b	#8,$fffa1b
		move.b	#200,$fffa21
		bset	#0,$fffa07
		bset	#0,$fffa13

		bra 	wait

; well, this is the routine that does the job!

noborder:	movem.l d0-d7/a0-a6,-(sp)
		move	#$2700,sr

		lea	$ff8209,a0	; video address counter low
		lea	$ff8260,a1	; resolution
		lea	$fffa21,a2	; timer B data

		moveq	#0,d0
		moveq	#0,d1
		moveq	#16,d2
		moveq	#2,d3
		moveq	#0,d4

tbsyncloop:	cmp.b	#199,(a2)
		bne 	tbsyncloop

waitloop:	move.b	(a0),d0
		beq.s	waitloop

		sub	d0,d2
		lsl.w	d2,d1

begin:		dcb.w	92,$4e71

		lea	$ff820a,a0	; sync modus
		move	#34,d0		; number of scanlines to be opened

; repeat this for a number of scanlines

lines:		nop

; switch to mono -> obliterate linker border (MMU: OUCH!!)

		move.b	d3,(a1)		; to monochrome
		move.b	d4,(a1)		; to lo-res

		dcb.w	89,$4e71

; 50/60 Hz for right border (NURSE!!!)
		
		move.b	d4,(a0)
		move.b	d3,(a0)

		dcb.w	13,$4e71

; another 70Hz shock to make it work on all STs

		move.b	d3,(a1)
		nop
		move.b	d4,(a1)
 
		dcb.w	9,$4e71

		dbra	d0,lines	; end of loop, we've had 512 cycles

		movem.l	(sp)+,d0-d7/a0-a6
		bclr	#0,$fffa0f
		rte

; end of border-obliterating timer B interrupt!!!

wait:		move	#7,-(sp)
		trap	#1
		addq.l	#2,sp

		move.b	#0,$fffa1b
		bclr	#0,$fffa07
		bclr	#0,$fffa13

		move.b	#$51,$fffa1d

		move	#$777,$ff8240
		move	#0,$ff8240+6

		move.b	#1,$ff8260	; midres
		move.b	#2,$ff820a	; 50Hz

		move.l	oldscr,d0
		lsr.l	#8,d0
		move.b	d0,$ff8203
		lsr	#8,d0
		move.b	d0,$ff8201

		move.l	old_stack(pc),-(sp)
		move	#$20,-(sp)
		trap	#1
		addq.l	#6,sp

		clr.w	-(sp)
		trap	#1
	
		even

old_stack:	dc.l	0

palette:	dc.w	$0000,$0076,$0210,$0650,$0320,$0760,$0540,$0430	
		dc.w	$0527,$0111,$0222,$0333,$0444,$0555,$0666,$0333

box:		dc.w	$0001,$0000,$FFFF,$FFFF,$7FFD,$7FFC,$8003,$FFFF
		dc.w	$4005,$7FFC,$8003,$FFFF,$5FF5,$7FFC,$8003,$FFFF
		dc.w	$5015,$701C,$8FE3,$FFFF,$57D5,$701C,$8FE3,$FFFF
		dc.w	$5455,$739C,$8FE3,$FFFF,$5555,$739C,$8FE3,$FFFF
		dc.w	$5455,$739C,$8FE3,$FFFF,$57D5,$701C,$8FE3,$FFFF
		dc.w	$5015,$701C,$8FE3,$FFFF,$5FF5,$7FFC,$8003,$FFFF
		dc.w	$4005,$7FFC,$8003,$FFFF,$7FFD,$7FFC,$8003,$FFFF
		dc.w	$0001,$0000,$FFFF,$FFFF,$FFFF,$0000,$FFFF,$FFFF

		even

oldscr:		dc.l	0
newscr:		dc.l	0
However, this does not work my my Mega STE (in 8Mhz mode of course), and I don't want to debug code that I don't know how is supposed to work... Is there some simple, easy to follow code out there that opens the left/right borders at a certain scanline?
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2260
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Removing left and right borders

Post by Cyprian »

There are some differences between ST and STE overscan code, also in case of the ST there are 4 a bit different codes due to “wakeup” modes.

Anyway there you can find a couple of them:
ST Synclock demosystem v1.0 by Evil / DHS
https://dhs.nu/files.php?t=democreation

Code: Select all

- 400x273 fullscreen (230 byte lw, ST/STe)
- 400x273 fullscreen (224 byte lw, STe)
- 320x265 screen with syncscrolling (ST/STe)
- 400x265 screen with syncscrolling (ST/STe)

Also there are a nice articles by Evil/DHS:

https://dhs.nu/misc.php?t=special&feature=overscan
http://ae.dhs.nu/hatari_overscan/
Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
User avatar
thomas3
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Apr 11, 2017 8:57 pm
Location: the people's republic of south yorkshire, uk.

Re: Removing left and right borders

Post by thomas3 »

This may not work.
But in the label "lines", where is says "NURSE!" as a comment...
Add a nop between the move.bs and change the subsequent dcb to 12 from 13. Those are the timings I use.

EDIT: the timings of the first switch are also a nop different from what I'd use. As Cyprian says, try the code in Evil's demosystem.
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2260
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Removing left and right borders

Post by Cyprian »

from that topic: https://www.atari-forum.com/viewtopic.php?t=25002

DHS Evil's code :

Code: Select all

		move.b	d7,$ffff8260.w			; Left border
		move.w	d7,$ffff8260.w

		dcb.w	90,$4e71

		move.w	d7,$ffff820a.w			; Right border
		move.b	d7,$ffff820a.w

		dcb.w	26,$4e71

James Ingram's code:

Code: Select all

		move.b	d3,(a1)			; Left border
		move.b	d4,(a1)

		dcb.w	90,$4e71

		move.b	d4,(a0)			; Right border
		move.b	d3,(a0)

		dcb.w	13,$4e71

		move.b	d3,(a1)			; Stabilizer
		nop
		move.b	d4,(a1)

		dcb.w	12,$4e71
Last edited by Cyprian on Sun Sep 12, 2021 7:39 pm, edited 2 times in total.
Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
User avatar
thomas3
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Apr 11, 2017 8:57 pm
Location: the people's republic of south yorkshire, uk.

Re: Removing left and right borders

Post by thomas3 »

For the ST/STe overscan, the DHS demosys is the same as Ingham's but adds a nop between the first switch moves, then 89 nops, then another nop between the next switch, then 12 nops, then the stabiliser as above. This is the code I use and its stable.
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2260
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Removing left and right borders

Post by Cyprian »

as @thomas3 mentioned I did some changes and now it should works:

Code: Select all

; repeat this for a number of scanlines

lines:
		; nop

; switch to mono -> obliterate linker border (MMU: OUCH!!)

		move.b	d3,(a1)		; to monochrome
		move.b	d4,(a1)		; to lo-res

		; dcb.w	89,$4e71
		dcb.w	90,$4e71

; 50/60 Hz for right border (NURSE!!!)
thomas3 wrote: Sun Sep 12, 2021 7:38 pm For the ST/STe overscan, the DHS demosys is the same as Ingham's but adds a nop between the first switch moves, then 89 nops, then another nop between the next switch, then 12 nops, then the stabiliser as above. This is the code I use and its stable.
Both codes work but the screen is skewed by 16 pixels between them. The first picture shows that https://www.atari-forum.com/viewtopic.p ... 54#p231254
Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Removing left and right borders

Post by joska »

Ok, I have updated the timings with the ones from the DHS demosystem. It is working on emulated ST and STE on Hatari, but not on a real STE or emulated or real Mega STE. I currently don't have a working real ST to test on.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2260
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Removing left and right borders

Post by Cyprian »

joska wrote: Mon Sep 13, 2021 11:24 am I currently don't have a working real ST to test on.
Evil's code is for the STE only
James Ingram's code is I guess for a dedicated ST's wakeup mode
Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Removing left and right borders

Post by joska »

No, I used the ST+STE code from DHS demo system. In my case it is not working on real STE/MSTE. So clearly I'm doing something wrong.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
Cyprian
10 GOTO 10
10 GOTO 10
Posts: 2260
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: Removing left and right borders

Post by Cyprian »

joska wrote: Mon Sep 13, 2021 12:38 pm So clearly I'm doing something wrong
or maybe you have STE (very early) with different timings
Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
User avatar
troed
Atari God
Atari God
Posts: 1472
Joined: Mon Apr 30, 2012 6:20 pm
Location: Sweden

Re: Removing left and right borders

Post by troed »

All STEs have the same fullscreen line timings. Early Level 16 (Union Demo) and ST demoscene timings failed removing the left border when run on STE though.
User avatar
thomas3
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Apr 11, 2017 8:57 pm
Location: the people's republic of south yorkshire, uk.

Re: Removing left and right borders

Post by thomas3 »

joska - if you updated the timings for the fullscreen lines, did you also change the first string of NOPs before the very first left border removal, after the hardsync?

This will now also be out by one or two nops (assuming the initial timings is OK) - trial and error at this point I'm afraid....
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Removing left and right borders

Post by joska »

The problem is not the border-busting code itself, but that the interrupt is not running on real hardware. So something wrong with the ancient TEX code on my 2.06-equipped STE's. I'll look into this later, no use in messing with the timing until this is fixed :)
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
thomas3
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Apr 11, 2017 8:57 pm
Location: the people's republic of south yorkshire, uk.

Re: Removing left and right borders

Post by thomas3 »

Hi,

Looking at the timer B code, I'm surprised it works at all on anything:

Code: Select all

		move.l	#noborder,$120
		move.b	#0,$fffa1b
		move.b	#line,$fffa21
		move.b	#8,$fffa1b
		move.b	#200,$fffa21		; <--------------------
		bset	#0,$fffa07
		bset	#0,$fffa13
I've marked the offending line with an arrow -- for some reason, the starting scanline for the timer B is first set as line but then two commands later changed to 200 - outside the visible screen area?!
czietz
Hardware Guru
Hardware Guru
Posts: 1623
Joined: Tue May 24, 2016 6:47 pm

Re: Removing left and right borders

Post by czietz »

Just a total shot in the dark: Could it be that (for whatever reason) the "interrupt in service" bit is set for Timer B? In that case, no new interrupts would occur until the bit is reset. Try adding a "bclr #0,$fffa0f" to the part of the code where Timer B interrupt is installed.
ijor
Hardware Guru
Hardware Guru
Posts: 4086
Joined: Sat May 29, 2004 7:52 pm
Contact:

Re: Removing left and right borders

Post by ijor »

thomas3 wrote: Tue Sep 14, 2021 8:02 am Hi,

Looking at the timer B code, I'm surprised it works at all on anything:

Code: Select all

		move.l	#noborder,$120
		move.b	#0,$fffa1b
		move.b	#line,$fffa21
		move.b	#8,$fffa1b
		move.b	#200,$fffa21		; <--------------------
		bset	#0,$fffa07
		bset	#0,$fffa13
I've marked the offending line with an arrow -- for some reason, the starting scanline for the timer B is first set as line but then two commands later changed to 200 - outside the visible screen area?!
Each MFP timer has two separate registers. The reload counter and the actual main counter. If the timer is stopped, writing to the the TxDR register modifies both the reload and the main counter. However if the timer is already enabled, then writes to the TxDR modify the reload counter only. The current counter is not modified, not immediately until timing out and "reloaded".
Fx Cast: Atari St cycle accurate fpga core
User avatar
thomas3
Captain Atari
Captain Atari
Posts: 204
Joined: Tue Apr 11, 2017 8:57 pm
Location: the people's republic of south yorkshire, uk.

Re: Removing left and right borders

Post by thomas3 »

ijor wrote: Tue Sep 14, 2021 9:46 pm Each MFP timer has two separate registers. The reload counter and the actual main counter. If the timer is stopped, writing to the the TxDR register modifies both the reload and the main counter. However if the timer is already enabled, then writes to the TxDR modify the reload counter only. The current counter is not modified, not immediately until timing out and "reloaded".
I'm rubbish at MFP programming - I didn't know this, and this is interesting. In practice, what function does the reload counter perform?
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Removing left and right borders

Post by joska »

I also find the MFP hard to understand. A few years ago I finished a 25 year old demo project, and spent quite some time getting the rasters/bottom border removal correctly working on STE and TOS 2. I will just re-use that code instead of trying to understand the TEX code in this example.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
ijor
Hardware Guru
Hardware Guru
Posts: 4086
Joined: Sat May 29, 2004 7:52 pm
Contact:

Re: Removing left and right borders

Post by ijor »

thomas3 wrote: Wed Sep 15, 2021 8:26 am I'm rubbish at MFP programming - I didn't know this, and this is interesting. In practice, what function does the reload counter perform?
The reload register let you trigger the timer at a constant period, precisely and without need to reprogramming the timer after each timeout. MFP timers can be used for many purposes, not just for interrupts. In the ST, i.e., they are used to produce the serial port baud rate. How could you implement this without some kind reload functionality? Or say, you may want to produce a waveform with variable period. You start the timer with certain period, and while it is counting with the "old" period, you program the reload register with the next period.
Fx Cast: Atari St cycle accurate fpga core
joska
Hardware Guru
Hardware Guru
Posts: 5064
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Removing left and right borders

Post by joska »

I used the known working interrupt code, the interrupts are now working properly and I can start figuring out the border removal itself :) Right border removal worked first time, but left is still there so I will have to take a closer look at the timings.
Jo Even

VanillaMiNT - Falcon060 - Milan060 - Falcon040 - MIST - Mega STE - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64
User avatar
troed
Atari God
Atari God
Posts: 1472
Joined: Mon Apr 30, 2012 6:20 pm
Location: Sweden

Re: Removing left and right borders

Post by troed »

Right border removal needs to be exact (to four cycles precision) so it's the more difficult one. Once you have that, it's a simple case of counting nops until the left border block.

The canonical Level 16 fullscreen line, with care taken for STE and WS2 compatibility of the left border, is:

Code: Select all

lea $ffff820a.w,a0
lea $ffff8260.w,a1
moveq #0,d0

rept 274

; cycle 0 - left border
move.w a0,(a1) ; 8
nop            ; 4
move.b d0,(a1) ; 8

dcb.w $4e71,89 ; 356

; cycle 376 - right border
move.b d0,(a0) ; 8
move.w a0,(a0) ; 8

dcb.w $4e71,13 ; 52

; cycle 444 - L16 Shifter stabilizer
move.w a0,(a1) ; 8
nop            ; 4
move.b d0,(a1) ; 8

dcb.w $4e71,12 ; 48

endr
(Written from memory, apologies if there are errors)

I think your left border switch has been too tight in the posted examples. It was a common mistake to make in the beginning of fullscreen lines.

/Troed
Post Reply

Return to “Coding”