Display of TI$ in border (unex. or +3K)

Basic and Machine Language

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Display of TI$ in border (unex. or +3K)

Post by Mike »

Hi, all!

I simply couldn't resist to de-lurk after I found this board 2 days ago. I'd like to introduce myself with a small ML program I wrote several years ago. It is a interrupt-driven display of TI$ in the border. Enjoy.

Greetings,

Michael

Image

Code: Select all

1 POKE55,145:POKE56,29:CLR:FORT=7569TO7679:READA:POKET,A:NEXT:SYS7569
2 DATA 120,169,163,141,20,3,169,29,141,21,3,169,176,141,3,144,88,96,162,3,181,159,149
3 DATA 250,202,208,249,160,47,56,200,165,253,253,250,29,133,253,165,252,253,244,29,133
4 DATA 252,165,251,253,238,29,133,251,176,232,165,253,125,250,29,133,253,165,252,125
5 DATA 244,29,133,252,165,251,125,238,29,133,251,152,157,250,31,173,134,2,157,250,151
6 DATA 232,224,6,208,193,76,191,234,32,3,0,0,0,0,245,75,140,14,2,0,128,192,160,16,88,60
(download)
Last edited by Mike on Thu Feb 20, 2014 5:43 pm, edited 3 times in total.
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

holy shizznit!
High Scores, Links, and Jeff's Basic Games page.
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

This will need some modification to work on a PAL machine as the jiffy clock is 1/50ths of a second not 1/60ths.

Just for those who want to know ..

Code: Select all

; vic 20 border clock
; displays TI$ in the screen border
; disassembly of BASIC DATA statements

LAB_9F	= $9F				; jiffy clock address - 1
LAB_FA	= $FA				; free page 0 space address -1
LAB_FB	= $FB				; copied jiffy high byte
LAB_FC	= $FC				; copied jiffy mid byte
LAB_FD	= $FD				; copied jiffy low byte

LAB_0286	= $0286			; current colour code

LAB_0314	= $0314			; IRQ vector low byte
LAB_0315	= $0315			; IRQ vector high byte

LAB_1FFA	= $1FFA			; video memory base pointer, first byte of extra row

LAB_9003	= $9003			; VIC chip, set rows & character size
						; bit	function
						; ---	--------
						;  7	b9 raster line
						; 6-1	number of rows
						;  0	8x16 / 8x8 characters

LAB_97FA	= $97FA			; colour memory base pointer, first byte of extra row

LAB_EABF	= $EABF			; kernal IRQ routine

; put this at the top of user RAM after reducing the RAM top to protect it

	.ORG	$1D91

; initialisation routine, set the IRQ vector to point to our code and enable an extra
; row on the VIC display

LAB_1D91
	SEI					; disable interrupts
	LDA	#<LAB_1DA3			; get our code start low byte
	STA	LAB_0314			; set IRQ vector low byte
	LDA	#>LAB_1DA3			; get our code start high byte
	STA	LAB_0315			; set IRQ vector high byte
	LDA	#$B0				; set rows & character size, 1 row more than standard
						; bit	function
						; ---	--------
						;  7	b9 raster line
						; 6-1	number of rows
						;  0	8x16 / 8x8 characters
	STA	LAB_9003			; save to VIC chip
	CLI					; enable interrupts
	RTS

; IRQ routine. copy the jiffy clock time and display it as HHMMSS in the VIC border
; which is really an extra, incomplete, row at the bottom of the screen

LAB_1DA3
	LDX	#$03				; three bytes to copy
LAB_1DA5
	LDA	LAB_9F,X			; copy jiffy clock byte ..
	STA	LAB_FA,X			; .. to free page zero byte
	DEX					; decrement count/index
	BNE	LAB_1DA5			; loop if more to do

						; now calculate each digit in turn, use Y as the
						; running current digit value
LAB_1DAC
	LDY	#$2F				; set to "0" - 1
	SEC					; set carry for subtract
