You will not be able to post if you are still using Microsoft email addresses such as Hotmail etc
See here for more information viewtopic.php?f=20&t=7296
BOOKMARK THIS PAGE !
https://www.exxosforum.co.uk:8085/IP_CHECK/
You can unban yourself if needed. It also sends me reports to investigate the ban.
DO NOT USE MOBILE / CGNAT DEVICES WHERE THE IP CHANGES CONSTANTLY!
At this time, it is unfortunately not possible to whitelist users when your IP changes constantly.
You may inadvertently get banned because a previous attack may have used the IP you are now on.
So I suggest people only use fixed IP address devices until I can think of a solution for this problem!

Converting HISOFT to 68K ASM "almost" works

News,announcements,programming,fixes,game patches & discussions.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Converting HISOFT to 68K ASM "almost" works

Post by exxos »

So my test HISOFT program works, it outputs time and date fine.

Code: Select all

'GET FLASHY CLOCK TIME TO SET OS TIME

LIBRARY "gemaes","gemvdi","bios","gemdos","xbios" 

'R8k is double the stack size 4096bytes 4k
'500k doesnt work, 600 does but odd crashes.. so try 620

'$option k350,E+,N-,O-,X+,V+' ,M8,R8
'$option g,y+,u+,#,[,]
'$option fE:\CLOCK\TIMESET.PRG

DEFINT a-z


DIM SEL,RTC_ADDRESS,RTC_DATA_ADDRESS
DIM SHARED  TC$,tmp&

RTC_ADDRESS& = 16746992			'FF89F0
RTC_DATA_ADDRESS& = 16746994    'FF89F2

'WINDOW OPEN 1,"TEMP",0,0,200,200,1


CALL GETRTCTIMEDATE

'WINDOW CLOSE 1

END




'********************
'BUSY WAIT LOOP 
'*********************

'MAKE SURE WE DONT READ OR WRITE DURING A INTERNAL UPDATE TO THE REGISTERS

DEF BUSYWAIT

SHARED RTC_ADDRESS&,RTC_DATA_ADDRESS&
STATIC TMP%,T$,N&,junk 

'WAIT FOR BIT TO GO LOW
N&=0 ' should really use timer ticks for this as boosters may upset the count

DO
POKEW (RTC_ADDRESS&),&B1111111100001010 ' CONTROL REGISTER 0AH
TMP% = PEEKW (RTC_DATA_ADDRESS&)
T$=BIN$(TMP%)
N& = N& +1: if N&>10000 THEN PRINT "RTC TIME OUT":MOUSE 0 :BUSYWAIT = 1:EXIT DEF 
LOOP UNTIL MID$(T$,9,1)="0" ' 1111111100000000

BUSYWAIT = 0 ' no error

END DEF



'********************************************************
'GET RTC TIME  DATE - EPIC EFFORT ROUTINE 
'********************************************************

SUB GETRTCTIMEDATE
SHARED RTC_ADDRESS&,RTC_DATA_ADDRESS&
STATIC TMP%,H%,M%,S%,DY%,DATE%,MTH%,YR%,E%,DATA$,Z

E% = 0 ' ERRORS 0

'******************************
'START OF HOURS,MINS,SECS READ 
'******************************

Z = BUSYWAIT' if rtc timeout then z will be 1, otherwise 0 for no error

'if we timed out here then assume everything is fucked 
IF Z = 1 THEN PRINT "RTC TIME OUT!":EXIT SUB

'GET SECONDS REGISTRES
POKEW (RTC_ADDRESS&),&B1111111100000000
TMP% = PEEKW (RTC_DATA_ADDRESS&)
S% = (TMP% + 256)' 256 CLEARS THE HIGH BYTE 11111111

Z= BUSYWAIT 'MAKE SURE RTC NOT BUSY

'GET MINUTES REGISTRES
POKEW (RTC_ADDRESS&),&B1111111100000010
TMP% = PEEKW (RTC_DATA_ADDRESS&)
M% = TMP% + 256

Z= BUSYWAIT 'FORMAT C: 

