-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMM58167_GER.BAS
217 lines (161 loc) · 6.42 KB
/
MM58167_GER.BAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
REM MM58167
REM github.com/jensma-de/MM58167-ISA-RTC
ERR = 0
VERBOSE = 0
FORCE = 0
EXPOR = 1
A = 0
rtcd = 0
P = 0
REM get address from arguments
rtcinput$ = UCASE$(MID$(COMMAND$, 1, 3))
FOR i = LEN(rtcinput$) TO 1 STEP -1
A$ = MID$(rtcinput$, i, 1)
IF A$ = "A" THEN A$ = "10"
IF A$ = "B" THEN A$ = "11"
IF A$ = "C" THEN A$ = "12"
IF A$ = "D" THEN A$ = "13"
IF A$ = "E" THEN A$ = "14"
IF A$ = "F" THEN A$ = "15"
A = VAL(A$) * 16 ^ P
rtcd = rtcd + A
P = P + 1
NEXT i
REM process arguments
IF INSTR(UCASE$(COMMAND$), "GET") THEN mode$ = "GET"
IF INSTR(UCASE$(COMMAND$), "SET") THEN mode$ = "SET"
IF INSTR(UCASE$(COMMAND$), "VERBOSE") THEN VERBOSE = 1
IF INSTR(UCASE$(COMMAND$), "FORCE") THEN FORCE = 1
IF INSTR(UCASE$(COMMAND$), "NOEX") THEN EXPOR = 0
IF mode$ = "" THEN ERR = 1
IF ERR = 1 THEN GOTO usage
REM check if RTC is at given address
IF FORCE = 0 THEN
checkstart% = VAL(HEX$(INP(rtcd + 1)))
start# = TIMER
DO
LOOP UNTIL (TIMER - start#) >= .1
checkend% = VAL(HEX$(INP(rtcd + 1)))
IF checkend% < checkstart% THEN checkend% = checkend% + 100
result% = checkend% - checkstart%
IF result% = 0 OR result% > 50 THEN
PRINT "No clock found at "; rtcinput$; "h"
PRINT "To force this address, use FORCE argument"
END
END IF
END IF
IF mode$ = "GET" THEN
sekunde$ = HEX$(INP(rtcd + 2))
minute$ = HEX$(INP(rtcd + 3))
stunde$ = HEX$(INP(rtcd + 4))
tag$ = HEX$(INP(rtcd + 6))
monat$ = HEX$(INP(rtcd + 7))
jahr$ = HEX$(INP(rtcd + 9))
IF LEN(tag$) = 1 THEN tag$ = "0" + tag$
IF LEN(monat$) = 1 THEN monat$ = "0" + monat$
IF LEN(jahr$) = 1 THEN jahr$ = "0" + jahr$
IF LEN(stunde$) = 1 THEN stunde$ = "0" + stunde$
IF LEN(minute$) = 1 THEN minute$ = "0" + minute$
IF LEN(sekunde$) = 1 THEN sekunde$ = "0" + sekunde$
readdate$ = monat$ + "-" + tag$ + "-" + jahr$
readtime$ = stunde$ + ":" + minute$ + ":" + sekunde$
REM Check if a year has passed
IF EXPOR = 1 THEN
OPEN "C:\MM581.RTC" FOR APPEND AS #1
IF LOF(1) THEN
CLOSE #1
OPEN "C:\MM581.RTC" FOR INPUT AS #1
INPUT #1, yearfile$
INPUT #1, monthfile$
INPUT #1, dayfile$
CLOSE #1
IF (VAL(monthfile$) > VAL(monat$)) THEN
IF (VAL(dayfile$) > VAL(day$)) THEN
IF VERBOSE = 1 THEN
PRINT "Ein Jahreswechsel fand seit dem letzten Lesen der RTC statt."
END IF
jahrdec% = VAL(jahr$)
jahrdec% = jahrdec% + 1
jahr$ = LTRIM$(STR$(jahrdec%))
yearwrite% = VAL("&H" + jahr$)
OUT rtcd + 9, (yearwrite%)
KILL "C:\MM581.RTC"
OPEN "C:\MM581.RTC" FOR APPEND AS #1
PRINT #1, jahr$
PRINT #1, monat$
PRINT #1, tag$
CLOSE #1
END IF
END IF
ELSE
PRINT #1, jahr$
PRINT #1, monat$
PRINT #1, tag$
CLOSE #1
END IF
END IF
IF VERBOSE = 1 THEN
PRINT "Systemdatum und -zeit wurden auf "; readdate$; " und "; readtime$; " gesetzt."
END IF
DATE$ = readdate$
TIME$ = readtime$
END
END IF
IF mode$ = "SET" THEN
REM Set time
readdate$ = DATE$
readtime$ = TIME$
month$ = MID$(readdate$, 1, 2)
day$ = MID$(readdate$, 4, 2)
year$ = RIGHT$(MID$(readdate$, 7, 4), 2)
IF EXPOR = 1 THEN
KILL "C:\MM581.RTC"
OPEN "C:\MM581.RTC" FOR APPEND AS #1
PRINT #1, year$
PRINT #1, month$
PRINT #1, day$
CLOSE #1
END IF
hours$ = MID$(readtime$, 1, 2)
minutes$ = MID$(readtime$, 4, 2)
seconds$ = MID$(readtime$, 7, 2)
monthwrite% = VAL("&H" + month$)
daywrite% = VAL("&H" + day$)
yearwrite% = VAL("&H" + year$)
secondswrite% = VAL("&H" + seconds$)
minuteswrite% = VAL("&H" + minutes$)
hourswrite% = VAL("&H" + hours$)
OUT rtcd + 2, (secondswrite%)
OUT rtcd + 3, (minuteswrite%)
OUT rtcd + 4, (hourswrite%)
OUT rtcd + 6, (daywrite%)
OUT rtcd + 7, (monthwrite%)
OUT rtcd + 9, (yearwrite%)
IF VERBOSE = 1 THEN
PRINT "Zeit und Datum der RTC wurden auf "; readdate$; " und "; readtime$; " gesetzt."
END IF
END
END IF
usage:
PRINT "Anwendung:"
PRINT "----------"
PRINT ""
PRINT "MM58167.EXE ADDRESSh SET|GET [VERBOSE] [FORCE] [NOEX]"
PRINT ""
PRINT "Adressh: Adresse der RTC, setzbar mit Jumpern auf der PCB, z.B. 240h"
PRINT "SET|GET: SETzen der RTC auf Systemzeit, und anders herum."
PRINT "[VERBOSE]: Zeigt etwas mehr Infos an."
PRINT "[FORCE]: šbernimmt die ADDRESSE ohne auf Plausibilit„t zu prfen."
PRINT "[NOEX]: Keine Auslagerungsdatei C:\MM581.RTC erzeugen."
PRINT " Die Datei wird zum Erkennen eines Jahreswechsels gebraucht."
PRINT ""
PRINT "Beispiel:"
PRINT "Systemzeit auf die RTC schreiben, konfiguriert auf 340h:"
PRINT "MM58167.EXE 340h SET"
PRINT ""
PRINT "--------------------------------------------------------"
PRINT "Danke fr die Hile:"
PRINT "github.com/mrehkopf/ & github.com/Sciurus68k/"
PRINT ""
PRINT "Projektseite:"
PRINT "github.com/jensma-de/MM58167-ISA-RTC/"