LAB_1DAF
	INY					; increment character
	LDA	LAB_FD			; get copied jiffy high byte
	SBC	LAB_1DFA,X			; subtract high byte of current unit
	STA	LAB_FD			; save new jiffy high byte
	LDA	LAB_FC			; get copied jiffy mid byte
	SBC	LAB_1DF4,X			; subtract mid byte of current unit
	STA	LAB_FC			; save new jiffy mid byte
	LDA	LAB_FB			; get copied jiffy low byte
	SBC	LAB_1DEE,X			; subtract low byte of current unit
	STA	LAB_FB			; save new jiffy low byte
	BCS	LAB_1DAF			; loop if no undereflow

						; result underflowed so add back the last subtract
	LDA	LAB_FD			; get copied jiffy high byte
	ADC	LAB_1DFA,X			; add back high byte of current unit
	STA	LAB_FD			; save new jiffy high byte
	LDA	LAB_FC			; get copied jiffy mid byte
	ADC	LAB_1DF4,X			; add back mid byte of current unit
	STA	LAB_FC			; save new jiffy mid byte
	LDA	LAB_FB			; get copied jiffy low byte
	ADC	LAB_1DEE,X			; add back mid byte of current unit
	STA	LAB_FB			; save new jiffy low byte

	TYA					; Y holds the character code for the current digit
						; so copy it to A
	STA	LAB_1FFA,X			; save to video memory
	LDA	LAB_0286			; get current colour code
	STA	LAB_97FA,X			; save to colour memory
	INX					; increment index
	CPX	#$06				; compare to max + 1
	BNE	LAB_1DAC			; if not all done yet loop for next digit

	JMP	LAB_EABF			; jump to IRQVP. this is a bit naughty, what should
						; have been done was to save the original vector and
						; jump to that. this would allow chaining with other
						; IRQ wedges

; NTSC jiffy clock conversion table. values are high (LAB_1DEE) mid (LAB_1DF4) and low
; (LAB_1DFA) bytes for the following jiffy (1/60) seconds totals ..
;
; 2160000 10's of hours
;  216000  1's of hours
;   36000 10's of minutes
;    3600  1's of minutes
;     600 10's of seconds
;      60  1's of seconds

LAB_1DEE
	.byte	$20,$03,$00,$00,$00,$00
LAB_1DF4
	.byte	$F5,$4B,$8C,$0E,$02,$00
LAB_1DFA
	.byte	$80,$C0,$A0,$10,$58,$3C

; if you're running this on a PAL machine you need the PAL values for the jiffy clock
; conversion so comment out the code above and uncomment and use this table

;; PAL jiffy clock conversion table. values are high (LAB_1DEE) mid (LAB_1DF4) and low
;; (LAB_1DFA) bytes for the following jiffy (1/50) seconds totals ..
;;
;; 1800000 10's of hours
;;  180000  1's of hours
;;   30000 10's of minutes
;;    3000  1's of minutes
;;     500 10's of seconds
;;      50  1's of seconds
;
;LAB_1DEE
;	.byte	$1B,$02,$00,$00,$00,$00
;LAB_1DF4
;	.byte	$77,$BF,$75,$0B,$01,$00
;LAB_1DFA
;	.byte	$40,$20,$30,$B8,$F4,$32

	.END
Curses! the TABs got mangled by the code foramt yet again! 8^)=
Haven't tested the PAL values yet as I'm away from a real PAL Vic.

Cheers,

Lee.
Bacon
for breakfast
Posts: 578
Joined: Mon Apr 19, 2004 8:07 am

Post by Bacon »

Ahhh... Nice to see the source instead of incomprehensible DATA statements :wink:

Will try it out this weekend. Thanks to both of you, Mike and Leeeeee!
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Whoa! My first posting above, and the next thing that happens is a dis-assembly by another board member. I guess I'm in the right place here. :)

Leeeeee, AFAIK on both VIC-20 and C= 64 the jiffy clock is done with timers in the VIA/CIA chips. It runs at 60 Hz regardless of PAL or NTSC. So there's no need for an adaptation. The situation is different with the C= 128, where the jiffy clock is tightened to a raster interrupt.

I developed this program within the 6502 tube emulation on an Acorn Archimedes A5000. This emulation starts up HI BASIC, which itself contains a comfortable inline assembler. Of course, I checked the program on my still working VIC.

There are some other programs (ML and BASIC, some need up to +24K ex.) I consider to publish on my web-site. However, there's still some HTML to finish. Maybe this weekend.

Cheers,

Michael
Leeeeee
soldering master
Posts: 396
Joined: Fri Apr 23, 2004 8:14 am

Post by Leeeeee »

I never can remember which machines have which jiffy clock increment, if I need to know I go look in the books but they are miles away ATM.

I think the routine can lose the add back on underflow bit by using two's complement on alternate values and adding them instead of subtracting. Can't remember the details and those notes, like the books, are miles away.

Nice wedge. 8^)=

Lee.
User avatar
Victragic
Frogger '07
Posts: 605
Joined: Tue Nov 14, 2006 5:56 pm
Location: South Australia

Thankyou

Post by Victragic »

Excellent,

2 years too late but I found this a very useful tool, saved me frustration having to write it myself! Thanks!