'GET HOURS REGISTRES
POKEW (RTC_ADDRESS&),&B1111111100000100
TMP% = PEEKW (RTC_DATA_ADDRESS&)
TMP%=TMP% + 256
IF TMP% > 32767 THEN TMP%=TMP% - 32768 ' IF THE PM BIT IS SET THEN WE NEED TO ZERO IT
H% = TMP% 

'WITHOUT RTC RESET WE GET BACK 40,51,137 SO NEED TO ERROR CHECK 

IF H% >24 OR M%>60 OR S%>60 THEN 
INCR E%
PRINT "RTC TIME IS CORRUPTED"
END IF 

'*************************
'START OF DATE STUFF 
'************************


'GET WEEK DAY ( NOT USED - or is it ;) )
'SUNDAY = 1
POKEW (RTC_ADDRESS&),&B1111111100000110    ' SET ADDRESS 06H
DY% = PEEKW (RTC_DATA_ADDRESS&)  - &B1111111100000000         ' READ REGISTER

'GET DAY 1-30
POKEW (RTC_ADDRESS&),&B1111111100000111    ' SET ADDRESS 07H
DATE% = PEEKW (RTC_DATA_ADDRESS&) - &B1111111100000000         ' READ REGISTER

'GET MONTH 1-12
POKEW (RTC_ADDRESS&),&B1111111100001000    ' SET ADDRESS 08H
MTH% = PEEKW (RTC_DATA_ADDRESS&)  - &B1111111100000000         ' READ REGISTER

'GET YEAR
POKEW (RTC_ADDRESS&),&B1111111100001001    ' SET ADDRESS 09H
YR% = PEEKW (RTC_DATA_ADDRESS&) - &B1111111100000000          ' READ REGISTER

IF DY% >7 OR DATE%>32 OR MTH%>12 THEN 
INCR E%
PRINT "RTC TIME IS CORRUPTED"
END IF 


'**************************************************************************
'WE ALSO NEED TO CHECK BINARY OR OCT MODE (RTC DEFAULTS TO OCT I THINK?)
'**************************************************************************

'LOOK AT 0BH    DM 
'12345678  9   10  11  12   13 14   15   16 
'         SET,PIE,AIE,UIE,SQWE,DM,24/12,DSE
POKEW (RTC_ADDRESS&),&B1111111100001011    ' SET ADDRESS 0BH
TMP% = PEEKW (RTC_DATA_ADDRESS&)           ' READ REGISTER into tmp&
IF MID$(STR$(TMP%),14,1) = "0" THEN 
INCR E%
PRINT "RTC TIME IS CORRUPTED"
END IF 

'IF E%>0 THEN WE HAVE RTC ERRORS SO QUIT THIS ROUTINE 
IF E% > 0 THEN EXIT SUB 

'IF WE ARE HERE THEN WE NEED TO SET THE RTC MENU NUMBERS 
'A BIT SHITTY AS WE HAVE TO CONVERT NUMBER TO STRING THEN REMOVE THE FIRST SPACE

PRINT MID$(STR$(H%),2,LEN(STR$(H%))-1) ' HOURS
PRINT MID$(STR$(M%),2,LEN(STR$(M%))-1) 'MINS
PRINT MID$(STR$(S%),2,LEN(STR$(S%))-1) 'SECONDS

PRINT MID$(STR$(DATE%),2,LEN(STR$(DATE%))-1) ' DAY
PRINT MID$(STR$(MTH%),2,LEN(STR$(MTH%))-1) 'MONTH
PRINT MID$(STR$(YR%),2,LEN(STR$(YR%))-1)    'YEAR

'TRANSLATE WEEK DAY TO TEXT 

'IF DY%=1 THEN Setob_Text WEEKDAY%,"SUNDAY"
'IF DY%=2 THEN Setob_Text WEEKDAY%,"MONDAY"
'IF DY%=3 THEN Setob_Text WEEKDAY%,"TUESDAY"
'IF DY%=4 THEN Setob_Text WEEKDAY%,"WEDNESDAY"
'IF DY%=5 THEN Setob_Text WEEKDAY%,"THURSDAY"
'IF DY%=6 THEN Setob_Text WEEKDAY%,"FRIDAY"
'IF DY%=7 THEN Setob_Text WEEKDAY%,"SATURDAY"
'IF DY%>7 THEN Setob_Text WEEKDAY%,"EXXOSDAY"

 