For anyone interested in using this, the VIC20 definitely uses a jiffy clock that is incremented each time the interrupt is called, so PAL users must use the amended 'table' above..

..also, disk use and cassette use (and other interrupts) will play havoc with the time - I saw a program for the Commodore 64 by someone called Mike Forani that uses the 6522 chip to do much the same thing.. a bit beyond my ability to try and rewrite that for VIC20, even if it is possible.

But, this is good enough for my purposes and perfect for BASIC apps..

-G
3^4 is 81.0000001
User avatar
Victragic
Frogger '07
Posts: 605
Joined: Tue Nov 14, 2006 5:56 pm
Location: South Australia

Oops

Post by Victragic »

6526 chip, not 6522 chip... :roll:
3^4 is 81.0000001
User avatar
Victragic
Frogger '07
Posts: 605
Joined: Tue Nov 14, 2006 5:56 pm
Location: South Australia

Post by Victragic »

Or maybe not... seems every reference I see now is that PAL updates 1/60 of a second as well....

This is the routine that the kernal uses to increment time..

.C:f734 A2 00 LDX #$00
.C:f736 E6 A2 INC $A2
.C:f738 D0 06 BNE $F740
.C:f73a E6 A1 INC $A1
.C:f73c D0 02 BNE $F740
.C:f73e E6 A0 INC $A0
.C:f740 38 SEC
.C:f741 A5 A2 LDA $A2
.C:f743 E9 01 SBC #$01
.C:f745 A5 A1 LDA $A1
.C:f747 E9 1A SBC #$1A
.C:f749 A5 A0 LDA $A0
.C:f74b E9 4F SBC #$4F
.C:f74d 90 06 BCC $F755
.C:f74f 86 A0 STX $A0
.C:f751 86 A1 STX $A1
.C:f753 86 A2 STX $A2
.C:f755 AD 2F 91 LDA $912F
.C:f758 CD 2F 91 CMP $912F
.C:f75b D0 F8 BNE $F755
.C:f75d 85 91 STA $91
.C:f75f 60 RTS

It seems to wait based on $912F, which is Port A output register, not sure what that is doing, can anyone shed some light on this?

-G
3^4 is 81.0000001
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

The last part of the routine reads and debounces the status of the RUN STOP key (i.e. whether it is depressed, or not).

Greetings,

Michael
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

Post by pitcalco »

While it was a while you posted this, I have just now entered the program as listed.

I cannot quite get it to work, however. I get ti$, but not in the border. It shows up in the bottom line followed by some gobbeldygook. Any ideas?
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

Could someone make a PRG or D64 of this? It would be easier to preview.
High Scores, Links, and Jeff's Basic Games page.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

@Jeff-20: I've sent you an e-mail with clock.prg attached.

@pitcalco:
I get TI$, but not in the border. It shows up in the bottom line followed by some gobbeldygook. Any ideas?
The gobbeldygook is in fact the beginning the character ROM, showing the definitions of '@' and 'A', as textual characters. The colours are essentially random, as the kernel didn't initialise these positions. As Lee wrote in the disassembled listing above:
; IRQ routine. copy the jiffy clock time and display it as HHMMSS in the VIC border
; which is really an extra, incomplete, row at the bottom of the screen
Emphasis by me. The program opens an 24th row, which however doesn't interfere with the rest of the screen. So, for me, it's still simply 'in the border'. Hope that helps.

Greetings,

Michael
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

Post by pitcalco »

Yes, thanks Mike. It does explain things a bit better.

I suppose I was picky in expecting a nice "12:00:00" or something in the blue border, but I find this program useful anyway and most of all I am glad to know that I have the correct result.
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

pitcalco wrote:I suppose I was picky in expecting a nice "12:00:00" or something in the blue border,
This can be done, but needs a little more code. And, preferably, an 8K or greater RAM expansion.

In that case, the screen is relocated to 4096. I.e. the 24th row is completely placed into RAM. One then can put the time into this place, center it and/or expand it with ':' chars. By putting spaces and numbers in reverse, and in border colour you can make the clock appear as if it was written into the border.

If you then want the clock in another colour than background, you need to sync a raster IRQ to the first line of the 24th row, change the background colour in 36879, wait 8 lines, and restore register 36879 to the old value.

But this would have surely at least doubled the length of the program.
pitcalco wrote:I find this program useful anyway and most of all I am glad to know that I have the correct result.
Thanks!

So, ... time for pulling the rabbit out of the hat. ;)

Greetings,

Michael
Last edited by Mike on Mon Sep 03, 2007 1:11 am, edited 1 time in total.
Post Reply