'NEED TO GET THE DLS 24H FIGURES FROM THE RTC AND SET THE TICK BOXES 
'12345678  9   10  11  12   13 14   15   16 
'         SET,PIE,AIE,UIE,SQWE,DM,24/12,DSE
Z= BUSYWAIT 'MAKE SURE RTC NOT BUSY
POKEW (RTC_ADDRESS&),&B1111111100001011 ' CONTROL REGISTER 0BH
DATA$ = BIN$(PEEKW (RTC_DATA_ADDRESS&))
'IF MID$(DATA$,16,1) = "1" THEN Setob_state DLSRADIO%,mask_checked ELSE Setob_state DLSRADIO%,mask_normal
'IF MID$(DATA$,15,1) = "1" THEN Setob_state  RADIO24%,mask_checked ELSE Setob_state RADIO24%,mask_normal

END SUB
GPT5 failed badly at the conversion.

GROK is almost there, but the year keeps showing as zero or odd things like "J8" instead of 26 :shrug: Anyone take a peek see if anything looks wrong in the ASM code ?

Code: Select all

* Atari ST 68000 Assembly for Devpac
* Fixed version: uses proper low-byte masking (andi #$00FF) for ALL registers
* Year is now correctly preserved and printed (was being overwritten before)
* Matches HiSoft BASIC logic exactly where it matters
* Busy-wait and DM check also use safe masking
* PRINT_NUM logic is correct (DIVU remainder/quotient handling was already right)

	SECTION TEXT

START:
	jsr	GETRTCTIMEDATE
	clr.w	-(sp)
	trap	#1

* BusyWait - returns d0=0 ok, d0=1 timeout
BUSYWAIT:
	movem.l	d1/a0,-(sp)
	move.l	#10000,d1
.loop:
	move.w	#$FF0A,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0	; safe low byte
	btst	#7,d0		; UIP bit
	beq.s	.ok
	subq.l	#1,d1
	bne.s	.loop
	moveq	#1,d0
	bra.s	.exit
.ok:
	moveq	#0,d0
.exit:
	movem.l	(sp)+,d1/a0
	rts

GETRTCTIMEDATE:
	movem.l	d0-d7/a0-a1,-(sp)
	clr.w	d7		; error flag

	jsr	BUSYWAIT
	tst.w	d0
	beq.s	.notimeout
	pea	MSG_TIMEOUT(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	bra	.exit
.notimeout:

* Seconds (reg 0)
	move.w	#$FF00,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d6		; S%

	jsr	BUSYWAIT

* Minutes (reg 2)
	move.w	#$FF02,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d5		; M%

	jsr	BUSYWAIT

* Hours (reg 4) - ignore 12h/PM bit (assumes 24h as per your BASIC checks)
	move.w	#$FF04,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d4		; H%

* Time validity
	cmpi.w	#24,d4
	bhi.s	.timecorr
	cmpi.w	#60,d5
	bhi.s	.timecorr
	cmpi.w	#60,d6
	bhi.s	.timecorr
	bra.s	.timeok
.timecorr:
	addq.w	#1,d7
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.timeok:

* Weekday (reg 6)
	move.w	#$FF06,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d3		; DY%

* Day (reg 7)
	move.w	#$FF07,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d2		; DATE%

* Month (reg 8)
	move.w	#$FF08,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d1		; MTH%

* Year (reg 9) - THIS IS THE ONE THAT WAS BEING LOST
	move.w	#$FF09,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	andi.w	#$00FF,d0
	move.w	d0,d0		; YR% now safely in d0 (and preserved until print)

* Date validity
	cmpi.w	#7,d3
	bhi.s	.datecorr
	cmpi.w	#32,d2
	bhi.s	.datecorr
	cmpi.w	#12,d1
	bhi.s	.datecorr
	bra.s	.dateok
.datecorr:
	addq.w	#1,d7
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.dateok:

* DM bit check (binary mode)
	jsr	BUSYWAIT
	move.w	#$FF0B,(RTC_ADDR)
	move.w	(RTC_DATA),d3
	andi.w	#$00FF,d3
	btst	#2,d3		; DM=1 (binary)
	bne.s	.dmok
	addq.w	#1,d7
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.dmok:

	tst.w	d7
	bne.s	.exit

* Print: H M S DATE MTH YEAR (year was previously lost)
	move.w	d0,-(sp)	; save year
	move.w	d4,d0
	jsr	PRINT_NUM
	move.w	d5,d0
	jsr	PRINT_NUM
	move.w	d6,d0
	jsr	PRINT_NUM
	move.w	d2,d0
	jsr	PRINT_NUM
	move.w	d1,d0
	jsr	PRINT_NUM
	move.w	(sp)+,d0	; restore year
	jsr	PRINT_NUM

.exit:
	movem.l	(sp)+,d0-d7/a0-a1
	rts

* PRINT_NUM: prints 0-99 as decimal string + CRLF (no leading zero)
PRINT_NUM:
	movem.l	d1/a1,-(sp)
	lea	BUFFER(PC),a1
	cmpi.w	#10,d0
	bcs.s	.one
	move.w	d0,d1
	divu.w	#10,d1
	swap	d1
	addi.b	#'0',d1
	move.b	d1,1(a1)	; units
	swap	d1
	addi.b	#'0',d1
	move.b	d1,(a1)		; tens
	moveq	#2,d1
	bra.s	.out
.one:
	addi.b	#'0',d0
	move.b	d0,(a1)
	moveq	#1,d1
.out:
	clr.b	(a1,d1.w)
	pea	(a1)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	pea	CRLF(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d1/a1
	rts

	SECTION DATA
RTC_ADDR	EQU	$FF89F0
RTC_DATA	EQU	$FF89F2

MSG_TIMEOUT	DC.B	'RTC TIME OUT!',13,10,0
MSG_CORRUPTED	DC.B	'RTC TIME IS CORRUPTED',13,10,0
CRLF		DC.B	13,10,0

	SECTION BSS
BUFFER		DS.B	10

	END
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

ah.. this now now reports "26" correctly. I asked Grok to not use D0...

Code: Select all

* Atari ST 68000 Assembly for Devpac
* Fixed version: matches HiSoft BASIC extraction methods exactly
* Time regs: add.w #256,d0
* Date regs: sub.w #$FF00,d0
* Year stored in d7 (higher data reg) to avoid any issues
* PRINT_NUM has clr.l d1 for safety

	SECTION TEXT

START:
	jsr	GETRTCTIMEDATE
	clr.w	-(sp)
	trap	#1

* BusyWait - returns d0=0 ok, d0=1 timeout
BUSYWAIT:
	movem.l	d1/a0,-(sp)
	move.l	#10000,d1
.loop:
	move.w	#$FF0A,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	add.w	#256,d0		; match BASIC for control
	btst	#7,d0		; UIP bit
	beq.s	.ok
	subq.l	#1,d1
	bne.s	.loop
	moveq	#1,d0
	bra.s	.exit
.ok:
	moveq	#0,d0
.exit:
	movem.l	(sp)+,d1/a0
	rts

GETRTCTIMEDATE:
	movem.l	d0-d7/a0-a1,-(sp)
	clr.w	d0		; error flag in d0 now

	jsr	BUSYWAIT
	tst.w	d0
	beq.s	.notimeout
	pea	MSG_TIMEOUT(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	bra	.exit
.notimeout:

* Seconds (reg 0)
	move.w	#$FF00,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	add.w	#256,d0
	move.w	d0,d6		; S%

	jsr	BUSYWAIT

* Minutes (reg 2)
	move.w	#$FF02,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	add.w	#256,d0
	move.w	d0,d5		; M%

	jsr	BUSYWAIT

* Hours (reg 4)
	move.w	#$FF04,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	add.w	#256,d0
	cmpi.w	#128,d0
	blo.s	.no_pm
	subi.w	#128,d0		; clear PM bit
.no_pm:
	move.w	d0,d4		; H%

* Time validity
	cmpi.w	#24,d4
	bhi.s	.timecorr
	cmpi.w	#60,d5
	bhi.s	.timecorr
	cmpi.w	#60,d6
	bhi.s	.timecorr
	bra.s	.timeok
.timecorr:
	addq.w	#1,d0
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.timeok:

* Weekday (reg 6)
	move.w	#$FF06,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	sub.w	#$FF00,d0
	move.w	d0,d3		; DY%

* Day (reg 7)
	move.w	#$FF07,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	sub.w	#$FF00,d0
	move.w	d0,d2		; DATE%

* Month (reg 8)
	move.w	#$FF08,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	sub.w	#$FF00,d0
	move.w	d0,d1		; MTH%

* Year (reg 9)
	move.w	#$FF09,(RTC_ADDR)
	move.w	(RTC_DATA),d0
	sub.w	#$FF00,d0
	move.w	d0,d7		; save YR in d7

* Check date validity
	cmpi.w	#7,d3
	bhi.s	.datecorr
	cmpi.w	#32,d2
	bhi.s	.datecorr
	cmpi.w	#12,d1
	bhi.s	.datecorr
	bra.s	.dateok
.datecorr:
	addq.w	#1,d0
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.dateok:

* DM bit check (binary mode)
	jsr	BUSYWAIT
	move.w	#$FF0B,(RTC_ADDR)
	move.w	(RTC_DATA),d3
	add.w	#256,d3		; match BASIC for control
	btst	#2,d3		; DM=1 (binary)
	bne.s	.dmok
	addq.w	#1,d0
	pea	MSG_CORRUPTED(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
.dmok:

	tst.w	d0
	bne.s	.exit

* Print: H M S DATE MTH YEAR
	move.w	d4,d0
	jsr	PRINT_NUM
	move.w	d5,d0
	jsr	PRINT_NUM
	move.w	d6,d0
	jsr	PRINT_NUM
	move.w	d2,d0
	jsr	PRINT_NUM
	move.w	d1,d0
	jsr	PRINT_NUM
	move.w	d7,d0		; year from d7
	jsr	PRINT_NUM

.exit:
	movem.l	(sp)+,d0-d7/a0-a1
	rts

* PRINT_NUM: prints 0-99 as decimal string + CRLF (no leading zero)
PRINT_NUM:
	movem.l	d1/a1,-(sp)
	lea	BUFFER(PC),a1
	cmpi.w	#10,d0
	bcs.s	.one
	clr.l	d1		; clear high word for clean dividend
	move.w	d0,d1
	divu.w	#10,d1
	swap	d1		; remainder in low
	addi.b	#'0',d1
	move.b	d1,1(a1)	; units
	swap	d1		; quotient in low
	addi.b	#'0',d1
	move.b	d1,(a1)		; tens
	moveq	#2,d1
	bra.s	.out
.one:
	addi.b	#'0',d0
	move.b	d0,(a1)
	moveq	#1,d1
.out:
	clr.b	(a1,d1.w)
	pea	(a1)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	pea	CRLF(PC)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d1/a1
	rts

	SECTION DATA
RTC_ADDR	EQU	$FF89F0
RTC_DATA	EQU	$FF89F2

MSG_TIMEOUT	DC.B	'RTC TIME OUT!',13,10,0
MSG_CORRUPTED	DC.B	'RTC TIME IS CORRUPTED',13,10,0
CRLF		DC.B	13,10,0

	SECTION BSS
BUFFER		DS.B	10

	END

Now to figure out how to set system time :lol:
User avatar
mrbombermillzy
Moderator
Moderator
Posts: 2266
Joined: 03 Jun 2018 19:37

Re: Converting HISOFT to 68K ASM "almost" works

Post by mrbombermillzy »

Sorry, by the time I had written back, you had already answered yourself. :lol:

But anyway, grok has done more than 'not use d0'.

It basically went from ANDing the RTC value that was then stored into d0 (plus nonsensically storing d0 on top of itself - Im sure logic ops on the 680xx store the result in the register automatically, so this is not necessary).

Whereas the new version SUBTRACTS 255/$ff from the top byte of the RTC_DATA value in d0. (It then stores in d7 because you told it to; you should be able to use d0 though). Im not told how the year value is stored in the register, so cant really clarify why this result is correct, but if you say it works, thats great! :)


HTH
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

@mrbombermillzy I ran out of "free" chats for Grok for today. So I moved to GPT5, but like you say, it decides to correct stuff it thinks its wrong without asking. So it then breaks other stuff..

I was trying to get GPT to add in the bios calls to set the time.. it sort of did it, but now all the values are listed in hex, and wasn't before. I told it to correct it, now im getting weird numbers all over the place :roll:
Steve
Posts: 3273
Joined: 15 Sep 2017 11:49

Re: Converting HISOFT to 68K ASM "almost" works

Post by Steve »

@exxos a lot of the guys over in another forum are mainly using Claude.ai to assist their programming. Perhaps you could give that a go.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

Steve wrote: 09 Feb 2026 15:55 @exxos a lot of the guys over in another forum are mainly using Claude.ai to assist their programming. Perhaps you could give that a go.
Will give it go later... thanks.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

So currently it *almost* works..

I set all to zero in CP.. then load the set program, then the year jumps up 2 :shrug:

IMG_4585.JPG
(stupid cam wouldn't focus)
IMG_4586.JPG
IMG_4587.JPG

Code: Select all

* Atari ST 68000 Assembly for Devpac
* Original working RTC read code (HiSoft BASIC compatible)
* + Added: set GEMDOS system date/time when no errors

        SECTION TEXT

START:
        jsr     GETRTCTIMEDATE
        clr.w   -(sp)
        trap    #1

* BusyWait - returns d0=0 ok, d0=1 timeout
BUSYWAIT:
        movem.l d1/a0,-(sp)
        move.l  #10000,d1
.loop:
        move.w  #$FF0A,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        add.w   #256,d0         ; match BASIC for control
        btst    #7,d0           ; UIP bit
        beq.s   .ok
        subq.l  #1,d1
        bne.s   .loop
        moveq   #1,d0
        bra.s   .exit
.ok:
        moveq   #0,d0
.exit:
        movem.l (sp)+,d1/a0
        rts

GETRTCTIMEDATE:
        movem.l d0-d7/a0-a1,-(sp)
        clr.w   d0              ; error flag in d0 now

        jsr     BUSYWAIT
        tst.w   d0
        beq.s   .notimeout
        pea     MSG_TIMEOUT(PC)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
        bra     .exit
.notimeout:

* Seconds (reg 0)
        move.w  #$FF00,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        add.w   #256,d0
        move.w  d0,d6           ; S%

        jsr     BUSYWAIT

* Minutes (reg 2)
        move.w  #$FF02,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        add.w   #256,d0
        move.w  d0,d5           ; M%

        jsr     BUSYWAIT

* Hours (reg 4)
        move.w  #$FF04,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        add.w   #256,d0
        cmpi.w  #128,d0
        blo.s   .no_pm
        subi.w  #128,d0         ; clear PM bit
.no_pm:
        move.w  d0,d4           ; H%

* Time validity
        cmpi.w  #24,d4
        bhi.s   .timecorr
        cmpi.w  #60,d5
        bhi.s   .timecorr
        cmpi.w  #60,d6
        bhi.s   .timecorr
        bra.s   .timeok
.timecorr:
        addq.w  #1,d0
        pea     MSG_CORRUPTED(PC)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
.timeok:

* Weekday (reg 6)
        move.w  #$FF06,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        sub.w   #$FF00,d0
        move.w  d0,d3           ; DY%

* Day (reg 7)
        move.w  #$FF07,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        sub.w   #$FF00,d0
        move.w  d0,d2           ; DATE%

* Month (reg 8)
        move.w  #$FF08,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        sub.w   #$FF00,d0
        move.w  d0,d1           ; MTH%

* Year (reg 9)
        move.w  #$FF09,(RTC_ADDR)
        move.w  (RTC_DATA),d0
        sub.w   #$FF00,d0
        move.w  d0,d7           ; save YR in d7

* Check date validity
        cmpi.w  #7,d3
        bhi.s   .datecorr
        cmpi.w  #32,d2
        bhi.s   .datecorr
        cmpi.w  #12,d1
        bhi.s   .datecorr
        bra.s   .dateok
.datecorr:
        addq.w  #1,d0
        pea     MSG_CORRUPTED(PC)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
.dateok:

* DM bit check (binary mode)
        jsr     BUSYWAIT
        move.w  #$FF0B,(RTC_ADDR)
        move.w  (RTC_DATA),d3
        add.w   #256,d3         ; match BASIC for control
        btst    #2,d3           ; DM=1 (binary)
        bne.s   .dmok
        addq.w  #1,d0
        pea     MSG_CORRUPTED(PC)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
.dmok:

        tst.w   d0
        bne.s   .print_only

* --------- NEW: set GEMDOS system date/time ----------
        jsr     SET_SYSTEM_TIME

.print_only:
* Print: H M S DATE MTH YEAR
        move.w  d4,d0
        jsr     PRINT_NUM
        move.w  d5,d0
        jsr     PRINT_NUM
        move.w  d6,d0
        jsr     PRINT_NUM
        move.w  d2,d0
        jsr     PRINT_NUM
        move.w  d1,d0
        jsr     PRINT_NUM
        move.w  d7,d0           ; year from d7 (00-99)
        jsr     PRINT_NUM

.exit:
        movem.l (sp)+,d0-d7/a0-a1
        rts

* ------------------------------------------------------------
* SET_SYSTEM_TIME
* Uses: d4=hour d5=min d6=sec d2=day d1=month d7=year(00-99)
* Assumes RTC year is 2000-2099 -> years since 1980 = 20 + year
*
* GEMDOS:
*   Tsetdate (0x2B): packed date = ((year-1980)<<9) | (month<<5) | day
*   Tsettime (0x2D): packed time = (hour<<11) | (min<<5) | (sec>>1)
* ------------------------------------------------------------
SET_SYSTEM_TIME:
        movem.l d0-d3,-(sp)

* ---- Pack date into d0.w ----
        move.w  d7,d0           ; year 00-99
        addi.w  #20,d0          ; year-1980 (assumes 2000-2099)
        lsl.w   #8,d0           ; <<8
        lsl.w   #1,d0           ; <<9 total

        move.w  d1,d1           ; month in d1
        move.w  d1,d2           ; temp use d2
        lsl.w   #5,d2           ; month<<5
        or.w    d2,d0
        move.w  d2,d2           ; (no-op, keeps assembler happy if picky)

        move.w  d2,d2           ; (no-op)
        move.w  d2,d2           ; (no-op)

        * OR in day (original day is in d2, but we used d2 temp above)
        * So reload day from saved regs: use d3 as temp to avoid confusion
        move.w  d2,d3           ; d3 currently holds month<<5, keep? (not needed)
        move.w  d2,d3           ; (no-op)

        * Correctly OR the day from the original day reg:
        * Original day is still in d2? No, we overwrote d2 as temp.
        * So: use d3 for temp month, and keep day safe by copying it first.

        movem.l (sp)+,d0-d3     ; restore and redo cleanly (safer than being clever)
        movem.l d0-d3,-(sp)

        * Clean pack date without clobbering day:
        move.w  d2,d3           ; save DAY into d3
        move.w  d7,d0
        addi.w  #20,d0
        lsl.w   #8,d0
        lsl.w   #1,d0
        move.w  d1,d2
        lsl.w   #5,d2
        or.w    d2,d0
        or.w    d3,d0           ; OR in day

        move.w  d0,-(sp)
        move.w  #$2B,-(sp)      ; Tsetdate
        trap    #1
        addq.l  #4,sp

* ---- Pack time into d0.w ----
        move.w  d4,d0           ; hour
        lsl.w   #8,d0
        lsl.w   #3,d0           ; <<11 total

        move.w  d5,d1
        lsl.w   #5,d1           ; min<<5
        or.w    d1,d0

        move.w  d6,d1
        lsr.w   #1,d1           ; sec>>1
        or.w    d1,d0

        move.w  d0,-(sp)
        move.w  #$2D,-(sp)      ; Tsettime
        trap    #1
        addq.l  #4,sp

        movem.l (sp)+,d0-d3
        rts

* PRINT_NUM: prints 0-99 as decimal string + CRLF (no leading zero)
PRINT_NUM:
        movem.l d1/a1,-(sp)
        lea     BUFFER(PC),a1
        cmpi.w  #10,d0
        bcs.s   .one
        clr.l   d1              ; clear high word for clean dividend
        move.w  d0,d1
        divu.w  #10,d1
        swap    d1              ; remainder in low
        addi.b  #'0',d1
        move.b  d1,1(a1)        ; units
        swap    d1              ; quotient in low
        addi.b  #'0',d1
        move.b  d1,(a1)         ; tens
        moveq   #2,d1
        bra.s   .out
.one:
        addi.b  #'0',d0
        move.b  d0,(a1)
        moveq   #1,d1
.out:
        clr.b   (a1,d1.w)
        pea     (a1)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
        pea     CRLF(PC)
        move.w  #9,-(sp)
        trap    #1
        addq.l  #6,sp
        movem.l (sp)+,d1/a1
        rts

        SECTION DATA
RTC_ADDR        EQU     $FF89F0
RTC_DATA        EQU     $FF89F2

MSG_TIMEOUT     DC.B    'RTC TIME OUT!',13,10,0
MSG_CORRUPTED   DC.B    'RTC TIME IS CORRUPTED',13,10,0
CRLF            DC.B    13,10,0

        SECTION BSS
BUFFER          DS.B    10

        END
You do not have the required permissions to view the files attached to this post.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

So Claude says..

1.PNG
2.PNG

I made the change, but CP still shows 28 for the year :roll:

1.PNG
2.PNG

So basically it has no idea either :lol: :roll:
You do not have the required permissions to view the files attached to this post.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

:lol: I've seen that behavior last last somewhere.. where the AI goes down a logical path and they says "oh wait" then goes down another path.. :lol: :roll: So why bother outputting the first lot of info when its wrong anyway :roll:


So it output a debug version...

IMG_4588.JPG
Excellent! Now I can see the problem. The packed date is $95C4 but it should be $5C49!
Let me decode $95C4:

Bits 15-9 (year): $95C4 >> 9 = $4A = 74 decimal → 1980 + 74 = 2054 (wrong!)
Bits 8-5 (month): ($95C4 >> 5) & $0F = 2 ✓
Bits 4-0 (day): $95C4 & $1F = 4 (should be 9!)

Wait, that's weird. Let me recalculate. Actually looking at the bits:
$95C4 = 1001 0101 1100 0100
The issue is clear - the bytes are swapped! The Motorola 68000 is big-endian, but when you push a word onto the stack for GEMDOS, it might be expecting it in a different byte order, OR the issue is that you're computing it wrong.
Actually, let me verify: $5C49 would be:

0101 1100 0100 1001
Year (bits 15-9): 010 1110 = 46 ✓
Month (bits 8-5): 0 010 = 2 ✓
Day (bits 4-0): 0 1001 = 9 ✓

So $5C49 is correct. But you're getting $95C4.
AH! I found it! Look at your hex printing routine - it has a bug! The rol.w #4,d0 is rotating the original value, but you're also doing complex bit shifting. The PRINT_HEX routine is showing you the wrong value.
But more importantly, the real bug is that $95C4 when decoded actually gives year 2028 if GEMDOS is interpreting it correctly!
Let me calculate what $95C4 means:

$95C4 >> 9 = $12B >> 1 = ... wait, let me be more careful.

$95C4 in binary: 1001010111000100

Bits 15-9: 1001010 = 74 decimal → year 2054

That's not 28. Let me think about this differently...
The problem might be byte-swapping on the stack! Try this fix:Edited a file, read a fileFix potential byte-order issue when pushing date to GEMDOSrtc_debug.s+5-4Presented fileDoneTry adding swap d0 before pushing the date value to the stack. This swaps the high and low bytes of the word, which might be what GEMDOS expects!

Capture.PNG


It probably need someone to look at the code who knows what they are doing :lol:
You do not have the required permissions to view the files attached to this post.
User avatar
exxos
Site Admin
Site Admin
Posts: 28157
Joined: 16 Aug 2017 23:19
Location: UK

Re: Converting HISOFT to 68K ASM "almost" works

Post by exxos »

Bonkers.. I set 26 in the year in CP.. Then run my program..

IMG_4589.JPG

All shows 26.. all fine...


Then load CP and its 28 again :WTF:


IMG_4590.JPG

I think Control Panel must be broken somehow at this point :roll:
You do not have the required permissions to view the files attached to this post.

Return to “SOFTWARE PROGRAMMING & DISCUSSION”

Who is online

Users browsing this forum: CCBot, petal [bot] and 8 guests